QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22767. Pasture Fences

Statistics

Farmer John has a long fence made of fence poles and rails. Each of the $N$ ($1 \le N \le 3000$) fence poles carries a sign with a single number from -1000 through +1000. Some poles might have the same number on their sign as other poles. While chewing their cud, the cows made up a game. The cow who can find the "best fence sum" gets ice cream for dessert.

To win the game, the winning cow must find the longest contiguous set of poles whose sum has the smallest absolute value. Help them determine the winning sum.

Input

  • Line 1: One line with a single integer: $N$

  • Lines $2..N+1$: Each line contains a pole's label. Line 2 contains the value for pole with sequence number 1, etc.

Output

A single line with three numbers:

  • the sequence number of the pole that is first to be summed,

  • the sequence number of the pole that is last to be summed, and

  • the absolute value of the sum of the labels of those poles. If more than one sequence has the same "best fence sum" and same maximum length, report the sequence with the lowest first sequence number.

Examples

Input 1

6
5
10
-5
-6
2
4

Output 1

4 6 0

Problem credits: Dominic Battre, 2001

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.