import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto K1 = s[1] - 1; auto K2 = s[2] - 1; float offset = K1 < K2 ? K1 + 0.1 : K2 - 0.1; auto Q = readln.chomp.to!int; auto A = iota(Q).map!(_ => readln.split.map!(to!long).array).array; int[] events; alias PQ = BinaryHeap!(Array!(Tuple!(int, long)), "a[1] > b[1]"); auto pq1 = new PQ; auto pq2 = new PQ; foreach (i; 0..Q) pq1.insert(tuple(i, A[i][0])); long time = 0; while (!pq1.empty) { while (!pq2.empty && pq2.front[1] <= pq1.front[1]) { auto idx = pq2.front[0]; events ~= -(idx + 1); pq2.removeFront; } if (pq2.length < N) { auto idx = pq1.front[0]; auto t = pq1.front[1]; time = max(time, t); events ~= idx + 1; pq1.removeFront; pq2.insert(tuple(idx, time + A[idx][1])); } else { auto t = pq2.front[1]; while (!pq2.empty && pq2.front[1] == t) { auto idx = pq2.front[0]; time = max(time, t); events ~= -(idx + 1); pq2.removeFront; } } } auto seats = new bool[](N); alias SET = RedBlackTree!(int, (a,b)=>abs(a-offset) 0) { int a; if (!set1.empty) { a = set1.front; ans[idx] = a; seats[a] = true; set1.removeKey(a); set2.removeKey(a); } else { a = set2.front; ans[idx] = a; seats[a] = true; set2.removeKey(a); } if (a > 0 && !set1.equalRange(a-1).empty) { set1.removeKey(a-1); } if (a < N - 1 && !set1.equalRange(a+1).empty) { set1.removeKey(a+1); } } else { auto a = ans[idx]; seats[a] = false; set2.insert(a); if (both_empty(a)) set1.insert(a); if (a > 0 && !seats[a-1] && both_empty(a-1)) set1.insert(a-1); if (a < N - 1 && !seats[a+1] && both_empty(a+1)) set1.insert(a+1); } } ans.map!(i => i + 1).each!writeln; }