#include #include #include #include using namespace std; int main() { int n; cin >> n; int x1, y1; int x2, y2; cin >> x1 >> y1 >> x2 >> y2; x1--; y1--; x2--; y2--; vector colors(n*n); vector length(n*n); vector> graph(n*n); vector parents(n*n); for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { for (int i = -2; i <= 2; i++) { for (int j = -2; j <= 2; j++) { if (abs(i) + abs(j) != 3) { continue; } int xt = x + i; int yt = y + j; if (xt < 0 || xt >= n) { continue; } if (yt < 0 || yt >= n) { continue; } graph[y*n + x].push_back(yt*n + xt); } } } } queue q; int s = y2*n + x2; colors[s] = 1; q.push(s); parents[s] = s; while (!q.empty()) { int k = q.front(); q.pop(); for (int t : graph[k]) { if (colors[t] == 0) { colors[t] = 1; q.push(t); parents[t] = k; length[t] = length[k] + 1; } } } cout << length[y1*n + x1] << '\n'; int t = y1*n + x1; while (t != s) { int x, y; x = t % n; y = t / n; cout << x + 1 << ' ' << y + 1 << '\n'; t = parents[t]; } cout << x2 + 1 << ' ' << y2 + 1; return 0; }