malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct point {     long long x, y;   };   point p[345678];   vector<point> important, ugly;   vector<int> ilist;   int n;   long long ans[345678];   long long distance(int i, int j) {     return llabs(important[i].x - important[j].x) +            llabs(important[i].y - important[j].y);   }   long long distance(point p, point q) {     return llabs(p.x - q.x) + llabs(p.y - q.y);   }   long long dp[15][15][15][15];   long long lovetourist(int i, int f, int l, int k) {     if (k == 0) return distance(f, l);     if (i == important.size()) return -1e17;     if (dp[i + 1][f + 1][l + 1][k + 1] != -1)       return dp[i + 1][f + 1][l + 1][k + 1];     long long ret = lovetourist(i + 1, f, l, k);     if (f == -1)       ret = max(ret, lovetourist(i + 1, i, i, k - 1));     else       ret = max(ret, distance(l, i) + lovetourist(i + 1, f, i, k - 1));     return dp[i + 1][f + 1][l + 1][k + 1] = ret;   }   long long respecttourist() {     long long res = -1e17;     for (int i = 0; i < ilist.size(); i++) {       for (int j = i + 1; j < ilist.size(); j++) {         for (int k = 1; k <= n; k++) {           if (k == ilist[i] || k == ilist[j]) continue;           res = max(res, distance(p[ilist[i]], p[ilist[j]]) +                              distance(p[ilist[i]], p[k]) +                              distance(p[ilist[j]], p[k]));         }       }     }     return res;   }   int main() {     cin >> n;     long long minx, maxx, miny, maxy, sum = 0;     for (int i = 1; i <= n; i++) {       cin >> p[i].x >> p[i].y;       if (i == 1) {         minx = p[i].x;         maxx = p[i].x;         miny = p[i].y;         maxy = p[i].y;       }       minx = min(minx, p[i].x);       maxx = max(maxx, p[i].x);       miny = min(miny, p[i].y);       maxy = max(maxy, p[i].y);     }     p[n + 1] = p[1];     for (int i = 1; i <= n; i++) {       sum += llabs(p[i].x - p[i + 1].x) + llabs(p[i].y - p[i + 1].y);       ilist.push_back(i);       if (p[i].x == minx)         important.push_back(p[i]);       else if (p[i].x == maxx)         important.push_back(p[i]);       else if (p[i].y == miny)         important.push_back(p[i]);       else if (p[i].y == maxy)         important.push_back(p[i]);       else {         ugly.push_back(p[i]);         ilist.pop_back();       }     }     memset(dp, -1, sizeof(dp));     long long res = lovetourist(0, -1, -1, important.size());     assert(2 <= important.size() && important.size() <= 8);     int k = n;     while (!ugly.empty()) {       ans[k--] = res;       ugly.pop_back();     }     for (int i = important.size(); i >= 3; i--)       ans[k--] = lovetourist(0, -1, -1, i);     ans[3] = max(ans[3], respecttourist());     for (int i = 3; i <= n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   struct str {     char s[110];   } p[110];   int n;   int ans[26], connect[26][26], v, e;   int toposort(int n, int mat[][26], int* ret) {     int d[26], i, j, k;     for (i = 0; i < n; i++)       for (d[i] = j = 0; j < n; d[i] += mat[j++][i])         ;     for (k = 0; k < n; ret[k++] = i) {       for (i = 0; d[i] && i < n; i++)         ;       if (i == n) return 0;       for (d[i] = -1, j = 0; j < n; j++) d[j] -= mat[i][j];     }     return 1;   }   int main() {     int i, j;     bool ok = true;     scanf( %d , &n);     memset(connect, 0, sizeof(connect));     for (i = 0; i < n; ++i) {       scanf( %s , p[i].s);       if (i > 0 && ok) {         for (j = 0; p[i].s[j] && p[i - 1].s[j]; ++j) {           if (p[i].s[j] != p[i - 1].s[j]) {             connect[p[i - 1].s[j] -  a ][p[i].s[j] -  a ] = 1;             break;           }         }         if (strlen(p[i].s) < strlen(p[i - 1].s) && j == strlen(p[i].s))           ok = false;       }     }     if (ok && toposort(26, connect, ans)) {       for (i = 0; i < 25; ++i) {         printf( %c , ans[i] +  a );       }       printf( %c n , ans[i] +  a );     } else {       puts( Impossible );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, k, a[110000], cnt, tmp[110000];   int edgenum = 1, vet[610000], val[610000], Next[610000], Head[110000];   double ang[610000];   bool vis[110000];   map<pair<int, int>, int> rnk;   vector<long long> sum[110000];   struct node {     int x, y;     node() {}     node(int _x, int _y) : x(_x), y(_y) {}   } p[110000];   node operator-(const node &a, const node &b) {     return node(a.x - b.x, a.y - b.y);   }   char Getchar() {     static char now[1 << 20], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 20, stdin);       if (T == S) return EOF;     }     return *S++;   }   int read() {     int x = 0, f = 1;     char ch = Getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = Getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = Getchar();     return x * f;   }   void addedge(int u, int v) {     vet[++edgenum] = v;     Next[edgenum] = Head[u];     Head[u] = edgenum;   }   int dfs(int u) {     vis[u] = true;     int flow = 1, tmp;     for (int e = Head[u]; e; e = Next[e])       if (!vis[vet[e]]) {         tmp = dfs(vet[e]);         val[e] += tmp;         val[e ^ 1] -= tmp;         flow += tmp;       }     return flow;   }   inline bool cmp(int a, int b) { return ang[a] < ang[b]; }   inline long long cross(node x, node y) {     return 1ll * x.x * y.y - 1ll * x.y * y.x;   }   int main() {     n = read();     m = read();     int u, v;     for (int i = 1; i <= m; i++) {       u = read();       v = read();       addedge(u, v);       addedge(v, u);     }     for (int i = 1; i <= n; i++) p[i].x = read(), p[i].y = read();     int rt = 1;     for (int i = 2; i <= n; i++)       if (p[i].x < p[rt].x) rt = i;     dfs(rt);     for (int u = 1; u <= n; u++) {       cnt = 0;       for (int e = Head[u]; e; e = Next[e]) {         tmp[++cnt] = e;         v = vet[e];         ang[e] = atan2(p[v].y - p[u].y, p[v].x - p[u].x);       }       sort(tmp + 1, tmp + cnt + 1, cmp);       sum[u].push_back(0);       for (int i = 1; i <= cnt; i++) {         rnk[pair<int, int>(u, vet[tmp[i]])] = i;         sum[u].push_back(sum[u].back() + val[tmp[i]]);       }     }     q = read();     int l, r;     while (q--) {       k = read();       for (int i = 1; i <= k; i++) a[i] = read();       long long s = 0, ans = k;       for (int i = 2; i < k; i++)         s += cross(p[a[i]] - p[a[1]], p[a[i + 1]] - p[a[1]]);       if (s < 0) reverse(a + 1, a + k + 1);       a[0] = a[k];       a[k + 1] = a[1];       for (int i = 1; i <= k; i++) {         l = rnk[pair<int, int>(a[i], a[i + 1])];         r = rnk[pair<int, int>(a[i], a[i - 1])];         ans += sum[a[i]][r] - sum[a[i]][l - 1];         if (l > r) ans += sum[a[i]][(int)sum[a[i]].size() - 1];       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     if (m == 3) {       if (n == 3) {         cout << 0 <<     << 0 <<   n ;         cout << 0 <<     << 1 <<   n ;         cout << 1 <<     << 0 <<   n ;         return 0;       } else if (n == 4) {         cout << 0 <<     << 0 <<   n ;         cout << 0 <<     << 10 <<   n ;         cout << 10 <<     << 0 <<   n ;         cout << 1 <<     << 1 <<   n ;         return 0;       } else if (n >= 5) {         cout << -1;         return 0;       }     }     int x = 1000000;     for (int i = 0; i < m; i++) cout << i <<     << (i * i + x) <<   n ;     for (int i = 0; i < n - m; i++) cout << i <<     << (-i * i - x) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, memo[100001];   vector<long long> a;   long long x;   long long rek(int pos) {     long long &ret = memo[pos];     if (ret != -1) return ret;     ret = rek(pos - 1) + 20;     x = upper_bound(a.begin(), a.end(), a[pos] - 90) - a.begin();     if (x)       ret = min(ret, rek(x - 1) + 50);     else       ret = min(ret, 50LL);     x = upper_bound(a.begin(), a.end(), a[pos] - 1440) - a.begin();     if (x)       ret = min(ret, rek(x - 1) + 120);     else       ret = min(ret, 120LL);     return ret;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }     memset(memo, -1, sizeof(memo));     memo[0] = 20;     rek(n - 1);     for (int i = 0; i < n; i++)       if (!i)         cout << memo[i] << endl;       else         cout << memo[i] - memo[i - 1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     map<int, int> mp;     int n, k;     cin >> n >> k;     int c;     cin >> c;     for (int i = 1; i <= c; i++) {       int x;       cin >> x;       mp[x] = 1;     }     int ans = 0;     int t = 0;     for (int i = 1; i <= n; i++) {       t++;       if (mp[i] == 1) {         ans++;         t = 0;       } else if (t == k) {         ans++;         t = 0;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T, typename TT>   inline ostream &operator<<(ostream &os, const pair<T, TT> &t) {     return os << t.first <<     << t.second;   }   template <typename T>   inline ostream &operator<<(ostream &os, const vector<T> &t) {     for (auto i : t) os << i <<    ;     return os;   }   template <typename T>   inline istream &operator>>(istream &is, vector<T> &v) {     for (T &t : v) is >> t;     return is;   }   template <typename T1, typename T2>   inline istream &operator>>(istream &is, pair<T1, T2> &t) {     is >> t.first >> t.second;     return is;   }   const long long mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     vector<int> v(n);     cin >> v;     int mn = *min_element(v.begin(), v.end()),         c = n - count(v.begin(), v.end(), mn);     if (c >= n / 2)       cout <<  Alice  <<   n ;     else       cout <<  Bob  <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ;     int T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool mat[3001][3001];   vector<int> v[3010];   int main() {     int n, m, a, b, result = 0;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) mat[i][j] = false;     for (int i = 0; i < m; i++) {       cin >> a >> b;       v[a].push_back(b);       mat[a][b] = true;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i != j) {           int r = 0;           for (int k = 0; k < v[i].size(); k++) {             if (mat[v[i][k]][j] == true) r++;           }           result += (r * (r - 1)) / 2;         }       }     }     cout << result;   }
#include <bits/stdc++.h>   using namespace std;   int n;   double P[1000];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lf , P + i);     }     sort(P, P + n);     reverse(P, P + n);     double x1 = 0;     double x2 = 1;     double res = 0;     for (int i = 0; i < n; i++) {       double s = (1 - P[i]);       if (s == 0) s = 1;       if (res == 1) break;       x1 += P[i] / s;       x2 *= s;       res = max(res, x1 * x2);     }     printf( %.12lf n , res);     return 0;   }
#include <bits/stdc++.h>   int main(void) {     int size = 0;     scanf( %ld , &size);     char fmt[size + 1];     fmt[size] =   0 ;     scanf( %s , fmt);     int width = 0;     int maxHeight = 1;     int ithX[size];     int depth[size];     int currentDepth = 0;     char ch =   0 ;     for (size_t ith = 0; ith < size; ith += 1) {       char thisCh = fmt[ith];       width += 1;       if (thisCh ==  [ ) {         currentDepth += 1;         depth[ith] = currentDepth;       } else {         depth[ith] = currentDepth;         currentDepth -= 1;         if (ch ==  [ ) width += 3;       }       ithX[ith] = width;       size_t thisHeight = (currentDepth << 1) + 1;       if (maxHeight < thisHeight) maxHeight = thisHeight;       ch = thisCh;     }     size_t outLen = width * maxHeight;     char buffer[outLen + 1];     buffer[outLen] =   0 ;     memset(buffer,    , outLen);     for (size_t ith = 0; ith < size; ith += 1) {       size_t x = ithX[ith] - 1;       size_t d = depth[ith];       int lineEnd = maxHeight - d;       int lineStart = maxHeight - (lineEnd + 1);       int indexStart = x + lineStart * width;       int indexEnd = x + lineEnd * width;       if (fmt[ith] ==  [ )         buffer[indexStart + 1] = buffer[indexEnd + 1] =  - ;       else         buffer[indexEnd - 1] = buffer[indexStart - 1] =  - ;       buffer[indexStart] = buffer[indexEnd] =  + ;       for (size_t y = lineStart + 1; y < lineEnd; y += 1)         buffer[x + y * width] =  | ;     }     for (size_t line = 0; line < maxHeight; line += 1) {       fwrite(buffer + line * width, sizeof(char), width, stdout);       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, x, y, T, ans, mx, mi, cas, num, len;   bool flag;   int p, a[25][105], b[25][105], c[25][105];   char s[1000];   int dp[1005];   int main() {     scanf( %d%d%d , &n, &m, &p);     for (i = 1; i <= n; i++) {       scanf( %s , s);       for (j = 1; j <= m; j++) {         scanf( %d%d%d , &a[i][j], &b[i][j], &c[i][j]);       }     }     int v;     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         memset(dp, 0, sizeof(dp));         for (x = 1; x <= m; x++) {           for (v = p; v >= 0; v--) {             for (num = 0; num <= c[i][x]; num++) {               int pro = b[j][x] - a[i][x];               if (v - num >= 0 && dp[v] < dp[v - num] + pro * num) {                 dp[v] = dp[v - num] + pro * num;                 ans = max(ans, dp[v]);               } else if (v - num < 0)                 break;             }           }         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long LLMAX = 9223372036854775807LL;   const int MOD = 1000000007;   const int maxn = 500001;   int n;   int a[maxn];   pair<int, int> p[maxn];   int pr[maxn], ne[maxn];   int main() {     scanf( %d , &(n));     for (int(i) = 0; (i) < (int)(n); ++(i)) scanf( %d , &(a[i]));     for (int i = 0; i < n; ++i) {       p[i] = make_pair((a[i]), (i));       pr[i] = i - 1;       ne[i] = i + 1;     }     sort(p, p + n);     long long ans = 0, l = 0, r = n - 1;     for (int i = 0; i < n - 2; ++i) {       int j = p[i].second;       if (j == l) {         ans += p[i].first;         l = ne[j];       } else if (j == r) {         ans += p[i].first;         r = pr[r];       } else {         ans += min(a[pr[j]], a[ne[j]]);         pr[ne[j]] = pr[j];         ne[pr[j]] = ne[j];       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     string a, b, c;     vector<vector<long long> > arr(3, vector<long long>((26 * 2) + 1, 0));     cin >> n;     cin >> a >> b >> c;     long long len = a.length();     for (long long i = 0; i < len; i++) {       char cur = a[i];       if (cur >=  a ) {         arr[0][cur - 97]++;       } else {         arr[0][cur - 65 + 26]++;       }     }     for (long long i = 0; i < len; i++) {       char cur = b[i];       if (cur >=  a ) {         arr[1][cur - 97]++;       } else {         arr[1][cur - 65 + 26]++;       }     }     for (long long i = 0; i < len; i++) {       char cur = c[i];       if (cur >=  a ) {         arr[2][cur - 97]++;       } else {         arr[2][cur - 65 + 26]++;       }     }     for (long long i = 0; i < 52; i++) {       if (arr[0][i] > arr[0][52]) {         arr[0][52] = arr[0][i];       }       if (arr[1][i] > arr[1][52]) {         arr[1][52] = arr[1][i];       }       if (arr[2][i] > arr[2][52]) {         arr[2][52] = arr[2][i];       }     }     long long x = arr[0][52], y = arr[1][52], z = arr[2][52];     if (n == 1 && x == len) {       x = len - 1;     } else if (x + n >= len) {       x = len;     } else {       x += n;     }     if (n == 1 && y == len) {       y = len - 1;     } else if (y + n >= len) {       y = len;     } else {       y += n;     }     if (n == 1 && z == len) {       z = len - 1;     } else if (z + n >= len) {       z = len;     } else {       z += n;     }     if (x > y && x > z) {       cout <<  Kuro n ;     } else if (y > x && y > z) {       cout <<  Shiro n ;     } else if (z > x && z > y) {       cout <<  Katie n ;     } else {       cout <<  Draw n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 5;   const int inf = ~0U >> 1;   template <class U, class V>   struct MCMF {     static const int N = 8000, M = 7001010;     int h[N], ing[N], pre[N], to[M], ne[M], e, s, t, n;     U cap[M];     V dis[N], cost[M];     void ini(int _n = N) {       fill(h, h + (n = _n), -1);       e = 0;     }     void liu(int u, int v, U c, V w) {       to[e] = v;       ne[e] = h[u];       cap[e] = c;       cost[e] = w;       h[u] = e++;     }     void link(int u, int v, U c, V w) {       liu(u, v, c, w);       liu(v, u, 0, -w);     }     bool spfa() {       queue<int> Q;       fill(dis, dis + n, -inf);       Q.push(s), ing[s] = 1, dis[s] = 0;       while (!Q.empty()) {         int c = Q.front();         Q.pop();         ing[c] = 0;         for (int k = h[c]; ~k; k = ne[k])           if (cap[k] > 0) {             int v = to[k];             if (dis[c] + cost[k] > dis[v]) {               dis[v] = dis[c] + cost[k];               pre[v] = k;               if (!ing[v]) Q.push(v), ing[v] = 1;             }           }       }       return dis[t] != -inf;     }     U flow;     V mincost;     pair<U, V> run(int _s, int _t) {       s = _s, t = _t;       flow = mincost = 0;       while (spfa()) {         U pl = inf;         int p, k;         for (p = t; p != s; p = to[k ^ 1]) pl = min(pl, cap[k = pre[p]]);         for (p = t; p != s; p = to[k ^ 1])           cap[k = pre[p]] -= pl, cap[k ^ 1] += pl;         mincost += pl * dis[t];         flow += pl;       }       return make_pair(flow, mincost);     }   };   MCMF<int, int> flow;   int n, a[N];   int can[3005][3005];   int main() {     scanf( %d , &n);     for (int i = (1); i < (n + 1); i++) {       scanf( %d , &a[i]);     }     flow.ini(n * 2 + 100);     int t = flow.n - 1, s = t - 1, ss = s - 1;     ;     for (int i = (1); i < (n + 1); i++) {       flow.link(i, i + n, 1, 1);       flow.link(i, i + n, inf, 0);       int f1 = 1, f2 = 1, f3 = 1;       for (int j = (i + 1); j < (n + 1); j++) {         if (a[j] - a[i] == 1 && f1) {           f1 = 0;           flow.link(i + n, j, 1, 0);         }         if (a[i] - a[j] == 1 && f2) {           f2 = 0;           flow.link(i + n, j, 1, 0);         }         if (a[i] - a[j] == 0 && f3) {           f3 = 0;           flow.link(i + n, j, 1, 0);         }       }     }     for (int j = (0); j < (7); j++) {       int pre = 0;       for (int i = (1); i < (n + 1); i++) {         if (a[i] % 7 == j) {           if (pre) flow.link(pre + n, i, 1, 0);           pre = i;         }       }     }     for (int i = (1); i < (n + 1); i++)       flow.link(ss, i, 1, 0), flow.link(i + n, t, 1, 0);     flow.link(s, ss, 4, 0);     int ans = flow.run(s, t).second;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cout << setprecision(12);     int l;     cin >> l;     string s;     cin >> s;     size_t t = 0;     for (auto c : s) t += (c ==  1 );     if (t * 2 == s.length()) {       cout << 2 << endl;       cout << s[0] <<     << s.substr(1) << endl;     } else {       cout << 1 << endl;       cout << s << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   inline void cmin(int &x, int y) {     if (y < x) x = y;   }   inline void cmax(int &x, int y) {     if (y > x) x = y;   }   const int N = 1000006;   int a[12][N], sum[N], tmp[N], bcj[N], f[N][22], id[N], n, m, T, i, j, l, r;   int inline read() {     char ch = getchar();     int z = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       z = z * 10 + ch -  0 ;       ch = getchar();     }     return z * f;   }   int find(int x) {     if (bcj[x] == x) return x;     return bcj[x] = find(bcj[x]);   }   int calc(int f[], int g[], int j, int k) {     int i, ans = 0;     for ((i) = (1); (i) <= (n + n); ++i) bcj[i] = f[i];     for ((i) = (1); (i) <= (n + n); ++i) bcj[n + n + i] = n + n + g[i];     for ((i) = (1); (i) <= (n); ++i)       if (a[i][j] == a[i][k] && find(n + i) != find(n + n + i)) {         ++ans;         bcj[find(n + n + i)] = find(n + i);       }     return ans;   }   void build(int l, int r, int x) {     int mid = l + r >> 1, i;     if (l == r) {       int ans = 1;       for ((i) = (2); (i) <= (n); ++i)         if (a[i][l] != a[i - 1][l]) ++ans;       sum[x] = ans;       for ((i) = (1); (i) <= (n); ++i)         if (i == 1 || a[i][l] != a[i - 1][l])           f[x][i] = i;         else           f[x][i] = f[x][i - 1];       for ((i) = (1); (i) <= (n); ++i) f[x][n + i] = f[x][i];     } else {       build(l, mid, x * 2);       build(mid + 1, r, x * 2 + 1);       sum[x] = sum[x * 2] + sum[x * 2 + 1];       sum[x] -= calc(f[x * 2], f[x * 2 + 1], mid, mid + 1);       for ((i) = (1); (i) <= (n * 4); ++i) bcj[i] = find(i), id[i] = 0;       for ((i) = (1); (i) <= (n); ++i) {         int z = bcj[i];         if (!id[z]) id[z] = i;         f[x][i] = id[z];       }       for ((i) = (n + 1); (i) <= (n + n); ++i) {         int z = bcj[n * 2 + i];         if (!id[z]) id[z] = i;         f[x][i] = id[z];       }     }   }   int query(int l, int r, int x, int s, int t, int g[]) {     int i;     if (s <= l && r <= t) {       for ((i) = (1); (i) <= (n + n); ++i) g[i] = f[x][i];       return sum[x];     }     int mid = l + r >> 1;     if (t <= mid) return query(l, mid, x * 2, s, t, g);     if (s > mid) return query(mid + 1, r, x * 2 + 1, s, t, g);     int h1[22], h2[22];     int ans =         query(l, mid, x * 2, s, t, h1) + query(mid + 1, r, x * 2 + 1, s, t, h2);     ans -= calc(h1, h2, mid, mid + 1);     for ((i) = (1); (i) <= (n * 4); ++i) bcj[i] = find(i), id[i] = 0;     for ((i) = (1); (i) <= (n); ++i) {       int z = bcj[i];       if (!id[z]) id[z] = i;       g[i] = id[z];     }     for ((i) = (n + 1); (i) <= (n + n); ++i) {       int z = bcj[n * 2 + i];       if (!id[z]) id[z] = i;       g[i] = id[z];     }     return ans;   }   int main() {     n = read();     m = read();     T = read();     for ((i) = (1); (i) <= (n); ++i)       for ((j) = (1); (j) <= (m); ++j) a[i][j] = read();     build(1, m, 1);     while (T--) {       l = read();       r = read();       printf( %d n , query(1, m, 1, l, r, tmp));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long int j, n, m, po, a, b, no, flag, cnt = 0, t, cnt2, ar[200001], x, y,                                                i, co[200001], sum = 0, k,                                                ans = INT_MIN, sum1 = 0;     string str[1000], ptr, tr, rtr, rt;     vector<long long int> v1, v2;     set<string> s;     set<long long int> si;     queue<long long int> qui;     queue<string> qus;     set<string>::iterator it;     cin >> t;     while (t--) {       cin >> n >> a >> b;       string sr;       for (i = 0; i < a; i++) {         sr[i] = char( a  + i % b);       }       for (i = 0; i < n; i++) {         cout << sr[i % a];       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long cnt[5], ans1, ans2;   int main() {     int n, a[200010];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1)         cnt[1]++;       else         cnt[0]++;     }     for (int i = 0; i < n; i++) {       if (a[i] == 0)         cnt[0]--;       else {         ans1 += cnt[0];       }     }     cout << ans1;     return 0;   }