There is a matrix A of size x × y filled with integers. For every ,
Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix.
You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you started in the cell containing the number a1, then moved to the cell with the number a2, and so on.
From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells:
- (i + 1, j) — only if i < x;
- (i, j + 1) — only if j < y;
- (i - 1, j) — only if i > 1;
- (i, j - 1) — only if j > 1.
Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a1, then move to the cell containing a2 (in one step), then move to the cell containing a3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?
The first line contains one integer number n (1 ≤ n ≤ 200000) — the number of cells you visited on your path (if some cell is visited twice, then it's listed twice).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the integers in the cells on your path.
If all possible values of x and y such that 1 ≤ x, y ≤ 109 contradict with the information about your path, print NO.
Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 109.
8 1 2 3 6 9 8 5 2
YES 3 3
6 1 2 1 2 5 3
NO
2 1 10
YES 4 9
The matrix and the path on it in the first test looks like this:

Also there exist multiple correct answers for both the first and the third examples.
题意:
给一个人旅游路线,求一个二维数组满足所给路线,看看样例1 ,就能明白
思路:
1.相邻的数字只能相差1,或者相差二维数组的列数,所以相邻的数字差最多为2种
2.由于不能停在同一个方格里,所以相邻的数字不能相同
3.类似样例,3*3的二维数组比较特殊,3并不能一步到达4,需要特殊判断
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 200005;
int arr[N];
int main(){
int n;
cin>>n;
int maxt=1;
for(int i=0;i<n;i++){
cin>>arr[i];
if(i==0) continue;
if(arr[i]==arr[i-1]){
//cout<<"1: ";
cout<<"NO"<<endl;
return 0;
}
maxt=max(maxt,abs(arr[i]-arr[i-1]));
}
for(int i=1;i<n;i++){
int k=abs(arr[i]-arr[i-1]);
if(k!=1&&k!=maxt){
//cout<<"2: ";
cout<<"NO"<<endl;
return 0;
}
if(arr[i]%maxt==0&&arr[i-1]-arr[i]==1&&maxt!=1){
//cout<<"3: ";
cout<<"NO"<<endl;
return 0;
}
else if(arr[i]%maxt==1&&arr[i]-arr[i-1]==1&&maxt!=1){
//cout<<"4: ";
cout<<"NO"<<endl;
return 0;
}
}
cout<<"YES"<<endl;
cout<<1000000000<<' '<<maxt<<endl;
return 0;
}