malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10, STAN = (1 << 30) - 1;   struct QJ {     int l, r, q;   } q[MAXN];   int n, m;   struct Seg {     int water[MAXN * 4], sh[MAXN * 4];     bool fir[MAXN * 4];     Seg() {       memset(water, 0, sizeof(water));       memset(fir, 0, sizeof(fir));     }     int _st, _ed, _x, _t;     void _insert(int num, int l, int r) {       if (_st <= l && r <= _ed) {         water[num] |= _x;         return;       }       int mid = (l + r) >> 1;       if (_st <= mid) _insert(num << 1, l, mid);       if (_ed >= mid + 1) _insert(num << 1 | 1, mid + 1, r);     }     int _swim(int num, int l, int r, int now) {       int x;       now |= water[num];       if (l == r) {         if (!fir[num]) {           sh[num] = now;           fir[num] = true;         } else           sh[num] &= now;         return now;       }       int mid = (l + r) >> 1;       if (_t <= mid)         now = _swim(num << 1, l, mid, now);       else         now = _swim(num << 1 | 1, mid + 1, r, now);       if (!fir[num]) {         sh[num] = now;         fir[num] = true;       } else         sh[num] &= now;       return now;     }     int _check(int num, int l, int r) {       if (l == r) return sh[num];       if (_st <= l && r <= _ed) return sh[num];       int mid = (l + r) >> 1;       int ans = STAN;       if (_st <= mid) ans &= _check(num << 1, l, mid);       if (_ed >= mid + 1) ans &= _check(num << 1 | 1, mid + 1, r);       return ans;     }     inline void Insert(int l, int r, int q) {       _st = l, _ed = r, _x = q;       _insert(1, 1, n);     }     inline int Swim(int t) {       _t = t;       return _swim(1, 1, n, 0);     }     inline bool Check(int l, int r, int q) {       _st = l;       _ed = r;       return _check(1, 1, n) == q;     }   } T;   int a[MAXN];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &q[i].l, &q[i].r, &q[i].q);       T.Insert(q[i].l, q[i].r, q[i].q);     }     for (int i = 1; i <= n; i++) a[i] = T.Swim(i);     for (int i = 1; i <= m; i++)       if (!T.Check(q[i].l, q[i].r, q[i].q)) {         printf( NO n );         return 0;       }     printf( YES n );     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[5003];   vector<int> color[5003];   int ans[5003];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k, i, j;     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a, a + n);     for (i = 0; i < n; i++) {       color[i % k].push_back(a[i].first);       ans[a[i].second] = (i % k);     }     for (i = 0; i < k; i++) {       for (j = 1; j < color[i].size(); j++) {         if (color[i][j] == color[i][j - 1]) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES n ;     for (i = 0; i < n; i++) {       cout << (ans[i] + 1) <<    ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const long long N = 1e5 + 10;   const long double Pie = acos(-1);   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long arr[n];       for (long long i = 0; i < n; i++) cin >> arr[i];       for (long long i = 0; i < n; i++) {         if (i % 2 == 0) {           if (arr[i] >= 0)             cout << arr[i] <<    ;           else             cout << -1 * arr[i] <<    ;         } else if (i % 2 == 1) {           if (arr[i] <= 0)             cout << arr[i] <<    ;           else             cout << -1 * arr[i] <<    ;         }       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 200005;   vector<int> g[maxn];   int dis[maxn];   int pa[maxn];   set<pair<int, int>> st;   void dfs(int now, int pre = 0) {     if (dis[now] > 2) {       st.insert({dis[now], now});     }     for (auto &i : g[now]) {       if (i ^ pre) {         pa[i] = now;         dis[i] = dis[now] + 1;         dfs(i, now);       }     }   }   void go() {     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1);     int ans = 0;     while (st.size()) {       auto x = *(--st.end());       int v = pa[x.second];       st.erase({dis[v], v});       for (auto &i : g[v]) {         st.erase({dis[i], i});       }       ans++;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int c = 0;     int t;     if (!c) {       t = 1;     } else {       cin >> t;     }     while (t--) {       go();     }   }
#include <bits/stdc++.h>   using namespace std;   long long int newarr[1005];   long long int dp[1005][1005];   long long int n, k;   long long int solution(long long int index, long long int m) {     if (m < 0) m += k;     if (index >= n && m != 0)       return 0;     else if (m == 0)       return 1;     else if (dp[index][m] != -1)       return dp[index][m];     else {       long long int x = solution(index + 1, m);       long long int y = solution(index + 1, m - newarr[index]);       if (x > 0) x = 1;       if (y > 0) y = 1;       if (m >= newarr[index]) {         dp[index + 1][m - newarr[index]] = y;       }       dp[index + 1][m] = x;       return x + y;     }   }   int32_t main() {     memset(dp, -1, sizeof(dp));     cin >> n;     cin >> k;     long long int arr[n];     long long int ctr = 0;     for (long long int i = 0; i < n; i++) {       cin >> arr[i];     }     if (n > k) {       cout <<  YES n ;     } else {       for (long long int i = 0; i < n; i++) {         newarr[i] = arr[i] % k;         if (newarr[i] == 0) ctr++;       }       long long int x = solution(0, k);       if (x > 0 || ctr > 0)         cout <<  YES n ;       else         cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int bas = 23333;   const long long mod = 9999999999973ll;   int N, M, S[26], L[555];   char C[255][255];   long long H[26], W[255][255][255], G[555];   int manacher(int n) {     int k = 0, m = 0, res = 0;     memset(L, 0, sizeof(L));     for (int i = 1; i <= n; i++) {       if (G[i] == -1) {         continue;       }       int l = (m > i) ? min(L[2 * k - i], m - i) : 1;       while (G[i - l] != -1 && G[i + l] != -1 && G[i - l] == G[i + l]) {         l++;       }       if (l + i > m) {         m = l + i;         k = i;       }       L[i] = l;       res += l;     }     return (res - N - 1) >> 1;   }   int main() {     scanf( %d%d n , &N, &M);     long long h = 1;     for (int i = 0; i < 26; i++) {       h = h * bas % mod;       H[i] = h;     }     for (int i = 1; i <= N; i++) {       scanf( %s , C[i] + 1);       for (int j = 1; j <= M; j++) {         C[i][j] -=  a ;         W[i][j][j] = H[C[i][j]];         for (int k = j - 1; k > 0; k--) {           W[i][k][j] = W[i][k + 1][j] + H[C[i][k]];           if (W[i][k][j] >= mod) {             W[i][k][j] -= mod;           }         }         memset(S, 0, sizeof(S));         int cnt = 0;         for (int k = j; k > 0; k--) {           S[C[i][k]]++;           if (S[C[i][k]] & 1) {             cnt++;           } else {             cnt--;           }           if (cnt > 1) {             W[i][k][j] = -1;           }         }       }     }     long long ANS = 0;     for (int j = 1; j <= M; j++) {       for (int k = j; k <= M; k++) {         memset(G, 0, sizeof(G));         G[0] = -1;         G[(N + 1) << 1] = -1;         for (int i = 1; i <= N; i++) {           G[i << 1] = W[i][j][k];         }         ANS += manacher((N << 1) | 1);       }     }     printf( %lld , ANS);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef long long lo;   typedef vector<lo> vl;   typedef vector<lo> vll;   typedef vector<vl> vvl;   template <typename T>   ostream &operator<<(ostream &o, vector<T> v) {     if (v.size() > 0) o << v[0];     for (unsigned i = 1; i < v.size(); i++) o <<     << v[i];     return o <<   n ;   }   template <typename U, typename V>   ostream &operator<<(ostream &o, pair<U, V> p) {     return o <<  (  << p.first <<  ,   << p.second <<  )  ;   }   template <typename T>   istream &operator>>(istream &in, vector<T> &v) {     for (unsigned i = 0; i < v.size(); i++) in >> v[i];     return in;   }   template <typename T>   istream &operator>>(istream &in, pair<T, T> &p) {     in >> p.first;     in >> p.second;     return in;   }   string s;   lo len[203][2];   lo dp[203][203][203][2];   lo cal(string &t) {     for (lo i = t.size(); i > 0; i--) {       if (s.substr(0, i) == t.substr(t.size() - i, i)) return i;     }     return 0;   }   void add(lo &a, lo b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     if (a < 0) a += 1000000007;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(20);     lo n, ssz;     cin >> n >> s;     ssz = s.size();     if (s[0] ==  ( )       len[0][0] = 1;     else       len[0][1] = 1;     string pref;     for (lo i = (0); i < (lo)ssz; i++) {       pref += s[i];       pref +=  ( ;       len[i + 1][0] = cal(pref);       pref.pop_back();       pref +=  ) ;       len[i + 1][1] = cal(pref);       pref.pop_back();     }     dp[0][0][0][0] = 1;     for (lo i = (0); i < (lo)2 * n; i++) {       for (lo(j) = 0; (j) < (n + 1); (j)++) {         for (lo(pos) = 0; (pos) < (ssz + 1); (pos)++) {           for (lo(f) = 0; (f) < (2); (f)++) {             if (dp[i][j][pos][f] == 0) continue;             if (j + 1 <= n)               add(dp[i + 1][j + 1][len[pos][0]][f | (len[pos][0] == ssz)],                   dp[i][j][pos][f]);             if (j > 0)               add(dp[i + 1][j - 1][len[pos][1]][f | (len[pos][1] == ssz)],                   dp[i][j][pos][f]);           }         }       }     }     lo ans = 0;     for (lo i = (0); i < (lo)ssz + 1; i++) add(ans, dp[2 * n][0][i][1]);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void checkMax(T& a, const T& b) {     if (a < b) a = b;   }   template <typename T>   inline void checkMin(T& a, const T& b) {     if (a > b) a = b;   }   const int kMod = 1000000007;   template <typename U, typename V>   inline void addMod(U& x, const V y) {     x += y;     if (x >= kMod) {       x -= kMod;     }   }   template <int N>   struct CombinationTable {     CombinationTable() { init(); }     static long long table[N + 1][N + 1];     static void init() {       table[0][0] = 1;       for (int i = 1; i <= N; ++i) {         table[i][0] = table[i][i] = 1;         for (int j = 1; j < i; ++j) {           table[i][j] = table[i - 1][j] + table[i - 1][j - 1];         }       }     }   };   template <int N>   long long CombinationTable<N>::table[N + 1][N + 1];   CombinationTable<40> comb_tbl;   long long n, t;   void go() {     if ((t & -t) != t) {       puts( 0 );       return;     }     ++n;     int tt = 1;     while (t >>= 1) ++tt;     int num_one;     long long tmp = n;     do {       num_one += (tmp & 1);     } while (tmp >>= 1);     long long ans = (tt == num_one);     for (int n___LINE__ = (50), i = 0; i < n___LINE__; ++i) {       if (n & 1) {         --num_one;         if (num_one <= tt && i >= 0 && tt >= num_one && tt - num_one <= i) {           ans += comb_tbl.table[i][tt - num_one];         }       }       n >>= 1;     }     if (tt == 1) --ans;     cout << ans << endl;   }   int main() {     cin >> n >> t;     go();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[100069], f[100069], p10[10];   int main() {     long long t, rr, k, i, p, z, pp, ppp, zzz;     p10[0] = 1;     for (i = 1; i < 10; i++) {       p10[i] = p10[i - 1] * 10;     }     for (i = 1; 1; i++) {       f[i] = f[i - 1];       for (k = i; k > 0; k /= 10) {         f[i]++;       }       a[i] = a[i - 1] + f[i];       if (a[i] > 1000000000) {         break;       }     }     scanf( %lld , &t);     for (rr = 0; rr < t; rr++) {       scanf( %lld , &k);       p = lower_bound(a, a + 21837, k) - a;       pp = k - a[p - 1];       for (i = 1; i <= 5; i++) {         if (pp <= 9 * p10[i - 1] * i) {           z = (pp - 1) / i + p10[i - 1];           ppp = i - (pp - 1) % i;           break;         }         pp -= 9 * p10[i - 1] * i;       }       for (; ppp > 1; ppp--, z /= 10)         ;       zzz = z % 10;       printf( %lld n , zzz);     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   ostream& operator<<(ostream& out, const pair<S, T> p) {     out <<  (  << p.first <<  ,  << p.second <<  ) ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& v) {     for (auto a : v) out << a <<    ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, const set<T>& S) {     for (auto a : S) cout << a <<    ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, const multiset<T>& S) {     for (auto a : S) cout << a <<    ;     return out;   }   template <typename S, typename T>   ostream& operator<<(ostream& out, const map<S, T>& M) {     for (auto m : M) cout <<  (  << m.first <<  ->  << m.second <<  )  ;     return out;   }   template <typename S, typename T>   pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   template <typename S, typename T>   pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     cout << n + n / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   inline long long rd() {     long long _x = 0;     int _ch = getchar(), _f = 1;     for (; !isdigit(_ch) && (_ch !=  - ) && (_ch != EOF); _ch = getchar())       ;     if (_ch ==  - ) {       _f = 0;       _ch = getchar();     }     for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch -  0 ;     return _f ? _x : -_x;   }   void write(long long _x) {     if (_x >= 10)       write(_x / 10), putchar(_x % 10 +  0 );     else       putchar(_x +  0 );   }   inline void wrt(long long _x, char _p) {     if (_x < 0) putchar( - ), _x = -_x;     write(_x);     if (_p) putchar(_p);   }   int n, m;   char s[1005][1005];   bool flag1, flag2;   bool vis[1005][1005];   void dfs(int x, int y) {     if (vis[x][y] || s[x][y] !=  #  || x == 0 || y == 0 || x == n + 1 ||         y == m + 1)       return;     vis[x][y] = 1;     dfs(x + 1, y), dfs(x, y + 1);     dfs(x - 1, y), dfs(x, y - 1);   }   int main() {     n = rd(), m = rd();     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);     }     for (int i = 1; i <= n; i++) {       bool tag = 0;       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  # ) tag = 1;       }       flag1 |= !tag;     }     for (int i = 1; i <= m; i++) {       bool tag = 0;       for (int j = 1; j <= n; j++) {         if (s[j][i] ==  # ) tag = 1;       }       flag2 |= !tag;     }     if (((!flag1) && (flag2)) || ((flag1) && (!flag2))) {       printf( -1 n );       return 0;     }     bool flag = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  # ) {           int t = j;           while (s[i][t] ==  # ) t++;           for (int k = t; k <= m; k++)             if (s[i][k] ==  # ) flag = 1;         }       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         if (s[j][i] ==  # ) {           int t = j;           while (s[t][i] ==  # ) t++;           for (int k = t; k <= n; k++)             if (s[k][i] ==  # ) flag = 1;         }       }     }     if (flag) {       printf( -1 n );       return 0;     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (s[i][j] ==  #  && !vis[i][j]) {           dfs(i, j);           cnt++;         }     }     wrt(cnt,   n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, l, r;     cin >> n >> l >> r;     long long int dp[n][3];     long long int a = r / 3 - (l - 1) / 3;     long long int b = (r + 2) / 3 - (l + 1) / 3;     long long int c = (r + 1) / 3 - l / 3;     dp[0][0] = r / 3 - (l - 1) / 3;     dp[0][1] = (r + 2) / 3 - (l + 1) / 3;     dp[0][2] = (r + 1) / 3 - l / 3;     for (int i = 1; i < n; i++) {       dp[i][0] =           (dp[i - 1][0] * a + dp[i - 1][1] * c + dp[i - 1][2] * b) % 1000000007;       dp[i][1] =           (dp[i - 1][0] * b + dp[i - 1][1] * a + dp[i - 1][2] * c) % 1000000007;       dp[i][2] =           (dp[i - 1][0] * c + dp[i - 1][1] * b + dp[i - 1][2] * a) % 1000000007;     }     cout << dp[n - 1][0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, a[1000], d;     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       d = 0;       for (int i = 1; i < n; i++) {         if (a[i] - a[i - 1] <= 1) {           d++;         }       }       if (d)         cout << 2 << endl;       else         cout << 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int p[100];   char mm[100];   int main() {     while (scanf( %d , &n) != EOF) {       scanf( %s , &mm);       int len = strlen(mm);       m = 0;       for (int i = 0; i < len; ++i) m = m * 10 + (mm[i] -  0 );       if (n == 0) {         if (strlen(mm) != 1)           puts( WRONG_ANSWER );         else if (m == 0)           puts( OK );         else           puts( WRONG_ANSWER );       } else {         if (mm[0] ==  0 ) {           puts( WRONG_ANSWER );           return 0;         }         int x = n;         memset(p, 0, sizeof(p));         while (x > 0) {           p[x % 10]++;           x /= 10;         }         int now = 0;         for (int i = 1; i <= 9; ++i)           if (p[i]) {             now = i;             p[i]--;             break;           }         for (int i = 0; i <= 9; ++i) {           while (p[i]) {             now = now * 10 + i;             p[i]--;           }         }         if (now == m)           puts( OK );         else           puts( WRONG_ANSWER );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX_N = 3e5 + 5;   const int MX_M = 3e5 + 5;   int N, M, D[MX_N];   vector<pair<int, int>> al[MX_N];   int vis[MX_N], sumD;   vector<int> edges;   void dfs(int u, int p = 0, int pe = 0) {     vis[u] = 1;     for (auto v : al[u])       if (!vis[v.first]) {         dfs(v.first, u, v.second);       }     if (D[u]) edges.push_back(pe), D[p] ^= 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M;     for (int i = (1); i <= (N); ++i) {       cin >> D[i];       if (D[i] >= 0) sumD += D[i];     }     for (int i = (1); i <= (M); ++i) {       int U, V;       cin >> U >> V;       al[U].emplace_back(V, i);       al[V].emplace_back(U, i);     }     for (int i = (1); i <= (N); ++i)       if (D[i] == -1) {         if (sumD & 1)           D[i] = 1, ++sumD;         else           D[i] = 0;       }     if (sumD & 1)       cout << -1;     else {       dfs(1);       cout << ((int)(edges).size()) <<   n ;       sort(edges.begin(), edges.end());       for (int& e : edges) cout << e <<    ;     }   }
#include <bits/stdc++.h>   long long RemoveZeros(long long a) {     long long temp;     long long x = 0;     long long i = 10;     while (a > 0) {       if (a % 10 != 0) {         temp = (a % 10) * i;         x += temp;         i *= 10;       }       a /= 10;     }     return x / 10;   }   using namespace std;   int main() {     long long a, b, c;     cin >> a >> b;     c = a + b;     long long a1 = RemoveZeros(a);     long long b1 = RemoveZeros(b);     long long c1 = RemoveZeros(c);     if (a1 + b1 == c1)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using li = long long;   using ld = long double;   using pii = pair<int, int>;   const int INF = 1e9 + 13;   const int N = 2e5 + 13;   const int M = 1e9 + 7;   const int B = 600;   const int A = 256;   const ld e = 1e-8;   const int LOGN = 20;   mt19937 rnd(time(0));   void solve() {     int n, m;     cin >> n >> m;     vector<bool> a(n, false);     for (int i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y >> z;       y--;       a[y] = true;     }     int v = -1;     for (int i = 0; i < n; i++)       if (!a[i]) v = i;     for (int i = 0; i < n; i++) {       if (i != v) cout << v + 1 <<     << i + 1 <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   #pragma GCC optimize  03    using namespace std;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   const int inf = 1e9 + 9;   pair<int, int> ans[1004];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int c1 = 0, c2 = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  0 ) {         if (c1 == 0) {           c1 = 1;           ans[i].first = 3, ans[i].second = 1;         } else {           c1 = 0;           ans[i].first = 1, ans[i].second = 1;         }       } else {         if (c2 == 0) {           c2 = 1;           ans[i].first = 1, ans[i].second = 3;         } else {           c2 = 0;           ans[i].first = 1, ans[i].second = 1;         }       }     }     for (int i = 0; i < s.length(); i++)       cout << ans[i].first <<     << ans[i].second <<   n ;     return 0;   }
#include <bits/stdc++.h>   const int MAX_N = 1e5 + 5;   int n, m;   char str[MAX_N], nxt[256];   bool chk[256], vis[256], not_root[256], flag;   std::vector<char> ans;   void dfs(char c) {     if (!vis[c]) {       vis[c] = true;       ans.push_back(c);       if (nxt[c]) dfs(nxt[c]);     } else       flag = true;   }   int main() {     scanf( %d , &n);     while (n--) {       scanf(  %s , str);       m = strlen(str);       for (int i = 0; i < m; ++i) chk[str[i]] = true;       for (int i = 0; i + 1 < m; ++i) {         if (nxt[str[i]] == 0)           nxt[str[i]] = str[i + 1];         else if (nxt[str[i]] != str[i + 1]) {           printf( NO n );           return 0;         }         not_root[str[i + 1]] = true;       }     }     for (char i =  a ; i <=  z ; ++i)       if (!not_root[i] && chk[i]) dfs(i);     for (char i =  a ; i <=  z ; ++i) flag |= chk[i] != vis[i];     if (flag) {       printf( NO n );       return 0;     }     for (char c : ans) printf( %c , c);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int A[5];   int main() {     ios_base::sync_with_stdio(0);     int a, b, n, T, cas = 0;     cin >> T;     while (T--) {       cin >> A[0] >> A[1] >> A[2];       int cnt = 0;       sort(A, A + 3, greater<int>());       for (int i = 0; i < 3; ++i) {         if (A[i]) A[i]--, cnt++;       }       if (A[0] && A[1]) A[0]--, A[1]--, cnt++;       if (A[0] && A[2]) A[0]--, A[2]--, cnt++;       if (A[1] && A[2]) A[1]--, A[2]--, cnt++;       if (A[0] && A[1] && A[2]) {         ++cnt;       }       cout << cnt << endl;     }     return 0;   }