template void sort_idx_proto(const ITER begin, const ITER end, const ITER2 idxbegin, const ITER2 idxend){//, vector &idxr) { size_t n = end - begin; for (auto i = idxbegin; i != idxend; ++i) *i = i-idxbegin; sort(idxbegin, idxend, [&begin](int l, int r) {return begin[l] < begin[r]; }); } ll n; ll aa[10010]; ll bb[10010]; ll gg[10010]; ll v[10010]; { rd(n, aa(n)); //vector v(n); rep(i, n){ rep(j, i+1, n) gg[j] = gcd(aa[i],aa[j]); sort_idx_proto(gg+i, gg+n, v+i, v+n); rep(j, i+1, n){ bb[j] = aa[v[j]]; } rep(j, i+1, n){ aa[j] = bb[j]; } } wt(aa(n)); }