malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2500 * 4 + 10;   int n, k, d, sz;   bool isV[2000], M = 0;   string arr[N];   set<string> st[N];   string change(string z) {     int c = 0;     string s =   ;     for (int i = z.size() - 1; i >= 0; i--) {       s += z[i];       if (isV[z[i]]) M = 1, c++;       if (c == k) break;     }     if (c != k) M = 0;     reverse(s.begin(), s.end());     return s;   }   bool checkAABB() {     vector<string> v(10);     for (int i = 0; i < sz; i++) {       for (int j = 0; j < 4; j++) {         v[j] = arr[i * 4 + j];       }       if (v[0] != v[1] || v[2] != v[3]) return 0;     }     return 1;   }   bool checkABAB() {     vector<string> v(10);     for (int i = 0; i < sz; i++) {       for (int j = 0; j < 4; j++) {         v[j] = arr[i * 4 + j];       }       if (v[0] != v[2] || v[1] != v[3]) return 0;     }     return 1;   }   bool checkABBA() {     vector<string> v(10);     for (int i = 0; i < sz; i++) {       for (int j = 0; j < 4; j++) {         v[j] = arr[i * 4 + j];       }       if (v[0] != v[3] || v[2] != v[1]) return 0;     }     return 1;   }   bool checkAAAA() {     vector<string> v(10);     for (int i = 0; i < sz; i++) {       for (int j = 0; j < 4; j++) {         v[j] = arr[i * 4 + j];       }       if (v[0] != v[1] || v[2] != v[3] || v[1] != v[2]) return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     isV[ a ] = isV[ o ] = isV[ i ] = isV[ u ] = isV[ e ] = 1;     cin >> n >> k;     sz = n;     n *= 4;     bool Valid = 1;     for (int i = 0; i < n; i++) {       cin >> arr[i];       M = 0;       arr[i] = change(arr[i]);       if (!M) Valid = 0;     }     if (!Valid) return cout <<  NO  << endl, 0;     if (checkAAAA())       cout <<  aaaa  << endl;     else if (checkABAB())       cout <<  abab  << endl;     else if (checkABBA())       cout <<  abba  << endl;     else if (checkAABB())       cout <<  aabb  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline long long mul(long long x, long long y) {     if (x >= (1ll << 60) / y)       return (1ll << 60);     else       return x * y;   }   int n, m, p;   int d[100005];   long long cat[100005], sum[100005];   long long dp[105][100005];   int dq[100005], s, e;   int main() {     scanf( %d%d%d , &n, &m, &p);     for (int i = 2; i <= n; ++i) scanf( %d , d + i), d[i] += d[i - 1];     for (int i = 1; i <= m; ++i) {       int h, t;       scanf( %d%d , &h, &t);       cat[i] = t - d[h] + 1000000000;     }     sort(cat + 1, cat + 1 + m);     for (int i = 1; i <= m; ++i) sum[i] = sum[i - 1] + cat[i];     memset(dp, 63, sizeof(dp));     for (int i = 0; i < 105; ++i) dp[i][0] = 0;     for (int k = 1; k <= p; ++k) {       dq[0] = 0, s = 0, e = 1;       for (int i = 1; i <= m; ++i) {         long long c1 = cat[i], c2 = i * c1 - sum[i];         while (s + 1 < e) {           long long x1 = dq[s], y1 = dp[k - 1][x1] + sum[x1];           long long x2 = dq[s + 1], y2 = dp[k - 1][x2] + sum[x2];           if ((y2 - y1) <= mul(c1, (x2 - x1)))             s++;           else             break;         }         int t = dq[s];         dp[k][i] = min(dp[k][i], dp[k - 1][t] + sum[t] - c1 * t + c2);         while (s + 1 < e) {           long long x1 = i, y1 = dp[k - 1][i] + sum[i];           long long x2 = dq[e - 1], y2 = dp[k - 1][x2] + sum[x2];           long long x3 = dq[e - 2], y3 = dp[k - 1][x3] + sum[x3];           if (mul((y1 - y2), (x2 - x3)) <= mul((y2 - y3), (x1 - x2)))             e--;           else             break;         }         dq[e++] = i;       }     }     printf( %I64d n , dp[p][m]);   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   const int maxn = 3e5 + 5, N = 1e6 + 5, SQ = 55, base = 879169, mod = 1e9 + 7,             INF = 1e9 + 5, lg = 20;   const long double eps = 1e-4;   struct node {     int mn = INF, lz = 0;     int c1 = 0, c2 = 0;   };   node seg[4 * maxn];   int n, p[maxn], pos[maxn], q[maxn];   inline void shift(int v) {     seg[2 * v].mn += seg[v].lz;     seg[2 * v + 1].mn += seg[v].lz;     seg[2 * v].lz += seg[v].lz;     seg[2 * v + 1].lz += seg[v].lz;     seg[v].lz = 0;   }   void add(int l, int r, int x, int v = 1, int s = 0, int e = n) {     if (l >= e || s >= r) {       return;     }     if (l <= s && e <= r) {       seg[v].mn += x;       seg[v].lz += x;       return;     }     shift(v);     add(l, r, x, 2 * v, s, (s + e) / 2);     add(l, r, x, 2 * v + 1, (s + e) / 2, e);     seg[v].mn = min(seg[2 * v].mn, seg[2 * v + 1].mn);   }   pair<int, int> get(int l, int r, int v = 1, int s = 0, int e = n) {     if (l >= e || s >= r) {       return {0, 0};     }     if (l <= s && e <= r) {       return {seg[v].c1, seg[v].c2};     }     shift(v);     pair<int, int> a = get(l, r, 2 * v, s, (s + e) / 2);     pair<int, int> b = get(l, r, 2 * v + 1, (s + e) / 2, e);     return {a.first + b.first, a.second + b.second};   }   void modify_num(int p, int x, int v = 1, int s = 0, int e = n) {     seg[v].c2++;     seg[v].mn = min(seg[v].mn, x);     if (e - s == 1) {       return;     }     shift(v);     if (p < (s + e) / 2) {       modify_num(p, x, 2 * v, s, (s + e) / 2);       return;     }     modify_num(p, x, 2 * v + 1, (s + e) / 2, e);   }   void modify_bomb(int p, int v = 1, int s = 0, int e = n) {     seg[v].c1++;     if (e - s == 1) {       return;     }     shift(v);     if (p < (s + e) / 2) {       modify_bomb(p, 2 * v, s, (s + e) / 2);       return;     }     modify_bomb(p, 2 * v + 1, (s + e) / 2, e);   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> p[i];     }     for (int i = 0; i < n; ++i) {       cin >> q[i];     }     for (int i = 0; i < n; ++i) {       p[i]--, q[i]--;       pos[p[i]] = i;     }     int ans = n - 1;     for (int i = 0; i < n; ++i) {       while (ans) {         add(0, pos[ans], -1);         pair<int, int> res = get(pos[ans], n);         if (res.first < res.second + 1 || seg[1].mn <= 0) {           add(0, pos[ans], 1);           break;         }         modify_num(pos[ans], res.first - res.second);         ans--;       }       cout << ans + 1 <<    ;       modify_bomb(q[i]);       add(0, q[i] + 1, 1);     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e3 + 1;   struct node {     int w, x, y, z;   };   queue<int> q;   vector<int> g[N], rg[N];   int d[N][N], rd[N][N], vis[N];   vector<pair<int, int>> fg[N], frg[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       rg[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         vis[j] = 0;         d[i][j] = n + 1;       }       vis[i] = 1;       q.push(i);       d[i][i] = 0;       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto u : g[v]) {           if (vis[u]) continue;           vis[u] = 1;           q.push(u);           d[i][u] = d[i][v] + 1;         }       }       for (int j = 1; j <= n; j++) {         if (j == i) continue;         if (d[i][j] != n + 1) fg[i].push_back({d[i][j], j});       }       sort(fg[i].begin(), fg[i].end());       for (int j = 1; j <= n; j++) {         vis[j] = 0;         rd[i][j] = n + 1;       }       vis[i] = 1;       q.push(i);       rd[i][i] = 0;       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto u : rg[v]) {           if (vis[u]) continue;           vis[u] = 1;           q.push(u);           rd[i][u] = rd[i][v] + 1;         }       }       for (int j = 1; j <= n; j++) {         if (j == i) continue;         if (rd[i][j] != n + 1) frg[i].push_back({rd[i][j], j});       }       sort(frg[i].begin(), frg[i].end());     }     int ans = 0;     node A;     for (int b = 1; b <= n; b++) {       for (int c = 1; c <= n; c++) {         if (b == c || d[b][c] == n + 1) continue;         int ans1 = 0, z = 0;         node B;         int sz1 = frg[b].size(), sz2 = fg[c].size();         for (int j = sz1 - 1; j >= max(z, sz1 - 3); j--) {           int a = frg[b][j].second;           for (int k = sz2 - 1; k >= max(z, sz2 - 3); k--) {             int dd = fg[c][k].second;             if (a == c || dd == b || a == dd) continue;             int ans2 = d[b][c] + rd[b][a] + d[c][dd];             node C;             C.w = a;             C.x = b;             C.y = c;             C.z = dd;             if (ans2 > ans1) {               ans1 = ans2;               B = C;             }           }         }         if (ans1 > ans) {           ans = ans1;           A = B;         }       }     }     cout << A.w <<     << A.x <<     << A.y <<     << A.z <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 5;   vector<int> adjList[N];   unordered_set<int> remaining;   bitset<N> inQ, nextToQ;   vector<int> ans;   void solve(int u) {     remaining.erase(u);     for (auto v : adjList[u]) {       remaining.erase(v);     }     if (!remaining.empty()) {       solve(*remaining.begin());     }     if (!nextToQ[u]) {       inQ[u] = 1;       nextToQ[u] = 1;       for (auto v : adjList[u]) {         nextToQ[v] = 1;       }       ans.push_back(u);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       adjList[u].push_back(v);     }     for (int i = 1; i <= n; i++) {       remaining.insert(i);     }     solve(1);     cout << ans.size() << endl;     for (auto u : ans) {       cout << u <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const double EPS = 1e-6;   const string alpha =  abcdefghijklmnopqrstuvwxyz ;   const long long INFINF = 1e18;   const int INF = 1e9;   const int maxN = 1e6;   int T;   void tc() {     int N;     cin >> N;     string second =   ;     int d = 0;     for (int i = 0; i < N; i++) {       if (d < N) {         second +=  8 ;         d += 4;       } else {         second +=  9 ;       }     }     reverse(second.begin(), second.end());     cout << second << endl;   }   int main() {     cin >> T;     while (T--) {       tc();     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2,Ofast,inline,unroll-all-loops,-ffast-math )   #pragma GCC target( avx,sse2,sse3,sse4,popcnt )   using namespace std;   int nxt[100010][26], f[255][255][255], pos[26], n, q, a = 0, b = 0, c = 0;   char s[100010], A[255], B[255], C[255];   template <class T>   void read(T &x) {     char ch = x = 0;     bool fl = false;     while (!isdigit(ch)) fl |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     x = fl ? -x : x;   }   int main() {     read(n), read(q), scanf( %s , s + 1);     for (int i = 0; i < 26; i++) {       pos[i] = n + 1;     }     memcpy(nxt[n + 1], pos, sizeof(pos));     for (int i = n; ~i; i--) {       memcpy(nxt[i], pos, sizeof(pos)), pos[s[i] -  a ] = i;     }     char op[10];     for (int i = 1, x; i <= q; i++) {       scanf( %s , op);       if (op[0] ==  + ) {         read(x), scanf( %s , op);         if (x == 1) {           A[++a] = op[0];           for (int b = 0; b <= ::b; b++) {             for (int c = 0; c <= ::c; c++) {               f[a][b][c] = 1 << 30;               if (a)                 f[a][b][c] = min(f[a][b][c], nxt[f[a - 1][b][c]][A[a] -  a ]);               if (b)                 f[a][b][c] = min(f[a][b][c], nxt[f[a][b - 1][c]][B[b] -  a ]);               if (c)                 f[a][b][c] = min(f[a][b][c], nxt[f[a][b][c - 1]][C[c] -  a ]);             }           }         }         if (x == 2) {           B[++b] = op[0];           for (int a = 0; a <= ::a; a++) {             for (int c = 0; c <= ::c; c++) {               f[a][b][c] = 1 << 30;               if (a)                 f[a][b][c] = min(f[a][b][c], nxt[f[a - 1][b][c]][A[a] -  a ]);               if (b)                 f[a][b][c] = min(f[a][b][c], nxt[f[a][b - 1][c]][B[b] -  a ]);               if (c)                 f[a][b][c] = min(f[a][b][c], nxt[f[a][b][c - 1]][C[c] -  a ]);             }           }         }         if (x == 3) {           C[++c] = op[0];           for (int a = 0; a <= ::a; a++) {             for (int b = 0; b <= ::b; b++) {               f[a][b][c] = 1 << 30;               if (a)                 f[a][b][c] = min(f[a][b][c], nxt[f[a - 1][b][c]][A[a] -  a ]);               if (b)                 f[a][b][c] = min(f[a][b][c], nxt[f[a][b - 1][c]][B[b] -  a ]);               if (c)                 f[a][b][c] = min(f[a][b][c], nxt[f[a][b][c - 1]][C[c] -  a ]);             }           }         }       } else {         read(x);         if (x == 1) a--;         if (x == 2) b--;         if (x == 3) c--;       }       puts(f[a][b][c] <= n ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, A, B;   long long arr[100000];   long long solve(long long l, long long r, long long depth, long long add) {     if (l == r) return A;     if (depth == 0) return B * (r - l);     long long mid =         lower_bound(arr + l, arr + r, (1 << (depth - 1)) + add) - (arr);     return min(B * (r - l) * (1 << depth),                solve(l, mid, depth - 1, add) +                    solve(mid, r, depth - 1, add + (1 << (depth - 1))));   }   int32_t main() {     cin >> n >> k >> A >> B;     for (long long i = 0; i < k; ++i) cin >> arr[i];     sort(arr, arr + k);     cout << solve(0, k, n, 1) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, q;     cin >> n >> m >> q;     vector<vector<int> > arr(n);     for (int i = 0; i < n; i++) {       arr[i].resize(m);     }     vector<pair<int, int> > did;     for (int i = 0; i < q; i++) {       int t;       cin >> t;       if (t == 1) {         int x, c;         cin >> x;         x--;         c = arr[x][0];         for (int j = 0; j < m - 1; j++) {           arr[x][j] = arr[x][j + 1];         }         arr[x][m - 1] = c;         did.push_back({1, x});       }       if (t == 2) {         int x, c;         cin >> x;         x--;         c = arr[0][x];         for (int j = 0; j < n - 1; j++) {           arr[j][x] = arr[j + 1][x];         }         arr[n - 1][x] = c;         did.push_back({2, x});       }       if (t == 3) {         int x, y, c;         cin >> x >> y >> c;         arr[x - 1][y - 1] = c;       }     }     for (int i = did.size() - 1; i >= 0; i--) {       int x = did[i].second;       if (did[i].first == 1) {         int c = arr[x][m - 1];         for (int j = m - 1; j > 0; j--) {           arr[x][j] = arr[x][j - 1];         }         arr[x][0] = c;       } else {         int c = arr[n - 1][x];         for (int j = n - 1; j > 0; j--) {           arr[j][x] = arr[j - 1][x];         }         arr[0][x] = c;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << arr[i][j] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   std::mt19937 rng(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   struct PT {     long long x, y;     PT(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}     PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); }     PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); }     PT operator*(long long c) const { return PT(x * c, y * c); }     long long operator*(const PT &p) const { return x * p.x + y * p.y; }     long long operator%(const PT &p) const { return x * p.y - y * p.x; }     bool operator<(const PT &p) const { return x != p.x ? x < p.x : y < p.y; }     bool operator==(const PT &p) const { return x == p.x && y == p.y; }     friend std::ostream &operator<<(std::ostream &os, const PT &p) {       return os << p.x <<     << p.y;     }     friend std::istream &operator>>(std::istream &is, PT &p) {       return is >> p.x >> p.y;     }   };   bool comp(PT a, PT b) {     int hp1 = (a.x < 0 || (a.x == 0 && a.y < 0));     int hp2 = (b.x < 0 || (b.x == 0 && b.y < 0));     if (hp1 != hp2) return hp1 < hp2;     long long R = a % b;     if (R) return R > 0;     return a * a < b * b;   }   const int ms = 6060;   int choice[3];   long long f[4];   long long go(int on, int lst) {     if (on == 3) {       int got = 0;       for (int i = 0; i < 3; i++)         for (int j = i + 1; j < 3; j++) {           if (choice[i] ^ choice[j]) {             got++;           }         }       if (got % 2 == 0) {         long long ans = 1;         for (int l = 0, r = 0; l < 3; l = r) {           while (r < 3 && choice[r] == choice[l]) r++;           long long v = f[choice[l]];           if (r - l == 1) {             ans *= v;           } else if (r - l == 2) {             ans *= v * (v - 1) / 2;           } else {             ans *= v * (v - 1) * (v - 2) / 6;           }         }         return ans;       }       return 0;     }     long long ans = 0;     choice[on] = lst;     ans = go(on + 1, lst);     if (lst < 3) {       ans += go(on, lst + 1);     }     return ans;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     int n;     std::cin >> n;     std::vector<PT> a(n);     for (int i = 0; i < n; i++) {       std::cin >> a[i];       int v1 = (int)a[i].x % 4 / 2, v2 = (int)a[i].y % 4 / 2;       f[v1 * 2 + v2]++;     }     std::cout << go(0, 0) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int printx(int x, int a, int b, int c) {     if (x == 0)       return a;     else if (x == 1)       return b;     else       return c;   }   int main() {     long long n;     int x;     cin >> n >> x;     n %= 6;     switch (n) {       case 0:         x = printx(x, 0, 1, 2);         break;       case 1:         x = printx(x, 1, 0, 2);         break;       case 2:         x = printx(x, 1, 2, 0);         break;       case 3:         x = printx(x, 2, 1, 0);         break;       case 4:         x = printx(x, 2, 0, 1);         break;       case 5:         x = printx(x, 0, 2, 1);         break;     }     cout << x << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a[100];   int id[30];   vector<int> cn[30];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       char l1 =  - ;       char l2 =  - ;       int j = -1;       int s = a[i - 1].size();       if (a[i - 1].size() > a[i].size()) {         s = a[i].size();         if (a[i] == string(a[i - 1].substr(0, s))) id[0]++;       }       while (++j < s) {         if (a[i - 1][j] == a[i][j]) continue;         l1 = a[i - 1][j];         l2 = a[i][j];         break;       }       if (l1 !=  - ) {         cn[l1 -  a ].push_back(l2 -  a );         id[l2 -  a ]++;       }     }     queue<int> ts;     for (int i = 0; i < 26; i++)       if (!id[i]) ts.push(i);     string anw =   ;     while (!ts.empty()) {       int u = ts.front();       ts.pop();       anw += char(u +  a );       for (auto v : cn[u]) {         id[v]--;         if (!id[v]) ts.push(v);       }     }     cout << (anw.size() == 26 ? anw :  Impossible ) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int dp[26][26];   int main(void) {     int n, i, j, a, b, l, ans = 0;     char s[20];     memset(dp, 0, sizeof dp);     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %s , s);       l = strlen(s);       a = s[0] -  a ;       b = s[l - 1] -  a ;       for (j = 0; j < 26; j++) {         if (dp[j][a]) {           dp[j][b] = max(dp[j][b], dp[j][a] + l);         }       }       dp[a][b] = max(dp[a][b], l);     }     for (i = 0; i < 26; i++) {       ans = max(ans, dp[i][i]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   inline void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int& e : a) {       cin >> e;     }     long long b = a[0];     for (int i = 0; i < n - 1; ++i) {       int d = a[i + 1] - a[i];       if (d < 0) {         b += d;         if (b < 0) {           cout <<  NO n ;           return;         }       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     size_t t = 1;     cin >> t;     for (int i = 0; i < t; ++i) {       solve();     }   }
#include <bits/stdc++.h>   const int N = 4096;   int a, n, v[N], h;   long long w, c[N * 10];   char s[N];   int main() {     std::cin >> a >> s;     for (; s[n]; ++n) v[n + 1] = v[n] + s[n] -  0 ;     h = v[n];     for (int i = 1; i <= n; ++i)       for (int j = 0; j < i; ++j) ++c[v[i] - v[j]];     if (a) {       for (int i = 1; i <= h && i * i <= a; ++i)         if (0 == a % i)           if (a / i <= h) w += c[i] * c[a / i] * (i * i == a ? 1 : 2);     } else       w = c[0] * ((n + 1) * n - c[0]);     std::cout << w << std::endl;   }
#include <bits/stdc++.h>   using namespace std;   long long f[25], ny[40], ff[40];   int vis[2100000];   int n;   long long s;   long long ans = 0;   void pre() {     ny[0] = ny[1] = ff[0] = ff[1] = 1;     for (int i = 2; i < 39; i++) {       long long t = 1000000007 / i, k = 1000000007 % i;       ff[i] = i * t % 1000000007 * t % 1000000007 * ff[k] % 1000000007 * ff[k] %               1000000007;       ny[i] = ny[i - 1] * ff[i] % 1000000007;     }   }   long long C(long long a, long long b) {     if (a < b) return 0;     long long cur = 1;     for (int i = 0; i < b; i++) cur = cur * ((a - i) % 1000000007) % 1000000007;     cur = cur * ny[b] % 1000000007;     return cur;   }   void dfs(int st, long long sum, int zf) {     if (vis[st]) return;     vis[st] = 1;     long long cur =         (zf * C(s - sum + n - 1, n - 1) % 1000000007 + 1000000007) % 1000000007;     ans = (ans + cur) % 1000000007;     if (st == ((1 << n) - 1)) return;     for (int i = 0; i < n; i++)       if ((st & (1 << i)) == 0) {         dfs(st | (1 << i), sum + f[i] + 1, -zf);       }   }   int main() {     pre();     scanf( %d%I64d , &n, &s);     for (int i = 0; i < n; i++) scanf( %I64d , &f[i]);     dfs(0, 0, 1);     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e3 + 10;   int N;   vector<int> g[maxn];   int sub[maxn][maxn], fa[maxn][maxn];   long long dp[maxn][maxn];   void DFS1(int anc, int v, int p) {     sub[anc][v] = 1;     for (int u : g[v]) {       if (u != p) {         fa[anc][u] = v;         DFS1(anc, u, v);         sub[anc][v] += sub[anc][u];       }     }   }   long long DFS2(int v, int u) {     if (v == u) return 0;     if (dp[v][u] != -1) return dp[v][u];     dp[v][u] = (long long)sub[v][u] * sub[u][v] +                max(DFS2(v, fa[v][u]), DFS2(fa[u][v], u));     return dp[v][u];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> N;     for (int i = 1; i <= N - 1; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= N; ++i) {       fa[i][i] = i;       DFS1(i, i, i);     }     long long ret = 0;     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= N; ++j) {         dp[i][j] = -1;       }     }     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= N; ++j) {         ret = max(ret, DFS2(i, j));       }     }     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     string fir;     cin >> fir;     vector<long long> v;     for (long long i = 0; i < fir.size(); ++i) {       if (fir[i] ==  0 ) {         v.push_back(i);       }     }     long long ans = pow(10, 7);     long long m = 0;     for (long long l = 0; l < v.size() - k; ++l) {       long long r = l + k;       ;       while (v[m] - v[l] < v[r] - v[m]) {         ++m;       }       ans = min(ans, max(v[m] - v[l], v[r] - v[m]));       ans = min(ans, max(v[m - 1] - v[l], v[r] - v[m - 1]));     }     cout << ans << endl;   }