#include <bits/stdc++.h>
#include "interactive.h"
#define For(i, x, y) for (int i = (x); i <= (y); i++)
#define pb push_back
using namespace std;
using vi = vector<int>;
const int N = 505;
int n;
bool e[N][N];
int query3(int x, int y, int z) {
vi q = {x, y, z};
For (i, 1, n) if (i != x && i != y && i != z) q.pb(i);
return query(q);
}
void calc(int x, int y, int z) {
int v1 = query3(x, y, z), v2 = query3(y, x, z);
if (v1 > v2) {
e[y][z] = e[z][y] = 1;
int v3 = query3(x, z, y), v4 = query3(z, x, y);
if (v3 == v4) e[x][y] = e[y][x] = 1;
return;
}
if (v1 < v2) {
e[x][z] = e[z][x] = 1;
int v3 = query3(y, z, x), v4 = query3(z, y, x);
if (v3 == v4) e[x][y] = e[y][x] = 1;
return;
}
if (v1 == v2) {
int v3 = query3(y, z, x), v4 = query3(z, y, x);
if (v3 < v4) e[x][y] = e[y][x] = 1;
if (v3 > v4) e[x][z] = e[z][x] = e[y][z] = e[z][y] = 1;
return;
}
return;
}
vi ans;
void dfs(int x, int fa) {
ans.pb(x);
For (y, 1, n) if (y != fa && a[x][y]) dfs(y, x);
return;
}
bool used[N];
int work(int d, int l, int r) {
vi q;
For (i, 2, l - 1) q.pb(i);
for (int i = 0; i < d && l + i <= r; i++) {
int p = l + i;
if (i & 1) {
while (p <= r && p + d <= n) p += d;
while (p >= l) q.pb(p), p -= d;
} else {
while (p <= r + d && p <= n) q.pb(p), p += d;
}
}
mem(used, 0);
for (int x : q) used[x] = 1;
rep (i, min(n, l + d - 1), 1) if (!used[i]) q.pb(i), used[i] = 1;
For (i, r + 1, n) if (!used[i]) q.pb(i);
int res = query(q);
For (i, 0, n - 2) res -= e[q[i]][q[i + 1]];
return res;
}
void solve(int d, int l, int r, int res) {
if (!res) return;
if (l == r) return e[l][l + d] = e[l + d][l] = 1, void();
int mid = (l + r) >> 1, resl = work(d, l, mid);
solve(d, l, mid, resl); solve(d, mid + 1, r, res - resl);
return;
}
vi solve(int m) {
n = m;
For (i, 2, n - 1) calc(1, i, i + 1);
For (d, 2, n - 2) solve(d, 2, n - d, work(d, 2, n - d));
For (i, 1, n) {
int cnt = 0;
For (j, 1, n) cnt += a[i][j];
if (cnt == 1) {
dfs(i, 0);
break
}
}
return ans;
}