O='P'
N=dict
M=input
K=range
H=print
D=len
L=int(M())
def I(a,b):
A=0
for B in K(min(D(a),D(b))):
if a[B]==b[B]:A+=1
else:break
return A
F=N()
for A in K(L):F[M()]=0
J=''
for A in F:
if D(A)>D(J):J=A
P=N()
for A in F:F[A]=I(A,J)
B=[A for A in F]
B.sort(key=lambda x:(F[x],x))
G=1
C=[]
for A in K(D(B)-1):
for E in B[A][D(C):]:C.append(E);G+=1
G+=1
for A in B[A][I(B[A],B[A+1]):][::-1]:G+=1;C.pop()
for E in B[-1][D(C):]:G+=1
H(G)
C=[]
for A in K(D(B)-1):
for E in B[A][D(C):]:C.append(E);H(E)
H(O)
for A in B[A][I(B[A],B[A+1]):][::-1]:H('-');C.pop()
for E in B[-1][D(C):]:H(E)
H(O)
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
18228 KB |
Output is correct |
2 |
Correct |
34 ms |
18196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
18216 KB |
Output is correct |
2 |
Correct |
49 ms |
18180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
18252 KB |
Output is correct |
2 |
Correct |
37 ms |
18212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
18260 KB |
Output is correct |
2 |
Correct |
38 ms |
18216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
19500 KB |
Output is correct |
2 |
Correct |
120 ms |
25440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
26160 KB |
Output is correct |
2 |
Correct |
134 ms |
26536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
234 ms |
27684 KB |
Output is correct |
2 |
Correct |
226 ms |
28524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
241 ms |
28012 KB |
Output is correct |
2 |
Correct |
240 ms |
27688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
426 ms |
28960 KB |
Output is correct |
2 |
Correct |
590 ms |
29736 KB |
Output is correct |
3 |
Correct |
428 ms |
30064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
452 ms |
30300 KB |
Output is correct |
2 |
Correct |
648 ms |
31832 KB |
Output is correct |
3 |
Correct |
455 ms |
31144 KB |
Output is correct |
4 |
Correct |
534 ms |
31672 KB |
Output is correct |