def robot(command, obstacles, x, y):
xx = 0
yy = 0
tmp = []
for c in command:
if c == 'U':
yy += 1
if c == 'R':
xx += 1
tmp.append([xx, yy])
#print(tmp)
index, times= -1, -1
for i in range(len(tmp)):
tx, ty = tmp[i]
if (x-tx)%xx ==0 and (y-ty)%yy == 0 and (x-tx)//xx == (y-ty)//yy:
index, times = i, (x-tx)//xx
break
if index==-1:
return False
for ob in obstacles:
ox, oy = ob
oidx, otimes = -1, -1
for i in range(len(tmp)):
tx, ty = tmp[i]
if (ox - tx) % xx == 0 and (oy - ty)%yy == 0 and (ox - tx) // xx == (oy - ty) // yy:
oidx, otimes = i, (ox - tx) // xx
break
if oidx!=-1 and otimes!=-1 and (otimes<times or otimes==times and oidx<=index):
return False
return True
print(robot('URR', [[4, 2]],3,2))