Filippo loves ice cream, so when he found out that a new ice cream shop had opened in Bologna, he had to go and taste their ice cream!
The shop sells flavours of ice cream, each flavour is represented by a string . The ice cream shop offers a special promotion, each customer can choose a non-empty string and he will receive a cup containing all flavours starting with , for example if the flavours are “chocolate”, “coffee” and “cookies”, by choosing the string “co” you would receive the flavours “coffee” and “cookies” but not the “chocolate” flavour.
Filippo wants to buy exactly flavours using the fewest number of cups, however Filippo can’t decide which flavours to choose so, to avoid blocking the queue, he decided to buy exactly the first flavours (i.e. flavours , , , ).
Help Filippo find the minimum number of cups needed to buy exactly the first flavours, for each
Input data
The first line contains the only integer . The next lines contain a string representing a flavour.
Output data
You need to write lines with an integer each: the minimum number of cups needed to order all flavours from to but none of the flavours from to , for each .
Constraints and clarifications
- ;
- Each flavour is formed by lowercase English characters (
a
toz
). - The total length of all flavours is at most .
- All flavours are different.
- It’s guaranteed that it is always possible to buy the first flavours for each = , , .
- The same flavour is allowed to appear in more than one cup (while still counting as a single flavour).
# | Score | Constraints |
---|---|---|
1 | 0 | Examples |
2 | 22 | , the total length of all flavours is at most . |
3 | 24 | , the total length of all flavours is at most . |
4 | 23 | The flavours are sorted in lexicographical order. |
5 | 31 | No additional limitations. |
Example 1
stdin
5
chocolate
coffee
cookies
pistachio
strawberry
stdout
1
2
1
2
3
Explanation
- : Filippo can buy one cup with = “choco”.
- : Filippo can buy two cups with = “choco” and = “coffee”
- : Filippo can buy one cup with = “c”
- : Filippo can buy two cups with = “c” and = “pi”.
- : Filippo can buy three cups with = “c”, = “pi” and = “straw”.
Example 2
stdin
10
orange
peanutbutter
mango
mint
cheesecacke
coconut
oreo
cherry
peppermint
watermelon
stdout
1
2
3
3
4
5
5
4
4
5