Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.For example, 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.
InputThe first line contains integer n (1 ≤ n ≤ 105) — 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 108.
OutputIf 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 108 or even be negative (see test samples).
Examples input 3 4 1 7 output 2 -2 10 input 1 10 output -1 input 4 1 3 5 9 output 1 7 input 4 4 3 4 5 output 0 input 2 2 4 output 30 3 6
这道题好伤啊,我还以为按原始输入的序列判断,我想,我曹,这J8也太难了吧,还是读题不细心,看样例不细心啊。贴一下人家思路清晰的代码。
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std ; int a[101200] ; int main() { int n ; while(~scanf("%d",&n)) { for(int i = 0 ; i < n ; i++) scanf("%d",&a[i]) ; if(n == 1) { printf("-1\n") ; continue ; } if(n == 0) { printf("0\n") ; continue ; } sort(a,a + n) ; if(n == 2) { if(a[1] == a[0]) printf("1\n%d",a[0]) ; else if((a[1]-a[0]) % 2 == 0) printf("3\n%d %d %d\n",a[0]-(a[1]-a[0]),(a[1]-a[0])/2+a[0],a[1]+a[1]-a[0]) ; else printf("2\n%d %d\n",a[0]-(a[1]-a[0]),a[1]+a[1]-a[0]) ; } else if(n > 2) { int pos = 0 ; int d = 2100000000 ; for(int i = 0 ; i < n-1 ; i++) { if(a[i+1]-a[i] < d) d = a[i+1]-a[i] ; } int count = 0 ; for(int i = 0 ; i < n-1 ; i++) { if((a[i+1]-a[i] )!= d) { pos = i ; count++ ; } } if(count == 0 && d != 0) printf("2\n%d %d\n",a[0]-d,a[n-1]+d) ; else if(count == 0 && d == 0) printf("1\n%d\n",a[0]) ; else if(count == 1 && (a[pos+1]-a[pos]) == 2*d) printf("1\n%d\n",a[pos]+d) ; else printf("0\n") ; } } return 0 ; }