#GL0000316. Khôi phục phép lấy dư (Restore Modulo)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 . It can be generated by a modular generator if there exist integers , , and such that
$$a_1=s\bmod m,\qquad a_i=(a_{i-1}+c)\bmod m\quad(2\le i\le n).$$Here, is the non-negative remainder of division by . Determine whether such a generator exists, and, if it does, maximize the modulus .
- Print
-1when no generator exists. - Print
0if can be arbitrarily large. - Otherwise print the largest possible and a suitable increment , where .
Input
The first line contains . The second line contains exactly non-negative integers in their original order.
Output
Print one line containing -1, 0, or two space-separated integers , as specified in the problem statement.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Example 1
Input
6
1 9 17 6 14 3
Output
19 8
Explanation
The consecutive differences are . With , both wrap-around transitions are correct, and the two distinct differences force .
Example 2
Input
3
4 2 2
Output
-1
Explanation
The successive differences are and , which cannot arise from one fixed modular increment.
Example 3
Input
2
1 1
Output
0
Explanation
Taking and any works, so is unbounded.