malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, n, i, j, money;     cin >> a >> b >> c;     cin >> n;     int m[n];     money = 0;     for (i = 0; i < n; i++) {       cin >> m[i];       if (m[i] > b && m[i] < c) money = money + 1;     }     if (a > b && a < c)       cout << money;     else       cout << 0;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void display(T a[], int size) {     for (int i = 0; i < size; i++) {       cout << a[i] <<    ;     }     cout << endl;   }   void display(vector<pair<int, int> > a) {     for (int i = 0; i < a.size(); i++) {       cout <<  (  << a[i].first <<  ,  << a[i].second <<  )             <<    ;     }     cout << endl;   }   void display(const vector<int>& a) {     for (int i = 0; i < a.size(); i++) {       cout << a[i];       if (i == a.size() - 1)         cout << endl;       else         cout <<    ;     }   }   template <typename T>   void initialise(T a[], T value, int length) {     for (int i = 0; i < length; i++) a[i] = value;   }   template <typename T>   void initialise(vector<T>& a, T value) {     for (int i = 0; i < a.size(); i++) a[i] = value;   }   bool compare(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first)       return a.first < b.first;     else       return a.second < b.second;   }   int max(int a[], int n) {     int max = -1000000000;     for (int i = 0; i < n; i++) {       if (a[i] > max) max = a[i];     }     return max;   }   bool find(string a[], string s, int n) {     int left = 0;     int right = n - 1;     while (left < right) {       int mid = (left + right) / 2;       if (s.compare(a[mid]) == 0)         return true;       else if (s.compare(a[mid]) < 0) {         right = mid;       } else {         left = mid + 1;       }     }     return false;   }   void factor(int a[], int base, int num, int n) {     for (int i = n - 1; i >= 0; i--) {       a[i] = num % base;       num = num / base;     }   }   int findLength(int n, int base) {     int i = 0;     while (n > 0) {       i++;       n = n / base;     }     return i;   }   int gcd(int a, int b) {     while (a % b != 0 && b % a != 0) {       if (b > a) {         b = b % a;       } else if (a > b) {         a = a % b;       }     }     if (a <= b)       return a;     else       return b;   }   int main() {     int n;     cin >> n;     int dir[n];     int step[n];     for (int i = 0; i < n; i++) {       char now;       cin >> now;       if (now ==  > )         dir[i] = 1;       else         dir[i] = -1;     }     for (int i = 0; i < n; i++) {       cin >> step[i];     }     int trace[n];     initialise(trace, 0, n);     int curr = 0;     while (true) {       if (trace[curr] == 1) {         cout <<  INFINITE  << endl;         break;       } else {         trace[curr] = 1;         curr = curr + dir[curr] * step[curr];         if (curr >= n || curr < 0) {           cout <<  FINITE  << endl;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, dp[100005][3], MOD = 1000000007;   char s[2][100005];   long long ans = 1;   int main() {     scanf( %d%s%s , &N, s[0], s[1]);     for (int i = 0; i < N; ++i) {       if (s[0][i] ==  ? ) ans = (((ans * 10) % (MOD) + (MOD)) % (MOD));       if (s[1][i] ==  ? ) ans = (((ans * 10) % (MOD) + (MOD)) % (MOD));       for (int x = 0; x < 10; ++x) {         for (int y = 0; y < 10; ++y) {           if ((s[0][i] ==  ?  || s[0][i] == x +  0 ) &&               (s[1][i] ==  ?  || s[1][i] == y +  0 )) {             if (x >= y) {               dp[i][0] =                   (((dp[i][0] + (i ? dp[i - 1][0] : 1)) % (MOD) + (MOD)) % (MOD));             }             if (x <= y) {               dp[i][1] =                   (((dp[i][1] + (i ? dp[i - 1][1] : 1)) % (MOD) + (MOD)) % (MOD));             }             if (x == y) {               dp[i][2] =                   (((dp[i][2] + (i ? dp[i - 1][2] : 1)) % (MOD) + (MOD)) % (MOD));             }           }         }       }     }     if (N == 1)       puts( 0 );     else       printf(            %d n ,           (((ans - dp[N - 1][0] - dp[N - 1][1] + dp[N - 1][2]) % (MOD) + (MOD)) %            (MOD)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, c = 0, d = 0, k;     string str;     cin >> n >> str;     for (int i = 0; i < n; i++) {       if (str[i] ==  - ) c++;     }     if (c == n) {       cout << 0 << endl;       return 0;     } else if (str[0] ==  - ) {       for (int i = 0; i < n; i++) {         if (str[i] ==  - ) {           continue;         } else {           k = i;           break;         }       }       for (int i = k; i < n; i++) {         if (str[i] ==  + )           d += 1;         else {           d -= 1;           if (d < 0) d = 0;         }       }     } else {       for (int i = 0; i < n; i++) {         if (str[i] ==  + )           d += 1;         else {           d -= 1;           if (d < 0) d = 0;         }       }     }     cout << d << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int M;   const int MAX = 100001;   vector<int> _size, marked, _pow, _ipow;   vector<pair<int, int> > adjList[MAX + 1];   int getSize(int u, int p = -1) {     _size[u] = 1;     for (auto [v, w] : adjList[u])       if (v != p && !marked[v]) _size[u] += getSize(v, u);     return _size[u];   }   int getCentroid(int u, int p, int n) {     for (auto [v, w] : adjList[u])       if (v != p && !marked[v] && _size[v] * 2 > n) return getCentroid(v, u, n);     return u;   }   void add(unordered_map<int, int> &aux, int u, int p, int lvl, int rem) {     aux[rem]++;     for (auto [v, w] : adjList[u])       if (v != p && !marked[v])         add(aux, v, u, lvl + 1, (int(1LL * w * _pow[lvl] % M) + rem) % M);   }   void remove(unordered_map<int, int> &aux, int u, int p, int lvl, int rem) {     aux[rem]--;     for (auto [v, w] : adjList[u])       if (v != p && !marked[v])         remove(aux, v, u, lvl + 1, (int(1LL * w * _pow[lvl] % M) + rem) % M);   }   long long count(unordered_map<int, int> &aux, int u, int p, int lvl, int rem) {     int nxt = int(1LL * _ipow[lvl] * (M - rem) % M);     long long ans = aux[nxt];     for (auto [v, w] : adjList[u])       if (v != p && !marked[v])         ans += count(aux, v, u, lvl + 1, (rem * 10LL + w) % M);     return ans;   }   long long solve(int u) {     int N = getSize(u);     u = getCentroid(u, -1, N);     marked[u] = 1;     unordered_map<int, int> aux;     aux[0] = 1;     for (auto [v, w] : adjList[u])       if (!marked[v]) add(aux, v, u, 1, w % M);     long long ans = aux[0] - 1;     for (auto [v, w] : adjList[u])       if (!marked[v]) {         remove(aux, v, u, 1, w % M);         ans += count(aux, v, u, 1, w % M);         add(aux, v, u, 1, w % M);       }     aux.clear();     for (auto [v, w] : adjList[u])       if (!marked[v]) ans += solve(v);     return ans;   }   int gcd(int a, int b, int &x, int &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     int x1, y1;     int d = gcd(b, a % b, x1, y1);     x = y1;     y = x1 - y1 * (a / b);     return d;   }   int getInv() {     int x, y;     int g = gcd(10, M, x, y);     assert(g == 1);     return (x % M + M) % M;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n >> M;     _size = vector<int>(n), _pow = vector<int>(n + 1, 1),     _ipow = vector<int>(n + 1, 1), marked = vector<int>(n + 1);     _ipow[1] = getInv();     _pow[1] = 10;     for (int i = 2; i <= n; i++) {       _pow[i] = int(1LL * _pow[i - 1] * 10 % M);       _ipow[i] = int(1LL * _ipow[i - 1] * _ipow[1] % M);     }     for (int i = 0; i < n - 1; i++) {       int u, v, w;       cin >> u >> v >> w;       adjList[u].push_back({v, w});       adjList[v].push_back({u, w});     }     cout << solve(0) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 100, M = 1e6 + 100;   int n, up[N], down[M], nei[M][2];   int lim;   bool mark[M], bad[M];   vector<int> vec;   int f(int a) { return lower_bound(vec.begin(), vec.end(), a) - vec.begin(); }   bool dfs(int v) {     mark[v] = true;     for (int i = 0; i < 2 && nei[v][i] <= lim; i++) {       int u = nei[v][i];       if (up[u] == -1 || (mark[up[u]] == false && dfs(up[u]))) {         up[u] = v;         down[v] = u;         return true;       }     }     return false;   }   bool ok(int X) {     lim = X;     fill(up, up + N, -1);     fill(down, down + M, -1);     memset(bad, false, sizeof bad);     int matching = 0;     bool done = false;     for (int v = 0; v < n; v++)       if (nei[v][0] > lim)         return false;       else if (nei[v][1] > lim) {         if (up[nei[v][0]] != -1) return false;         down[v] = nei[v][0];         up[nei[v][0]] = v;         bad[v] = true;         matching++;       }     while (done == false) {       done = true;       copy(bad, bad + n, mark);       for (int v = 0; v < n; v++)         if (mark[v] == false && down[v] == -1 && dfs(v)) {           matching++;           done = false;         }     }     return matching == n;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> nei[i][0] >> nei[i][1];       vec.push_back(nei[i][0]);       vec.push_back(nei[i][1]);     }     sort(vec.begin(), vec.end());     vec.resize(unique(vec.begin(), vec.end()) - vec.begin());     for (int i = 0; i < n; i++)       nei[i][0] = f(nei[i][0]), nei[i][1] = f(nei[i][1]);     if (ok(vec.size() - 1) == false) {       cout << -1;       return 0;     }     if (ok(vec.size() - 2) == false) {       cout << vec.back();       return 0;     }     int l = -1, r = vec.size() - 1;     while (r - l > 1) {       if (ok((l + r) >> 1))         r = lim;       else         l = lim;     }     cout << vec[r];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int val[200007], add[200007];   int main() {     int n, t, a, x, k, l = 1;     long long sum = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &t);       if (t == 1) {         scanf( %d%d , &a, &x);         add[a] += x;         sum += a * x;       } else if (t == 2) {         scanf( %d , &k);         val[++l] = k;         sum += val[l];       } else if (l > 1) {         sum -= val[l];         sum -= add[l];         add[l - 1] += add[l];         add[l] = 0;         --l;       }       printf( %.6lf n , (double)sum / l);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int N = 2e5 + 10;   long long n, w, k, happy[N], nice, t[N], mytime, ans;   bool in[N];   pair<int, int> lowest;   set<pair<int, int>> st;   queue<int> q;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> w >> k;     for (int i = 0; i < n; i++) cin >> happy[i];     for (int i = 0; i < n; i++) cin >> t[i];     for (int i = n - 1; ~i; i--) {       st.insert({t[i], -i});       if ((int)st.size() == w) {         lowest = *st.begin();         mytime += (t[i] + 1) / 2;         in[i] = true;       } else if ((int)st.size() > w) {         if (t[i] >= lowest.first) {           in[-lowest.second] = false;           mytime += (t[i] + 1) / 2;           mytime -= (lowest.first + 1) / 2;           mytime += lowest.first;           lowest = *st.upper_bound(lowest);           in[i] = true;         } else           mytime += t[i];       } else {         in[i] = true;         mytime += (t[i] + 1) / 2;       }       nice += happy[i];       q.push(i);       while (mytime > k) {         nice -= happy[q.front()];         if (in[q.front()]) {           mytime -= (t[q.front()] + 1) / 2;           in[q.front()] = false;           st.erase({t[q.front()], -q.front()});           if ((int)st.size() >= w) {             lowest = *(--st.lower_bound(lowest));             in[-lowest.second] = true;             mytime -= lowest.first;             mytime += (lowest.first + 1) / 2;           }         } else {           mytime -= t[q.front()];           st.erase({t[q.front()], -q.front()});         }         q.pop();       }       ans = max(ans, nice);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void speedUp() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long int t, n, m, p[100005], q[100005], Podd, Peven, Qodd, Qeven, tot;   int main() {     speedUp();     int t, n;     cin >> t;     while (t--) {       tot = Podd = Peven = Qodd = Qeven = 0;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> p[i];         if (p[i] % 2 == 0)           Peven++;         else           Podd++;       }       cin >> m;       for (int i = 1; i <= m; i++) {         cin >> q[i];         if (q[i] % 2 == 0)           Qeven++;         else           Qodd++;       }       for (int i = 1; i <= n; i++) {         if (p[i] % 2 == 0)           tot += Qeven;         else           tot += Qodd;       }       cout << tot << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     scanf( %d , &n);     int v[n];     for (int i = 0; i < n; i++) scanf( %d , v + i);     if (n > 2) {       for (int i = 0; i + 3 <= n; i++) {         int a = v[i], b = v[i + 1], c = v[i + 2];         int ans1 = -1, ans2 = -1;         set<int> ms;         ms.insert(a);         ms.insert(b);         ms.insert(c);         if (ms.size() == 1)           continue;         else if (ms.size() == 3) {           if (a == *ms.begin())             ans1 = i, ans2 = i + 1;           else if (a == *(++ms.begin()))             ans1 = i, ans2 = i + 2;           else if (a == *ms.rbegin())             ans1 = i, ans2 = i + 1;         } else if (ms.size() == 2) {           if (a == c) {             int d = -1;             if (i > 0) {               d = v[i - 1];               if (d != a)                 ans1 = i - 1, ans2 = i;               else                 ans1 = i, ans2 = i + 1;             } else if (i + 3 < n) {               d = v[i + 3];               if (d != a)                 ans1 = i + 2, ans2 = i + 3;               else                 ans1 = i + 1, ans2 = i + 2;             } else               continue;           } else if (a == b)             ans1 = i + 1, ans2 = i + 2;           else if (b == c)             ans1 = i, ans2 = i + 1;         }         printf( %d %d n , ans1 + 1, ans2 + 1);         return 0;       }     }     printf( -1 n );     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-2;   struct cplx {     double x, y;     cplx(double x1 = 0, double x2 = 0) { x = x1, y = x2; }   } g[2000001], f[2000001];   cplx operator+(cplx a, cplx b) { return cplx(a.x + b.x, a.y + b.y); }   cplx operator-(cplx a, cplx b) { return cplx(a.x - b.x, a.y - b.y); }   cplx operator*(cplx a, cplx b) {     return cplx(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);   }   void swap(cplx &a, cplx &b) { swap(a.x, b.x), swap(a.y, b.y); }   int a[2000001], b[2000001];   int r[2000001];   const double Pi = acos(-1);   void fft(cplx f[], int op, int n) {     for (int i = 0; i < n; i++)       if (i < r[i]) swap(f[i], f[r[i]]);     for (int w = 2; w <= n; w <<= 1) {       int len = w / 2;       cplx tmp(cos(Pi / len), op * sin(Pi / len));       for (int k = 0; k < n; k += w) {         cplx buf(1, 0);         for (int l = k; l < k + len; l++) {           cplx tt = f[len + l] * buf;           f[len + l] = f[l] - tt;           f[l] = f[l] + tt;           buf = buf * tmp;         }       }     }     if (op == -1) {       for (int i = 0; i < n; i++) f[i].x /= n, f[i].y /= n;     }   }   char p[2000001];   char q[2000001];   int res[2000001];   int l1, l2, k, n, m;   void solve(char c) {     for (int i = 0; i <= n; i++) f[i].x = f[i].y = g[i].x = g[i].y = 0;     int far = -1;     for (int i = 0; i < l1; i++) {       if (p[i] == c) far = i + k;       if (i <= far) f[i].x = 1;     }     far = l1;     for (int i = l1 - 1; i >= 0; i--) {       if (p[i] == c) far = i - k;       if (i >= far) f[i].x = 1;     }     for (int i = 0; i < l2; i++)       if (q[i] == c) g[i].x = 1;     fft(f, 1, n);     fft(g, 1, n);     for (int i = 0; i < n; i++) f[i] = f[i] * g[i];     fft(f, -1, n);     for (int i = 0; i < n; i++) res[i] += (int)(f[i].x + eps);   }   signed main() {     int ans = 0;     scanf( %d%d%d , &l1, &l2, &k);     cin >> p;     cin >> q;     reverse(p, p + l1);     n = l1, m = l2;     for (m += n, n = 1; n <= m; n <<= 1)       ;     for (int i = 0; i < n; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) ? n >> 1 : 0);     solve( A );     solve( T );     solve( G );     solve( C );     for (int i = 0; i <= l1 - l2; i++)       if (res[l1 - i - 1] >= l2) ans++;     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   struct edge {     int to, nxt;   } e[100005], e2[100005];   int h[100005], n, cnt, hei[100005], gson[100005], node[100005], N, fa[100005];   void ins(int x, int y) {     e[++cnt].nxt = h[x];     e[cnt].to = y;     h[x] = cnt;   }   void dfs1(int x) {     hei[x] = 1;     for (int i = h[x]; i; i = e[i].nxt) {       dfs1(e[i].to);       hei[x] = std::max(hei[x], hei[e[i].to] + 1);       if (hei[gson[x]] < hei[e[i].to]) gson[x] = e[i].to;     }   }   void dfs2(int x) {     node[++N] = x;     for (int i = h[x]; i; i = e[i].nxt)       if (e[i].to != gson[x]) dfs2(e[i].to);     if (gson[x]) dfs2(gson[x]);   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) scanf( %d , &fa[i]), ins((++fa[i]), i);     dfs1(1);     dfs2(1);     for (int i = 1; i <= n; i++) printf( %d  , node[i] - 1);     printf(  n%d n , n - hei[1]);     for (int i = 1, j = 1, k = 0; i <= n - hei[1]; i++) {       while (j <= n && fa[node[j]] == k) k = node[j++];       if (j > n) break;       printf( %d  , node[j] - 1);       k = fa[k];     }   }
#include <bits/stdc++.h>   using namespace std;   char a[1005], b[1005];   int main() {     int s1 = 0, s2 = 0;     scanf( %s %s , &a, &b);     int len1 = strlen(a);     int len2 = strlen(b);     for (int i = 0; i < len1; i++)       if (a[i] ==  1 ) s1++;     for (int i = 0; i < len2; i++)       if (b[i] ==  1 ) s2++;     if (s1 & 1) s1++;     if (s1 >= s2)       puts( YES );     else       puts( NO );   }
#include <bits/stdc++.h>   using namespace std;   int n, Q, x, y, z, kk;   int dis[500005], head[500005], father[500005], top[500005], q[500005];   bool vis[500005];   int far[500005], heavyson[500005], rak[500005], sum[500005], leaf[500005], ans,       d[500005];   struct Tree {     int nxt, to, step;   } e[500005];   inline bool cmp(int u, int v) {     return dis[u] - dis[father[top[u]]] > dis[v] - dis[father[top[v]]];   }   inline void link(int x, int y, int z) {     e[++kk].nxt = head[x];     e[kk].to = y;     e[kk].step = z;     head[x] = kk;   }   inline int bfs(int S) {     int left1 = 1;     int right1 = 1;     q[left1] = S;     memset(d, 0, sizeof(d));     memset(vis, false, sizeof(vis));     vis[S] = true;     while (left1 <= right1) {       int u = q[left1++];       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         if (vis[v]) continue;         vis[v] = true;         q[++right1] = v;         d[v] = d[u] + e[i].step;       }     }     int kkk = 0;     for (int i = 1; i <= n; i++) {       if (d[i] > d[kkk]) kkk = i;     }     return kkk;   }   void dfs1(int u, int fa) {     far[u] = dis[u];     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       father[v] = u;       dis[v] = dis[u] + e[i].step;       dfs1(v, u);       if (!heavyson[u] || far[u] < far[v]) heavyson[u] = v, far[u] = far[v];     }   }   void dfs2(int u, int first) {     top[u] = first;     if (!heavyson[u]) {       leaf[++leaf[0]] = u;       return;     }     dfs2(heavyson[u], first);     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == father[u] || v == heavyson[u]) continue;       dfs2(v, v);     }   }   inline int solve(int x, int y) {     if (rak[top[x]] <= 2 * y - 1) return sum[min(y * 2 - 1, leaf[0])];     int u = x;     while (rak[top[u]] > y * 2 - 1) u = father[top[u]];     return sum[y * 2 - 1] -            min(min(sum[y * 2 - 1] - sum[y * 2 - 2], far[u] - dis[u]), dis[u]) +            far[x] - dis[u];   }   int main() {     scanf( %d%d , &n, &Q);     for (int i = 1; i < n; i++) {       scanf( %d%d%d , &x, &y, &z);       link(x, y, z);       link(y, x, z);     }     int first = bfs(1);     int root = bfs(first);     dfs1(root, -1);     dfs2(root, root);     sort(leaf + 1, leaf + leaf[0] + 1, cmp);     for (int i = 1; i <= leaf[0]; i++) {       rak[top[leaf[i]]] = i;       sum[i] = sum[i - 1] + dis[leaf[i]] - dis[father[top[leaf[i]]]];     }     while (Q--) {       scanf( %d%d , &x, &y);       x = ((x + ans - 1) % n) + 1;       y = ((y + ans - 1) % n) + 1;       printf( %d n , ans = solve(x, y));     }     return 0;   }
#include<bits/stdc++.h>      #define For(i, x, n) for(int i = x; i < n; i++)   #define ROF(i,x,n) for(int i = n - 1; i >= x; i--)      #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)   #define F first   #define S second   #define pb push_back   #define po pop_back   #define mp make_pair   #define En endl   ///#define endl   n       #define ALL(x) x.begin(), x.end()      using namespace std;      typedef double db;   typedef long long LL;   typedef string str;   typedef pair<int, int> PII;   typedef pair<LL, LL> PLL;      typedef vector<int> VI;   typedef vector<LL> VLL;   typedef vector<bool> VB;   typedef vector<char> VC;   typedef vector<PII> VPII;   typedef vector<string> VSTR;   typedef set<int> SI;   typedef set<LL> SLL;   typedef set<PII> SPII;      typedef const int CI;   typedef const long long CLL;      /// CI MAX_N = ;   CI MOD = 1e9 + 7;      int t, n, a;      int main () {       IOS;       cin >> t;       while (t--) {           cin >> n;           int sumz = 0;           int sumf = 0;           For (i, 0, 2 * n) {               cin >> a;               if (a % 2 == 0) sumz++;               else sumf++;           }           if (sumz == sumf) cout <<  YES  << En;           else cout <<  NO  << En;       }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   int n, m, X, a[maxn], b[maxn], c[maxn], d[maxn], tr[maxn];   long long ans;   vector<int> M[maxn];   vector<pair<int, int>> Q[maxn];   void add(int p) {     for (; p <= X; p += p & -p) tr[p]++;   }   int sum(int p) {     int s = 0;     for (; p; p -= p & -p) s += tr[p];     return s;   }   int main() {     scanf( %d %d %d , &n, &m, &X);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]), a[i] = min(a[i], X);     }     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]), b[i] = min(b[i], X);     }     auto init = [&](int n, int *a, int *c) {       static int mx[20][maxn], lb[maxn], rb[maxn];       for (int i = 1; i <= n; i++) {         mx[0][i] = a[i], lb[i] = rb[i] = 0;       }       for (int i = 1; i < 20; i++) {         for (int j = 1; j + (1 << i) - 1 <= n; j++) {           mx[i][j] = max(mx[i - 1][j], mx[i - 1][j + (1 << (i - 1))]);         }       }       auto query = [&](int l, int r) {         int k = log2(r - l + 1);         return max(mx[k][l], mx[k][r - (1 << k) + 1]);       };       stack<int> st;       for (int i = 1; i <= n; i++) {         while (!st.empty() && a[st.top()] > a[i]) rb[st.top()] = i, st.pop();         if (!st.empty()) lb[i] = st.top();         st.push(i);       }       for (int i = 1; i <= n; i++) {         c[i] = min(!lb[i] ? X : query(lb[i], i), !rb[i] ? X : query(i, rb[i]));       }     };     init(n, a, c), init(m, b, d);     for (int i = 1; i <= n; i++) {       Q[X - c[i]].emplace_back(a[i], -1);       Q[X - a[i]].emplace_back(a[i], 1);     }     for (int i = 1; i <= m; i++) {       M[b[i]].push_back(X - d[i] + 1);     }     for (int i = 0; i < X; i++) {       for (int d : M[i]) add(d);       for (auto p : Q[i]) ans += p.second * sum(p.first);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int a[n], b[n];     long int s = 0;     for (int i = 0; i < n; i++) scanf( %d%d , &a[i], &b[i]);     for (int i = 1; i < n; i++) {       if (b[i] >= b[i - 1]) b[i] = b[i - 1];       s += (a[i] * b[i]);     }     printf( %ld n , s + (a[0] * b[0]));     return 0;   }