malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, m, q, t, c;   string s;   long long inv[200007];   long long p[200007];   long long f[200007];   long long nq[200007];   long long mq[200007];   long long res[200007];   long long dp[200007];   vector<long long> que[200007];   long long fpow(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a % 1000000007;     if (b % 2)       return (a * fpow(a, b - 1)) % 1000000007;     else {       long long q = fpow(a, b / 2);       return (q * q) % 1000000007;     }   }   long long dziel(long long a, long long b) {     return (a * fpow(b % 1000000007, 1000000007 - 2)) % 1000000007;   }   long long choose(long long a, long long b) {     return dziel(f[a], f[b] * f[a - b]);   }   void solve(long long m) {     memset(dp, 0, sizeof dp);     dp[m] = 1;     long long dwumian = 1;     for (long long i = m + 1; i <= 1e5; ++i) {       dwumian = (((dwumian * (i - 1)) % 1000000007) * inv[i - m]) % 1000000007;       dp[i] = (26 * dp[i - 1] + dwumian * p[i - m]) % 1000000007;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     f[0] = 1;     p[0] = 1;     for (long long i = 1; i < 200007; ++i) {       f[i] = (f[i - 1] * i) % 1000000007;       p[i] = (25 * p[i - 1]) % 1000000007;       inv[i] = fpow(i, 1000000007 - 2);     }     cin >> q >> s;     m = s.size();     for (long long i = 1; i <= q; ++i) {       cin >> t;       if (t == 1) {         cin >> s;         m = s.size();       } else {         cin >> n;         nq[++c] = n;         mq[c] = m;         que[m].push_back(c);       }     }     for (long long i = 1; i <= 1e5; ++i) {       if (!que[i].empty()) solve(i);       for (auto it : que[i]) res[it] = dp[nq[it]];     }     for (long long i = 1; i <= c; ++i) {       cout << res[i] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const long long NLINF = 0xf7f7f7f7f7f7f7f7;   const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;   const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;   const int N = 1e5 + 10;   vector<int> sz;   int t, n, lst;   int main() {     for (scanf( %d , &t); t--;) {       scanf( %d , &n), lst = -1;       printf( 1 );       while (n > 0) {         ;         int k = 1;         while (k * (k - 1) / 2 <= n) k++;         k--;         if (lst != -1) sz.emplace_back(lst - k);         lst = k, n -= k * (k - 1) / 2;       }       sz.emplace_back(lst);       ;       reverse(sz.begin(), sz.end());       for (auto &x : sz) {         for (int i = 0; i < x; i++) printf( 3 );         printf( 7 );       }       sz.clear();       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int s, n, a[10000] = {0}, m = -1, y, i;     cin >> s >> n;     int c = n;     while (n--) {       cin >> i >> y;       a[i] += y;       m = max(m, i);     }     for (int i = 0; i < 10000; i++) {       if (s > i) {         s += a[i];       }     }     s > m ? cout <<  YES  : cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, m, k, x, y, z;     cin >> n >> m >> k;     vector<long long> v(n + 1);     vector<long long> s(n + 2, 0);     vector<long long> m1(m + 1);     vector<long long> m2(m + 1);     vector<long long> m3(m + 1);     vector<long long> k1(m + 2);     for (long long i = 1; i <= n; ++i) {       cin >> x;       v[i] = x;     }     for (long long i = 1; i <= m; ++i) {       cin >> x >> y >> z;       m1[i] = x;       m2[i] = y;       m3[i] = z;     }     for (long long i = 1; i <= k; ++i) {       cin >> x >> y;       k1[x] += 1;       k1[y + 1] += -1;     }     long long sum = 0;     for (long long i = 1; i <= m; ++i) {       sum += k1[i];       s[m1[i]] += sum * m3[i];       s[m2[i] + 1] -= sum * m3[i];     }     sum = 0;     for (long long i = 1; i <= n; ++i) {       s[i] += sum;       sum = s[i];     }     for (long long i = 1; i <= n; ++i) {       s[i] += v[i];       cout << s[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int inf = 0x3f3f3f3f;   long long dp[maxn];   int n, m;   struct node {     int lb, lu;     long long w;   };   vector<node> ve[maxn];   int lb, lu;   long long w, cost[maxn];   struct seg {     long long ma, lazy;   } tr[maxn << 2];   void build(int o, int l, int r) {     tr[o].ma = 0;     tr[o].lazy = 0;     if (l == r) {       return;     }     int mid = (l + r) >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);   }   void pushup(int o) { tr[o].ma = max(tr[o << 1].ma, tr[o << 1 | 1].ma); }   void pushdown(int o) {     if (tr[o].lazy) {       tr[o << 1].ma += tr[o].lazy;       tr[o << 1 | 1].ma += tr[o].lazy;       tr[o << 1].lazy += tr[o].lazy;       tr[o << 1 | 1].lazy += tr[o].lazy;       tr[o].lazy = 0;     }   }   void update(int o, int l, int r, int ql, int qr, long long val) {     if (ql <= l && qr >= r) {       tr[o].ma += val;       tr[o].lazy += val;       return;     }     pushdown(o);     int mid = (l + r) >> 1;     if (ql <= mid) update(o << 1, l, mid, ql, qr, val);     if (qr > mid) update(o << 1 | 1, mid + 1, r, ql, qr, val);     pushup(o);   }   long long query(int o, int l, int r, int ql, int qr) {     if (ql <= l && qr >= r) {       return tr[o].ma;     }     pushdown(o);     int mid = (l + r) >> 1;     long long maxx = 0;     if (ql <= mid) maxx = max(maxx, query(o << 1, l, mid, ql, qr));     if (qr > mid) maxx = max(maxx, query(o << 1 | 1, mid + 1, r, ql, qr));     return maxx;   }   int main() {     while (cin >> n >> m) {       for (int i = 1; i <= n; i++) {         scanf( %lld , &cost[i]);         ve[i].clear();       }       for (int i = 1; i <= m; i++) {         scanf( %d%d%lld , &lb, &lu, &w);         ve[lu].push_back({lb, lu, w});       }       build(1, 0, n);       long long maxx = 0;       for (int i = 1; i <= n; i++) {         dp[i] = dp[i - 1];         update(1, 0, n, 0, i - 1, -cost[i]);         for (int j = 0; j < ve[i].size(); j++) {           lb = ve[i][j].lb, w = ve[i][j].w;           update(1, 0, n, 0, lb - 1, w);         }         dp[i] = max(dp[i], query(1, 0, n, 0, i - 1));         update(1, 0, n, i, i, dp[i]);         maxx = max(maxx, dp[i]);       }       printf( %lld n , maxx);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     unsigned long long ans = 1, ans2 = 1;     for (int i = 0; i < n; i++) {       ans = (ans * 27);       ans2 = (ans2 * 7);       if (ans2 > 1000000007 || ans % 1000000007 > ans2) {         ans %= 1000000007;         ans2 %= 1000000007;       }     }     cout << (1000000007 + ans - ans2) % 1000000007 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int read_number(int i) {     cout <<  ?   << i <<   n ;     fflush(stdout);     int number;     cin >> number;     return number;   }   bool intersects(int l1, int l2, int r1, int r2) {     if (l1 >= l2) swap(l1, l2);     if (r1 >= r2) swap(r2, r1);     return max(l1, r1) <= min(l2, r2);   }   bool contains(int l1, int l2, int r1, int r2) {     if (l1 >= l2) swap(l1, l2);     if (r1 >= r2) swap(r1, r2);     return (l1 <= r1 && l2 >= r2) || (r1 <= l1 && l2 <= r2);   }   bool dif(int l1, int l2, int r1, int r2) { return (l2 - l1) * (r2 - r1) <= 0; }   bool solution(int l1, int l2, int r1, int r2) {     return (dif(l1, l2, r1, r2) && intersects(l1, l2, r1, r2)) ||            contains(l1, l2, r1, r2);   }   int main() {     int n;     cin >> n;     if ((n / 2) % 2 == 1) {       cout <<  ! -1 n ;       return 0;     }     int l1 = read_number(1);     int r1 = read_number(n / 2 + 1);     int l2 = r1;     int r2 = l1;     int min_l1 = 1;     int max_l1 = n / 2 + 1;     int min_r1 = n / 2 + 1;     int max_r2 = n + 1;     if (l1 == r1) {       cout <<  !   << l1 <<   n ;       return 0;     }     while (true) {       int med_l1 = (1 + min_l1 + max_l1) / 2;       int med_r2 = (1 + min_r1 + max_r2) / 2;       int temp_l1 = read_number(med_l1);       int temp_r1 = read_number(med_r2);       if (temp_l1 == temp_r1) {         cout <<  !   << med_l1 <<   n ;         return 0;       }       if (solution(l1, temp_l1, r1, temp_r1)) {         l2 = temp_l1;         r2 = temp_r1;         max_l1 = med_l1;         max_r2 = med_r2;       } else {         l1 = temp_l1;         r1 = temp_r1;         min_l1 = med_l1;         min_r1 = med_r2;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t, k;   vector<int> g[200010];   int par[200010];   int nodeId;   int leaf;   vector<int> deep[200010];   int a[200010];   void createGraph(int x, int level) {     if (level > t) return;     for (int i = 1; i <= a[level]; i++) {       g[x].push_back(++nodeId);       par[nodeId] = x;       deep[level].push_back(nodeId);     }     leaf += a[level];     if (level != t) leaf--;     createGraph(nodeId, level + 1);   }   void adjust(int dp) {     queue<int> Q;     for (int i : deep[dp]) {       if (g[i].size() == 0) {         Q.push(i);       }     }     int size = deep[dp + 1].size();     for (int i = 0; i < size - 1; i++) {       if (Q.empty()) break;       if (leaf <= k) break;       int node = deep[dp + 1][i];       par[node] = Q.front();       Q.pop();       --leaf;     }   }   int main(int argc, char const *argv[]) {     nodeId = 1;     scanf( %d %d %d , &n, &t, &k);     for (int i = 1; i <= t; i++) {       scanf( %d , a + i);     }     createGraph(1, 1);     if (leaf < k) {       printf( -1 n );       exit(0);     }     for (int i = 1; i < t; i++) {       adjust(i);     }     if (leaf != k) {       printf( -1 n );       exit(0);     }     printf( %d n , n);     for (int i = 2; i <= n; i++) {       printf( %d %d n , par[i], i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long m, k;     cin >> n >> m >> k;     vector<long long> arr(n);     long long max1 = -1;     long long max2 = -2;     long long temp;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] > max2) {         max2 = arr[i];       }       if (max2 > max1) {         temp = max2;         max2 = max1;         max1 = temp;       }     }     long long cycle = (max1 * k) + max2;     long long period = k + 1;     long long ans = (m / period) * cycle;     ans += (m % period) * max1;     cout << ans;   }
#include <bits/stdc++.h>   template <class T>   inline T lowbit(T x) {     return x & (-x);   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline bool scan(T &ret) {     char c;     int sgn;     if (c = getchar(), c == EOF) return 0;     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     sgn = (c ==  - ) ? -1 : 1;     ret = (c ==  - ) ? 0 : (c -  0 );     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     ret *= sgn;     return 1;   }   const double pi = 3.14159265358979323846264338327950288L;   using namespace std;   int n, pre;   char a[100005];   bool vis[100005];   pair<int, int> q[100005];   vector<int> ans[100005], num;   long long Pow[100005], fac[100005], rev[100005];   long long qpow(long long a, long long b) {     if (b == 0) return 1;     long long ans = qpow(a, b >> 1);     ans = ans * ans % 1000000007;     if (b & 1) ans = ans * a % 1000000007;     return ans;   }   long long C(int m, int n) {     if (m < n) return 0;     return fac[m] * rev[n] % 1000000007 * rev[m - n] % 1000000007;   }   void solve() {     fac[0] = 1;     for (int i = 1; i < 100005; i++) fac[i] = fac[i - 1] * i % 1000000007;     rev[100005 - 1] = qpow(fac[100005 - 1], 1000000007 - 2);     for (int i = 100005 - 2; i >= 0; i--)       rev[i] = rev[i + 1] * (i + 1) % 1000000007;     for (int i = 0; i < 100005; i++) ans[i].clear();     num.clear();     Pow[0] = 1;     for (int i = 1; i < 100005; i++) Pow[i] = Pow[i - 1] * 25 % 1000000007;     for (int i = 1; i <= 100000; i++)       if (vis[i]) {         num.push_back(i);         for (int j = 0; j < 100005; j++) {           if (j < i) {             ans[i].push_back(0);             continue;           }           long long tmp = 1LL * ans[i][j - 1] * 26 % 1000000007 +                           C(j - 1, i - 1) * Pow[j - i] % 1000000007;           ans[i].push_back(tmp % 1000000007);         }       }     for (int i = 0; i < n; i++) {       if (q[i].first == 1) {         pre = q[i].second;       } else {         int k = *(lower_bound(num.begin(), num.end(), pre));         printf( %d n , ans[k][q[i].second]);       }     }   }   int main() {     memset(vis, 0, sizeof(vis));     cin >> n >> a;     vis[pre = strlen(a)] = 1;     for (int i = 0; i < n; i++) {       cin >> q[i].first;       if (q[i].first == 1) {         cin >> a;         int len = strlen(a);         q[i].second = len;         vis[len] = 1;       } else {         cin >> q[i].second;       }     }     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main()   {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin>>t;     while(t--)     {       int n;       cin>>n;       vector<long long int>a(n);       for(int i=0;i<n;i++)         cin>>a[i];       sort(a.begin(),a.end());       long long int as=0,bs=0,turn=0;       for(int i=n-1;i>=0;i--)       {         if(turn==0)         {           if(a[i]%2==0)           {             as+=a[i];           }         }         else          {           if(a[i]&1)           {             bs+=a[i];           }         }         turn=1-turn;       }       if(as>bs)         cout<< Alice <<endl;       else if(bs>as)         cout<< Bob <<endl;       else         cout<< Tie <<endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 55;   int n, num, h[N], siz[N], e[N << 1], pre[N << 1];   double g[N], C[N][N], f[N][N];   inline void add(int x, int y) { e[++num] = y, pre[num] = h[x], h[x] = num; }   void dfs(int u, int fa = 0) {     memset(f[u], 0, sizeof f[u]), f[u][0] = siz[u] = 1;     for (int i = h[u]; i; i = pre[i])       if (e[i] != fa) {         dfs(e[i], u), siz[u] += siz[e[i]];         memset(g, 0, sizeof g);         for (int j = 0; j < siz[e[i]]; ++j) g[j] = f[e[i]][j] * (siz[e[i]] - j);         for (int j = 1; j <= siz[e[i]]; ++j)           for (int k = 0; k < j; ++k) g[j] += f[e[i]][k] / 2;         for (int j = siz[u]; j--;) {           f[u][j] = f[u][j] * g[0] * C[siz[u] - 1 - j][siz[e[i]]];           for (int k = 1; k <= siz[e[i]]; ++k)             f[u][j] +=                 f[u][j - k] * g[k] * C[siz[u] - 1 - j][siz[e[i]] - k] * C[j][k];         }       }   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i < n; ++i) scanf( %d%d , &x, &y), add(x, y), add(y, x);     C[0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= i; ++j)         C[i][j] = (j ? C[i - 1][j - 1] : 0) + C[i - 1][j];     double k = 1;     for (int i = 1; i < n; ++i) k /= i;     for (int i = 1; i <= n; ++i) dfs(i), printf( %.10lf n , f[i][n - 1] * k);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (1e6) + 5;   const int M = (60) + 5;   int memo[M][M];   int n, a[N];   int grundy(int n, int last) {     if (n == 0) {       return 0;     }     int &ret = memo[n][last];     if (ret != -1) return ret;     set<int> S;     for (int i = last + 1; i <= n; i += 1) {       S.insert(grundy(n - i, i));     }     ret = 0;     while (S.count(ret)) ret++;     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     memset(memo, -1, sizeof memo);     int g = 0;     for (int i = 0; i < n; i += 1) {       g ^= grundy(a[i], 0);     }     cout << (g == 0 ?  YES  :  NO ) <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse4 )   using namespace std;   const int MOD = 1e9 + 7;   const int MX = 2e5 + 5;   const long long INF = 1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-6;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const char nl =   n ;   template <typename T>   inline T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   void ckmin(T& a, T b) {     a = min(a, b);   }   template <class T>   void ckmax(T& a, T b) {     a = max(a, b);   }   int pct(int x) { return __builtin_popcount(x); }   int pct(long long x) { return __builtin_popcountll(x); }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << h;     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   void setIn(string s) { freopen(s.c_str(),  r , stdin); }   void setOut(string s) { freopen(s.c_str(),  w , stdout); }   void unsyncIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   void setIO(string s =   ) {     unsyncIO();     if ((int)s.size()) {       setIn(s +  .in ), setOut(s +  .out );     }   }   long long pow(long long b, long long e, long long m = 0LL,                 long long ans = 1LL) {     while (e) {       if (e & 1LL) {         ans *= b;         if (m) ans %= m;       }       b *= b, e >>= 1LL;       if (m) b %= m;     }     return ans;   }   void solve(int tcn) {     int n, m;     cin >> n >> m;     vector<vector<int> > l(n + 1, vector<int>(m + 1)),         r(n + 1, vector<int>(m + 1));     for (int i = (0); i < (n); ++i) {       int k;       cin >> k;       for (int j = (0); j < (k); ++j) {         int lll, rrr;         cin >> lll >> rrr;         for (int x = (lll); x < (rrr + 1); ++x) {           l[i + 1][x] = lll;           r[i + 1][x] = rrr;         }       }     }     vector<vector<long long> > dp(m + 2, vector<long long>(m + 2, 0LL));     for (int lll = m; lll >= 1; --lll) {       for (int rrr = (lll); rrr < (m + 1); ++rrr) {         for (int x = (lll); x < (rrr + 1); ++x) {           long long cnt = 0LL;           for (int k = (1); k < (n + 1); ++k)             if (l[k][x] >= lll && r[k][x] <= rrr) ++cnt;           ckmax(dp[lll][rrr], dp[lll][x - 1] + cnt * cnt + dp[x + 1][rrr]);         }       }     }     cout << dp[1][m] << nl;   }   int main() {     setIO();     int t = 1;     for (int i = 1; i <= t; ++i) {       solve(i);     }     return 0;   }
#include<bits/stdc++.h>   using namespace std;   int main(){       int t;       cin>>t;              while(t--){       string s;       cin>>s;              int n = s.length();              int i=0,j = n-1,k = n-1;       char z =  a ;              while(k>=0){           if(s[i] == z+k)           i++;           else if(s[j] == z+k)           j--;           else           break;                      k--;       }              if(k == -1)       cout<< YES <<endl;       else       cout<< NO <<endl;              }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long N = 1000L + 10;   const long long modulo = 1000000007L;   vector<pair<long, long> > interv;   bool memo[N][N];   bool visited[N];   void divideByZero(const char *error) {     printf(error);     fclose(stdout);     int a = 234;     a = a / (a - a);   }   bool canDirectly(long a, long b, long c, long d) {     return (c < a && a < d) || (c < b && b < d);   }   void addInterval(long x, long y) {     long n = interv.size();     interv.push_back(make_pair(x, y));     for (long i = 0; i < n; i++) {       if (canDirectly(interv[i].first, interv[i].second, x, y)) {         memo[i][n] = true;       }       if (canDirectly(x, y, interv[i].first, interv[i].second)) {         memo[n][i] = true;       }     }   }   bool pathExists(long from, long to) {     for (long i = 0; i < N; i++) visited[i] = false;     long n = interv.size();     queue<long> q;     visited[from] = true;     q.push(from);     while (!q.empty()) {       long v = q.front();       if (v == to) return true;       q.pop();       for (long nb = 0; nb < n; nb++)         if (memo[v][nb]) {           if (visited[nb]) continue;           visited[nb] = true;           q.push(nb);         }     }     return false;   }   int main() {     long n;     scanf( %ld  , &n);     for (long i = 0; i < n; i++)       for (long j = 0; j < n; j++) memo[i][j] = false;     for (long i = 0; i < n; i++) {       long mode, x, y;       scanf( %ld %ld %ld , &mode, &x, &y);       if (mode == 1)         addInterval(x, y);       else {         if (pathExists(x - 1, y - 1))           printf( YES n );         else           printf( NO n );       }     }     return 0;   }
#include <bits/stdc++.h>   constexpr int Maxn = 2e5 + 7;   constexpr int Maxm = 1e6 + 7;   constexpr int Mod = 1e9 + 7;   int n, k, sum, root;   void add(int bit[], int p, int v) {     for (; p < Maxn; p += p & -p) bit[p] = (bit[p] + v) % Mod;   }   int query(int bit[], int p) {     int res = 0;     for (; p; p -= p & -p) res = (res + bit[p]) % Mod;     return res;   }   struct Edge {     int nxt, to, w;   } e[Maxn << 1];   int head[Maxn], edge_cnt, res;   inline void add_edge(int u, int v, int w) {     e[++edge_cnt].to = v;     e[edge_cnt].nxt = head[u];     e[edge_cnt].w = w;     head[u] = edge_cnt;   }   int a[Maxn], siz[Maxn], f[Maxn];   int del[Maxn];   void getroot(int u, int fa) {     siz[u] = 1;     f[u] = 0;     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (!del[v] && v != fa) {         getroot(v, u);         siz[u] += siz[v];         f[u] = std::max(f[u], siz[v]);       }     }     f[u] = std::max(f[u], sum - siz[u]);     if (f[u] < f[root]) root = u;   }   int val[2][Maxn], num[2][Maxn];   void DFS(int u, int fa, int rcol, int col, int nxt, int tot, int opt) {     tot = (tot + a[u]) % Mod;     if (opt == 0) {       if (k >= nxt) {         int cnt = query(num[rcol], k - nxt + 1);         int cur = query(val[rcol], k - nxt + 1);         res = (res + 1LL * cnt * tot % Mod) % Mod;         res = (res + cur) % Mod;       }       if (k >= nxt + 1) {         int cnt = query(num[rcol ^ 1], k - nxt);         int cur = query(val[rcol ^ 1], k - nxt);         res = (res + 1LL * cnt * tot % Mod) % Mod;         res = (res + cur) % Mod;       }       if (k >= nxt) res = (res + tot) % Mod;     } else if (opt == 1) {       add(num[rcol], nxt + 1, 1);       add(val[rcol], nxt + 1, tot);     } else {       add(num[rcol], nxt + 1, Mod - 1);       add(val[rcol], nxt + 1, Mod - tot);     }     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to, w = e[i].w;       if (del[v] || v == fa) continue;       int nxtstp = nxt;       if (w != col) ++nxtstp;       DFS(v, u, rcol, w, nxtstp, tot, opt);     }   }   void solve(int u) {     del[u] = 1;     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to, w = e[i].w;       if (!del[v]) {         DFS(v, u, w, w, 0, a[u], 0);         DFS(v, u, w, w, 0, 0, 1);       }     }     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to, w = e[i].w;       if (!del[v]) DFS(v, u, w, w, 0, 0, -1);     }     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (!del[v]) {         root = 0, sum = siz[v];         getroot(v, 0);         solve(root);       }     }   }   int main() {     scanf( %d%d , &n, &k);     f[0] = sum = n;     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1, u, v, w; i <= n - 1; ++i) {       scanf( %d%d%d , &u, &v, &w);       add_edge(u, v, w), add_edge(v, u, w);     }     getroot(1, 0);     solve(root);     for (int i = 1; i <= n; ++i) res = (res + a[i]) % Mod;     printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   void rwFile() {     freopen( INP.inp ,  r , stdin);     freopen( OUT.out ,  w , stdout);   }   void solveC_VanyaAndScales() {     long long w, m;     cin >> w >> m;     if (w == 2) {       cout <<  YES ;       return;     }     int able = 1;     while (m) {       long long tmp = m % w;       m /= w;       if (tmp == w - 1) {         m++;         continue;       }       if (tmp == 1 || tmp == 0) continue;       able = 0;       break;     }     if (able == 1)       cout <<  YES ;     else       cout <<  NO ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     solveC_VanyaAndScales();   }