#include<bits/stdc++.h> // #define SINGLE_INPUT #define ll long long #define ull unsigned long long #define N 500005 #define MOD 998244353 usingnamespace std;
random_device seed; ranlux48 engine(seed()); intrandom(int l, int r){ uniform_int_distribution<> distrib(l, r); returndistrib(engine); } template<classt,classu> ostream& operator<<(ostream& os,const pair<t,u>& p) { return os<<'['<<p.first<<", "<<p.second<<']'; } template<classt> ostream& operator<<(ostream& os,const vector<t>& v) { os<<'['; int s = 1; for(auto e:v) { if (s) s = 0; else os << ", "; os << e; } return os<<']'; } template<classt,classu> ostream& operator<<(ostream& os,const map<t,u>& mp){ os<<'{'; int s = 1; for(auto [x,y]:mp) { if (s) s = 0; else os << ", "; os<<x<<": "<<y; } return os<<'}'; }
voidsol(){ int n; cin >> n; vector<int> a(n), c(n+1); for (int& i:a) cin >> i; vector<vector<int>> g(n+1); for (int i=0; i<n; i++) { g[++c[a[i]]].push_back(i); } vector<int> b(n); for (auto& i:g) { int sz = i.size(); sort(i.begin(), i.end(), [&](int x, int y) { return a[x] < a[y]; }); // cout << i << endl; for (int j=0; j<sz; j++) { b[i[(j+sz-1)%sz]] = a[i[j]]; // cout << j << ": " << i[j] << ", " << a[i[j]] << endl; } } // cout << g << endl; // cout << b << endl; for (int i:b) { cout << i << " "; } cout << "\n"; }