malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   const int N = 100005;   int n, m, k;   vector<int> adj[N];   int cnt[N];   int mark[N];   int pass;   int aux[N];   bool ta[N];   bool clique(int x) {     pass++;     mark[x] = pass;     int id = 0;     for (int i : adj[x])       if (!ta[i]) {         mark[i] = pass;         aux[id++] = i;       }     for (int i = 0; i < id; i++) {       for (int j = i + 1; j < id; j++) {         if (!binary_search(adj[aux[i]].begin(), adj[aux[i]].end(), aux[j]))           return 0;       }     }     return 1;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d %d %d , &n, &m, &k);       for (int i = 1; i <= n; i++) {         adj[i].clear();         cnt[i] = 0;         ta[i] = 0;       }       for (int i = 0; i < m; i++) {         int a, b;         scanf( %d %d , &a, &b);         adj[a].push_back(b);         adj[b].push_back(a);         cnt[b]++;         cnt[a]++;       }       for (int i = 1; i <= n; i++) {         sort(adj[i].begin(), adj[i].end());       }       priority_queue<ii> pq;       for (int i = 1; i <= n; i++) {         pq.push({-cnt[i], i});       }       bool ok = 0;       while (1) {         if (pq.empty()) break;         int c, x;         tie(c, x) = pq.top();         c = -c;         if (c != cnt[x]) {           pq.pop();           continue;         }         if (c >= k) {           vector<int> ans;           while (!pq.empty()) {             int c, x;             tie(c, x) = pq.top();             c = -c;             pq.pop();             if (c != cnt[x]) {               continue;             }             ans.push_back(x);           }           printf( 1 %d n , (int)ans.size());           for (int i : ans) {             printf( %d  , i);           }           printf(  n );           ok = 1;           break;         }         pq.pop();         if (c == k - 1) {           if (clique(x)) {             printf( 2 n );             printf( %d , x);             for (int i : adj[x])               if (!ta[i]) {                 printf(  %d , i);               }             printf(  n );             ok = 1;             break;           }         }         cnt[x] = 0;         ta[x] = 1;         for (int i : adj[x])           if (cnt[i]) {             cnt[i]--;             pq.push({-cnt[i], i});           }       }       if (!ok) {         printf( -1 n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ara[1000];   int rf[1000];   int main() {     int n, i, f, w, cnt = 0, m, r;     char str[1000001];     scanf( %d %d , &n, &m);     scanf( %s , str);     for (i = 0; i < n; i++) {       r = str[i];       ara[r] = ara[r] + 1;     }     for (i = 0; i < n; i++) {       r = str[i];       if (rf[r] == 0) {         cnt++;         rf[r] = 1;         if (cnt > m) {           printf( YES );           return 0;         }       }       ara[r] = ara[r] - 1;       if (ara[r] == 0) {         cnt--;       }     }     printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long mint = 0x7fffffff;   const long long linf = 1000000000000000000LL;   const long long mod = 1000000007LL;   const double eps = 1e-3;   const int N = 1000020;   inline long long read() {     long long 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;   }   long long qpow(long long a, long long b, long long m) {     long long ans = 1;     while (b > 0) {       if (b & 1) {         ans = ans * a % m;       }       a = a * a % m;       b >>= 1;     }     return ans;   }   int main(void) {     for (int _ = read(); _ > 0; _--) {       int n = read();       long long p = read();       vector<long long> k(n);       long long b = 0;       for (int i = 0; i < n; i++) k[i] = read();       sort(k.begin(), k.end(), greater<long long>());       long long q = 1;       bool f = false;       if (p == 1) {         printf( %d n , n % 2 == 1 ? 1 : 0);         continue;       }       long long now = k[0];       b = 1;       int i = 1;       for (; i < n; i++) {         if (b == 0)           now = k[i];         else           while (now > k[i] && !f) {             if (b >= n) {               f = true;               break;             }             b = b * p;             now--;           }         if (f) {           break;         } else {           if (b > 0)             b--;           else             b++;         }       }       long long ans = b % mod * qpow(p, now, mod) % mod;       for (; i < n; i++) ans = (ans + (mod - 1) * qpow(p, k[i], mod) % mod) % mod;       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long n;   long long a[N], b[N], c[N];   bool check() {     bool check = 0;     for (long long i = 1; i <= n; i++)       if (a[i] != b[i]) check = 1;     bool check2 = 0;     for (long long i = 1; i <= n; i++)       if (a[i] != c[i]) check2 = 1;     return check & check2;   }   void work() {     for (long long i = 1; i <= n - 1; i++) {       if (a[i] != a[i + 1]) {         swap(a[i], a[i + 1]);         if (check()) {           cout << i <<     << i + 1;           exit(0);         }         swap(a[i], a[i + 1]);       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       b[i] = a[i];       c[i] = b[i];     }     sort(b + 1, b + n + 1);     sort(c + 1, c + n + 1, greater<long long>());     work();     cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, dem;   string s;   void setup() {}   void solve() {     cin >> n;     cin >> s;     if (n == 1)       cout << s;     else {       for (int i = 0; i <= n - 1; ++i) dem += s[i] ==  0 ;       cout << 1;       for (int i = 1; i <= dem; ++i) cout << 0;     }   }   int main() {     setup();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[100], f0[100];   int main() {     int n, k, m;     scanf( %d %d %d , &n, &k, &m);     for (int i = 1; i < k; i++) f0[i] = 0, f[i] = 0;     int tmp = 1;     long long ans = 0;     for (int i = 0; i < n; i++) {       f0[0] = 1;       for (int j = 0; j < k; j++)         if (f0[j] > 0) {           for (int p = 0; p < 10; p++) {             f[(p * tmp + j) % k] = (f[(p * tmp + j) % k] + f0[j]) % m;           }         }       tmp = tmp * 10 % k;       long long asd = 1;       for (int j = i + 1; j < n - 1; j++) asd = asd * 10 % m;       if (i + 1 < n) asd = (asd * 9) % m;       ans = (ans + asd * (f[0] - 1) + m) % m;       f[0] = 0;       memcpy(f0, f, sizeof f0);       memset(f, 0, sizeof f);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     long long int a[n];     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int m;     cin >> m;     long long int num1[m], num2[m];     for (long long int i = 0; i < m; i++) {       cin >> num1[i] >> num2[i];     }     for (long long int i = 0; i < m; i++) {       long long int x = num1[i] - 1;       long long int y = num2[i];       if (x - 1 >= 0) {         a[x - 1] += y - 1;       }       if (x + 1 < n) {         a[x + 1] += a[x] - y;       }       a[x] = 0;     }     for (long long int i = 0; i < n; i++) cout << a[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e16;   const long long maxn = 128;   const long long maxlog = 60;   long long a, b;   string s, t;   long long dp[maxlog][maxn];   long long ans;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> a >> b;     cin >> s >> t;     string S =   ;     for (long long i = 100; i--; S += s)       ;     for (long long i = 0; i < s.size(); i++) {       long long p1 = 0, p2 = i;       for (; p1 < t.size(); p1++, p2++) {         for (; p2 < S.size() and S[p2] != t[p1]; p2++)           ;         if (p2 == S.size()) break;       }       if (p1 == t.size())         dp[0][i] = p2 - i;       else         dp[0][i] = inf;     }     for (long long j = 1; j < maxlog; j++)       for (long long i = 0; i < s.size(); i++)         dp[j][i] =             min(dp[j - 1][i] + dp[j - 1][(i + dp[j - 1][i]) % s.size()], inf);     long long len = 0;     for (long long j = maxlog; j--;)       if (dp[j][len % s.size()] + len <= a * s.size())         ans |= 1ll << j, len = len + dp[j][len % s.size()];     cout << ans / b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T>   using vec = vector<T>;   template <typename T>   using Prior = priority_queue<T>;   template <typename T>   using prior = priority_queue<T, vector<T>, greater<T>>;   const int INF = 1e9;   const int nINF = -1e9;   const ll llINF = 4 * 1e18;   const int MOD = 1e9 + 7;   ll& pmod(ll& a, ll b) {     a = (a + b) % MOD;     return a;   }   ll& pmod(ll& a, ll b, ll c) {     a = (a + b) % c;     return a;   }   ll& mmod(ll& a, ll b) {     a = (a - b + MOD) % MOD;     return a;   }   ll& mmod(ll& a, ll b, ll c) {     a = (a - b + c) % c;     return a;   }   ll& tmod(ll& a, ll b) {     a = (a * b) % MOD;     return a;   }   ll mul(ll a, ll b) { return (a * b) % MOD; }   ll mul(ll a, ll b, ll c) { return (a * b) % c; }   ll POW(ll a, ll b) {     ll res = 1;     do {       if (b % 2) tmod(res, a);       tmod(a, a);     } while (b >>= 1);     return res;   }   ll FAC(ll a) {     ll res = 1;     for (int i = 1; i <= a; i++) tmod(res, i);     return res;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     cout << a.first <<     << a.second;     return out;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int n;     cin >> n;     vec<int> _list(n);     for (auto& i : _list) cin >> i;     if (n % 2) {       cout <<  YES n ;       cout << n - 2 <<   n ;       for (int i = 0; i < n - 2; i += 2)         cout << i + 1 <<     << i + 2 <<     << i + 3 <<   n ;       for (int i = 0; i < n - 3; i += 2)         cout << i + 1 <<     << i + 2 <<     << n <<   n ;     } else {       int tmp = 0, idx = -1;       for (int i = 0; i < n; i++) {         tmp ^= _list[i];         if (_list[i]) idx = i;       }       if (tmp != 0)         cout <<  NO n ;       else {         cout <<  YES n ;         cout << n - 2 <<   n ;         for (int i = 0; i < n - 2; i += 2)           cout << i + 1 <<     << i + 2 <<     << i + 3 <<   n ;         for (int i = 0; i < n - 3; i += 2)           cout << i + 1 <<     << i + 2 <<     << n <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int M = 100 + 5, SM = 600;   const long long int inf = 1e18;   const long long int lg = 18;   const long long int z = 26;   long long int dp[M][M][M];   string dps[M][M][M];   long long int x;   long long int nxt[M][z];   long long int tt = 1;   long long int f[M];   long long int insert(string s) {     long long int p = 0;     for (char c : s) {       if (nxt[p][c -  A ] == 0) {         nxt[p][c -  A ] = tt++;       }       p = nxt[p][c -  A ];     }     return p;   }   int main() {     string s, t, virus;     cin >> s >> t;     long long int n = ((long long int)s.size());     long long int m = ((long long int)t.size());     cin >> virus;     long long int vi = insert(virus);     {       queue<long long int> q;       for (long long int i = 0; i < 26; i++) {         if (nxt[0][i] != 0) q.push(nxt[0][i]);       }       while (((long long int)q.size()) > 0) {         long long int x = q.front();         q.pop();         for (long long int i = 0; i < 26; i++) {           if (nxt[x][i] == 0)             nxt[x][i] = nxt[f[x]][i];           else {             f[nxt[x][i]] = nxt[f[x]][i];             q.push(nxt[x][i]);           }         }       }     }     for (long long int i = 1; i < n + 1; i++) {       for (long long int j = 1; j < m + 1; j++) {         if (s[i - 1] == t[j - 1]) {           for (long long int k = 0; k < tt; k++) {             long long int d = nxt[k][s[i - 1] -  A ];             if (k == vi || d == vi) continue;             if (dp[i][j][d] < dp[i - 1][j - 1][k] + 1) {               dp[i][j][d] = dp[i - 1][j - 1][k] + 1;               dps[i][j][d] = dps[i - 1][j - 1][k] + s[i - 1];             }           }         }         for (long long int k = 0; k < tt; k++) {           if (dp[i][j][k] < dp[i][j - 1][k]) {             dp[i][j][k] = dp[i][j - 1][k];             dps[i][j][k] = dps[i][j - 1][k];           }           if (dp[i][j][k] < dp[i - 1][j][k]) {             dp[i][j][k] = dp[i - 1][j][k];             dps[i][j][k] = dps[i - 1][j][k];           }         }       }     }     long long int res = 0;     string pes =   ;     for (long long int k = 0; k < tt; k++) {       if (k != vi) {         if (res < dp[n][m][k]) {           res = dp[n][m][k];           pes = dps[n][m][k];         }       }     }     cout << (pes ==    ?  0  : pes);   }
#include <bits/stdc++.h>   using namespace std;   void candy(int x, int y) {     int d = 1;     bool flag = true;     while (x >= 0 && y >= 0) {       if (flag) {         x = x - d;         d++;         flag = false;       } else {         y = y - d;         d++;         flag = true;       }       if (flag == true && x < d) {         cout <<  Vladik  << endl;         break;       } else if (flag == false && y < d) {         cout <<  Valera  << endl;         break;       }     }   }   int main(int argc, char** argv) {     int a, b;     cin >> a >> b;     candy(a, b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, r1, c1, r2, c2;   char a[120][120];   int main() {     cin >> n >> m;     bool sign = true;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] ==  B ) {           if (sign) {             r1 = i;             c1 = j;             sign = false;           }           r2 = i;           c2 = j;         }     cout << (r1 + r2) / 2 <<     << (c1 + c2) / 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 1e9;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   int a, b;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> a >> b;     int t = gcd(a, b);     a /= t;     b /= t;     if (abs(a - b) <= 1) return puts( Equal );     puts(a < b ?  Dasha  :  Masha );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long A[200010], sz[200010], v[200010][11];   vector<long long> l[11];   class Timer {    private:     using clock_t = std::chrono::high_resolution_clock;     using second_t = std::chrono::duration<double, std::ratio<1> >;     std::chrono::time_point<clock_t> m_beg;       public:     Timer() : m_beg(clock_t::now()) {}     void reset() { m_beg = clock_t::now(); }     double elapsed() const {       return std::chrono::duration_cast<second_t>(clock_t::now() - m_beg).count();     }   } T;   long long cnt(long long x) {     long long r = 0;     while (x) r++, x /= 10;     return r;   }   void precompute(long long n, long long k) {     for (long long i = 0; i < n; i++) {       sz[i] = cnt(A[i]);       long long x = A[i];       v[i][0] = x;       for (long long j = 1; j < 11; j++) x = (x * 10) % k, v[i][j] = x;       A[i] %= k;     }   }   void put(long long i) {     l[sz[i]].push_back(A[i]);     return;   }   long long binary(long long T, long long mod) {     long long L = 0, R = (long long)l[T].size() - 1, ans1 = -1;     while (L <= R) {       long long mid = (L + R) >> 1;       if (l[T][mid] == mod)         ans1 = mid, R = mid - 1;       else if (l[T][mid] > mod)         R = mid - 1;       else         L = mid + 1;     }     if (ans1 == -1) return 0;     L = 0, R = (long long)l[T].size() - 1;     long long ans2 = -1;     while (L <= R) {       long long mid = (L + R) >> 1;       if (l[T][mid] == mod)         ans2 = mid, L = mid + 1;       else if (l[T][mid] > mod)         R = mid - 1;       else         L = mid + 1;     }     return (ans2 - ans1 + 1);   }   long long get(long long idx, long long k) {     long long ans = 0LL;     for (long long i = 1; i < 11; i++) {       long long x = v[idx][i];       ans += binary(i, (k - x) % k);       if (i == sz[idx] && (v[idx][i] + A[idx]) % k == 0) ans--;     }     return ans;   }   signed main() {     long long n, k;     scanf( %I64d %I64d , &n, &k);     for (long long i = 0; i < n; i++) scanf( %I64d , &A[i]);     precompute(n, k);     for (long long i = 0; i < n; i++) put(i);     for (long long i = 1; i < 11; i++) sort(l[i].begin(), l[i].end());     long long ans = 0;     for (long long i = 0; i < n; i++) ans += get(i, k);     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0, f = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int MAXN = 3e2 + 5;   const int MAXQ = 2e6 + 5;   struct Query {     int x, y, nc, oc;   } q[MAXQ];   int fa[MAXQ << 1], ans[MAXQ], a[MAXN][MAXN], id[MAXN][MAXN];   int N, M, Q, Num, cnt;   inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   inline int mrg(int x, int y) {     if (find(x) != find(y)) {       fa[fa[x]] = fa[y];       Num--;     }   }   inline void check(int x, int y) {     if (a[x][y] == a[x - 1][y]) mrg(id[x][y], id[x - 1][y]);     if (a[x][y] == a[x + 1][y]) mrg(id[x][y], id[x + 1][y]);     if (a[x][y] == a[x][y - 1]) mrg(id[x][y], id[x][y - 1]);     if (a[x][y] == a[x][y + 1]) mrg(id[x][y], id[x][y + 1]);   }   inline void solveTo() {     for (int i = 1; i <= Q; i++) {       if (q[i].oc == q[i].nc) continue;       int x = q[i].x, y = q[i].y;       Num = 1;       a[x][y] = q[i].nc;       id[x][y] = ++cnt;       fa[cnt] = cnt;       check(x, y);       ans[i] += Num;     }   }   inline void solveBack() {     for (int i = Q; i; i--) {       if (q[i].oc == q[i].nc) continue;       int x = q[i].x, y = q[i].y;       Num = 1;       a[x][y] = q[i].oc;       id[x][y] = ++cnt;       fa[cnt] = cnt;       check(x, y);       ans[i] -= Num;     }   }   int main() {     N = read();     M = read();     Q = read();     for (int i = 1; i <= Q; i++) {       int x = read(), y = read(), z = read();       q[i] = {x, y, z, a[x][y]};       a[x][y] = z;     }     ans[0] = 1;     cnt = 0;     memset(a, -1, sizeof(a));     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) a[i][j] = 0;     solveTo();     memset(fa, cnt = 0, sizeof(fa));     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) {         id[i][j] = ++cnt;         fa[cnt] = cnt;       }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) check(i, j);     solveBack();     for (int i = 1; i <= Q; i++) {       ans[i] += ans[i - 1];       printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long int myRand(long long int B) { return (unsigned long long)rng() % B; }   struct UnionFind {     vector<int> par, num;     vector<bool> done;     UnionFind(int n) : par(n), num(n, 1), done(n, false) {       iota(par.begin(), par.end(), 0);     }     int find(int v) { return (par[v] == v) ? v : (par[v] = find(par[v])); }     void unite(int u, int v) {       u = find(u), v = find(v);       if (u == v) return;       if (num[u] < num[v]) swap(u, v);       num[u] += num[v];       par[v] = u;       done[u] = done[u] | done[v];     }     bool same(int u, int v) { return find(u) == find(v); }     bool ispar(int v) { return v = find(v); }     int size(int v) { return num[find(v)]; }   };   const int BS = 524288;   int CNT, rc;   char inb[BS];   inline char gchar(void) {     if (CNT % BS == 0) {       CNT = 0;       rc = fread(inb, 1, BS, stdin);     }     return CNT < rc ? inb[CNT++] : 0;   }   inline int _readint(int *ptr) {     int n = 0, c = 0;     *ptr = 0;     while (1) {       char read = gchar();       if (read >=  0  && read <=  9 )         read -=  0 , n *= 10, n += read;       else {         *ptr = n;         return n == 0 ? 0 : !c;       }       c++;     }     *ptr = n;     return 0;   }   inline int readint(void) {     int ptr;     while (_readint(&ptr))       ;     return ptr;   }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int n, m, q;     cin >> n >> m >> q;     vector<int> x(m), y(m), w(m);     vector<pair<int, int>> v(m);     for (int i = 0; i < m; i++) {       cin >> x[i] >> y[i] >> w[i];       x[i]--;       y[i]--;       v[i] = make_pair(w[i], i);     }     sort(v.rbegin(), v.rend());     while (q--) {       int l, r;       cin >> l >> r;       l--;       int res = -1;       UnionFind uf(2 * n);       for (int i = 0; i < v.size(); i++) {         if (v[i].second < l || r <= v[i].second) continue;         int id = v[i].second;         if (uf.same(x[id], y[id])) {           res = v[i].first;           break;         } else {           uf.unite(x[id], y[id] + n);           uf.unite(x[id] + n, y[id]);         }       }       printf( %d n , res);     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   string S;   long long dp[222][222];   long long GetAnswer(int pos, int numdigs) {     if (pos == S.size()) {       if (numdigs == 0)         return 0;       else         return -1;     }     if (numdigs == 0) return -1;     if (dp[pos][numdigs] != -2) return dp[pos][numdigs];     long long ret = -1;     long long x = 0;     if ((numdigs - 1.0) * log(n) > log(1400000000000000000ll))       return dp[pos][numdigs] = -1;     long long npow = 1;     for (int j = 0; j < numdigs - 1; j++) npow *= n;     if (npow > 1000000000000000000ll) return dp[pos][numdigs] = -1;     for (int j = pos; j < S.size(); j++) {       if (S[pos] ==  0  && j > pos) break;       x = x * 10 + S[j] -  0 ;       if (x >= n) break;       long long curr = GetAnswer(j + 1, numdigs - 1);       if (curr == -1 || curr > 1000000000000000000ll ||           x > 1000000000000000000ll / npow)         continue;       if (log(x) + (numdigs - 1.0) * log(n) > log(1400000000000000000ll - curr))         continue;       curr += x * npow;       if (curr <= 1000000000000000000ll && (ret == -1 || curr < ret)) ret = curr;     }     return dp[pos][numdigs] = ret;   }   int main() {     cin >> n >> S;     long long answer = -1;     for (int j = 0; j < 222; j++)       for (int k = 0; k < 222; k++) dp[j][k] = -2;     for (int numdigs = 1; numdigs <= 61; numdigs++) {       long long curr = GetAnswer(0, numdigs);       if (curr == -1) continue;       if (answer == -1 || (curr < answer)) answer = curr;     }     cout << answer << endl;   }