CF733B.Parade

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.

There will be nn columns participating in the parade, the ii -th column consists of lil_{i} soldiers, who start to march from left leg, and rir_{i} soldiers, who start to march from right leg.

The beauty of the parade is calculated by the following formula: if LL is the total number of soldiers on the parade who start to march from the left leg, and RR is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal LR|L-R| .

No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index ii and swap values lil_{i} and rir_{i} .

Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.

输入格式

The first line contains single integer nn ( 1<=n<=1051<=n<=10^{5} ) — the number of columns.

The next nn lines contain the pairs of integers lil_{i} and rir_{i} ( 1<=li,ri<=5001<=l_{i},r_{i}<=500 ) — the number of soldiers in the ii -th column which start to march from the left or the right leg respectively.

输出格式

Print single integer kk — the number of the column in which soldiers need to change the leg from which they start to march, or 00 if the maximum beauty is already reached.

Consider that columns are numbered from 1 to nn in the order they are given in the input data.

If there are several answers, print any of them.

输入输出样例

  • 输入#1

    3
    5 6
    8 9
    10 3
    

    输出#1

    3
    
  • 输入#2

    2
    6 5
    5 6
    

    输出#2

    1
    
  • 输入#3

    6
    5 9
    1 3
    4 8
    4 5
    23 54
    12 32
    

    输出#3

    0
    

说明/提示

In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5+8+10=235+8+10=23 , and from the right leg — 6+9+3=186+9+3=18 . In this case the beauty of the parade will equal 2318=5|23-18|=5 .

If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal 5+8+3=165+8+3=16 , and who march from the right leg — 6+9+10=256+9+10=25 . In this case the beauty equals 1625=9|16-25|=9 .

It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.

首页