#include #include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, prv; cin >> n; vector idx(n, -1); vector> tb; int xp = -1, yp = -1; for(int i = 0; i < n; i++){ int x, y; cin >> x >> y; if(xp != -1) idx[i] = idx[xp]; if(x == 1) xp = i; else xp = -1; if(y == 2) yp = i; else if(y == 1) idx[i] = idx[yp]; if(idx[i] == -1){ idx[i] = tb.size(); tb.emplace_back(vector({})); } tb[idx[i]].emplace_back(i + 1); } for(auto &&vec : tb) reverse(vec.begin(), vec.end()); sort(tb.begin(), tb.end()); for(auto &&vec : tb) for(auto &&v : vec) cout << v << '\n'; }