# UUID: 091a6b5b-d40d-496e-9c90-6617ac49fa8a
def dfshossz(hely):
for i in graf[hely][1]:
dfshossz(i[1])
graf[graf[hely][2]][0]=max(graf[graf[hely][2]][0],graf[hely][0]+1)
graf[hely][1].sort(key= lambda x:x[1],reverse=True)
def dfs(hely):
for j in range(graf[hely][3]):
ki.append("P")
for i in graf[hely][1]:
ki.append(i[0])
dfs(i[1])
ki.append("-")
n=int(input())
l=[]
for i in range(n):
l.append(input())
#print(l)
graf=[]
graf=[[0,[],0,0]]
for i in l:
hely=0
for ch in i:
talalt=False
for j in graf[hely][1]:
#print(j)
if j[0]==ch:
hely=j[1]
talalt=True
break
if not talalt:
graf[hely][1].append([ch,len(graf)])
graf.append([0,[],hely,0])
hely=len(graf)-1
graf[hely][3]+=1
dfshossz(0)
#print(graf)
ki=[]
dfs(0)
while True:
if ki[-1]=="-":
ki.pop()
else:
break
#print(ki)
print(len(ki))
for i in ki:
print(i)
"""
ki=[]
stack=[]
for i in l:
hely=0
for j in i:
if len(stack)==hely:
break
elif stack[hely]!=j:
break
hely+=1
if len(stack)>hely:
while True:
kidob=len(stack)
if kidob==hely:
break
ki.append("-")
stack.pop()
hely=0
for j in i:
if len(stack)==hely:
ki.append(j)
stack.append(j)
hely+=1
ki.append("P")
print(len(ki))
for i in ki:
print(i)
"""
Compilation message (stdout)
Compiling 'printer.py'...
=======
adding: __main__.pyc (deflated 42%)
=======
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |