Problem:
Make a Loop
Taro is playing with a set of toy rail tracks. All of the tracks are arc-shaped with a right central angle (an angle of 90 degrees), but with many different radii. He is trying to construct a single loop using all of them. Here, a set of tracks is said to form a single loop when both ends of all the tracks are smoothly joined to some other track, and all the tracks are connected to all the other tracks directly or indirectly. Please tell Taro whether he can ever achieve that or not.
Tracks may be joined in an arbitrary order, but their directions are restricted by the directions of adjacent tracks, as they must be joined smoothly. For example, if you place a track so that a train enters eastward and turns 90 degrees northward, you must place the next track so that the train enters northward and turns 90 degrees to either east or west (Figure F.1). Tracks may cross or even overlap each other as elevated construction is possible.
Figure F.1. Example of smoothly joining tracks
Input
The input consists of a single test case in the following format.
$n$
$r_1$ ... $r_n$
$n$ represents the number of tracks, which is an even integer satisfying $4 \leq n \leq 100$. Each $r_i$ represents the radius of the $i$-th track, which is an integer satisfying $1 \leq r_i \leq 10000$.
Output
If it is possible to construct a single loop using all of the tracks, print
Yes
; otherwise, print
No
.
Sample Input 1
4
1 1 1 1
Sample Output 1
Yes
Sample Input 2
6
1 3 1 3 1 3
Sample Output 2
Yes
Sample Input 3
6
2 2 1 1 1 1
Sample Output 3
No
Sample Input 4
8
99 98 15 10 10 5 2 1
Sample Output 4
Yes
Possible loops for the sample inputs 1, 2, and 4 are depicted in the following figures.
Figure F.2. Possible loops for the sample inputs

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=10000005,INF=15<<26;

bitset<MAX> dp[105][2];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vi A(N);
    int S=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        S+=A[i];
    }
    if(S&1){
        cout<<"No\n";
        return 0;
    }
    dp[0][0][0]=1;
    for(int i=0;i<N;i++){
        for(int t=0;t<2;t++){
            dp[i+1][t]|=dp[i][t];
            dp[i+1][t^1]|=dp[i][t]<<A[i];
        }
    }
    if(dp[N][0][S/2]){
        vi X,Y;
        int pa=0,now=S/2;
        for(int i=N-1;i>=0;i--){
            if(dp[i][pa][now]){
                Y.pb(i);
            }else{
                X.pb(i);
                pa^=1;
                now-=A[i];
            }
        }
        
        for(int i=0;i<=N;i++){
            for(int t=0;t<2;t++){
                dp[i][t].reset();
            }
        }
        dp[0][0][0]=1;
        for(int i=0;i<si(X);i++){
            for(int t=0;t<2;t++){
                dp[i+1][t]|=dp[i][t];
                dp[i+1][t^1]|=dp[i][t]<<A[X[i]];
            }
        }
        for(int t=0;t<2;t++){
            dp[si(X)][t][0]=0;
            dp[si(X)][t][S/2]=0;
        }
        for(int i=0;i<si(Y);i++){
            for(int t=0;t<2;t++){
                dp[si(X)+i+1][t]|=dp[si(X)+i][t];
                dp[si(X)+i+1][t^1]|=dp[si(X)+i][t]<<A[Y[i]];
            }
        }
        
        if(dp[N][0][S/2]) cout<<"Yes\n";
        else cout<<"No\n";
    }else{
        cout<<"No\n";
    }
    
}
accuracy: 1
time_ms: 180
memory_kb: 254936
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = s; i < (int)(t); i++)
#define rrep(i, s, t) for (int i = (ll)(t) - 1; i >= (int)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define TT template <typename T>
TT using vec = vector<T>;
template <class T1, class T2>
bool chmin(T1 &x, T2 y) { return x > y ? (x = y, true) : false; }
template <class T1, class T2>
bool chmax(T1 &x, T2 y) { return x < y ? (x = y, true) : false; }

struct io_setup {
    io_setup() {
        ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        cout << fixed << setprecision(15);
        srand(time(NULL));
    }
} io_setup;

void solve(){
    int N;
    cin >> N;
    vector<int> R(N);
    rep(i, 0 , N) cin >> R[i];
    if (N % 2 == 1) {
        cout << "No" << endl;
        return;
    }
    int sum = R[0];
    vector dp(2, vector<int>(2 * sum + 1, 0));
    dp[1][R[0] + sum] = 1;
    for (int i = 1; i < N; i++) {
        vector nxt(2, vector<int>(2 * (sum + R[i]) + 1));
        for (int t = 0; t < 2; t++) {
            for (int s = 0; s <= 2 * sum; s++) {
                int v = s - sum;
                nxt[1 ^ t][v + R[i] + (sum + R[i])] += dp[t][s];
                chmin(nxt[1 ^ t][v + R[i] + (sum + R[i])], 2);
                nxt[t][v - R[i] + (sum + R[i])] += dp[t][s];
                chmin(nxt[t][v - R[i] + (sum + R[i])], 2);
            }
        }
        swap(dp, nxt);
        sum += R[i];
    }
    if (dp[0][0 + sum] == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main() {
    solve();
}
accuracy: 1
time_ms: 520
memory_kb: 42508
final_rank: 7

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
using ll = long long;
template<class A, class B> void chmax(A& a, const B& b){ if(a < b) a = b; }
template<class A, class B> void chmin(A& a, const B& b){ if(b < a) a = b; }
using PLL = pair<ll, ll>;
#define rep(i,n) for(ll i=0; i<ll(n); i++)

void testcase(){
    ll N; cin >> N;
    vector<ll> A(N); rep(i,N) cin >> A[i];
    ll S = 0; for(auto a : A) S += a;
    vector<ll> dp0(S+1, 0);
    vector<ll> dp1(S+1, 0);
    dp0[0] = 1;
    for(ll a : A){
        for(ll i=S; i>=a; i--){
            dp0[i] = min<ll>(4, dp0[i] + dp1[i-a]);
            dp1[i] = min<ll>(4, dp1[i] + dp0[i-a]);
        } 
    }
    //for(auto a : dp0){ cout << a; } cout << endl;
    //for(auto a : dp1){ cout << a; } cout << endl;
    if(S%2 == 0 && dp0[S/2] > 2) cout << "Yes\n"; else cout << "No\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef NACHIA
    ll T; cin >> T; rep(t,T){
    #endif
    testcase();
    
    #ifdef NACHIA
    cout << "---------------------" << endl; }
    #endif
    return 0;
}
accuracy: 1
time_ms: 140
memory_kb: 18740
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
int dp[2][5<<17];
int main(){
  cin.tie(0)->sync_with_stdio(0);
  int n;cin>>n;
  int sum=0;
  dp[0][0]=1;
  for(int i=0;i<n;++i){
    int r;cin>>r;
    sum+=r;
    for(int j=500000;r<=j;--j)for(int k=0;k<2;++k){
      dp[1-k][j]+=dp[k][j-r];
      if(4<dp[1-k][j])dp[1-k][j]=4;
    }
  }
  if(sum%2==0&&4<=dp[0][sum/2]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
accuracy: 1
time_ms: 40
memory_kb: 7884
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0)->sync_with_stdio(0);
  int n;cin>>n;
  vector<int>r(n);for(int i=0;i<n;++i)cin>>r[i];
  const int M=500000;
  vector dp(2,vector<short>(M+1));
  dp[0][0]=1;
  for(int i=0;i<n;++i){
      for(int j=M;r[i]<=j;--j){
    for(int k=0;k<2;++k){
        dp[1-k][j]+=dp[k][j-r[i]];
        if(4<dp[1-k][j])dp[1-k][j]=4;
      }
    }
  }
  int sum=0;
  for(int i=0;i<n;++i)sum+=r[i];
  if(sum%2==0&&dp[0][sum/2]>=4){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
accuracy: 1
time_ms: 90
memory_kb: 6000
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++) cin >> a[i];
	if(n%2){
		cout << "No" << endl;
		return 0;
	}
	int sum = 0;
	for(int i = 0;i < n;i++) sum += a[i];
	if(sum%2){
		cout << "No" << endl;
		return 0;
	}
	vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
	dp[0][0] = 1;
	for(int i = 0;i < n;i++){
		vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
		for(int j = 0;j <= sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
			if(j + a[i] <= sum/2 && ndp[j + a[i]][1 - k] < 4) ndp[j + a[i]][1 - k] += dp[j][k];
			if(ndp[j][k] < 4) ndp[j][k] += dp[j][k];
		}
		swap(dp,ndp);
	}
	if(dp[sum/2][0] >= 4) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
accuracy: 1
time_ms: 1640
memory_kb: 57812
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++) cin >> a[i];
	if(n%2){
		cout << "No" << endl;
		return 0;
	}
	int sum = 0;
	for(int i = 0;i < n;i++) sum += a[i];
	if(sum%2){
		cout << "No" << endl;
		return 0;
	}
	vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
	dp[0][0] = 1;
	for(int i = 0;i < n;i++){
		vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
		for(int j = 0;j <= sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
			if(j + a[i] <= sum/2 && ndp[j + a[i]][1 - k] < 4) ;
			if(j + a[i] <= sum/2) ndp[j + a[i]][1 - k] += dp[j][k];
			if(ndp[j][k] < 4) ;
			ndp[j][k] += dp[j][k];
		}
		swap(dp,ndp);
	}
	if(dp[sum/2][0] >= 4) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
accuracy: 0.5
time_ms: 1270
memory_kb: 58152
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++) cin >> a[i];
	if(n%2){
		cout << "No" << endl;
		return 0;
	}
	int sum = 0;
	for(int i = 0;i < n;i++) sum += a[i];
	vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
	dp[0][0] = 1;
	for(int i = 0;i < n;i++){
		vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
		for(int j = 0;j <= sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
			if(j + a[i] <= sum/2 && ndp[j + a[i]][1 - k] < 4) ndp[j + a[i]][1 - k] += dp[j][k];
			if(ndp[j][k] < 4) ndp[j][k] += dp[j][k];
		}
		swap(dp,ndp);
	}
	if(dp[sum/2][0] >= 4) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
accuracy: 0.6290322580645161
time_ms: 1260
memory_kb: 58148
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++) cin >> a[i];
	if(n%2){
		cout << "No" << endl;
		return 0;
	}
	int sum = 0;
	for(int i = 0;i < n;i++) sum += a[i];
	vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
	dp[0][0] = 1;
	for(int i = 0;i < n;i++){
		vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
		for(int j = 0;j <= sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
			if(j + a[i] <= sum/2 && ndp[j + a[i]][1 - k] < 4) ndp[j + a[i]][1 - k] += dp[j][k];
			if(ndp[j][k] < 4) ndp[j][k] += dp[j][k];
		}
		swap(dp,ndp);
	}
	if(dp[sum/2][0] >= 4) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
accuracy: 0.6290322580645161
time_ms: 1640
memory_kb: 57976
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++) cin >> a[i];
	if(n%2){
		cout << "No" << endl;
		return 0;
	}
	int sum = 0;
	for(int i = 0;i < n;i++) sum += a[i];
	vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
	dp[0][0] = 1;
	for(int i = 0;i < n;i++){
		vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
		for(int j = 0;j <= sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
			if(j + a[i] <= sum/2 && ndp[j + a[i]][1 - k] < 4) ndp[j + a[i]][1 - k] += dp[j][k];
			if(ndp[j][k] < 4) ndp[j][k] += dp[j][k];
		}
		swap(dp,ndp);
	}
	if(dp[sum/2][0] >= 3) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
accuracy: 0.532258064516129
time_ms: 1650
memory_kb: 58008
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++) cin >> a[i];
	if(n%2){
		cout << "No" << endl;
		return 0;
	}
	int sum = 0;
	for(int i = 0;i < n;i++) sum += a[i];
	vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
	dp[0][0] = 1;
	for(int i = 0;i < n;i++){
		vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
		for(int j = 0;j < sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
			if(j + a[i] <= sum/2 && ndp[j + a[i]][1 - k] < 4) ndp[j + a[i]][1 - k] += dp[j][k];
			if(ndp[j][k] < 4) ndp[j][k] += dp[j][k];
		}
		swap(dp,ndp);
	}
	if(dp[sum/2][0] >= 3) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
accuracy: 0.04838709677419355
time_ms: 1410
memory_kb: 48072
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) cin >> a[i];
    if(n%2){
        cout << "No" << endl;
        return 0;
    }
    int sum = 0;
    for(int i = 0;i < n;i++) sum += a[i];
    vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
    dp[0][0] = 2;
    for(int i = 0;i < n;i++){
        vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
        for(int j = 0;j < sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
            if(j + a[i] <= sum/2){
                ndp[j + a[i]][1 - k] += dp[j][k];
                if(ndp[j + a[i]][1 - k]>4)ndp[j + a[i]][1 - k]=4;
            }
            ndp[j][k] += dp[j][k];
            if(ndp[j][k] > 4) ndp[j][k]=4;
        }
        swap(dp,ndp);
    }
    if(dp[sum/2][0] >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
accuracy: 0.532258064516129
time_ms: 1270
memory_kb: 58152
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) cin >> a[i];
    if(n%2){
        cout << "No" << endl;
        return 0;
    }
    int sum = 0;
    for(int i = 0;i < n;i++) sum += a[i];
    vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
    dp[0][0] = true;
    for(int i = 0;i < n;i++){
        vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
        for(int j = 0;j < sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
            if(j + a[i] <= sum/2){
                ndp[j + a[i]][1 - k] += dp[j][k];
                if(ndp[j + a[i]][1 - k]>4)ndp[j + a[i]][1 - k]=4;
            }
            ndp[j][k] += dp[j][k];
            if(ndp[j][k] > 4) ndp[j][k]=4;
        }
        swap(dp,ndp);
    }
    if(dp[sum/2][0] >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
accuracy: 0.04838709677419355
time_ms: 1080
memory_kb: 48416
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++) cin >> a[i];
    if(n%2){
        cout << "No" << endl;
        return 0;
    }
    int sum = 0;
    for(int i = 0;i < n;i++) sum += a[i];
    vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
    dp[0][0] = true;
    for(int i = 0;i < n;i++){
        vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
        for(int j = 0;j < sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
            if(j + a[i] <= sum/2 && ndp[j + a[i]][1 - k] < 4) ndp[j + a[i]][1 - k] += dp[j][k];
            if(ndp[j][k] < 4) ndp[j][k] += dp[j][k];
        }
        swap(dp,ndp);
    }
    if(dp[sum/2][0] >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
accuracy: 0.04838709677419355
time_ms: 1090
memory_kb: 48416
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(a) begin(a),end(a)

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++) cin >> a[i];
	if(n%2){
		cout << "No" << endl;
		return 0;
	}
	int sum = 0;
	for(int i = 0;i < n;i++) sum += a[i];
	vector<vector<int>> dp(sum/2 + 1,vector<int>(2));
	dp[0][0] = true;
	for(int i = 0;i < n;i++){
		vector<vector<int>> ndp(sum/2 + 1,vector<int>(2));
		for(int j = 0;j < sum/2;j++)for(int k = 0;k < 2;k++)if(dp[j][k]){
			if(j + a[i] <= sum/2 && ndp[j + a[i]][1 - k] < 4) ndp[j + a[i]][1 - k] += dp[j][k];
			if(ndp[j][k] < 4) ndp[j][k] += dp[j][k];
		}
		swap(dp,ndp);
	}
	if(dp[sum/2][0] >= 3) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
accuracy: 0.04838709677419355
time_ms: 1400
memory_kb: 48308
final_rank: 19

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int SUM = 0;
    rep(i,0,N) cin >> A[i], SUM += A[i];
    if (SUM % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    vector<int> DP0(SUM+1,0), DP1(SUM+1,0);
    DP0[0] = 1;
    rep(i,0,N) {
        vector<int> NDP0(SUM+1,0), NDP1(SUM+1,0);
        rep(j,0,SUM+1) {
            if (DP0[j] > 0) NDP0[j] += DP0[j], NDP1[j+A[i]] += DP0[j];
            if (DP1[j] > 0) NDP1[j] += DP1[j], NDP0[j+A[i]] += DP1[j];
        }
        rep(j,0,SUM+1) chmin(NDP0[j],10), chmin(NDP1[j],10);
        swap(DP0,NDP0), swap(DP1,NDP1);
    }
    cout << (DP0[SUM/2] >= 3 ? "Yes" : "No") << endl;
}
accuracy: 1
time_ms: 310
memory_kb: 18720
final_rank: 6

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

template < class T > vector< T >& operator++(vector< T >& a) { for(T& x : a) x++; return a; }
template < class T > vector< T >& operator--(vector< T >& a) { for(T& x : a) x--; return a; }
template < class T > vector< T >  operator++(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x++; return res; }
template < class T > vector< T >  operator--(vector< T >& a, signed) { vector< T > res = a; for(T& x : a) x--; return res; }

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

int main() {
    int n = in();
    vector<int> a = in(n);

    const int sum_a = sum_of<int>(a);
    if(sum_a % 2 == 1) return print("No");

    vector dp(sum_a / 2 + 1, vector(2, int(0)));
    dp[0][0] = 1;
    for(int i : rep(n)) {
        auto nt = dp;
        for(int x = 0; x <= sum_a / 2; x++) {
            if(x + a[i] <= sum_a / 2) {
                for(int b : {0, 1}) {
                    nt[x + a[i]][b ^ 1] += dp[x][b];
                    chmin(nt[x + a[i]][b ^ 1], 4);
                }
            }
        }
        dp = move(nt);
    }
    print(dp[sum_a / 2][0] == 4 ? "Yes" : "No");
}
accuracy: 1
time_ms: 1820
memory_kb: 57812
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

int is[1000001], is2[1000001];
int main(){
    int n, y, s = 0;
    cin >> n;
    is2[0] = 1;
    for(int i = 0; i < n; i++){
        cin >> y;
        for (int x = s; x >= 0; --x){
            is[x + y] = min(is[x + y] + is2[x], 4);
            is2[x + y] = min(is2[x + y] + is[x], 4);
        }
        s += y;
    }
    if (s % 2){
        cout << "No\n";
    }
    else if (is2[s / 2] < 4){
        cout << "No\n";
    }
    else{
        cout << "Yes\n";
    }
}
accuracy: 1
time_ms: 60
memory_kb: 10804
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

const int mxsiz = 10000 * 100 / 2 + 10;
unsigned char dp0[mxsiz], dp1[mxsiz], ndp0[mxsiz], ndp1[mxsiz];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  int N; cin >> N;
  vector<int> R(N);
  for (int i = 0; i < N; ++i) cin >> R[i];
  
  int Rsum = accumulate(R.begin(), R.end(), 0);
  int Rhalf = Rsum / 2;
  
  if (N & 1 || Rsum & 1)
  {
    cout << "No" << endl;
    return 0;
  }
  
  int siz = Rhalf + 10;
  dp0[0] = 1;
  
  for (int r : R)
  {    
    for (int j = siz; j >= 0; --j)
    {
      if (j - r >= 0)
      {
        dp0[j] += dp1[j-r];
        dp1[j] += dp0[j-r];
      }
      
      if (dp0[j] > 4) dp0[j] = 4;
      if (dp1[j] > 4) dp1[j] = 4;
    }
  }
  
  cout << (dp0[Rhalf] >= 4 ? "Yes" : "No") << endl;
  
  
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4316
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define ll long long
#define elif else if
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int,int>


#define repname(a, b, c, d, e, ...) e
#define rep(...)                    repname(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define rep0(x)                     for (int rep_counter = 0; rep_counter < (x); ++rep_counter)
#define rep1(i, x)                  for (int i = 0; i < (x); ++i)
#define rep2(i, l, r)               for (int i = (l); i < (r); ++i)
#define rep3(i, l, r, c)            for (int i = (l); i < (r); i += (c))





struct ScalarInput {
    template<class T>
    operator T(){
        T ret;
        cin >> ret;
        return ret;
    }
};
struct VectorInput {
    size_t n;
    VectorInput(size_t n): n(n) {}
    template<class T>
    operator vector<T>(){
        vector<T> ret(n);
        for(T &x : ret) cin >> x;
        return ret;
    }
};
ScalarInput input(){ return ScalarInput(); }
VectorInput input(size_t n){ return VectorInput(n); }

template<typename T>
void print(vector<T> a){
  for(int i=0;i<a.size();i++){
    cout<<a[i]<<" \n"[i+1==a.size()];
  }
}

template<class T>
void print(T x){
    cout << x << '\n';
}
 
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail){
  cout << head << ' ';
  print(forward<Tail>(tail)...);
}

int dp0[2000100],dp1[2000100],ndp0[2000100],ndp1[2000100];
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin>>n;
  if(n%2==1){
    print("No");
    exit(0);
  }

  int m=10000*n+10;
  dp0[m]=1;

  rep(i,n){
    int ai;
    cin>>ai;
    rep(j,2*m){
      ndp0[j]=0;
      ndp1[j]=0;
    }
    rep(j,2*m){
      if(j+ai<2*m){
        ndp1[j+ai]+=dp0[j];
        ndp0[j+ai]+=dp1[j];
      }
      if(j-ai>=0){
        ndp0[j-ai]+=dp0[j];
        ndp1[j-ai]+=dp1[j];
      }
    }
    rep(j,2*m){
      dp0[j]=min(4,ndp0[j]);
      dp1[j]=min(4,ndp1[j]);
    }
  }
  if(dp0[m]>=4)print("Yes");
  else print("No");
}
accuracy: 1
time_ms: 740
memory_kb: 34704
final_rank: 8