• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #224 Div2 C

C. Arithmetic Progression
time limit per test 1 second
memory limit per test 256 megabytes
 

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.

Input

The 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.

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 108 or even be negative (see test samples).

Sample test(s)
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
3 
0 3 6
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <stack>
 6 #include <queue>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 #define maxn 1000005
12 int n, m;
13 int a[maxn];
14 int main(){
15     scanf("%d", &n);
16     for (int i = 0; i < n; i++){
17         scanf("%d", &a[i]);
18     }
19     sort(a, a + n);
20     int t = a[0], z = 0;
21     if (n == 1){ printf("-1\n"); return 0; }
22     for (int i = 0; i < n; i++){
23         if (a[i] == t)z++;
24     }
25     if (z == n){ printf("1\n"); printf("%d\n", t); return 0; }
26     int x, y;
27     if (n == 2){
28         x = max(a[0], a[1]);
29         y = min(a[0], a[1]);
30         if ((x - y) % 2 == 1){
31             printf("2\n");
32             printf("%d %d\n", y - (x - y), x + (x - y));
33         }
34         else{
35             printf("3\n");
36             printf("%d %d %d\n", y - (x - y), (x + y) / 2, x + (x - y));
37         }
38         return 0;
39     }
40     int flag = 1;
41     int aa;
42     int d = 1000000000;
43     for (int i = 1; i < n; i++){
44         d = min(d,a[i] - a[i - 1]);
45     }
46     for (int i = 1; i < n; i++){
47         x = a[i] - a[i - 1];
48         if (x!=d){
49             if (x != d&&flag){ t = x; aa = a[i - 1]; flag = 0; continue; }
50             else { printf("0\n"); return 0; }
51         }
52     }
53     if (flag == 0 &&(t % 2 != 0||t==0||t/2!=d)){ printf("0\n"); return 0; }
54     if (flag){
55         printf("2\n");
56         printf("%d %d\n", a[0] - x, a[n - 1] + x);
57         return 0;
58     }
59     printf("1\n");
60     printf("%d\n", aa + t / 2);
61     return 0;
62 }
View Code
posted @ 2014-01-18 02:37  HaibaraAi  阅读(191)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3