#include using namespace std; map SeatToIdx; map IdxToSeat; int main() { int n, k1, k2; cin >> n >> k1 >> k2; vector> v(n); for(int i = 1; i <= n; ++i) { if(k1 < k2) { if(i <= k1) { v[i - 1] = make_tuple(abs(k1 - i), 1, i); } else { v[i - 1] = make_tuple(abs(k1 - i), 0, i); } } else { if(k1 <= i) { v[i - 1] = make_tuple(abs(k1 - i), 1, i); } else { v[i - 1] = make_tuple(abs(k1 - i), 0, i); } } } sort(v.begin(), v.end()); for(int i = 0; i < n; ++i) { int _, __, seat; tie(_, __, seat) = v[i]; SeatToIdx[seat] = i + 1; IdxToSeat[i + 1] = seat; } set ok; set notUsed; for(int i = 1; i <= n; ++i) ok.insert(i); for(int i = 1; i <= n; ++i) notUsed.insert(i); priority_queue, vector>, greater>> pq; int q; cin >> q; while(q--) { int64_t a, b; cin >> a >> b; while(pq.size()) { int64_t t, idx; tie(t, idx) = pq.top(); if(t > a) { if(ok.empty()) { if(notUsed.empty()) { a = t; continue; } } break; } pq.pop(); int seat = IdxToSeat[idx]; bool left = true, right = true; if(SeatToIdx[seat - 1] != 0 and notUsed.find(SeatToIdx[seat - 1]) == notUsed.end()) { left = false; } if(SeatToIdx[seat + 1] != 0 and notUsed.find(SeatToIdx[seat + 1]) == notUsed.end()) { right = false; } if(left and right) { ok.insert(idx); } notUsed.insert(idx); if(SeatToIdx[seat - 1] != 0 and notUsed.find(SeatToIdx[seat - 1]) != notUsed.end()) { if(SeatToIdx[seat - 2] != 0 and notUsed.find(SeatToIdx[seat - 2]) != notUsed.end()) { ok.insert(SeatToIdx[seat - 1]); } else if(SeatToIdx[seat - 2] == 0) { ok.insert(SeatToIdx[seat - 1]); } } if(SeatToIdx[seat + 1] != 0 and notUsed.find(SeatToIdx[seat + 1]) != notUsed.end()) { if(SeatToIdx[seat + 2] != 0 and notUsed.find(SeatToIdx[seat + 2]) != notUsed.end()) { ok.insert(SeatToIdx[seat + 1]); } else if(SeatToIdx[seat + 2] == 0) { ok.insert(SeatToIdx[seat + 1]); } } } // cout << "OK" << '\n'; // for(int i : ok) { // cout << i << " "; // } // cout << '\n' << "Not Used" << '\n'; // for(int i : notUsed) { // cout << i << " "; // } // cout << '\n'; int idx, seat; if(ok.size()) { idx = *ok.begin(); seat = IdxToSeat[idx]; } else { idx = *notUsed.begin(); seat = IdxToSeat[idx]; } ok.erase(idx); notUsed.erase(idx); if(seat + 1 <= n) ok.erase(SeatToIdx[seat + 1]); if(seat - 1 >= 1) ok.erase(SeatToIdx[seat - 1]); pq.emplace(a + b, idx); cout << seat << '\n'; // cout << '\n'; } return 0; }