malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     string s;     cin >> s;     string ss = s;     int iter = 0;     int total = 0;     while (true) {       int cnt = 0;       for (int i = 1; i < n; i++)         if (s[i - 1] ==  R  && s[i] ==  L ) {           s[i - 1] =  L ;           s[i] =  R ;           cnt++;           i++;         }       if (cnt == 0) break;       iter++;       total += cnt;     }     if (k < iter || k > total) {       cout << -1 << endl;       return 0;     }     s = ss;     int slow = k - iter;     while (true) {       int cnt = 0;       vector<int> res;       for (int i = 1; i < n; i++)         if (s[i - 1] ==  R  && s[i] ==  L ) {           s[i - 1] =  L ;           s[i] =  R ;           cnt++;           if (slow > 0) {             slow--;             cout <<  1   << i <<   n ;           } else {             res.push_back(i);           }           i++;         }       if (cnt == 0) break;       if (res.size() > 0) {         cout << res.size();         for (int i = 0; i < res.size(); i++) cout <<     << res[i];         cout <<   n ;       } else {         slow++;       }     }     cout.flush();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     int v[N];     for (int i = 0; i < N; i++) {       cin >> v[i];     }     vector<int> quadr;     for (int i = 0; 1; i++) {       if (i > sqrt(INT_MAX)) {         break;       }       quadr.push_back(i * i);     }     int dist[N];     vector<int> minDiffs;     int contQuadr = 0;     for (int i = 0; i < N; i++) {       int curr = v[i];       int index = upper_bound(quadr.begin(), quadr.end(), curr) - quadr.begin();       int l = abs(curr - quadr[index]);       int r = l;       if (index - 1 >= 0) r = abs(curr - quadr[index - 1]);       int minDiff = min(l, r);       if (minDiff == 0) contQuadr++;       minDiffs.push_back(minDiff);     }     if (contQuadr == N / 2) {       cout << 0;       return 0;     }     if (contQuadr < N / 2) {       int diff = N / 2 - contQuadr;       sort(minDiffs.begin(), minDiffs.end());       long long int res = 0;       int i = 0;       int cont = 0;       while (diff > 0 && i < N) {         if (minDiffs[i] == 0) {           i++;           continue;         }         res += minDiffs[i];         i++;         diff--;       }       cout << res;       return 0;     }     if (contQuadr > N / 2) {       long long int diff = contQuadr - N / 2;       long long int res = 0;       int costs[N];       memset(costs, 0, N * sizeof(int));       for (int i = 0; i < N; i++) {         if (v[i] == 0) {           costs[i] = 2;           continue;         }         if (minDiffs[i] == 0) {           costs[i] = 1;         }       }       sort(costs, costs + N);       for (int i = 0; i < N && diff > 0; i++) {         if (costs[i] == 0) continue;         res += costs[i];         diff--;       }       cout << res;       return 0;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   char a[N], b[N];   int main() {     int n, k;     cin >> n >> k;     scanf( %s %s , a + 1, b + 1);     long long ans = 0, t = 1;     for (int i = 1; i <= n; ++i) {       t = t * 2;       if (b[i] ==  a ) t--;       if (a[i] ==  b ) t--;       if (t > k) t = k + 1;       ans += (t > k ? k : t);     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   class FenwickTree {    private:     vector<T> bit;     int M;       public:     FenwickTree(int M) : bit(vector<T>(M + 1, 0)), M(M) {}     int sum(int i) {       if (!i) return 0;       return bit[i] + sum(i - (i & -i));     }     void add(int i, T x) {       if (i > M) return;       bit[i] += x;       add(i + (i & -i), x);     }   };   int main() {     ios::sync_with_stdio(false);     int N;     cin >> N;     vector<int> X1(N), X2(N), Y1(N), Y2(N);     map<int, int> Yc;     set<int> Ys;     vector<int> YI;     map<int, vector<int>> Ha, He;     map<int, vector<pair<int, int>>> V, H;     set<int> cand;     YI.push_back(-1 << 30);     for (int i = 0; i < N; ++i) {       int x1, x2, y1, y2;       cin >> x1 >> y1 >> x2 >> y2;       if (x2 < x1) swap(x1, x2);       if (y2 < y1) swap(y1, y2);       YI.push_back(y1 - 1);       YI.push_back(y1);       YI.push_back(y1 + 1);       YI.push_back(y2 - 1);       YI.push_back(y2);       YI.push_back(y2 + 1);       X1[i] = x1, X2[i] = x2, Y1[i] = y1, Y2[i] = y2;     }     sort((YI.begin()), (YI.end()));     YI.erase(unique(YI.begin(), YI.end()), YI.end());     for (int i = 0; i < N; ++i) {       Y1[i] = lower_bound((YI.begin()), (YI.end()), Y1[i]) - YI.begin();       Y2[i] = lower_bound((YI.begin()), (YI.end()), Y2[i]) - YI.begin();       if (X1[i] == X2[i]) {         V[X1[i]].push_back({Y1[i], Y2[i]});         cand.insert(X1[i]);       } else {         Ha[X1[i]].push_back(Y1[i]);         He[X2[i]].push_back(Y1[i]);         H[Y1[i]].push_back({X1[i], X2[i]});         cand.insert(X1[i]);         cand.insert(X2[i]);       }     }     FenwickTree<signed long long> bt(YI.size());     signed long long ret = 0;     for (auto cx : cand) {       for (auto y : Ha[cx])         if (Yc[y]++ == 0) bt.add(y, 1);       if (V.count(cx)) {         vector<pair<int, int>>& T = V[cx];         sort((T.begin()), (T.end()));         int ma = -1 << 30;         for (auto r : T) {           r.first = max(r.first, ma + 1);           if (r.first > r.second) continue;           ret += YI[r.second] - YI[r.first] + 1;           ret -= bt.sum(r.second) - bt.sum(r.first - 1);           ma = r.second;         }       }       for (auto y : He[cx])         if (--Yc[y] == 0) bt.add(y, -1);     }     for (auto hy : H) {       vector<pair<int, int>>& T = hy.second;       sort((T.begin()), (T.end()));       int ma = -1 << 30;       for (auto r : T) {         r.first = max(r.first, ma + 1);         if (r.first > r.second) continue;         ret += r.second - r.first + 1;         ma = r.second;       }     }     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 777;   vector<int> G[maxn];   map<int, int> savesiz[maxn];   int siz[maxn];   vector<int> ans;   int n;   void dfs(int s, int fa) {     siz[s] = 1;     int cnt = 0;     for (int d : G[s]) {       if (d == fa) continue;       dfs(d, s);       savesiz[s][siz[d]]++;       cnt++;       siz[s] += siz[d];     }     if (n - siz[s] > 0) {       savesiz[s][n - siz[s]]++;       cnt++;     }     if (savesiz[s].size() == 1 && cnt >= 2) ans.push_back(s);   }   vector<int> aans;   map<int, int> have[maxn];   void func(int s) {     int nowsiz = 1;     int nowid = G[s][0];     int fa = s;     while (G[nowid].size() == 2) {       nowsiz++;       if (G[nowid][0] == fa) {         fa = nowid;         nowid = G[nowid][1];       } else {         fa = nowid;         nowid = G[nowid][0];       }     }     if (have[nowid].count(nowsiz)) return;     if (have[nowid].size() >= 2) return;     have[nowid][nowsiz] = 1;     if ((savesiz[nowid][nowsiz] == 1 && savesiz[nowid].size() == 2) ||         savesiz[nowid].size() == 1) {       aans.push_back(s);     }   }   set<int> se[maxn];   int vis[maxn];   bool ck(int s) {     for (int i = 0; i <= n; i++) {       se[i].clear();       vis[i] = 0;     }     queue<pair<int, int> > q;     vis[s] = 1;     q.push(make_pair(s, 0));     while (!q.empty()) {       int nowid = q.front().first;       int nowdis = q.front().second;       q.pop();       se[nowdis].insert(G[nowid].size());       if (se[nowdis].size() >= 2) return false;       for (int d : G[nowid]) {         if (vis[d]) continue;         vis[d] = 1;         q.push(make_pair(d, nowdis + 1));       }     }     return true;   }   void solve() {     scanf( %d , &n);     if (n == 1) {       cout << 1 << endl;       return;     }     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);     }     dfs(1, 1);     for (int iid : ans) {       if (ck(iid)) {         cout << iid << endl;         return;       }     }     for (int i = 1; i <= n; i++) {       if (G[i].size() == 1) {         func(i);       }     }     for (int iid : aans) {       if (ck(iid)) {         cout << iid << endl;         return;       }     }     cout << -1 << endl;   }   signed main() { solve(); }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const int maxn = (int)1e4 + 10;   int a[maxn], b[maxn];   int main() {     int n, c;     cin >> n >> c;     if (c < n) {       cout << 0 << endl;       return 0;     }     c -= n;     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];     }     int m = 0;     for (int i = 0; i < n; i++)       if (a[i] != 0) {         a[m] = a[i];         b[m] = b[i];         m++;       }     if (m == 0) {       if (c == 0) {         cout << -1 << endl;       } else {         cout << 0 << endl;       }       return 0;     }     long long least = 0;     for (int i = 0; i < m; i++) {       least += a[i] / b[i];     }     if (least > c) {       cout << 0 << endl;       return 0;     }     long long lf = 0;     long long rg = (long long)1e18;     while (lf < rg - 1) {       long long mm = (lf + rg) >> 1;       double sum = 0.0;       for (int i = 0; i < m; i++) {         sum += floor(a[i] * 1.0 / b[i] * mm + eps);         if (sum >= c) break;       }       if (sum >= c) {         rg = mm;       } else {         lf = mm;       }     }     long long sum = 0;     for (int i = 0; i < m; i++) {       sum += (long long)(a[i] * 1.0 / b[i] * rg + eps);     }     if (sum > c) {       cout << 0 << endl;       return 0;     }     int res = (int)1e9 + 10;     for (int i = 0; i < m; i++) {       int ost = a[i] % b[i] * 1LL * (rg % b[i]) % b[i];       res = min(res, 1 + (b[i] - ost) / a[i] - ((b[i] - ost) % a[i] == 0));     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)15e4 + 10, M = 310;   int n, m, d;   long long a[N], b[N], t[N], tmp[N], dp[2][N];   inline void f(int j) {     long long k = 1ll * (t[j] - t[j - 1]) * d;     int r = j % 2;     deque<int> deq;     for (int i = 0; i < n; i++) {       while (deq.size() && dp[!r][deq.back()] <= dp[!r][i]) deq.pop_back();       deq.push_back(i);       while (deq.front() < i - k) deq.pop_front();       tmp[i] = dp[!r][deq.front()];     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> d;     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> t[i];       a[i]--;     }     for (int i = 0; i < n; i++) dp[0][i] = b[0] - abs(a[0] - i);     for (int j = 1; j < m; j++) {       int r = j % 2;       f(j);       for (int i = 0; i < n; i++) dp[r][i] = tmp[i];       reverse(dp[!r], dp[!r] + n);       f(j);       for (int i = 0; i < n; i++) dp[r][i] = max(dp[r][i], tmp[n - 1 - i]);       for (int i = 0; i < n; i++) dp[r][i] += b[j] - abs(a[j] - i);     }     m--;     cout << *max_element(dp[m % 2], dp[m % 2] + n);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops ,  omit-frame-pointer ,  inline )   #pragma GCC optimize(3)   using namespace std;   const long long INF = 1e17;   const long long maxn = 1e5 + 700;   const int mod = 998244353;   const int up = 1e9;   template <typename T>   inline void read(T &a) {     char c = getchar();     T x = 0, f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     a = f * x;   }   long long n, m, p;   int num[maxn];   struct node {     int tag, w, l, r;   } t[maxn * 40];   int root[maxn * 40];   int cnt = 0;   void Modify(int &now, int pre, int l, int r, int x, int y, int w) {     t[now = ++cnt] = t[pre];     if (x <= l && y >= r) {       t[now].tag += w;       t[now].w += w;       return;     }     int mid = (l + r) / 2;     if (x <= mid) Modify(t[now].l, t[pre].l, l, mid, x, y, w);     if (y > mid) Modify(t[now].r, t[pre].r, mid + 1, r, x, y, w);     int ls = t[now].l, rs = t[now].r;     t[now].w = min(t[ls].w, t[rs].w) + t[now].tag;   }   int Query(int now, int l, int r, int id, int tag, int k) {     if (l == r) return l;     int mid = (l + r) / 2;     if (mid < id) return Query(t[now].r, mid + 1, r, id, tag + t[now].tag, k);     int ls = t[now].l, rs = t[now].r;     return t[rs].w + tag + t[now].tag > k                ? Query(ls, l, mid, id, tag + t[now].tag, k)                : Query(rs, mid + 1, r, id, tag + t[now].tag, k);   }   int work(int x) {     int s = 1, ans = 0;     while (s <= n) {       s = Query(root[s], 1, n, s, 0, x) + 1;       ans++;     }     return ans;   }   int last[maxn];   int main() {     read(n);     for (int i = 1; i <= n; i++) read(num[i]);     for (int i = n; i >= 1; i--) {       int up = last[num[i]] ? last[num[i]] - 1 : n;       Modify(root[i], root[i + 1], 1, n, i, up, 1);       last[num[i]] = i;     }     for (int i = 1; i <= n; i++) printf( %d  , work(i));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000000], ans[1000000];   int n, k, p, x, y, sum = 0;   int main() {     cin >> n >> k >> p >> x >> y;     for (int i = 1; i <= k; i++) {       cin >> a[i];       sum += a[i];     }     if (sum + n - k > x) {       cout << -1;       return 0;     }     for (int i = k + 1; i <= n; i++) {       a[i] = y;       sum += y;     }     int id = k + 1;     while (sum > x) {       if (a[id] == 1) {         id++;         continue;       }       a[id]--;       sum--;     }     int c = 0;     for (int i = k + 1; i <= n; i++) ans[c++] = a[i];     sort(a + 1, a + n + 1);     if (a[(n + 1) / 2] < y)       cout << -1;     else {       for (int i = 0; i < c; i++) cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   inline bool check(int x) {     long long t = (long long)x * (long long)(x - 1) / 2;     if (x & 1)       t++;     else       t += x / 2;     return t <= N;   }   int main() {     int M;     scanf( %d%d , &N, &M);     vector<int> A;     for (int i = 0; i < M; i++) {       int x;       scanf( %*d%d , &x);       A.push_back(x);     }     sort(A.begin(), A.end(), greater<int>());     int lb = 1, rb = M;     while (lb < rb) {       int mid = (lb + rb + 1) >> 1;       if (check(mid))         lb = mid;       else         rb = mid - 1;     }     long long ans = 0;     for (int i = 0; i < lb; i++) ans += A[i];     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     cin >> x;     string names[x * 2];     for (int i = 0; i < x * 2; i++) cin >> names[i];     for (int i = 0; i < x * 2; i++)       if (names[i] ==  rat ) {         cout << names[i - 1];         cout << endl;       }     for (int i = 0; i < x * 2; i++)       if (names[i] ==  woman  || names[i] ==  child ) {         cout << names[i - 1];         cout << endl;       }     for (int i = 0; i < x * 2; i++)       if (names[i] ==  man ) {         cout << names[i - 1];         cout << endl;       }     for (int i = 0; i < x * 2; i++)       if (names[i] ==  captain ) {         cout << names[i - 1];         cout << endl;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   struct EDGE {     int u, v, w;   } p[100000 + 5];   struct Edge {     int v, w, next;   } edge[100000 + 5];   int head[100000 + 5], cnt = 0;   void init() {     cnt = 0;     memset(head, -1, sizeof head);   }   void add_edge(int u, int v, int w) {     edge[cnt].v = v;     edge[cnt].w = w;     edge[cnt].next = head[u];     head[u] = cnt++;   }   int vis[100000 + 5];   int rd[100000 + 5];   bool check(int up) {     memset(rd, 0, sizeof rd);     memset(vis, 0, sizeof vis);     queue<int> que;     for (int i = 1; i <= m; i++)       if (p[i].w > up) rd[p[i].v]++;     int tot = 0;     while (1) {       for (int u = 1; u <= n; u++)         if (!vis[u] && rd[u] == 0) que.push(u);       if (que.empty()) break;       while (!que.empty()) {         int u = que.front();         que.pop();         vis[u] = ++tot;         for (int i = head[u]; i != -1; i = edge[i].next)           if (!vis[edge[i].v] && edge[i].w > up) rd[edge[i].v]--;       }     }     for (int u = 1; u <= n; u++)       if (!vis[u]) return 0;     return 1;   }   int main() {     if (1 && fopen( in.txt ,  r )) {       freopen( in.txt ,  r , stdin);       freopen( out.txt ,  w , stdout);     }     init();     scanf( %d%d , &n, &m);     int l = 0, r = 0, mid;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &p[i].u, &p[i].v, &p[i].w);       add_edge(p[i].u, p[i].v, p[i].w);       r = max(r, p[i].w);     }     while (l < r) {       mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     int ans = l;     vector<int> ansque;     check(ans);     for (int i = 1; i <= m; i++) {       int u = p[i].u, v = p[i].v;       if (p[i].w <= ans && vis[u] > vis[v]) ansque.push_back(i);     }     sort(ansque.begin(), ansque.end());     printf( %d %d n , ans, ansque.size());     for (int i = 0; i < ansque.size(); i++)       printf( %d%c , ansque[i], i == ansque.size() - 1 ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, a[150];     scanf( %d , &n);     int sum = 0;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     int ans = 0;     for (i = 0; i < n; i++) (sum % 2) ^ ((a[i] + 1) % 2) ? ans++ : ans = ans;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     int mini = INT_MAX;     cin >> a >> b;     int az = a.size();     for (int i = -2000; i <= az; i++) {       int ans = b.size();       for (int j = 0; j < b.size(); j++) {         ans -= (i + j >= 0 && i + j < a.size() && a[i + j] == b[j]);       }       mini = min(mini, ans);     }     cout << mini;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct line {     int k;     int b;     long double x;   } line;   bool com(line l1, line l2) {     if (l1.x < l2.x)       return true;     else       return false;   }   int main() {     long long k, b, n, t;     cin >> k >> b >> n >> t;     long long x = 1;     int t1 = 0;     while (x < t) {       x = k * x + b;       t1++;     }     if (x != t) t1--;     if (t1 < n) {       cout << n - t1;     } else       cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   struct Edge {     int to, nxt;   } e[N << 1];   int h[N], idx;   void Ins(int a, int b) {     e[++idx].to = b;     e[idx].nxt = h[a];     h[a] = idx;   }   int bas, f[N], g[N], to[N], n, siz[N], Mx[N], mk[N], sec[N];   void dfs(int u, int fa) {     siz[u] = 1;     for (int i = h[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       dfs(v, u);       siz[u] += siz[v];       if (Mx[u] < siz[v]) Mx[u] = siz[v], to[u] = v;       if (siz[v] <= bas) {         if (g[u] < siz[v]) {           sec[u] = g[u];           g[u] = siz[v];           mk[u] = v;         } else if (sec[u] < siz[v]) {           sec[u] = siz[v];         }       } else {         if (g[v] > g[u]) {           sec[u] = g[u];           g[u] = g[v];           mk[u] = v;         } else if (g[v] > sec[u])           sec[u] = g[v];       }     }     if (Mx[u] < n - siz[u]) {       Mx[u] = n - siz[u];       to[u] = fa;     }   }   void dfs2(int u, int fa) {     if (Mx[u] <= bas)       f[u] = 1;     else if (to[u] != fa)       f[u] = (Mx[u] - g[to[u]]) <= bas;     else {       if (mk[fa] == u) {         f[u] = (Mx[u] - sec[fa]) <= bas;       } else         f[u] = (Mx[u] - g[fa]) <= bas;     }     if (mk[fa] == u) {       if (sec[fa] > g[u]) {         sec[u] = g[u];         g[u] = sec[fa];         mk[u] = fa;       } else if (sec[fa] > sec[u]) {         sec[u] = sec[fa];       }       int w = n - siz[u];       if (w <= bas) {         if (w > g[u]) {           sec[u] = g[u];           g[u] = w;           mk[u] = fa;         } else if (w > sec[u]) {           sec[u] = w;         }       }     } else {       if (g[fa] > g[u]) {         sec[u] = g[u];         g[u] = g[fa];         mk[u] = fa;       } else if (g[fa] > sec[u])         sec[u] = g[fa];       int w = n - siz[u];       if (w <= bas) {         if (w > g[u]) {           sec[u] = g[u];           g[u] = w;           mk[u] = fa;         } else if (w > sec[u]) {           sec[u] = w;         }       }     }     for (int i = h[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       dfs2(v, u);     }   }   int main() {     scanf( %d , &n);     bas = n >> 1;     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       Ins(a, b);       Ins(b, a);     }     dfs(1, 0);     dfs2(1, 0);     for (int i = 1; i <= n; i++) printf( %d  , f[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   int main() {     int n;     cin >> n >> ws;     char s[1001];     scanf( %s , &s);     int h = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  H ) h++;     }     int _min = INF;     for (int i = 0; i < n; i++) {       int ans = 0;       for (int j = 0; j < h; j++) {         if (s[(i + j) % n] ==  T ) ans++;       }       _min = min(ans, _min);     }     cout << _min;     return 0;   }
#include <bits/stdc++.h>   using ll = long long;   using ld = long double;   using ull = unsigned long long;   using namespace std;   const int N = 10;   int T, n, a[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> T;     while (T--) {       cin >> n;       for (int i = (0); i <= (n - 1); ++i) cin >> a[i];       sort(a, a + n);       bool ok = 0;       for (int i = (0); i <= (n - 1); ++i) {         if (a[i] == 0 || (i > 0 && a[i] == a[i - 1])) ok = 1;       }       for (int i = (0); i <= (n - 1); ++i) {         for (int j = (0); j <= (n - 1); ++j)           if (a[j] == -a[i]) {             ok = 1;             break;           }         for (int x = (0); x <= ((1 << n) - 1); ++x)           if (!(x >> i & 1)) {             for (int mask = x;; mask = (mask - 1) & x) {               int sum = 0;               for (int j = (0); j <= (n - 1); ++j)                 if (x >> j & 1) {                   if (mask >> j & 1)                     sum += a[j];                   else                     sum -= a[j];                 }               if (sum == a[i]) {                 ok = 1;                 break;               }               if (mask == 0) break;             }           }       }       cout << (ok ?  YES n  :  NO n );     }     return 0;   }