malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int SIZE = 1e6 + 5;   const long long INF = 1LL << 55;   const double eps = 1e-10;   long long expo(long long a, long long b) {     if (b == 0) return 1;     long long h = expo(a, b / 2);     h = (h * h) % MOD;     if (b % 2) h = (h * a) % MOD;     return h;   }   long long f[100009];   long long ivf[100009];   long long C(long long a, long long b) {     return (((f[a] * ivf[b]) % MOD) * ivf[a - b]) % MOD;   }   char s[100009];   long long dp[100009];   int main() {     f[0] = ivf[0] = 1;     for (int i = (1); i < (100009); ++i) {       f[i] = (f[i - 1] * i) % MOD;       ivf[i] = expo(f[i], MOD - 2);     }     int n, k;     scanf( %d%d , &n, &k);     scanf( %s , (s));     for (int j = (1); j < (n + 1); ++j) {       if (n - j - 1 < k - 1)         dp[j] = dp[j - 1];       else         dp[j] = (dp[j - 1] + expo(10, j - 1) * C(n - j - 1, k - 1)) % MOD;     }     long long ans = 0;     for (int i = 0; i < (n); ++i) {       ans = (ans + (long long)(s[i] -  0 ) * dp[n - i - 1]) % MOD;       if (i >= k && n - i - 1 >= 0)         ans = (ans +                (long long)(s[i] -  0 ) * (expo(10, n - i - 1) * C(i, k)) % MOD) %               MOD;     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   template <typename T>   void chkmax(T &x, T y) {     x = max(x, y);   }   template <typename T>   void chkmin(T &x, T y) {     x = min(x, y);   }   template <typename T>   void read(T &x) {     x = 0;     int f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -f;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= f;   }   int ans, dp[MAXN][2], sum[MAXN][2];   vector<int> a[MAXN];   void update(int pos) {     dp[pos][0] = sum[pos][1] + 1;     dp[pos][1] = sum[pos][0];   }   void getdp(int pos, int fa) {     for (auto x : a[pos])       if (x != fa) {         getdp(x, pos);         sum[pos][0] += dp[x][0];         sum[pos][1] += dp[x][1];       }     update(pos);   }   void getans(int pos, int fa) {     chkmin(ans, dp[pos][0] - 1);     for (auto x : a[pos])       if (x != fa) {         sum[pos][0] -= dp[x][0];         sum[pos][1] -= dp[x][1];         update(pos);         sum[x][0] += dp[pos][0];         sum[x][1] += dp[pos][1];         update(x);         getans(x, pos);         sum[x][0] -= dp[pos][0];         sum[x][1] -= dp[pos][1];         update(x);         sum[pos][0] += dp[x][0];         sum[pos][1] += dp[x][1];         update(pos);       }   }   int main() {     int n;     read(n);     for (int i = 1; i <= n - 1; i++) {       int x, y;       read(x), read(y);       a[x].push_back(y);       a[y].push_back(x);     }     ans = n + 1;     getdp(1, 0);     getans(1, 0);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 1;   int f[MAXN];   int s[MAXN];   int e[MAXN];   int main() {     string S;     cin >> S;     int maxi = 0;     int len = 0;     int start = 0;     stack<int> st;     f[0] = 1;     s[0] = -1;     e[0] = -1;     for (int i = 0; i < S.length(); i++) {       if (S[i] ==  ( ) {         st.push(i);       } else if (st.empty()) {         e[i] = s[i] = -1;       } else {         start = st.top();         st.pop();         s[i] = e[i] = start;         start--;         if (start >= 0 && S[start] ==  )  && s[start] >= 0 && e[start] >= 0) {           e[i] = e[start];         }         len = i - e[i] + 1;         f[len]++;         maxi = max(maxi, len);       }     }     cout << maxi <<     << f[maxi] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100, yzh = 1e9 + 7;   void read(int &x) {     char ch;     bool flag = 0;     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch ==  - )) || 1);          ch = getchar())       ;     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())       ;     x *= 1 - 2 * flag;   }   void print(long long x) {     if (x > 9) print(x / 10);     putchar(x % 10 + 48);   }   void write(long long x) {     if (x < 0) putchar( - );     print(((x) < 0 ? (-(x)) : (x)));   }   int n, x, g[N + 5];   int f[N + 5][N + 5][N + 5];   char ch[N + 5];   int quick_pow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1ll * ans * a % yzh;       b >>= 1, a = 1ll * a * a % yzh;     }     return ans;   }   void work() {     read(n), read(x);     scanf( %s , ch + 1);     g[0] = g[1] = 1;     for (int i = 2; i <= x; i++) g[i] = (g[i - 1] + g[i - 2]) % (yzh - 1);     for (int i = 0; i <= x; i++) g[i] = quick_pow(2, g[i]);     for (int i = 1; i <= n; i++)       if (ch[i] ==  0 )         f[i][i][0] = 1;       else         f[i][i][1] = 1;     for (int i = 2; i <= x; i++) {       for (int l = 1; l <= n; l++)         for (int r = l; r <= n; r++) {           if (r == n)             (f[l][r][i] += 1ll * f[l][r][i - 1] * g[i - 2] % yzh) %= yzh;           else             (f[l][r][i] += f[l][r][i - 1]) %= yzh;           if (l == 1)             (f[l][r][i] += 1ll * f[l][r][i - 2] * g[i - 1] % yzh) %= yzh;           else             (f[l][r][i] += f[l][r][i - 2]) %= yzh;           for (int k = l; k < r; k++)             (f[l][r][i] += 1ll * f[l][k][i - 1] * f[k + 1][r][i - 2] % yzh) %=                 yzh;         }     }     (write(f[1][n][x]), putchar(  n ));   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int mod = (int)1e9 + 7;   int sum(int a, int b) {     int s = a + b;     if (s >= mod) s -= mod;     return s;   }   int mult(int a, int b) { return (1LL * a * b) % mod; }   int pw(int a, int b) {     if (b == 0) return 1;     if (b & 1) return mult(a, pw(a, b - 1));     int res = pw(a, b / 2);     return mult(res, res);   }   const int maxN = (int)1e5 + 100;   int dp[maxN];   int calc(int x) {     dp[0] = 2;     dp[1] = 2;     for (int i = 2; i <= x; i++) {       dp[i] = 0;       dp[i] = sum(dp[i], dp[i - 1]);       dp[i] = sum(dp[i], dp[i - 2]);     }     return dp[x];   }   int n, m;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m;     int f1 = calc(n);     int f2 = calc(m);     int ans = sum(f1, f2);     ans -= 2;     if (ans < 0) ans += mod;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000;   const long long LINF = (long long)INF * INF;   const int MAX = 2e5;   const double EPS = 1e-9;   const double PI = acos(-1.);   int n, m, k;   vector<pair<int, long long> > g[300005];   set<pair<pair<int, int>, int> > elist;   set<int> ans;   int siz[300005];   namespace D {   vector<long long> d;   vector<pair<long long, long long> > p;   void go() {     d.resize(n, LINF);     p.resize(n);     d[0] = 0;     priority_queue<pair<long long, long long> > q;     q.push(make_pair(0LL, 0LL));     while (!q.empty()) {       long long v = q.top().second, cur_d = -q.top().first;       q.pop();       if (cur_d > d[v]) continue;       for (size_t j = 0; j < g[v].size(); ++j) {         long long to = g[v][j].first, len = g[v][j].second;         if (d[v] + len < d[to]) {           d[to] = d[v] + len;           p[to] = make_pair(v, len);           q.push(make_pair(-d[to], to));         }       }     }   }   }  // namespace D   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> k;     for (int i = (0); i < (m); ++i) {       int x, y, z;       cin >> x >> y >> z;       x--;       y--;       g[x].push_back(make_pair(y, z));       g[y].push_back(make_pair(x, z));       if (x > y) swap(x, y);       elist.insert(make_pair(make_pair(x, y), i + 1));     }     D::go();     for (int i = (0); i < (n); ++i) {       g[i].clear();     }     for (int i = (1); i < (n); ++i) {       int u = D::p[i].first;       int v = i;       int w = D::p[i].second;       g[u].push_back(make_pair(v, w));       g[v].push_back(make_pair(u, w));       if (u > v) swap(u, v);       int id = elist.lower_bound(make_pair(make_pair(u, v), -1))->second;       ans.insert(id);     }     if (k == 0) {       cout << 0;       return 0;     }     set<int> foo;     for (int i = (0); i < (n); ++i) {       siz[i] = (int)g[i].size();       if ((int)g[i].size() == 1) {         foo.insert(i);       }     }     int cur = n - 1;     while (cur > k) {       int u = *foo.begin();       foo.erase(foo.begin());       if (u == 0) continue;       siz[u] = -1;       for (int i = (0); i < ((int)g[u].size()); ++i) {         int v = g[u][i].first;         if (siz[v] == 2) {           if (v) foo.insert(v);         }         if (siz[v] != -1) {           siz[v]--;           int x = u;           int y = v;           if (x > y) swap(x, y);           int id = elist.lower_bound(make_pair(make_pair(x, y), -1))->second;           ans.erase(id);         }       }       cur--;     }     cout << ans.size() << endl;     for (auto& iter : ans) {       cout << iter <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char ch = getchar();     long long p = 1, data = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) p = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       data = data * 10 + (ch ^ 48);       ch = getchar();     }     return p * data;   }   inline long long qpow(long long a, long long b) {     long long r = 1;     while (b) {       if (b & 1) r = a * r;       a = a * a;       b >>= 1;     }     return r;   }   inline long long gcd(long long a, long long b) {     if (!a || !b) return (!a) ? b : a;     while (b ^= a ^= b ^= a %= b)       ;     return a;   }   inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   void exgcd(long long a, long long b, long long &x, long long &y) {     if (!b)       x = 1, y = 0;     else {       exgcd(b, a % b, y, x);       y -= x * (a / b);     }   }   const int mod = 1e9 + 7;   int main() {     int n = read();     long long a[2] = {0, 0};     for (int i = 1; i <= n; i++) {       long long x = read();       a[i & 1] += x / 2 + x % 2;       a[1 - i & 1] += x / 2;     }     printf( %lld n , min(a[0], a[1]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int to, next, v;   } e[2005 * 105];   int head[2005], tot, n;   void add(int x, int y, int v) {     e[++tot] = (edge){y, head[x], v};     head[x] = tot;   }   struct Graph {     int S, sz;     bool vis[2005];     long long dis[2005], b[2005];     void work() {       for (int i = 1; i <= n; i++)         if (i != S) dis[i] = (1ll << 62);       for (int i = 1; i <= n; i++) {         int k = 0;         for (int j = 1; j <= n; j++)           if (!vis[j] && (!k || dis[j] < dis[k])) k = j;         vis[k] = 1;         for (int j = head[k]; j; j = e[j].next)           dis[e[j].to] = min(dis[e[j].to], dis[k] + e[j].v);       }       memcpy(b, dis, sizeof(b));       sort(b + 1, b + n + 1);       sz = unique(b + 1, b + n + 1) - b - 1;       for (int i = 1; i <= n; i++)         dis[i] = lower_bound(b + 1, b + sz + 1, dis[i]) - b;     }   } G[2];   int sz[2005][2005];   long long sum[2005][2005];   long long f[2005][2005][2][2];   bool vis[2005][2005][2][2];   int SZ(int x, int y, int X, int Y) { return sz[x][y] - sz[X][Y]; }   long long SUM(int x, int y, int X, int Y) { return sum[x][y] - sum[X][Y]; }   long long DP(int x, int y, int who, int can) {     if (x > G[0].sz || y > G[1].sz) return 0;     if (vis[x][y][who][can]) return f[x][y][who][can];     vis[x][y][who][can] = 1;     long long ans;     if (who)       ans = DP(x, y + 1, who, can || SZ(x, y, x, y + 1)) + SUM(x, y, x, y + 1);     else       ans = DP(x + 1, y, who, can || SZ(x, y, x + 1, y)) + SUM(x, y, x + 1, y);     if (can) ans = max(ans, -DP(x, y, who ^ 1, 0));     return f[x][y][who][can] = ans;   }   int m, v[2005];   int main() {     scanf( %d%d%d%d , &n, &m, &G[0].S, &G[1].S);     for (int i = 1; i <= n; i++) scanf( %d , &v[i]);     for (int i = 1; i <= m; i++) {       int x, y, v;       scanf( %d%d%d , &x, &y, &v);       add(x, y, v);       add(y, x, v);     }     G[0].work();     G[1].work();     for (int i = 1; i <= n; i++) {       sz[G[0].dis[i]][G[1].dis[i]]++;       sum[G[0].dis[i]][G[1].dis[i]] += v[i];     }     for (int i = G[0].sz; i; i--)       for (int j = G[1].sz; j; j--) {         sz[i][j] += sz[i][j + 1] + sz[i + 1][j] - sz[i + 1][j + 1];         sum[i][j] += sum[i][j + 1] + sum[i + 1][j] - sum[i + 1][j + 1];       }     long long ans = DP(1, 1, 0, 0);     if (ans == 0)       puts( Flowers );     else if (ans < 0)       puts( Cry );     else       puts( Break a heart );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int a, b, i, cnt, x;     cin >> a >> b;     if (a < b) {       cout <<  0 n ;       return 0;     }     if (a == b) {       cout <<  infinity n ;       return 0;     }     a = a - b;     cnt = 0;     for (i = 1; i <= sqrt(a); i++) {       if (a % i == 0) {         x = a / i;         if (x == i) {           if (i > b) cnt++;         } else {           if (i > b) cnt++;           if (x > b) cnt++;         }       }     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ansp[200001];   int main() {     long long k;     memset(ansp, 0, sizeof(ansp));     scanf( %lld , &k);     char s[200001], t[200001], ans[200001];     scanf( %s %s , s, t);     long long add = 0, dec = 0, again = 0;     long long i, j;     for (i = 0; i < k; i++) {       long long x = s[i] -  a , y = t[i] -  a  + add;       add = 0;       if ((x + y) % 2 != 0) {         add = 26;         y--;       }       long long now = (x + y) / 2;       ansp[i] = now;     }     for (i = k - 1; i >= 0; i--) {       ansp[i - 1] += ansp[i] / 26;       ansp[i] %= 26;     }     for (i = 0; i < k; i++) printf( %c , (char)(ansp[i] +  a ));   }
#include <bits/stdc++.h>   using namespace std;   int bit(int mask, int n) { return mask & (1 << n) ? 1 : 0; }   int rev(int a) {     int res = 0;     for (int i = 0; i < 8; ++i) res = res | ((1 << (7 - i)) * bit(a, i));     return res;   }   int main() {     string s;     int prev = 0;     getline(cin, s);     for (int i = 0; i < s.length(); ++i) {       int cur = (256 + prev - rev(s[i])) % 256;       cout << cur << endl;       prev = rev(s[i]);     }     cin >> s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a[100010], ans;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   inline long long cal(long long a) {     if (a % 2 == 0) return 0;     long long tmp = 0;     for (int i = 0; (a << i) < m; i++) {       tmp += m - (a << i);     }     return tmp;   }   int main() {     scanf( %d%d , &n, &m);     long long d = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i)         d = gcd(d, a[i] - 1);       else         d = a[i] - 1;     }     for (int i = 1; i * i <= d; i++) {       if (d % i == 0) {         ans += cal(i);         if (i * i != d) ans += cal(d / i);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(int x, int y) { return x > y; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     cin >> t;     long long m, n, k;     string a, b;     while (t--) {       cin >> n;       vector<long long> vec(n);       for (long long i = 0; i < n; i++) cin >> vec[i];       map<long long, long long> mp;       for (long long i = 0; i < n; i++) {         long long k = (long long)(log2(vec[i]));         mp[k] += 1;       }       map<long long, long long>::iterator it = mp.begin();       long long ans = 0;       while (it != mp.end()) {         ans += ((it->second) * (it->second - 1)) / 2;         ++it;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long ans = 0, fl = 0;     if (a != c && b != d)       ans = abs(a - c) + abs(b - d) + 2;     else       ans = abs(a - c) + abs(b - d);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) solve();     return 0;     ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int N;     cin >> N;     int arr[N], grr[100006] = {0}, fre[100005] = {0}, x, ma = 0, ans = 0;     for (int i = 0; i < N; i++) {       bool ok = false;       cin >> x;       grr[fre[x]]--;       fre[x]++;       grr[fre[x]]++;       ma = max(ma, fre[x]);       if (grr[1] == i + 1)         ok = true;       else if (grr[i + 1] == 1)         ok = true;       else if (grr[ma - 1] * (ma - 1) == i + 1 - ma && grr[ma] == 1)         ok = true;       else if (grr[1] == 1 && grr[ma] * (ma) == i)         ok = true;       if (ok) ans = i + 1;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int SIZE = 2e6 + 10;   int a[SIZE];   int num[SIZE], nxt[SIZE];   int main() {     int n, q;     scanf( %d%d , &n, &q);     long long sum = 0;     for (int i = 0; i < (n); ++i) {       scanf( %d , &(a[i]));       sum += a[i];       a[i + n] = a[i];     }     for (int tt = 1; tt <= q; tt++) {       long long b;       scanf( %I64d , &b);       if (b >= sum) {         puts( 1 );         continue;       }       {         int rr = -1;         long long now = 0;         for (int i = 0; i < (n); ++i) {           while (now + a[rr + 1] <= b) now += a[++rr];           nxt[i] = rr + 1;           nxt[i + n] = rr + 1 + n;           num[i] = 1;           now -= a[i];         }       }       int an = n;       for (int i = n - 1; i >= 0; i--) {         if (nxt[i] < n) {           num[i] += num[nxt[i]];           nxt[i] = nxt[nxt[i]];         }         if (nxt[i] >= i + n) an = min(an, num[i]);       }       printf( %d n , an);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b) {     return ((a % 1000000007) * (b % 1000000007)) % 1000000007;   }   long long power(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long temp = power(a, b / 2);     if (b % 2 == 0)       return mul(temp, temp);     else       return mul(mul(temp, temp), a);   }   vector<long long> g[100005];   long long color[100005];   long long curr_color, ok;   void dfs(long long node, long long par) {     ok = ok && (color[node] == curr_color);     for (long long i = 0; i < g[node].size(); i++) {       if (g[node][i] != par) {         dfs(g[node][i], node);       }     }   }   long long solve(long long node) {     long long ans = 1;     ok = 1;     for (long long i = 0; i < g[node].size(); i++) {       curr_color = color[g[node][i]];       dfs(g[node][i], node);       ans = ans && ok;     }     return ans;   }   int main() {     long long n, i, x, a, b;     cin >> n;     for (i = 0; i < n - 1; i++) {       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     for (i = 0; i < n; i++) cin >> color[i + 1];     long long root1 = -1, root2 = -1;     for (i = 1; i <= n; i++) {       for (long long j = 0; j < g[i].size(); j++) {         if (color[i] != color[g[i][j]]) {           root1 = i;           root2 = g[i][j];         }       }     }     if (root1 == -1) {       cout <<  YES  << endl;       cout << 1 << endl;       return 0;     }     if (solve(root1)) {       cout <<  YES  << endl;       cout << root1 << endl;       return 0;     }     if (solve(root2)) {       cout <<  YES  << endl;       cout << root2 << endl;       return 0;     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[105];   int dp[105][55];   int f[55];   int n, k;   void dfs(int u, int fa) {     dp[u][0] = 1;     dp[u][k + 1] = 1;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == fa) continue;       dfs(v, u);       memset(f, 0, sizeof(f));       for (int j = 0; j <= 2 * k; j++)         for (int p = 0; p <= 2 * k; p++) {           if (j + p <= 2 * k) {             f[min(p + 1, j)] += (1LL * dp[u][j] * dp[v][p]) % 1000000007;             f[min(p + 1, j)] %= 1000000007;           } else {             f[max(p + 1, j)] += (1LL * dp[u][j] * dp[v][p]) % 1000000007;             f[max(p + 1, j)] %= 1000000007;           }         }       for (int j = 0; j <= 2 * k; j++) dp[u][j] = f[j];     }   }   int main() {     cin >> n >> k;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1, 1);     int ans = 0;     for (int i = 0; i <= k; i++) {       ans = (ans + dp[1][i]) % 1000000007;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt;   char c[11];   int main() {     scanf( %d %s , &n, c + 1);     if (n == 6)       printf( espeon n );     else if (n == 8)       printf( vaporeon n );     else if (c[1] ==  j  || c[2] ==  o  || c[4] ==  t )       printf( jolteon n );     else if (c[1] ==  u  || c[2] ==  m  || c[3] ==  b )       printf( umbreon n );     else if (c[1] ==  l  || c[2] ==  e  || c[4] ==  f )       printf( leafeon n );     else if (c[1] ==  s  || c[2] ==  y  || c[4] ==  v )       printf( sylveon n );     else if (c[1] ==  f  || c[4] ==  r )       printf( flareon n );     else       printf( glaceon n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     const int n = s.length() + 5;     int arr[n];     memset(arr, 0, sizeof arr);     int m, l, r;     for (int i = 0; i < s.length(); i++) {       if (s[i] == s[i + 1]) {         arr[i + 2]++;       }       arr[i + 1] += arr[i];     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> l >> r;       cout << arr[r] - arr[l] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int dp[110][10100];   bool f[110][10100] = {false};   int main() {     int m, n, x, y, i, j, k, a[1111];     pair<int, int> pii[101];     cin >> n;     for (i = 0; i < n; i++) cin >> pii[i].second >> pii[i].first;     sort(pii, pii + n);     for (i = 0; i <= n; i++)       for (j = 0; j <= 10000; j++) dp[i][j] = 555555;     reverse(pii, pii + n);     f[0][0] = true;     dp[0][0] = 0;     int t = 0;     for (i = 0; i < n; i++) {       x = pii[i].first;       y = pii[i].second;       for (j = t; j >= 0; j--) {         dp[i + 1][j + y] = min(dp[i + 1][j + y], dp[i][j] + y);         if (dp[i][j] >= x) {           f[i + 1][j - x] = true;           dp[i + 1][j - x] = min(dp[i + 1][j - x], dp[i][j]);         }       }       t += y;     }     int ans = 5555555;     for (i = 0; i <= t; i++) ans = min(ans, dp[n][i]);     cout << ans;   }