#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector already(N); vector P(N),rev(N),answer,fro(N,-1),bac(N,-1); for(int i=0; i> p; p--; rev.at(p) = i; P.at(i) = p; } for(int i=1; i