#include <iostream>
using namespace std;
const int MAX_SIZE = 50;
int main() {
int mtSize, windLine[MAX_SIZE + 1][MAX_SIZE + 1];
cin >> mtSize;
for (int line = 1; line <= mtSize; ++line) {
for (int col = 1; col <= mtSize; ++col) {
cin >> windLine[line][col];
}
}
int direction = 0; // 0: right, 1: down-left, 2: down, 3: up-right
for (int linePos = 1, colPos = 1; linePos <= mtSize && colPos <= mtSize;) {
cout << windLine[linePos][colPos] << " ";
if (direction == 0) { // right
if ((linePos + colPos) % 2 == 0 && colPos == mtSize) {
direction = 2; // change to down
} else if ((linePos + colPos) % 2 != 0) {
direction = 1; // change to down-left
}
} else if (direction == 1) { // down-left
if (linePos == mtSize || colPos == 1) {
direction = (linePos == mtSize) ? 3 : 0; // change to up-right or right
}
} else if (direction == 2) { // down
if ((linePos + colPos) % 2 == 0 && linePos == mtSize) {
direction = 3; // change to up-right
} else if ((linePos + colPos) % 2 != 0) {
direction = 1; // change to down-left
}
} else if (direction == 3) { // up-right
if (linePos == 1 || colPos == mtSize) {
direction = (colPos == mtSize) ? 2 : 0; // change to down or right
}
}
if (direction == 0) { colPos++; }
else if (direction == 1) { linePos++; colPos--; }
else if (direction == 2) { linePos++; }
else if (direction == 3) { linePos--; colPos++; }
}
return 0;
}