-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path444c.cpp
More file actions
164 lines (138 loc) · 3.69 KB
/
444c.cpp
File metadata and controls
164 lines (138 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//sidcodes
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef priority_queue<int, vector<int>, greater<int>> pqmin;
#define endl '\n'
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define fr(i,n) for(int i=0;i<n;i++)
#define pyes cout<<"YES\n"
#define pno cout<<"NO\n"
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
typedef vector<vll> vvll;
const int MOD = 1e9+7;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << " = "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(long double t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(unsigned long long t) {cerr << t;}
void _print(long long t) {cerr << t;}
template <class T, class V> void _print(pair<T, V> p);
template <class T> void _print(vector<T> v);
template <class T> void _print(set<T> v);
template <class T, class V> void _print(map<T, V> v);
template <class T> void _print(multiset<T> v);
template <class T, class V> void _print(pair<T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector<T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set<T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset<T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map<T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
vector<ll> fact, invfact;
ll modpow(ll a, ll b, ll mod = MOD) {
ll res = 1;
while (b) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
void init_nck(int maxn){
fact.assign(maxn+1, 1);
invfact.assign(maxn+1, 1);
for(int i = 1; i <= maxn; i++)
fact[i] = (fact[i-1] * i) % MOD;
invfact[maxn] = modpow(fact[maxn], MOD - 2);
for(int i = maxn-1; i >= 0; i--)
invfact[i] = (invfact[i+1] * (i+1)) % MOD;
}
ll nck(ll n, ll r){
if(r < 0 || r > n) return 0;
return (((fact[n] * invfact[r]) % MOD) * invfact[n-r]) % MOD;
}
vector<vll> adj;
vll depth, parent, sub;
vector<vll> dp;
void dfs(ll u, ll p) {
parent[u] = p;
sub[u] = 1;
for (auto v : adj[u]) {
if (v == p) continue;
depth[v] = depth[u] + 1;
dfs(v, u);
sub[u] += sub[v];
}
}
void solve() {
ll n;
cin>>n;
vll v(n);
fr(i,n) cin>>v[i];
set<ll>s(all(v));
if(s.size()==1){
cout<<v[0];
return;
}
sort(all(v));
set<ll> ans;
// c1 L not in arr
if(n%2==0){
set<ll> temp;
ll i=0;
ll j=n-1;
while(i<j){
temp.insert(v[i]+v[j]);
i++;
j--;
}
if(temp.size()==1){
ans.insert(v[0]+v[n-1]);
}
}
// in arr
ll i=0;
ll j=n-1;
ll mx=v[n-1];
bool poss=1;
while(i<j){
if(v[j]==mx){
j--;
continue;
}
else if(v[i]+v[j]!=mx){
poss=0;
break;
}
i++;
j--;
}
if(poss) ans.insert(mx);
for(auto i:ans) cout<<i<<" ";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}