malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-5;   struct line {     double x, y, vx, vy;     void read() {       double t1, t2;       cin >> t1 >> x >> y >> t2 >> vx >> vy;       vx = (vx - x) / (t2 - t1);       vy = (vy - y) / (t2 - t1);       x -= vx * t1;       y -= vy * t1;     }   } L[1005];   struct vec {     double x, y;   } b[1005];   double cross(const vec &a, const vec &b) { return a.x * b.y - a.y * b.x; }   double a[1005];   int tot;   bool cmp(const vec a, const vec b) {     if (fabs(cross(a, b)) < eps) {       if (fabs(a.x - b.x) < eps) return a.y < b.y;       return a.x < b.x;     }     return cross(a, b) < 0;   }   int main() {     ios::sync_with_stdio(0);     int N;     cin >> N;     int ans = 0;     double px, py, pvx, pvy, t;     for (int i = 1; i <= N; i++) L[i].read();     for (int i = 1; i <= N; i++) {       tot = 0;       for (int j = 1; j <= N; j++)         if (i != j) {           px = L[j].x - L[i].x;           py = L[j].y - L[i].y;           pvx = L[j].vx - L[i].vx;           pvy = L[j].vy - L[i].vy;           t = 0;           if (!((fabs(pvx) < eps)))             t = px / pvx;           else if (!(fabs(pvy) < eps))             t = py / pvy;           if (fabs(px - t * pvx) < eps && fabs(py - t * pvy) < eps) {             a[++tot] = t;             b[tot].x = pvx, b[tot].y = pvy;           }         }       sort(a + 1, a + tot + 1);       int cnt = 0;       for (int j = 1; j <= tot; j++) {         if (fabs(a[j] - a[j - 1]) < eps)           cnt++;         else           cnt = 1;         ans = max(ans, cnt);       }       sort(b + 1, b + tot + 1, cmp);       cnt = 0;       for (int j = 1; j <= tot; j++) {         if (fabs(cross(b[j], b[j - 1])) < eps) {           if (fabs(b[j].x - b[j - 1].x) > eps || fabs(b[j].y - b[j - 1].y) > eps)             cnt++;         } else           cnt = 1;         ans = max(ans, cnt);       }     }     cout << ans + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int A = 26;   const int maxn = 5e3 + 5;   const long long mod = 1e9 + 7;   char s[maxn];   int n;   int nxt[maxn][A];   long long fat[maxn], inv[maxn];   long long dp[maxn][maxn];   string t;   void fillNxtTable() {     t = s;     t =  $  + t;     int last[A];     fill(last, last + A, n + 1);     for (int i = n; i >= 0; i--) {       for (int j = 0; j < A; j++) nxt[i][j] = last[j];       if (i) last[t[i] -  a ] = i;     }   }   long long exp(long long a, long long b) {     long long result = 1;     while (b) {       if (b & 1) result = (result * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return result;   }   void preComputeBinomial() {     fat[0] = 1;     inv[0] = 1;     for (int i = 1; i < maxn; i++) {       fat[i] = (fat[i - 1] * i) % mod;       inv[i] = exp(fat[i], mod - 2);     }   }   long long C(int n, int k) {     if (k < 0) return 0;     return (((fat[n] * inv[n - k]) % mod) * inv[k]) % mod;   }   long long solve(int pos, int k) {     if (pos > n) return 0;     long long &ans = dp[pos][k];     if (ans != -1) return ans;     ans = C(n - 1, k - 1);     for (int i = 0; i < A; i++) {       if ((t[pos] -  a ) != i) {         ans = (ans + solve(nxt[pos][i], k + 1));       }     }     ans %= mod;     return ans;   }   int main() {     scanf( %d , &n);     scanf( %s , s);     fillNxtTable();     preComputeBinomial();     memset(dp, -1, sizeof(dp));     printf( %lld n , solve(0, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int nbElems, nbAuto;   bitset<2000> autos[2000];   bitset<2000> inverse[2000];   int main() {     scanf( %d%d , &nbElems, &nbAuto);     vector<pair<int, int> > paires;     for (int iPaire = 0; iPaire < nbAuto; iPaire++) {       int pos, elem;       scanf( %d%d , &pos, &elem);       autos[pos - 1][elem - 1] = true;       paires.push_back(make_pair(pos - 1, elem - 1));     }     for (int iElem = 0; iElem < nbElems; iElem++) {       inverse[iElem][iElem] = 1;     }     for (int iLigne = 0; iLigne < nbElems; iLigne++) {       if (!autos[iLigne][iLigne]) {         for (int iAutre = iLigne + 1; iAutre < nbElems; iAutre++) {           if (autos[iAutre][iLigne]) {             autos[iLigne] ^= autos[iAutre];             inverse[iLigne] ^= inverse[iAutre];             break;           }         }       }       for (int iAutre = 0; iAutre < nbElems; iAutre++) {         if (iAutre != iLigne && autos[iAutre][iLigne]) {           autos[iAutre] ^= autos[iLigne];           inverse[iAutre] ^= inverse[iLigne];         }       }     }     for (int iPaire = 0; iPaire < nbAuto; iPaire++) {       if (inverse[paires[iPaire].second][paires[iPaire].first]) {         printf( NO n );       } else {         printf( YES n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, a[100005], tot = 0, tmp;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (long long i = 1; i <= m; i++) {       cin >> a[i];       if (i + a[i] - 1 > n) {         cout << -1 << endl;         return 0;       }       tot += a[i];     }     if (tot < n) {       cout << -1 << endl;       return 0;     }     cout << 1;     tot -= a[1];     n--;     for (long long i = 2; i <= m; i++) {       if (tot > n) {         cout <<     << i;         tot -= a[i];         n--;       } else {         cout <<     << i + n - tot;         tmp = i + n - tot + a[i];         for (long long j = i + 1; j <= m; j++) {           cout <<     << tmp;           tmp += a[j];         }         cout << endl;         return 0;       }     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, mod, s, s1, s2;   inline long long get(long long id, long long rem, long long l, long long r,                        long long b, long long e, long long x) {     if (e < l || r < b) {       return 0;     }     if (b <= l && r <= e) {       if (x < rem) {         return 0;       }       s = (x - rem) / (1LL << id);       s1 = s;       s2 = s + 1;       if (s % 2 == 0) {         s1 /= 2;       } else {         s2 /= 2;       }       return (((s + 1) % mod) * (rem % mod) % mod +               ((1LL << id) % mod) * (s1 % mod) % mod * (s2 % mod) % mod) %              mod;     }     long long lrem = rem, rrem = rem + (1LL << id);     if (rem == 0) {       rrem = 0;       lrem = (1LL << id);     }     return (get(id + 1, lrem, l, (l + r) / 2, b, e, x) +             get(id + 1, rrem, (l + r) / 2 + 1, r, b, e, x)) %            mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long m, l, r, u, v;     cin >> n >> m >> mod;     while (m--) {       cin >> l >> r >> u >> v;       cout << (get(0, 0, 1, n, l, r, min(n, v)) -                get(0, 0, 1, n, l, r, min(n + 1, u) - 1) + mod) %                   mod            << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int p = 0;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       x--;       if (x % 2) p++;       if (p % 2)         cout << 1 << endl;       else         cout << 2 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> m >> n;     map<int, vector<pair<int, int>>> matrix;     vector<int> cnt(n, m), mag(m, n);     int cnt2 = m;     for (int i = 0; i < m; ++i) {       for (int j = 0; j < n; ++j) {         int a;         cin >> a;         matrix[a].push_back(make_pair(j, i));       }     }     int ans = -1;     for (auto &elem : matrix) {       ans = elem.first;       bool ok = 1;       for (auto &pr : elem.second) {         int i = pr.first, j = pr.second;         --cnt[i];         --mag[j];         if (cnt[i] == 0) {           ok = 0;           break;         }         if (mag[j] == 1) --cnt2;       }       if (!ok || cnt2 == 0) break;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     srand(time(NULL));     int tt = 1;     cin >> tt;     while (tt--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int up_div(int a, int b) { return a / b + (a % b != 0); }   int down_div(int a, int b) { return a / b; }   int main() {     int a, b;     cin >> a >> b;     int res = 0;     for (int k = 1; k <= a + b; ++k) {       int d = (a + b) / k;       int min_k = k;       int max_k = (a + b) / d;       res += (up_div(a, d + 1) <= down_div(a, d) &&               up_div(b, d + 1) <= down_div(b, d)) *              (min(down_div(a, d) + down_div(b, d), max_k) -               max(up_div(a, d + 1) + up_div(b, d + 1), min_k) + 1);       k = max_k;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = 10e17 + 9;   const long double p = acos(-1);   int n, x;   vector<int> v[200009];   int dis1[200009];   int dis2[200009];   void dfs1(int node, int p, int k) {     dis1[node] = k;     for (int i = 0; i < v[node].size(); i++) {       int u = v[node][i];       if (u != p) dfs1(u, node, k + 1);     }   }   void dfs2(int node, int p, int k) {     dis2[node] = k;     for (int i = 0; i < v[node].size(); i++) {       int u = v[node][i];       if (u != p) dfs2(u, node, k + 1);     }   }   int main() {     cin >> n >> x;     x--;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b, a--, b--;       v[a].push_back(b), v[b].push_back(a);     }     dfs1(0, 0, 0);     dfs2(x, x, 0);     int mx = 0;     for (int i = 0; i < n; i++) {       int x = 0;       if (dis2[i] < dis1[i]) x = dis1[i];       mx = max(mx, x);     }     cout << mx * 2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   long long m, n, t, a1, b1, cnta, cntb, b[maxn];   struct point {     long long x, y;     point(long long x = 0, long long y = 0) : x(x), y(y) {}     bool operator<(const point& p) const {       return x < p.x || (x == p.x && y < p.y);     }   } a[maxn];   int main() {     cin >> m;     while (m--) {       cnta = cntb = 0;       cin >> n >> t >> a1 >> b1;       for (long long i = 1; i <= n; i++) {         cin >> b[i];         if (b[i])           cntb++;         else           cnta++;       }       for (long long i = 1; i <= n; i++) {         long long x;         cin >> x;         a[i] = point(x, b[i]);       }       a[n + 1] = point(t + 1, 0);       sort(a + 1, a + n + 2);       long long ans = 0, cnt1 = 0, cnt2 = 0;       for (int i = 1; i <= n + 1; i++) {         long long sum = cnt1 * a1 + cnt2 * b1, res = a[i].x - sum - 1;         if (res >= 0) {           long long ta = min(cnta - cnt1, res / a1);           res -= ta * a1;           long long tb = min(cntb - cnt2, res / b1);           ans = max(ans, cnt1 + cnt2 + ta + tb);         }         long long cnt = i;         while (cnt <= n + 1 && a[cnt].x == a[i].x) {           if (a[cnt].y)             cnt2++;           else             cnt1++;           cnt++;         }         i = cnt - 1;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   const int N = 1e3 + 10;   const double eps = 1e-5;   int n;   struct Tarr {     long long tarr[N][N];     Tarr() {       for (int i = 0; i < N; i++) {         for (int j = 0; j < N; j++) {           tarr[i][j] = 0;         }       }     }     static int lowbit(int x) { return x & -x; }     void add(int x, int y, long long val) {       while (x <= n) {         int p = y;         while (p <= n) {           tarr[x][p] ^= val;           p += lowbit(p);         }         x += lowbit(x);       }     }     long long query(int x, int y) {       long long res = 0;       while (x) {         int p = y;         while (p) {           res ^= tarr[x][p];           p -= lowbit(p);         }         x -= lowbit(x);       }       return res;     }   };   Tarr an, ai, aj, aij;   long long query(int x, int y) {     return (((x + 1) * (y + 1) % 2) * an.query(x, y)) ^            (((x + 1) % 2) * ai.query(x, y)) ^ (((y + 1) % 2) * aj.query(x, y)) ^            aij.query(x, y);   }   long long query(int x1, int y1, int x2, int y2) {     return query(x2, y2) ^ query(x1 - 1, y2) ^ query(x2, y1 - 1) ^            query(x1 - 1, y1 - 1);   }   void add(int x, int y, long long val) {     an.add(x, y, val);     ai.add(x, y, (y % 2) * val);     aj.add(x, y, (x % 2) * val);     aij.add(x, y, (x * y % 2) * val);   }   void add(int x1, int y1, int x2, int y2, long long val) {     add(x1, y1, val);     add(x1, y2 + 1, val);     add(x2 + 1, y1, val);     add(x2 + 1, y2 + 1, val);   }   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int op;       cin >> op;       if (op == 2) {         int x1, y1, x2, y2;         long long v;         cin >> x1 >> y1 >> x2 >> y2 >> v;         add(x1, y1, x2, y2, v);       } else {         int x1, y1, x2, y2;         cin >> x1 >> y1 >> x2 >> y2;         cout << query(x1, y1, x2, y2) <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, hd, el;   char s[1000];   struct E {     char tag;     int p[26];   } e[1000000];   void ins() {     int i, j, k, l;     for (i = 0, l = hd; s[i]; i++) {       if (!e[l].p[s[i] -  a ]) e[l].p[s[i] -  a ] = el++;       l = e[l].p[s[i] -  a ];     }   }   void dfs(int ei) {     int i, j, c[5] = {0, 0, 0, 0, 0};     for (i = j = 0; i < 26; i++) {       if (e[ei].p[i]) {         j = 1;         dfs(e[ei].p[i]);         c[e[e[ei].p[i]].tag]++;       }     }     if (!j)       e[ei].tag = 1;     else if (c[4] || (c[1] && c[2]))       e[ei].tag = 3;     else if (c[1])       e[ei].tag = 2;     else if (c[2])       e[ei].tag = 1;     else       e[ei].tag = 4;   }   void init() {     int i, j, k, l;     hd = el = 0;     el++;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %s , s);       ins();     }     dfs(hd);   }   void solve() {     if (e[hd].tag == 1 || e[hd].tag == 4)       puts( Second );     else if (e[hd].tag == 3)       puts( First );     else if (m & 1)       puts( First );     else       puts( Second );   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tree[10000][2];   int lights;   void mark(int node, int l) {     int p = node / 2;     if (p == 0) return;     tree[p][node % 2] = min(tree[p][node % 2], lights - l);     mark(p, l);   }   int cont[10000];   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     memset(tree, -1, sizeof(tree));     int n, a, p;     cin >> n;     int lim = (1 << (n + 1)) - 1;     for (int i = 2; i <= lim; ++i) {       cin >> a;       p = i / 2;       tree[p][i % 2] = a;     }     lights = 0;     queue<int> Q;     Q.push(1);     Q.push(0);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       int l = Q.front();       Q.pop();       if (tree[u][0] == -1) {         lights = max(lights, l);         cont[u] = l;         continue;       }       Q.push(2 * u);       Q.push(tree[u][0] + l);       Q.push(2 * u + 1);       Q.push(tree[u][1] + l);       tree[u][0] = tree[u][1] = 0x3fffffff;     }     for (int i = 1 << n; i <= lim; ++i) mark(i, cont[i]);     int ans = 0;     Q.push(1);     Q.push(0);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       int l = Q.front();       Q.pop();       if (tree[u][0] == -1) continue;       ans += tree[u][0] + tree[u][1] - 2 * l;       Q.push(2 * u);       Q.push(tree[u][0]);       Q.push(2 * u + 1);       Q.push(tree[u][1]);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n), ans;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       auto cyc = [&](int idx) {         swap(a[idx + 2], a[idx]);         swap(a[idx + 1], a[idx + 2]);         ans.push_back(idx);       };       if (n == 3) {         if (!is_sorted(a.begin(), a.end())) cyc(0);         if (!is_sorted(a.begin(), a.end())) cyc(0);       }       for (int i = 0; i + 2 < n; i++) {         vector<pair<int, int>> b(n);         for (int j = 0; j < n; j++) {           b[j] = {a[j], j};         }         sort(b.begin(), b.end());         if (i < b[i].second) {           for (int k = b[i].second - 2; k >= i; k -= 2) {             cyc(k);           }           if ((b[i].second - i) & 1) {             cyc(i);             cyc(i);           }         }       }       if (a[n - 2] > a[n - 1]) {         int x = -1;         for (int i = 0; i + 2 < n; i++) {           if (a[i] == a[i + 1]) {             x = i;           }         }         if (x != -1) {           for (int i = x; i < n - 4; i++) {             cyc(i);           }           cyc(n - 3);           cyc(n - 4);           for (int i = n - 5; i >= x; i--) {             cyc(i);             cyc(i);           }         }       }       if (a[n - 2] > a[n - 1]) cyc(n - 3);       if (is_sorted(a.begin(), a.end()) && ans.size() <= n * n) {         cout << ans.size() <<   n ;         for (auto i : ans) cout << i + 1 <<    ;         cout <<   n ;       } else {         cout << -1 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 7;   vector<long long> v[N];   long long vis[N], prt[N], bip[N], cs, ce;   void dfs(long long ver, long long par) {     bip[ver] = (!bip[par]);     vis[ver] = 1;     prt[ver] = par;     for (auto it : v[ver]) {       if (vis[it] == 2 || it == par) continue;       if (vis[it] == 1) {         cs = it;         ce = ver;         break;       }       dfs(it, ver);     }     vis[ver] = 2;   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, m, k;     cin >> n >> m >> k;     for (long long i = (long long)(1); i <= (long long)(m); i++) {       long long x, y;       cin >> x >> y;       if (x > k || y > k) continue;       v[x].push_back(y);       v[y].push_back(x);     }     for (long long i = (long long)(1); i <= (long long)(k); i++) {       if (vis[i]) continue;       dfs(i, 0);     }     if (cs) {       cout << 2 <<   n ;       vector<long long> ans;       while (cs != ce) {         ans.push_back(ce);         ce = prt[ce];       }       ans.push_back(ce);       cout << ans.size() <<   n ;       for (auto it : ans) cout << it <<    ;     } else {       cout << 1 <<   n ;       long long kk = k / 2 + k % 2;       long long tmp = count(bip + 1, bip + k + 1, 0);       if (tmp >= kk) {         for (long long i = (long long)(1); i <= (long long)(k); i++) {           if (kk > 0 && bip[i] == 0) {             cout << i <<    ;             kk--;           }         }       } else {         for (long long i = (long long)(1); i <= (long long)(k); i++) {           if (kk > 0 && bip[i]) {             cout << i <<    ;             kk--;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l;     cin >> n >> l;     double a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(&a[0], &a[n]);     float x = a[0] - 0;     float y = l - a[n - 1];     for (int i = 0; i < n - 1; i++) a[i] = (a[i + 1] - a[i]) / 2;     if (x > y)       a[n - 1] = x;     else       a[n - 1] = y;     sort(&a[0], &a[n]);     cout << std::fixed << a[n - 1];   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   const int mod = 100003;   const int INF = 0x3f3f3f;   int n, m, x, y;   int vis[N];   struct node {     int x, r, i, v;   } tar[N];   bool cmp1(node &x, node &y) { return x.x < y.x; }   bool cmp2(node &x, node &y) { return x.i < y.i; }   int find(int x) {     int l, mid, r;     l = 1, r = n;     while (r - l > 1) {       mid = (l + r) / 2;       if (tar[mid].x == x) return mid;       if (tar[mid].x < x) l = mid;       if (tar[mid].x > x) r = mid;     }     return l;   }   bool chk(int p, int x, int y) {     if ((tar[p].x - x) * (tar[p].x - x) + y * y <= tar[p].r * tar[p].r)       return true;     else       return false;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     memset(vis, 0, sizeof(vis));     ;     for (int i = 1; i <= n; i++) {       cin >> tar[i].x >> tar[i].r;       tar[i].v = -1;       tar[i].i = i;     }     sort(tar + 1, tar + 1 + n, cmp1);     cin >> m;     int pos;     int sum = 0;     for (int i = 1; i <= m; i++) {       cin >> x >> y;       pos = find(x);       if (tar[pos - 1].v == -1 && chk(pos - 1, x, y)) {         tar[pos - 1].v = i;         sum++;       }       if (tar[pos].v == -1 && chk(pos, x, y)) {         tar[pos].v = i;         sum++;       }       if (tar[pos + 1].v == -1 && chk(pos + 1, x, y)) {         tar[pos + 1].v = i;         sum++;       }     }     sort(tar + 1, tar + 1 + n, cmp2);     cout << sum << endl;     for (int i = 1; i <= n; i++) {       cout << tar[i].v <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if (s[1] ==  1 ) {       if (s[0] ==  a  || s[0] ==  h ) {         cout <<  3  << endl;       } else {         cout <<  5  << endl;       }     } else if (s[1] ==  8 ) {       if (s[0] ==  a  || s[0] ==  h ) {         cout <<  3  << endl;       } else {         cout <<  5  << endl;       }     } else {       if (s[0] ==  a  || s[0] ==  h ) {         cout <<  5  << endl;       } else {         cout <<  8  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int l, r, b, No;     bool operator<(const Node &t) const {       if (b != t.b) return b < t.b;       return r < t.r;     }   };   const int N = 200005;   const int M = 1000005;   int n, Q;   int seq[N];   Node q[N];   int cnt[M];   long long ans[N];   long long &cal(int x, int &l, int &r, long long &ret) {     int L = q[x].l, R = q[x].r;     while (l > L) {       --l;       int t = seq[l];       ret += 2LL * cnt[t] * t + t;       cnt[t]++;     }     while (r < R) {       ++r;       int t = seq[r];       ret += 2LL * cnt[t] * t + t;       cnt[t]++;     }     while (l < L) {       int t = seq[l];       ret += -2LL * cnt[t] * t + t;       ++l;       cnt[t]--;     }     while (r > R) {       int t = seq[r];       ret += -2LL * cnt[t] * t + t;       --r;       cnt[t]--;     }     return ret;   }   void solve() {     int B = (int)sqrt(1.0 * n);     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= Q; ++i) {       scanf( %d %d , &q[i].l, &q[i].r);       q[i].b = q[i].l / B;       q[i].No = i;     }     sort(q + 1, q + 1 + Q);     int l = q[1].l, r = q[1].r;     long long ret = 0;     for (int i = l; i <= r; ++i) {       int t = seq[i];       ret += 2LL * cnt[t] * t + t;       cnt[t]++;     }     ans[q[1].No] = ret;     for (int i = 2; i <= Q; ++i) {       ans[q[i].No] = cal(i, l, r, ret);     }     for (int i = 1; i <= Q; ++i) {       printf( %I64d n , ans[i]);     }   }   int main() {     while (scanf( %d %d , &n, &Q) != EOF) {       for (int i = 1; i <= n; ++i) {         scanf( %d , &seq[i]);       }       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int l = s.length();       vector<int> v(26, 0);       for (int i = 0; i < l; i++) {         if (s[i] == s[i + 1]) {           i++;         } else {           v[s[i] -  a ] = 1;         }       }       for (int i = 0; i < 26; i++) {         if (v[i]) {           cout << (char)(i +  a );         }       }       cout << endl;     }     return 0;   }