Trie={}
def insert(Trie,s,n):
my_try=Trie
for i in range(n):
if(s[i] in my_try):
my_try=my_try[s[i]][0]
else:
my_try[s[i]]=[{},False]
if(i==n-1):
my_try[s[n-1]][1]=True
my_try=my_try[s[i]][0]
return(Trie)
def search(Trie,s,n):
my_try=Trie
for i in range(n):
if(s[i] not in my_try):
return(i)
else:
if(i==n-1):
if(my_try[s[n-1]][1]==True or my_try[s[n-1]][1]==False ):
return(-1)
my_try=my_try[s[i]][0]
t=int(input())
pos=[]
neg=[]
count=0
for i in range(t):
k=(input())
if(k[0]=="-"):
count=count+1
neg.append(k[1:])
else:
pos.append(k[1:])
if(count==0):
print(0)
elif(count==t):
print(1)
print('')
else:
output=[]
ans=0
for i in pos:
Trie=insert(Trie,i,len(i))
for i in neg:
val=search(Trie,i,len(i))
if(val==-1):
print(-1)
ans=-1
break
else:
output.append(i[:val+1])
if(ans>=0):
we=list(set(output))
we.sort()
print(len(we))
for q in we:
print(q)
VHJpZT17fQpkZWYgaW5zZXJ0KFRyaWUscyxuKToKCW15X3RyeT1UcmllCgkKCWZvciBpIGluIHJhbmdlKG4pOgoJCWlmKHNbaV0gaW4gbXlfdHJ5KToKCQkJbXlfdHJ5PW15X3RyeVtzW2ldXVswXQoJCWVsc2U6CgkJCW15X3RyeVtzW2ldXT1be30sRmFsc2VdCgkJCWlmKGk9PW4tMSk6CgkJCQlteV90cnlbc1tuLTFdXVsxXT1UcnVlCgkJCW15X3RyeT1teV90cnlbc1tpXV1bMF0KCXJldHVybihUcmllKQoJCmRlZiBzZWFyY2goVHJpZSxzLG4pOgoJbXlfdHJ5PVRyaWUKCWZvciBpIGluIHJhbmdlKG4pOgoJCWlmKHNbaV0gbm90IGluIG15X3RyeSk6CgkJCXJldHVybihpKQoJCWVsc2U6CgkJCWlmKGk9PW4tMSk6CgkJCQlpZihteV90cnlbc1tuLTFdXVsxXT09VHJ1ZSBvciBteV90cnlbc1tuLTFdXVsxXT09RmFsc2UgKToKCQkJCQlyZXR1cm4o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