Mysterious words | 프로그래밍의 벗 PivotOJ
PivotOJ

Mysterious words

시간 제한: 1000ms메모리 제한: 1024MB출처: LMIO 2015-2016BOJ 30332

문제

Vincent likes mysterious words. Mystery level is defined by the number of letters that can be removed from a word one by one such that the new word exists in the dictionary.

For example, if the dictionary contains words BALANDIS, PALIS, SPALIS, PLIS, LIS, word SPALIS has a mystery level of 3: SPALISPALISPLISLIS. Word BALANDIS has a mystery level 0, since removing letters from it doesn’t produce any words in the dictionary.

Help Vincent find the most mysterious word in the given dictionary.

입력

The first line contains an integer N – the number of words in a dictionary. The following N lines consist of a number li, followed by a single space and a word of length li. All words in the dictionary are different and contain only uppercase English letters (A – Z).

출력

Output a single integer – the mystery level of the most mysterious word in the dictionary.

예제

예제 1

입력
5
8 BALANDIS
5 PALIS
6 SPALIS
4 PLIS
3 LIS
출력
3

예제 2

입력
4
6 ADOMAS
4 ADAS
8 VYTAUTAS
5 VYTAS
출력
0
코드를 제출하려면 로그인하세요.