PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000316. Khôi phục phép lấy dư (Restore Modulo)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Khôi phục phép lấy dư (Restore Modulo)

Restore Modulo

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Alex has a non-negative integer array a1,a2,…,ana_1,a_2,\ldots,a_n. It can be generated by a modular generator if there exist integers m>0m>0, 0≤c<m0\le c<m, and s≥0s\ge0 such that

$$a_1=s\bmod m,\qquad a_i=(a_{i-1}+c)\bmod m\quad(2\le i\le n).$$

Here, x mod mx\bmod m is the non-negative remainder of division by mm. Determine whether such a generator exists, and, if it does, maximize the modulus mm.

  • Print -1 when no generator exists.
  • Print 0 if mm can be arbitrarily large.
  • Otherwise print the largest possible mm and a suitable increment cc, where 0≤c<m0\le c<m.

Input

The first line contains nn. The second line contains exactly nn non-negative integers a1,a2,…,ana_1,a_2,\ldots,a_n in their original order.

Output

Print one line containing -1, 0, or two space-separated integers m,cm,c, as specified in the problem statement.

Subtasks

  • Subtask 1 (20 points): 2≤n≤42\le n\le4; 0≤ai≤1090\le a_i\le10^9 for every ii.
  • Subtask 2 (30 points): 2≤n≤502\le n\le50; 0≤ai≤1090\le a_i\le10^9 for every ii.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 0≤ai≤1090\le a_i\le10^9 for every ii.

Examples

Example 1

Input

6
1 9 17 6 14 3

Output

19 8

Explanation

The consecutive differences are 8,8,−11,8,−118,8,-11,8,-11. With m=19,c=8m=19,c=8, both wrap-around transitions are correct, and the two distinct differences force m=8+11=19m=8+11=19.

Example 2

Input

3
4 2 2

Output

-1

Explanation

The successive differences are −2-2 and 00, which cannot arise from one fixed modular increment.

Example 3

Input

2
1 1

Output

0

Explanation

Taking c=0c=0 and any m>1m>1 works, so mm is unbounded.