Longest non-decreasing subsegment

Find the longest contiguous non-decreasing run in a list and output its length and the sum of its elements, breaking ties by earliest start.

Easy3ArrayImplementationTwo pointersGreedyInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

A subsegment is a contiguous piece of the list. In the list [1,2,3,4,5][1, 2, 3, 4, 5] the subsegments include [1,2,3,4][1, 2, 3, 4], [2,3][2, 3] and [3,4][3, 4]. The list [1,3,4,5][1, 3, 4, 5] is not a subsegment, because 1 and 3 are not next to each other in the original list.

A subsegment is non-decreasing when it holds no element smaller than the element right before it.

The list [3,1,2,4,2,2,3,6][3, 1, 2, 4, 2, 2, 3, 6] has these non-decreasing subsegments, among others:

  • [3][3], [1][1], [2][2], [4][4], [2][2], [2][2], [3][3], [6][6]. A single element cannot decrease.
  • [1,2,4][1, 2, 4]
  • [2,2,3,6][2, 2, 3, 6]

The longest of them is [2,2,3,6][2, 2, 3, 6], with 4 elements.

Compute the length of the longest non-decreasing subsegment and the sum of its elements. If several non-decreasing subsegments reach the maximum length, answer for the one that starts earliest in the input.

Input

The first line contains an integer nn (1n1051 \le n \le 10^5), the size of the list. The second line contains the nn elements of the list separated by spaces. Every element is an integer between 11 and 10910^9.

Output

Print two integers on one line, separated by a single space. The first is the length of the longest non-decreasing subsegment and the second is the sum of its elements. If several non-decreasing subsegments reach the maximum length, print the length and the sum of the one that starts earliest in the input.