#include <stdio.h>
#define MAX 20
void printSpiralMatrix(int n) {
int matrix[MAX][MAX];
int left = 0, right = n - 1, top = 0, bottom = n - 1;
int value = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = 0;
}
}
while (value <= n * n) {
for (int i = left; i <= right; i++) {
matrix[top][i] = value++;
}
top++;
for (int i = top; i <= bottom; i++) {
matrix[i][right] = value++;
}
right--;
if (top <= bottom) {
for (int i = right; i >= left; i--) {
matrix[bottom][i] = value++;
}
bottom--;
}
if (left <= right) {
for (int i = bottom; i >= top; i--) {
matrix[i][left] = value++;
}
left++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
}
}
}
int main() {
int n;
if (n > 0 && n <= 20) {
printSpiralMatrix(n);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIE1BWCAyMAoKdm9pZCBwcmludFNwaXJhbE1hdHJpeChpbnQgbikgewogICAgaW50IG1hdHJpeFtNQVhdW01BWF07CiAgICBpbnQgbGVmdCA9IDAsIHJpZ2h0ID0gbiAtIDEsIHRvcCA9IDAsIGJvdHRvbSA9IG4gLSAxOwogICAgaW50IHZhbHVlID0gMTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbjsgaisrKSB7CiAgICAgICAgICAgIG1hdHJpeFtpXVtqXSA9IDA7CiAgICAgICAgfQogICAgfQoKICAgIHdoaWxlICh2YWx1ZSA8PSBuICogbikgewogICAgICAgIGZvciAoaW50IGkgPSBsZWZ0OyBpIDw9IHJpZ2h0OyBpKyspIHsKICAgICAgICAgICAgbWF0cml4W3RvcF1baV0gPSB2YWx1ZSsrOwogICAgICAgIH0KICAgICAgICB0b3ArKzsKCiAgICAgICAgZm9yIChpbnQgaSA9IHRvcDsgaSA8PSBib3R0b207IGkrKykgewogICAgICAgICAgICBtYXRyaXhbaV1bcmlnaHRdID0gdmFsdWUrKzsKICAgICAgICB9CiAgICAgICAgcmlnaHQtLTsKCiAgICAgICAgaWYgKHRvcCA8PSBib3R0b20pIHsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IHJpZ2h0OyBpID49IGxlZnQ7IGktLSkgewogICAgICAgICAgICAgICAgbWF0cml4W2JvdHRvbV1baV0gPSB2YWx1ZSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJvdHRvbS0tOwogICAgICAgIH0KCiAgICAgICAgaWYgKGxlZnQgPD0gcmlnaHQpIHsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IGJvdHRvbTsgaSA+PSB0b3A7IGktLSkgewogICAgICAgICAgICAgICAgbWF0cml4W2ldW2xlZnRdID0gdmFsdWUrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZWZ0Kys7CiAgICAgICAgfQogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBuOyBqKyspIHsKICAgICAgICAgICAgcHJpbnRmKCIlZCAiLCBtYXRyaXhbaV1bal0pOwogICAgICAgIH0KICAgICAgICBwcmludGYoIlxuIik7CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgaW50IG47CiAgICBzY2FuZigiJWQiLCAmbik7CgogICAgaWYgKG4gPiAwICYmIG4gPD0gMjApIHsKICAgICAgICBwcmludFNwaXJhbE1hdHJpeChuKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=