Settling Salaries

No attempts yetTime limit1sMemory limit512 MB

Problem

Bajtosoft employs nn workers. Because the projects it develops are confidential, not all of them know one another. Two workers know each other only if they handle consecutive stages of the same project.

Every project is developed sequentially: worker 11 (the team lead) makes the first draft and passes it to worker 22; after finishing their part, worker 22 passes the result to worker 33, and so on, until the project reaches worker nn, who completes it and hands the finished product back to the team lead (worker 11).

Each worker has a salary written into their contract. However, the company does not always honor the contract exactly. It always pays out the correct total amount, but not always to the right people: it often happens that one person receives less than their contract guarantees while another receives more.

Luckily the workers are honest, so they agreed that after every payout they will settle the amounts among themselves so that in the end everyone receives exactly what their contract guarantees.

There is just one catch: money can be transferred only between workers who know each other. That is, for every 1<i<n1 < i < n, worker ii may give money to or receive money from only workers i1i-1 and i+1i+1; worker 11 may transact with workers 22 and nn; and worker nn may transact with workers n1n-1 and 11.

Because each such settlement requires many transactions, the Bajtosoft workers have asked you, an independent programmer, to write a program that after each payout determines the minimum number of transactions needed to settle the accounts.

We assume that in these transactions workers use only the money they received from the company in the given payout together with the money they received from other workers in earlier transactions.

Input

The first line of standard input contains a single integer nn (1n1061 \le n \le 10^6), the number of Bajtosoft workers.

Each of the next nn lines contains two integers aia_i and bib_i (1ai,bi10001 \le a_i, b_i \le 1000), separated by a single space: the salary of the ii-th worker guaranteed by the contract and the amount they actually received (both in bytalers). You may assume that a1+a2++an=b1+b2++bna_1 + a_2 + \dots + a_n = b_1 + b_2 + \dots + b_n.

Output

Print, in the first and only line of standard output, a single integer: the minimum number of transactions between workers who know each other that reaches a state where every worker ends up (after all transactions) with exactly the amount guaranteed by their contract.

If no set of transactions can reach such a state, print the single word "NIE".

Hint

Explanation of the sample: All salaries are settled in two steps: worker 33 gives worker 22 one bytaler, and worker 11 gives worker 44 three bytalers.