#P7718. 「EZEC-10」Equalization

「EZEC-10」Equalization

Description

You are given an array a1,a2,,ana_1, a_2, \ldots, a_n of length nn.

You may choose any three integers l,r,x (1lrnl, r, x\ (1 \le l \le r \le n, xZ)x \in \mathbb Z), and add xx to each of al,al+1,,ara_l, a_{l+1}, \ldots, a_r. This is called one operation.

Find the minimum number of operations needed to make all elements in aa equal, and also find the number of different optimal plans that achieve this minimum number of operations.

Since the number of plans may be very large, output it modulo 109+710^9 + 7.

Two plans are considered the same if and only if, for every operation, the chosen (l,r,x)(l, r, x) are exactly the same.

In particular, performing no operation is also considered a valid plan.

Input Format

The first line contains one integer nn.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n.

Output Format

The first line contains one integer, the minimum number of operations.

The second line contains one integer, the number of plans modulo 109+710^9 + 7.

3
1 2 3
2
16

Hint

[Sample 1 Explanation]

One feasible plan is: (l,r,x)=(1,1,1),(3,3,1)(l, r, x) = (1, 1, 1), (3, 3, -1).

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (1 point): n=2n = 2.
  • Subtask 2 (5 points): n=3n = 3.
  • Subtask 3 (14 points): aa is guaranteed to be non-increasing or non-decreasing.
  • Subtask 4 (20 points): n10n \le 10.
  • Subtask 5 (20 points): n16n \le 16.
  • Subtask 6 (40 points): no special restrictions.

For 100%100\% of the testdata, 1n181 \le n \le 18, 109a109-10^9 \le a \le 10^9.

Translated by ChatGPT 5