#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
const int SIZE = 10000; // Cədvəlin ölçüsü (10^4 x 10^4)
long long N;
cin >> N;
// N-ə uyğun koordinatları tapırıq
long long row = (N - 1) / SIZE; // Sətir nömrəsi (0-dan başlayır)
long long col = (N - 1) % SIZE; // Sütun nömrəsi (0-dan başlayır)
// Qonşu damaların koordinatlarını təyin edirik
vector<long long> neighbors;
// Yuxarıdakı dama
if (row > 0)
neighbors.push_back((row - 1) * SIZE + col + 1);
// Aşağıdakı dama
if (row < SIZE - 1)
neighbors.push_back((row + 1) * SIZE + col + 1);
// Soldakı dama
if (col > 0)
neighbors.push_back(row * SIZE + (col - 1) + 1);
// Sağdakı dama
if (col < SIZE - 1)
neighbors.push_back(row * SIZE + (col + 1) + 1);
// Qonşuları artma sırası ilə çap edirik
sort(neighbors.begin(), neighbors.end());
for (long long neighbor : neighbors) {
cout << neighbor << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgY29uc3QgaW50IFNJWkUgPSAxMDAwMDsgLy8gQ8mZZHbJmWxpbiDDtmzDp8O8c8O8ICgxMF40IHggMTBeNCkKICAgIGxvbmcgbG9uZyBOOwogICAgY2luID4+IE47CgogICAgLy8gTi3JmSB1ecSfdW4ga29vcmRpbmF0bGFyxLEgdGFwxLFyxLFxCiAgICBsb25nIGxvbmcgcm93ID0gKE4gLSAxKSAvIFNJWkU7ICAvLyBTyZl0aXIgbsO2bXLJmXNpICgwLWRhbiBiYcWfbGF5xLFyKQogICAgbG9uZyBsb25nIGNvbCA9IChOIC0gMSkgJSBTSVpFOyAvLyBTw7x0dW4gbsO2bXLJmXNpICgwLWRhbiBiYcWfbGF5xLFyKQoKICAgIC8vIFFvbsWfdSBkYW1hbGFyxLFuIGtvb3JkaW5hdGx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