#include #include #include #include #include #include #include using namespace std; using namespace atcoder; using ll = long long; using mint = modint998244353; using vi = vector; using vvi = vector; using vvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vmi = vector; using vvmi = vector; using vvvmi = vector; #define all(a) (a).begin(), (a).end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) using p = pair; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; vector

vp(n); vi v1, v2; rep(i, n){ int a, b; cin >> a >> b; vp[i] = {a, b}; if(b == 1){ v1.push_back(i+1); }else if(b == 2){ v2.push_back(i+1); } } map mp; rep(i, v2.size()){ mp[v2[i]] = v1[i]; } stack

st; queue q; rep(i, n){ auto [a, b] = vp[i]; if(a != 1 && b != 2){ q.push(i+1); }else if(a == 1){ st.push({0, i+1}); }else{ st.push({1, i+1}); } if(q.empty())continue; while(!st.empty()){ auto [c, d] = st.top(); if(c == 0){ if(q.back() == d+1){ q.push(d); st.pop(); }else{ break; } }else{ if(q.back() == mp[d]){ q.push(d); st.pop(); }else{ break; } } } } while(!q.empty()){ cout << q.front() << endl; q.pop(); } return 0; }