#include <bits/stdc++.h>
#pragma optimize("g", on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
void Freopen () {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
using namespace std;
#define fi first
#define se second
// #define int long long
const int N = 250000 + 7, M = 250000, mod = 1e9 + 7;
int n, a[N];
bitset<N> dp[507];
void knapsack(vector<int> v, int bs) {
dp[bs][0] = 1;
for(auto j : v) {
dp[bs] |= (dp[bs] << j);
}
}
void solve() {
cin>>n;
vector<int> vec;
for(int i = 1; i <= n; i++) {
cin>>a[i];
vec.push_back(a[i]);
}
int need = accumulate(a + 1, a + 1 + n, 0ll);
if(need % 2 == 1) {
cout << "0\n";
return;
}
need /= 2;
knapsack(vec, 0);
if(!dp[0][need]) {
cout << "0\n";
return;
}
for(int i = 1; i <= n; i++) {
vector<int> vec;
for(int j = 1; j <= n; j++) {
if(i != j)vec.push_back(a[j]);
}
knapsack(vec, i);
}
vector<int> ans;
for(int i = 1; i <= M; i++) {
bool an = 1;
for(int j = 1; j <= n; j++) {
int W = need * 2 + i - a[j];
if(W % 2 == 1) {
an = 0;
break;
}
if(!dp[j][W / 2] || !dp[j][W / 2 - i]) {
an = 0;
break;
}
}
if(an)ans.push_back(i);
}
cout << ans.size() << '\n';
for(auto j : ans)cout << j << ' ';
cout << '\n';
}
signed main() {
// freopen("duty.in", "r", stdin);
// freopen("duty.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//Freopen();
int T = 1;
// cin>>T;
while(T --)solve();
}
/*
please AC
*/
Compilation message (stderr)
bootfall.cpp: In function 'void Freopen()':
bootfall.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |