import
java.util.*;
class
GFG
{
static
class
TrieNode
{
char
val;
HashMap<Character, TrieNode> children;
int
visited;
TrieNode(
char
x)
{
val = x;
visited =
0
;
children =
new
HashMap<>();
}
}
static
class
Trie
{
TrieNode head;
int
ans;
Trie()
{
head =
new
TrieNode(
'\0'
);
ans =
0
;
}
void
addWord(String s)
{
TrieNode temp = head;
int
n = s.length();
for
(
int
i =
0
; i < n; i++)
{
char
ch = s.charAt(i);
if
(temp.children.get(ch) ==
null
)
{
temp.children.put(ch,
new
TrieNode(ch));
}
temp = temp.children.get(ch);
temp.visited++;
}
}
int
dfs(TrieNode node,
int
depth)
{
int
vis =
0
;
Iterator hmIterator = node.children.entrySet().iterator();
while
(hmIterator.hasNext())
{
Map.Entry child = (Map.Entry)hmIterator.next();
vis += dfs((TrieNode)child.getValue(), depth +
1
);
}
node.visited -= vis;
int
String_pair =
0
;
if
(node.visited >
1
)
{
String_pair = (node.visited /
2
);
ans += (depth * String_pair);
node.visited -= (
2
* String_pair);
}
return
(
2
* String_pair + vis);
}
int
dfshelper()
{
ans =
0
;
dfs(head,
0
);
return
ans;
}
}
public
static
void
main(String args[])
{
Trie T =
new
Trie();
String str[]
= {
"babab"
,
"ababb"
,
"abbab"
,
"aaaaa"
,
"babaa"
,
"babbb"
};
int
n =
6
;
for
(
int
i =
0
; i < n; i++)
{
T.addWord(str[i]);
}
int
ans = T.dfshelper();
System.out.println( ans );
}
}