malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> dp[1100][20];   int bitcnt[1100];   long long p10[21];   string a;   int n, k;   pair<long long, long long> dfs(int bi, int pos, int flag, int leading) {     if (pos == -1) return make_pair(0, 1);     if (dp[bi][pos].second != -1 && !flag && !leading) {       return dp[bi][pos];     }     long long ans = 0;     long long cnt = 0;     int upper = (flag ? a[n - pos - 1] -  0  : 9);     for (int i = 0; i <= upper; i++) {       int nextstate = (bi | (1 << i));       if ((bi & (1 << i)) == 0 && !(leading && i == 0)) {         if (bitcnt[nextstate] > k) continue;         pair<long long, long long> p =             dfs(nextstate, pos - 1, flag && (i == upper), leading && (i == 0));         cnt = (cnt + p.second) % 998244353;         ans = (ans +                ((((p.second * i) % 998244353) * p10[pos]) % 998244353 + p.first) %                    998244353) %               998244353;       } else {         pair<long long, long long> p =             dfs(bi, pos - 1, flag && (i == upper), leading && (i == 0));         cnt = (cnt + p.second) % 998244353;         ans = (ans +                ((((p.second * i) % 998244353) * p10[pos]) % 998244353 + p.first) %                    998244353) %               998244353;       }     }     if (!flag && !leading) {       dp[bi][pos] = make_pair(ans % 998244353, cnt % 998244353);     }     return make_pair(ans % 998244353, cnt % 998244353);   }   long long solve(long long num) {     a = to_string(num);     n = (int)a.length();     pair<long long, long long> p = dfs(0, n - 1, 1, 1);     return p.first % 998244353;   }   int main() {     long long l, r;     int i, j;     p10[0] = 1;     for (i = 1; i <= 20; i++) {       p10[i] = (p10[i - 1] * 10) % 998244353;     }     for (i = 0; i < 1100; i++) {       for (j = 0; j < 20; j++) {         dp[i][j] = make_pair(0, -1);       }     }     bitcnt[0] = 0;     bitcnt[1] = 1;     for (i = 2; i < 1100; i++) bitcnt[i] = bitcnt[i - (i & -i)] + 1;     cin >> l >> r >> k;     cout << (solve(r) - solve(l - 1) + 998244353) % 998244353 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   string s;   int main() {     int t, cas = 1;     cin >> s;     int n = ((int)(s).size());     for (int i = 1; i <= n / 2; i++) {       int cnt = 0;       for (int j = 0; j < n - i; j++) {         if (s[j] == s[j + i])           cnt++;         else           cnt = 0;         if (cnt == i) {           s = s.substr(0, j - i + 1) + s.substr(j + 1, n - j - 1);           n -= i;           i = 0;           break;         }       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int b[200005];     vector<int> a;     cin >> n;     a.push_back(31);     a.push_back(28);     a.push_back(31);     a.push_back(30);     a.push_back(31);     a.push_back(30);     a.push_back(31);     a.push_back(31);     a.push_back(30);     a.push_back(31);     a.push_back(30);     a.push_back(31);     for (int i = 0; i < n; i++) {       cin >> b[i];     }     for (int i = 0; i < 12; i++) {       int count = 0, f = 0;       for (int j = 0; j < n; j++) {         if ((i + j) % 12 == 1) {           if (a[(i + j) % 12] == b[j])             continue;           else {             if (a[(i + j) % 12] == 28 && b[j] == 29 && count == 0) {               count = 1;               continue;             }           }         }         if (a[(i + j) % 12] != b[j]) {           f = 1;           break;         }       }       if (f == 0) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( sse4,avx )   const double pi = 3.14159265358979323;   struct dpoint {     double x, y;     dpoint() : x(0), y(0) {}     dpoint(double x, double y) : x(x), y(y) {}   };   void run(std::istream& in, std::ostream& out) {     int n;     dpoint p;     in >> n >> p.x >> p.y;     std::vector<dpoint> points(n);     for (int i = 0; i < n; i++) {       in >> points[i].x >> points[i].y;     }     double maxR = 0;     double minR = 1e10;     for (int i = 0; i < n; i++) {       double dist1 = hypot(points[i].x - p.x, points[i].y - p.y);       maxR = std::max(maxR, dist1);       minR = std::min(minR, dist1);       dpoint& p1 = points[i];       dpoint& p2 = points[(i + 1) % n];       if ((p2.x - p1.x) * (p.x - p1.x) + (p2.y - p1.y) * (p.y - p1.y) > 0.5 &&           (p1.x - p2.x) * (p.x - p2.x) + (p1.y - p2.y) * (p.y - p2.y) > 0.5) {         double a = p1.y - p2.y;         double b = p2.x - p1.x;         double dist = a * p.x + b * p.y - a * p1.x - b * p1.y;         dist /= hypot(a, b);         minR = std::min(minR, std::abs(dist));       }     }     out.precision(20);     out << std::fixed;     out << (maxR * maxR - minR * minR) * pi << std::endl;   }   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     run(std::cin, std::cout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fastInOut() {     ios_base::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);   }   int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};   int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};   int main() {     double m, n, total = 0.0;     cin >> m >> n;     for (double i = 1; i <= m; i++) {       double temp = pow(i / m, n) - pow((i - 1) / m, n);       temp *= i;       total += temp;     }     cout << fixed << setprecision(12) << total;   }
#include <bits/stdc++.h>   using namespace std;   const int _1e5 = 100000;   const int _1e7 = 10000000;   const int _1e9 = 1000000000;   template <typename A, typename B>   ostream& operator<<(ostream& str, const pair<A, B>& p) {     return str <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& str, const vector<T>& v) {     str <<  [ ;     for (const auto& n : v) str << n <<  ,  ;     str <<  ] ;     return str;   }   template <typename T>   ostream& operator<<(ostream& str, const set<T>& v) {     str <<  { ;     for (const auto& n : v) {       str << n <<  ,  ;     }     str <<  } ;     return str;   }   template <typename K, typename V>   ostream& operator<<(ostream& str, const unordered_map<K, V>& v) {     str <<  { ;     for (const auto& p : v) {       str << p.first <<   =>   << p.second <<  ,  ;     }     str <<  } ;     return str;   }   int main() {     ios_base::sync_with_stdio(false);     cout.setf(std::ios::fixed);     cout.precision(12);     int n;     cin >> n;     string a;     cin >> a;     vector<int> f(10);     f[0] = 0;     for (int i = 1; i <= 9; ++i) {       cin >> f[i];     }     int left_start = -1;     for (int i = 0; i < a.size(); ++i) {       int digit = a[i] -  0 ;       if (f[digit] > digit) {         left_start = i;         break;       }     }     if (left_start == -1) {       cout << a << endl;       return 0;     }     while (true) {       if (left_start >= a.size()) {         break;       }       int digit = a[left_start] -  0 ;       if (f[digit] < digit) {         break;       }       a[left_start++] =  0  + f[digit];     }     cout << a << endl;   }
#include <bits/stdc++.h>   using namespace std;   int w[2][2];   int kb[2], kc[2];   int size[10][10];   string s;   int main() {     ios_base::sync_with_stdio(0);     for (int i = 0; i <= (int)(2) - 1; i++) {       cin >> s;       w[i][0] = s[0] -  a ;       w[i][1] = s[1] -  1 ;     }     cin >> s;     kb[0] = s[0] -  a ;     kb[1] = s[1] -  1 ;     cin >> s;     kc[0] = s[0] -  a ;     kc[1] = s[1] -  1 ;     for (int i = 0; i <= (int)(10) - 1; i++)       for (int j = 0; j <= (int)(10) - 1; j++) size[i][j] = 0;     int x, y;     for (int ii = 0; ii <= (int)(2) - 1; ii++) {       for (int i = w[ii][0] + 1; i <= 7; i++) {         if (i == kb[0] && w[ii][1] == kb[1]) break;         size[i][w[ii][1]] = 1;       }       for (int i = w[ii][0] - 1; i >= 0; i--) {         if (i == kb[0] && w[ii][1] == kb[1]) break;         size[i][w[ii][1]] = 1;       }       for (int j = w[ii][1] + 1; j <= 7; j++) {         if (w[ii][0] == kb[0] && j == kb[1]) break;         size[w[ii][0]][j] = 1;       }       for (int j = w[ii][1] - 1; j >= 0; j--) {         if (w[ii][0] == kb[0] && j == kb[1]) break;         size[w[ii][0]][j] = 1;       }     }     for (int i = -1; i <= 1; i++)       for (int j = -1; j <= 1; j++) {         int a = i + kb[0], b = j + kb[1];         if (a >= 0 && a < 8 && b >= 0 && b < 8) {           size[a][b] = 1;         }       }     for (int i = -1; i <= 1; i++)       for (int j = -1; j <= 1; j++) {         int a = i + kc[0], b = j + kc[1];         if (a >= 0 && a < 8 && b >= 0 && b < 8) {           if (size[a][b]) {           } else {             cout <<  OTHER n ;             return 0;           }         }       }     cout <<  CHECKMATE n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5 + 10;   int a[MAX_N];   vector<pair<int, int>> scanCuts[2][MAX_N];   pair<int, int> cuts[MAX_N];   int tree[2 * MAX_N], d[2 * MAX_N];   void push(int i) {     d[2 * i + 1] += d[i];     d[2 * i + 2] += d[i];     tree[2 * i + 1] += d[i];     tree[2 * i + 2] += d[i];     d[i] = 0;   }   void pull(int i) {     tree[i] = min(tree[2 * i + 1], tree[2 * i + 2]);     tree[i] += d[i];   }   void build(int i, int l, int r) {     if (r - l == 1) {       tree[i] = a[l];       return;     }     int mid = (l + r) / 2;     build(2 * i + 1, l, mid);     build(2 * i + 2, mid, r);     pull(i);   }   void add(int l, int r, int x, int i, int cl, int cr) {     if (r <= cl || cr <= l) return;     if (l <= cl && cr <= r) {       tree[i] += x;       d[i] += x;       return;     }     int mid = (cl + cr) / 2;     add(l, r, x, 2 * i + 1, cl, mid);     add(l, r, x, 2 * i + 2, mid, cr);     pull(i);   }   int get(int l, int r, int i, int cl, int cr) {     if (r <= cl || cr <= l) return +1e9;     if (l <= cl && cr <= r) return tree[i];     int mid = (cl + cr) / 2;     push(i);     return min(get(l, r, 2 * i + 1, cl, mid), get(l, r, 2 * i + 2, mid, cr));   }   void print(int i, int cl, int cr) {     cout << i <<   (  << cl <<  ;   << cr <<  ) ->   << tree[i] <<     << d[i]          <<   n ;     if (cr - cl == 1) return;     int mid = (cl + cr) / 2;     print(2 * i + 1, cl, mid);     print(2 * i + 2, mid, cr);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     for (int i = 0; i < n; ++i) cin >> a[i];     build(0, 0, n);     set<int> bestAns;     set<int> currAns;     for (int i = 0; i < q; ++i) {       cin >> cuts[i].first >> cuts[i].second;       --cuts[i].first;       currAns.insert(i);       add(cuts[i].first, cuts[i].second, -1, 0, 0, n);       scanCuts[0][cuts[i].first].push_back({cuts[i].second, i});       scanCuts[1][cuts[i].second].push_back({cuts[i].first, i});     }     int ans = 0;     for (int i = 0; i < n; ++i) {       for (auto u : scanCuts[0][i]) {         add(i, u.first, 1, 0, 0, n);         currAns.erase(u.second);       }       for (auto u : scanCuts[1][i]) {         add(u.first, i, -1, 0, 0, n);         currAns.insert(u.second);       }       int lans = get(i, i + 1, 0, 0, n) - get(0, n, 0, 0, n);       if (lans > ans) {         ans = lans;         bestAns = currAns;       }     }     cout << ans <<   n ;     cout << bestAns.size() <<   n ;     for (int u : bestAns) cout << u + 1 <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isprime(long long n) {     if (n == 1) return false;     if (n == 2) return true;     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long poww(long long b, long long e) {     if (e == 0)       return 1;     else if (e % 2 == 0) {       long long a = pow(b, e / 2);       return a * a;     } else {       long long a = pow(b, e / 2);       return b * a * a;     }   }   long long powm(long long x, long long y, long long m = 1000000007) {     x = x % m;     long long res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long modInverse(long long a, long long m = 1000000007) {     return powm(a, m - 2, m);   }   void print(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }   }   void print(long long arr[]) {     long long size = *(&arr + 1) - arr;     for (long long i = 0; i < size; i++) {       cout << arr[i] <<    ;     }   }   string to_bin(long long n) {     string res =   ;     long long i = 0;     while (n > 0) {       if (n % 2 == 1) {         res = res +  1 ;       } else {         res = res +  0 ;       }       n /= 2;       i++;     }     reverse(res.begin(), res.end());     return res;   }   long long to_dec(string second) {     long long n = second.size(), ans = 0, temp = 1;     for (long long i = n - 1; i >= 0; i--) {       long long x = second[i] -  0 ;       ans += x * temp;       temp *= 2;     }     return ans;   }   void result(bool first) {     if (first)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   void solve() {     long long a, b, p;     cin >> a >> b >> p;     string second;     cin >> second;     reverse(second.begin(), second.end());     long long n = second.length();     long long ind = 1;     long long maxi;     for (long long i = 1; i < n; i++) {       char ch = second[i];       if (second[i] ==  B ) {         if (p >= b) {           p -= b;           if (i != n - 1) {             while (second[i + 1] ==  B ) {               i++;             }           }           ind = i + 1;         } else           break;       } else if (second[i] ==  A ) {         if (p >= a) {           p -= a;           if (i != n - 1) {             while (second[i + 1] ==  A ) {               i++;             }           }           ind = i + 1;         } else           break;       }     }     long long ans = n - ind + 1;     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio();     cin.tie(0);     cout.tie(0);     long long tests;     cin >> tests;     while (tests--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int C = 10005, N = 1005;   int n, w, b, x, c[N], cost[N];   long long dp[2][C];   template <class T>   void maxz(T &a, T b) {     if (a < b) a = b;   }   int main() {     int i, j, k, ub;     long long mn;     scanf( %d%d%d%d , &n, &w, &b, &x);     for (i = 1; i <= n; i++) scanf( %d , c + i);     for (i = 1; i <= n; i++) scanf( %d , cost + i);     memset(dp[0], -1, sizeof(dp[0]));     ub = 1;     dp[0][0] = w;     for (i = 1; i <= n; i++) {       memset(dp[i & 1], -1, sizeof(dp[0]));       for (j = 0; j < ub; j++)         if (dp[~i & 1][j] >= 0) {           mn = min(dp[~i & 1][j] + x, w + (long long)b * j);           for (k = 0; k <= c[i] && mn >= 0; k++) {             maxz(dp[i & 1][j + k], mn);             mn -= cost[i];           }           maxz(ub, j + k);         }     }     printf( %d , ub - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int r = 2, g = 5, b = 8, n, k;   int h, j, p;   int main() {     cin >> n >> k;     h = r * n;     j = g * n;     p = b * n;     h = (h + k - 1) / k;     j = (j + k - 1) / k;     p = (p + k - 1) / k;     cout << p + j + h;   }
#include <bits/stdc++.h>   int sw, sw1, sw2;   int main() {     char a[1000];     scanf( %s , a);     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       char b[10];       scanf( %s , b);       if (b[0] == a[0] && b[1] == a[1]) sw = 1;       if (b[1] == a[0]) sw1 = 1;       if (b[0] == a[1]) sw2 = 1;     }     if (sw == 1 || sw1 == 1 && sw2 == 1)       printf( YES );     else       printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<long long>> dp(10, vector<long long>(1000005, 0));   long long g(long long n) {     if (n < 10) return n;     long long ans = 1;     while (n) {       if (n % 10) ans *= (n % 10);       n /= 10;     }     return g(ans);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (long long i = 1; i <= 1000000; i++) dp[g(i)][i]++;     for (long long i = 0; i < 10; i++) {       for (long long j = 2; j <= 1000000; j++) {         dp[i][j] += dp[i][j - 1];       }     }     long long t;     cin >> t;     while (t--) {       long long l, r, k;       cin >> l >> r >> k;       cout << dp[k][r] - dp[k][l - 1] <<   n ;     }   }
#include <bits/stdc++.h>   const int MOD = 1e9;   const int N = 100003;   using namespace std;   vector<int> ans;   int main() {     int n;     cin >> n;     int p, q;     p = q = 0;     for (int i = 0; i < n; i++) {       char c;       int x, y;       cin >> c;       scanf( %d , &x);       scanf( %d , &y);       if (x > y) swap(x, y);       if (c ==  + )         p = max(p, x), q = max(q, y);       else if (p <= x && q <= y)         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 69;   const int inf = 1e9 + 5;   const long long mod = 1e9 + 7;   const long double eps = 1e-10;   vector<int> v[MX];   int par[24][MX];   int depth[MX];   void dfs(int x, int p) {     for (auto g : v[x]) {       if (g == p) {         continue;       }       depth[g] = depth[x] + 1;       dfs(g, x);       par[0][g] = x;     }   }   int lca(int x, int y) {     if (depth[x] > depth[y]) swap(x, y);     int i = 22;     while (depth[x] < depth[y]) {       if (depth[par[i][y]] >= depth[x]) {         y = par[i][y];       }       i--;     }     for (int i = 22; i >= 0; i--) {       if (par[i][x] != par[i][y]) {         x = par[i][x];         y = par[i][y];       }     }     if (x != y) {       x = par[0][x];       y = par[0][y];     }     return x;   }   int dis(int a, int b) { return (depth[a] + depth[b] - 2 * depth[lca(a, b)]); }   int cal(int a, int b, int c) {     int ret = 0;     int q1 = lca(a, b);     int q2 = lca(a, c);     int q3 = lca(b, c);     if (depth[q1] >= max(depth[q2], depth[q3])) {       ret = dis(lca(a, b), c);     } else {       ret = dis((depth[q2] >= depth[q3] ? q2 : q3), c);     }     return ret;   }   int main() {     depth[0] = -1;     int n, q;     cin >> n >> q;     for (int i = 2; i <= n; i++) {       int b;       scanf( %d , &b);       v[i].push_back(b);       v[b].push_back(i);     }     dfs(1, -1);     for (int i = 1; i < 23; i++) {       for (int j = 1; j <= n; j++) {         par[i][j] = par[i - 1][par[i - 1][j]];       }     }     while (q--) {       int ans = 0;       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       ans = max(cal(a, b, c), max(cal(a, c, b), cal(b, c, a)));       printf( %d n , ans + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<int>> g(n);     vector<pair<int, int>> e(n - 1);     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       --u;       --v;       g[u].push_back(v);       g[v].push_back(u);       e[i] = make_pair(u, v);     }     vector<int> col(n);     for (int &i : col) {       cin >> i;     }     int diff = 0;     for (auto i : e) {       if (col[i.first] != col[i.second]) {         ++diff;       }     }     for (int i = 0; i < n; ++i) {       int ctr = 0;       for (int j : g[i]) {         if (col[i] != col[j]) {           ++ctr;         }       }       if (ctr == diff) {         cout <<  YES n  << i + 1;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   int cnt;   int n, m, k;   char s[1111][1111];   int c[1111][1111], vis[1111][1111];   int b[1111];   int tot;   void dfs(int p, int q) {     c[p][q] = cnt;     vis[p][q] = 1;     if (s[p - 1][q] ==  .  && !vis[p - 1][q]) dfs(p - 1, q);     if (s[p - 1][q] ==  * ) tot++;     if (s[p + 1][q] ==  .  && !vis[p + 1][q]) dfs(p + 1, q);     if (s[p + 1][q] ==  * ) tot++;     if (s[p][q - 1] ==  .  && !vis[p][q - 1]) dfs(p, q - 1);     if (s[p][q - 1] ==  * ) tot++;     if (s[p][q + 1] ==  .  && !vis[p][q + 1]) dfs(p, q + 1);     if (s[p][q + 1] ==  * ) tot++;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);     for (int i = 0; i <= m + 1; i++) {       s[0][i] = s[n + 1][i] =  # ;     }     for (int i = 1; i <= n; i++) s[i][0] = s[i][m + 1] =  # ;     cnt = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) vis[i][j] = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (!vis[i][j] && s[i][j] ==  . ) {           tot = 0;           cnt++;           dfs(i, j);           b[cnt] = tot;         }     for (int i = 1; i <= k; i++) {       int x, y;       scanf( %d%d , &x, &y);       printf( %d n , b[c[x][y]]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, true : false;   }   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, true : false;   }   int readint() {     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;   }   int n, k;   int a[20];   bitset<2001> d[66000];   multiset<pair<int, int> > s;   void solve(int now, int cs, int r) {     if (!now) return;     while (cs <= 2000) {       for (int i = 1; i <= n; i++) {         if (((now >> (i - 1)) & 1) && cs >= a[i] &&             d[now ^ (1 << (i - 1))][cs - a[i]]) {           s.insert(make_pair(-r, a[i]));           solve(now ^ (1 << (i - 1)), cs - a[i], r);           return;         }       }       cs = cs * k, r++;     }     assert(0);   }   int main() {     n = readint();     k = readint();     for (int i = 1; i <= n; i++) a[i] = readint();     d[0][0] = 1;     for (int i = 1; i < (1 << n); i++) {       for (int j = 1; j <= n; j++)         if ((i >> (j - 1)) & 1) d[i] |= d[i ^ (1 << (j - 1))] << a[j];       for (int j = 2000 / k; j >= 1; j--)         if (d[i][j * k]) d[i][j] = 1;     }     if (!d[(1 << n) - 1][1]) return printf( NO n ), 0;     printf( YES n );     solve((1 << n) - 1, 1, 0);     while (s.size() > 1) {       auto it1 = s.begin(), it2 = it1;       it2++;       assert(it1->first == it2->first);       printf( %d %d n , it1->second, it2->second);       int tmp = it1->second + it2->second, dep = -it1->first;       while (tmp % k == 0) tmp /= k, dep--;       s.erase(it1);       s.erase(it2);       s.insert(make_pair(-dep, tmp));     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, c, ab = -1, min;     scanf( %d %d %d , &a, &b, &c);     min = b;     if (a < b) min = a;     for (int i = 0; i <= min; i++) {       if (b + a - 2 * i == c) {         ab = i;         break;       }     }     if (ab == -1)       printf( Impossible );     else       printf( %d %d %d , ab, b - ab, a - ab);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, b, d;     cin >> n >> b >> d;     int cur = 0, cnt = 0;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a > b) continue;       cur += a;       if (cur > d) {         cnt++;         cur = 0;       }     }     if (cur > d) cnt++;     cout << cnt << endl;     return 0;   }