#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("! ") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf(" ") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int n; int mp[100005]; int main() { int i,j; while(sf("%d",&n)==1) { mem(mp,0); for(i=0;i<n;i++) { sf("%d",&mp[i]); } sort(mp,mp+n); if(n==1) { pf("-1 "); continue; } if(n==2) { int d = mp[1]-mp[0]; if(d==0) { pf("1 %d ",mp[0]); } else if(d%2==0) { pf("3 %d %d %d ",mp[0]-d,mp[0]+d/2,mp[1]+d); } else { pf("2 %d %d ",mp[0]-d,mp[1]+d); } } if(n==3) { int d = mp[1]-mp[0]; int d2 = mp[2]-mp[1]; if(d==d2) { pf("2 %d %d ",mp[0]-d,mp[2]+d); } else if(d==d2*2) pf("1 %d ",mp[0]+d2); else if(d*2==d2) pf("1 %d ",mp[1]+d); else pf("0 "); } if(n>3) { int cnt=0,cnt2=0,find=0,d2,ok=1,x; int d = mp[1]-mp[0]; for(i=0;i<n-1;i++) { int tmp = mp[i+1]-mp[i]; if(d==tmp) cnt++; else { if(!find) { d2=tmp; find=1; x = i; } if(tmp==d2) cnt2++; else { ok=0;break; } } } if(!ok) { pf("0 "); continue; } if(cnt==n-1) { pf("2 %d %d ",mp[0]-d,mp[n-1]+d); } else if(cnt==n-2) { if(d2==d*2) { pf("1 %d ",mp[x]+d); } else pf("0 "); } else { if(d==d2*2) { pf("1 %d ",mp[0]+d2); } else pf("0 "); } } } }
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <cctype> #include <vector> #include <iterator> #include <set> #include <map> #include <sstream> using namespace std; #define mem(a,b) memset(a,b,sizeof(a)) #define pf printf #define sf scanf #define spf sprintf #define pb push_back #define debug printf("! ") #define INF 10000 #define MAXN 5010 #define MAX(a,b) a>b?a:b #define blank pf(" ") #define LL long long #define ALL(x) x.begin(),x.end() #define INS(x) inserter(x,x.begin()) #define pqueue priority_queue int n; int a[100005]; map<int,int> mp; int main() { int i,j; while(sf("%d",&n)==1) { mp.clear(); for(i=0;i<n;i++) { sf("%d",&a[i]); mp[a[i]]++; } map<int,int>::iterator it; int res[3],cnt=0,ok=0; for(it=mp.begin();it!=mp.end();it++) { if(it->second) { res[cnt++] = it->first; it->second--; if(cnt==3) { pf("%d %d %d ",res[2],res[1],res[0]); cnt=0; ok=1; it = mp.begin(); } } } if(!ok) pf("0 "); } }