while True:
print_map(m)
dx, dy = dirs[cd]
nx, ny = x + dx, y + dy
c = m[ny][nx]
if c == chars[cd] or c == '\\':
cd = (cd + (c == '\\')) % 2
m[y][x], m[ny][nx], lc, x, y = lc, '$', c, nx, ny
path.append((y - 1, x - 1))
else:
break
input()
print(path)