Under construction

Still being built. Things may change

String LD

Interview

Time limit1sMemory limit128 MB

Summary
Count how many times the first character can be stripped from every word before a word empties or two words match.
Level

Easy3 of 10

Topics
String, Simulation, Hash map
Solved
No attempts yet

Problem

Stringld (left delete) takes a string and removes its leftmost character. For example, Stringld("acm") returns "cm".

You are given a list of distinct words. In one step you apply Stringld once to every word in the list. Write a program that finds how many steps you can apply before at least one of the two conditions below becomes true.

  1. Some word becomes the empty string.
  2. Two or more words become identical.

For example, take the list aab, abac, caac. Applying the function once gives ab, bac, aac. Applying it again gives b, ac, ac, and because ac appears twice, condition 2 is true. The answer is 1. The step that made the condition true is not counted.

Input

The input holds several test cases. The first line of each test case has the number of words nn (1≤n≤1001 \le n \le 100). Each of the next nn lines has one word of at most 100 lowercase letters. Inside one test case all words are different. The input ends with a line holding a single 0.

Output

For each test case, print on one line the largest number of times Stringld can be called.

Examples1

  1. Example 1

    Input
    4
    aaba
    aaca
    baabcd
    dcba
    3
    aaa
    bbbb
    ccccc
    0
    
    Expected output
    1
    2