PivotOJ

Fair Share

시간 제한: 3000ms메모리 제한: 2048MB출처: NWERC 2025BOJ 35077

문제

Your university's teams are celebrating an outstanding performance at this year's NWERC in Karlsruhe. After a delicious dinner at a local restaurant, you call it a day. The trip home tomorrow will be a long one.

While trying to pay the bill, your group realizes that the restaurant takes no cash. Furthermore, it is too late to split the bill. Caught off-guard, everybody starts to open their wallets and puts some cash on the table. Someone has to pay the bill with their credit card and take the cash.

Each person ii spent €bib_i during the evening but has €aia_i in cash to contribute to the group payment (if someone else pays). To keep it fair, the group does not want the person who pays the final bill (and takes the money from the cash pool) to end up paying more than their individual share. Thus, if person ii is the one paying, then the remainder of the bill, after accounting for the cash contributions of the others, should not be more than their own share €bib_i of the bill.

Help the group determine who should pay the final bill.

입력

The input consists of:

  • One line with an integer nn (2n1052 \leq n \leq 10^5), the size of your dinner group.
  • nn lines, the iith of which contains two integers aia_i and bib_i (1ai,bi10001 \leq a_i, b_i \leq 1000), the amount of cash person ii would contribute if someone else pays and their share of the bill, respectively.

출력

If there is no suitable person to settle the bill, output "impossible". Otherwise, output one integer ii (1in1 \leq i \leq n), the index of the person settling the bill.

If there are multiple valid solutions, you may output any one of them.

예제

예제 1

입력
3
4 3
5 4
1 3
출력
3

예제 2

입력
5
1 4
8 1
1 4
2 5
4 6
출력
impossible

예제 3

입력
8
4 3
5 8
7 2
1 9
6 3
2 6
5 7
8 6
출력
4
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.