Best Ice Cream Flavours

Time limit: 0.5s Memory limit: 512MB Input: Output:

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 NN flavours of ice cream, each flavour is represented by a string FiF_i. The ice cream shop offers a special promotion, each customer can choose a non-empty string ss and he will receive a cup containing all flavours starting with ss, 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 kk 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 kk flavours (i.e. flavours F0F_0, F1F_1, \dots, Fk1F_{k−1}).

Help Filippo find the minimum number of cups needed to buy exactly the first kk flavours, for each k=1,,Nk = 1, \dots, N

Input data

The first line contains the only integer NN. The next NN lines contain a string representing a flavour.

Output data

You need to write NN lines with an integer each: the minimum number of cups needed to order all flavours from 00 to k1k − 1 but none of the flavours from kk to N1N − 1, for each k=1,,Nk = 1, \dots, N.

Constraints and clarifications

  • 2N100 0002 \leq N \leq 100 \ 000;
  • Each flavour is formed by lowercase English characters (a to z).
  • The total length of all flavours is at most 2 000 0002 \ 000 \ 000.
  • All flavours are different.
  • It’s guaranteed that it is always possible to buy the first kk flavours for each kk = 11, \dots, NN.
  • 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 N10N \leq 10, the total length of all flavours is at most 100100.
3 24 N500N \leq 500, the total length of all flavours is at most 10 00010 \ 000.
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

  • k=1k = 1: Filippo can buy one cup with s1s_1 = “choco”.

  • k=2k = 2: Filippo can buy two cups with s1s_1 = “choco” and s2s_2 = “coffee”

  • k=3k = 3: Filippo can buy one cup with s1s_1 = “c”

  • k=4k = 4: Filippo can buy two cups with s1s_1 = “c” and s2s_2 = “pi”.

  • k=5k = 5: Filippo can buy three cups with s1s_1 = “c”, s2s_2 = “pi” and s3s_3 = “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

Log in or sign up to be able to send submissions!