cho.sh
Notes
Loading...

Equal-Length Subarray Sum Difference

Time limit

5s

Memory limit

128 MB

Problem

You are given an array A. Define s(i, k) as the sum of k consecutive elements starting from the i-th element of A.

s(i, k) = A[i] + A[i+1] + ... + A[i+k-1]

Two ranges [i, i+k-1] and [j, j+k-1] do not overlap when i+k <= j. For every possible positive integer k, choose two non-overlapping contiguous subarrays of the same length k and minimize the absolute difference |s(i, k) - s(j, k)| between their sums.

Input

The first line contains a natural number n. The value n is at least 2 and at most 3,000.

The second line contains the elements of A in order from A[0] through A[n-1]. Each A[i] is an integer from 0 to 1,000,000,000.

Output

Print the k that gives the minimum difference on the first line.

Print that minimum difference on the second line. If multiple values of k give the same minimum difference, print the largest such k.