There is a matrix A of size x × y filled with integers. For every $i \in [ 1 . . x ]$, $j \in [ 1 . . y ]$ A_{i}, 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 a_1, a_2, ..., a_{n} denoting that you started in the cell containing the number a_1, then moved to the cell with the number a_2, 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 a_1, then move to the cell containing a_2 (in one step), then move to the cell containing a_3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves?


-----Input-----

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 a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the integers in the cells on your path.


-----Output-----

If all possible values of x and y such that 1 ≤ x, y ≤ 10^9 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 10^9.


-----Examples-----
Input
8
1 2 3 6 9 8 5 2

Output
YES
3 3

Input
6
1 2 1 2 5 3

Output
NO

Input
2
1 10

Output
YES
4 9



-----Note-----

The matrix and the path on it in the first test looks like this: [Image] 

Also there exist multiple correct answers for both the first and the third examples.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Implementation


Solutions:
import sys, math, queue, bisect
MOD = 998244353
sys.setrecursionlimit(1000000)
n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
	if a[i] == a[i - 1]:
		print('NO')
		exit()
y = None
for i in range(1, n):
	if abs(a[i] - a[i - 1]) == 1:
		continue
	if y is None:
		y = abs(a[i] - a[i - 1])
	elif y != abs(a[i] - a[i - 1]):
		print('NO')
		exit()
if y is None:
	y = max(a)
for i in range(1, n):
	if abs(a[i] - a[i - 1]) != 1:
		continue
	if a[i] % y == 0:
		if a[i - 1] != a[i] - 1 and a[i - 1] != a[i] + y:
			print('NO')
			exit()
	elif a[i] % y == 1:
		if a[i - 1] != a[i] - y and a[i - 1] != a[i] + 1:
			print('NO')
			exit()
x = math.ceil(max(a) / y)
print('YES')
print(x, y)


n = int(input())
a = [int(i) for i in input().split()]
c = 1
for i in range(1, n):
	if abs(a[i] - a[i - 1]) > 1:
		c = abs(a[i] - a[i - 1])
x3 = 10 ** 9
r = 1
for i in range(n - 1):
	x1 = max(0, a[i] - 1) // c
	y1 = a[i] % c
	if y1 == 0:
		y1 = c
	x2 = max(0, a[i + 1] - 1) // c
	y2 = a[i + 1] % c
	if y2 == 0:
		y2 = c
	if x2 == x1 + 1 and y2 == y1 and (x1 < x3):
		continue
	elif x2 == x1 and y2 == y1 + 1 and (y1 < c):
		continue
	elif x2 == x1 - 1 and y2 == y1 and (x1 > 0):
		continue
	elif x2 == x1 and y2 == y1 - 1 and (y1 > 0):
		continue
	else:
		r = 0
if r == 1:
	print('YES')
	print(x3, c)
else:
	print('NO')


from math import ceil

def count_xy(n, b):
	c = {abs(b[i + 1] - b[i]) for i in range(n - 1) if abs(b[i + 1] - b[i]) != 1}
	if 0 in c:
		return (-1, -1)
	if len(c) > 1:
		return (-1, -1)
	if len(c) == 0:
		return (1, max(b))
	y = c.pop()
	for i in range(1, n):
		(cur, pr) = (b[i], b[i - 1])
		if abs(cur - pr) == 1 and min(cur, pr) % y == 0:
			return (-1, -1)
	return (ceil(max(b) / y), y)
n = int(input())
b = [int(x) for x in input().split()]
(x, y) = count_xy(n, b)
if x == -1:
	print('NO')
else:
	print('YES')
	print(x, y)


n = int(input())
a = list(map(int, input().split()))
(x, y) = (int(1000000000.0), -1)
for i in range(n - 1):
	d = abs(a[i] - a[i + 1])
	if d == 0:
		print('NO')
		exit()
	if d > 1:
		if y == -1:
			y = d
		if y != -1 and y != d:
			print('NO')
			exit()
if y == -1:
	y = int(1000000000.0)
for i in range(n - 1):
	if abs(a[i] - a[i + 1]) == 1:
		if a[i] % y == 0 and a[i + 1] % y == 1 and (a[i + 1] > a[i]) or (a[i] % y == 1 and a[i + 1] % y == 0 and (a[i + 1] < a[i])):
			print('NO')
			exit()
print('YES')
print(x, y)


n = int(input())
a = list(map(int, input().split()))
from math import ceil
s = set()
s0 = None
my = 0
for i in range(1, n):
	if a[i] == a[i - 1]:
		print('NO')
		exit()
	if abs(a[i] - a[i - 1]) != 1:
		s.add(abs(a[i] - a[i - 1]))
		s0 = abs(a[i] - a[i - 1])
	if len(s) > 1:
		print('NO')
		exit()
	elif len(s) == 1:
		my = max(ceil(max(a[i], a[i - 1]) / s0), my)
if len(s) == 0:
	x = 1
	print('YES')
	print(x, max(a))
	exit()
for i in range(1, n):
	if abs(a[i] - a[i - 1]) == 1:
		if ceil(a[i] / s0) != ceil(a[i - 1] / s0):
			print('NO')
			exit()
print('YES')
print(my, s0)


n = int(input())
a = list(map(int, input().split(' ')))
m = a[0]
b = a[0]
x = 1
mas = []
fl = True
for i in range(1, n):
	if a[i] == a[i - 1]:
		fl = False
		break
	if abs(a[i] - a[i - 1]) > 1:
		if x == 1:
			x = abs(a[i] - a[i - 1])
		elif x != abs(a[i] - a[i - 1]):
			fl = False
			break
		if m != b:
			mas.append((m, b))
		m = a[i]
		b = a[i]
	else:
		if a[i] > b:
			b = a[i]
		if a[i] < m:
			m = a[i]
if m != b:
	mas.append((m, b))
for i in range(len(mas)):
	if x != 1:
		if (mas[i][0] - 1) // x != (mas[i][1] - 1) // x:
			fl = False
			break
if fl:
	print('YES')
	print(str(1000000000), str(x))
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
diff_set = set()
for i in range(n - 1):
	diff_set.add(abs(a[i] - a[i + 1]))
diffs = []
for diff in diff_set:
	if diff == 0:
		print('NO')
		exit()
	if diff != 1:
		diffs.append(diff)
if len(diffs) == 0:
	print('YES')
	print(10 ** 9, 10 ** 9)
	exit()
elif len(diffs) > 1:
	print('NO')
	exit()
diff = diffs[0]
for i in range(n - 1):
	if abs(a[i] - a[i + 1]) != 1:
		continue
	if (a[i] - 1) // diff != (a[i + 1] - 1) // diff:
		print('NO')
		exit()
print('YES')
print(10 ** 9, diff)


n = int(input())
a = [int(x) for x in input().split()]
y = []
for (s, t) in zip(a, a[1:]):
	if abs(s - t) != 1 and s != t:
		y.append(abs(s - t))
y.append(1)
y = y[0]
for (s, t) in zip(a, a[1:]):
	if not (abs(s - t) == y or (abs(s - t) == 1 and min(s, t) % y != 0)):
		break
else:
	print('YES')
	print('{} {}'.format(10 ** 9, y))
	return
print('NO')


illegal = {(0, 1), (1, -1)}
n = int(input())
if n == 1:
	print('YES\n1000000000 1')
	exit()
l = [*map(int, input().split())]
d = {abs(l[i + 1] - l[i]) for i in range(n - 1)}
(x, y) = (int(1000000000.0), max(d) if max(d) != 1 else int(1000000000.0))
if 0 not in d and len(d - {1}) <= 1 and all(((l[i] % y, l[i + 1] - l[i]) not in illegal for i in range(n - 1))):
	print('YES')
	print(x, y)
else:
	print('NO')


n = int(input())
vals = [int(x) for x in input().split()]
x = 10 ** 9
y = None
for diff in [abs(val2 - val1) for (val1, val2) in zip(vals, vals[1:])]:
	if diff == 0:
		print('NO')
		break
	if diff != 1:
		if not y:
			y = diff
		elif y != diff:
			print('NO')
			break
else:
	if not y:
		y = 10 ** 9
	if max(vals) > x * y:
		print('NO')
		exit(0)
	for (val, diff) in [(val1, val2 - val1) for (val1, val2) in zip(vals, vals[1:])]:
		if diff == 1 and val % y == 0 and (y != 1):
			print('NO')
			break
		if diff == -1 and val % y == 1:
			print('NO')
			break
	else:
		print('YES')
		print(x, y)


n = int(input())
a = list(map(int, input().split()))
b = set((abs(a[i] - a[i - 1]) for i in range(1, n) if abs(a[i] - a[i - 1]) - 1))
m = 10 ** 9
if len(b) > 1:
	print('NO')
elif b:
	b = b.pop()
	if b and all(((a[i] - 1) // b == (a[i - 1] - 1) // b for i in range(1, n) if abs(a[i] - a[i - 1]) == 1)):
		print('YES')
		print(m, b)
	else:
		print('NO')
else:
	print('YES')
	print(m, m)


import sys
n = int(sys.stdin.readline())
vals = [int(x) for x in sys.stdin.readline().split()]
import operator
diffs = list(set((r for (x, y) in zip(vals[1:], vals) for r in (abs(x - y),) if r != 1)))
if len(diffs) > 1 or 0 in diffs:
	print('NO')
	sys.exit()
if not diffs:
	print('YES')
	print(f'{10 ** 9} {10 ** 9}')
	sys.exit()
j = diffs[0]
for i in range(1, n):
	if abs(vals[i - 1] - vals[i]) != 1:
		continue
	if (vals[i - 1] - 1) // j != (vals[i] - 1) // j:
		print('NO')
		sys.exit()
print('YES')
print(f'{10 ** 9} {j}')


while True:
	n = int(input())
	path = list(map(int, input().split()))
	eleminatedY = {1}
	y = 1
	for i in range(n - 1):
		diff = abs(path[i] - path[i + 1])
		if diff == 0:
			print('NO')
			return
		if diff == 1:
			eleminatedY.add(min(path[i], path[i + 1]))
			if min(path[i], path[i + 1]) % y == 0 and y != 1:
				print('NO')
				return
			continue
		if y == diff:
			continue
		for value in eleminatedY:
			if value % diff == 0:
				print('NO')
				return
		if y == 1:
			y = diff
			continue
		print('NO')
		return
	print('YES\n{} {}'.format(1000000000, y))
	return


from math import ceil
n = int(input())
arr = list(map(int, input().split()))
s = set()
for i in range(1, n):
	if abs(arr[i] - arr[i - 1]) == 1:
		continue
	s.add(abs(arr[i] - arr[i - 1]))
if not s:
	print('YES')
	print(1000000000, max(arr))
	exit()
s = list(s)
if s and s[0] == 0:
	print('NO')
	exit()
if len(s) > 1:
	print('NO')
	exit()
c = s[0]
flag = 0
row = 0
for i in range(n - 1):
	if arr[i] % c == 0 and arr[i + 1] == arr[i] + 1:
		flag = 1
		break
	if arr[i + 1] % c == 0 and arr[i] - 1 == arr[i + 1]:
		flag = 1
		break
	row = max(row, ceil(arr[i] / c), ceil(arr[i + 1] / c))
if flag == 1:
	print('NO')
else:
	print('YES')
	print(1000000000, c)


n = int(input())
a = list(map(int, input().split()))
ok = 1
x = y = 0
for i in range(1, n):
	d = abs(a[i] - a[i - 1])
	if d == 0:
		ok = 0
	if d > 1:
		if y:
			if y != d:
				ok = 0
		else:
			y = d
if y > 0:
	for i in range(1, n):
		d = a[i] - a[i - 1]
		if d == 1:
			if a[i - 1] % y == 0:
				ok = 0
		if d == -1:
			if a[i] % y == 0:
				ok = 0
else:
	y = 1
if ok:
	x = (max(a) + y - 1) // y
	print('YES')
	print(x, y)
else:
	print('NO')


import configparser
import math
import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	if n == 1:
		print('YES')
		print(1, ' ', int(1000000000.0))
		return
	diff = None
	for i in range(n - 1):
		cur_diff = abs(a[i + 1] - a[i])
		if cur_diff == 0:
			print('NO')
			return
		if cur_diff != 1:
			if diff is None:
				diff = cur_diff
			elif cur_diff != diff:
				print('NO')
				return
	if diff == None:
		print('YES')
		print(int(1000000000.0), ' ', 1)
		return
	cols = diff
	for i in range(n - 1):
		cur_diff = a[i + 1] - a[i]
		if a[i] % cols == 0:
			if cur_diff == -1 or cur_diff == -cols or cur_diff == cols:
				continue
			else:
				print('NO')
				return
		elif a[i] % cols == 1:
			if cur_diff == 1 or cur_diff == -cols or cur_diff == cols:
				continue
			else:
				print('NO')
				return
		elif cur_diff == 1 or cur_diff == -1 or cur_diff == -cols or (cur_diff == cols):
			continue
		else:
			print('NO')
			return
	print('YES')
	print(int(1000000000.0), ' ', cols)
main()


n = int(input())
a = list(map(int, input().split()))
m = 1
for (l, r) in zip(a, a[1:]):
	if abs(l - r) != 1 and l != r:
		m = abs(l - r)
		break
for (l, r) in zip(a, a[1:]):
	if not (abs(l - r) == m or (abs(l - r) == 1 and min(l, r) % m != 0)):
		print('NO')
		exit()
print('YES')
print('{} {}'.format(10 ** 9, m))


import math
while True:
	try:
		n = int(input())
		ara = list(map(int, input().split()))
		maxx = -100
		for i in range(1, n, 1):
			maxx = max(maxx, abs(ara[i] - ara[i - 1]))
		i = diff = t1 = t2 = 0
		if maxx == -100:
			print('YES')
			print(10 ** 9, ara[0])
			continue
		else:
			while i < n - 1:
				if ara[i] == ara[i + 1]:
					break
				t1 = int(math.ceil(ara[i] / maxx))
				t2 = int(math.ceil(ara[i + 1] / maxx))
				diff = abs(t1 - t2)
				if diff > 1:
					break
				if diff == 0 and abs(ara[i + 1] - ara[i]) > 1:
					break
				elif diff == 1 and max(ara[i + 1], ara[i]) != min(ara[i], ara[i + 1]) + maxx:
					break
				i += 1
		if i == n - 1:
			print('YES')
			print(10 ** 9, maxx)
		else:
			print('NO')
	except EOFError:
		break


def getpos(n, cols):
	if n % cols == 0:
		i = n // cols
	else:
		i = n // cols + 1
	if n % cols == 0:
		j = cols
	else:
		j = n % cols
	return (i, j)

def simul(x, m):
	D = {}
	L = max(x) // m + 10
	for i in range(len(x) - 1):
		curr_pos = getpos(x[i], m)
		next_pos = getpos(x[i + 1], m)
		if abs(curr_pos[0] - next_pos[0]) > 1 or abs(curr_pos[1] - next_pos[1]) > 1:
			return False
		if abs(curr_pos[0] - next_pos[0]) == 1 and abs(curr_pos[1] - next_pos[1]) == 1:
			return False
	return True

def solve3(x):
	if len(x) == 1:
		return ('YES', x[0])
	y = [abs(y) for y in [x[i + 1] - x[i] for i in range(len(x) - 1)]]
	m = max(y)
	if m == 1:
		m = max(x)
	if 0 in y:
		return ('NO', m)
	if len(set(y).difference({1})) <= 1:
		if simul(x, m):
			return ('YES', m)
		else:
			return ('NO', m)
	else:
		return ('NO', m)
n = int(input())
x = list(map(int, input().strip().split()))
ans = solve3(x)
if ans[0] == 'YES':
	m = ans[1]
	print('YES')
	print('1000000000 ' + str(m))
else:
	print('NO')


import sys
n = int(sys.stdin.readline().strip())
ais = list(map(int, sys.stdin.readline().strip().split()))
if n == 1:
	print('YES')
	print(1, ais[0])
	sys.exit(0)
ys = list(set((abs(a0 - a1) for (a0, a1) in zip(ais[:-1], ais[1:]))))
if 1 not in ys:
	ys.append(1)
if len(ys) == 1:
	print('YES')
	print(1, max(ais))
	sys.exit(0)
if len(ys) > 2 or 0 in ys:
	print('NO')
	sys.exit(0)
y = max(ys)
x = (max(ais) - 1) // y + 1
for (a0, a1) in zip(ais[:-1], ais[1:]):
	(b0, b1) = (min(a0, a1), max(a0, a1))
	if b1 - b0 == 1 and b0 % y == 0:
		print('NO')
		sys.exit(0)
print('YES')
print(x, y)


n = int(input())
a = list(map(int, input().split()))
x = 1
for i in range(n - 1):
	if abs(a[i + 1] - a[i]) > x:
		x = abs(a[i + 1] - a[i])
		break
for i in range(n - 1):
	y = abs(a[i + 1] - a[i])
	if y == 1 and (a[i] - 1) % x == 0 and (a[i + 1] < a[i]) and ((a[i + 1] - 1) % x != 0):
		print('NO')
		exit(0)
	elif y == 1 and a[i] % x != 0:
		continue
	elif y == 1 and a[i] % x == 0 and (a[i + 1] >= a[i]) and (a[i + 1] % x != 0):
		print('NO')
		exit(0)
	elif y == 1 and a[i] % x == 0 and (a[i + 1] < a[i] or a[i + 1] % x == 0):
		continue
	elif y == x:
		continue
	else:
		print('NO')
		exit(0)
print('YES')
print(1000000000, x)


n = int(input())
a = [int(x) for x in input().split()]
d = -1
for i in range(n - 1):
	dif = abs(a[i] - a[i + 1])
	if dif == 1:
		continue
	if dif == 0:
		print('NO')
		exit()
	elif d == -1:
		d = dif
	elif d != dif:
		print('NO')
		exit()
if d == -1:
	print('YES')
	print(10 ** 9, 10 ** 9)
	exit()
for i in range(n - 1):
	if a[i] == a[i + 1] + 1 and a[i + 1] % d == 0 or (a[i] == a[i + 1] - 1 and a[i] % d == 0):
		print('NO')
		exit()
print('YES')
print('%d %d' % (10 ** 9, d))


n = int(input())
arr = [int(i) for i in input().split()]
y = -1
for i in range(1, n):
	if arr[i] == arr[i - 1] - 1 or arr[i] == arr[i - 1] + 1:
		pass
	elif arr[i] == arr[i - 1]:
		print('NO')
		exit(0)
	elif y == -1:
		y = abs(arr[i] - arr[i - 1])
	else:
		q = abs(arr[i] - arr[i - 1])
		if q != y:
			print('NO')
			exit(0)
if y == -1:
	mx = -1
	for i in arr:
		mx = max(i, mx)
	print('YES\n{} {}'.format(10 ** 9, mx))
	exit(0)
bl = False
for i in range(1, n):
	pp = arr[i - 1] % y
	if pp == 0 and arr[i - 1] + 1 == arr[i] or (pp == 1 and arr[i - 1] - 1 == arr[i]):
		bl = True
		break
if bl:
	print('NO')
else:
	print('YES\n{} {}'.format(10 ** 9, y))


n = int(input())
a = list(map(int, input().split()))
m = -1
f = 0
for i in range(n - 1):
	dif = abs(a[i] - a[i + 1])
	if dif == 0:
		f = 1
		break
	if dif != 1:
		if m == -1:
			m = dif
		elif m != dif:
			f = 1
			break
if f:
	print('NO')
elif m == -1:
	print('YES')
	print(1, max(a))
else:
	mj = -1
	for i in a:
		mj = max(mj, (i - 1) // m + 1)
	f = 0
	for i in range(n - 1):
		dif = abs(a[i] - a[i + 1])
		if dif == 1:
			if (a[i] - 1) // m != (a[i + 1] - 1) // m:
				f = 1
				break
	if f:
		print('NO')
	else:
		print('YES')
		print(mj, m)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = list(map(int, input().split()))
c = 1
for i in range(1, n):
	if l[i] == l[i - 1]:
		print('NO')
		sys.exit()
	if abs(l[i] - l[i - 1]) != 1:
		if c == 1:
			c = abs(l[i] - l[i - 1])
		elif c != abs(l[i] - l[i - 1]):
			print('NO')
			sys.exit()
if c == 1:
	print('YES')
	print(10 ** 9, c)
	sys.exit()
for i in range(n):
	if i > 0 and (l[i] - 1) % c == 0:
		if l[i - 1] == l[i] - 1:
			print('NO')
			sys.exit()
	if i < n - 1 and (l[i] - 1) % c == 0:
		if l[i + 1] == l[i] - 1:
			print('NO')
			sys.exit()
print('YES')
print(10 ** 9, c)


n = int(input())
m = list(map(int, input().split()))
f = 0
cur = 0
for i in range(n - 1):
	if abs(m[i] - m[i + 1]) == 0:
		f = 2
	elif abs(m[i] - m[i + 1]) > 1:
		x = abs(m[i] - m[i + 1])
		f = 1
if f == 2:
	print('NO')
elif f == 0:
	print('YES')
	print(1000000000, 1000000000)
else:
	i = (m[0] - 1) // x
	j = (m[0] - 1) % x
	for u in range(1, n):
		i2 = (m[u] - 1) // x
		j2 = (m[u] - 1) % x
		if i == i2 and abs(j - j2) == 1 or (j == j2 and abs(i - i2) == 1):
			pass
		else:
			f = 2
		i = i2
		j = j2
	if f == 2:
		print('NO')
	else:
		print('YES')
		print(1000000000, x)


n = int(input())
a = list(map(int, input().split()))
diff = []
x = 1000000000
for i in range(1, n):
	ele = abs(a[i] - a[i - 1])
	if ele != 1:
		diff += [ele]
diff = list(set(diff))
if len(diff) > 1 or 0 in diff:
	print('NO')
	quit()
if not diff:
	print('YES')
	print(x, x)
	quit()
d = diff[0]
for i in range(1, n):
	ele = abs(a[i] - a[i - 1])
	if ele != 1:
		continue
	if (a[i] - 1) // d != (a[i - 1] - 1) // d:
		print('NO')
		quit()
print('YES')
print(x, d)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a * a + b * b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
l = list(map(int, input().split()))
c = 1
for i in range(1, n):
	if l[i] == l[i - 1]:
		print('NO')
		sys.exit()
	if abs(l[i] - l[i - 1]) != 1:
		if c == 1:
			c = abs(l[i] - l[i - 1])
		elif c != abs(l[i] - l[i - 1]):
			print('NO')
			sys.exit()
if c == 1:
	print('YES')
	print(10 ** 9, c)
	sys.exit()
for i in range(n):
	if i > 0 and (l[i] - 1) % c == 0:
		if l[i - 1] == l[i] - 1:
			print('NO')
			sys.exit()
	if i < n - 1 and (l[i] - 1) % c == 0:
		if l[i + 1] == l[i] - 1:
			print('NO')
			sys.exit()
print('YES')
print(10 ** 9, c)


n = int(input())
a = [int(x) for x in input().split()]
last = 1
y = -1
for i in range(1, n):
	if abs(a[i] - a[i - 1]) != 1:
		y = abs(a[i] - a[i - 1])
		break
if y == -1 or y == 0:
	if y == -1:
		print('YES')
		print(int(1000000000.0), int(1000000000.0))
	else:
		print('NO')
else:
	f = True
	I = a[0] // y
	if a[0] % y != 0:
		I = I + 1
	J = a[0] % y
	if a[0] % y == 0:
		J = y
	for i in range(1, n):
		delt = a[i] - a[i - 1]
		if delt == 1:
			J = J + 1
		if delt == -1:
			J = J - 1
		if delt == y:
			I = I + 1
		if delt == -y:
			I = I - 1
		if abs(delt) != 1 and abs(delt) != y:
			f = False
		if I <= 0 or J <= 0 or J > y:
			f = False
	if f == True:
		print('YES')
		print(int(1000000000.0), y)
	else:
		print('NO')


n = int(input())
m = list(map(int, input().split()))
x = 1
from math import fabs
for i in range(1, n):
	if not -1 <= m[i] - m[i - 1] <= 1:
		x = int(fabs(m[i] - m[i - 1]))
		break
for i in range(1, n):
	if not (fabs(m[i] - m[i - 1]) == x or (m[i] - 1) // x == (m[i - 1] - 1) // x) or m[i - 1] == m[i]:
		print('NO')
		break
else:
	print('YES')
	print(10 ** 9, x)


from sys import stdin, stdout
inp = lambda : (int(o) for o in stdin.readline().split())
n = int(input())
a = list(inp())
(ans, c) = (1, [])
b = [1]
for i in range(n - 1):
	s = abs(a[i] - a[i + 1])
	if s == 1:
		c.append(max(a[i], a[i + 1]))
		continue
	if s == 0:
		exit(print('NO'))
	elif s > 1:
		b.append(s)
if len(set(b)) > 2:
	exit(print('NO'))
if b[-1] != 1:
	for i in c:
		if (i - 1) % b[-1] == 0:
			exit(print('NO'))
stdout.write('YES\n')
stdout.write('1000000000 ' + str(b[-1]))


def cm(c1, c2, c):
	(x1, y1, x2, y2) = (-1, -1, -1, -1)
	if c1 % c == 0:
		y1 = c1 // c
		x1 = c
	else:
		y1 = c1 // c + 1
		x1 = c1 % c
	if c2 % c == 0:
		y2 = c2 // c
		x2 = c
	else:
		y2 = c2 // c + 1
		x2 = c2 % c
	if y1 == y2:
		if abs(x1 - x2) == 1:
			return True
		else:
			return False
	else:
		return False
n = int(input())
arr = list(map(int, input().strip().split(' ')))
ctr = 0
r = -1
c = -1
while ctr < len(arr) - 1:
	c1 = arr[ctr]
	c2 = arr[ctr + 1]
	if abs(c2 - c1) != 1:
		c = abs(c2 - c1)
		break
	ctr += 1
if c == -1:
	print('YES')
	print(1, max(arr))
else:
	ctr = 0
	flag = True
	if c == 0:
		print('NO')
	else:
		while ctr < len(arr) - 1:
			c1 = arr[ctr]
			c2 = arr[ctr + 1]
			if abs(c2 - c1) != 1 and abs(c2 - c1) != c or abs(c1 - c2) == 0:
				print('NO')
				flag = False
				break
			if abs(c2 - c1) == 1:
				if cm(c1, c2, c) == False:
					print('NO')
					flag = False
					break
			ctr += 1
		if flag:
			print('YES')
			print(10 ** 9, c)


n = int(input())
a = list(map(int, input().split()))
x = 1
y = 10 ** 9
if n == 1:
	print('YES')
	print(y, x)
else:
	t = 0
	for i in range(1, n):
		s = a[i] - a[i - 1]
		if s != 1 and s != -1:
			s = max(s, -s)
			if x != 1 and x != s or s == 0:
				print('NO')
				t = 1
				break
			x = s
	if t == 0 and x > 1:
		for i in range(1, n):
			if a[i] % x == 0 and a[i - 1] == a[i] + 1 or (a[i - 1] % x == 0 and a[i] == a[i - 1] + 1):
				print('NO')
				t = 1
				break
	if t == 0:
		print('YES')
		print(y, x)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print('YES')
	print(a[0], a[0])
	exit()
vdist = set((abs(a[i] - a[i - 1]) for i in range(1, len(a))))
maxn = max(a)
y = max(vdist)
if 0 in vdist:
	print('NO')
	exit()
if y == 1:
	print('YES')
	print(maxn, 1)
	exit()
if len(vdist) > 2 or (len(vdist) == 2 and 1 not in vdist):
	print('NO')
	exit()
for i in range(1, len(a)):
	(start, finish) = (min(a[i], a[i - 1]), max(a[i], a[i - 1]))
	if start % y == 0 and finish - start < y:
		print('NO')
		exit()
print('YES')
print(maxn // y + 1, y)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	n = ni()
	l = nl()
	if n == 1:
		print('YES')
		print(10 ** 9, 10 ** 9)
		return
	s = set([abs(l[i + 1] - l[i]) for i in range(n - 1)])
	if len(s) > 2 or 0 in s:
		print('NO')
		return
	H = 10 ** 9
	if s == {1}:
		W = 10 ** 9
	else:
		W = max(s)
	c = l[0]
	for x in l[1:]:
		if x - c == 1:
			if c % W == 0:
				print('NO')
				return
		elif x - c == -1:
			if c % W == 1:
				print('NO')
				return
		elif x - c == W:
			if (c - 1) // W == H - 1:
				print('NO')
				return
		elif x - c == -W:
			if (c - 1) // W == 0:
				print('NO')
				return
		else:
			print('NO')
			return
		c = x
	print('YES')
	print(H, W)
	return
solve()


MAXN = 1000000000
n = int(input())
a = list(map(int, input().split()))

def solve1():
	for i in range(n - 1):
		if abs(a[i] - a[i + 1]) != 1:
			return False
	print('YES\n%d %d' % (MAXN, 1))
	return True

def solve2():
	w = -1
	for i in range(n - 1):
		d = abs(a[i] - a[i + 1])
		if d != 1:
			if w == -1:
				w = d
			elif w != d:
				return False
	if w <= 0:
		return False
	for i in range(n - 1):
		if abs(a[i] - a[i + 1]) == 1 and (a[i] - 1) // w != (a[i + 1] - 1) // w:
			return False
	print('YES\n%d %d' % (MAXN, w))
	return True
if solve1():
	pass
elif solve2():
	pass
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
for i in range(n - 1):
	if abs(a[i] - a[i + 1]) == 1:
		c.append(max(a[i], a[i + 1]))
		continue
	elif a[i] == a[i + 1]:
		exit(print('NO'))
	else:
		b.append(abs(a[i] - a[i + 1]))
if len(set(b)) > 1:
	print('NO')
elif len(set(b)) == 0:
	print('YES')
	exit(print(1000000000, 1000000000))
else:
	for i in c:
		if (i - 1) % b[0] == 0:
			exit(print('NO'))
	print('YES')
	print(1000000000, b[0])


import sys
n = int(input())
a = list(map(int, input().split()))
(x, y) = (0, 0)
ans_y = -1
matrix = {(0, 0): a[0]}
used = {a[0]}
(l, r, u) = (0, 0, 0)
for (p, c) in zip(a, a[1:]):
	if p == c:
		print('NO')
		exit()
	if abs(p - c) > 1:
		if ans_y == -1:
			ans_y = abs(p - c)
		elif ans_y != abs(p - c):
			print('NO')
			exit()
		if p < c:
			x += 1
		else:
			x -= 1
			u = min(u, x)
	else:
		if p < c:
			y += 1
		else:
			y -= 1
		(l, r) = (min(l, y), max(r, y))
	if (x, y) not in matrix and c in used or ((x, y) in matrix and matrix[x, y] != c):
		print('NO')
		exit()
	used.add(c)
	matrix[x, y] = c
if ans_y == -1:
	ans_y = 10 ** 9
if r - l + 1 > ans_y or a[-1] - (y - l) - (x - u) * ans_y < 1:
	print('NO')
	exit()
l = r - ans_y + 1
for ((cx, cy), val) in matrix.items():
	if (val - 1) % ans_y > cy - l:
		print('NO')
		exit()
print(f'YES\n{10 ** 9} {ans_y}')


n = int(input())
a = list(map(int, input().strip().split()))
y = -1
for i in range(1, n):
	_y = abs(a[i] - a[i - 1])
	if _y == 0:
		print('NO')
		exit(0)
	if _y == 1:
		continue
	if y == -1:
		y = _y
	elif y != _y:
		print('NO')
		exit(0)
if y == -1:
	y = max(a)
x = int(1000000000.0)
(pr, pc) = (-1, -1)
for i in range(n):
	r = (a[i] - 1) // y
	c = (a[i] - 1) % y
	if not (0 <= r < x and 0 <= c < y):
		print('NO')
		exit(0)
	if pr != -1:
		if r == pr and c == pc + 1:
			pass
		elif r == pr and c == pc - 1:
			pass
		elif r == pr + 1 and c == pc:
			pass
		elif r == pr - 1 and c == pc:
			pass
		else:
			print('NO')
			exit(0)
	(pr, pc) = (r, c)
print('YES')
print(x, y)


n = int(input())
l = [int(i) for i in input().split()]
if n == 1:
	print('YES')
	print(l[0], l[0])
	exit()
row = None
col = None
m = max(l)
for i in range(1, n):
	if abs(l[i] - l[i - 1]) == 0:
		print('NO')
		exit()
	if abs(l[i] - l[i - 1]) != 1:
		if col == None:
			col = abs(l[i] - l[i - 1])
		elif col != abs(l[i] - l[i - 1]):
			print('NO')
			exit()
if not col:
	print('YES')
	print(max(l), 1)
	exit()
for i in range(1, n):
	if abs(l[i] - l[i - 1]) == 1:
		if min(l[i], l[i - 1]) % col == 0:
			print('NO')
			exit()
from math import ceil
if col == None:
	col = 1
	print('YES')
	row = ceil(max(l) / col)
	print(row, col)
	exit()
print('YES')
row = ceil(max(l) / col)
print(row, col)


def sove(n, a):
	m = 1
	for i in range(1, n):
		if abs(a[i] - a[i - 1]) == 0:
			return -1
		if abs(a[i] - a[i - 1]) > 1:
			if m == 1:
				m = abs(a[i] - a[i - 1])
			elif m != 1:
				if abs(a[i] - a[i - 1]) != m:
					return -1
	for i in range(n - 1):
		if a[i] % m == 0:
			if a[i + 1] != a[i] - 1 and a[i + 1] != a[i] - m and (a[i + 1] != a[i] + m):
				return -1
		elif a[i] % m == 1:
			if a[i + 1] != a[i] + 1 and a[i + 1] != a[i] - m and (a[i + 1] != a[i] + m):
				return -1
	return [10 ** 9, m]
n = int(input())
a = list(map(int, input().split()))
p = sove(n, a)
if p == -1:
	print('NO')
else:
	print('YES')
	print(*p)


def main():
	n = int(input())
	line = [int(i) for i in input().split()]
	(left, right) = (0, 0)
	coor = 0
	x = -1
	flag = True
	i = 0
	while flag and i < n - 1:
		if line[i] - line[i + 1] == -1:
			if coor == right:
				right += 1
			coor += 1
		elif line[i] - line[i + 1] == 1:
			if coor == left:
				left -= 1
			coor -= 1
		else:
			con = abs(line[i] - line[i + 1])
			if x == -1:
				x = con
			elif x != con:
				flag = False
		i += 1
	if x == -1:
		x = max(line)
	if right - left + 1 > x:
		flag = False
	i = 0
	while flag and i < n - 1:
		if line[i] - line[i + 1] == -1:
			if line[i] % x == 0:
				flag = False
		elif line[i] - line[i + 1] == 1:
			if line[i] % x == 1:
				flag = False
		i += 1
	if flag:
		print('YES')
		print(1000000000, x)
	else:
		print('NO')
main()


import sys, math
n = int(input())
a = [int(i) for i in sys.stdin.readline().split()]
b = [1]
c = []
for i in range(n - 1):
	m = abs(a[i] - a[i + 1])
	if m == 0:
		sys.stdout.write('NO')
		exit(0)
	if m not in b and len(b) == 2:
		sys.stdout.write('NO')
		exit(0)
	elif m == 1:
		c.append(max(a[i], a[i + 1]))
	else:
		b.append(m)
k = max(b)
if k != 1:
	for i in c:
		if (i - 1) % k == 0:
			sys.stdout.write('NO')
			exit(0)
sys.stdout.write('YES\n')
sys.stdout.write('1000000000 ' + str(max(b)))


n = int(input())
num = list(map(int, input().split()))
y = []
fl = True
for i in range(len(num) - 1):
	y1 = abs(num[i] - num[i + 1])
	if y1 > 1:
		y.append(y1)
	elif y1 == 0:
		fl = False
if len(y) == 0 and fl:
	print('YES')
	print(10 ** 9, 10 ** 9)
else:
	if fl:
		smth = y[0]
		if len(set(y)) > 1:
			fl = False
		else:
			for i in range(len(num) - 1):
				(a, b) = (num[i], num[i + 1])
				if a > b:
					(a, b) = (b, a)
				if a == b:
					fl = False
					break
				elif abs(a - b) != 1 and a % smth != b % smth:
					fl = False
					break
				elif abs(a - b) == 1 and a % smth == 0 and (b % smth == 1):
					fl = False
					break
	if not fl:
		print('NO')
	elif smth <= 10 ** 9:
		print('YES')
		print(10 ** 9, smth)
	else:
		print('NO')


import os
import sys
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = array()
x = 10 ** 9
y = 1
for i in range(1, n):
	if abs(a[i] - a[i - 1]) > 1:
		y = abs(a[i] - a[i - 1])
ok = True
for i in range(1, n):
	row1 = Ceil(a[i], y)
	row2 = Ceil(a[i - 1], y)
	if row1 == row2:
		if abs(a[i] - a[i - 1]) != 1:
			ok = False
	else:
		if abs(row2 - row1) != 1:
			ok = False
		if a[i] % y != a[i - 1] % y:
			ok = False
if ok:
	print('YES')
	print(x, y)
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
j = 10 ** 9
moves = []
flag = True
for i in range(n - 1):
	if abs(a[i + 1] - a[i]) != 1:
		if j == 10 ** 9:
			j = abs(a[i + 1] - a[i])
		elif j == abs(a[i + 1] - a[i]):
			pass
		else:
			flag = False
			break
if j == 0:
	flag = False
if flag:
	for i in range(n - 1):
		if abs(a[i + 1] - a[i]) == 1:
			if a[i + 1] > a[i]:
				if a[i] % j == 0:
					flag = False
					break
			elif a[i + 1] % j == 0:
				flag = False
				break
if flag:
	print('YES')
	print(10 ** 9, j)
else:
	print('NO')


import math
n = int(input())
a = list(map(int, input().split(' ')))
y = -1
cnt = 0
for i in range(n - 1):
	if abs(a[i + 1] - a[i]) != 1:
		if y == -1:
			y = abs(a[i + 1] - a[i])
		elif y != abs(a[i + 1] - a[i]):
			print('NO')
			exit(0)
if y == -1 or n == 1:
	print('YES')
	print('1000000000 1000000000')
	exit(0)
if y == 0:
	print('NO')
	exit(0)
if y != -1:
	for i in range(n - 1):
		if a[i] % y == 0 and a[i + 1] == a[i] + 1 or (a[i + 1] % y == 0 and a[i] == a[i + 1] + 1):
			print('NO')
			exit(0)
m = max(a)
if m % y == 0:
	x = m // y
else:
	x = m // y + 1
print('YES')
print(str(x) + ' ' + str(y))


def to_xy(v, y):
	v -= 1
	return (v // y, v % y)

def verify(a, y):
	pos = to_xy(a[0], y)
	for v in a[1:]:
		p2 = to_xy(v, y)
		d = sum((abs(pos[k] - p2[k]) for k in range(2)))
		if d != 1:
			return False
		pos = p2
	return True
n = int(input())
a = list(map(int, input().split()))
opts = set()
poss = True
for i in range(1, n):
	d = abs(a[i] - a[i - 1])
	if d == 0:
		poss = False
	if d == 1:
		continue
	opts.add(abs(d))
if not poss or len(opts) >= 2:
	print('NO')
elif len(opts) == 0:
	print('YES')
	print('1 1000000000')
elif len(opts) == 1:
	y = list(opts)[0]
	if verify(a, y):
		print('YES')
		print('1000000000 ' + str(y))
	else:
		print('NO')


n = int(input())
path = [int(r) for r in input().split()]
row_len = 1
for i in range(1, len(path)):
	ap = abs(path[i] - path[i - 1])
	if ap != 1 and ap != 0:
		row_len = ap
		break
path = [x - 1 for x in path]
for i in range(1, len(path)):
	start_x = path[i - 1] // row_len
	start_y = path[i - 1] % row_len
	end_x = path[i] // row_len
	end_y = path[i] % row_len
	ax = abs(start_x - end_x)
	ay = abs(start_y - end_y)
	if ax > 1 or ay > 1 or ax == ay:
		print('NO')
		exit()
print('YES')
print('1000000000 ' + str(row_len))


n = int(input())
walk = list(map(int, input().split()))
MAXN = 1000000000

def solve1():
	for i in range(n - 1):
		if abs(walk[i + 1] - walk[i]) != 1:
			return False
	print('YES')
	print(MAXN, 1)
	return True

def solve2():
	colum = -1
	for i in range(n - 1):
		diff = abs(walk[i + 1] - walk[i])
		if diff != 1:
			if colum == -1:
				colum = diff
			elif colum != diff:
				return False
	if colum <= 0:
		return False
	for i in range(n - 1):
		if abs(walk[i + 1] - walk[i]) == 1 and (walk[i + 1] - 1) // colum != (walk[i] - 1) // colum:
			return False
	print('YES')
	print(MAXN, colum)
	return True
if solve1():
	pass
elif solve2():
	pass
else:
	print('NO')


import math
n = int(input())
a = list(map(int, input().split(' ')))

def mat(a, b, x, y):
	i = a
	j = b
	return i * y + (j + 1)

def valid(mat, curr, next, x, y):
	i = (curr - 1) // y
	j = (curr - 1) % y
	if i < x - 1 and mat(i + 1, j, x, y) == next:
		return True
	if j < y - 1 and mat(i, j + 1, x, y) == next:
		return True
	if i > 0 and mat(i - 1, j, x, y) == next:
		return True
	if j > 0 and mat(i, j - 1, x, y) == next:
		return True
	return False
max_diff = 0
for i in range(n - 1):
	if abs(a[i] - a[i + 1]) > max_diff:
		max_diff = abs(a[i] - a[i + 1])
y = max_diff
if y != 0:
	x = math.ceil(max(a) / y)
if max_diff == 0:
	flag = False
elif x > 1000000000 or y > 1000000000 or max_diff == 0:
	flag = False
else:
	flag = True
	for c in range(n - 1):
		curr = a[c]
		next = a[c + 1]
		if curr == next or valid(mat, curr, next, x, y) == False:
			flag = False
			break
if n == 1:
	x = 1
	y = a[0]
	flag = True
if flag == False:
	print('NO')
else:
	print('YES')
	print(x, y)


while True:
	try:

		def solution(n, a):
			diff = set()
			for i in range(n - 1):
				if abs(a[i] - a[i + 1]) == 0:
					print('NO')
					return
				diff.add(abs(a[i] - a[i + 1]))
			if len(diff) > 2:
				print('NO')
				return
			dif = []
			for x in diff:
				dif.append(x)
			dif.sort()
			if len(dif) == 1:
				print('YES')
				print(10 ** 9, dif[0])
				return
			if dif[0] > 1:
				print('NO')
			elif True:
				for i in range(n - 1):
					if abs(a[i] - a[i + 1]) == 1 and (a[i] - 1) // dif[1] != (a[i + 1] - 1) // dif[1]:
						print('NO')
						return
				print('YES')
				print(10 ** 9, dif[1])

		def read():
			n = int(input())
			a = list(map(int, input().split()))
			if n == 1:
				print('YES')
				print(10 ** 9, a[0])
				return
			solution(n, a)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


n = int(input())
A = [int(x) - 1 for x in input().split()]
stay_at_cell = any([A[i] == A[i + 1] for i in range(n - 1)])
found = False
for i in range(n - 1):
	if abs(A[i] - A[i + 1]) != 1:
		found = True
		y = abs(A[i] - A[i + 1])
if stay_at_cell:
	print('NO')
elif not found:
	print('YES')
	print(10 ** 9, 1)
else:
	is_ok = True
	for i in range(len(A) - 1):
		neighbours = []
		if A[i] >= y:
			neighbours += [A[i] - y]
		neighbours += [A[i] + y]
		if A[i] % y != 0:
			neighbours += [A[i] - 1]
		if A[i] % y != y - 1:
			neighbours += [A[i] + 1]
		is_ok = is_ok and A[i + 1] in neighbours
	if is_ok:
		print('YES')
		print(10 ** 9, y)
	else:
		print('NO')


n = int(input())
a = list(map(int, input().split()))
y = 1
for i in range(1, n):
	if y == 1 and abs(a[i] - a[i - 1]) != 1:
		y = abs(a[i] - a[i - 1])
	if abs(a[i] - a[i - 1]) not in [y, 1]:
		print('NO')
		exit(0)
if y == 1:
	print('YES')
	print(10 ** 9, y)
	exit(0)
if y == 0:
	print('NO')
	exit(0)
x = 10 ** 9
xx = a[0] // y + int(a[0] % y != 0)
yy = a[0] - y * (xx - 1)
for i in range(1, n):
	(xxx, yyy) = (xx, yy)
	to = []
	if xx + 1 <= x and y * xx + yy == a[i]:
		xx += 1
	elif xx - 1 >= 1 and y * (xx - 2) + yy == a[i]:
		xx -= 1
	elif yy + 1 <= y and y * (xx - 1) + yy + 1 == a[i]:
		yy += 1
	elif yy - 1 >= 1 and y * (xx - 1) + yy - 1 == a[i]:
		yy -= 1
	if xxx == xx and yyy == yy:
		print('NO')
		exit(0)
print('YES')
print(x, y)


n = int(input())
a = list(map(int, input().split()))
x = 0
y = 0
for (i, el) in enumerate(a[1:]):
	pr = a[i]
	delta = abs(el - pr)
	if delta == 0:
		print('NO')
		exit()
	if delta != 1:
		if y == 0:
			y = abs(el - pr)
		elif y != delta:
			print('NO')
			exit()
if y == 0:
	y = 1
if y != 1:
	x = (a[0] - 1) // y + 1
	for (i, el) in enumerate(a[1:]):
		pr = a[i]
		delta = abs(el - pr)
		if delta == 1:
			if (el - 1) // y != (pr - 1) // y:
				print('NO')
				exit()
		if (el - 1) // y + 1 > x:
			x = (el - 1) // y + 1
	print('YES')
	print(x, y)
else:
	print('YES')
	print(max(a), 1)


n = int(input())
l = [int(x) for x in input().split()]
impossible = False
gaps = set()
for i in range(n - 1):
	gap = abs(l[i + 1] - l[i])
	if gap == 1:
		continue
	elif gap > 1:
		gaps.add(gap)
	else:
		impossible = True
		break
if len(gaps) == 0:
	x = 1
	y = max(l)
elif len(gaps) == 1:
	y = gaps.pop()
	(q, r) = divmod(max(l), y)
	x = q if r == 0 else q + 1
else:
	impossible = True
if not impossible:
	for i in range(n - 1):
		(a, b) = (min(l[i], l[i + 1]), max(l[i], l[i + 1]))
		(q, r) = divmod(a, y)
		ia = q if r == 0 else q + 1
		ja = r if r != 0 else y
		(q, r) = divmod(b, y)
		ib = q if r == 0 else q + 1
		jb = r if r != 0 else y
		if (ib, jb) == (ia + 1, ja) or (ib, jb) == (ia, ja + 1):
			continue
		else:
			impossible = True
			break
if impossible:
	print('NO')
else:
	print('YES')
	print(x, y)


n = int(input())
a = list(map(int, input().split()))
x = max(a)
y = -1
ans = 'YES'
for i in range(n - 1):
	da = abs(a[i + 1] - a[i])
	if da > 1:
		if y == -1:
			y = da
		elif y != da:
			ans = 'NO'
			break
	if da == 0:
		ans = 'NO'
		break
if y == -1:
	y = 1000000000
if ans != 'NO':
	for i in range(n - 1):
		da = abs(a[i + 1] - a[i])
		if (da == 1) & (int((a[i + 1] - 1) / y) != int((a[i] - 1) / y)):
			ans = 'NO'
			break
x = int(max(a) / y) + 1
if n == 1:
	x = a[n - 1]
	y = a[n - 1]
print(ans)
if ans == 'YES':
	print(x, y)


n = int(input())
a = list(map(int, input().split()))
x = 1
for i in range(n - 1):
	if a[i] == a[i + 1]:
		print('NO')
		break
	if abs(a[i] - a[i + 1]) != 1:
		if x == 1:
			x = abs(a[i] - a[i + 1])
		elif abs(a[i] - a[i + 1]) != x:
			print('NO')
			break
else:
	pos = []
	for i in range(n):
		pos.append(((a[i] - 1) % x, (a[i] - 1) // x))
	for i in range(n - 1):
		if abs(pos[i][0] - pos[i + 1][0]) + abs(pos[i][1] - pos[i + 1][1]) != 1:
			print('NO')
			break
	else:
		print('YES')
		print(max(a), x)


n = int(input())
vs = list(map(int, input().split()))
dver = 10 ** 9
dgor = 0
sizex = 1
sizey = 0
res = 'YES'
right = 0
for i in range(len(vs) - 1):
	d = vs[i + 1] - vs[i]
	if d == -1:
		right -= 1
	elif d == 1:
		right += 1
	if d != 1 and d != -1:
		if dver == 10 ** 9:
			dver = abs(d)
		elif abs(d) != dver:
			res = 'NO'
if abs(right) > dver:
	res = 'NO'
sizex = dver
if sizex == 0:
	sizex += 1
sizey = 10 ** 9

def get(y, a):
	py = (a - 1) % y
	px = (a - 1) // y
	return [px, py]
if len(vs) == 1:
	sizex = 1
if res == 'YES' and len(vs) != 1:
	for i in range(len(vs) - 1):
		ar1 = get(sizex, vs[i])
		ar2 = get(sizex, vs[i + 1])
		if abs(ar1[0] - ar2[0]) + abs(ar1[1] - ar2[1]) != 1:
			res = 'NO'
	if res == 'YES':
		print('YES')
		if sizex == 0:
			sizex = 1
		print(sizey, sizex)
elif res == 'YES':
	print(res)
	print(sizey, sizex)
if res == 'NO':
	print('NO')


n = int(input())
a = list(map(int, input().split()))
ans = 1
s = set()
for i in range(n - 1):
	if abs(a[i + 1] - a[i]) != 1:
		s.add(abs(a[i + 1] - a[i]))
if ans == -1 or len(s) > 1 or 0 in s:
	print('NO')
else:
	if len(s) > 0:
		ans = s.pop()
	for i in range(n - 1):
		a1 = min(a[i], a[i + 1])
		a2 = max(a[i], a[i + 1])
		if a2 - a1 == 1 and a1 % ans == 0 and (ans != 1):
			ans = -1
			break
	if ans == -1:
		print('NO')
	else:
		print('YES')
		print(10 ** 9, ans)


n = int(input())
a = list(map(int, input().split()))
diff = 0
failed = False
m = 0
for i in range(len(a) - 1):
	if abs(a[i] == a[i + 1]):
		failed = True
		break
	elif abs(a[i] - a[i + 1]) > 1:
		if diff == 0:
			diff = abs(a[i] - a[i + 1])
		elif abs(a[i] - a[i + 1]) != diff:
			failed = True
			break
	if a[i] > m:
		m = a[i]
if a[-1] > m:
	m = a[-1]
if failed:
	print('NO')
elif diff == 0:
	print('YES')
	print(m, 1)
else:
	for i in range(len(a) - 1):
		if abs(a[i] - a[i + 1]) == 1 and min(a[i], a[i + 1]) % diff == 0:
			failed = True
	if failed:
		print('NO')
	elif m % diff == 0:
		print('YES')
		print(m // diff, diff)
	else:
		print('YES')
		print(m // diff + 1, diff)


def main():
	int(input())
	a = list(map(int, input().split()))
	ds = [i - j for (i, j) in zip(a[1:], a)]
	dss = set((abs(x) for x in ds))
	if 0 in dss:
		return False
	try:
		dss.remove(1)
	except KeyError:
		pass
	if len(dss) > 1:
		return False
	if not dss:
		return (1000000000.0, 1000000000.0)
	y = next(iter(dss))
	for (d, c) in zip(ds, a):
		j = (c - 1) % y
		if d == 1 and j == y - 1:
			return False
		if d == -1 and j == 0:
			return False
	return (1000000000.0, y)
ans = main()
if ans:
	print('YES')
	print('%d %d' % ans)
else:
	print('NO')


n = int(input())
way = list(map(int, input().split()))
(i, f) = (0, 0)
while i + 1 < n and abs(way[i] - way[i + 1]) == 1:
	i += 1
if i == n - 1:
	y = 10 ** 9
else:
	y = abs(way[i] - way[i + 1])
i = 0
while i + 1 < n and f == 0 and (y != 0):
	if abs(way[i] - way[i + 1]) == 1:
		if (way[i] - 1) // y != (way[i + 1] - 1) // y:
			f = 1
	elif y != abs(way[i] - way[i + 1]):
		f = 1
	i += 1
if f == 1 or y == 0:
	print('NO')
else:
	print('YES')
	print(10 ** 9, y)