import sys
from collections import deque
def solve():
try:
input_data = sys.stdin.read().split()
if len(input_data) >= 3:
N = int(input_data[0])
start_pos = input_data[1]
end_pos = input_data[2]
else:
N = 8
start_pos = "a1"
end_pos = "d4"
except:
N = 8
start_pos = "a1"
end_pos = "d4"
def parse(pos):
c = ord(pos[0]) - ord('a')
r = int(pos[1:]) - 1
return r, c
def stringify(r, c):
return f"{chr(c + ord('a'))}{r + 1}"
sx, sy = parse(start_pos)
ex, ey = parse(end_pos)
moves = [
(2, 1), (2, -1), (-2, 1), (-2, -1),
(1, 2), (1, -2), (-1, 2), (-1, -2)
]
dist = [[-1] * N for _ in range(N)]
dist[sx][sy] = 0
queue = deque([(sx, sy)])
while queue:
x, y = queue.popleft()
if x == ex and y == ey:
break
for dx, dy in moves:
nx, ny = x + dx, y + dy
if 0 <= nx < N and 0 <= ny < N and dist[nx][ny] == -1:
dist[nx][ny] = dist[x][y] + 1
queue.append((nx, ny))
if dist[ex][ey] == -1:
print("Шляху немає")
return
paths = []
def backtrack(cx, cy, current_path):
if cx == sx and cy == sy:
paths.append(current_path[::-1])
return
d = dist[cx][cy]
for dx, dy in moves:
px, py = cx - dx, cy - dy
if 0 <= px < N and 0 <= py < N:
if dist[px][py] == d - 1:
backtrack(px, py, current_path + [stringify(px, py)])
backtrack(ex, ey, [stringify(ex, ey)])
paths.sort()
print(f"Мінімальна кількість ходів: {dist[ex][ey]}")
print(f"Кількість варіантів: {len(paths)}")
for p in paths:
print(" - ".join(p))
if __name__ == "__main__":
solve()
aW1wb3J0IHN5cwpmcm9tIGNvbGxlY3Rpb25zIGltcG9ydCBkZXF1ZQoKZGVmIHNvbHZlKCk6CiAgICB0cnk6CiAgICAgICAgaW5wdXRfZGF0YSA9IHN5cy5zdGRpbi5yZWFkKCkuc3BsaXQoKQogICAgICAgIGlmIGxlbihpbnB1dF9kYXRhKSA+PSAzOgogICAgICAgICAgICBOID0gaW50KGlucHV0X2RhdGFbMF0pCiAgICAgICAgICAgIHN0YXJ0X3BvcyA9IGlucHV0X2RhdGFbMV0KICAgICAgICAgICAgZW5kX3BvcyA9IGlucHV0X2RhdGFbMl0KICAgICAgICBlbHNlOgogICAgICAgICAgICBOID0gOAogICAgICAgICAgICBzdGFydF9wb3MgPSAiYTEiCiAgICAgICAgICAgIGVuZF9wb3MgPSAiZDQiCiAgICBleGNlcHQ6CiAgICAgICAgTiA9IDgKICAgICAgICBzdGFydF9wb3MgPSAiYTEiCiAgICAgICAgZW5kX3BvcyA9ICJkNCIKCiAgICBkZWYgcGFyc2UocG9zKToKICAgICAgICBjID0gb3JkKHBvc1swXSkgLSBvcmQoJ2EnKQogICAgICAgIHIgPSBpbnQocG9zWzE6XSkgLSAxCiAgICAgICAgcmV0dXJuIHIsIGMKCiAgICBkZWYgc3RyaW5naWZ5KHIsIGMpOgogICAgICAgIHJldHVybiBmIntjaHIoYyArIG9yZCgnYScpKX17ciArIDF9IgoKICAgIHN4LCBzeSA9IHBhcnNlKHN0YXJ0X3BvcykKICAgIGV4LCBleSA9IHBhcnNlKGVuZF9wb3MpCgogICAgbW92ZXMgPSBbCiAgICAgICAgKDIsIDEpLCAoMiwgLTEpLCAoLTIsIDEpLCAoLTIsIC0xKSwKICAgICAgICAoMSwgMiksICgxLCAtMiksICgtMSwgMiksICgtMSwgLTIpCiAgICBdCgogICAgZGlzdCA9IFtbLTFdICogTiBmb3IgXyBpbiByYW5nZShOKV0KICAgIGRpc3Rbc3hdW3N5XSA9IDAKICAgIAogICAgcXVldWUgPSBkZXF1ZShbKHN4LCBzeSldKQogICAgCiAgICB3aGlsZSBxdWV1ZToKICAgICAgICB4LCB5ID0gcXVldWUucG9wbGVmdCgpCiAgICAgICAgaWYgeCA9PSBleCBhbmQgeSA9PSBleToKICAgICAgICAgICAgYnJlYWsKICAgICAgICAKICAgICAgICBmb3IgZHgsIGR5IGluIG1vdmVzOgogICAgICAgICAgICBueCwgbnkgPSB4ICsgZHgsIHkgKyBkeQogICAgICAgICAgICBpZiAwIDw9IG54IDwgTiBhbmQgMCA8PSBueSA8IE4gYW5kIGRpc3RbbnhdW255XSA9PSAtMToKICAgICAgICAgICAgICAgIGRpc3RbbnhdW255XSA9IGRpc3RbeF1beV0gKyAxCiAgICAgICAgICAgICAgICBxdWV1ZS5hcHBlbmQoKG54LCBueSkpCgogICAgaWYgZGlzdFtleF1bZXldID09IC0xOgogICAgICAgIHByaW50KCLQqNC70Y/RhdGDINC90LXQvNCw0ZQiKQogICAgICAgIHJldHVybgoKICAgIHBhdGhzID0gW10KCiAgICBkZWYgYmFja3RyYWNrKGN4LCBjeSwgY3VycmVudF9wYXRoKToKICAgICAgICBpZiBjeCA9PSBzeCBhbmQgY3kgPT0gc3k6CiAgICAgICAgICAgIHBhdGhzLmFwcGVuZChjdXJyZW50X3BhdGhbOjotMV0pCiAgICAgICAgICAgIHJldHVybgoKICAgICAgICBkID0gZGlzdFtjeF1bY3ldCiAgICAgICAgCiAgICAgICAgZm9yIGR4LCBkeSBpbiBtb3ZlczoKICAgICAgICAgICAgcHgsIHB5ID0gY3ggLSBkeCwgY3kgLSBkeQogICAgICAgICAgICBpZiAwIDw9IHB4IDwgTiBhbmQgMCA8PSBweSA8IE46CiAgICAgICAgICAgICAgICBpZiBkaXN0W3B4XVtweV0gPT0gZCAtIDE6CiAgICAgICAgICAgICAgICAgICAgYmFja3RyYWNrKHB4LCBweSwgY3VycmVudF9wYXRoICsgW3N0cmluZ2lmeShweCwgcHkpXSkKCiAgICBiYWNrdHJhY2soZXgsIGV5LCBbc3RyaW5naWZ5KGV4LCBleSldKQogICAgCiAgICBwYXRocy5zb3J0KCkKCiAgICBwcmludChmItCc0ZbQvdGW0LzQsNC70YzQvdCwINC60ZbQu9GM0LrRltGB0YLRjCDRhdC+0LTRltCyOiB7ZGlzdFtleF1bZXldfSIpCiAgICBwcmludChmItCa0ZbQu9GM0LrRltGB0YLRjCDQstCw0YDRltCw0L3RgtGW0LI6IHtsZW4ocGF0aHMpfSIpCiAgICBmb3IgcCBpbiBwYXRoczoKICAgICAgICBwcmludCgiIC0gIi5qb2luKHApKQoKaWYgX19uYW1lX18gPT0gIl9fbWFpbl9fIjoKICAgIHNvbHZlKCk=