malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, sg, m, k;     cin >> n >> sg >> m >> k;     vector<int> a(n), starts(n, n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < sg; i++) {       int l, r;       cin >> l >> r;       l--;       r--;       starts[r] = min(starts[r], l);     }     auto bldPrefCnt = [&](int x) {       vector<int> res(n);       int cur = 0;       for (int i = 0; i < n; i++) {         if (a[i] <= x) {           cur++;         }         res[i] = cur;       }       return res;     };     auto check = [&](int x) {       auto prefs = bldPrefCnt(x);       vector<int> sufMem(n, -1);       map<int, int> sufL;       for (int i = 0; i < n; i++) {         int l = starts[i];         if (l == n) {           continue;         }         auto itL = sufL.lower_bound(l);         if (itL != sufL.end()) {           sufMem[i] = itL->first;         }         while (sufL.size() > 0 && l <= sufL.rbegin()->second) {           sufL.erase(prev(sufL.end()));         }         sufL[i] = l;       }       vector<vector<int>> dp(n, vector<int>(m + 1, 0));       int best = 0;       vector<int> prefMx(n);       for (int j = 1; j <= m; j++) {         vector<int> nxtPrefMx(n);         for (int i = 0; i < n; i++) {           auto &cur = dp[i][j];           if (starts[i] < n) {             int l = starts[i];             if (l > 0) {               cur = (prefs[i] - prefs[l - 1]) + prefMx[l - 1];             } else {               cur = prefs[i];             }             int u = sufMem[i];             if (u != -1) {               int take = prefs[i] - prefs[u];               cur = max(cur, take + dp[u][j - 1]);             }           }           nxtPrefMx[i] =               (i > 0 && nxtPrefMx[i - 1] > cur) ? nxtPrefMx[i - 1] : cur;           best = max(best, cur);         }         prefMx = nxtPrefMx;       }       return best >= k;     };     int l = 0, r = 1e9 + 10;     int ans = -1;     if (check(r)) {       while (l < r) {         int mid = (l + r) / 2;         if (check(mid)) {           r = mid;         } else {           l = mid + 1;         }       }       ans = r;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int w[40];   int main() {     int m, n;     cin >> m >> n;     for (int i = 1; i <= n; i++) {       cout << 1 << endl;       cin >> w[i];       if (w[i] == 0) {         return 0;       }     }     int l = 1, r = m;     int index = 1;     while (l <= r) {       int mid = (l + r) / 2;       cout << mid << endl;       int q;       cin >> q;       if (q == 0) return 0;       if (q == w[(index - 1) % n + 1]) {         l = mid + 1;       } else {         r = mid;       }       index++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   const int INF = 0x3F3F3F3F;   const int MOD = 1000003;   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   vector<vector<char> > mat;   int n, m;   bool isvalid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   int main() {     cin >> n >> m;     mat.resize(n);     for (int i = 0; i < n; i++) {       mat[i].resize(m);       for (int j = 0; j < m; j++) {         cin >> mat[i][j];       }     }     bool flag = 0;     int num = 0;     for (int i = 0; i < n; i++) {       if (flag) break;       bool l[2] = {0};       for (int j = 0; j < m; j++) {         if (mat[i][j] ==  . ) continue;         if (mat[i][j] ==  1  || mat[i][j] ==  2 ) {           l[j & 1] = 1;         } else {           l[(j + 1) & 1] = 1;         }       }       if (l[0] && l[1]) flag = 1;       if (!l[0] && !l[1]) num++;     }     for (int j = 0; j < m; j++) {       if (flag) break;       bool u[2] = {0};       for (int i = 0; i < n; i++) {         if (mat[i][j] ==  . ) continue;         if (mat[i][j] ==  1  || mat[i][j] ==  4 ) {           u[i & 1] = 1;         } else {           u[(i + 1) & 1] = 1;         }       }       if (u[0] && u[1]) flag = 1;       if (!u[0] && !u[1]) num++;     }     if (flag) {       cout << 0 << endl;       return 0;     }     int ans = 1;     for (int i = 0; i < num; i++) {       ans = (ans * 2) % MOD;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, cnt = 0;     cin >> n;     long long ar[n];     for (i = 0; i < n; i++) cin >> ar[i];     for (i = 0; i < n; i++) {       if (ar[i] % 2 != 0) cnt++;     }     cout << min(cnt, n - cnt);   }
#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     sort(arr.begin(), arr.end());     vector<int> fst;     for (int i = 0; i < (n / 2); i++) fst.push_back(arr[i]);     vector<int> snd;     for (int i = (n / 2); i < n; i++) snd.push_back(arr[i]);     int hidden = 0;     int j = 0;     for (int i = 0; i < fst.size(); i++) {       while (j < snd.size() && snd[j] < 2 * fst[i]) j++;       if (j == snd.size()) break;       hidden++;       j++;     }     cout << n - hidden <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> nxt[1 << 13], G[15];   vector<pair<int, int> > lca[13];   bool a[14][14], ok[14][1 << 13];   long long int dp[14][1 << 13][2];   int n;   long long int solve(int root, int mask, int check) {     if (check == 0) {       int i;       for (i = 0; i < lca[root].size(); i++) {         int x = lca[root][i].first, y = lca[root][i].second;         if ((mask & (1 << x)) == 0 && x != root) return 0;         if ((mask & (1 << y)) == 0 && y != root) return 0;       }     }     long long int &ret = dp[root][mask][check];     if (ret != -1) return ret;     if (mask == 0) return ret = 1;     ret = 0;     int i, j, k;     for (i = 0; i < nxt[mask].size(); i++) {       int newmask = nxt[mask][i];       if (!ok[root][newmask]) continue;       int msb = -1, ch = -1;       for (k = 0; k < n; k++) {         if (mask & (1 << k)) msb = k;         if ((newmask & (1 << k)) && a[root][k]) {           if (ch == -1)             ch = k;           else             ch = -2;         }       }       if (ch == -2 || (newmask & (1 << msb)) == 0) continue;       if (ch == -1) {         for (k = 0; k < n; k++) {           if (newmask & (1 << k))             ret +=                 solve(k, newmask ^ (1 << k), 0) * solve(root, mask ^ newmask, 1);         }       } else         ret += solve(ch, newmask ^ (1 << ch), 0) * solve(root, mask ^ newmask, 1);     }     return ret;   }   int main() {     int i, j, m, k, k1, q;     scanf( %d%d , &n, &m);     ;     scanf( %d , &q);     ;     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       ;       x--;       y--;       G[x].push_back(y);       G[y].push_back(x);       a[x][y] = 1;       a[y][x] = 1;     }     while (q--) {       int x, y, z;       scanf( %d%d , &x, &y);       ;       scanf( %d , &z);       ;       x--;       y--;       z--;       lca[z].push_back(make_pair(x, y));     }     for (i = 0; i < 1 << n; i++)       for (j = 0; j < i + 1; j++)         if ((i & j) == j) nxt[i].push_back(j);     for (i = 0; i < n; i++) {       for (j = 0; j < 1 << n; j++) {         bool f = 1;         if (j & (1 << i)) continue;         for (k = 0; k < n; k++) {           if ((j & (1 << k)) == 0) continue;           for (k1 = 0; k1 < G[k].size(); k1++)             if ((j & (1 << G[k][k1])) == 0 && G[k][k1] != i) f = 0;         }         for (k = 0; k < lca[i].size(); k++) {           int x = lca[i][k].first, y = lca[i][k].second;           if ((j & (1 << x)) && (j & (1 << y))) f = 0;         }         ok[i][j] = f;       }     }     memset(dp, -1, sizeof(dp));     cout << solve(0, ((1 << (n - 1)) - 1) << 1, 0) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using db = double;   const int mxn = 300006;   const ll mod = 1E9L + 7;   int n;   ll a[mxn];   ll p[mxn];   int main() {     cin >> n;     for (int i = 0; i < n; ++i) scanf( %lld , &a[i]);     sort(a, a + n);     p[0] = 1;     for (int i = 1; i <= n; ++i) p[i] = p[i - 1] * 2 % mod;     ll ans = 0;     for (int i = 0; i < n; ++i) {       ans -= a[i] * p[n - 1 - i];       ans += a[i] * p[i];       ans %= mod;     }     cout << (ans + mod) % mod << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = 0x3f3f3f3f3f3f3f3fll;   const int mx = 15000005;   vector<string> adj[2000005];   vector<bool> vis;   vector<pair<string, int>> pa;   int ind = 0, mxx = 0;   void dfs(int d, int ti) {     mxx = max(mxx, d);     adj[d].push_back(pa[ind].first);     while (ti--) {       ind++;       if (ind < pa.size()) dfs(d + 1, pa[ind].second);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     std::istringstream is(s);     std::string token;     int now = 1;     while (std::getline(is, token,  , )) {       if (now) {         pa.push_back({token, 0});       } else {         int val = 0;         for (char c : token) {           val = val * 10 + (c -  0 );         }         pa.back().second = val;       }       now = now ^ 1;     }     vis.assign(pa.size() + 1, false);     while (ind < pa.size()) {       dfs(0, pa[ind].second);       ind++;     }     int i = 0;     cout << mxx + 1 << endl;     while (100) {       if (adj[i].size() == 0) break;       for (string u : adj[i]) cout << u <<    ;       cout << endl;       i++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> times;   const int INF = 0x3fffffff;   struct Node {     int l, r;     int v;     Node() { l = -1, r = -1; }     Node(int _l, int _r) { l = _l, r = _r; }   } node[120000];   int fa[120000];   int n, v, ls, rs, root;   int ans;   int Findroot(int t) {     if (fa[t] != t) return Findroot(fa[t]);     return t;   }   void dfs(int mi, int ma, int now) {     if (node[now].v <= mi || node[now].v >= ma) {       if (times[node[now].v] != -1) {         ans++;         times[node[now].v]++;       }     } else {       ans -= times[node[now].v];       times[node[now].v] = -1;     }     if (node[now].l ^ (~0)) dfs(mi, min(ma, node[now].v), node[now].l);     if (node[now].r ^ (~0)) dfs(max(mi, node[now].v), ma, node[now].r);     return;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &v, &ls, &rs);       if (ls ^ (~0)) fa[ls] = i;       if (rs ^ (~0)) fa[rs] = i;       node[i].l = ls;       node[i].r = rs;       node[i].v = v;     }     root = Findroot(1);     dfs(-INF, INF, root);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400000 + 10;   const double eps = 1e-9;   const double pi = acos(-1);   int n;   long long k;   struct Vec {     int x, y;     double d() { return x * x + y * y; }   } p[N];   vector<double> v;   int id(double x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }   int bit[N];   void add(int x, int k) {     while (x < N) {       bit[x] += k;       x += x & (-x);     }   }   int sum(int x) {     int ans = 0;     while (x > 0) {       ans += bit[x];       x -= x & (-x);     }     return ans;   }   long long cal(vector<pair<double, double> > vec) {     memset(bit, 0, sizeof(bit));     sort(vec.begin(), vec.end());     v.clear();     for (auto p : vec) {       v.push_back(p.first);       v.push_back(p.second);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     long long res = 0;     for (auto p : vec) {       res += sum(id(p.second)) - sum(id(p.first));       add(id(p.second), 1);     }     return res;   }   double check(double x) {     vector<pair<double, double> > vec;     long long tot = 1LL * n * (n - 1) / 2, cnt = 0;     for (int i = 1; i <= n; i++) {       if (p[i].d() > x * x - eps) {         double dis = sqrt(p[i].d());         double theta = acos(x / dis);         double mid = atan2(p[i].y, p[i].x);         int pre = vec.size();         if (mid < 0) mid += 2 * pi;         if (mid + theta > 2 * pi) {           vec.push_back(make_pair(mid + theta - 2 * pi, mid - theta));         } else if (mid - theta < 0) {           vec.push_back(make_pair(mid + theta, mid - theta + 2 * pi));         } else {           vec.push_back(make_pair(mid - theta, mid + theta));         }         int cur = vec.size();       }     }     tot -= cal(vec);     return tot >= k;   }   int main() {     scanf( %d%lld , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &p[i].x, &p[i].y);     }     double lef = 0, rig = 2e4;     for (int i = 1; i <= 100; i++) {       double mid = (lef + rig) / 2;       if (check(mid))         rig = mid;       else         lef = mid;     }     printf( %.8f n , rig);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10);     int m, x, y;     cin >> m;     vector<int> M(m);     for (int i = 0; i < (m); ++i) cin >> M[i];     int sum = accumulate(M.begin(), M.end(), 0);     cerr << sum << endl;     cin >> x >> y;     int val = 0;     for (int i = 0; i < (m); ++i) {       val += M[i];       if (val > y) {         cout << 0 << endl;         exit(0);       }       if (val >= x && sum - val >= x && sum - val <= y) {         cout << i + 2 << endl;         exit(0);       }     }     cout << 0 << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[5000005];   void solve() {     for (long long i = 1; i <= 5000000; i++) dp[i] = i * (i - 1) / 2;     for (long long i = 2; i <= 5000000 / 2; i++) {       for (long long j = 2; j <= i; j++) {         if (i * j > 5000000) break;         dp[i * j] = min(dp[i * j], dp[i] + j * (j - 1) / 2 * i);         dp[i * j] = min(dp[i * j], dp[j] + i * (i - 1) / 2 * j);       }     }     long long t, l, r;     cin >> t >> l >> r;     long long tt = 1, ans = 0;     while (l <= r) {       dp[l] %= (long long)(1e9 + 7);       ans = (ans + tt * dp[l]) % (long long)(1e9 + 7);       tt = (tt * t) % (long long)(1e9 + 7);       l++;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct sak {     int x, y;     sak(int x1, int y1) {       x = x1;       y = y1;     }   };   vector<sak> A, B;   vector<int> AA, BB;   int findA(int k) {     int t1 = -1;     for (int i = 0; i < A.size(); i++)       if (A[i].x <= k && AA[i] == 0 && (t1 == -1 || A[t1].y < A[i].y)) {         t1 = i;       }     return t1;   }   int findB(int k) {     int t1 = -1;     for (int i = 0; i < B.size(); i++)       if (B[i].x <= k && BB[i] == 0 && (t1 == -1 || B[t1].y < B[i].y)) {         t1 = i;       }     return t1;   }   int main() {     int n, k;     while (scanf( %d %d , &n, &k) == 2) {       int x, y, z;       A.clear();       B.clear();       AA.clear();       BB.clear();       for (int i = 0; i < n; i++) {         scanf( %d %d %d , &x, &y, &z);         if (x == 0) {           A.push_back(sak(y, z));           AA.push_back(0);         } else {           B.push_back(sak(y, z));           BB.push_back(0);         }       }       int maxi = 0;       int sak1 = findA(k);       if (A.size() > 0 && sak1 != -1) {         int cnt = 1;         x = 1;         y = 0;         int kk = k + A[sak1].y;         AA[sak1] = 1;         while (1) {           sak1 = findB(kk);           if (sak1 == -1) break;           cnt++;           kk += B[sak1].y;           BB[sak1] = 1;           y++;           sak1 = findA(kk);           if (sak1 == -1) break;           cnt++;           kk += A[sak1].y;           AA[sak1] = 1;           x++;         }         if (cnt > maxi) maxi = cnt;       }       for (int i = 0; i < AA.size(); i++) AA[i] = 0;       for (int i = 0; i < BB.size(); i++) BB[i] = 0;       sak1 = findB(k);       if (B.size() > 0 && sak1 != -1) {         int cnt = 1;         x = 0;         y = 1;         int kk = k + B[sak1].y;         BB[sak1] = 1;         while (1) {           sak1 = findA(kk);           if (sak1 == -1) break;           cnt++;           kk += A[sak1].y;           AA[sak1] = 1;           x++;           sak1 = findB(kk);           if (sak1 == -1) break;           cnt++;           kk += B[sak1].y;           BB[sak1] = 1;           y++;         }         if (cnt > maxi) maxi = cnt;       }       printf( %d n , maxi);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int main() {     long long x, y, a, b, c;     cin >> a >> b >> c;     c = -c;     long long g = gcdExtended(a, b, &x, &y);     if (c % g == 0)       cout << c * x / g <<     << c * y / g << endl;     else       cout <<  -1  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, a, b, d;   bool fun(long long mid) {     long long total = mid * (mid + 1) / 2;     if (total >= d) {       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> a >> b;       d = abs(a - b);       long long s = 0, e = 1000000007, mid;       while (s < e) {         mid = (s + e) / 2;         if (fun(mid)) {           e = mid;         } else {           s = mid + 1;         }       }       long long total = s * (s + 1) / 2;       while (total % 2 != d % 2) {         s++;         total = s * (s + 1) / 2;       }       cout << s << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int n;   bool sogl(char x) {     return x !=  a  && x !=  e  && x !=  i  && x !=  o  && x !=  u ;   }   int dp[3000], opt[3000];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> s;     int n = s.size();     for (int i = 0; i < n; i++) {       dp[i] = i + 1;       opt[i] = i;       for (int j = i; j >= 0; j--) {         if (i - j + 1 >= 3 && sogl(s[j]) && sogl(s[j + 1]) && sogl(s[j + 2]) &&             (s[j] != s[j + 1] || s[j] != s[j + 2] || s[j + 1] != s[j + 2]))           break;         if ((j != 0 ? dp[j - 1] : 0) + 1 < dp[i]) {           dp[i] = (j != 0 ? dp[j - 1] : 0) + 1;           opt[i] = j;         }       }     }     vector<char> ans;     int v = n - 1;     while (v != -1) {       int u = opt[v];       for (int i = v; i >= u; i--) ans.push_back(s[i]);       ans.push_back(   );       v = u - 1;     }     ans.pop_back();     reverse(ans.begin(), ans.end());     for (char x : ans) cout << x;   }
#include <bits/stdc++.h>   using namespace std;   int a[5][5];   int b[] = {0, 1, 2, 3, 4};   long long sol() {     int p0 = b[0];     int p1 = b[1];     int p2 = b[2];     int p3 = b[3];     int p4 = b[4];     long long p = a[p0][p1] + a[p1][p0] + a[p2][p3] + a[p3][p2];     p += a[p1][p2] + a[p2][p1] + a[p3][p4] + a[p4][p3];     p += a[p2][p3] + a[p3][p2];     p += a[p3][p4] + a[p4][p3];     return p;   }   int main() {     for (long long i = 0; i < 5; i++)       for (long long j = 0; j < 5; j++) cin >> a[i][j];     long long m = 0;     do {       m = max(sol(), m);     } while (next_permutation(b, b + 5));     cout << m;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   const int mod = 1e9 + 7;   int n, k, m, dp[N], lst[300];   char s[N];   inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }   inline int mul(int x, int y) { return (long long int)x * y % mod; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> k >> (s + 1);     m = strlen(s + 1);     dp[0] = 1;     for (int i = 1; i <= m; i++) {       dp[i] = mul(dp[i - 1], 2);       if (lst[s[i]] != 0) dp[i] = add(dp[i], mod - dp[lst[s[i]] - 1]);       lst[s[i]] = i;     }     for (int i = m + 1; i <= n + m; i++) {       dp[i] = mul(dp[i - 1], 2);       int mn = 0;       for (int j = 0; j < k; j++) {         if (lst[mn +  a ] > lst[j +  a ]) mn = j;       }       if (lst[mn +  a ] != 0) dp[i] = add(dp[i], mod - dp[lst[mn +  a ] - 1]);       lst[mn +  a ] = i;     }     cout << dp[n + m] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c;     cin >> r >> c;     if (r == c and r == 1) return cout << 0, 0;     if (r == 1) {       for (int i = 0; i < c; i++) cout << 2 + i <<    ;       return 0;     }     if (c == 1) {       for (int i = 0; i < r; i++) cout << 2 + i <<    ;       return 0;     }     int ans[r][c];     for (int i = 0; i < r; i++)       for (int j = 0; j < c; j++) ans[i][j] = 1;     int val = r + c;     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) ans[i][j] = val;       val--;     }     for (int j = 0; j < c; j++) {       for (int i = 0; i < r; i++) {         ans[i][j] = ans[i][j] * val;       }       val--;     }     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) cout << ans[i][j] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[4];   int cmp(int x, int y) { return x > y; }   int main() {     int t;     cin >> t;     while (t--) {       int ans = 0;       cin >> a[0] >> a[1] >> a[2];       sort(a, a + 3, cmp);       if (a[0]) {         a[0]--;         ans++;       }       if (a[1]) {         a[1]--;         ans++;       }       if (a[2]) {         a[2]--;         ans++;       }       if (a[0] && a[1]) {         a[0]--, a[1]--;         ans++;       }       if (a[0] && a[2]) {         a[0]--, a[2]--;         ans++;       }       if (a[1] && a[2]) {         a[1]--, a[2]--;         ans++;       }       if (a[0] && a[1] && a[2]) {         ans++;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int a[s.length()];     int ans = -1;     int n = s.length();     for (int i = 0; i < s.length(); i++) {       a[i] = int(s[i]) - 48;     }     for (int i = 0; i < n; i++) {       if (a[i] % 8 == 0) {         ans = a[i];         break;       } else         for (int j = i + 1; j < n; j++) {           if ((a[i] * 10 + a[j]) % 8 == 0) {             ans = a[i] * 10 + a[j];             break;           } else             for (int k = j + 1; k < n; k++) {               if ((100 * a[i] + 10 * a[j] + a[k]) % 8 == 0) {                 ans = 100 * a[i] + 10 * a[j] + a[k];                 break;               }             }         }     }     if (ans != -1) {       cout <<  YES  << endl;       cout << ans;     } else       cout <<  NO ;     cout << endl;   }
#include <bits/stdc++.h>      using namespace std;      int ans[30][5] = {    {1, 0, 0, 1, 0},    {1, 1, 0, 2, 0},    {2, 0, 0, 1, 1},    {2, 1, 0, 1, 2},    {1, 1, 0, 1, 1},    {2, 1, 0, 2, 1},    {2, 2, 0, 2, 2},    {1, 2, 0, 2, 1},    {1, 1, 0, 1, 1},    {1, 2, 0, 1, 2},    {1, 0, 1, 2, 0},    {1, 1, 1, 3, 0},    {2, 0, 1, 2, 1},    {2, 1, 1, 2, 2},    {1, 1, 1, 2, 1},    {2, 1, 1, 3, 1},    {2, 2, 1, 3, 2},    {1, 2, 1, 3, 1},    {1, 1, 1, 2, 1},    {1, 2, 1, 2, 2},    {1, 0, 2, 2, 1},    {1, 1, 2, 3, 1},    {1, 2, 1, 1, 3},    {2, 0, 2, 2, 2},    {2, 1, 2, 2, 3},    {1, 1, 2, 2, 2}   };      int main() {    int N; scanf( %d , &N);    for(int i = 0; i < N; i++) {     int a[5];     for(int j = 0; j < 5; j++) scanf( %d , &a[j]);     for(int j = 0; j < 26; j++) {      bool ok = true;      for(int k = 0; k < 5; k++) if(ans[j][k] != a[k]) ok = false;      if(ok) { printf( %c ,  a  + j); break; }     }    }    puts(  );    return 0;   }