malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long offset[1000];   vector<pair<long long, int> > x[1000];   long long v[500005];   int bucketsize = 700;   inline int bucket(int x) { return x / bucketsize; }   int buckets, n;   inline int bstart(int x) {     if (x == buckets + 1) {       return n + 1;     }     return x * bucketsize;   }   void resort(int buc) {     x[buc].clear();     int l = bstart(buc), r = bstart(buc + 1);     for (int j = l; j < r; j++) {       x[buc].push_back({v[j], j});     }     sort(x[buc].begin(), x[buc].end());   }   int main() {     int q;     scanf( %d %d , &n, &q);     buckets = bucket(n);     for (int i = 1; i <= n; i++) {       int k;       scanf( %d , &k);       v[i] = k;       x[bucket(i)].push_back({v[i], i});     }     for (int i = 0; i <= buckets; i++) {       resort(i);     }     for (int qq = 0; qq < q; qq++) {       int t;       scanf( %d , &t);       if (t == 1) {         int l, r, dd;         scanf( %d %d %d , &l, &r, &dd);         long long d = dd;         int lbucket0 = bucket(l);         int lbucket1 = lbucket0 + 1;         int rbucket = bucket(r);         int lstart1 = bstart(lbucket1);         for (int j = lbucket1; j < rbucket; j++) {           offset[j] += d;         }         if (lbucket0 == rbucket) {           for (int j = l; j <= r; j++) v[j] += d;           resort(lbucket0);         } else {           for (int j = l; j < lstart1; j++) v[j] += d;           for (int j = bstart(rbucket); j <= r; j++) v[j] += d;           resort(lbucket0);           resort(rbucket);         }       } else {         int yy;         scanf( %d , &yy);         long long y = yy;         vector<pair<long long, int> >::iterator it;         int l = 0, r = -1;         for (int i = 0; i <= buckets; i++) {           if (y - offset[i] <= 0) continue;           pair<long long, int> search = {y - offset[i], 0};           it = lower_bound(x[i].begin(), x[i].end(), search);           if (it == x[i].end()) continue;           if (it->first == y - offset[i]) {             l = it->second;             break;           }         }         for (int i = buckets; i >= 0; i--) {           if (y - offset[i] <= 0) continue;           pair<long long, int> search = {y - offset[i] + 1, 0};           it = lower_bound(x[i].begin(), x[i].end(), search);           if (it == x[i].begin()) continue;           it--;           if (it->first == y - offset[i]) {             r = it->second;             break;           }         }         printf( %d n , r - l);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       int a, b, n;       cin >> a >> b >> n;       if (n % 3 == 0)         cout << a << endl;       else if (n % 3 == 1)         cout << b << endl;       else         cout << (a ^ b) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a;   int tab[105];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a;       tab[a]--;     }     sort(tab + 1, tab + 1 + 100);     {}     for (int wynik = 1; wynik <= 101; wynik++) {       int ile = 0;       for (int i = 1; i <= 100; i++) {         ile += (-tab[i]) / wynik;       }       if (ile < n) {         printf( %d n , wynik - 1);         return 0;       }     }     puts( 0 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0, a[100001];     long long sum = 0, x = 0, ans = 0;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];     sum = sum / n;     for (int i = 0; i < n; i++) x += a[i] - sum, ans += abs(x);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char a[440000], b[440000];   int cnta = 0, cntb = 0;   int df[440000] = {0};   int czl[440000], czr[440000];   int zz1 = 0, zz2 = 0;   int ab[440000] = {0}, ba[440000] = {0};   int ans = 0;   int main() {     cin >> n;     cin >> a >> b;     for (int i = 0; i < n; i++) {       if (a[i] ==  a ) {         cnta++;         if (a[i] != b[i]) ab[++zz1] = i + 1;       }       if (b[i] ==  a ) {         cntb++;         if (a[i] != b[i]) ba[++zz2] = i + 1;       }     }     if ((zz1 + zz2) % 2 == 1) {       cout << -1 << endl;       return 0;     }     while (zz1 || zz2) {       if (zz2 % 2 == 1) {         zz2++;         ans++;         czl[ans] = ab[zz1], czr[ans] = ab[zz1];         ba[zz2] = ab[zz1];         zz1--;       }       if (zz1) {         ans++;         czl[ans] = ab[zz1], czr[ans] = ab[zz1 - 1];         zz1 -= 2;       } else {         ans++;         czl[ans] = ba[zz2], czr[ans] = ba[zz2 - 1];         zz2 -= 2;       }     }     cout << ans << endl;     for (int i = 1; i <= ans; i++) cout << czl[i] <<     << czr[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int vis[N];   vector<int> a[N], tmp;   int main() {     int n;     scanf( %d , &n);     int x = 1;     for (int i = 2; i <= n; i++) {       if (n - (n + i - 1) / i - i + 1 > n - (n + x - 1) / x - x + 1) x = i;     }     int ans = n - (n + x - 1) / x - x + 1;     int cur = 0;     for (int i = 1; i <= n; i++) {       if (i % x == 1) cur++;       a[cur].push_back(i);     }     int cnt = 0;     while (cnt < ans) {       for (int i = 1; i <= cur; i++) {         int sz = a[i].size();         for (int j = 0; j < sz - 1; j++) {           if (!vis[a[i][j]]) {             vis[a[i][j]] = 1;             tmp.push_back(a[i][j]);           }           if (tmp.size() == x) break;         }         if (tmp.size() == x) break;       }       int k = tmp.size();       cnt += k;       printf( %d  , k);       for (int j : tmp) printf( %d  , j);       printf(  n );       fflush(stdout);       tmp.clear();       int pos;       scanf( %d , &pos);       for (int i = 1; i <= k; i++) {         if (vis[pos]) cnt--;         vis[pos] = 0;         pos = pos % n + 1;       }     }     printf( 0 n );     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     bool a[m + 1];     memset(a, 0, sizeof(a));     for (int i = 1; i <= n; i++) {       int l, r;       cin >> l >> r;       for (int j = l; j <= r; j++) a[j] = 1;     }     vector<int> v;     int res = 0;     for (int i = 1; i <= m; i++) {       if (a[i] == 0) {         res++;         v.push_back(i);       }     }     cout << res << endl;     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   struct a1 {     int value, freq;   } arr[101];   bool compare(a1 lhs, a1 rhs) { return lhs.freq > rhs.freq; }   int main() {     int temp = 0, j, n, num = 0, m, i, a[101], ans = 0;     scanf( %d %d , &n, &m);     int b[n], c[n];     memset(a, 0, sizeof(a));     for (i = 0; i < n; i++) {       scanf( %d , &temp);       a[temp]++;     }     temp = 0;     for (i = 1; i <= 100; i++) {       if (a[i] != 0) {         arr[num].freq = a[i];         arr[num++].value = i;       }     }     sort(arr, arr + num, compare);     for (i = 0; i < num; i++) {       j = 0;       while (j < arr[i].freq) {         b[temp++] = arr[i].value;         j++;       }     }     for (i = arr[0].freq; i < n; i++) {       c[i - arr[0].freq] = b[i];     }     for (i = 0; i < arr[0].freq; i++) {       c[n - arr[0].freq + i] = arr[0].value;     }     for (i = 0; i < n; i++) {       if (b[i] != c[i]) ans++;     }     printf( %d n , ans);     for (i = 0; i < n; i++) {       printf( %d %d n , b[i], c[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class A>   void pr(A a) {     cout << a;     cout <<   n ;   }   template <class A, class B>   void pr(A a, B b) {     cout << a <<    ;     pr(b);   }   template <class A, class B, class C>   void pr(A a, B b, C c) {     cout << a <<    ;     pr(b, c);   }   template <class A, class B, class C, class D>   void pr(A a, B b, C c, D d) {     cout << a <<    ;     pr(b, c, d);   }   template <class A>   void PR(A a, long long n) {     for (long long i = (long long)(0); i < (long long)(n); i++) {       if (i) cout <<    ;       cout << a[i];     }     cout <<   n ;   }   long long check(long long n, long long m, long long x, long long y) {     return x >= 0 && x < n && y >= 0 && y < m;   }   const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},                   dy[4] = {0, 1, 0, -1};   void Main() {     int h1, m1, h2, m2;     scanf( %d:%d , &h1, &m1);     scanf( %d:%d , &h2, &m2);     int d = h1 * 60 + m1 + h2 * 60 + m2;     d /= 2;     if (h1 * 60 + m1 > h2 * 60 + m2) d += 12 * 60;     d %= 24 * 60;     printf( %02d:%02d n , d / 60, d % 60);   }   int main() {     Main();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   struct Node {     int a, px, ori, c;   } node[N];   int n, l, r;   bool cmp_px(Node &a, Node &b) { return a.px < b.px; }   bool cmp_ori(Node &a, Node &b) { return a.ori < b.ori; }   int main() {     cin >> n >> l >> r;     int t;     for (int i = 0; i < n; i++) {       cin >> t;       node[i].ori = i;       node[i].a = t * (-1);       node[i].c = l;     }     for (int i = 0; i < n; i++) {       cin >> t;       node[i].px = t;     }     sort(node, node + n, cmp_px);     for (int i = 1; i < n; i++) {       if (node[i].a > node[i - 1].a) continue;       int cha = node[i - 1].a - node[i].a;       node[i].a = node[i].a + cha + 1;       node[i].c += cha + 1;       if (node[i].c > r) {         cout << -1 << endl;         return 0;       }     }     {       sort(node, node + n, cmp_ori);       for (int i = 0; i < n; i++) {         cout << node[i].c <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int sb, eb;     vector<int> box;     cin >> sb;     for (int a = 0; a < sb; a++) {       cin >> eb;       box.push_back(eb);     }     sort(box.begin(), box.end());     for (int a = 0; a < sb; a++) {       cout << box[a] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, q, cnt, k, m, r, ans;   int fa[21][100010], dep[100010], st[100010], ed[100010], h[100010];   int f[100010][310];   int t[100010];   bool vis[100010];   struct node {     int id, num;     bool operator<(const node &T) const { return num < T.num; }   } s[100010];   vector<int> e[100010], Q;   inline void insert(int u, int v) {     e[u].push_back(v);     e[v].push_back(u);   }   int find(int x) {     int sum = 0;     for (; x; x -= (x & -x)) sum += t[x];     return sum;   }   void add(int x, int k) {     for (; x <= n; x += (x & -x)) t[x] += k;   }   void dfs(int x) {     st[x] = ++cnt;     for (int i = 0; i < e[x].size(); i++)       if (fa[0][x] != e[x][i]) {         fa[0][e[x][i]] = x;         dep[e[x][i]] = dep[x] + 1;         dfs(e[x][i]);       }     ed[x] = cnt;   }   int lca(int a, int b) {     int i, kk;     if (dep[a] != dep[b]) {       if (dep[a] < dep[b]) swap(a, b);       i = 0;       kk = 1;       while (kk <= dep[a] - dep[b]) {         i++;         kk <<= 1;       }       while (dep[a] > dep[b]) {         if (kk <= dep[a] - dep[b]) a = fa[i][a];         i--;         kk >>= 1;       }     }     if (a == b) return a;     i = 0;     while (fa[i][a] != fa[i][b]) i++;     while (fa[0][a] != fa[0][b]) {       if (fa[i][a] != fa[i][b]) {         a = fa[i][a];         b = fa[i][b];       }       i--;     }     return fa[0][a];   }   int main() {     int a, b;     scanf( %d%d , &n, &q);     for (int i = 1; i < n; i++) {       scanf( %d%d , &a, &b);       insert(a, b);     }     dfs(1);     f[0][0] = 1ll;     for (int i = 1; i <= 20; i++)       for (int j = 1; j <= n; j++) fa[i][j] = fa[i - 1][fa[i - 1][j]];     while (q--) {       scanf( %d%d%d , &k, &m, &r);       Q.clear();       cnt = ans = 0;       for (int j = 1; j <= k; j++) {         scanf( %d , &a);         Q.push_back(a);         vis[a] = 1;         add(st[a], 1);         add(ed[a] + 1, -1);       }       for (int j = 0; j < k; j++) {         a = Q[j];         b = lca(r, a);         h[a] = find(st[a]) + find(st[r]) - 2 * find(st[b]) + vis[b] - 1;         s[++cnt].id = a;         s[cnt].num = h[a];       }       sort(s + 1, s + 1 + cnt);       for (int i = 0; i <= m; i++) f[1][i] = 0ll;       for (int i = 1; i <= k; i++)         for (int j = 1; j <= m; j++)           f[i][j] = ((long long)f[i - 1][j] * (j - s[i].num) % 1000000007 +                      f[i - 1][j - 1]) %                     1000000007;       for (int j = 1; j <= m; j++) ans = (ans + f[k][j]) % 1000000007;       printf( %d n , ans);       for (int j = 0; j < k; j++) {         a = Q[j];         add(st[a], -1);         add(ed[a] + 1, 1);         vis[a] = 0;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   long long binpow(long long base, long long exp, int mod) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) res = (res * base) % mod;       exp = exp >> 1;       base = (base * base) % mod;     }     return res;   }   long long mod(long long x) {     return ((x % 1000000007LL + 1000000007LL) % 1000000007LL);   }   long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }   long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n, m;       cin >> n >> m;       long long int maxdiff = -1e18;       long long int maxele = -1e18;       for (int i = 0; i < n; i++) {         long long int l, r;         cin >> l >> r;         maxdiff = max(maxdiff, l - r);         maxele = max(maxele, l);       }       long long int ans = 1;       m -= maxele;       if (m > 0) {         if (maxdiff <= 0) {           ans = -1;         } else {           ans += (m + maxdiff - 1) / maxdiff;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const double PI = 3.141592653589793238460;   using namespace std;   vector<int> d;   vector<int> l;   vector<int> r;   vector<int> u;   bool isPossibleL(string st) {     for (char ch : st) {       for (int n : l)         if (ch -  0  == n) return false;     }     return true;   }   bool isPossibleR(string st) {     for (char ch : st) {       for (int n : r)         if (ch -  0  == n) return false;     }     return true;   }   bool isPossibleU(string st) {     for (char ch : st) {       for (int n : u)         if (ch -  0  == n) return false;     }     return true;   }   bool isPossibleD(string st) {     for (char ch : st) {       for (int n : d)         if (ch -  0  == n) return false;     }     return true;   }   int main() {     l.push_back(1), l.push_back(4), l.push_back(7), l.push_back(0);     r.push_back(3), r.push_back(6), r.push_back(9), r.push_back(0);     d.push_back(7), d.push_back(0), d.push_back(9);     u.push_back(1), u.push_back(2), u.push_back(3);     int n;     string st;     cin >> n >> st;     if (isPossibleL(st) || isPossibleR(st) || isPossibleU(st) || isPossibleD(st))       cout <<  NO ;     else       cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> statues(8);   vector<vector<char>> MAT(8, vector<char>(8));   vector<vector<vector<bool>>> VIS(8,                                    vector<vector<bool>>(8,                                                         vector<bool>(10, false)));   vector<pair<int, int>> moveDir = {{0, 1},  {0, -1}, {1, 0},   {-1, 0}, {1, 1},                                     {-1, 1}, {1, -1}, {-1, -1}, {0, 0}};   bool checkStatues(int r, int c, int level) {     for (int i = 0; i < statues[c].size(); ++i) {       if (statues[c][i] + level < 8 && statues[c][i] + level == r) return false;     }     return true;   }   bool isSafe(int r, int c, int level) {     if (level > 8) level = 8;     if (r < 0 || r >= 8 || c < 0 || c >= 8 || VIS[r][c][level]) return false;     return checkStatues(r, c, level);   }   bool dfs(int r, int c, int level) {     bool canMove = false;     if (level > 8) level = 8;     if (r == 0 && c == 7) return true;     for (int i = 0; i < 9; ++i) {       int newR = r + moveDir[i].first;       int newC = c + moveDir[i].second;       if (isSafe(newR, newC, level + 1) && checkStatues(newR, newC, level)) {         VIS[r][c][level] = true;         canMove = canMove || dfs(newR, newC, level + 1);       }     }     return canMove;   }   int main() {     for (int i = 0; i < 8; ++i) {       for (int j = 0; j < 8; ++j) {         cin >> MAT[i][j];         if (MAT[i][j] ==  S ) statues[j].push_back(i);       }     }     bool canWin = dfs(7, 0, 0);     cout << ((canWin) ?  WIN  :  LOSE ) <<   n ;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const double eps = 10e-10;   const int mod = 1000000007;   const int maxn = 300005;   const int maxm = 10005;   pair<int, int> ans[maxn];   int main() {     int n, m, a;     while (~scanf( %d%d , &n, &m)) {       priority_queue<pair<int, int> > q;       for (int i = (0); i < (n); i++)         scanf( %d , &a), q.push(make_pair(a, i + 1));       int cnt = 0;       while (!q.empty()) {         stack<pair<int, int> > st;         pair<int, int> cur = q.top();         q.pop();         while (!q.empty() && cur.first) {           pair<int, int> cc = q.top();           q.pop();           if (cc.first >= 1)             cc.first--, cur.first--,                 ans[cnt++] = make_pair(cc.second, cur.second);           if (cc.first) st.push(cc);         }         if (cur.first) break;         while (!st.empty()) q.push(st.top()), st.pop();       }       if (cnt < m / 2) {         puts( No );         continue;       }       printf( Yes n%d n , m / 2);       for (int i = (0); i < (cnt); i++)         printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M, neg, nsus;   int ar[100002];   int cnt[100002];   int sus[100002];   int main() {     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) {       scanf( %d , &ar[i]);       if (ar[i] > 0)         cnt[ar[i]]++;       else {         cnt[-ar[i]]--;         neg++;       }     }     for (int i = 1; i <= N; i++)       if (cnt[i] + neg == M) {         sus[i] = 1;         nsus++;       }     for (int i = 1; i <= N; i++) {       if ((ar[i] < 0 && !sus[-ar[i]]) || (ar[i] > 0 && sus[ar[i]] && nsus == 1))         printf( Truth n );       else if ((ar[i] < 0 && sus[-ar[i]] && nsus == 1) ||                (ar[i] > 0 && !sus[ar[i]]))         printf( Lie n );       else         printf( Not defined n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       long long a = 0;       for (int i = 0; i < n; i++) {         int k;         cin >> k;         a += k;       }       if (a == m)         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 1e2 + 10;   const long long mod = 1e9 + 31;   mt19937 mtrand(time(0));   int n, m;   char s[2][1 << 12];   int mp[2][1 << 14];   int f[1 << 15], ans, pr[1 << 15];   int unfd(int x) {     int r = x;     while (r != f[r]) r = f[r];     int t;     while (f[x] != r) t = f[x], f[x] = r, x = t;     return r;   }   void unjoin(int x, int y) {     int fx = unfd(x), fy = unfd(y);     if (fx != fy) {       --ans;       f[fx] = fy;     }   }   int main() {     int num;     cin >> n >> m;     for (int i = 0; i < n; ++i) {       int id = i & 1, nid = id ^ 1;       scanf( %s , s[id]);       num = 0;       for (int j = 0; j < m / 4; ++j) {         if (s[id][j] >=  0  && s[id][j] <=  9 )           num = s[id][j] -  0 ;         else           num = s[id][j] -  A  + 10;         for (int k = 0; k < 4; ++k) {           mp[id][j * 4 + k] = (num >> (3 - k)) & 1;           if (mp[id][j * 4 + k] == 1) ++ans;         }       }       for (int j = m; j < m * 2; ++j) f[j] = j;       if (i > 0) {         for (int j = 0; j < m; ++j) {           if (mp[nid][j] & mp[id][j]) unjoin(j, m + j);         }       }       for (int j = 1; j < m; ++j) {         if (mp[id][j - 1] & mp[id][j]) unjoin(m + j - 1, m + j);       }       for (int j = m; j < m * 2; ++j) {         pr[unfd(j)] = j - m;       }       for (int j = 0; j < m; ++j) {         f[j] = pr[unfd(j + m)];       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 2e5 + 10;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   long long poww(long long a, long long b) {     if (b == 0) return 1;     long long x = poww(a, b / 2) % mod;     if (b & 1)       return (((x * x) % mod) * a) % mod;     else       return (x * x) % mod;   }   long long n, m, k, dis[maxn], mark[maxn], p[maxn], ans1 = 0, ans2 = 0;   vector<long long> g[maxn], g2[maxn];   void bfs(long long v) {     queue<long long> qu;     for (int i = 1; i <= n; i++) {       mark[i] = 0;       dis[i] = INF;     }     mark[v] = 1;     dis[v] = 0;     qu.push(v);     while (qu.size()) {       long long u = qu.front();       qu.pop();       for (auto uu : g2[u]) {         if (!mark[uu]) {           mark[uu] = 1;           dis[uu] = dis[u] + 1;           qu.push(uu);         }       }     }   }   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; i++) {       long long v, u;       cin >> v >> u;       g[v].push_back(u);       g2[u].push_back(v);     }     cin >> k;     for (int i = 1; i <= k; i++) cin >> p[i];     long long t = p[k];     bfs(t);     for (int i = 1; i < k; i++) {       long long minn = INF, te = 0;       for (auto u : g[p[i]]) {         if (dis[u] < minn) {           minn = dis[u];           te = 1;         } else if (dis[u] == minn)           te++;       }       long long to = p[i + 1];       if (dis[to] > minn) {         ans1++;         ans2++;       } else {         if (te > 1) ans2++;       }     }     cout << ans1 <<     << ans2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       if (a == 0 || b == 0 || c == 0) {         int cnt = 0;         if (a % 2 == 1) cnt++;         if (b % 2 == 1) cnt++;         if (c % 2 == 1) cnt++;         if (d % 2 == 1) cnt++;         if (cnt < 2)           cout <<  Yes  << endl;         else           cout <<  No  << endl;         continue;       }       int cnt = 0;       if (a % 2 == 1) cnt++;       if (b % 2 == 1) cnt++;       if (c % 2 == 1) cnt++;       if (d % 2 == 1) cnt++;       if (cnt == 1 || cnt == 0)         cout <<  Yes  << endl;       else {         a--;         b--;         c--;         d += 3;         int cnt = 0;         if (a % 2 == 1) cnt++;         if (b % 2 == 1) cnt++;         if (c % 2 == 1) cnt++;         if (d % 2 == 1) cnt++;         if (cnt == 1 || cnt == 0)           cout <<  Yes  << endl;         else           cout <<  No  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, sum = 0;       long long ans = 0;       cin >> n;       char s[n];       cin >> (s + 1);       map<int, int> f;       f[0] = 1;       for (int i = 1; i <= n; i++) {         int tmp = s[i] -  0 ;         sum += tmp;         ans += f[sum - i];         f[sum - i]++;       }       cout << ans << endl;     }   }