stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<vector>

using namespace std;

int n,tot;

const int N=200010;

int head[N],to[N<<1],nt[N<<1],ans[N],mx[N],fa[N],son[N],sf[N],sub[N];

vector<int>v[N];

void add(int f,int t)

{

	to[++tot]=t;nt[tot]=head[f];head[f]=tot;

}

namespace DSU

{

	int fa[N],siz[N];

	void YYCH(){for(int i=1;i<=n;++i)fa[i]=i,siz[i]=1;}

	int find(int x){return x==fa[x]?fa[x]:fa[x]=find(fa[x]);}

	void he(int x,int y)

	{	

		x=find(x);y=find(y);if(x==y)return;

		fa[x]=y;siz[y]+=siz[x];

	}

}

void dfs1(int x,int fa)

{

	::fa[x]=fa;mx[x]=max(mx[fa],fa);sf[x]=son[mx[x]];

	for(int i=head[x];i;i=nt[i])

		if(to[i]!=fa)son[x]=to[i],dfs1(to[i],x);

}

void dfs2(int x,int fa)

{

	if(fa)ans[x]+=ans[mx[x]]-sub[son[mx[x]]]+1;

	for(int i=head[x];i;i=nt[i])

		if(to[i]!=fa)son[x]=to[i],dfs2(to[i],x);

}

int main()

{

	cin>>n;DSU::YYCH();

	for(int i=1,x,y;i<n;++i)

		scanf("%d%d",&x,&y),add(x,y),add(y,x);

	dfs1(1,0);

	for(int i=2;i<=n;++i)v[mx[i]].push_back(i);

	

	for(int i=1;i<=n;++i)

	{

		for(int j=0,siz=v[i].size();j<siz;++j)

		{

			int x=v[i][j];

			if(x<i)ans[x]=DSU::siz[DSU::find(x)]-1;

			else

			{

				if(x!=sf[x])ans[x]+=DSU::siz[DSU::find(sf[x])];

				for(int k=head[x];k;k=nt[k])

					if(to[k]!=fa[x]&&to[k]<i)

					{

						sub[to[k]]=DSU::siz[DSU::find(to[k])];

						ans[x]+=sub[to[k]];

					}

			}

		}

		for(int j=head[i];j;j=nt[j])

			if(to[j]<i)DSU::he(i,to[j]);

	}

	dfs2(1,0);

	for(int i=2;i<=n;++i)printf("%d ",ans[i]);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int N=500005;

struct ab{int f,t;} t[N];

int h,hh[N],vv[N],ans[N];

void make(int x,int y)

{

	t[++h].f=hh[x];

	t[h].t=y;

	hh[x]=h;

}

int dfs1(int x,int y,int z)

{

	if(x>z) return 0;

	int now=1;

	for(int i=hh[x];i;i=t[i].f)

	{

		int j=t[i].t;

		if(j==y) continue;

		now+=dfs1(j,x,z);

	}

	return now;

}

int dfs2(int x,int y,int z)

{

	int now=1;

	for(int i=hh[x];i;i=t[i].f)

	{

		int j=t[i].t;

		if(j==y) continue;

		if(j<z) now+=dfs2(j,x,z);

	}

	return now;

}

void dfs(int x,int y,int z,int v)

{

	if(x>z) v+=dfs2(x,y,z);

	ans[x]=v;

	for(int i=hh[x];i;i=t[i].f)

	{

		int j=t[i].t;

		if(j==y) continue;

		if(x>z) dfs(j,x,x,v+dfs1(j,x,x)-dfs1(j,x,z));

		else dfs(j,x,z,v);

	}

}

int main()

{

	int n;

	scanf("%d",&n);

	for(int i=1;i<n;i++)

	{

		int x,y;

		scanf("%d%d",&x,&y);

		make(x,y),make(y,x);

	}

	dfs(1,0,0,0);

	for(int i=2;i<=n;i++) printf("%d ",ans[i]-1);printf("\n");

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define MAX_V 100000

#define INF 1<<29

using namespace std;

struct edge{int to,cap,rev;};

vector<edge>G[MAX_V];

int level[MAX_V];

int iter[MAX_V];

void add_edge(int from,int to,int cap){

  G[from].push_back((edge){to,cap,(int)G[to].size()});

  G[to].push_back((edge){from,0,(int)G[from].size()-1});

}

void bfs(int s){

  memset(level,-1,sizeof(level));

  queue<int>q;

  level[s]=0;

  q.push(s);

  while(!q.empty()){

    int v=q.front();q.pop();

    for(int i=0;i<(int)(G[v].size());i++){

      edge &e=G[v][i];

      if(e.cap>0&&level[e.to]<0){

        level[e.to]=level[v]+1;

        q.push(e.to);

      }

    }

  }

}

int dfs(int v,int t,int f){

  if(v==t)return f;

  for(int &i=iter[v];i<(int)(G[v].size());i++){

    edge &e=G[v][i];

    if(e.cap>0&&level[v]<level[e.to]){

      int d=dfs(e.to,t,min(f,e.cap));

      if(d>0){

        e.cap-=d;

        G[e.to][e.rev].cap+=d;

        return d;

      }

    }

  }

  return 0;

}

int max_flow(int s,int t){

  int flow=0;

  while(1){

    bfs(s);

    if(level[t]<0)return flow;

    memset(iter,0,sizeof(iter));

    int f;

    while((f=dfs(s,t,INF))>0){

      flow+=f;

    }

  }

}

int main(){

  int x,y,n,s,t;

  vector<pair<int,int>> A,B;

  cin>>n;

  x=n;

  y=n;

  for(int i=0;i<n;i++){

  	cin>>s>>t;

  	A.push_back({s,t});

  }

  for(int i=0;i<n;i++){

  	cin>>s>>t;

  	B.push_back({s,t});

  }

  for(int i=0;i<n;i++){

  	for(int j=0;j<n;j++){

  		if(A[i].first<B[j].first&&A[i].second<B[j].second){

  			add_edge(i+1,n+j+1,1);

  		}

  	}

  }

  for(int i=0;i<y;i++){

  	add_edge(x+i+1,x+y+1,1);

  }

  for(int i=0;i<x;i++){

  	add_edge(0,i+1,1);

  }

  cout<<max_flow(0,x+y+1)<<endl;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 115;

int a[maxn], b[maxn], a1[maxn], b1[maxn];

int  v[maxn], match[maxn];

int n;

vector < int > g[maxn];

bool dfs(int x)

{

	int y;

	for(int i = 0; i < g[x].size(); i++){

		y = g[x][i];

		if(!v[y]){

			v[y] = 1;

			if(!match[y] || dfs(match[y])){

				match[y] = x;

				return true;

			}

		}

	}

	return false;

}

int main()

{

	scanf("%d", &n);

	for(int i = 1; i <= n; i++){

		scanf("%d %d", a + i, b + i);

	}

	for(int i = 1; i <= n; i++){

		scanf("%d %d", a1 + i, b1 + i);

	}

	for(int i = 1; i <= n; i++){

		for(int j = 1; j <= n; j++){

			if(a[i] < a1[j] && b[i] < b1[j]){

				g[i].push_back(j);

			}

		}

	}

//	for(int i = 1; i <= n; i++){

//		for(int j = 1; j <= n; j++){

//			printf("%d ", g[i][j]);

//		}

//		printf("\n");

//	}

	int ans = 0;

	for(int i  = 1; i <= n; i++){

		memset(v, 0, sizeof(v));

		if(dfs(i))ans++;

	}

	printf("%d", ans);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int n, m, p;

vector<tuple<int, int, int>> edges;

vector<int> graph[2500];

vector<int> reverse_graph[2500];



bool can_reach_rev[2500];

bool can_reach[2500];



int coins[2500];



void dfs(int u) {

  if (can_reach[u]) {

    return;

  }

  can_reach[u] = true;

  for (int v : graph[u]) {

    dfs(v);

  }

}



void reverse_dfs(int u) {

  if (can_reach_rev[u]) {

    return;

  }

  can_reach_rev[u] = true;

  for (int v : reverse_graph[u]) {

    reverse_dfs(v);

  }

}



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0);

  cin >> n >> m >> p;



  for (int i = 0; i < n; i++) {

    coins[i] = INT_MIN/2;

  }



  for (int i = 0; i < m; i++) {

    int a, b, c;

    cin >> a >> b >> c;

    c -= p;

    a -= 1;

    b -= 1;

    graph[a].emplace_back(b);

    reverse_graph[b].emplace_back(a);

    edges.emplace_back(a, b, c);

  }

  dfs(0);

  reverse_dfs(n - 1);



  coins[0] = 0;

  for (int i = 0; i < n; i++) {

    for (auto t : edges) {

      int u, v, c;

      tie(u, v, c) = t;

      if (can_reach[u] && can_reach_rev[v]) {

        if (coins[u] + c > coins[v]) {

          coins[v] = coins[u] + c;

        }

      }

    }

  }

  for (auto t : edges) {

    int u, v, c;

    tie(u, v, c) = t;

    if (can_reach[u] && can_reach_rev[v]) {

      if (coins[u] + c > coins[v]) {

        printf("-1\n");

        return 0;

      }

    }

  }

  printf("%d\n", max(coins[n - 1], 0));

}

// Optimized solution to the same problem (faster):
// problem: longest distance from 0 to V-1, checking for positive cycle only on this path

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll INF = 1 << 30;



struct Tadj {

	int id, w;

};

vector<vector<Tadj>> adjList;

int V;



vector<ll> ld;



vector<bool> visited;

void dfs(int u) {

   if (visited[u]) return;

   visited[u] = 1;

   for (Tadj v : adjList[u])

      dfs(v.id);

}



/* O(V*E) - retorna true se há um ciclo positivo entre 0 e V-1 */

bool belmman_ford(int s) {

   ld.assign(V, -INF); ld[s] = 0;



   ll first0, first1;

   for (int i = 0; i < V; i++) {

      // para cada aresta u --v.w--> v.id

      for (int u = 0; u < V; u++)

         for (Tadj v : adjList[u]) {

            if (ld[u] + v.w > ld[v.id] && ld[u] > -INF) {

               ld[v.id] = ld[u] + v.w;



               // se ainda conseguiu relaxar depois das V-1 vezes anteriores

               if (i == V-1) {

                  visited.assign(V, 0);

                  dfs(v.id);

                  if (visited[0] || visited[V-1]) return true;

               }

            }

         }

   }



   return false;

}



int main() {

   int E, P; cin >> V >> E >> P;

   adjList.assign(V, vector<Tadj>());

   while (E--) {

      int u, v, w; cin >> u >> v >> w; u--; v--; w -= P;

      adjList[u].push_back({v, w});

   }



   cout << (belmman_ford(0)? -1 : max(ld[V-1], 0ll)) << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)

#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)

#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)

#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)



/*

*/



ll n,m,p,dp[2510],dp2[2510],t;

vector<ll> v[2510],c[2510];



void init(){

	cin>>n>>m>>p;

	rep(i,m){

		ll a,b,x;

		cin>>a>>b>>x;

		v[a].push_back(b);

		c[a].push_back(x-p);

	}

	reg(i,1,n){

		dp[i]=-1e18;

		dp2[i]=-1e18;

	}

	dp[1]=0;

}



int main(void){

	init();

	reg(cnt,1,2*n){

		reg(i,1,n){

			rep(j,v[i].size()){

				if(dp2[v[i][j]]<dp[i]+c[i][j]){

					dp2[v[i][j]]=dp[i]+c[i][j];

				}

			}

		}

		if(cnt==n-1)t=dp2[n];

		reg(i,1,n)dp[i]=dp2[i];

	}

	if(dp[n]>t){

		cout<<-1<<endl;

	}else{

		cout<<max(t,0LL)<<endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)

#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)

#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)

#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)





// from: https://atcoder.jp/contests/abc137/submissions/6831647

template<typename T>

struct BellmanFord{

	struct edge{

		int u,v;

		T w;

		edge(){}

		edge(int u,int v,T w):u(u),v(v),w(w){}

	};



	int n;

	vector< vector<int> > G,Ginv;

	vector<int> reach;

	BellmanFord(int n):n(n),G(n),Ginv(n),reach(n,0){}



	vector<edge> es;

	void add_edge(int u,int v,T c){

		es.emplace_back(u,v,c);

		G[u].emplace_back(v);

		Ginv[v].emplace_back(u);

	}



	void dfs(int v){

		if(reach[v]) return;

		reach[v]=1;

		for(int u:Ginv[v]) dfs(u);

	}



	T build(int from,int to,int &neg_loop){

		dfs(n-1);

		const T INF = numeric_limits<T>::max();

		vector<T> ds(n,INF);

		ds[from]=0;

		for(int j=0;j<n;j++){

			bool update=0;

			for(auto e:es){

				if(!reach[e.u]||!reach[e.v]||ds[e.u]==INF) continue;

				if(ds[e.v]>ds[e.u]+e.w){

					ds[e.v]=ds[e.u]+e.w;

					update=1;

				}

			}

			if(!update) break;

			if(j==n-1){

				neg_loop=1;

				return INF;

			}

		}

		neg_loop=0;

		return ds[to];

	}

};



ll n,m,p,ans;



int main(){

	cin>>n>>m>>p;

	BellmanFord<ll> f(n);

	rep(i,m){

		ll a,b,x;

		cin>>a>>b>>x;

		f.add_edge(a-1,b-1,p-x);

	}

	int neg_loop;

	ans = f.build(0,n-1,neg_loop);

	cout<<(neg_loop?-1:max(-ans,0LL))<<endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define MAX 5050

#define INF (1LL<<60LL)

typedef pair<int,int> P;

int V;

struct edge2{

  int from,to,cost;

  edge2(){}

  edge2(int from,int to,int cost):from(from),to(to),cost(cost){}

};

edge2 es[MAX];

int d[MAX];

int ok[MAX];

int used[MAX];

int shortest_path(int s,int e){

  for(int i=0;i<V;i++) d[i]=INF;

  d[s]=0;

  for(int j=0;j<V;j++){

    bool update=0;

    for(int i=0;i<e;i++){

      edge2 e=es[i];

      if(!ok[e.from]||!ok[e.to]) continue;

      if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){

        d[e.to]=d[e.from]+e.cost;

        update=1;

      }

    }

    if(!update) break;

    if(j==V-1){

      cout<<-1<<endl;

      exit(0);

    }

  }

  return d[V-1];

}



vector<int> G[MAX];

void dfs2(int v){

  if(used[v]) return;

  used[v]=1;

  for(int u:G[v]){

    dfs2(u);

  }

}



signed main(){

  int v,e,p;

  cin>>v>>e>>p;

  for(int i=0;i<e;i++){

    int u,v,d;

    cin>>u>>v>>d;u--;v--;

    G[u].push_back(v);

    es[i]=edge2(u,v,p-d);

  }

  for(int i=0;i<v;i++){

    memset(used,0,sizeof(used));

    dfs2(i);

    ok[i]=used[v-1];

  }

  V=v;

  cout<<max<int>(-shortest_path(0,e),0)<<endl;

  return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}

template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}



//INSERT ABOVE HERE

template<typename T>

struct BellmanFord{

  struct edge{

    int u,v;

    T w;

    edge(){}

    edge(int u,int v,T w):u(u),v(v),w(w){}

  };



  int n;

  vector< vector<int> > G;

  vector<int> used,reach;

  BellmanFord(int n):n(n),G(n),used(n,0),reach(n,0){}



  vector<edge> es;

  void add_edge(int u,int v,T c){

    es.emplace_back(u,v,c);

    G[u].emplace_back(v);

  }



  void dfs(int v){

    if(used[v]) return;

    used[v]=1;

    for(int u:G[v]) dfs(u);

  }



  T build(int from,int to,int &neg_loop){

    for(int i=0;i<n;i++){

      fill(used.begin(),used.end(),0);

      dfs(i);

      reach[i]=used[to];

    }

    const T INF = numeric_limits<T>::max();

    vector<T> ds(n,INF);

    ds[from]=0;

    for(int j=0;j<n;j++){

      bool update=0;

      for(auto e:es){

        if(!reach[e.u]||!reach[e.v]||ds[e.u]==INF) continue;

        if(ds[e.v]>ds[e.u]+e.w){

          ds[e.v]=ds[e.u]+e.w;

          update=1;

        }

      }

      if(!update) break;

      if(j==n-1){

        neg_loop=1;

        return INF;

      }

    }

    neg_loop=0;

    return ds[to];

  }



};

signed main(){

  int n,m,p;

  cin>>n>>m>>p;

  BellmanFord<int> G(n);

  for(int i=0;i<m;i++){

    int a,b,c;

    cin>>a>>b>>c;

    a--;b--;

    G.add_edge(a,b,p-c);

  }

  int neg_loop;

  int res=G.build(0,n-1,neg_loop);

  if(neg_loop){

    cout<<-1<<endl;

    return 0;

  }

  cout<<max(-res,0)<<endl;

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <queue>

#include <set>

#include <map>

#include <string.h>

#include <cmath>



using namespace std;

typedef long long i64;

typedef long double ld;

typedef pair<i64,i64> P;

#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))



int n;



i64 c[1010];

i64 w[1010];



i64 sum[1010];



int dp[1010][1010];



int main()

{

	cin >> n;

	rep(i,0,n - 1)

		cin >> c[i] >> w[i];



	rep(i,1,n)

	{

		sum[i] = sum[i - 1] + w[i - 1];

	}



	auto getsum = [&](int l,int r){

		return sum[r] - sum[l];

	};



	rep(i,0,1000) rep(j,0,1000) dp[i][j] = 1e9;



	rep(i,0,1000)

		dp[i][i + 1] = 1;

	

	rep(w,2,n)

	{

		rep(l,0,n - 1)

		{

			//[l,r)

			int r = l + w;

			if(r > n) continue;



			rep(mid,l + 1,r - 1)

			{

				dp[l][r] = min(dp[l][r] , dp[l][mid] + dp[mid][r]);

			}



			//left is mighty

			{



				i64 w_s = getsum(l + 1,r);

				if(c[l] >= w_s && dp[l + 1][r] == 1)

				{

					dp[l][r] = 1;

				}

			}

			{

				i64 w_s = getsum(l,r - 1);

				if(c[r - 1] >= w_s && dp[l][r - 1] == 1)

				{

					dp[l][r] = 1;

				}

			}

			/*

			rep(i,0,n)

			{

				if(l <= i && i < r)

					cout << "=";

				else

					cout << " ";

			}

			cout << dp[l][r] << endl;

			*/

		}



	}



	cout << dp[0][n] << endl;



}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

#define all(x) x.begin(),x.end()



int N;



i64 dp[1010][1010];

vector<i64> c,w;



i64 ret[1010];



int main(){

  cin >> N;

  c.resize(N + 1);

  w.resize(N + 1);

  rep(i,1,N) cin >> c[i] >> w[i];

  rep(i,1,N) w[i] += w[i - 1];





  rep(i,1,N) dp[i][i] = 1;

  for(int d = 1;d <= N;d++){

    for(int l = 1;l + d <= N;l++){

      int r = l + d;

      if(dp[l][r - 1] == 1 && (w[r - 1] - w[l - 1]) <= c[r]){

        dp[l][r] = 1;

      }

      if(dp[l + 1][r] == 1 && (w[r] - w[l + 1 - 1]) <= c[l]){

        dp[l][r] = 1;

      }

    }

  }



  for(int i = 1;i <= N;i++) ret[i] = 1e9;

  for(int i = 1;i <= N;i++){

    for(int j = i;j <= N;j++){

      if(dp[i][j] == 1){

        ret[j] = min(ret[j] , ret[i - 1] + 1);

      }

    }

  }



  cout << ret[N] << endl;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define REP(i,n,N) for(int i=n;i<N;i++)

#define p(S) cout<<(S)<<endl

using namespace std;

int dp[1001][1001];

int w[100010],c[100010];

int sumw[100010];

int main(){

	int n;

	cin>>n;

	REP(i,0,n) {

		cin>>c[i]>>w[i];

		if(i>0)	sumw[i]=sumw[i-1]+w[i];

		else sumw[i]=w[i];

	}

	REP(i,0,1001) REP(j,i,1001) dp[i][j]=j-i+1;

	REP(i,0,n-1)  if(c[i]>=w[i+1]||c[i+1]>=w[i]) dp[i][i+1]=1;





	for(int k=2;k<n;k++){

		for(int i=0;i+k<n;i++){

			if((dp[i+1][i+k]==1&&c[i]>=sumw[i+k]-sumw[i])||(dp[i][i+k-1]==1&&c[i+k]>=sumw[i+k-1]-(i?sumw[i-1]:0)))

				dp[i][i+k]=1;

			else dp[i][i+k]=min(dp[i+1][i+k],dp[i][i+k-1])+1;



			for(int j=i+1;j<i+k;j++)

				dp[i][i+k]=min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]);

		}

	}

	p(dp[0][n-1]);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define REP(i,n,N) for(int i=n;i<N;i++)

#define p(S) cout<<(S)<<endl

using namespace std;

int dp[1001][1001];

int w[1001],c[1001];

int sumw[1001];

int main(){

	int n;

	cin>>n;

	cin>>c[0]>>w[0];

	sumw[0]=w[0];

	REP(i,1,n) {

		cin>>c[i]>>w[i];

		sumw[i]=sumw[i-1]+w[i];

	}

	REP(i,0,n) REP(j,i,n) dp[i][j]=j-i+1;

	REP(i,0,n-1)  if(c[i]>=w[i+1]||c[i+1]>=w[i]) dp[i][i+1]=1;



	for(int k=2;k<n;k++){

		for(int i=0;i+k<n;i++){

			if((dp[i+1][i+k]==1&&c[i]>=sumw[i+k]-sumw[i])||(dp[i][i+k-1]==1&&c[i+k]>=sumw[i+k-1]-(i?sumw[i-1]:0)))

				dp[i][i+k]=1;

			for(int j=i+1;j<i+k;j++)

				dp[i][i+k]=min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]);

		}

	}

	p(dp[0][n-1]);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



bool solve(int i, int m);

int n, q, A[2000], m[2000];



int main()

{

	using namespace std;

	cin >> n;

	for (int i = 0; i < n; i++)

	{

		cin >> A[i];

	}

	cin >> q;

	for (int i = 0; i < q; i++)

	{

		cin >> m[i];

	}

	for (int i = 0; i < q; i++)

	{

		if (solve(0, m[i]))

		{

			cout << "yes\n";

		}

		else

		{

			cout << "no\n";

		}

	}

	return 0;

}



bool solve(int i, int m)

{

	if (m == 0)

	{

		return true;

	}

	if (i >= n)

	{

		return false;

	}

	return solve(i + 1, m) || solve(i + 1, m - A[i]);

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>



int n, A[50], dp[21][2001];



int solve(int i, int m)

{

  if (dp[i][m] != -1)

  {

    return dp[i][m];

  }



  if (m == 0)

    dp[i][m] = 1;

  else if (i >= n)

    dp[i][m] = 0;

  else if (solve(i + 1, m))

    dp[i][m] = 1;

  else if (solve(i + 1, m - A[i]))

    dp[i][m] = 1;

  else

    dp[i][m] = 0;



  return dp[i][m];

}



int main()

{

  scanf("%d", &n);

  for (int i = 0; i < n; i++)

  {

    scanf("%d", &A[i]);

  }

  int q, m;

  scanf("%d", &q);

  for (int i = 0; i < q; i++)

  {

    memset(dp, -1, sizeof(dp));

    scanf("%d", &m);

    if (solve(0, m) != 0) printf("yes\n");

    else printf("no\n");

  }

  return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>



using namespace std;



int A[20], N;



bool exhaustiveSearch(int m, int s, int n){

    if(n==N+1) return false;//it's over

    if(s==m) return true;



    if (exhaustiveSearch(m,s,n+1)) {

        return true;

    }else

    {

        return exhaustiveSearch(m,s+A[n],n+1);

    }

}



int main(){

    int i,q;

    cin >> N;

    for(i=0;i<N;i++) cin>>A[i];

    cin>>q;

    for(i=0;i<q;i++){

        int m;

        cin >> m;

        exhaustiveSearch(m,0,0)?cout<<"yes":cout<<"no";

        cout<<endl;

    }

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int A[20], N;



bool exhaustiveSearch(int m, int s, int n){

    if(n==N+1) return false;//it's over

    if(s==m) return true;



    if (exhaustiveSearch(m,s,n+1)) {

        return true;

    }else

    {

        return exhaustiveSearch(m,s+A[n],n+1);

    }

}



int main(){

    int i,q;

    scanf("%d",&N);

    for(i=0;i<N;i++) scanf("%d",&A[i]);

    scanf("%d",&q);

    for(i=0;i<q;i++){

        int m;

        scanf("%d",&m);

        exhaustiveSearch(m,0,0)?printf("yes\n"):printf("no\n");

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long int

#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)

#define REP(i,n) FOR(i,0,n)

#define REP1(i,n) FOR(i,1,n)

using namespace std;

 

int A[50], n, memo[50][500];

 

int solve (int i, int m) {

  

  if (m == 0) 

    memo[i][m] = 1;

  else if (i >= n) 

    memo[i][m] = 0;

  else if (solve(i + 1, m))

    memo[i][m] = 1;

  else if (solve(i + 1, m - A[i])) 

    memo[i][m] = 1;

  else 

    memo[i][m] = 0;



  return memo[i][m];

}

 

int main(){

  REP(i, 50) {

    REP(j, 500) {

      memo[i][j] = -1;

    }

  }

  int q, M;

  cin >> n;

  REP(i, n) {

    cin >> A[i];

  }

  cin >> q;

  REP(i, q) {

    cin >> M;

    if (solve(0, M)) cout << "yes" << endl;

    else cout << "no" << endl;

  }

 

  return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define ll long long int

#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)

#define REP(i,n) FOR(i,0,n)

#define REP1(i,n) FOR(i,1,n)

using namespace std;

 

int A[50], n;

 

int solve (int i, int m) {

  if (m == 0) return 1;

  if (i >= n) return 0;

  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);

  return res;

}

 

int main(){

  int q, M;

  cin >> n;

  REP(i, n) {

    cin >> A[i];

  }

  cin >> q;

  REP(i, q) {

    cin >> M;

    if (solve(0, M)) cout << "yes" << endl;

    else cout << "no" << endl;

  }

 

  return 0;

}

// Fastest known solution for this problem: