Goodness of a sequence

For every contiguous block, subtract the maximum increasing-subsequence sum from the block sum, then report the best value and how many shortest blocks achieve it.

Hard8Dynamic programmingPrefix sumSegment treeGreedyNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given a sequence A=A0,A1,,AN1A = A_0, A_1, \dots, A_{N-1} of NN integers. Subsequences, increasing subsequences, and contiguous subsequences are defined as follows.

  • Subsequence: a sequence built by deleting zero or more numbers from AA. The numbers that are kept stay in their original order. A subsequence may have size 00, and that one is called the empty subsequence.
  • Increasing subsequence: a subsequence of length at least 11 in which every number is larger than the number right before it.
  • Contiguous subsequence: a subsequence whose kept numbers are neighbors in the original sequence AA. The contiguous subsequence made of the ll-th through the rr-th numbers of AA is written A[l,r]=Al,Al+1,,ArA[l, r] = A_l, A_{l+1}, \dots, A_r. (lrl \le r)

For A=[2,1,3]A = [2, 1, 3], the subsequences are [],[2],[1],[3],[2,1],[2,3],[1,3],[2,1,3][], [2], [1], [3], [2, 1], [2, 3], [1, 3], [2, 1, 3], the contiguous subsequences are [2],[1],[3],[2,1],[1,3],[2,1,3][2], [1], [3], [2, 1], [1, 3], [2, 1, 3], and the increasing subsequences are [2],[1],[3],[2,3],[1,3][2], [1], [3], [2, 3], [1, 3].

Three functions are defined on a sequence.

  • sum(l,r)=Al+Al+1++Arsum(l, r) = A_l + A_{l+1} + \dots + A_r
  • inc(l,r)inc(l, r): the largest sum of the elements of an increasing subsequence of A[l,r]A[l, r]
  • f(l,r)=sum(l,r)inc(l,r)f(l, r) = sum(l, r) - inc(l, r)

The goodness gg of the sequence is g=maxf(l,r)g = \max f(l, r) over 0lr<N0 \le l \le r < N. That is, gg is the largest f(l,r)f(l, r) among all contiguous subsequences of AA.

Let the integer mm be the smallest length of a contiguous subsequence with f(l,r)=gf(l, r) = g.

Given AA, find gg first, then count the contiguous subsequences with rl+1=mr - l + 1 = m and f(l,r)=gf(l, r) = g.

Input

The first line contains an integer NN (1N200,0001 \le N \le 200{,}000). The second line contains A0,A1,,AN1A_0, A_1, \dots, A_{N-1} separated by spaces. (40Ai40-40 \le A_i \le 40)

Output

Print two integers on one line, separated by a space. The first integer is gg for the given sequence. The second integer is the number of contiguous subsequences with rl+1=mr - l + 1 = m and f(l,r)=gf(l, r) = g.