Problem 1: The Devious Minister, (Indraneel Mukherjee and R Shreevatsa, CMI)

The government of Siruseri has just commissioned one of the longest and most modern railway routes in the world. This route runs the entire length of Siruseri and passes through many of the big cities and a large number of small towns and villages in Siruseri.

The railway stations along this route have all been constructed keeping in mind the comfort of the travellers. Every station has big parking lots, comfortable waiting rooms and plenty of space for eateries. The railway authorities would like to contract out the catering services of these eateries.

The Siruseri Economic Survey has done a through feasibility study of the different stations and documented the expected profits (or losses) for the eateries in all the railway stations on this route. The authorities would like to ensure that every station is catered to. To prevent caterers from bidding only for profitable stations, the authorities have decided to give out catering contracts for contiguous segments of stations.

The minister in charge realises that one of the bidders is his bitter adversary and he has decided to hand out as useless a segment as possible to him. On the other hand, he does not want to be seen to be blatantly unfair by handing out a large loss-making section to the adversary. Instead he wants to find the largest segment whose sum is closest to 0, so that his adversary spends all his time running a large number of canteens and makes either a small loss or a small profit or, even better, nothing at all!

In other words, if the profits/losses at the stations are p1, p2, ..., pN the minister would like to handover a sequence i, i+1, ..., j such that the absolute value of pi + pi+1 + ... + pj is minimized. If there is more than one sequence with this minimum absolute value then he would like to hand over the longest one.

For example, suppose there are 8 stations along the line and their profitability is as follows:

Station              1    2    3    4    5    6    7    8 
Expected Profits   -20   90  -30  -20   80  -70  -60  125 

If the adversary is awarded the section 1 through 4, he will make a net profit of 20. On the other hand if he is given stations 6, 7 and 8, he will make loss of 5 rupees. This is the best possible value.

Input format

The first line of the input contains a single integer N indicating the number of stations. The next N lines (lines 2, 3, ..., N+1) describe the profitability of the N stations. Line i+1 contains a single integer denoting the expected profit at station i.

Output format

The first line contains a single integer indicating the minimum possible profit/loss among all segments. The second line contains two integers indicating the starting and ending point of the longest sequence with this minimum profit/loss. If there is more than one answer, it suffices to print one.

Test Data:

You may assume N ≤ 100000. You may further assume that in 40% of the inputs N ≤ 4000.

Example:

Here is the sample input and output corresponding to the example discussed above.

Sample Input

8
-20
90
-30
-20
80
-70
-60
125

Sample Output

-5
6 8

CPU Timelimit: 3 seconds
Memory limit: 64M
Grading style: ioi
Register Now