'''
Validator for PPCG challenge.
Provide input and output filenames as arguments or input and output as stdin (2 lines input and then 1line output).
'''
import sys
if len(sys.argv)==3:
with open(sys.argv[1]) as f:
si=f.readline().rstrip()
so=f.readline().rstrip()
with open(sys.argv[2]) as f:
moves=f.readline().rstrip()
else:
si=input()
so=input()
moves=input()
if sorted(si)!=sorted(so):
print('incompatible start and goal strings')
exit()
d={'u':(0,-1),'d':(0,1),'l':(-1,0),'r':(1,0)}
p=[]
for i in range(len(si)):
p+=[(i,0)]
for i,move in enumerate(moves.split()):
try:
poss,dir=move.split(':')
pos=int(poss)
p[pos]=tuple(a+b for a,b in zip(p[pos],d[dir]))
if len(set(p))<len(si):
print('letters at the same position at move',i+1)
exit()
except:
print('format error at move',i+1)
exit()
step_count=i+1
r=set()
for i,pe in enumerate(p):
if pe[1]==0 and 0<=pe[0]<len(so) and si[i]==so[pe[0]]:
r.add(pe[0])
else:
print('goal string not reached')
exit()
if len(r)!=len(so):
print('goal string not reached')
else:
print('move sequence verified with step count',step_count)
JycnClZhbGlkYXRvciBmb3IgUFBDRyBjaGFsbGVuZ2UuCgpQcm92aWRlIGlucHV0IGFuZCBvdXRwdXQgZmlsZW5hbWVzIGFzIGFyZ3VtZW50cyBvciBpbnB1dCBhbmQgb3V0cHV0IGFzIHN0ZGluICgyIGxpbmVzIGlucHV0IGFuZCB0aGVuIDFsaW5lIG91dHB1dCkuCicnJwppbXBvcnQgc3lzCgppZiBsZW4oc3lzLmFyZ3YpPT0zOgogICAgd2l0aCBvcGVuKHN5cy5hcmd2WzFdKSBhcyBmOgogICAgICAgIHNpPWYucmVhZGxpbmUoKS5yc3RyaXAoKQogICAgICAgIHNvPWYucmVhZGxpbmUoKS5yc3RyaXAoKQogICAgd2l0aCBvcGVuKHN5cy5hcmd2WzJdKSBhcyBmOgogICAgICAgIG1vdmVzPWYucmVhZGxpbmUoKS5yc3RyaXAoKQplbHNlOgogICAgc2k9aW5wdXQoKQogICAgc289aW5wdXQoKQogICAgbW92ZXM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