#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>n; vector a(n); for(Int i=0;i>a[i]; vector > ds(n); for(Int i=0;i > vs(MAX); auto add=[&](Int i){ for(Int x:ds[i]) vs[x].emplace(a[i]); }; auto rmv=[&](Int i){ for(Int x:ds[i]) vs[x].erase(vs[x].find(a[i])); }; for(Int i=1;i rev; for(Int i=0;i b(n); b[0]=a[0]; for(Int i=0;i+1k/__gcd(cur,k)) nxt=k; if(nxt/__gcd(cur,nxt)==k/__gcd(cur,k)&&nxt>k) nxt=k; } b[i+1]=nxt; rmv(rev[nxt]); } for(Int i=0;i