https://www.lanqiao.cn/courses/31016/learning/?id=1896464&compatibility=false
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
typedef vector<long long> VI;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define pb(i) push_back(i)
#define int long long
#define INF 0x3f3f3f3f
#define oz 998244353
#define endl '\n'
#define N 30
const int mod = 1e9 + 7;
int p[N], si[N];
int find(int x) {
if (x != p[x]) p[x] = find(p[x]);
return p[x];
}
//size[find(b)] += size[find(a)];
//p[find(a)] = find(b);
int n, m;
bool vis[N][N];
vector<PII> res;
int row[N], col[N]; //维护行列上箭的个数
int dx[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
void dfs(int u, int v) {
if (u == n && v == n) { // 递归结束
rep(i, 1, n)if (col[i])return ;
rep(i, 1, n)if (row[i])return ;
for (auto [a, b] : res) {
int x = (a - 1) * n + (b - 1);
cout << x << " ";
}
return ;
}
rep(i, 0, 3) {
int x = u + dx[i][0], y = dx[i][1] + v;
if (x < 1 || x > n || y < 1 || y > n || vis[x][y] || row[x] <= 0 || col[y] <= 0)continue; //我剪
res.push_back({x, y});
row[x] --;
col[y] --;
vis[x][y] = true;
dfs(x, y);
res.pop_back();
row[x] ++;
col[y] ++;
vis[x][y] =false;
}
}
void solve() {
cin >> n;
rep(i, 1, n)cin >> col[i];
rep(i, 1, n)cin >> row[i];
res.push_back({1, 1});
col[1] --;
row[1] --;
vis[1][1] = true;
dfs(1, 1);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
solve();
return 0;
}