malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char ss[30];   int mem[200], cur = 0, n, m;   int goodal(int start, int _long) {     for (int i = 1; i <= _long; ++i)       if (mem[i + start - 1] != 0 || i + start - 1 > m) return 0;     return 1;   }   void _fill(int start, int _long) {     for (int i = 1; i <= _long; ++i) mem[i + start - 1] = cur;   }   void show() {     for (int i = 1; i <= m; ++i) printf( %d  , mem[i]);     printf(  n );   }   void alloc() {     int ind;     scanf( %d , &ind);     scanf(  n );     for (int i = 1; i <= m; ++i)       if (goodal(i, ind)) {         ++cur;         _fill(i, ind);         printf( %d n , cur);         return;       }     printf( NULL n );   }   void erase() {     int ind, flag = 0;     scanf( %d , &ind);     scanf(  n );     for (int i = 1; i <= m; ++i)       if (mem[i] == ind && ind != 0) flag = 1, mem[i] = 0;     if (flag == 0) printf( ILLEGAL_ERASE_ARGUMENT n );   }   void defragment() {     scanf(  n );     int now = 1;     for (int i = 1; i <= m; ++i)       if (mem[i] == 0) {         now = i;         break;       }     for (int i = 1; i <= m; ++i)       if (i > now && mem[i] != 0) mem[now++] = mem[i], mem[i] = 0;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %s , &ss);       if (ss[0] ==  a )         alloc();       else if (ss[0] ==  e )         erase();       else         defragment();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     vector<long long> arr(n);     for (auto& i : arr) cin >> i;     long long l = 0, r = 2, ans = 0;     while (r < n) {       if (arr[r] - arr[l] <= k) {         long long val = r - l - 1;         val = (val * (val + 1)) / 2;         ans += val;         r++;       } else {         l++;       }       if (r == l + 1) r++;     }     cout << ans <<   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 n;     cin >> n;     vector<int> hl(n, -1);     vector<pair<pair<int, int>, int>> v(n);     for (int i = (0); i < (n); i++) {       cin >> v[i].first.first >> v[i].first.second;       v[i].second = i;     }     sort(v.begin(), v.end());     for (int i = (0); i < (n); i++) {       hl[v[i].second] = v[i].first.first;       for (int j = (i + 1); j < (n); j++) {         if (v[j].first.first == v[i].first.first) {           v[j].first.first++;         } else {           break;         }       }       sort(v.begin(), v.end());     }     for (int i = (0); i < (n); i++) cout << hl[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[5050][5050], b[5050][5050] = {0};   int q, l, r;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[0][i];       b[0][i] = a[0][i];     }     for (int l = 1; l < n; l++) {       for (int i = 0; i < n - l; i++) {         a[l][i] = a[l - 1][i] ^ a[l - 1][i + 1];         b[l][i] = max(b[l - 1][i], b[l - 1][i + 1]);         b[l][i] = max(b[l][i], a[l][i]);       }     }     cin >> q;     for (int i = 0; i < q; i++) {       cin >> l >> r;       cout << b[r - l][l - 1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e2 + 10;   int n;   int t[N], w[N], dp[N][2 * N];   int main() {     cin >> n;     int sumw = 0;     for (int i = 1; i <= n; i++) {       cin >> t[i] >> w[i];       sumw += w[i];     }     for (int i = 0; i <= n; i++) {       for (int j = 1; j <= 2 * n; j++) dp[i][j] = -1e9;     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= 2 * n; j++) dp[i][j] = dp[i - 1][j];       for (int j = 0; j <= 2 * n - t[i]; j++) {         dp[i][j + t[i]] = max(dp[i][j + t[i]], dp[i - 1][j] + w[i]);       }     }     int ans = 1e9;     for (int i = 1; i <= 2 * n; i++) {       if (sumw - dp[n][i] <= i) {         ans = i;         break;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   int main() {     int same = 0, diff = 0;     int a, b;     scanf( %d %d , &a, &b);     while (a != 0 && b != 0) {       diff++;       a--;       b--;     }     while (a >= 2) {       a -= 2;       same++;     }     while (b >= 2) {       b -= 2;       same++;     }     printf( %d %d n , diff, same);     return 0;   }
#include <bits/stdc++.h>   using std::sort;   const int SIZE = 100;   int dig[SIZE + 10];   char str[SIZE + 10];   int strsplit(char *str, int len) {     int size = -1;     for (char *p = strtok(str,  + ); p != NULL; p = strtok(NULL,  + ))       sscanf(p,  %d , &dig[++size]);     return size;   }   int main() {     while (scanf( %s , str) != -1) {       int len = strlen(str);       int size = strsplit(str, len);       if (size < 0) {         printf(  n );         continue;       }       sort(dig, dig + size + 1);       for (int i = 0; i < size; i++) printf( %d+ , dig[i]);       printf( %d n , dig[size]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     long long a[300005], p[300005];     long long n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> p[i];     long long g = 0;     for (int i = 1; i < n; i++) {       g = gcd(g, a[i] - a[i - 1]);     }     for (int i = 0; i < m; i++) {       if (g % p[i] == 0) {         cout <<  YES  << endl;         cout << a[0] <<     << i + 1 << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct tri {     tri(int x = 0, int y = 0, int z = 0) { a = x, b = y, c = z; }     int a, b, c;   } par[101][101][101];   char col[101][101];   string h[101];   int d[101][101][101];   queue<tri> q;   int main() {     int n, a, b, c;     cin >> n >> a >> b >> c;     if (a == b || b == c || a == c) {       cout << -1;       return 0;     }     for (int i = 1; i <= n; i++) {       cin >> h[i];       for (int j = 1; j <= n; j++) col[i][j] = h[i][j - 1];     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++) d[i][j][k] = 1e9;     d[a][b][c] = 0;     q.push(tri(a, b, c));     while (!q.empty()) {       tri cu = q.front();       q.pop();       int dis = d[cu.a][cu.b][cu.c];       int tmp[] = {cu.a, cu.b, cu.c};       sort(tmp, tmp + 3);       int A = tmp[0], B = tmp[1], C = tmp[2];       if (A == 1 && B == 2 && C == 3) {         cout << dis << endl;         vector<pair<int, int> > m;         for (int i = dis; i > 0; i--) {           tri pare = par[cu.a][cu.b][cu.c];           if (pare.a != cu.a) m.push_back(make_pair(pare.a, cu.a));           if (pare.b != cu.b) m.push_back(make_pair(pare.b, cu.b));           if (pare.c != cu.c) m.push_back(make_pair(pare.c, cu.c));           cu = pare;         }         for (int i = dis - 1; i >= 0; i--)           cout << m[i].first <<     << m[i].second << endl;         return 0;       }       A = cu.a, B = cu.b, C = cu.c;       for (int i = 1; i <= n; i++) {         if (i != A && i != B && i != C) {           if (d[i][B][C] == 1e9 && col[A][i] == col[B][C]) {             par[i][B][C] = tri(A, B, C);             d[i][B][C] = dis + 1;             q.push(tri(i, B, C));           }           if (d[A][i][C] == 1e9 && col[B][i] == col[A][C]) {             par[A][i][C] = tri(A, B, C);             d[A][i][C] = dis + 1;             q.push(tri(A, i, C));           }           if (d[A][B][i] == 1e9 && col[C][i] == col[A][B]) {             par[A][B][i] = tri(A, B, C);             d[A][B][i] = dis + 1;             q.push(tri(A, B, i));           }         }       }     }     cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<char, int> tile = {       { + , 15},     { - , 8 + 2},  { | , 1 + 4},  { ^ , 1},       { v , 4},      { > , 2},      { < , 8},      { L , 15 - 8},       { R , 15 - 2}, { U , 15 - 1}, { D , 15 - 4}, { * , 0},   };   int n, m, xt, yt, xm, ym;   vector<string> laby;   bool ok(char t, int d, int l, int x, int y) {     if (x < 0 || x >= n) return false;     if (y < 0 || y >= m) return false;     int t1 = tile[t],         t2 = ((((((((tile[laby[x][y]]) << 1) & 15) + ((tile[laby[x][y]]) >> 3)))                 << 1) &                15) +               ((((((tile[laby[x][y]]) << 1) & 15) + ((tile[laby[x][y]]) >> 3))) >>                3));     for (__typeof(l) _i = 0; _i < (l); ++_i) {       t1 = ((((t1) << 1) & 15) + ((t1) >> 3));       t2 = ((((t2) << 1) & 15) + ((t2) >> 3));     }     return t1 & t2 & d;   }   int main() {     cin >> n >> m;     laby.resize(n);     for (__typeof(n) i = 0; i < n; ++i) cin >> laby[i];     cin >> xt >> yt >> xm >> ym;     xt--, yt--, xm--, ym--;     vector<bool> seen(n * m * 4);     deque<pair<int, int>> q = {{0, ((0) * n * m + (xt)*m + yt)}};     while (q.size()) {       pair<int, int> p = q.front();       q.pop_front();       int t = p.first, pos = p.second;       if (seen[pos]) continue;       seen[pos] = true;       int l = pos / n / m, y = pos % m, x = pos / m % n;       if (x == xm && y == ym) {         cout << t << endl;         return 0;       }       q.push_back({t + 1, ((l + 1 & 3) * n * m + (x)*m + y)});       if (ok(laby[x][y], 1, l, x - 1, y)) {         q.push_back({t + 1, ((l)*n * m + (x - 1) * m + y)});       }       if (ok(laby[x][y], 4, l, x + 1, y)) {         q.push_back({t + 1, ((l)*n * m + (x + 1) * m + y)});       }       if (ok(laby[x][y], 8, l, x, y - 1)) {         q.push_back({t + 1, ((l)*n * m + (x)*m + y - 1)});       }       if (ok(laby[x][y], 2, l, x, y + 1)) {         q.push_back({t + 1, ((l)*n * m + (x)*m + y + 1)});       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                            {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};   const long long INF = 1000000000000000000;   struct SEG {     int siz = 1 << 19;     long long s[1 << 20];     long long t[1 << 20];     void init() {       for (int i = 0; i < 2 * siz - 1; i++) {         s[i] = 0;         t[i] = 0;       }     }     void add(int a, int b, long long x, int k, int l, int r) {       if (b <= l || r <= a) return;       if (a <= l && r <= b) {         s[k] += x;         t[k] += x;         return;       }       add(a, b, x, 2 * k + 1, l, (l + r) / 2);       add(a, b, x, 2 * k + 2, (l + r) / 2, r);       s[k] = min(s[2 * k + 1], s[2 * k + 2]) + t[k];     }     long long query(int a, int b, int k, int l, int r) {       if (b <= l || r <= a) return INF;       if (a <= l && r <= b) return s[k];       long long chl = query(a, b, 2 * k + 1, l, (l + r) / 2);       long long chr = query(a, b, 2 * k + 2, (l + r) / 2, r);       return min(chl, chr) + t[k];     }   } seg;   int main() {     static int n, q;     static int p[500010];     static long long w[500010];     static int v[500010], l[500010], r[500010];     scanf( %d%d , &n, &q);     for (int i = 2; i <= n; i++) {       scanf( %d%lld , &p[i], &w[i]);     }     for (int i = 0; i < q; i++) scanf( %d%d%d , &v[i], &l[i], &r[i]);     static int R[500010];     for (int i = 1; i <= n; i++) R[i] = i;     for (int i = n; i >= 2; --i) {       R[p[i]] = max(R[p[i]], R[i]);     }     seg.init();     static int cnt[500010] = {};     for (int i = 1; i <= n; i++) {       cnt[p[i]]++;     }     static long long d[500010];     d[1] = 0;     seg.add(1, 2, INF, 0, 0, seg.siz);     for (int i = 2; i <= n; i++) {       d[i] = d[p[i]] + w[i];       seg.add(i, i + 1, cnt[i] == 0 ? d[i] : INF, 0, 0, seg.siz);     }     static vector<pair<pair<int, int>, pair<int, int> > > Que;     for (int i = 0; i < q; i++)       Que.push_back(pair<pair<int, int>, pair<int, int> >(           pair<int, int>(v[i], i), pair<int, int>(l[i], r[i])));     sort(Que.begin(), Que.end());     static long long ans[500010];     int k = 0;     for (int i = 1; i <= n; i++) {       while (k < Que.size() && Que[k].first.first == i) {         ans[Que[k].first.second] = seg.query(             Que[k].second.first, Que[k].second.second + 1, 0, 0, seg.siz);         k++;       }       if (i == n) break;       int loc = i;       while (loc != p[i + 1]) {         seg.add(0, seg.siz, -w[loc], 0, 0, seg.siz);         seg.add(loc, R[loc] + 1, 2 * w[loc], 0, 0, seg.siz);         loc = p[loc];       }       seg.add(0, seg.siz, w[i + 1], 0, 0, seg.siz);       seg.add(i + 1, R[i + 1] + 1, -2 * w[i + 1], 0, 0, seg.siz);     }     for (int i = 0; i < q; i++) {       printf( %lld n , ans[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 10;   const long long mod = 998244353;   long long power(long long x, long long y) {     x = x % mod, y = y % (mod - 1);     long long ans = 1;     while (y > 0) {       if (y & 1) {         ans = (1ll * x * ans) % mod;       }       y >>= 1;       x = (1ll * x * x) % mod;     }     return ans;   }   long long add(long long a, long long b) { return (a % mod + b % mod) % mod; }   long long mul(long long a, long long b) { return (a % mod * b % mod) % mod; }   long long n, k;   const long long K = 210;   vector<long long> a(N);   vector<long long> b(N);   multiset<long long> st;   long long pow2[N];   void power_2() {     pow2[0] = 1;     long long x = 1;     long long cnt = 1;     while (cnt < 3e5) {       pow2[cnt] = mul(pow2[cnt - 1], 2);       cnt++;     }   }   int32_t main() {     long long nx, mx;     cin >> nx >> mx;     string s, t;     cin >> s >> t;     power_2();     long long temp = 0, ans = 0;     long long n = min(s.size(), t.size());     for (long long i = 0; i < mx; i++) {       if (i < nx and s[nx - i - 1] ==  1 ) temp = add(temp, pow2[i]);       if (t[mx - i - 1] ==  1 ) ans = add(ans, temp);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long n, m;   long long a[maxn], b[maxn];   bool cmp(long long a, long long b) { return a > b; }   int main() {     scanf( %lld %lld , &n, &m);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= m; i++) scanf( %lld , &b[i]);     sort(a + 1, a + n + 1, cmp);     sort(b + 1, b + m + 1, cmp);     if (a[1] > b[m]) {       cout << -1 << endl;       return 0;     }     long long ans = a[1], t = m - 1, bj = 1;     for (int i = 1; i <= m; i++) {       if (b[i] == a[1]) continue;       if (t == 0) {         bj++;         ans += a[bj];         t = m - 1;       }       ans += b[i];       t--;     }     for (int i = n; i > bj; i--) ans += (a[i] * m);     ans += t * a[bj];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k, l;     cin >> k;     vector<int> a[k];     for (int i = 0; i < k; i++)       for (int j = 0; j < k; j++) cin >> l, a[i].push_back(l);     l = 0;     for (int i = 0; i < k; i++) l += a[k / 2][i];     for (int i = 0; i < k; i++) l += a[i][k / 2];     for (int i = 0; i < k; i++) l += a[i][i];     for (int i = 0; i < k; i++) l += a[i][k - i - 1];     cout << l - (3 * (a[k / 2][k / 2]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (a != 0 && b != 0) {       if (a > b) {         a %= b;       } else if (a < b) {         b %= a;       } else {         return a;       }     }     return a + b;   }   long long divS(long long a) {     long long res = 0;     while (a > 0) {       res += a % 10;       a /= 10;     }     return res;   }   int distToSym(char a, char b) {     if (abs(int(a) - int(b)) <= 13)       return abs(int(a) - int(b));     else       return (26 % abs(int(a) - int(b)));   }   int main() {     ios_base::sync_with_stdio(false);     string s;     cin >> s;     bool v = false, h = false;     for (auto& x : s) {       if (x ==  0 ) {         if (v)           cout <<  1 1 n ;         else           cout <<  3 1 n ;         v = !v;       } else {         if (h)           cout <<  1 1 n ;         else           cout <<  1 3 n ;         h = !h;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4010;   const int MAXT = 1 << 15;   int N, P, Q;   vector<pair<int, int> > qu[MAXT];   vector<pair<int, int> > items[2 * MAXT];   int ans[MAXT];   void update(int a, int b, pair<int, int> v, int cur = 1, int lt = 0,               int rt = MAXT) {     if (rt <= a || b <= lt) {       return;     }     if (a <= lt && rt <= b) {       items[cur].push_back(v);       return;     }     int mid = (lt + rt) / 2;     update(a, b, v, 2 * cur, lt, mid);     update(a, b, v, 2 * cur + 1, mid, rt);   }   int dp[17][MAXN];   void rec(int lt = 0, int rt = MAXT, int cur = 1, int dep = 0) {     if (dep) {       memcpy(dp[dep], dp[dep - 1], sizeof(dp[dep]));     }     for (pair<int, int> p : items[cur]) {       for (int i = MAXN - 1; i >= p.first; i--) {         dp[dep][i] = max(dp[dep][i], dp[dep][i - p.first] + p.second);       }     }     if (rt == lt + 1) {       for (pair<int, int> p : qu[lt]) {         ans[p.second] = dp[dep][p.first];       }     } else {       int mid = (lt + rt) / 2;       rec(lt, mid, 2 * cur, dep + 1);       rec(mid, rt, 2 * cur + 1, dep + 1);     }   }   int main() {     scanf( %d %d , &N, &P);     for (int i = 0; i < N; i++) {       int c, h, t;       scanf( %d %d %d , &c, &h, &t);       update(t, t + P, pair<int, int>(c, h));     }     scanf( %d , &Q);     for (int i = 0; i < Q; i++) {       int t, b;       scanf( %d %d , &t, &b);       qu[t].push_back(pair<int, int>(b, i));     }     rec();     for (int i = 0; i < Q; i++) {       printf( %d n , ans[i]);     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:256000000 )   using namespace std;   int main() {     int tux;     cin >> tux;     int foo = 0;     int bar = 0;     int baz = 0;     int quz = 1;     for (int i = 0; i < tux; i++) {       int pur;       cin >> pur;       foo = foo + pur;       bar = bar + 1;       if (max(foo * quz, bar * baz) == foo * quz) {         baz = foo;         quz = bar;       }     }     printf( %.10lf n , (double)baz / quz);     return 0;   }
#include <bits/stdc++.h>   const int maxn = 200005;   const int inf = 1234567890;   using namespace std;   int n, a, b;   int main(void) {     cin >> n >> a >> b;     double max_x = -1;     for (int i = ((1) > (n - b) ? (1) : (n - b));          i <= ((n - 1) < (a) ? (n - 1) : (a)); i++) {       double av1 = 1.0 * a / i;       double av2 = 1.0 * b / (n - i);       double cur_x = ((av1) < (av2) ? (av1) : (av2));       max_x = ((max_x) > (cur_x) ? (max_x) : (cur_x));     }     cout << (int)max_x << endl;     return 0;   }
#include <bits/stdc++.h>   static inline void setio(void);   int main(void) {     setio();     long long n;     std::cin >> n;     std::vector<long long> vec(n);     std::vector<char> neg(n);     for (long long i = 0; i < n; ++i) {       std::cin >> vec[i];       if (vec[i] < 0) {         neg[i] = true;         vec[i] = -vec[i];       }     }     std::vector<long long> primes;     std::vector<char> sieve(1000000, true);     for (long long i = 2; i < sieve.size(); ++i) {       if (!sieve[i]) continue;       primes.push_back(i * i);       if (primes.back() > 100000001LL) break;       for (long long j = i + i; j < sieve.size(); j += i) sieve[j] = false;     }     for (auto& num : vec) {       for (const auto& p : primes) {         if (p > num) break;         while (num % p == 0) num /= p;       }     }     for (long long i = 0; i < n; ++i)       if (neg[i]) vec[i] = -vec[i];     std::vector<long long> cnts(n + 1, 0);     std::vector<long long> last_time(n);     std::map<long long, long long> bleh;     for (long long i = 0; i < n; ++i) {       last_time[i] = bleh[vec[i]] - 1;       bleh[vec[i]] = i + 1;     }     bool seen_zero;     for (long long i = 0; i < n; ++i) {       long long count = 0;       seen_zero = false;       for (long long j = i; j < n; ++j) {         count += last_time[j] < i;         seen_zero = seen_zero || vec[j] == 0;         if (count == 1 && seen_zero)           cnts[count]++;         else if (count > 0)           cnts[count - (seen_zero)]++;       }     }     for (long long i = 1; i <= n; ++i) std::cout << cnts[i] <<    ;     std::cout <<   n ;     return 0;   }   static inline void setio(void) {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.precision(10);     std::cout << std::fixed;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long x = max((3 * a) / 10, (a - ((a / 250) * c)));     long long y = max((3 * b) / 10, (b - ((b / 250) * d)));     string s =  Tie ;     if (x > y)       s =  Misha ;     else if (x < y)       s =  Vasya ;     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int seg[(long long int)3e5 * 3];   int laz[(long long int)3e5 * 3];   void build(int index, int a, int b, int *ar) {     if (a == b) {       seg[index] = ar[a];       return;     }     int mid = (a + b) / 2;     build(2 * index, a, mid, ar);     build(2 * index + 1, mid + 1, b, ar);     seg[index] = max(seg[2 * index], seg[2 * index + 1]);   }   void la(int l, int r, int index) {     seg[index] += laz[index];     int a = 2 * index;     int b = 2 * index + 1;     if (l < r) {       laz[a] += laz[index];       laz[b] += laz[index];     }     laz[index] = 0;   }   void upd(int val, int l, int r, int x, int y, int index) {     la(x, y, index);     if (x > r || l > y) return;     if (l <= x and r >= y) {       laz[index] += val;       la(x, y, index);       return;     }     int mid = (x + y) / 2;     upd(val, l, r, x, mid, 2 * index);     upd(val, l, r, mid + 1, y, 2 * index + 1);     seg[index] = max(seg[2 * index], seg[2 * index + 1]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, p;     cin >> n >> m >> p;     vector<pair<int, int>> weap;     vector<pair<int, int>> armr;     vector<pair<int, pair<int, int>>> monst;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       weap.push_back({a, b});     }     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       armr.push_back({a, b});     }     for (int i = 0; i < p; i++) {       int a, b, c;       cin >> a >> b >> c;       monst.push_back({a, {b, c}});     }     sort(weap.begin(), weap.end());     sort(armr.begin(), armr.end());     sort(monst.begin(), monst.end());     int pt = 0;     int ar[(int)3e5];     for (int i = 0; i < m; i++) ar[i + 1] = -armr[i].second;     build(1, 1, m, ar);     int ans = -2 * (1e9 + 7);     for (int i = 0; i < n; i++) {       while (pt < p and weap[i].first > monst[pt].first) {         int l = upper_bound(armr.begin(), armr.end(),                             make_pair(monst[pt].second.first, (int)1e9 + 7)) -                 armr.begin();         l++;         if (l <= m) {           upd(monst[pt].second.second, l, m, 1, m, 1);         }         pt++;       }       ans = max(ans, (seg[1] - weap[i].second));     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ifstream ff( file.txt );     int n, m;     cin >> n >> m;     map<int, int> Mymap;     int u;     for (int i = 0; i < n; i++) {       cin >> u;       Mymap.insert(pair<int, int>(i + 1, u));     }     unsigned long long sum = 0;     vector<int> v2;     int z;     unsigned int sv;     for (int i = 0; i < m; i++) {       sv = v2.size();       cin >> z;       if (v2.empty()) {         v2.push_back(z);       } else {         for (int j = sv - 1; j >= 0; j--) {           if (v2[j] != z) {             sum += Mymap[v2[j]];           } else {             v2.erase(v2.begin() + j);             v2.push_back(z);             break;           }           if (j == 0) {             v2.push_back(z);           }         }       }     }     cout << sum << endl;     return 0;   }