malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int t, n, m, cur;   int nxt[200200][26], link[200200], dp[200200], cnt[200200], ord[200200],       occur[200200];   char s[200200];   void extend(int c) {     int x = cur, y = cur = ++m;     dp[y] = dp[x] + 1;     occur[y] = 1;     while (x && !nxt[x][c]) nxt[x][c] = y, x = link[x];     if (!x)       link[y] = 1;     else {       int z = nxt[x][c];       if (dp[z] == dp[x] + 1)         link[y] = z;       else {         int u = ++m;         memcpy(nxt[u], nxt[z], sizeof nxt[u]);         link[u] = link[z], link[z] = link[y] = u;         dp[u] = dp[x] + 1;         while (x && nxt[x][c] == z) nxt[x][c] = u, x = link[x];       }     }   }   void build(char *s) {     memset(nxt, 0, sizeof nxt), memset(link, 0, sizeof link),         memset(dp, 0, sizeof dp);     n = strlen(s), m = 0;     cur = ++m;     for (int i = 0; i < n; i++) extend(s[i] -  a );     memset(cnt, 0, sizeof cnt);     for (int i = 1; i <= m; i++) cnt[dp[i]]++;     for (int i = 1; i <= n; i++) cnt[i] += cnt[i - 1];     for (int i = m; i >= 1; i--) ord[cnt[dp[i]]--] = i;   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %s , s);       memset(occur, 0, sizeof occur);       build(s);       for (int i = m; i >= 1; i--) occur[link[ord[i]]] += occur[ord[i]];       long long ans = 0;       for (int i = 1; i <= m; i++)         ans += 1ll * occur[i] * occur[i] * (dp[i] - dp[link[i]]);       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e4;   long long F[maxN + 1];   void fact() {     F[0] = F[1] = 1;     for (int i = 2; i <= maxN; i++) F[i] = (1LL * F[i - 1] * i) % 998244353;   }   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) {         res = (1LL * res * a) % 998244353, b--;       } else {         a = (1LL * a * a) % 998244353, b >>= 1;       }     }     return res;   }   long long C(long long n, long long r) {     if (r > n) return 0;     long long res = F[n];     res = (1LL * res * power(F[r], 998244353 - 2)) % 998244353;     res = (1LL * res * power(F[n - r], 998244353 - 2)) % 998244353;     return res;   }   void solve() {     long long n, k;     cin >> n >> k;     string second;     cin >> second;     if (!k) {       cout <<  1 n ;       return;     }     long long ans = 1, l = 0, r = 0, cnt = 0;     while (r < n) {       if (second[r] ==  1 ) {         if (cnt == k) {           (ans += (C(r - l, k) - 1 + 998244353) % 998244353) %= 998244353;           while (l < n && second[l] !=  1 ) l++;           l++, cnt--;           ans = (ans - C(r - l, k - 1) + 1 + 998244353) % 998244353;         }         cnt++;       }       r++;     }     if (cnt == k) (ans += (C(r - l, k) - 1 + 998244353) % 998244353) %= 998244353;     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0), fact();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[250001];   int a, ans[250001], n, i, q, kol;   bool pole[250001];   void dfs(int nom) {     int i;     kol++;     pole[nom] = true;     for (i = 0; i < v[nom].size(); i++)       if (!pole[v[nom][i]]) dfs(v[nom][i]);     ans[nom] = kol;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> q;     while (q--) {       cin >> n;       for (i = 1; i <= n; i++) {         v[i].clear();         pole[i] = false;       }       for (i = 1; i <= n; i++) {         cin >> a;         v[i].push_back(a);       }       for (i = 1; i <= n; i++)         if (!pole[i]) {           kol = 0;           dfs(i);         }       for (i = 1; i <= n - 1; i++) cout << ans[i] <<    ;       cout << ans[n] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const long long INF = 1e18L + 7;   template <class n, class second>   ostream &operator<<(ostream &p, pair<n, second> x) {     return p <<  <  << x.first <<  ,   << x.second <<  > ;   }   template <class n>   auto operator<<(ostream &p, n y) ->       typename enable_if<!is_same<n, string>::value,                          decltype(y.begin(), p)>::type {     int o = 0;     p <<  { ;     for (auto c : y) {       if (o++) p <<  ,  ;       p << c;     }     return p <<  } ;   }   void dor() { cerr <<   n ; }   template <class n, class... second>   void dor(n p, second... y) {     cerr << p <<    ;     dor(y...);   }   template <class n, class second>   void mini(n &p, second y) {     if (p > y) p = y;   }   template <class n, class second>   void maxi(n &p, second y) {     if (p < y) p = y;   }   const int mod = 998244353;   const int N = 507;   int n, m;   int tab[N];   int dp[N][N][3];   int vis[N][N][3];   int pie[N];   int dru[N];   void solve(int a, int b, int t) {     if (vis[a][b][t]) return;     vis[a][b][t] = 1;     if (a > b) {       if (t == 2)         dp[a][b][t] = 1;       else         dp[a][b][t] = 0;       return;     }     int col = inf;     int ind = -1;     if (t == 2) {       for (int i = a; i <= b; ++i) {         if (col > tab[i]) {           col = tab[i];           ind = i;         }       }       solve(a, ind, 1);       solve(ind, b, 0);       dp[a][b][t] = (long long)dp[a][ind][1] * dp[ind][b][0] % mod;     } else if (t == 0) {       for (int i = a; i <= b; ++i) {         solve(a + 1, i, 2);         solve(i + 1, b, 2);         dp[a][b][t] += (long long)dp[a + 1][i][2] * dp[i + 1][b][2] % mod;         if (dp[a][b][t] >= mod) dp[a][b][t] -= mod;       }     } else if (t == 1) {       for (int i = a; i <= b; ++i) {         solve(a, i - 1, 2);         solve(i, b - 1, 2);         dp[a][b][t] += (long long)dp[a][i - 1][2] * dp[i][b - 1][2] % mod;         if (dp[a][b][t] >= mod) dp[a][b][t] -= mod;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> tab[i];     }     solve(1, n, 2);     cout << dp[1][n][2] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[3005], b[3005], df[3005];   long long F[3005][3005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       a[i] = a[i] - i;       b[i] = a[i];     }     sort(b + 1, b + n + 1);     int m = 0;     b[0] = b[1] - 1;     for (int i = 1; i <= n; ++i) {       if (b[i] > b[i - 1]) df[++m] = b[i];     }     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= m; ++j) {         F[i][j] = 1e18;       }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         F[i][j] = min(F[i][j - 1], F[i - 1][j] + abs(a[i] - df[j]));       }     }     long long rs = 1e18;     for (int i = 1; i <= m; ++i) rs = min(rs, F[n][i]);     cout << rs;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   const int LIM = 2e5 + 5, MOD = 1e9 + 7;   int t, n, m, k, x, y;   template <typename... T>   void read(T &...args) {     ((cin >> args), ...);   }   template <typename... T>   void print(T &&...args) {     ((cout << args <<    ), ...);   }   int main() {     int n;     read(n);     long long int arr[n];     for (int i = 0; i < n; i++) read(arr[i]);     sort(arr, arr + n);     long long int val = pow(arr[n - 1], 1.0 / (n - 1));     long long int a1 = 0, a2 = 0;     for (int i = 0; i < n; i++) {       a1 += abs(pow(val, i) - arr[i]);     }     val++;     for (int i = 0; i < n; i++) {       a2 += abs(pow(val, i) - arr[i]);     }     long long int curr = pow(val, n - 2), curr2 = pow(val, n - 1);     if (curr2 / curr == val)       cout << min(a1, a2) << endl;     else       cout << a1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct frac {     long long p, q;   } frac;   const double eps = 1e-8;   int n;   int nb[100100];   vector<int> G[100100];   bool col[100100];   int cur[100100];   int onstk[100100];   inline bool operator<(frac a, frac b) { return a.p * b.q < b.p * a.q; }   inline bool operator==(frac a, frac b) { return a.p * b.q == b.p * a.q; }   inline bool operator>(frac a, frac b) { return a.p * b.q > b.p * a.q; }   inline bool operator>=(frac a, double b) {     return ((double)a.p / (double)a.q) >= b;   }   inline bool operator!=(frac a, frac b) { return a.p * b.q != b.p * a.q; }   inline frac newfrac(long long a, long long b) {     frac x;     x.p = a;     x.q = b;     return x;   }   inline bool valid(double z, bool pr) {     priority_queue<pair<frac, int>, vector<pair<frac, int> >,                    greater<pair<frac, int> > >         S;     for (int i = (1); i <= (n); i++) {       cur[i] = 0;       onstk[i] = false;     }     for (int x = (1); x <= (n); x++) {       if (col[x]) {         for (int j = (0); j < (G[x].size()); j++) {           int y = G[x][j];           if (col[y]) {             cur[x]++;           }         }         S.push(make_pair(newfrac(cur[x], nb[x]), x));         onstk[x] = true;       }     }     bool ok = false;     while (!S.empty()) {       if (!onstk[S.top().second]) {         S.pop();         continue;       }       if (S.top().first >= z) {         ok = true;         break;       } else {         int x = S.top().second;         S.pop();         onstk[x] = false;         for (int j = (0); j < (G[x].size()); j++) {           int y = G[x][j];           if (onstk[y]) {             cur[y]--;             S.push(make_pair(newfrac(cur[y], nb[y]), y));           }         }       }     }     if (pr) {       int cnt = 0;       vector<int> V;       for (int i = (1); i <= (n); i++) {         if (onstk[i]) {           cnt++;           V.push_back(i);         }       }       printf( %d n , cnt);       for (int i = (0); i < (V.size()); i++) {         printf( %d , V[i]);         if (i < V.size() - 1) {           printf(   );         }       }       printf(  n );     }     return ok;   }   int main() {     int m, k, x, y;     scanf( %d%d%d , &n, &m, &k);     for (int i = (1); i <= (n); i++) {       nb[i] = 0;       col[i] = true;     }     for (int i = (1); i <= (k); i++) {       scanf( %d , &x);       col[x] = false;     }     for (int i = (1); i <= (m); i++) {       scanf( %d%d , &x, &y);       nb[x]++;       nb[y]++;       if ((col[y]) and (col[x])) {         G[x].push_back(y);         G[y].push_back(x);       }     }     double l = 0.0, r = 1.0;     while ((r - l) > eps) {       double mid = (l + r) / 2;       if (valid(mid, false)) {         l = mid;       } else {         r = mid;       }     }     col[0] = valid(l, true);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int n = 100002;   char h[n], h1[n];   int a[n];   bool check(int e, int r, int v1, int c1) {     int c, v, c2, v2;     while (e < r) {       for (c = 0; c < 10; c++)         for (v = 0; v < 10; v++)           if (c + v == v1 + h[r]) {             if ((c == 0) && (e == 0)) continue;             goto st;           }       if ((h[r] == 9) && (v1 == 10)) {         c = 9;         v = 0;         goto st;       }       return 0;     st:       h[r - 1] -= (c + v) / 10;       if (h[r - 1] < 0) {         for (c2 = r - 2; (c2 >= 0) && (h[c2 + 1] < 0); c2--) {           h[c2 + 1] += 10;           h[c2]--;         }         if (c2 < e - 1) return 0;       }       a[e] = c;       a[r] = v;       c += v;       v = v1 + h[e] - c;       if ((v != 0) && (v != 1)) return 0;       v1 = v * 10;       c1 = c / 10;       if (e == r - 1) {         if (v == 1) return 0;         return 1;       }       e++;       r--;     }     if (e > r) {       if ((v1 + c1 == 11) || (v1 + c1 == 0)) return 1;       return 0;     }     for (c = 0; c < 10; c++)       if (c + c == v1 + h[e]) break;     if (c == 10) return 0;     a[e] = c;     return 1;   }   int main() {     int q, w, e, r, t;     scanf( %s , h1);     q = strlen(h1);     for (w = 0; w < q; w++) h1[w] -= 48;     for (w = 0; w < q; w++) h[w] = h1[w];     if (check(0, q - 1, 0, 0)) {       for (w = 0; w < q; w++) printf( %d , a[w]);       return 0;     }     for (w = 0; w < q; w++) h[w] = h1[w];     if ((h[0] == 1) && (check(1, q - 1, 10, 0))) {       for (w = 1; w < q; w++) printf( %d , a[w]);       return 0;     }     printf( 0 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int A, B, C, D;   struct Point {     long long x, y;     Point(long long x, long long y) : x(x), y(y) {}   };   bool operator<(const Point& a, const Point& b) {     return a.x < b.x || (a.x == b.x && a.y > b.y);   }   int main() {     int n;     scanf( %d , &n);     scanf( %d/%d %d/%d , &A, &B, &C, &D);     vector<Point> P;     for (int i = 0; i < n; ++i) {       int u, v;       scanf( %d%d , &u, &v);       long long x = (long long)B * v - (long long)A * u;       long long y = (long long)C * u - (long long)D * v;       if (x > 0 && y > 0) {         P.emplace_back(Point(x, y));       }     }     sort(P.begin(), P.end());     vector<long long> len;     for (auto& it : P) {       int idx = lower_bound(len.begin(), len.end(), it.y) - len.begin();       if (idx == len.size()) {         len.emplace_back(it.y);       } else {         len[idx] = it.y;       }     }     printf( %d n , len.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[5000][5000];   int main() {     char a[5000], b[5000];     int ti, td, tr, te;     scanf( %d %d %d %d , &ti, &td, &tr, &te);     scanf( %s %s , a, b);     int n = strlen(a);     int m = strlen(b);     dp[0][0] = 0;     for (int i = 1; i <= n; i++) dp[i][0] = dp[i - 1][0] + td;     for (int i = 1; i <= m; i++) dp[0][i] = dp[0][i - 1] + ti;     int da[26];     int db;     memset(da, 0, sizeof(da));     int ii, jj, d;     for (int i = 1; i <= n; i++) {       db = 0;       for (int j = 1; j <= m; j++) {         d = (a[i - 1] == b[j - 1]) ? 0 : tr;         ii = da[b[j - 1] -  a ];         jj = db;         db = (a[i - 1] == b[j - 1]) ? j : db;         dp[i][j] =             min(dp[i][j - 1] + ti, min(dp[i - 1][j] + td, dp[i - 1][j - 1] + d));         if (ii > 0 && jj > 0)           dp[i][j] = min(dp[i][j], dp[ii - 1][jj - 1] + (i - ii - 1) * td +                                        (j - jj - 1) * ti + te);       }       da[a[i - 1] -  a ] = i;     }     printf( %d n , dp[n][m]);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct all {     int t, num;     char x, type;   } a[N];   bool cmp(all a, all b) { return a.t < b.t; }   int redhome[N], redaway[N];   int yellhome[N], yellaway[N];   string home, away;   int n;   int main() {     cin >> home >> away;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i].t >> a[i].x >> a[i].num >> a[i].type;     sort(a + 1, a + n + 1, &cmp);     for (int i = 1; i <= n; ++i) {       if (a[i].x ==  h ) {         if (a[i].type ==  r ) {           if (redhome[a[i].num] == 0) {             redhome[a[i].num] = a[i].t;             cout << home <<     << a[i].num <<     << a[i].t << endl;           }         } else {           if (yellhome[a[i].num] == 0)             yellhome[a[i].num] = a[i].t;           else if (redhome[a[i].num] == 0) {             redhome[a[i].num] = a[i].t;             cout << home <<     << a[i].num <<     << a[i].t << endl;           }         }       } else {         if (a[i].type ==  r ) {           if (redaway[a[i].num] == 0) {             redaway[a[i].num] = a[i].t;             cout << away <<     << a[i].num <<     << a[i].t << endl;           }         } else {           if (yellaway[a[i].num] == 0)             yellaway[a[i].num] = a[i].t;           else if (redaway[a[i].num] == 0) {             redaway[a[i].num] = a[i].t;             cout << away <<     << a[i].num <<     << a[i].t << endl;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p;     cin >> n >> p;     string s;     cin >> s;     bool f = 0;     int i = s.size() - 1;     if (i > 0) {       while (s[i] -  a  == p - 1) {         s[i] =  a ;         i--;       }       s[i]++;     }     if (s.size() == 2) i = s.size() - 1;     while (!f) {       if (i > 1 && s[i] != s[i - 1] && s[i] != s[i - 2])         if (i == s.size() - 1) {           f = 1;           break;         } else           i++;       else if (i > 1 && (s[i] == s[i - 1] || s[i] == s[i - 2])) {         if (s[i] -  a  < p - 1)           s[i]++;         else {           s[i] =  a ;           i--;           while (s[i] -  a  == p - 1 && i >= 0) {             s[i] =  a ;             i--;           }           if (i < 0) {             f = 0;             break;           }           if (i != 0) s[i]++;         }       } else if (i == 1 && s[i] != s[i - 1])         if (i == s.size() - 1) {           f = 1;           break;         } else           i++;       else if (i == 1 && s[i] == s[i - 1])         if (s[i] -  a  < p - 1)           s[i]++;         else {           s[i] =  a ;           i--;           if (s[i] -  a  == p - 1) {             f = 0;             break;           }         }       else if (i == 0) {         if (s[i] -  a  < p - 1) {           s[i]++;           i++;         } else {           f = 0;           break;         }         if (s.size() == 1) {           f = 1;           break;         }       }     }     if (f != 0)       cout << s << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   int euclid(int a, int b, int &x, int &y) {     if (!a) {       x = 0;       y = 1;       return b;     }     int _x, _y;     int g = euclid(b % a, a, _x, _y);     x = _y - b / a * _x;     y = _x;     return g;   }   void relax(int &obj, int C3, int C4, int C5, int _k3, int k4, int _k5, int &K3,              int &K4, int &K5) {     int f = abs(C3 * _k3 - C4 * k4) + abs(C4 * k4 - C5 * _k5);     if (f < obj) {       obj = f;       K3 = _k3, K4 = k4, K5 = _k5;     }   }   int main() {     int n, S, a[333];     cin >> n >> S;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int C[11] = {0};     for (int _n(n), i(0); i < _n; i++) C[a[i]]++;     int K3 = 1011111111, K4 = 1011111111, K5 = 1011111111, F = 1011111111;     int ek3 = 1011111111, ek5 = 1011111111;     const int D = euclid(C[3], C[5], ek3, ek5);     for (int k4 = 0; k4 * C[4] <= S; ++k4) {       const int REM = S - k4 * C[4];       if (REM % D) continue;       int k3 = ek3 * (REM / D), k5 = ek5 * (REM / D);       assert(k3 * C[3] + k5 * C[5] == REM);       int idx[] = {(k4 - k3 + C[5] / D - 1) / (C[5] / D),                    (k5 - k4 + C[3] / D - 1) / (C[3] / D),                    (k5 - k4 * C[4] + C[3] / D - 1) / (C[3] / D) + 4,                    (k4 * C[4] - k3 + C[5] / D - 1) / (C[5] / D) + 4};       for (int o = 0; o < 4; ++o) {         int j = idx[o];         for (int it = 0; it < 1055; --j, ++it) {           int _k3 = k3 + j * (C[5] / D);           int _k5 = k5 - j * (C[3] / D);           if (_k3 < 0) continue;           if (_k3 > k4) continue;           if (_k5 < k4) continue;           relax(F, C[3], C[4], C[5], _k3, k4, _k5, K3, K4, K5);         }       }     }     if (F == 1011111111) {       cout << -1 << endl;     } else {       printf( %d %d %d n , K3, K4, K5);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   struct custom_hash {     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return x + FIXED_RANDOM;     }   };   void solve() {     long long n;     cin >> n;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         cout << n / i <<     << n - (n / i) <<   n ;         return;       }     }     cout << 1 <<     << n - 1 <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 200 + 17, inf = 2e18 + 17;   long long a[MAXN], b[MAXN], n, m, k, t[MAXN][MAXN], np;   void fillA() {     for (int i = 1; i <= m; i++)       for (int j = 0; i - j > 0 && j < n; j++) a[i] = min(t[j + 1][i - j], a[i]);     for (int i = 1; i <= n; i++)       for (int j = 0; i + j <= n && j < m; j++)         a[i + m - 1] = min(a[i + m - 1], t[i + j][m - j]);   }   void fillBackT() {     for (int i = 1; i <= m; i++)       for (int j = 0; i - j > 0 && j < n; j++) t[j + 1][i - j] = a[i];     for (int i = 1; i <= n; i++)       for (int j = 0; i + j <= n && j < m; j++) t[i + j][m - j] = a[i + m - 1];   }   long long count(int x) {     a[x] = 0;     long long dp[MAXN][MAXN] = {};     if (a[1] == 1)       dp[1][1] = 0;     else       dp[1][1] = 1;     for (int i = 2; i <= np; i++)       for (int j = 0; j <= np; j++) {         if (a[i] == 1)           dp[i][j] = dp[i - 1][j + 1];         else if (a[i] == 0)           dp[i][j] = (j > 0 ? dp[i - 1][j - 1] : 0);         else           dp[i][j] =               min(inf, (dp[i - 1][j + 1] + (j > 0 ? dp[i - 1][j - 1] : 0)));       }     return dp[np][0];   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> t[i][j];     fill(a, a + MAXN, inf);     fillA();     np = n + m - 1;     iota(b + 1, b + np + 1, 1);     sort(b + 1, b + np + 1, [](int i, int j) { return a[i] < a[j]; });     for (int i = 1; i <= np; i++) {       long long tmp = count(b[i]);       if (tmp >= k)         a[b[i]] = 0;       else {         a[b[i]] = 1;         k -= tmp;       }     }     fillBackT();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cout << (t[i][j] ?  )  :  ( );       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int high = 2e5 + 6;   long long cnt[200005], dif[200005];   int main() {     long long n, m, k, i, j, ans, l, r, d, sum = 0, q;     scanf( %lld%lld%lld , &n, &k, &q);     for (i = 0; i < n; i++) {       scanf( %lld%lld , &l, &r);       dif[l]++;       dif[r + 1]--;     }     for (i = 1; i <= high; i++) {       dif[i] += dif[i - 1];     }     for (i = 1; i <= high; i++) {       if (dif[i] >= k) {         cnt[i] = 1;       }     }     for (i = 1; i <= high; i++) {       cnt[i] += cnt[i - 1];     }     while (q--) {       scanf( %lld%lld , &l, &r);       printf( %lld n , cnt[r] - cnt[l - 1]);     }   }
#include <bits/stdc++.h>   const long long int MOD = 1000000007ll;   const int mxsz = 200005;   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     long long int n, m, a;     cin >> n >> m >> a;     int ar1[n + 1], ar2[m + 1];     for (int i = 1; i <= n; i++) {       cin >> ar1[i];     }     for (int i = 1; i <= m; i++) {       cin >> ar2[i];     }     sort(ar1 + 1, ar1 + n + 1);     sort(ar2 + 1, ar2 + m + 1);     vector<long long int> b, p;     for (int i = 1; i <= min(n, m); i++) {       b.push_back(ar1[n - i + 1]);       p.push_back(ar2[i]);     }     int l = 0, r = min(n, m);     int ans = 0;     while (l <= r) {       int mid = (l + r) / 2;       long long int tmp = a;       for (int i = 0; i < mid; i++) {         tmp -= (long long int)max(0LL, p[mid - i - 1] - b[i]);         if (tmp < 0) {           break;         }       }       if (tmp >= 0) {         l = mid + 1;         ans = mid;       } else {         r = mid - 1;       }     }     cout << ans <<    ;     long long int tmp = 0;     for (int i = 0; i < ans; i++) {       tmp += (long long int)p[i];     }     cout << max(0LL, tmp - a);     return 0;   }