, his friends collectively owe him $0. Over days, numbered from to , one of his friends can either borrow money or return money that is owed to . It is possible that his friends return so much money such that he owes his friends back money (i.e. his friends owe him a negative amount).
often loans money to other people. As a result, many people are in debt to him. Initially, on dayAfter the days of borrowing/returning, acquires a time machine and would like to go back to the day where his friends have the most total debt. If there are multiple days where his friends have the most total debt, he wants to go to the earliest one of them. Please determine which day this is!
Input Specification
The first line of input will contain an integer , the number of days.
lines of input follow. The line can either be borrow x
, signifying that dollars are borrowed from (increase in debt), or return x
, signifying that dollars has been returned to him (decrease in debt). is guaranteed to be non-negative, and the absolute value of the total debt at any time will not exceed .
Output Specification
Output a single integer from to that signifies the earliest day where 's friends owe him the most.
Sample Input
5
borrow 38
borrow 10
return 5
borrow 5
return 20
Sample Output
2
Explanation for Sample Output
On days 2 and 4,
's friends owe him $48, the highest debt. He would want to go back to day 2 over day 4 since it is earlier.
Comments