malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const long long mod9 = 1e9 + 7;   const long long maxsize = 2e9 + 1;   const long long mod = 998244353;   const long long mod2 = 1073741824;   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     long long temp_len = 0;     long long max_len = 2;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 2; i < n; i++) {       if (a[i] == (a[i - 1] + a[i - 2])) {         temp_len = 3;         i++;         while (a[i] == (a[i - 1] + a[i - 2]) and i < n) {           temp_len++;           i++;         }         if (temp_len > max_len) max_len = temp_len;       }     }     if (n < max_len) max_len = n;     cout << max_len;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int a;     priority_queue<long long int> o, e;     for (long long int i = 0; i < n; i++) {       cin >> a;       if (a % 2 == 0)         e.push(a);       else         o.push(a);     }     if (e.size() == o.size()) {       cout << 0;       return 0;     }     long long int mi = min(e.size(), o.size());     if (e.size() == mi) {       for (long long int i = 0; i < mi; i++) e.pop();       for (long long int i = 0; i < mi + 1; i++) o.pop();     } else {       for (long long int i = 0; i < mi; i++) o.pop();       for (long long int i = 0; i < mi + 1; i++) e.pop();     }     long long int sum = 0;     while (!e.empty()) {       sum += e.top();       e.pop();     }     while (!o.empty()) {       sum += o.top();       o.pop();     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   long double PI = 4 * atan(1);   pair<int, int> p[3];   set<pair<int, int> > second;   bool cmp(pair<int, int> p1, pair<int, int> p2) { return p1.second > p2.second; }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     for (int i = 0; i < 3; i++) {       cin >> p[i].first >> p[i].second;       second.insert(p[i]);     }     sort(p, p + 3, cmp);     while (p[2].second != p[1].second) {       p[2].second++;       second.insert(p[2]);     }     sort(p, p + 3, cmp);     while (p[0].first != p[2].first) {       if (p[0].first > p[2].first)         p[2].first++;       else         p[2].first--;       second.insert(p[2]);     }     while (p[0].first != p[1].first) {       if (p[0].first > p[1].first)         p[1].first++;       else         p[1].first--;       second.insert(p[1]);     }     p[1] = p[2];     while (p[2].second != p[0].second) {       p[2].second++;       second.insert(p[2]);     }     cout << second.size() <<   n ;     for (pair<int, int> p1 : second) {       cout << p1.first <<     << p1.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxm = 3e6 + 7;   const int maxn = 2e5 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   deque<int> q;   int n, ans = 0;   bool judge[maxn];   int num[maxn], sum[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> n;     memset(judge, false, sizeof judge);     for (int i = 1; i <= n; i++) {       cin >> num[i];       sum[num[i]]++;     }     for (int i = 1; i <= n; i++)       if (!sum[i]) q.push_back(i);     for (int i = 1; i <= n; i++) {       if (sum[num[i]] > 1 && num[i] < q.front() && !judge[num[i]]) {         judge[num[i]] = true;         continue;       }       if (sum[num[i]] > 1) {         sum[num[i]]--;         num[i] = q.front();         q.pop_front();         ans++;       }     }     cout << ans << endl;     for (int i = 1; i <= n; i++) cout << num[i] <<    ;     return cout << endl, 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[7001][2], cnt[7001][2], p[2], n, b[7001][2], r, o;   queue<pair<int, int> > h;   bool f[7001][2];   int main() {     scanf( %d , &n);     scanf( %d , &p[0]);     for (int i = 0; i < p[0]; i++) scanf( %d , &b[i][0]);     scanf( %d , &p[1]);     for (int i = 0; i < p[1]; i++) scanf( %d , &b[i][1]);     for (int i = 1; i < n; i++) cnt[i][0] = p[0], cnt[i][1] = p[1];     a[0][0] = 1;     a[0][1] = 1;     h.push({0, 0});     h.push({0, 1});     while (!h.empty()) {       pair<int, int> tmp = h.front();       h.pop();       r = tmp.second ^ 1;       f[tmp.first][tmp.second] = true;       for (int j = 0; j < p[r]; j++) {         o = (tmp.first - b[j][r] + n) % n;         if (a[tmp.first][tmp.second] == 1) {           if (!f[o][r]) a[o][r] = -1, h.push({o, r});         } else {           cnt[o][r]--;           if (!cnt[o][r] && !f[o][r]) a[o][r] = 1, h.push({o, r});         }       }     }     for (int i = 1; i < n; i++)       if (a[i][0] == 1)         printf( Lose  );       else if (a[i][0] == 0)         printf( Loop  );       else         printf( Win  );     printf(  n );     for (int i = 1; i < n; i++)       if (a[i][1] == 1)         printf( Lose  );       else if (a[i][1] == 0)         printf( Loop  );       else         printf( Win  );     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000007;   const long long linf = 1LL << 62;   const unsigned long long ulinf = 1ULL << 63;   const double eps = 0.000001;   const double pi = 3.14159265358979323846;   template <class T>   T abs(T a) {     return a >= 0 ? a : -a;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <class T>   T mod(T a, T b) {     return (a % b + b) % b;   }   template <class T>   T addmod(T a, T b, T c) {     return (T)mod((long long)a + b, (long long)c);   }   template <class T>   T mulmod(T a, T b, T c) {     return (T)mod((long long)a * b, (long long)c);   }   template <class T>   T powmod(T a, T b, T c) {     return (T)mod(         b ? mulmod(mod(sqr((long long)powmod(a, b >> 1, c)), (long long)c),                    (b & 1LL) ? a : 1LL, (long long)c)           : 1LL,         (long long)c);   }   template <class T>   void maxe(T &a, T b) {     a = max(a, b);   }   template <class T>   void mine(T &a, T b) {     a = min(a, b);   }   template <class T>   void mode(T &a, T b) {     a = mod(a, b);   }   template <class T>   void addmode(T &a, T b, T c) {     a = addmod(a, b, c);   }   template <class T>   void mulmode(T &a, T b, T c) {     a = mulmod(a, b, c);   }   template <class T>   void powmode(T &a, T b, T c) {     a = powmod(a, b, c);   }   int iszero(double a) { return abs(a) <= eps; }   template <class T>   void getint(T &a) {     a = 0;     int b = 1, c = getchar();     if (c ==  - )       b = -1;     else       a = c - 48;     while ((c = getchar()) !=     && c !=   n ) a = a * 10 + c - 48;     a *= b;   }   void fileio_in_out() {     freopen( .in ,  r , stdin);     freopen( .out ,  w , stdout);   }   void fileio_txt() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 1111;   int test;   int n, m, k, ans;   int a[41] = {0,       2,       3,       5,       7,        13,      17,                19,      31,      61,      89,      107,      127,     521,                607,     1279,    2203,    2281,    3217,     4253,    4423,                9689,    9941,    11213,   19937,   21701,    23209,   44497,                86243,   110503,  132049,  216091,  756839,   859433,  1257787,                1398269, 2976221, 3021377, 6972593, 13466917, 20996011};   const int md = inf;   int main() {     scanf( %d , &n);     printf( %d n , addmod(powmod(2, a[n] - 1, md), -1, md));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 9223372036854775807LL;   const long double PI = acos(-1);   const int MAX_N = 1e+6;   const string digits =  0123456789 ;   const string alph =  abcdefghijklmnopqrstuvwxyz ;   void solve() {     long long n, root, answer;     cin >> n;     for (long long i = 1; i * i <= n; i++) root = i;     if (n == 1) {       answer = 2;     } else {       if (root * root == n) {         answer = 2LL * root;       } else {         if (root * root + root >= n) {           answer = 2LL * root + 1LL;         } else {           answer = 2LL * (root + 1LL);         }       }     }     cout << answer << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100005];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s);     s[n] =  # ;     for (int i = 0; i < n; i++) {       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||           s[i] ==  u  || s[i] ==  y ) {         if (s[i] ==  e  || s[i] ==  o ) {           int same = 1;           if (i != n - 1) {             if (s[i + 1] == s[i]) same++;           }           if (same == 2) {             if (i != n - 2) {               if (s[i + 2] == s[i]) {                 printf( %c , s[i]);                 for (int j = i + 2; j <= n; j++) {                   if (s[j] != s[i]) {                     i = j - 1;                     break;                   }                 }               } else {                 printf( %c%c , s[i], s[i]);                 i++;               }             } else {               printf( %c%c , s[i], s[i]);               i++;             }           } else             printf( %c , s[i]);         } else {           printf( %c , s[i]);           for (int j = i + 1; j <= n; j++) {             if (s[i] != s[j]) {               i = j - 1;               break;             }           }         }       } else         printf( %c , s[i]);     }   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC target( avx )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fu = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   const int N = 4005, md = 998244853;   inline int add(int x, int y) {     x += y;     if (x >= md) x -= md;     return x;   }   inline int sub(int x, int y) {     x -= y;     if (x < 0) x += md;     return x;   }   inline int mul(int x, int y) { return 1ll * x * y % md; }   inline int fpow(int x, int y) {     int ans = 1;     while (y) {       if (y & 1) ans = mul(ans, x);       y >>= 1;       x = mul(x, x);     }     return ans;   }   int fac[N], inv[N];   int n, m, ans;   inline int C(int n, int m) { return mul(fac[n], mul(inv[m], inv[n - m])); }   int main() {     read(n);     read(m);     fac[0] = 1;     for (register int i = 1; i <= n + m; i++) fac[i] = mul(fac[i - 1], i);     inv[n + m] = fpow(fac[n + m], md - 2);     for (register int i = n + m; i >= 1; i--) inv[i - 1] = mul(inv[i], i);     for (register int i = 1; i <= n; i++) {       if (n - m >= i)         ans = add(ans, C(n + m, m));       else         ans = add(ans, C(n + m, i + m));     }     print(ans,   n );     return 0;   }
#include <bits/stdc++.h>   const int N = 1000;   bool vis[N + 100];   int v[N + 100];   int top = 0;   int n = 0;   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) {       if (!vis[i]) {         vis[i] = true;         for (int j = 0; j < n; j++) {           if (!vis[j]) continue;           if (i * j > n) break;           if ((j % i == 0) || (i % j == 0)) continue;           vis[i * j] = true;         }         v[top++] = i;       }     }     printf( %d n , top);     for (int i = 0; i < top; i++) {       printf( %d  , v[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   static long long gcd(long long a, long long b) {     long long r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) {     long long temp = gcd(a, b);     return temp ? (a / temp * b) : 0;   }   int solve() {     long long n;     cin >> n;     long long k;     cin >> k;     long long maxans = (n * (n - 1)) / 2LL;     if (k > maxans) {       cout <<  Impossible ;       return 0;     }     long long cnt = 0;     long long tmp;     for (long long i = 1; i <= n; i++) {       if (((i * (i - 1)) / 2LL) <= k) {         tmp = i;       } else {         break;       }     }     long long open = tmp;     cnt = open;     k = k - ((tmp * (tmp - 1)) / 2LL);     string s;     for (int i = 0; i < open; i++) {       s.push_back( ( );     }     if (open >= 1) {       s.push_back( ) );       open--;     }     while (k > 0 && open > 0 && cnt <= n) {       if (open <= k) {         s.push_back( ( );         s.push_back( ) );         cnt++;         k = k - open;       } else {         open--;         s.push_back( ) );       }     }     if (k == 0 && cnt <= n) {       for (int i = 0; i < open; i++) {         s.push_back( ) );       }       for (int i = 0; i < (n - cnt); i++) {         s.push_back( ( );         s.push_back( ) );       }       cout << s;       return 0;     } else {       cout <<  Impossible ;       return 0;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str1[1000005], str2[1000005];   int cnt[3];   unsigned long long bao[1000005], base[1000005];   long long base2[1000005], da[1000005];   int main() {     int n, m, i, j, ans = 0;     scanf( %s , str1 + 1);     scanf( %s , str2 + 1);     n = strlen(str1 + 1);     m = strlen(str2 + 1);     base[0] = 1;     base2[0] = 1;     for (i = 1; i <= m; i++) {       base[i] = base[i - 1] * 233;       bao[i] = bao[i - 1] * 233 + str2[i] -  a  + 1;       base2[i] = base2[i - 1] * 2333 % 1000000007;       da[i] = (da[i - 1] * 2333 + str2[i] -  a  + 1) % 1000000007;     }     for (i = 1; i <= n; i++) {       cnt[str1[i] -  0 ]++;     }     int f = str1[1] -  0 ;     for (i = 1; i <= m / cnt[f]; i++) {       int w = m - cnt[f] * i;       if (w % cnt[1 - f] != 0 || w == 0) continue;       w /= cnt[1 - f];       unsigned long long a1 = bao[i], a2 = 114514;       long long b1 = da[i], b2 = 114514;       int now = i;       for (j = 2; j <= n; j++) {         if (str1[j] == f +  0 ) {           if (a1 != bao[now + i] - bao[now] * base[i]) break;           if (b1 !=               (da[now + i] - 1LL * da[now] * base2[i] % 1000000007 + 1000000007) %                   1000000007)             break;           now += i;         } else {           if (a2 == 114514 && b2 == 114514) {             a2 = bao[now + w] - bao[now] * base[w];             b2 = (da[now + w] - 1LL * da[now] * base2[w] % 1000000007 +                   1000000007) %                  1000000007;           } else {             if (a2 != bao[now + w] - bao[now] * base[w]) break;             if (b2 != (da[now + w] - 1LL * da[now] * base2[w] % 1000000007 +                        1000000007) %                           1000000007)               break;           }           now += w;         }       }       if (j > n) {         if (a1 != a2 && b1 != b2) ans++;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   int n, m, k;   int x[MAXN], y[MAXN];   void read_input() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       cin >> x[i] >> y[i];     }   }   const int INF = 1e9;   int pref[2][MAXN];   void update(int x, int val) {     for (int i = x; i <= m; i += (i & -i)) {       pref[0][i] = min(pref[0][i], val);     }   }   int query(int r) {     int ans = INF;     for (int i = r; i > 0; i -= (i & -i)) {       ans = min(ans, pref[0][i]);     }     return ans;   }   void update2(int x, int val) {     for (int i = x; i <= m; i += (i & -i)) {       pref[1][i] = max(pref[1][i], val);     }   }   int query2(int r) {     int ans = 0;     for (int i = r; i > 0; i -= (i & -i)) {       ans = max(ans, pref[1][i]);     }     return ans;   }   int mi_y[MAXN], ma_y[MAXN];   void solve() {     for (int i = 0; i <= m; i++) {       mi_y[i] = INF;       ma_y[i] = 0;       pref[0][i] = INF;       pref[1][i] = 0;     }     bool fl = true;     for (int i = 0; i < k; i++) {       if (fl) {         int tmpX = (x[i] + 1) / 2;         int tmpY = (y[i] + 1) / 2;         if (x[i] % 2 == 1) {           mi_y[tmpY] = min(mi_y[tmpY], tmpX);           update(tmpY, mi_y[tmpY]);         }         int rev = m - tmpY + 1;         if (x[i] % 2 == 0) {           ma_y[rev] = max(ma_y[rev], tmpX);           update2(rev, ma_y[rev]);         }         if (query(tmpY) <= query2(rev)) {           fl = false;         }       }       if (!fl) {         cout <<  NO n ;       } else {         cout <<  YES n ;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     read_input();     solve();     return 0;   }
#include <iostream>   #include <cmath>      using namespace std;      typedef long long int ll;      int main(){    int cases;    ll num;    double temp;    cin >> cases;    bool cube = false;    for(int a = 0; a < cases; a++){     cin >> num;     cube = false;     for(ll b = max(int(cbrt(double(num/2))), 1); b < cbrt(num) && cube == false; b++){      temp = cbrt(num - pow(b, 3));      if(abs(temp - int(temp)) < pow(10, -9)) cube = true;     }     printf(cube ?  YES n  :  NO n );    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename... T>   void see(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void put(T&&... args) {     ((cout << args <<    ), ...);     cout <<   n ;   }   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<  =  << a <<  ,  ;     err(++it, args...);   }   const long long inf = INT_MAX;   const long double ep = 0.0000001;   const long double pi = acos(-1.0);   const long long md = 1000000007;   vector<string> add = { 1869 ,  1968 ,  6918 ,  6198 ,  1698 ,  1986 ,  1896 };   void solve() {     string s;     see(s);     long long a = 0, b = 0, c = 0, d = 0;     string s1 =   ;     for (long long i = 0; i < s.size(); ++i) {       if (s[i] ==  1  && !a) {         a = 1;       } else if (s[i] ==  6  && !b) {         b = 1;       } else if (s[i] ==  8  && !c) {         c = 1;       } else if (s[i] ==  9  && !d) {         d = 1;       } else         s1 += s[i];     }     long long s3;     for (long long j = 0; j < 7; ++j) {       s3 = j;       for (long long i = 0; i < s1.size(); ++i) {         s3 = (s3 * 10 + (s1[i] -  0 )) % 7;       }       if (s3 == 0) {         s3 = j;         break;       }     }     s1 = add[s3] + s1;     cout << s1;   }   signed main() {     ios_base::sync_with_stdio(false);     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int s, v = 0;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n - 1; i++) {       if (arr[i] > arr[i + 1]) {         s = i + 1;         v++;       }     }     if (arr[n - 1] > arr[0]) {       s = n;       v++;     }     if (v == 0)       cout <<  0  << endl;     else {       if (v > 1)         cout <<  -1  << endl;       else         cout << n - s << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string t1, t2, t3, t4;     cin >> t1 >> t2 >> t3 >> t4;     string b = t1 + t2[1] + t2[0], e = t3 + t4[1] + t4[0];     b.erase(b.find( X ), 1);     e.erase(e.find( X ), 1);     for (int i = 0; i < 3; ++i) {       string a1 = e.substr(i);       string a2 = e.substr(0, i);       if (b == a1 + a2) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T0, typename T1>   std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) {     for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) {       os << p->first <<  :   << p->second <<    ;     }     return os;   }   template <typename T0, typename T1>   std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) {     os << v.first <<  :   << v.second <<    ;     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << endl;     }     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const vector<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] <<    ;     }     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const set<T>& v) {     vector<T> tmp(v.begin(), v.end());     os << tmp;     return os;   }   template <typename T>   std::ostream& operator<<(std::ostream& os, const deque<T>& v) {     vector<T> tmp(v.begin(), v.end());     os << tmp;     return os;   }   int main() {     long long N, M;     while (cin >> N >> M) {       long long lo = 1, hi = M + 1;       while (lo + 1 < hi) {         long long mid = (lo + hi) / 2;         long long edges = mid * (mid - 1) / 2;         if (mid % 2 == 0 && mid - 2 > 0) edges += (mid - 2) / 2;         if (edges <= N - 1)           lo = mid;         else           hi = mid;       }       vector<long long> w(M);       for (int i = 0, _n = (M); (i) < (int)_n; ++i) {         long long v;         cin >> v >> w[i];       }       sort((w).rbegin(), (w).rend());       cout << accumulate(&w[0], &w[lo], 0) << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   long long n, p;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long te;     cin >> te;     while (te--) {       cin >> n >> p;       vector<pair<long long, long long> > ans;       for (long long i = 1; i <= n; i++) {         for (long long j = i + 1; j <= n; j++) {           ans.push_back({i, j});         }       }       for (long long i = 0; i < 2 * n + p; i++)         cout << ans[i].first <<     << ans[i].second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795;   const long double eps = 0.000000001;   const int INF = 1E9;   const int MAXN = 100000;   int ans, a[2], mn;   string s[2];   char c;   bool f[2];   int getn(char c) { return ( 0  <= c && c <=  9 ) ? (c -  0 ) : (c -  A  + 10); }   int main() {     c = getchar();     while (c !=  : ) {       s[0] += c;       c = getchar();     }     cin >> s[1];     for (int k = 0; k < (int)(2); k++)       for (int i = 0; i < (int)(s[k].size() - 1); i++)         if (s[k][i] !=  0 ) f[k] = 1;     if (f[0] || f[1]) {       f[0] = 1;       for (int i = (int)(2); i <= (int)(60); i++) {         f[1] = 1;         for (int j = 0; j < (int)(2); j++) {           mn = 1;           a[j] = 0;           for (int k = (int)(s[j].size()) - 1; k >= 0; k--) {             if (getn(s[j][k]) >= i) f[1] = 0;             a[j] += mn * getn(s[j][k]);             mn *= i;           }         }         if (f[1] && a[0] <= 23 && a[1] <= 59) {           cout << i <<    ;           f[0] = 0;         }       }       if (f[0]) cout << 0 << endl;     } else {       if (getn(s[0][s[0].size() - 1]) <= 23)         cout << -1;       else         cout << 0;     }     return 0;   }