malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int A[100020] = {0};   int main() {     int n, i, dis1, dis2 = 0, dis = 0, min;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &A[i]);       if (min > A[i] || i == 1) min = A[i];     }     for (i = 1; i <= n; i++)       if (A[i] == min) {         if (dis2 == 0) dis2 = i;         dis1 = dis2;         dis2 = i;         if (dis > dis2 - dis1 || dis == 0) dis = dis2 - dis1;       }     printf( %d , dis);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s, t;     cin >> s;     cin >> t;     int sc[26] = {0}, tc[26] = {0};     for (int i = 0; i < n; i++) {       sc[s[i] -  a ]++;       tc[t[i] -  a ]++;     }     int flag = 1;     for (int i = 0; i < 26; i++) {       if (sc[i] == tc[i])         continue;       else {         cout << -1 << endl;         flag = 0;         break;       }     }     if (flag == 1) {       int k = 0, change[100005];       for (int i = 0; i < n; i++)         if (s[i] == t[i])           continue;         else           for (int j = i + 1; j < n; j++)             if (s[j] == t[i]) {               while (j > i) {                 char temp = s[j];                 s[j] = s[j - 1];                 s[j - 1] = temp;                 change[k++] = j;                 j--;               }               break;             }       cout << k << endl;       for (int i = 0; i < k; i++) cout << change[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k;   bool check(long long mid) {     long long sum = (mid + k - 1) * (k - mid) / 2;     return (sum >= n - 1);   }   int main() {     scanf( %I64d%I64d , &n, &k);     if (n == 1) {       printf( 0 );       return 0;     }     long long l = 1, r = k - 1, mid;     while (l < r) {       mid = (l + r + 1) >> 1;       if (check(mid))         l = mid;       else         r = mid - 1;     }     if ((l + k - 1) * (k - l) / 2 >= n - 1)       printf( %I64d , k - l);     else       printf( -1 );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n, a = 0, b = 0;     cin >> n;     string str;     cin >> str;     for (int i = 0; i < n - 1; i++) {       if (str[i] ==  S  && str[i + 1] ==  F )         a++;       else if (str[i] ==  F  && str[i + 1] ==  S )         b++;     }     if (a > b)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans;   int main() {     int i, j, k;     scanf( %d , &n);     for (i = k = 0; i < n; i++) {       scanf( %d , &j);       if (j == 0 && k == 0)         continue;       else if (j == 0 && k == 2)         k = 1;       else if (j == 0 && k == 1)         k = 0;       else if (j == 1 && k == 1)         k = 2, ans += 2;       else if (j == 1)         ans++, k = 2;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1E5 + 10;   const int INF = 1E9 + 10;   int n;   int a[MAXN][4];   int d[MAXN];   int dis[MAXN], pre[MAXN];   vector<int> lst[MAXN];   int val[MAXN << 2];   int choose(int l, int r) {     return a[lst[l].back()][1] < a[lst[r].back()][1] ? l : r;   }   void build(int u, int l, int r) {     if (l + 1 == r) {       val[u] = l;       return;     }     int m = l + r >> 1;     build(u << 1, l, m);     build(u << 1 | 1, m, r);     val[u] = choose(val[u << 1], val[u << 1 | 1]);   }   int query(int u, int l, int r, int c) {     if (r <= c) return val[u];     int m = l + r >> 1, ret = query(u << 1, l, m, c);     if (m < c) ret = choose(ret, query(u << 1 | 1, m, r, c));     return ret;   }   void update(int u, int l, int r, int c) {     if (l + 1 == r) return;     int m = l + r >> 1;     if (c < m)       update(u << 1, l, m, c);     else       update(u << 1 | 1, m, r, c);     val[u] = choose(val[u << 1], val[u << 1 | 1]);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d%d%d , &a[i][0], &a[i][1], &a[i][2], &a[i][3]);       d[i] = a[i][0];     }     sort(d, d + n);     int m = unique(d, d + n) - d;     for (int i = 0; i < n; ++i)       lst[lower_bound(d, d + m, a[i][0]) - d].push_back(i);     a[n][1] = INF;     a[n][2] = a[n][3] = 0;     for (int i = 0; i < m; ++i) {       lst[i].push_back(n);       sort(lst[i].begin(), lst[i].end(),            [](const int &l, const int &r) { return a[l][1] > a[r][1]; });     }     build(1, 0, m);     queue<int> Q;     dis[n] = 0;     for (int i = 0; i <= n; ++i) pre[i] = -1;     Q.push(n);     while (!Q.empty() && !~pre[n - 1]) {       int u = Q.front();       Q.pop();       int v, r = upper_bound(d, d + m, a[u][2]) - d;       while (r && a[lst[v = query(1, 0, m, r)].back()][1] <= a[u][3]) {         dis[lst[v].back()] = dis[u] + 1;         pre[lst[v].back()] = u;         Q.push(lst[v].back());         lst[v].pop_back();         update(1, 0, m, v);       }     }     if (~pre[n - 1]) {       printf( %d n , dis[n - 1]);       vector<int> ans;       for (int p = n - 1; p < n; p = pre[p]) ans.push_back(p + 1);       for (int i = ans.size() - 1; i >= 0; --i)         printf( %d%c , ans[i],   n  [!!i]);     } else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f[105][105];   string sa[105], sb[105];   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> sa[i];     }     sort(sa + 1, sa + n + 1);     for (int i = 1; i <= n; ++i) {       cin >> sb[i];     }     sort(sb + 1, sb + n + 1);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         f[i][j] = max(f[i - 1][j], f[i][j - 1]);         if (sa[i] == sb[j]) f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1);       }     }     cout << n - f[n][n];   }   int main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int len, link;     int nxt[26];     long long val;   };   struct Automaton {     int sz, last;     Node s[200100 * 10];     void init() {       sz = last = 0;       s[0].len = 0;       s[0].link = -1;       s[0].val = 0;       memset(s[0].nxt, 0, sizeof(s[0].nxt));       ++sz;     }     void extend(int c, int cost) {       int cur, p;       if (s[last].nxt[c]) {         cur = s[last].nxt[c];         if (s[cur].len == s[last].len + 1) {           s[cur].val += cost;           last = cur;           return;         }         int clone = sz++;         s[clone] = s[cur];         s[clone].len = s[last].len + 1;         s[clone].val = cost;         s[cur].link = clone;         for (p = last; p != -1 && s[p].nxt[c] == cur; p = s[p].link)           s[p].nxt[c] = clone;         last = clone;         return;       }       cur = sz++;       s[cur].len = s[last].len + 1;       s[cur].val = cost;       for (p = last; p != -1 && !s[p].nxt[c]; p = s[p].link) s[p].nxt[c] = cur;       if (p == -1)         s[cur].link = 0;       else {         int q = s[p].nxt[c];         if (s[p].len + 1 == s[q].len)           s[cur].link = q;         else {           int clone = sz++;           s[clone].len = s[p].len + 1;           memcpy(s[clone].nxt, s[q].nxt, sizeof(s[q].nxt));           s[clone].link = s[q].link;           s[clone].val = 0;           for (; p != -1 && s[p].nxt[c] == q; p = s[p].link) s[p].nxt[c] = clone;           s[q].link = s[cur].link = clone;         }       }       last = cur;     }     int cnt[10 * 200100], st[10 * 200100];     long long solve(int len) {       int i, j;       for (j = 0; j <= len; j++) cnt[j] = 0;       for (j = 0; j < sz; j++) cnt[s[j].len]++;       for (j = 1; j <= len; j++) cnt[j] += cnt[j - 1];       for (j = 0; j < sz; j++) st[cnt[s[j].len]--] = j;       long long ret = 0;       for (i = sz; i >= 1; i--) {         int x = st[i];         if (ret < s[x].val * s[x].len) ret = s[x].val * s[x].len;         int p = s[x].link;         if (p != -1) s[p].val += s[x].val;       }       return ret;     }   } sam;   string str[200100];   int c[200100];   int main() {     int N, i, len = 0;     scanf( %d , &N);     for (i = (0); i < (N); i++) cin >> str[i];     for (i = (0); i < (N); i++) scanf( %d , &c[i]);     sam.init();     for (i = (0); i < (N); i++) {       sam.last = 0;       for (int j = 0; j < str[i].length(); j++) {         sam.extend(str[i][j] -  a , c[i]);       }       if (len < str[i].length()) len = str[i].length();     }     long long ans = sam.solve(len);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n;   long double ang, ca, PI = acos(-1);   int main() {     ;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> t;     while (t--) {       cin >> n;       ang = 2 * PI / (2 * n);       ca = 0.5 / tan(ang / 2);       cout << fixed << setprecision(10) << 2 * ca <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int h, m, s, t1, t2;     cin >> h >> m >> s >> t1 >> t2;     h %= 12;     t1 %= 12;     t2 %= 12;     m /= 5;     s /= 5;     if (t1 > t2) swap(t1, t2);     if (((h >= t1 && h < t2) + (m >= t1 && m < t2) + (s >= t1 && s < t2)) % 3 ==         0) {       cout <<  YES ;     } else       cout <<  NO ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int key(int x);   int main() {     int t;     cin >> t;     int str[t];     for (int u = 0; u < t; u++) {       str[u] = key(u);     }     for (int u = 0; u < t; u++) cout << str[u] <<   n ;     return 0;   }   int key(int x) {     int n, k, d, mini = 1000, m = 0;     cin >> n >> k >> d;     int arr[n], c = 0;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int j = 0; j < n - d + 1; j++) {       for (int a = 0; a < d; a++) {         m = 0;         for (int b = 0; b <= a; b++) {           if (arr[j + a] == arr[j + b])             m++;           else             continue;         }         if (m <= 1) c++;       }       mini = min(mini, c);       c = 0;     }     return mini;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[200];     int t, n, x;     for (int i = 0; i <= 100; i++) a[i] = 0;     for (int i = 0; i <= 100; i++)       for (int j = 0; j <= 100; j++) {         t = 3 * i + 7 * j;         if (t > 100) break;         a[t] = 1;       }     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       if (a[x] == 0) cout <<  NO  << endl;       if (a[x] == 1) cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class t>   inline t read(t &x) {     x = 0;     char c = getchar();     bool f = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     if (f) x = -x;     return x;   }   template <class t>   inline void write(t x) {     if (x < 0) {       putchar( - ), write(-x);     } else {       if (x > 9) write(x / 10);       putchar( 0  + x % 10);     }   }   const int N = 1e5 + 5, M = 1e4 + 5, NM = N * 4 + M, TR = NM << 2;   int n, m, pt[NM], pn;   double p[TR], ans;   struct tree {     int x, h, l, r;   } a[N];   struct mushroom {     int x, v;   } b[M];   void build(int x, int l, int r) {     p[x] = 1;     if (l == r) return;     int mid = l + r >> 1;     build(x << 1, l, mid);     build(x << 1 | 1, mid + 1, r);   }   void up(int x, int l, int r, int L, int R, double v) {     if (L <= l && r <= R) {       p[x] *= v;       return;     }     int mid = l + r >> 1;     if (L <= mid) up(x << 1, l, mid, L, R, v);     if (R > mid) up(x << 1 | 1, mid + 1, r, L, R, v);   }   double que(int x, int l, int r, int pos) {     if (l == r) return p[x];     int mid = l + r >> 1;     if (pos <= mid) return p[x] * que(x << 1, l, mid, pos);     return p[x] * que(x << 1 | 1, mid + 1, r, pos);   }   signed main() {     read(n);     read(m);     for (int i = 1; i <= n; i++) {       read(a[i].x);       read(a[i].h);       read(a[i].l);       read(a[i].r);       pt[++pn] = a[i].x - a[i].h;       pt[++pn] = a[i].x - 1;       pt[++pn] = a[i].x + 1;       pt[++pn] = a[i].x + a[i].h;     }     for (int i = 1; i <= m; i++) {       read(b[i].x);       read(b[i].v);       pt[++pn] = b[i].x;     }     sort(pt + 1, pt + 1 + pn);     pn = unique(pt + 1, pt + 1 + pn) - pt - 1;     build(1, 1, pn);     for (int i = 1; i <= n; i++) {       up(1, 1, pn, lower_bound(pt + 1, pt + 1 + pn, a[i].x - a[i].h) - pt,          lower_bound(pt + 1, pt + 1 + pn, a[i].x - 1) - pt, 1.0 - 0.01 * a[i].l);       up(1, 1, pn, lower_bound(pt + 1, pt + 1 + pn, a[i].x + 1) - pt,          lower_bound(pt + 1, pt + 1 + pn, a[i].x + a[i].h) - pt,          1.0 - 0.01 * a[i].r);     }     for (int i = 1; i <= m; i++)       ans +=           que(1, 1, pn, lower_bound(pt + 1, pt + 1 + pn, b[i].x) - pt) * b[i].v;     printf( %.10lf , ans);   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 3e5 + 10;   const long long MAXE = 3e5 + 10;   const long long INF = 2e18 + 3;   long long n, m, k, ec;   long long from[2 * MAXE], to[2 * MAXE], prv[2 * MAXE], w[2 * MAXE], head[MAXN],       sec[2 * MAXE];   long long comp[MAXN], d[MAXN], ss[MAXN];   bool portal[MAXN], mark[MAXN];   set<pair<long long, long long>> st;   long long ans = 0;   void add_edge(long long u, long long v, long long c) {     from[ec] = u, to[ec] = v, w[ec] = c, prv[ec] = head[u];     head[u] = ec++;   }   long long get_min() {     pair<long long, long long> fr = *st.begin();     st.erase(st.begin());     return fr.second;   }   void update(long long v) {     mark[v] = 1;     for (long long e = head[v]; e != -1; e = prv[e]) {       long long u = to[e], c = w[e];       if (!mark[u] && d[u] > w[e] + d[v]) {         st.erase({d[u], u});         d[u] = d[v] + w[e];         st.insert({d[u], u});         ss[u] = ss[v];       }     }   }   void dijk() {     fill(d, d + MAXN, INF);     memset(ss, -1, sizeof(ss));     for (long long i = 0; i < n; i++)       if (portal[i]) mark[i] = 1, d[i] = 0, ss[i] = i;     for (long long i = 0; i < n; i++)       if (portal[i]) update(i);     while (st.size()) update(get_min());   }   bool cmp(long long e1, long long e2) {     if (w[e1] != w[e2]) return w[e1] < w[e2];     return e1 < e2;   }   long long get_comp(long long v) {     if (comp[v] == v) return v;     return comp[v] = get_comp(comp[v]);   }   void merge(long long e) {     if (get_comp(ss[to[e]]) == get_comp(ss[from[e]])) return;     ans += w[e];     comp[get_comp(ss[to[e]])] = get_comp(ss[from[e]]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     memset(head, -1, sizeof(head));     while (m--) {       long long a, b, c;       cin >> a >> b >> c;       a--, b--;       add_edge(a, b, c);       add_edge(b, a, c);     }     cin >> k;     while (k--) {       long long temp;       cin >> temp, temp--, portal[temp] = 1;     }     dijk();     ans = d[0];     iota(comp, comp + n, 0);     iota(sec, sec + ec, 0);     for (int i = 0; i < ec; i++) w[i] += d[from[i]] + d[to[i]];     sort(sec, sec + ec, cmp);     for (long long e = 0; e < ec; e++) merge(sec[e]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool hs(int mask, int i) { return mask & (1 << i); }   int dp[300000];   void dfs2(vector<int> &adj, int i, int &c) {     c++;     dp[i] = 3;     int u = adj[i];     if (dp[u] == 3) {       return;     }     dfs2(adj, u, c);   }   void dfs(vector<int> &adj, int i, int &c) {     dp[i] = 2;     int u = adj[i];     if (dp[u] == 0) {       dfs(adj, u, c);     } else if (dp[u] == 2) {       dfs2(adj, i, c);     }     dp[i] = 1;   }   int main() {     int n, t;     cin >> n;     t = n;     long long m = 1000000007;     vector<int> adj;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       a--;       adj.push_back(a);     }     memset(dp, 0, sizeof(dp));     long long ans = 1, k = 1;     vector<long long> v(200005);     for (int i = 0; i < v.size(); i++) {       v[i] = k;       k = k * 2ll;       k = k % m;     }     for (int i = 0; i < n; i++) {       int c = 0;       if (dp[i] == 0) {         dfs(adj, i, c);         t = t - c;         if (c > 1) {           ans = ans * (v[c] - 2ll);           ans = ans % m;         }       }     }     ans = ans * v[t];     ans = ans % m;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double PI = acos(-1.0);   const int MAXN = 100005;   const long long MOD = 1000000007;   void base() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   pair<int, int> arr[100005];   int occ[100005];   int main() {     base();     int n, k, temp, need = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> temp;       arr[i].second = temp;       occ[temp]++;     }     for (int i = 0; i < n; i++) {       cin >> temp;       arr[i].first = temp;     }     for (int i = 1; i <= k; i++) {       if (occ[i] == 0) need++;     }     sort(arr, arr + n);     long long ans = 0;     for (int i = 0; i < n; i++) {       if (occ[arr[i].second] > 1 && need > 0) {         occ[arr[i].second]--;         need--;         ans += (long long)arr[i].first;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, x = 1, y = 1;     cin >> n;     while (n--) {       cin >> s;       if (s ==  ULDR )         x++, y++;       else if (s ==  UR  || s ==  DL )         x++;       else         y++;     }     cout << 1LL * x * y << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   int x, y;   int main() {     scanf( %d%d , &x, &y);     int ans = 0, d = 1, xx = 0, yy = 0;     while (true) {       if (yy == y && xx <= x && xx + d >= x) break;       ans++;       xx += d;       if (xx == x && yy <= y && yy + d >= y) break;       ans++;       yy += d;       d++;       if (yy == y && xx - d <= x && xx >= x) break;       ans++;       xx -= d;       if (xx == x && yy - d <= y && yy >= y) break;       ans++;       yy -= d;       d++;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getint() {     int s = 0, o = 1;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) o = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) s *= 10, s += c -  0 ;     return s * o;   }   const int maxn = 30005;   int gem[maxn];   int a[maxn];   int dp[maxn][601], all, len, n, x;   inline void up(int &a, int b) {     if (a < b) a = b;   }   int main(int argc, char const *argv[]) {     n = getint(), len = getint();     for (int i = 0; i < n; i++) {       x = getint();       gem[x]++;       all = max(all, x);     }     int r = 0;     dp[len][0 + 300] = gem[len] + 1;     for (int i = 0; i <= all; ++i)       for (int j = -300; j < 300; ++j)         if (dp[i][j + 300]) {           r = max(r, dp[i][j + 300] - 1);           if (len + j > 0 && i + len + j - 1 <= all)             up(dp[i + len + j - 1][j - 1 + 300],                dp[i][j + 300] + gem[i + len + j - 1]);           if (i + len + j <= all)             up(dp[i + len + j][j + 300], dp[i][j + 300] + gem[i + len + j]);           if (i + len + j + 1 <= all)             up(dp[i + len + j + 1][j + 1 + 300],                dp[i][j + 300] + gem[i + len + j + 1]);         }     printf( %d n , r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read() {     T f = 0, x = 0;     char c = getchar();     while (!isdigit(c)) f = c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     return f ? -x : x;   }   namespace run {   inline char getc() {     char c = getchar();     while (!isalpha(c)) c = getchar();     return c;   }   const int N = 2e5 + 9;   int head[N], nex[N], to[N], cnt, deg[N];   inline void add(int u, int v) {     deg[v]++, nex[++cnt] = head[u], head[u] = cnt, to[cnt] = v;   }   int n, m, bel[N], tot, dfn[N], num, dwn[N];   inline void dfs(int u) {     dfn[u] = ++num;     for (int i = head[u]; i; i = nex[i]) dfs(to[i]);     dwn[u] = num;   }   struct node {     int x, l, r, v;     explicit node() {}     node(int _x, int _l, int _r, int _v) : x(_x), l(_l), r(_r), v(_v) {}     inline bool operator<(const node &A) const { return x < A.x; }   } q[N << 1];   namespace Seg {   int sum[N << 2], num[N << 2];   inline void pushup(int k, int l, int r) {     if (l == r) return num[k] = sum[k] > 0, void();     if (sum[k])       num[k] = r - l + 1;     else       num[k] = num[(k << 1)] + num[(k << 1 | 1)];   }   inline void modify(int k, int l, int r, int _l, int _r, int v) {     if (_l <= l && r <= _r) return sum[k] += v, pushup(k, l, r);     if (_l <= ((l + r) >> 1)) modify((k << 1), l, ((l + r) >> 1), _l, _r, v);     if (_r > ((l + r) >> 1))       modify((k << 1 | 1), ((l + r) >> 1) + 1, r, _l, _r, v);     pushup(k, l, r);   }   }  // namespace Seg   inline int id(int x, int y) { return (x - 1) * m + y; }   int main() {     n = read<int>(), m = read<int>();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         char c = getc();         if (c ==  D ) {           bel[id(i - 1, j)] = id(i, j), bel[id(i, j)] = id(i - 1, j);           if (i > 2) add(id(i - 2, j), id(i, j));           if (i + 1 <= n) add(id(i + 1, j), id(i - 1, j));         }         if (c ==  R ) {           bel[id(i, j - 1)] = id(i, j), bel[id(i, j)] = id(i, j - 1);           if (j > 2) add(id(i, j - 2), id(i, j));           if (j + 1 <= m) add(id(i, j + 1), id(i, j - 1));         }       }     for (int i = 1; i <= n * m; i++)       if (!deg[i]) dfs(i);     for (int i = 1; i <= n * m; i++) {       int l = dfn[bel[i]], r = dwn[bel[i]];       q[++tot] = node(dfn[i], l, r, 1), q[++tot] = node(dwn[i] + 1, l, r, -1);     }     sort(q + 1, q + tot + 1);     long long ans = 0;     for (int i = 1, j, las = 0; i <= tot; i = j + 1) {       j = i;       while (j + 1 <= tot && q[j + 1].x == q[i].x) j++;       ans += 1LL * (q[i].x - las) * Seg::num[1], las = q[i].x;       for (int k = i; k <= j; k++)         Seg::modify(1, 1, n * m, q[k].l, q[k].r, q[k].v);     }     printf( %lld n , ans >> 1);     return 0;   }   }  // namespace run   int main() { return run::main(); }
#include <bits/stdc++.h>   using namespace std;   int ans1 = 0, ans2 = 0, ans3 = 0, a[100];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (i % 3 == 1) ans1 += a[i];       if (i % 3 == 2) ans2 += a[i];       if (i % 3 == 0) ans3 += a[i];     }     if (ans1 >= ans2 && ans1 >= ans3) {       cout <<  chest  << endl;       return 0;     }     if (ans2 >= ans1 && ans2 >= ans3) {       cout <<  biceps  << endl;       return 0;     }     if (ans3 >= ans1 && ans3 >= ans2) {       cout <<  back  << endl;       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline const int getint() {     int r = 0, k = 1;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) k = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) r = r * 10 + c -  0 ;     return k * r;   }   const int N = 1e5 + 10;   char s[N];   int n;   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     int sum = 0, x = 0, y = 0, z = 0, need = 0;     for (int i = (1); i <= (n); ++i)       if (s[i] ==  ( )         ++x;       else if (s[i] ==  ) )         ++y;       else         ++z;     need = x - y - (z - 1);     if (need <= 0 && z) {       puts( -1 );       return 0;     }     int now = z;     for (int i = (n); i >= (1); --i) {       if (s[i] ==  ( )         ++sum;       else if (s[i] ==  ) )         --sum;       else {         if (now == z) {           sum -= need;         } else {           sum--;         }         --now;       }       if (sum > 0) {         puts( -1 );         return 0;       }     }     if (sum != 0) {       puts( -1 );       return 0;     }     now = 0;     for (int i = (1); i <= (n); ++i) {       if (s[i] ==  # ) {         ++now;         if (now == z)           printf( %d n , need);         else           puts( 1 );       }     }     return 0;   }