malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   const int MAXK = 17;   int X[MAXN];   long long Y[MAXN];   int N, M;   int par[MAXN][MAXK];   int dpth[MAXN];   int Q[MAXN];   int ql = 0, qr = 0;   int main() {     ios_base::sync_with_stdio(0);     cin >> N;     for (int i = 1; i <= N; ++i) {       cin >> X[i] >> Y[i];     }     for (int i = N; i > 0; --i) {       while (ql + 1 < qr) {         int a = Q[qr - 1], b = Q[qr - 2];         if ((Y[b] - Y[i]) * (X[a] - X[i]) > (Y[a] - Y[i]) * (X[b] - X[i])) {           --qr;         } else           break;       }       if (ql < qr) {         par[i][0] = Q[qr - 1];         dpth[i] = dpth[Q[qr - 1]] + 1;       } else         par[i][0] = i;       Q[qr] = i;       ++qr;     }     for (int k = 0; k + 1 < MAXK; ++k) {       for (int i = 1; i <= N; ++i) {         par[i][k + 1] = par[par[i][k]][k];       }     }     cin >> M;     for (int q = 0; q < M; ++q) {       int a, b;       cin >> a >> b;       if (dpth[a] < dpth[b]) swap(a, b);       for (int i = MAXK - 1; i >= 0; --i) {         if (dpth[par[a][i]] >= dpth[b]) {           a = par[a][i];         }       }       for (int i = MAXK - 1; i >= 0; --i) {         if (par[a][i] != par[b][i]) {           a = par[a][i];           b = par[b][i];         }       }       if (a != b) {         a = par[a][0];         b = par[b][0];       }       if (a != b) printf( what n );       printf( %d  , a);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   mt19937 rng;   ll MAX = 1e18;   const int MN = 1e3 + 100;   int get_rand(int x) {     return static_cast<int>(static_cast<ll>(rng()) * x /                             (static_cast<ll>(rng.max()) - rng.min() + 1));   }   int N;   ll L, E;   array<ll, 2> ans[MN];   ll get(int f, ll x) {     printf( ? %d %lld n , f, x);     fflush(stdout);     ll r;     scanf( %lld , &r);     return r;   }   ll loc(int f, ll v, ll l = 0, ll r = MAX) {     r++;     ll m;     while (r - l > 1) {       m = l + (r - l >> 1);       if (get(f, m) > v)         r = m;       else         l = m;     }     return l;   }   void solve(vector<int>& v, int l, int r, ll lp, ll rp) {     if (v.size() == 1) return ans[v[0]] = {lp, rp}, void();     random_shuffle(v.begin(), v.end(), get_rand);     int m = l + (r - l >> 1);     ll mp;     function<ll(vector<int>&, int)> kth_element = [&](vector<int>& x, int k) {       vector<int> a, b, c;       b.push_back(x.back());       ll t = loc(x.back(), m * E, lp, rp);       for (x.pop_back(); !x.empty(); x.pop_back()) {         ll q = get(x.back(), t);         if (m * E < q)           a.push_back(x.back());         else if (q < m * E)           c.push_back(x.back());         else           b.push_back(x.back());       }       if (k < a.size())         t = kth_element(a, k);       else if (a.size() + b.size() <= k)         t = kth_element(c, k - a.size() - b.size());       for (int i : a) x.push_back(i);       for (int i : b) x.push_back(i);       for (int i : c) x.push_back(i);       return t;     };     mp = kth_element(v, m - l);     vector<int> L, R;     for (int i = 0; i < m - l; i++) L.push_back(v[i]);     for (int i = m - l; i < r - l; i++) R.push_back(v[i]);     solve(L, l, m, lp, mp);     solve(R, m, r, mp, rp);   }   int main(void) {     srand(clock());     scanf( %d%lld , &N, &L);     E = L / N;     vector<int> a;     for (int i = 1; i <= N; i++) a.push_back(i);     solve(a, 0, N, 0, MAX);     printf( ! n );     for (int i = 1; i <= N; i++) printf( %lld %lld n , ans[i][0], ans[i][1]);     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, u, r;   int a[31], b[31], k[31], p[31];   long long int s = -333;   void calc(vector<int> &v) {     int f[31];     for (int j = 0; j < n; j++) {       f[j] = a[j];     }     for (int j = 0; j < v.size(); j++) {       if (v[j]) {         for (int i = 0; i < n; i++) {           f[i] ^= b[i];         }       } else {         int g[31];         for (int i = 0; i < n; i++) {           g[i] = f[p[i] - 1] + r;         }         for (int j = 0; j < n; j++) {           f[j] = g[j];         }       }     }     long long int c = 0;     for (int j = 0; j < n; j++) {       c += k[j] * f[j];     }     if (s != -333) {       s = max(c, s);     } else {       s = c;     }   }   void func(vector<int> v) {     int d = v.size();     if (v[d - 1] == 0) {       for (int i = d; i < u; i++) {         vector<int> f = v;         f.push_back(1);         if ((u - i - 1) % 2 == 0 && (u - i - 1 > 0)) calc(f);         func(f);         for (int j = i + 1; j < u; j++) {           f.push_back(0);         }         calc(f);         v.push_back(0);         if ((u - i - 1) % 2 == 0 && (u - i - 1 > 0)) calc(v);       }     } else {       if (d < u) {         v.push_back(0);         if ((u - d - 1) % 2 == 0 && (u - d - 1 > 0)) calc(v);       }       for (int i = d + 1; i < u; i++) {         vector<int> f = v;         f.push_back(1);         if ((u - i - 1) % 2 == 0 && (u - i - 1 > 0)) calc(f);         func(f);         for (int j = i + 1; j < u; j++) {           f.push_back(0);         }         calc(f);         v.push_back(0);         if ((u - i - 1) % 2 == 0 && (u - i - 1 > 0)) calc(v);       }     }   }   int solve() {     cin >> n >> u >> r;     for (int j = 0; j < n; j++) {       cin >> a[j];     }     for (int j = 0; j < n; j++) {       cin >> b[j];     }     for (int j = 0; j < n; j++) {       cin >> k[j];     }     for (int j = 0; j < n; j++) {       cin >> p[j];     }     vector<int> v1, v2;     v1.push_back(0);     v2.push_back(1);     vector<int> v3, v4;     v3.push_back(1);     v4.push_back(0);     for (int j = 0; j < u - 1; j++) {       v3.push_back(0);       v4.push_back(0);     }     if (u % 2 == 0) {       s = 0;       for (int j = 0; j < n; j++) {         s += a[j] * k[j];       }     }     calc(v4);     calc(v3);     func(v1);     func(v2);     cout << s <<   n ;     return 0;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010, oo = 1e9;   int n;   char s[maxn][maxn];   int f[maxn][maxn], fuck[maxn];   pair<int, int> pre[maxn][maxn];   vector<pair<int, int> > all, foo;   int main() {     scanf( %d , &n);     int m;     scanf( %d , &m);     for (int i = 1; i <= n; ++i) scanf( %s , s[i] + 1);     f[1][1] = (s[1][1] ==  a  ? 0 : 1);     if (m < f[1][1]) {       putchar(s[1][1]);       all.push_back(make_pair(1, 1));     } else {       int lst = 2;       for (int k = 3; k <= n + n; ++k) {         for (int i = 1; i <= n; ++i) {           int j = k - i;           if (j >= 1 && j <= n) {             f[i][j] = oo;             if (i > 1)               f[i][j] = min(f[i][j], f[i - 1][j] + (s[i][j] ==  a  ? 0 : 1));             if (j > 1)               f[i][j] = min(f[i][j], f[i][j - 1] + (s[i][j] ==  a  ? 0 : 1));             if (f[i][j] <= m) lst = k;           }         }       }       for (int i = 2; i <= lst; ++i) putchar( a );       if (lst == n + n) return 0;       for (int i = 1; i <= n; ++i) {         int j = lst - i;         if (j >= 1 && j <= n && f[i][j] <= m) all.push_back(make_pair(i, j));       }     }     int T = 0;     for (;;) {       if (all[0].first == n && all[0].second == n) break;       char mn =  z  + 1;       for (auto p : all) {         int x = p.first, y = p.second;         if (x + 1 <= n) mn = min(mn, s[x + 1][y]);         if (y + 1 <= n) mn = min(mn, s[x][y + 1]);       }       foo.clear();       ++T;       for (auto p : all) {         int x = p.first, y = p.second;         if (x + 1 <= n && s[x + 1][y] == mn) {           if (fuck[x + 1] != T)             fuck[x + 1] = T, foo.push_back(make_pair(x + 1, y)),                      pre[x + 1][y] = p;         }         if (y + 1 <= n && s[x][y + 1] == mn) {           if (fuck[x] != T)             fuck[x] = T, foo.push_back(make_pair(x, y + 1)), pre[x][y + 1] = p;         }       }       all = foo;     }     vector<char> ans;     for (int x = n, y = n; x && y;) {       auto t = pre[x][y];       if (!t.first || !t.second) break;       ans.push_back(s[x][y]);       x = t.first, y = t.second;     }     reverse(ans.begin(), ans.end());     for (auto c : ans) putchar(c);     putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<int, vector<int>, greater<int> > pq;   int dp[11][11];   void ini() {     int i, j;     for (int i = 0; i < 11; i++)       for (j = 0; j <= max(i, 10); j++) {         if (i == 0)           dp[i][j] = 0;         else if (i == j || j == 0)           dp[i][j] = 1;         else if (j == 1)           dp[i][j] = i;         else           dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];       }   }   int main() {     ini();     int b, i, n, t, m, sum, x, y;     string s1, s2;     cin >> s1;     cin >> s2;     int l = s1.length();     sum = 0;     x = 0;     y = 0;     for (int i = 0; i < l; i++)       if (s1[i] ==  + ) sum++;     int sum2 = 0;     for (int i = 0; i < l; i++) {       if (s2[i] ==  + )         sum2++;       else if (s2[i] ==  ? )         x++;     }     int anss = 0;     double answ = 0;     if (sum - sum2 < 0)       answ = 0;     else if (sum == sum2 && x == 0)       answ = 1;     else if (sum != sum2 && x == 0)       answ = 0;     else {       anss = dp[x][sum - sum2];       answ = (double)anss / pow(2, x);     }     printf( %0.11lf , answ);   }
#include <bits/stdc++.h>   using namespace std;   string ko(int k, int y) {     string g =   ;     while (y > 0) {       g = char(y % k + 48) + g;       y = y / k;     }     return g;   }   int main() {     int k;     cin >> k;     int i, j;     for (i = 1; i <= k - 1; i++) {       for (j = 1; j <= k - 1; j++) {         cout << ko(k, i * j) <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-6;   const long long oo = 1LL << 60;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int N = 100005;   struct segTree {     int num;     long long sum[5];   } node[N << 2];   struct Query {     int type, num;   } q[N];   void pushup(int rt) {     node[rt].num = (node[(rt << 1)].num + node[(rt << 1 | 1)].num) % 5;     int leftSonNum = node[(rt << 1)].num;     for (int i = 0; i < 5; ++i)       node[rt].sum[i] = node[(rt << 1)].sum[i] +                         node[(rt << 1 | 1)].sum[(i - leftSonNum + 5) % 5];   }   void update(int l, int r, int rt, int p, int v) {     if (l == r) {       node[rt].num = (v > 0);       node[rt].sum[1] = (v > 0 ? v : 0);       return;     }     if (p <= ((l + r) >> 1))       update(l, ((l + r) >> 1), (rt << 1), p, v);     else       update(((l + r) >> 1) + 1, r, (rt << 1 | 1), p, v);     pushup(rt);   }   vector<int> arr;   int pos[N];   int main() {     int n;     char s[5];     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %s , s);       if (s[0] ==  a ) {         scanf( %d , &q[i].num);         q[i].type = 1;         arr.push_back(q[i].num);       } else if (s[0] ==  d ) {         scanf( %d , &q[i].num);         q[i].type = 2;       } else         q[i].type = 0;     }     sort((arr).begin(), (arr).end());     arr.erase(unique((arr).begin(), (arr).end()), arr.end());     for (int i = 0; i < n; ++i)       if (q[i].type)         pos[i] =             lower_bound((arr).begin(), (arr).end(), q[i].num) - arr.begin() + 1;     int siz = (int(arr.size()));     for (int i = 0; i < n; ++i) {       if (q[i].type == 1)         update(1, siz, 1, pos[i], q[i].num);       else if (q[i].type == 2)         update(1, siz, 1, pos[i], -q[i].num);       else         printf( %I64d n , node[1].sum[3]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[100100], b[100100];   int id[100100], p[100100];   int main() {     int T = 1;     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         id[a[i]] = i;       }       for (int i = 1; i <= n; i++) {         scanf( %d , &b[i]);       }       for (int i = 1; i <= n; i++) {         int x = b[i];         int op = id[x];         p[i] = op;       }       for (int i = 1; i <= n; i++) printf( %d  , p[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   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 << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   int n, m, SG[55][55][55][55][2];   char mp[55][55];   int dfs(int x1, int y1, int x2, int y2, int type) {     if (x1 > x2 || y1 > y2) return 0;     if (SG[x1][y1][x2][y2][type] != -1) return SG[x1][y1][x2][y2][type];     bool vis[215];     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int x = i + j, y = i - j + m;         if ((i + j) % 2 == type || x < x1 || x > x2 || y < y1 || y > y2) continue;         int nxt = 0;         if (mp[i][j] ==  L )           nxt = dfs(x + 1, y1, x2, y2, type) ^ dfs(x1, y1, x - 1, y2, type);         else if (mp[i][j] ==  R )           nxt = dfs(x1, y + 1, x2, y2, type) ^ dfs(x1, y1, x2, y - 1, type);         else           nxt = dfs(x + 1, y + 1, x2, y2, type) ^                 dfs(x1, y1, x - 1, y - 1, type) ^                 dfs(x + 1, y1, x2, y - 1, type) ^ dfs(x1, y + 1, x - 1, y2, type);         vis[nxt] = 1;       }     }     int res = 0;     while (vis[res]) ++res;     return SG[x1][y1][x2][y2][type] = res;   }   int main() {     memset(SG, -1, sizeof(SG));     n = read();     m = read();     for (int i = 1; i <= n; i++) scanf( %s , (mp[i] + 1));     int ans = (dfs(1, 1, n + m, n + m, 0) ^ dfs(1, 1, n + m, n + m, 1));     if (ans)       puts( WIN );     else       puts( LOSE );   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long dx[] = {-1, 0, 1, 0};   long long dy[] = {0, -1, 0, 1};   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> v(n);     vector<long long> a;     for (long long i = 0; i < n; i++) {       cin >> v[i];       if (v[i] == 0) a.push_back(i);     }     for (long long i = 0; i < n; i++) {       long long k = upper_bound(a.begin(), a.end(), i) - a.begin();       long long ans = abs(i - a[k]);       if (k > 0) {         ans = min(ans, abs(i - a[k - 1]));       }       cout << ans <<    ;     }   }
#include <bits/stdc++.h>   const double PI = 3.141592653589793238;   using namespace std;   long long takeTurn(long long n) {     if (n % 2 == 1) return n - 1;     if (n % 4 == 0 && n > 4) return n - 1;     return n / 2;   }   void solve() {     long long n, res = 0;     cin >> n;     while (n > 0) {       long long t1 = takeTurn(n);       res += n - t1;       n = t1;       n = takeTurn(n);     }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[110][110];   int main() {     int n, m, i, j;     while (~scanf( %d %d , &n, &m)) {       for (i = 0; i < n; i++)         for (j = 0; j < m; j++) scanf( %d , &a[i]);       if (n & 1) {         cout << n << endl;         continue;       }       int vis;       for (i = 0; i < m; i++) {         for (j = 0, vis = 0; j < n; j++) {           if (a[j][i] != a[n - j - 1][i]) {             vis = 1;             break;           }         }         if (vis) break;       }       if (vis)         cout << n << endl;       else {         while (1) {           n /= 2;           if (n == 1 || (n & 1)) {             cout << n << endl;             break;           }           for (i = 0; i < m; i++) {             for (j = 0, vis = 0; j < n; j++) {               if (a[j][i] != a[n - j - 1][i]) {                 vis = 1;                 break;               }             }             if (vis) break;           }           if (vis) {             cout << n << endl;             break;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int k = 0;     int a, b, c;     string s1, s2, s3;     cin >> s1 >> s2 >> s3;     a = s1.size();     b = s2.size();     c = s3.size();     if ((a + b) != c) {       cout <<  NO ;       return 0;     }     s1 = s1 + s2;     for (int i = 0; i < c; i++) {       for (int j = 0; j < c; j++) {         if (s1[i] == s3[j]) {           k++;           s3[j] =  0 ;           break;         }       }     }     if (k == c)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n == 2)       cout << 1 << endl << 1;     else if (n == 3)       cout << 2 << endl <<  1 3 ;     else {       cout << n << endl;       for (int i = 2; i <= n; i += 2) cout << i <<    ;       for (int i = 1; i <= n; i += 2) cout << i <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   int dist(int from, int to, int count) {     if (from <= to) {       return to - from;     } else {       return dist(from, count - 1, count) + dist(0, to, count) + 1;     }   }   void output(const std::vector<int64_t>& boxes);   std::vector<int64_t> recover(const std::vector<int64_t>& boxes, int lastBox) {     std::vector<int64_t> result(boxes.size());     int minValue = *std::min_element(boxes.begin(), boxes.end());     int index = -1;     int minDist = -1;     for (size_t i = 0; i < boxes.size(); ++i) {       if (boxes[i] == minValue) {         if (index == -1 || minDist > dist(i, lastBox, boxes.size())) {           index = i;           minDist = dist(i, lastBox, boxes.size());         }       }     }     int64_t wasBalls =         boxes[index] * boxes.size() + dist(index, lastBox, boxes.size());     for (size_t i = 0; i < boxes.size(); ++i) {       if (i == index) {         result[i] = wasBalls;       } else {         int dst = dist(index, i, boxes.size()) - 1;         if (wasBalls >= dst) {           int64_t rem = wasBalls - dst;           int64_t add = rem / boxes.size();           if (rem % boxes.size() != 0) {             ++add;           }           result[i] = boxes[i] - add;           assert(result[i] >= 0);         } else {           result[i] = boxes[i];         }       }     }     return result;   }   void output(const std::vector<int64_t>& boxes) {     for (size_t i = 0; i < boxes.size(); ++i) {       cout << boxes[i] <<    ;     }     cout <<   n ;   }   void input(std::vector<int64_t>* boxes, int* lastBox) {     int count;     cin >> count >> *lastBox;     --(*lastBox);     boxes->resize(count);     for (int i = 0; i < count; ++i) {       cin >> (*boxes)[i];     }   }   void stressTest() {     int N = 10;     for (int tc = 0; tc < 1000; ++tc) {       std::vector<int64_t> a(N);       for (size_t i = 0; i < a.size(); ++i) {         if (rand() % 4 == 0) {           a[i] = 0;         } else {           a[i] = rand() % 1000;         }       }       int start = -1;       while (true) {         start = rand() % N;         if (a[start] == 0) {           continue;         }         break;       }       int cnt = a[start];       int realCnt = cnt;       a[start] = 0;       int i = (start + 1) % N;       for (; cnt > 0; cnt--, i = (i + 1) % N) {         ++a[i];       }       int end = (i + N - 1) % N;       std::vector<int64_t> b = recover(a, end);       assert(b[start] == realCnt);       b[start] = 0;       i = (start + 1) % N;       cnt = realCnt;       for (; cnt > 0; cnt--, i = (i + 1) % N) {         ++b[i];       }       if (a != b) {         cout << end + 1 <<   n ;         output(a);         output(b);         exit(0);       }       assert(a == b);     }   }   int main() {     std::ios_base::sync_with_stdio(false);     std::vector<int64_t> boxes;     int lastBox;     input(&boxes, &lastBox);     output(recover(boxes, lastBox));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, a, b;   void fn() {     cin >> a >> b;     if (a < b) swap(a, b);     a -= b;     int ans = a / 5;     a %= 5;     if (a == 1 || a == 2)       ans++;     else if (a == 3 || a == 4)       ans += 2;     cout << ans << endl;   }   int main() {     cin >> t;     while (t--) fn();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[300005];   void input() {     int i, l, r, x, cur, n, ne;     set<int> alive;     set<int>::iterator ite;     vector<int> xoa;     scanf( %d %d , &n, &ne);     for ((i) = (1); (i) <= (n); (i)++) alive.insert(i);     for ((i) = 0; (i) < (ne); (i)++) {       scanf( %d %d %d , &l, &r, &x);       xoa.clear();       ite = alive.lower_bound(l);       while (ite != alive.end()) {         cur = *ite;         if (cur > r) break;         if (cur != x) ans[cur] = x, xoa.push_back(cur);         ite++;       }       for (typeof(xoa.begin()) jte = xoa.begin(); jte != xoa.end(); jte++)         alive.erase(*jte);     }     for ((i) = (1); (i) <= (n); (i)++) printf( %d  , ans[i]);   }   int main() {     input();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   int a[MAX];   int main() {     ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     n = 2 * n + 1;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n - 1 && k; i++)       if (a[i - 1] + 1 < a[i] && a[i] > a[i + 1] + 1) {         a[i]--;         k--;       }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n], b[n + 1];     vector<pair<int, int>> c;     for (int i = 0; i < n; i++) cin >> a[i];     unordered_map<long long, long long> mp, mp1;     vector<vector<int>> v;     v.assign(n + 1, vector<int>());     for (int i = 0; i < n; i++) {       mp[a[i]]++;       v[n - a[i]].push_back(i + 1);     }     for (auto it : mp) {       c.push_back({it.second / (n - it.first), n - it.first});     }     int x = 0;     for (int i = 0; i < c.size(); i++) x += (c[i].first) * (c[i].second);     if (x != n)       cout <<  Impossible ;     else {       int y = 1;       cout <<  Possible n ;       for (auto it : c) {         for (int j = 0; j < it.first; j++) {           for (int k = 0; k < it.second; k++) {             x = *v[it.second].rbegin();             v[it.second].pop_back();             b[x] = y;           }           y += 1;         }       }       for (int i = 1; i <= n; i++) cout << b[i] <<    ;     }   }
#include <bits/stdc++.h>   int f[105][25][25], g[25][25], n, k, u, v;   std::vector<int> ch[105];   using ll = long long;   const int mod = 1e9 + 7;   void dfs(int u, int fa) {     f[u][0][1] = f[u][k][0] = 1;     for (int v : ch[u]) {       if (v == fa) continue;       dfs(v, u);       std::memcpy(g, f[u], sizeof(f[u]));       std::memset(f[u], 0, sizeof(f[u]));       for (int a = 0; a <= k; ++a)         for (int b = 0; b <= k; ++b)           for (int c = 0; c <= k; ++c)             for (int d = 0; d <= k; ++d) {               int d1 = b, d2 = d;               if (d1 <= c) d1 = 0;               if (d2 <= a) d2 = 0;               int i = std::max(a, c - 1);               int j = std::max(d1, d2 + (d2 != 0));               if (j <= k)                 f[u][i][j] = (f[u][i][j] + (ll)g[a][b] * f[v][c][d] % mod) % mod;             }     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &u, &v);       ch[u].push_back(v);       ch[v].push_back(u);     }     dfs(1, 0);     int ans = 0;     for (int i = 0; i <= k; ++i) ans = (ans + f[1][i][0]) % mod;     printf( %d , ans);     return 0;   }