Problem1123--Maximum Subsequence Sum

1123: Maximum Subsequence Sum

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 0  Solved: 1
[Submit] [Status] [Web Board] [Creator:]

Description

Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj} where 1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20. Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence.

Input

The first line contains a positive integer K (≤10000). The second line contains K numbers, separated by a space.

Output

The first line contains a positive integer K (≤10000). The second line contains K numbers, separated by a space.

Sample Input Copy

10
-10 1 2 3 4 -5 -23 3 7 -21

Sample Output Copy

10 1 4

Source/Category