#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ random_device seed_gen; mt19937 engine(seed_gen()); int n; cin >> n; vector a(n); rep(i,0,n) cin >> a[i]; if (n <= 10){ vector p(n); iota(p.begin(),p.end(),1); vector mem(1<<19,vector(0)); do{ int r=0; rep(i,0,n)r^=a[i]+p[i]; if(mem[r].size()>0){ rep(i,0,n){ cout << mem[r][i] << ' '; } cout << '\n'; rep(i,0,n){ cout << p[i] << ' '; } cout << '\n'; return 0; } mem[r] = p; }while(next_permutation(p.begin(),p.end())); cout << -1 << '\n'; }else{ vector mem(1<<19,-1); vector p(n); iota(p.begin(), p.end(), 1); vector hash1(n); vector hash2(n); uniform_int_distribution dist(0,998244353); rep(i,0,n){ hash1[i] = dist(engine); hash2[i] = dist(engine); } mint now1=0,now2=0; int val=0; rep(i,0,n){ now1 += hash1[i]*p[i]; now2 += hash2[i]*p[i]; val ^= p[i] + a[i]; } mem[val]=0; vector> sousa; uniform_int_distribution dist2(0,n-1); set> st; int cnt = 0; while(true){ int u=dist2(engine); int v=dist2(engine); if(u==v)continue; now1 -= hash1[u]*p[u]; now2 -= hash2[u]*p[u]; now1 -= hash1[v]*p[v]; now2 -= hash2[v]*p[v]; now1 += hash1[u]*p[v]; now2 += hash2[u]*p[v]; now1 += hash1[v]*p[u]; now2 += hash2[v]*p[u]; val ^= p[u]+a[u]; val ^= p[v]+a[v]; val ^= p[u]+a[v]; val ^= p[v]+a[u]; sousa.push_back(pair(u,v)); swap(p[u],p[v]); if (st.find(pair(now1.val(),now2.val()))==st.end()){ swap(p[u],p[v]); sousa.pop_back(); now1 += hash1[u]*p[u]; now2 += hash2[u]*p[u]; now1 += hash1[v]*p[v]; now2 += hash2[v]*p[v]; now1 -= hash1[u]*p[v]; now2 -= hash2[u]*p[v]; now1 -= hash1[v]*p[u]; now2 -= hash2[v]*p[u]; val ^= p[u]+a[u]; val ^= p[v]+a[v]; val ^= p[u]+a[v]; val ^= p[v]+a[u]; continue; } cnt++; st.insert(pair(now1.val(),now2.val())); if (mem[val]==-1){ mem[val]=cnt; }else{ { vector q(n); iota(q.begin(),q.end(),1); rep(i,0,mem[val]){ auto[x,y] = sousa[i]; swap(q[x],q[y]); } rep(i,0,n){ cout << q[i] << ' '; } cout << '\n'; } { vector q(n); iota(q.begin(),q.end(),1); rep(i,0,cnt){ auto[x,y] = sousa[i]; swap(q[x],q[y]); } rep(i,0,n){ cout << q[i] << ' '; } cout << '\n'; } return 0; } } } }