malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!(ch >=  0  && ch <=  9 )) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * f;   }   void chkmin(int &a, int b) {     if (b < a) a = b;   }   const int N = 81;   const int INF = 88888888;   int n;   int dp[N][N][N][3];   char s[N];   vector<int> V, K, O;   int calc(int pos, int a, int b, int c) {     int ret = 0;     for (int i = 1; i <= pos - 1; i++) {       if (s[i] ==  V ) {         if (a)           a--;         else           ++ret;       }       if (s[i] ==  K ) {         if (b)           b--;         else           ++ret;       }       if (s[i] !=  V  && s[i] !=  K ) {         if (c)           c--;         else           ++ret;       }     }     return ret;   }   int main() {     n = read();     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) {       if (s[i] ==  V )         V.push_back(i);       else if (s[i] ==  K )         K.push_back(i);       else         O.push_back(i);     }     for (int a = 0; a <= n; a++)       for (int b = 0; b <= n; b++)         for (int c = 0; c <= n; c++)           for (int d = 0; d <= 1; d++) dp[a][b][c][d] = INF;     dp[0][0][0][0] = 0;     for (int a = 0; a <= V.size(); a++) {       for (int b = 0; b <= K.size(); b++) {         for (int c = 0; c <= O.size(); c++) {           for (int flag = 0; flag <= 1; flag++) {             if (a < V.size())               chkmin(dp[a + 1][b][c][1], dp[a][b][c][flag] + calc(V[a], a, b, c));             if (b < K.size() && !flag)               chkmin(dp[a][b + 1][c][0], dp[a][b][c][flag] + calc(K[b], a, b, c));             if (c < O.size())               chkmin(dp[a][b][c + 1][0], dp[a][b][c][flag] + calc(O[c], a, b, c));           }         }       }     }     printf( %d n , min(dp[V.size()][K.size()][O.size()][0],                        dp[V.size()][K.size()][O.size()][1]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t;     cin >> t;     while (t--) {       int n, a[100005];       cin >> n;       for (int i = 0; i < n; ++i) cin >> a[i];       int MIN = INT_MAX, MAX = -100;       for (int i = 0; i < n; ++i) {         if (a[i] != -1 &&             ((i > 0 && a[i - 1] == -1) || (i < n - 1 && a[i + 1] == -1))) {           MIN = min(MIN, a[i]);           MAX = max(MAX, a[i]);         }       }       if (MIN == INT_MAX && MAX == -100)         cout << 0 <<     << 0;       else {         int ans = (MAX + MIN) / 2, d = 0;         for (int i = 0; i < n - 1; ++i) {           if (a[i] == -1 && a[i + 1] != -1)             d = max(d, abs(ans - a[i + 1]));           else if (a[i] != -1 && a[i + 1] != -1)             d = max(d, abs(a[i] - a[i + 1]));           else if (a[i] != -1 && a[i + 1] == -1)             d = max(d, abs(a[i] - ans));         }         cout << d <<     << ans;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double sqr(double x) { return x * x; }   double distsqr(double x, double y, double a, double b) {     return sqr((x - a)) + sqr((y - b));   }   double cosine_angle(double a, double b, double c) {     return (double)(sqr(a) + sqr(b) - sqr(c)) / ((double)2.0 * a * b);   }   template <class T>   T Maximum(T a, T b) {     return a > b ? a : b;   }   template <class T>   T Minimum(T a, T b) {     return a < b ? a : b;   }   template <class T>   T GCD(T a, T b) {     if (!b) return a;     return GCD(b, a % b);   }   template <class T>   void SWAP(T &a, T &b) {     T temp = a;     a = b;     b = temp;     return;   }   template <class T>   T BigMod(T a, T n, T mod) {     if (!n) return (T)1 % mod;     long long int power = BigMod(a, n >> 1, mod);     power %= mod;     power *= power;     power %= mod;     if (n & 1) power *= a % mod, power %= mod;     return power;   }   template <class T>   T ExtendedEuclid(T a, T b, T c) {     if (!a) return 0;     return (b * ExtendedEuclid(b % a, a, -c) + c) / a;   }   template <class T>   T ModInverse(T a, T m) {     return ((ExtendedEuclid(a, m, (T)GCD(a, m))) % (m) + (m)) % (m);   }   long long int valk[100010], valk_1[100010], cval[100010];   void Processsing(int n, int k) {     int i;     long long int power, temp;     if (k > 0) valk_1[k - 1] = 1;     for (i = k, power = 1; i < n; i++) {       if (i == k)         valk[i] = 1;       else {         valk[i] = valk[i - 1] * i;         valk[i] %= 1000000007;         valk[i] *= ModInverse((long long int)(i - k), (long long int)1000000007);         valk[i] %= 1000000007;       }       valk_1[i] = valk_1[i - 1] * i;       valk_1[i] %= 1000000007;       valk_1[i] *=           ModInverse((long long int)(i - k + 1), (long long int)1000000007);       valk_1[i] %= 1000000007;     }     for (i = 0; i < n - k; i++) {       if (i)         power *= 10;       else         power = 1;       power %= 1000000007;       temp = valk_1[n - 2 - i] * power;       temp %= 1000000007;       if (i)         cval[i] = cval[i - 1] + temp;       else         cval[i] = temp;       cval[i] %= 1000000007;     }   }   int main() {     int i, n, k;     char c;     long long int counts, temp;     scanf( %d %d , &n, &k);     Processsing(n, k);     for (i = counts = 0; i < n; i++) {       scanf(  %c , &c);       c -=  0 ;       if (i < k)         counts += cval[n - k - 1] * (int)c;       else {         temp = cval[n - 2 - i] + valk[i] * BigMod((long long int)10,                                                   (long long int)(n - 1 - i),                                                   (long long int)1000000007);         temp %= 1000000007;         temp *= (int)c;         temp %= 1000000007;         counts += temp;       }       counts %= 1000000007;     }     printf( %I64d n , counts);     return 0;   }
#include <bits/stdc++.h>   template <typename T>   extern inline void SWAP(T &a, T &b) {     T t = a;     a = b, b = t;   }   const int MAXN = 500005;   const int MAXBIT = 20;   const int MEMBIT = MAXBIT + 5;   int bas[MEMBIT], pos[MEMBIT], n, rt, a[MAXN], q;   struct quest {     int lt, rt, id;     bool operator<(const quest &tmp) const { return rt < tmp.rt; }   } Q[MAXN];   void insert(int x, int id) {     for (register int i = (MAXBIT); i >= (0); --i) {       if (x & (1 << i)) {         if (!bas[i]) {           bas[i] = x, pos[i] = id;           return;         }         if (pos[i] < id) SWAP(pos[i], id), SWAP(x, bas[i]);         x ^= bas[i];       }     }   }   int work(int lt) {     int ans = 0;     for (register int i = (MAXBIT); i >= (0); --i)       if (pos[i] >= lt && ans < (ans ^ bas[i])) ans ^= bas[i];     return ans;   }   int ans[MAXN];   int main() {     scanf( %d , &n);     for (register int i = (1); i <= (n); ++i) scanf( %d , &a[i]);     scanf( %d , &q);     for (register int i = (1); i <= (q); ++i)       scanf( %d%d , &Q[i].lt, &Q[i].rt), Q[i].id = i;     std::sort(Q + 1, Q + 1 + q);     for (register int i = (1); i <= (q); ++i) {       while (rt < Q[i].rt) {         ++rt;         insert(a[rt], rt);       }       ans[Q[i].id] = work(Q[i].lt);     }     for (register int i = (1); i <= (q); ++i) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<string> s(n);     for (int i = 0; i < n; ++i) cin >> s[i];     int answer = 0;     for (int col = 0; col < (int)s[0].size(); ++col) {       bool is_sorted = true;       for (int i = 0; i < n - 1; ++i) {         if (s[i].substr(0, col + 1) > s[i + 1].substr(0, col + 1)) {           is_sorted = false;         }       }       if (!is_sorted) {         ++answer;         for (int i = 0; i < n; ++i) {           string new_string;           for (int j = 0; j < (int)s[i].size(); ++j) {             if (j != col) {               new_string += s[i][j];             }           }           s[i] = new_string;         }         --col;       }     }     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v(n + 1, 0);     vector<vector<int> > g(n + 1);     int i, j, k;     for (i = 1; i <= n; i++) {       cin >> j >> k;       v[i] = k;       if (j != -1) {         g[j].push_back(i);       }     }     vector<int> ans;     for (i = 1; i <= n; i++) {       if (v[i] == 1) {         int kk = 1;         for (j = 0; j < g[i].size(); j++) {           if (v[g[i][j]] == 0) kk = 0;         }         if (kk) ans.push_back(i);       }     }     sort(ans.begin(), ans.end());     for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     if (ans.size() == 0) cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   int n, t;   int main() {     cin >> n >> t;     if (n == 1 && t == 10) {       cout << -1;       return 0;     }     if (t == 2) {       for (int i = 0; i < n - 1; i++) {         cout << 9;       }       cout << 2;       return 0;     }     if (t == 3) {       for (int i = 0; i < n - 1; i++) {         cout << 9;       }       cout << 3;       return 0;     }     if (t == 4) {       for (int i = 0; i < n - 1; i++) {         cout << 4;       }       cout << 4;       return 0;     }     if (t == 5) {       for (int i = 0; i < n - 1; i++) {         cout << 9;       }       cout << 5;       return 0;     }     if (t == 6) {       for (int i = 0; i < n - 1; i++) {         cout << 9;       }       cout << 6;       return 0;     }     if (t == 7) {       for (int i = 0; i < n - 1; i++) {         cout << 7;       }       cout << 7;       return 0;     }     if (t == 8) {       for (int i = 0; i < n - 1; i++) {         cout << 8;       }       cout << 8;       return 0;     }     if (t == 9) {       for (int i = 0; i < n - 1; i++) {         cout << 9;       }       cout << 9;       return 0;     }     if (t == 10) {       for (int i = 0; i < n - 1; i++) {         cout << 9;       }       cout << 0;       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265358979323846;   long long MOD = 1e9 + 7;   const char nl =   n ;   const long long inf = 1e15;   long long power(long long x, long long y) {     long long z = 1;     while (y > 0) {       if (y % 2) z = z * x;       x = x * x;       y /= 2;     }     return z;   }   long long gcd(long long a, long long b) {     if (a < b) return gcd(b, a);     if (b == 0) return a;     return gcd(b, a % b);   }   long long sq(long long a) {     long long ans = (1ll * a * a);     return ans;   }   bool isprime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long digitsum(long long x) {     long long ans = 0;     while (x > 0) {       ans += (x % 10);       x /= 10;     }     return ans;   }   void solve() {     long long m;     long long n, d;     cin >> n >> d >> m;     long long a[n];     long long i, j;     vector<long long> large;     vector<long long> small;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] <= m) {         small.push_back(a[i]);       } else {         large.push_back(a[i]);       }     }     long long ans = 0;     sort(large.begin(), large.end(), greater<int>());     sort(small.begin(), small.end(), greater<int>());     long long temp = 0;     for (i = 0; i < small.size(); i++) {       temp += small[i];     }     ans = max(ans, temp);     for (i = 1; i <= large.size(); i++) {       temp = 0;       if (n - 1 - (i - 1) * (d + 1) >= 0) {         long long x = small.size();         for (j = 0; j < min(n - 1 - (i - 1) * (d + 1), x); j++) {           temp += small[j];         }         temp += large[0];         for (j = 1; j <= i - 1; j++) {           temp += large[j];         }       }       ans = max(ans, temp);     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     long long TC = 1;     while (TC--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, s, K, r[55], f[55][2555];   char col[55];   pair<int, int> p[55];   inline void Umn(int &x, int y) { x = min(x, y); }   int main() {     scanf( %d%d%d , &n, &s, &K);     for (int i = 1; i <= n; ++i) scanf( %d , &r[i]);     scanf( %s , col + 1), col[0] =  & ;     for (int i = 1; i <= n; ++i) p[i] = (pair<int, int>){r[i], i};     sort(p + 1, p + n + 1);     memset(f, 0x3f, sizeof f);     f[0][0] = 0;     p[0].second = s;     int ans = 1e9;     for (int i = 1; i <= n; ++i) {       for (int j = p[i].first; j <= 2500; ++j) {         for (int k = 0; k < i; ++k)           if (p[k].first < p[i].first &&               (k == 0 || col[p[k].second] != col[p[i].second]))             Umn(f[i][j], f[k][j - p[i].first] + abs(p[i].second - p[k].second));         if (j >= K) Umn(ans, f[i][j]);       }     }     if (ans > 1e8) return puts( -1 ), 0;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(51);   long long ask(long long a, long long b, long long c) {     cout <<  ?   << a <<     << b <<     << c << endl;     long long p;     cin >> p;     return p;   }   signed main() {     long long t;     cin >> t;     while (t--) {       long long n, bad = 0, good = 0;       cin >> n;       vector<long long> type(n + 1);       for (long long i = 1; i <= n; i += 3) {         type[i] = ask(i, i + 1, i + 2);       }       for (long long i = 1; i <= n; i += 3) {         if (type[i] != type[i + 3]) {           type[i + 1] = ask(i + 1, i + 2, i + 3),                    type[i + 2] = ask(i + 2, i + 3, i + 4);           for (long long j = i; j < i + 3; j++) {             if (type[j] != type[j + 1]) {               if (type[j] == 0) {                 bad = j, good = j + 3;               } else {                 bad = j + 3, good = j;               }             }           }           break;         }       }       vector<long long> arr{bad};       for (long long i = 1; i <= n; i += 3) {         if ((i - 1) / 3 == (bad - 1) / 3 || (i - 1) / 3 == (good - 1) / 3) {           for (long long j = i; j < i + 3; j++) {             if (bad == j || good == j) {               continue;             }             if (ask(good, bad, j) == 0) {               arr.emplace_back(j);             }           }         } else if (type[i] == 0) {           if (ask(i, i + 1, good) == 0) {             arr.emplace_back(i);             arr.emplace_back(i + 1);             if (ask(i + 2, good, bad) == 0) arr.emplace_back(i + 2);           } else {             arr.emplace_back(i + 2);             if (ask(i, good, bad) == 0)               arr.emplace_back(i);             else               arr.emplace_back(i + 1);           }         } else {           if (ask(i, i + 1, bad) == 1) {             if (ask(i + 2, good, bad) == 0) arr.emplace_back(i + 2);           } else {             if (ask(i, good, bad) == 0)               arr.emplace_back(i);             else               arr.emplace_back(i + 1);           }         }       }       cout <<  !   << arr.size() <<    ;       for (auto to : arr) cout << to <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   long long int p = 1e9 + 7;   long long int power(long long int x, long long int y) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     long long int n, k;     scanf( %lld%lld , &n, &k);     if (k == 0 || n == 0) {       printf( %lld n , (2 % p * n % p) % p);       return 0;     }     long long int x = power(2, k + 1);     long long int g = power(2, k);     long long int a1 = ((n) % p * g % p) % p;     long long int a2 = ((n - 1) % p * g % p) % p;     long long int num1 = (a1 % p * (a1 + 1) % p) % p;     long long int num2 = (a2 % p * (a2 + 1) % p) % p;     long long int num = (num1 - num2 + p) % p;     long long int ans1 = power(g, p - 2);     long long int ans = (num % p * ans1 % p) % p;     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   struct event {     int t, l, r, v;   };   void solve() {     int n, q;     cin >> n >> q;     vector<event> e(q);     vector<int64_t> a(n, INT_MAX), upd(n, 0);     for (int i = 0; i < q; ++i) {       cin >> e[i].t;       cin >> e[i].l;       cin >> e[i].r;       cin >> e[i].v;       --e[i].l;       --e[i].r;       if (e[i].t == 1) {         for (int j = e[i].l; j < e[i].r + 1; ++j) {           upd[j] += e[i].v;         }       }     }     for (int i = q - 1; i >= 0; --i) {       if (e[i].t == 2) {         for (int j = e[i].l; j < e[i].r + 1; ++j) {           a[j] = min(a[j], e[i].v - upd[j]);         }       } else {         for (int j = e[i].l; j < e[i].r + 1; ++j) {           upd[j] -= e[i].v;         }       }     }     vector<int64_t> tmp(a);     for (int i = 0; i < q; ++i) {       if (e[i].t == 1) {         for (int j = e[i].l; j < e[i].r + 1; ++j) {           tmp[j] += e[i].v;         }       } else {         int64_t here = INT_MIN;         for (int j = e[i].l; j < e[i].r + 1; ++j) {           here = max(here, tmp[j]);         }         if (here != e[i].v) {           cout <<  NO n ;           return;         }       }     }     cout <<  YES n ;     for (int64_t i : a) {       if (i == INT_MAX)         cout << rand() % 1000 <<    ;       else         cout << i <<    ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   int main() {     int n;     cin >> n;     string a, b;     cin >> a >> b;     int x[n], y[n];     for (int i = 0; i < n; i++) {       x[i] = a[i] -  0 ;       y[i] = b[i] -  0 ;     }     sort(x, x + n);     sort(y, y + n);     int px = 0, py = 0, sher = 0, mori = 0;     vector<int> store;     for (py = 0; py < n; py++) {       if (x[px] > y[py]) {         mori++;       } else {         px++;       }     }     px = 0, py = 0;     for (py = 0; py < n; py++) {       if (x[px] < y[py]) {         sher++;         px++;       }     }     cout << mori << endl << sher << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, num[10], tu[500], fir[10], flag[10];   char ss[1000005];   struct node {     int v[5];   };   vector<node> p[100005];   map<long long, bool> ma[100005];   int main() {     tu[ G ] = 1;     tu[ H ] = 2;     tu[ R ] = 3;     tu[ S ] = 4;     scanf( %d , &n);     scanf( %s , &ss);     for (int i = 0; i < n; i++) {       ma[i].clear();       p[i].clear();     }     if (ss[0] !=  ? ) {       node no;       memset(no.v, 0, sizeof(no.v));       no.v[tu[ss[0]]]++;       p[0].push_back(no);     } else {       for (int i = 1; i <= 4; i++) {         node no;         memset(no.v, 0, sizeof(no.v));         no.v[i] = 1;         p[0].push_back(no);       }     }     for (int i = 1; i < n; i++) {       for (vector<node>::iterator it = p[i - 1].begin(); it != p[i - 1].end();            it++) {         node last = *it;         if (ss[i] !=  ? ) {           last.v[tu[ss[i]]]++;           long long sum = 0;           for (int k = 1; k <= 4; k++) sum = sum * 100000 + last.v[k];           if (!ma[i][sum]) {             p[i].push_back(last);             ma[i][sum] = 1;           }           continue;         }         int minv = 2000000000;         for (int j = 1; j <= 4; j++) minv = min(minv, last.v[j]);         for (int j = 1; j <= 4; j++)           if (last.v[j] == minv) {             node ne = last;             ne.v[j]++;             long long sum = 0;             for (int k = 1; k <= 4; k++) sum = sum * 100000 + ne.v[k];             if (!ma[i][sum]) {               p[i].push_back(ne);               ma[i][sum] = 1;             }           }       }     }     memset(flag, 0, sizeof(flag));     for (vector<node>::iterator it = p[n - 1].begin(); it != p[n - 1].end();          it++) {       node no = *it;       int minv = 2000000000;       for (int i = 1; i <= 4; i++) minv = min(minv, no.v[i]);       for (int i = 1; i <= 4; i++)         if (minv == no.v[i]) flag[i] = 1;     }     for (int k = 1; k <= 4; k++)       if (flag[k]) {         if (k == 1) printf( Gryffindor n );         if (k == 2) printf( Hufflepuff n );         if (k == 3) printf( Ravenclaw n );         if (k == 4) printf( Slytherin n );       }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 1000100;   const int Num = 999999;   const int Mod = 1e9 + 7;   int n;   int Sm1[maxN], Sm2[maxN], Sm3[maxN];   void Plus(int &x, int y);   void Minus(int &x, int y);   int QPow(int x, int cnt);   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       ++Sm3[x];     }     for (int i = 0; i <= Num; i++)       Sm1[i] = 1ll * Sm3[i] * i % Mod, Sm2[i] = 1ll * Sm3[i] * i % Mod * i % Mod;     for (int k = 8; k >= 0; k--)       for (int i = 0, mul = 1; i <= 5; i++, mul = mul * 10)         for (int j = 0; j <= Num; j++)           if (j / mul % 10 == k)             Plus(Sm1[j], Sm1[j + mul]), Plus(Sm2[j], Sm2[j + mul]),                 Plus(Sm3[j], Sm3[j + mul]);     int inv2 = QPow(2, Mod - 2);     for (int i = 0; i <= Num; i++) {       if (!Sm3[i]) continue;       int pw = QPow(2, Sm3[i] - 1);       int k = (1ll * Sm1[i] * Sm1[i] % Mod + Sm2[i]) % Mod;       Sm1[i] = 1ll * k * pw % Mod * inv2 % Mod;     }     for (int k = 0; k <= 8; k++)       for (int i = 0, mul = 1; i <= 5; i++, mul = mul * 10)         for (int j = 0; j <= Num; j++)           if (j / mul % 10 == k) Minus(Sm1[j], Sm1[j + mul]);     long long Ans = 0;     for (int i = 0; i <= Num; i++) Ans = Ans ^ (1ll * Sm1[i] * i);     printf( %I64d n , Ans);     return 0;   }   void Plus(int &x, int y) {     x += y;     if (x >= Mod) x -= Mod;     return;   }   void Minus(int &x, int y) {     x -= y;     if (x < 0) x += Mod;     return;   }   int QPow(int x, int cnt) {     int ret = 1;     while (cnt) {       if (cnt & 1) ret = 1ll * ret * x % Mod;       x = 1ll * x * x % Mod;       cnt >>= 1;     }     return ret;   }
#include <bits/stdc++.h>   using namespace std;   int n, s, x1, x2, v1, v2, w, d, ans;   int main() {     cin >> s >> x1 >> x2 >> v1 >> v2 >> w >> d;     ans = abs(x1 - x2) * v2;     if (d == 1) {       if (w < x2) {         if (x1 < x2) {           if (x1 >= w)             ans = min(ans, (x2 - w) * v1);           else             ans = min(ans, (2 * s + x2 - w) * v1);         } else           ans = min(ans, (2 * s - x2 - w) * v1);       } else {         if (x1 > x2)           ans = min(ans, (2 * s - x2 - w) * v1);         else           ans = min(ans, (2 * s + x2 - w) * v1);       }     } else {       if (w < x2) {         if (x1 > x2)           ans = min(ans, (2 * s - x2 + w) * v1);         else           ans = min(ans, (x2 + w) * v1);       } else {         if (x1 < x2)           ans = min(ans, (x2 + w) * v1);         else {           if (x1 <= w)             ans = min(ans, (w - x2) * v1);           else             ans = min(ans, (2 * s + w - x2) * v1);         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[111];   long long int dp[105][105][3010];   int n, l;   long long int cal(int pre, int ind, int rem) {     if (rem == 0) return 1;     if (rem < 0) return 0;     long long int &ret = dp[pre][ind][rem];     if (ret != -1) return ret;     ret++;     for (int i = 0; i < n; i++) {       if (i == ind) continue;       if (a[i].second == pre) ret += cal(a[i].first, i, rem - a[i].second);       if (a[i].first == pre && a[i].first != a[i].second)         ret += cal(a[i].second, i, rem - a[i].first);       ret %= 1000000007;     }     return ret % 1000000007;   }   int main() {     cin >> n >> l;     for (int i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a[i].second);     long long int ans = 0;     memset(dp, -1, sizeof dp);     for (int i = 0; i < n; i++) {       ans += cal(a[i].first, i, l - a[i].second);       if (a[i].first != a[i].second) ans += cal(a[i].second, i, l - a[i].first);       ans %= 1000000007;     }     cout << ans % 1000000007;   }