Problem:


MathJax.Hub.Config({
  tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});

Airport Codes

空港コード

JAG王国では国内の空港にそれぞれ空港コードを割り当てて識別をしている．

空港コードは，小文字の英語アルファベットで表記した空港の名前をもとに以下の規則で割り当てられる:

 名前の最初の文字と，母音 (a,i,u,e,o) の直後の文字を順に取り出す．

 取り出した文字列が k 文字未満ならそれを空港コードとし， k 文字以上なら，その取り出した文字列の先頭 k 文字を空港コードとして使う．

例えば k = 3 のとき，haneda には hnd ， oookayama には ooo ， tsu には t というコードが割り当てられる．

しかしこのコードの割り当て方では，違う名前の空港でも同じコードが割り当てられることがあり，混乱を招いてしまう．
空港の名前の一覧が与えられるので，すべての空港のコードが異なるようにできるか判定して，可能な場合はすべての空港コードが異なるようにできる最小の k を求め，不可能な場合はその旨を伝えるプログラムを作成せよ．

Input

入力は100個以下のデータセットからなる．
それぞれのデータセットは次の形式で与えられる．

n
s1
...
sn

1行目に空港の数 n (2 ≤ n ≤ 50) が整数で与えられ，続く n 行にはそれぞれ空港の名前 si が文字列で与えられる．
空港の名前は'a'から'z'の小文字の英語アルファベットのみで構成され，いずれも文字数は1以上50以下である． 
また，与えられる空港の名前はすべて異なる．すなわち，1 ≤ i < j ≤ n のとき si &ne; sj を満たす．

入力の終わりは1つのゼロだけからなる行で示される．

Output

それぞれのデータセットについて，すべての空港に相異なる空港コードを割り当てられるときは，そのような最小の k を1行に出力せよ．
不可能な場合は，-1を1行に出力せよ．

Sample Input

3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
4
haneda
honda
hanamaki
hawaii
0

Output for Sample Input

1
4
-1
3



Sample input:
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
4
haneda
honda
hanamaki
hawaii
0


Sample output:
1
4
-1
3

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(kisoku_S, max_len):
    for k in range(1, max_len):
        k_s = Counter([s[0:k] for s in kisoku_S])
        if all(c == 1 for s, c in k_s.items()):
            return k
    return -1


if __name__ == "__main__":
    while True:
        n = int(input())
        if n == 0:
            break
        S = [input() for _ in range(n)]
        kisoku_S = []
        for i in range(n):
            tmp = S[i][0]
            for j in range(1, len(S[i])):
                if (
                    S[i][j - 1] == "a"
                    or S[i][j - 1] == "i"
                    or S[i][j - 1] == "u"
                    or S[i][j - 1] == "e"
                    or S[i][j - 1] == "o"
                ):
                    tmp += S[i][j]
            kisoku_S.append(tmp)
        max_len = 1
        for i in kisoku_S:
            max_len = max(len(i), max_len)
        print(solve(kisoku_S=kisoku_S, max_len=max_len))

Submission status: Wrong Answer

Solution code:

def a2c(name):
	c = name[0]
	boin=['a','i','u','e','o']
	for i, b in enumerate(name[:-1]):
		if b in boin:
			c += name[i+1]
	
	return c

while True:
	n = int(raw_input())
	
	if n == 0:
		break
	
	names = []
	length = -1
	for i in xrange(n):
		tmp = a2c(raw_input())
		names.append(tmp)
		length = max(length, len(tmp))
	
	names = set(names)
	if len(names) != n:
		print -1
		continue
	
	for i in xrange(1, length):
		s = set([name[:i] for name in names])
		if len(s) == n:
			print i
			break

Submission status: Wrong Answer

Solution code:

def a2c(name):
	c = name[0]
	boin=['a','i','u','e','o']
	for i, b in enumerate(name[:-1]):
		if b in boin:
			c += name[i+1]
	
	return c

while True:
	n = int(raw_input())
	
	if n == 0:
		break
	
	names = []
	length = -1
	for i in xrange(n):
		tmp = a2c(raw_input())
		names.append(tmp)
		length = max(length, len(tmp))
	
	names = set(names)
	if len(names) != n:
		print -1
		continue
	
	for i in xrange(1, length):
		s = set([name[:min(i, len(name))] for name in names])
		if len(s) == n:
			print i
			break

Submission status: Wrong Answer

Solution code:

def a2c(name):
	c = name[0]
	boin=['a','i','u','e','o']
	for i, b in enumerate(name[:-1]):
		if b in boin:
			c += name[i+1]
	
	return c

	
while True:
	n = int(raw_input())
	
	if n == 0:
		break
	
	names = []
	length = -1
	for i in xrange(n):
		tmp = a2c(raw_input())
		#print tmp
		names.append(tmp)
		length = max(length, len(tmp))
	
	names = set(names)
	if len(names) != n:
		print -1
		continue
	
	for i in xrange(1, length):
		s = set([name[:min(i, len(name))] for name in names])
		if len(s) == n:
			print i
			n = 0
			break
	if n == 0:
		print -1

Submission status: Wrong Answer

Solution code:

def a2c(name):
	c = name[0]
	boin=['a','i','u','e','o']
	for i, b in enumerate(name[:-1]):
		if b in boin:
			c += name[i+1]
	
	return c

	
while True:
	n = int(raw_input())
	
	if n == 0:
		break
	
	names = []
	length = -1
	for i in xrange(n):
		tmp = a2c(raw_input())
		#print tmp
		names.append(tmp)
		length = max(length, len(tmp))
	
	names = set(names)
	if len(names) != n:
		print -1
		continue
	
	for i in xrange(1, length):
		s = set([name[:min(i, len(name))] for name in names])
		if len(s) == n:
			print i
			n = 0
			break
			
	if n != 0:
		print -1

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys

def coding(s):
    t = ''
    flag = True
    for i in s:
        if flag:
            t += i
            flag = False
        if i == 'a' or i == 'i' or i == 'u' or i == 'e' or i == 'o':
            flag = True;
    return t

def possible(ls,k):
    flag = True
    for i in range(len(ls)):
        for j in range(i+1,len(ls)):
            if len(ls[i]) < k or len(ls[j]) < k:
                if ls[i] == ls[j]:
                    flag = False
                    break
                else:
                    continue

            if ls[i][0:k] == ls[j][0:k]:
                flag = False
                break
        if flag:
            break
    return flag

if __name__ == '__main__':
    while(1):
        n = int(input());
        if n == 0:
            break
        l = []
        for i in range(n):
            l.append(input())
        nl = []
        for i in l:
            nl.append(coding(i))
        sz = min([len(i) for i in l])
        ll = 0
        hh = 50
        if not(possible(nl,hh)):
            print(-1)
            continue
        while True:
            mid = (ll + hh) // 2
            if ll == mid:
                print(hh)
                break
            if possible(nl,mid):
                hh = mid
            else:
                ll = mid

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys

def coding(s):
    t = ''
    flag = True
    for i in s:
        if flag:
            t += i
            flag = False
        if i == 'a' or i == 'i' or i == 'u' or i == 'e' or i == 'o':
            flag = True;
    return t

def pre_possible(ls):
    flag = False
    for i in range(len(ls)):
        for j in range(i+1,len(ls)):
            if ls[i] == ls[j]:
                flag = True
    return flag

def possible(ls,k):
    flag = True
    for i in range(len(ls)):
        for j in range(i+1,len(ls)):
            if len(ls[i]) < k or len(ls[j]) < k:
                if ls[i] == ls[j]:
                    flag = False
                    break
                else:
                    continue

            if ls[i][0:k] == ls[j][0:k]:
                flag = False
                break
        if flag:
            break
    return flag

if __name__ == '__main__':
    while(1):
        n = int(input());
        if n == 0:
            break
        l = []
        for i in range(n):
            l.append(input())
        nl = []
        for i in l:
            nl.append(coding(i))
        sz = min([len(i) for i in l])
        ll = 0
        hh = 50
        if pre_possible(nl):
            print(-1)
            continue
        while True:
            mid = (ll + hh) // 2
            if ll == mid:
                print(hh)
                break
            if possible(nl,mid):
                hh = mid
            else:
                ll = mid

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

while True:
    n = input()
    if n == 0:
        break
    lst = []
    for i in range(n):
        lst.append(raw_input())
    S_lst = []
    for i in range(n):
        S = lst[i][0]
        for j in range(len(lst[i]) - 1):
            if lst[i][j] in ['a', 'i', 'u', 'e', 'o']:
                S += lst[i][j + 1]
        S_lst.append(S)
    if len(list(set(S_lst))) < n:
        print -1
        continue
    for i in range(1000):
        lst = []
        for j in range(n):
            lst.append(S_lst[j][:i])
        if len(list(set(lst))) == n:
            print i
            break

Submission status: Accepted

Solution code:
from collections import Counter


def solve(kisoku_S, max_len):
    for k in range(1, max_len):
        k_s = Counter([s[0:k] for s in kisoku_S])
        if all(c == 1 for s, c in k_s.items()):
            return k
    return -1


if __name__ == "__main__":
    while True:
        n = int(input())
        if n == 0:
            break
        S = [input() for _ in range(n)]
        kisoku_S = []
        for i in range(n):
            tmp = S[i][0]
            for j in range(1, len(S[i])):
                if (
                    S[i][j - 1] == "a"
                    or S[i][j - 1] == "i"
                    or S[i][j - 1] == "u"
                    or S[i][j - 1] == "e"
                    or S[i][j - 1] == "o"
                ):
                    tmp += S[i][j]
            kisoku_S.append(tmp)

        max_len = len(max(kisoku_S, key=lambda x: len(x)))+1
        print(solve(kisoku_S=kisoku_S, max_len=max_len))

Submission status: Accepted

Solution code:

def a2c(name):
	c = name[0]
	boin=['a','i','u','e','o']
	for i, b in enumerate(name[:-1]):
		if b in boin:
			c += name[i+1]
	
	return c

	
while True:
	n = int(raw_input())
	
	if n == 0:
		break
	
	names = []
	length = -1
	for i in xrange(n):
		tmp = a2c(raw_input())
		#print tmp
		names.append(tmp)
		length = max(length, len(tmp))
	
	names = set(names)
	if len(names) != n:
		print -1
		continue
	
	for i in xrange(1, length+1):
		s = set([name[:min(i, len(name))] for name in names])
		if len(s) == n:
			print i
			n = 0
			break
			
	if n != 0:
		print -1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re

def enc(s):
    repatter = re.compile(r"[aiueo]")
    ans = s[0]
    for i in range(len(s)):
        if i < len(s)-1 and repatter.match(s[i]):
            ans += s[i+1]
    return ans

def max_str(s):
    ans = len(s[0])
    for i in s:
        ans = max(ans, len(i))
    return ans

def func(s, mn, k):
    if mn < k:
        return -1
    ss = []
    for i in s:
        ss.append(i[:k])
    for i in range(len(ss)-1):
        pp = ss.pop(0)
        if pp in ss:
            return func(s, mn, k+1)
    return k

if __name__ == "__main__":
    while True:
        n = int(input())
        if n is 0:
            break
        s = []
        for i in range(n):
            s.append(enc(input()))
        print(func(s, max_str(s), 1))

Submission status: Accepted

Solution code:
li_word=["a","i","u","e","o"]
while True :
    num=int(input())
    if num==0:
        break
    else:
        li=[]
        for i in range(num):
            name=[]
            airport=list(input())
            for i in range (len(airport)):
                if i==0 or airport[i-1] in li_word:
                    name.append(airport[i])
            li.append(tuple(name))
        li_set=list(set(li))
        if len(li) != len(li_set):
            print(-1)
        else:
            a=0
            while True:
                a+=1
                check=[]
                for i in li:
                    check.append(i[:a])
                if len(check)==len(list(set(check))):
                    print(a)
                    break

Submission status: Accepted

Solution code:
vowels = 'aiueo'

while True:
    n = int(input())
    if n == 0:
        break
    codes = []
    for _ in range(n):
        name = input()
        codes.append(name[0] + ''.join(c for p, c in zip(name, name[1:]) if p in vowels))
    if len(set(codes)) != len(codes):
        print(-1)
        continue
    k = 1
    while True:
        shorten = [code[:k] for code in codes]
        if len(set(shorten)) == len(shorten):
            print(k)
            break
        k += 1

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    air = [input() for _ in range(N)]
    codes = [''.join(x for i, x in enumerate(s) if i == 0 or s[i-1] in 'aiueo') for s in air]
    max_len = max(len(x) for x in codes)
    for k in range(1, max_len + 1):
        if len(set(x[:k] for x in codes)) == N:
            print(k)
            break
    else:
        print(-1)

Submission status: Accepted

Solution code:
while True:
    N = int(input())
    if N == 0:
        break
    air = [input() for _ in range(N)]
    codes = [''.join(x for i, x in enumerate(s) if i == 0 or s[i-1] in 'aiueo') for s in air]
    if len(set(codes)) != N:
        print(-1)
        continue
    max_len = max(len(x) for x in codes)
    for k in range(1, max_len + 1):
        if len(set(x[:k] for x in codes)) == N:
            print(k)
            break

Submission status: Accepted

Solution code:
# coding: utf-8

import sys

def coding(s):
    t = ''
    flag = True
    for i in s:
        if flag:
            t += i
            flag = False
        if i == 'a' or i == 'i' or i == 'u' or i == 'e' or i == 'o':
            flag = True;
    return t

def pre_possible(ls):
    flag = False
    for i in range(len(ls)):
        for j in range(i+1,len(ls)):
            if ls[i] == ls[j]:
                flag = True
    return flag

def possible(ls,k):
    flag = True
    for i in range(len(ls)):
        for j in range(i+1,len(ls)):
            if len(ls[i]) < k or len(ls[j]) < k:
                if ls[i] == ls[j]:
                    flag = False
                    break
                else:
                    continue

            if ls[i][0:k] == ls[j][0:k]:
                flag = False
                break
        if not(flag):
            break
    return flag

if __name__ == '__main__':
    while(1):
        n = int(input());
        if n == 0:
            break
        l = []
        for i in range(n):
            l.append(input())
        nl = []
        for i in l:
            nl.append(coding(i))
        sz = min([len(i) for i in l])
        ll = 0
        hh = 50
        if pre_possible(nl):
            print(-1)
            continue
        while True:
            mid = (ll + hh) // 2
            if ll == mid:
                print(hh)
                break
            if possible(nl,mid):
                hh = mid
            else:
                ll = mid

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break
    S = []
    for i in range(n):
        s = input()
        b = []
        for j in range(len(s)):
            if j < 1 or s[j-1] in "aiueo":
                b.append(s[j])
        S.append(b)
    ans = 0
    S.sort()
    for i in range(n-1):
        A = S[i]; B = S[i+1]
        if A == B:
            print(-1)
            break
        res = min(len(A), len(B))
        for j in range(res):
            if A[j] != B[j]:
                res = j
                break
        ans = max(ans, res+1)
    else:
        print(ans)

Submission status: Accepted

Solution code:
def code(name,k):
    ret = name[0]
    for c1,c2 in zip(name,name[1:]):
        if len(ret) >= k: break
        if c1 in 'aiueo':
            ret += c2
    return ret

while True:
    N = int(input())
    if N == 0: break
    src = [input() for i in range(N)]
    maxl = max(map(len,src))
    for k in range(1,maxl+1):
        st = set()
        for s in src:
            cd = code(s,k)
            if cd in st:
                break
            st.add(cd)
        else:
            print(k)
            break
    else:
        print(-1)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:break
    s = [input() for _ in range(n)]
    k = 1
    while True:
        a = set()
        f = True
        for j in range(n):
            c = s[j][0]
            for i in range(len(s[j]) - 1):
                if len(c) == k:
                    f = False
                    break
                if s[j][i] in "aiueo":c += s[j][i + 1]
            if c in a:break
            else:a.add(c)
        else:
            print(k)
            break
        k += 1
        if f:
            print(-1)
            break

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break

        a = [S() for _ in range(n)]
        b = []
        for s in a:
            t = s[0]
            for i in range(len(s)-1):
                if s[i] in 'aiueo':
                    t += s[i+1]
            b.append(t)
        r = -1
        for k in range(1,51):
            s = set()
            f = True
            for t in b:
                if t[:k] in s:
                    f = False
                    break
                s.add(t[:k])
            if f:
                r = k
                break

        rr.append(r)


    return '\n'.join(map(str, rr))


print(main())

Submission status: Accepted

Solution code:
boin = set(['a', 'i', 'u', 'e', 'o'])

def convert(name):
    s = name[0]
    for i, c in enumerate(name[1:], 1):
        if name[i - 1] in boin:
            s += name[i]
    return s

while True:
    n = int(input())
    if n == 0:
        break
    names = [input() for _ in range(n)]
    conv = [convert(n) for n in names]
    l = sum([len(c) for c in conv])

    ans = -1
    for k in range(1, l + 1):
        short = set([c[:k] for c in conv])
        if len(short) == n:
            ans = k
            break

    print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve(n):
    s = [input() for _ in range(n)]
    key = [[i[0]] for i in s]
    for i in range(n):
        for j in range(len(s[i])-1):
            if s[i][j] in "aiueo":
                key[i].append(s[i][j+1])
    k = 0
    for i in range(n):
        for j in range(i):
            nk = 0
            m = min(len(key[i]),len(key[j]))
            while nk < m and key[i][nk] == key[j][nk]:
                nk += 1
            nk += 1
            if nk == len(key[i])+1 == len(key[j])+1:
                print(-1)
                return
            if nk > k:
                k = nk
    print(k)
    return

#Solve
if __name__ == "__main__":
    while 1:
        n = I()
        if n == 0:
            break
        solve(n)

Submission status: Accepted

Solution code:
while True:
    n = int(input())
    if n == 0:
        exit()
    s = [None] * n
    for i in range(n):
        s[i] = input()
    ans = [None] * n
    for i, ap in enumerate(s):
        code = [ap[0]]
        for j in range(len(ap) - 1):
            if ap[j] in 'aiueo':
                code.append(ap[j + 1])
        ans[i] = code
    m = max(len(x) for x in ans)
    for k in range(m):
        f = True
        for i in range(n):
            for j in range(i + 1, n):
                if ''.join(ans[i][:k + 1]) == ''.join(ans[j][:k + 1]):
                    f = False
        if f:
            print(k + 1)
            break
    else:
        print(-1)

Submission status: Accepted

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(str(type(var)) + name +":" + " = " + repr(var), file=stderr)
    return
NUM = 100
MOD = 10 ** 16 + 61
base = 12345
base_inv = pow(base,MOD-2,MOD)
power = [1] * NUM
power_inv = [1] * NUM
for n in range(1,NUM):
    power[n] = power[n-1] * base % MOD
    power_inv[n] = power_inv[n-1] * base_inv % MOD
def rollhash(s):
    res = [0]*(len(s)+1)
    for i in range(len(s)):
        res[i+1] = (res[i] + power[i] * ord(s[i])) % MOD
    return res

def main():
    while(1):
        N = int(input())
        if (N == 0):
            break
        S = []
        mL = 0
        for _ in range(N):
            s = (input().rstrip())
            n = ''
            for i in range(len(s)-1):
                if s[i] in {'a', 'i', 'u', 'e', 'o'}:
                    n += s[i+1]
            n = s[0] + n
            S.append(n)
        S = sorted(S, key=lambda x: -len(x))
        # print(S)
        if len(set(S)) < N:
            print(-1)
            continue
        for k in range(1,51):
            kind = set()
            for s in S:
                kind.add(s[:k])
            if len(kind) == N:
                break
        if len(kind) == N:
            print(k)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

bo = ['a','e','i','u','o']

while True:
    N = inp()
    if N == 0:
        break
    else:
        codes = ['']*N
        for i in range(N):
            S = input()
            flag = True
            for s in S:
                if flag:
                    codes[i] = codes[i] + s
                    flag = False
                if s in bo:
                    flag = True

        for k in range(1,60):
            koho = set()
            for code in codes:
                koho.add(code[:k])

            if len(koho) == N:
                print(k)
                break
        else:
            print(-1)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if not n:break
    l=[]
    m=0
    for _ in range(n):
        s=input()
        a=s[0]
        for i,t in enumerate(s[:-1]):
            if any(t==c for c in'aiueo'):
                a+=s[i+1]
        m=max(m,len(a))
        l.append(a)
    for k in range(m+1):
        if len(set(t[:k]for t in l))==n:
            print(k)
            break
    else:
        print(-1)

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n==0:
    break

  s = []
  maxlen = 0
  for i in range(n):
    st = input()
    stt = ""
    for j in range(len(st)):
      if j==0 or st[j-1] in "aiueo":
        stt += st[j]
    s.append(stt)
    maxlen = max(maxlen, len(stt))
  ans = -1
  k = 1
  while k<=maxlen:
    code = set()
    for e in s:
      code.add(e[:k])
    if len(code)==len(s):
      ans = k
      break
    k += 1
  print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
while True:
    n = int(input())
    if n == 0:
        break
    s = ['a' + input() for _ in range(n)]
    m = max(len(x) for x in s)
    for i in range(1, m + 1):
        dic = dict()
        for x in s:
            code = ''
            for j in range(len(x)):
                if len(code) == i:
                    break
                if j > 0 and x[j - 1] in ['a', 'i', 'u', 'e', 'o']:
                    code += x[j]
            if code in dic:
                break
            dic[code] = True
        else:
            print(i)
            break
    else:
        print(-1)

Submission status: Accepted

Solution code:
V = {"a", "i", "u", "e", "o"}
while True:
    N = int(input())
    if N==0:
        exit()
    L = []
    maxs = 0
    for _ in range(N):
        s = input()
        s_ = s[0]
        for i in range(len(s)-1):
            if s[i] in V:
                s_ += s[i+1]
        maxs = max(maxs, len(s_))
        L.append(s_ + "."*(51-len(s_)))
    L.sort()
    k = 1
    for s1, s2 in zip(L[:-1], L[1:]):
        while k != 51 and s1[:k] == s2[:k]:
            k += 1
    if k==51:
        print(-1)
    else:
        print(k)

Submission status: Accepted

Solution code:
while 1:
    n=int(input())
    if n==0:break
    code=[]
    slmax=0
    for i in range(n):
        s=input()
        s_code=s[0]
        flag=0
        for j in range(len(s)-1):
            if s[j]=="a" or s[j]=="i" or s[j]=="u" or s[j]=="e" or s[j]=="o":s_code+=s[j+1]
        slmax=max(slmax,len(s_code))
        code.append(s_code)
    l_c=len(code)
    if l_c!=len(list(set(code))):
        print(-1)
    else:
        flag=0
        for i in range(1,slmax+1):
            if flag==1:break
            c_code=[]
            for j in code:
                c_code.append(j[:i])
                if len(list(set(c_code)))==l_c:
                    print(i)
                    flag=1
                    break

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if n == 0:break
  def to_code(s):
    ret = s[0]
    flag = False
    for c in s:
      if flag:ret += c
      flag = c in "aiueo"
    return ret
  
  lst = [to_code(input()) for _ in range(n)]
  for k in range(51):
    used = {}
    for code in lst:
      if code[:k] in used:
        break
      used[code[:k]] = True
    else:
      print(k)
      break
  else:
    print(-1)

Submission status: Accepted

Solution code:
while 1:
    n = int(input())
    if n == 0:
        break

    ports = []
    for _ in range(n):
        tmp = list(input())
        port = tmp[0]
        for i in range(len(tmp)):
            if i != len(tmp) - 1 and tmp[i] in list("aiueo"):
                port += tmp[i+1]
        ports.append(port)

    for i in range(1, 51):
        ext = []
        for p in ports:
            tmp = p[:i]
            if tmp in ext:
                break
            else:
                ext.append(tmp)
        else:
            print(i)
            break
    else:
        print(-1)

Submission status: Accepted

Solution code:
# coding: utf-8
while 1:
    n=int(input())
    if n==0:
        break
    dic={}
    data=[]
    for i in range(n):
        data.append(input())
        data[i]=''.join([data[i][j] for j in range(len(data[i])) if j==0 or data[i][j-1] in 'aiueo'])
    l=0
    r=51
    while 1:
        mid=(l+r)//2
        st=set()
        for i in range(n):
            st.add(data[i][:mid])
        if len(st)==n:
            r=mid
        else:
            l=mid
        if (l+r)//2==mid:
            break
    print(r if r!=51 else -1)

Submission status: Runtime Error

Solution code:

def a2c(name):
	c = name[0]
	boin=['a','i','u','e','o']
	for b in name:
		if i, b in enumerate(boin[:-1]):
			c += name[i+1]
	
	return c

while True:
	n = int(raw_input())
	
	if n == 0:
		break
	
	names = []
	length = -1
	for i in xrange(n):
		tmp = a2c(raw_input())
		names.append(tmp)
		length = max(length, len(tmp))
	
	names = set(names)
	if len(names) != n:
		print -1
		continue
	
	for i in xrange(1, length):
		s = set([name[:i] for name in names])
		if len(set) == n:
			print i
			break

Submission status: Runtime Error

Solution code:
while 1:
    n = int(input())
    S = []
    for i in range(n):
        s = input()
        b = []
        for j in range(len(s)):
            if j < 1 or s[j-1] in "aiueo":
                b.append(s[j])
        S.append(b)
    ans = 0
    S.sort()
    for i in range(n-1):
        A = S[i]; B = S[i+1]
        if A == B:
            print(-1)
            break
        res = min(len(A), len(B))
        for j in range(res):
            if A[j] != B[j]:
                res = j
                break
        ans = max(ans, res+1)
    else:
        print(ans)