that-arithmetic-progression

Everybody knows what an arithmetic progression is. 

Sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.

Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n+1 cards to make an arithmetic progression (Alexander has to use all of his cards).

Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.

Input

The first line contains integer n (1 ≤ n ≤ 10^5) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 10^8.

Output

If Arthur can write infinitely many distinct integers on the card, print on a single line -1.

Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 10^8 or even be negative.

SAMPLE INPUT
3
4 1 7

SAMPLE OUTPUT
2
-2 10

Explanation

Adding both of these numbers makes the sorted sequence in AP.

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
'''
read from stdin:
n
arr (list of n positive integers)

find every integer that when added to the sorted list makes it an arithmetic progression
arr[i+1] == arr[i] + d    with d=const. for all i

write to stdout:
number if integers found
integers found

'''

#!/usr/bin/python2

#read input
n= int(input())
if n > 0:
	arr= list(int(s) for s in input().split())
	arr.sort()

if n <= 1:
	#n == 0: any single number is an ap
	#n == 1: any two numbers are an ap
	print(-1)
elif n == 2:
	#continue at both ends
	#and if the difference is even add the arithmetic mean
	if (arr[1] - arr[0]) % 2 == 0:
		print(3)
		print(2*arr[0] - arr[1], (arr[0] + arr[1]) / 2, 2*arr[1] - arr[0])
	else:
		print(2)
		print(2*arr[0] - arr[1], 2*arr[1] - arr[0])
else:
	#walk from both ends as long as increments stay the same
	#from left
	di= arr[1] - arr[0]
	i= 1
	while i+1 < n and arr[i+1] - arr[i] == di:
		i+= 1
	#from right
	dj= arr[n-1] - arr[n-2]
	j= n - 2
	while j - 1 >= 0 and arr[j] - arr[j-1] == dj:
		j-= 1
	
	if j < i:
		#pointers have crossed meaning di == dj and the sequence
		#already is an ap. continue at both ends
		if di == dj == 0:
			print(1)
			print(arr[0])
		else:
			print(2)
			print(arr[0] - di, arr[n-1] + di)
	elif j == i:
		#overlap can only happen on one of the ends
		if i == 1 and di == 2 * dj:
			#at left end and gap can be closed
			print(1)
			print(arr[0] + dj)
		elif j == n - 2 and dj == 2 * di:
			#at right end and gap can be closed
			print(1)
			print(arr[n-1] - di)
		else:
			#gap cannot be closed
			print(0)
	elif j == i + 1:
		#two ap's on either side of the sequence separated by a gap
		if di == dj and arr[i] + di == arr[j] - dj:
			#gap can be closed
			print(1)
			print(arr[i] + di)
		else:
			#gap cannot be closed
			print(0)
	else:
		print(0)