malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int constexpr nax = 3e5 + 5;   using ll = int64_t;   const int INF = 1e9;   template <typename T>   struct fenwick {     T bit[nax];     fenwick() { memset(bit, 0, sizeof(bit)); }     void update(int x, T val) {       for (; x < nax; x += x & -x) bit[x] += val;     }     T get(int x) {       int res = 0;       for (; x > 0; x -= x & -x) res += bit[x];       return res;     }     T get(int l, int r) { return get(r) - get(l - 1); }   };   struct segtree {     static constexpr int Mx = 4 * nax;     ll sg[Mx] = {}, tag[Mx] = {};     inline void pull(int v) { sg[v] = min(sg[v * 2], sg[v * 2 + 1]); }     segtree() {       fill(sg, sg + Mx, INF);       fill(tag, tag + Mx, 0);     }     inline void push(int v) {       if (v * 2 + 1 < Mx && tag[v]) {         sg[v * 2] += tag[v];         sg[v * 2 + 1] += tag[v];         tag[v * 2] += tag[v];         tag[v * 2 + 1] += tag[v];       }       tag[v] = 0;     }     inline void update(int v, int x, int y, int l, int r, ll val) {       push(v);       if (l > r) return;       if (l == x && r == y) {         sg[v] += val;         tag[v] += val;         return push(v);       }       int mid = x + y >> 1;       update(v * 2, x, mid, l, min(r, mid), val);       update(v * 2 + 1, mid + 1, y, max(l, mid + 1), r, val);       pull(v);     }     int find_first_neg(int v, int x, int y) {       push(v);       if (x == y) {         assert(sg[v] <= 0);         return x;       } else {         int mid = x + y >> 1;         if (sg[v * 2] <= 0)           return find_first_neg(v * 2, x, mid);         else           return find_first_neg(v * 2 + 1, mid + 1, y);       }     }   };   segtree sg;   fenwick<int> sum;   int n, nq;   int ans[nax];   int b[nax];   vector<pair<int, int>> q[nax];   int main() {     cin.tie(0)->sync_with_stdio(false);     cin >> n >> nq;     for (int i = 1; i <= n; ++i) {       cin >> b[i];       b[i] = i < b[i] ? INF : i - b[i];     }     for (int i = 1; i <= nq; ++i) {       int x, y;       cin >> x >> y;       q[x + 1].emplace_back(n - y, i);     }     for (int i = n; i >= 1; --i) {       sg.update(1, 1, n, i, i, (ll)b[i] - INF);       while (sg.sg[1] <= 0) {         int v = sg.find_first_neg(1, 1, n);         sum.update(v, 1);         sg.update(1, 1, n, v, v, INF);         sg.update(1, 1, n, v, n, -1);       }       for (const auto &[r, id] : q[i]) ans[id] = sum.get(i, r);     }     for (int i = 1; i <= nq; ++i) {       cout << ans[i] <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   string s, t;   int dp[5005][5005];   int get(int i, int j) {     if (dp[i][j] != -1) return dp[i][j];     if (i >= s.size() or j >= t.size()) return 0;     int ret = get(i, j + 1);     if (s[i] == t[j]) ret = (ret + 1 + get(i + 1, j + 1)) % 1000000007;     return dp[i][j] = ret;     ;   }   int main() {     for (int i = 0; i < 5005; ++i)       for (int j = 0; j < 5005; ++j) dp[i][j] = -1;     cin >> s >> t;     long long ret = 0;     for (int i = 0; i < s.size(); ++i) ret = (ret + get(i, 0)) % 1000000007;     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long t, n, k;   long long f(long long x) {     if (x == 0) return k * (k + 1) / 2;     long long t = x % k, val = f(x / k), ofs = 0;     if (val < k * t + 2) {       ofs = k;     } else if ((t + 1) * k < val) {       ofs = 0;     } else {       ofs = (t + 1) * k - val + 1;     }     return k * (k + 1) / 2 - t + ofs;   }   long long rjesi(long long x) {     long long buk = (x - 1) / (k * k + 1);     long long pos = (k * k + 1) * buk + f(buk);     if (x != pos) {       long long lef = buk + (pos < x);       return (x - 1 - lef) / k - lef + x;     } else {       long long t = buk % k, val = f(buk / k);       if ((t + 1) * k < val) {         return rjesi(buk / k * (k * k + 1) + (t + 1) * k) + 1;       } else {         return rjesi(buk / k * (k * k + 1) + (t + 1) * k + 1) + 1;       }     }   }   int main() {     cin >> t;     while (t--) {       cin >> n >> k;       cout << rjesi(n) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 305;   long long dp[maxn][maxn][6];   int n, x[maxn], y[maxn];   vector<pair<double, pair<int, int>>> seg;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         for (int k = 0; k < 6; k++) dp[i][j][k] = 0;         if (i == j) dp[i][j][0] = 1;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i != j) {           int xx = x[j] - x[i], yy = y[j] - y[i];           seg.push_back({atan2(xx, yy), {i, j}});         }       }     }     sort(seg.begin(), seg.end());     int m = seg.size();     for (int cc = 0; cc < m; cc++) {       int i = seg[cc].second.first, j = seg[cc].second.second;       for (int k = 0; k < n; k++)         for (int f = 0; f < 5; f++) dp[k][i][f + 1] += dp[k][j][f];     }     long long ret = 0;     for (int i = 0; i < n; i++) ret += dp[i][i][5];     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     if ((n & (n - 1)) == 0) {       cout << 0 <<   n ;     } else {       int k = 0;       while ((1 << k + 1) <= n) {         k++;       }       n ^= 1 << k;       int ans = 0;       for (int i = 0; i < k; ++i) {         int j = i + 1;         if (j >= k) {           j -= k;         }         if (n & (1 << j)) {           ans |= 1 << i;         }       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool isprime(int n) {     if (n == 2) return 1;     for (int i = 2; i < n; i++) {       if (n % i == 0) return 0;     }     return 1;   }   int main() {     int n, m;     cin >> n >> m;     int flag = 1;     if (isprime(n) && isprime(m)) {       for (int i = n + 1; i < m; i++) {         if (isprime(i)) {           cout <<  NO  << endl;           flag = 0;           break;         }       }       if (flag) cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   const int N = 200000 + 10;   int a[N], n, K;   int main() {     scanf( %d%d , &n, &K);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     long long pre = 0;     int tot = n - 1, id = 0;     for (int i = 0; i < n; ++i) {       long long d = pre - (long long)a[i] * (tot - id) * id;       if (d < K) {         printf( %d n , i + 1);         --tot;       } else {         pre = pre + (long long)a[i] * id;         ++id;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[105][105], t, m, n, ret, cnt, mn;   int main(void) {     cin >> t;     for (int i = 0; i < t; i++) {       ret = 0, cnt = 0, mn = 101;       cin >> n >> m;       for (int j = 0; j < n; j++) {         for (int k = 0; k < m; k++) {           cin >> a[j][k];           if (a[j][k] <= 0) cnt++;           if (abs(a[j][k]) < mn) mn = abs(a[j][k]);         }       }       for (int j = 0; j < n; j++) {         for (int k = 0; k < m; k++) {           ret += abs(a[j][k]);         }       }       if (cnt % 2 == 1) ret -= 2 * mn;       cout << ret << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 510;   int n, m;   double xa, ya, x2, y2;   double v, vx1, vx2, vy1, vy2, t;   int check(double k) {     double x, y;     x = xa + vx1 * min(k, t) + vx2 * max(0.0, k - t);     y = ya + vy1 * min(k, t) + vy2 * max(0.0, k - t);     double dist = sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));     if (v * k >= dist) return 1;     return 0;   }   int main() {     int i, j, k;     while (~scanf( %lf%lf%lf%lf , &xa, &ya, &x2, &y2)) {       scanf( %lf%lf , &v, &t);       scanf( %lf%lf , &vx1, &vy1);       scanf( %lf%lf , &vx2, &vy2);       double l = 0.0, r = 1e9;       while ((r - l) > 1e-6) {         double mid = (l + r) / 2;         if (check(mid))           r = mid;         else           l = mid;       }       printf( %.10lf n , l);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, sum = 0, q;     vector<int> v;     vector<int>::iterator it;     scanf( %d , &n);     while (n--) {       scanf( %d , &x);       sum += x;       v.push_back(sum);     }     int sz = v.size();     scanf( %d , &q);     while (q--) {       scanf( %d , &x);       it = lower_bound(v.begin(), v.end(), x);       printf( %d n , (it - v.begin()) + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[3005];   int main() {     int n;     int cnt = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (a[i] > a[j]) cnt++;       }     }     if (cnt % 2 == 0)       printf( %.6f , cnt * 2.0);     else       printf( %.6f , cnt * 2.0 - 1);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops )   #pragma GCC target( avx,avx2,fma )   using namespace std;   template <typename T>   using vc = vector<T>;   template <typename T>   using uset = unordered_set<T>;   template <typename A, typename B>   using umap = unordered_map<A, B>;   template <typename T, typename Comp = less<T>>   using pq = priority_queue<T, vc<T>, Comp>;   template <typename T>   using minpq = pq<T, greater<T>>;   using ld = long double;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using ppi = pair<pii, int>;   using pip = pair<int, pii>;   using vi = vc<int>;   using vii = vc<pii>;   constexpr char el =   n ;   constexpr char sp =    ;   constexpr int INF = 0x3f3f3f3f;   constexpr ll LLINF = 0x3f3f3f3f3f3f3f3fLL;   char g[8][8];   int dr[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};   int dc[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};   vi a[8][8];   bool good(int r, int c) { return 0 <= r && r < 8 && 0 <= c && c < 8; }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed;     for (auto& x : g)       for (auto& y : x) cin >> y;     for (int i = 0; i < 8; ++i)       for (int j = 0; j < 8; ++j)         if (g[i][j] ==  S )           for (int k = i; k < 8; ++k) a[k][j].push_back(k - i);     for (auto& x : a)       for (auto& y : x) sort(y.begin(), y.end());     queue<tuple<int, int, int>> q;     q.emplace(7, 0, 0);     while (!q.empty()) {       auto [r, c, d] = q.front();       q.pop();       for (int i = 0; i < 9; ++i) {         int r1 = r + dr[i];         int c1 = c + dc[i];         if (r1 == 0 && c1 == 7) {           cout <<  WIN ;           exit(0);         }         if (!good(r1, c1) || binary_search(begin(a[r1][c1]), end(a[r1][c1]), d) ||             binary_search(begin(a[r1][c1]), end(a[r1][c1]), d + 1))           continue;         q.emplace(r1, c1, d + 1);       }     }     cout <<  LOSE ;   }
#include <bits/stdc++.h>   using namespace std;   namespace INIT {   char buf[1 << 15], *fs, *ft;   inline char getc() {     return (fs == ft &&             (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft))                ? 0                : *fs++;   }   inline int read() {     int x = 0, f = 1;     char ch = getc();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getc();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getc();     }     return x * f;   }   }  // namespace INIT   using namespace INIT;   int n, p[1000010], vis[1000010], ans[1000010];   vector<int> a[1000010], b[1000010];   int main() {     n = read();     for (int i = 1; i <= n; ++i) p[i] = read();     for (int i = 1; i <= n; ++i) {       int num = 0;       for (int j = i; !vis[j]; j = p[j]) vis[j] = 1, ++num, a[i].push_back(j);       b[num].push_back(i);     }     for (int i = 1; i <= n; ++i)       if (i % 2 == 0 && (b[i].size() & 1)) {         puts( -1 );         return 0;       }     memset(vis, 0, sizeof(vis));     for (int i = 0; i <= (int)b[1].size() - 1; ++i) ans[b[1][i]] = b[1][i];     for (int i = 2; i <= n; ++i)       for (int j = 0; j <= (int)b[i].size() - 1; ++j) {         if (i & 1) {           int x = a[b[i][j]][0], y = a[b[i][j]][i / 2 + 1];           while (!vis[x]) {             vis[x] = vis[y] = 1;             ans[x] = y;             x = p[x];             ans[y] = x;             y = p[y];           }         } else {           int x = a[b[i][j]][0], y = a[b[i][j + 1]][0];           while (!vis[x] && !vis[y]) {             vis[x] = vis[y] = 1;             ans[x] = y;             x = p[x];             ans[y] = x;             y = p[y];           }           j++;         }       }     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   const int MAXM = 20010;   const int MAXNODE = 16 * MAXN;   const int LOGMAXN = 50;   const int INF = 0x3f3f3f3f;   const double eps = 1e-9;   int N, M;   int b[MAXM], z[MAXM], x[3 * (MAXN + MAXM)];   struct Tree {     int x, h;     double l, r;   } a[MAXN];   struct SegmentTree {     double mul[MAXNODE];     void build(int o, int L, int R) {       mul[o] = 1;       if (L >= R) return;       int mid = L + (R - L) / 2;       build(o << 1, L, mid);       build(o << 1 | 1, mid + 1, R);     }     void pushdown(int o) {       mul[o << 1] *= mul[o];       mul[o << 1 | 1] *= mul[o];       mul[o] = 1;     }     void update(int o, int L, int R, int ql, int qr, double p) {       if (ql <= L && qr >= R) {         mul[o] *= p;         return;       }       pushdown(o);       int mid = L + (R - L) / 2;       if (ql <= mid) update(o << 1, L, mid, ql, qr, p);       if (qr > mid) update(o << 1 | 1, mid + 1, R, ql, qr, p);     }     double query(int o, int L, int R, int pos) {       if (L >= R) return mul[o];       pushdown(o);       int mid = L + (R - L) / 2;       double ans;       if (pos <= mid)         ans = query(o << 1, L, mid, pos);       else         ans = query(o << 1 | 1, mid + 1, R, pos);       return ans;     }   } tree;   int main() {     while (scanf( %d%d , &N, &M) != EOF) {       int k = 0;       for (int i = 0; i < N; i++) {         scanf( %d%d%lf%lf , &a[i].x, &a[i].h, &a[i].l, &a[i].r);         a[i].l /= 100;         a[i].r /= 100;         x[k++] = a[i].x;         x[k++] = a[i].x - a[i].h;         x[k++] = a[i].x + a[i].h;       }       for (int i = 0; i < M; i++) {         scanf( %d%d , &b[i], &z[i]);         x[k++] = b[i];       }       sort(x, x + k);       k = unique(x, x + k) - x;       tree.build(1, 1, k);       for (int i = 0; i < N; i++) {         int qm = lower_bound(x, x + k, a[i].x) - x + 1;         int ql = lower_bound(x, x + k, a[i].x - a[i].h) - x + 1,             qr = lower_bound(x, x + k, a[i].x + a[i].h) - x + 1;         tree.update(1, 1, k, ql, qm - 1, (1 - a[i].l));         tree.update(1, 1, k, qm + 1, qr, (1 - a[i].r));       }       double ans = 0;       for (int i = 0; i < M; i++) {         int pos = lower_bound(x, x + k, b[i]) - x + 1;         ans += z[i] * tree.query(1, 1, k, pos);       }       printf( %.10lf n , ans);     }     return 0;   }
#include <bits/stdc++.h>   const int N = 502;   void sw(float* x) {     float tmp = *x;     *x = *(x + 2);     *(x + 2) = *(x + 1);     *(x + 1) = tmp;   }   int main() {     int _t;     scanf( %d , &_t);     while (_t--) {       static float arr[N];       static int anss[N * N];       static int tm[N];       memset(tm, 0, sizeof(tm));       int n;       scanf( %d , &n);       int f2 = -1;       for (int i = 1; i <= n; i++) {         int a;         scanf( %d , &a);         tm[a]++;         if (tm[a] == 2) f2 = a;         arr[i] = a + 0.0001 * tm[a];       }       int nx = 0;       for (int i = 1; i < n; i++)         for (int j = i + 1; j <= n; j++)           if (arr[i] > arr[j]) nx++;       if (nx & 1) {         if (f2 != -1) {           int f21 = -1, f22 = -1;           for (int i = 1; i <= n; i++)             if (((int)arr[i]) == f2) {               if (f21 == -1)                 f21 = i;               else if (f22 == -1)                 f22 = i;               else                 break;             }           std::swap(arr[f21], arr[f22]);           nx++;         } else {           printf( -1 n );           continue;         }       }       int ans = 0;       while (nx) {         for (int i = 1; i <= n - 2; i++) {           if (arr[i] < arr[i + 2] && arr[i + 2] < arr[i + 1] ||               arr[i] > arr[i + 2] && arr[i + 2] > arr[i + 1]) {             sw(arr + i);             anss[++ans] = i;           }           if (arr[i] < arr[i + 1] && arr[i] > arr[i + 2] ||               arr[i] > arr[i + 1] && arr[i + 1] > arr[i + 2]) {             sw(arr + i);             nx -= 2;             anss[++ans] = i;           }         }       }       printf( %d n , ans);       for (int i = 1; i <= ans; i++) printf( %d  , anss[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string test;     cin >> test;     for (int i = 0; i < m; i++) {       int l, r;       char c1, c2;       cin >> l >> r >> c1 >> c2;       l -= 1;       r -= 1;       for (; l <= r; l++) {         if (test[l] == c1) {           test[l] = c2;         }       }     }     cout << test << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const long long mod = 1e9 + 7;   char s[maxn];   int num[55];   long long dp[maxn];   long long tmp[maxn];   long long quesnum[55][55];   long long ques[55][55];   long long inv[maxn], fac[maxn], invf[maxn];   void init(int hf) {     inv[1] = 1;     for (int i = 2; i < maxn; i++)       inv[i] = ((mod - mod / i) * inv[mod % i]) % mod;     fac[0] = 1;     for (int i = 1; i < maxn; i++) fac[i] = (fac[i - 1] * (long long)i) % mod;     invf[0] = 1;     for (int i = 1; i < maxn; i++) invf[i] = (invf[i - 1] * inv[i]) % mod;     memset(dp, 0, sizeof(dp));     memset(ques, -1, sizeof(ques));     dp[0] = 1;     for (int i = 0; i < 55; i++) {       if (!num[i]) continue;       for (int j = hf; j >= num[i]; j--) {         dp[j] = (dp[j] + dp[j - num[i]]) % mod;       }     }     for (int i = 0; i < 52; i++) {       for (int j = i; j < 52; j++) {         for (int k = 0; k <= hf; k++) tmp[k] = dp[k];         for (int k = num[i]; k <= hf; k++)           tmp[k] = (tmp[k] - tmp[k - num[i]] + mod) % mod;         if (i != j)           for (int k = num[j]; k <= hf; k++)             tmp[k] = (tmp[k] - tmp[k - num[j]] + mod) % mod;         quesnum[i][j] = quesnum[j][i] = tmp[hf];       }     }   }   int main() {     scanf( %s , s);     memset(num, 0, sizeof(num));     int len = strlen(s);     int hf = len / 2;     for (int i = 0; i < len; i++) {       if (s[i] >=  a  && s[i] <=  z )         num[s[i] -  a ]++;       else         num[s[i] -  A  + 26]++;     }     init(hf);     int q;     scanf( %d , &q);     int x, y;     while (q--) {       scanf( %d%d , &x, &y);       x--;       y--;       int idx, idy;       if (s[x] >=  a  && s[x] <=  z )         idx = s[x] -  a ;       else         idx = s[x] -  A  + 26;       if (s[y] >=  a  && s[y] <=  z )         idy = s[y] -  a ;       else         idy = s[y] -  A  + 26;       if (ques[idx][idy] != -1) {         printf( %I64d n , ques[idx][idy]);         continue;       }       long long ans;       if (idx == idy) {         if (num[idx] > hf) {           printf( 0 n );           ques[idx][idx] = 0;           continue;         }         long long cc =             ((fac[hf] * invf[num[idx]]) % mod * invf[hf - num[idx]]) % mod;         ans = ((cc * fac[hf - num[idx]]) % mod * fac[hf]) % mod;       } else {         if (num[idx] + num[idy] > hf) {           ques[idx][idy] = ques[idy][idx] = 0;           printf( 0 n );           continue;         }         int numx = num[idx], numy = num[idy];         int num_hfx = hf - numx;         long long cc1 = ((fac[hf] * invf[numx]) % mod * invf[hf - numx]) % mod;         long long cc2 =             ((fac[num_hfx] * invf[numy]) % mod * invf[num_hfx - numy]) % mod;         ans = (((cc1 * cc2) % mod * fac[hf]) % mod * fac[hf - numx - numy]) % mod;       }       for (int i = 0; i < 55; i++) {         if (i == idx || i == idy) continue;         ans = (ans * invf[num[i]]) % mod;       }       ans = (ans * quesnum[idx][idy]) % mod;       ans = (ans * 2) % mod;       ques[idx][idy] = ques[idy][idx] = ans;       printf( %I64d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500000 + 10;   int a[MAXN];   int n, m, ans, tp, tot;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     ans = n;     sort(a + 1, a + 1 + n);     for (int i = n / 2; i >= 1; --i)       if (a[ans] >= a[i] * 2) --ans;     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   char a[500001 + 10], b[500001 + 10], s[(500001 << 1) + 10];   int n, m;   struct BIT {     long long c[500001 << 1];     long long query(int x) {       if (x <= 0) return 0;       long long ans = 0;       for (int i = x; i; i -= (i & -i)) ans += c[i];       return ans;     }     void add(int x, long long p) {       if (x <= 0) x = 1;       for (int i = x; i <= 1000000; i += (i & -i)) c[i] += p;     }   } b1, b2;   int za[500001 * 3], zb[500001 * 3];   char mod[500001 * 3];   void zfunc(char *s, int n, int *z) {     int l = 0, r = 0;     z[1] = n;     int pt;     for (int i = 2; i <= n; ++i) {       if (r < i) {         for (pt = i; pt <= n && s[pt] == s[pt - i + 1]; ++pt)           ;         --pt;         z[i] = pt - i + 1;         if (z[i]) l = i, r = pt;       } else {         int b = r - i + 1, i_ = i - l + 1;         if (z[i_] < b)           z[i] = z[i_];         else {           for (pt = r + 1; pt <= n && s[pt] == s[pt - i + 1]; ++pt)             ;           --pt;           z[i] = pt - i + 1;           l = i, r = pt;         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     scanf( %s%s%s , a + 1, b + 1, s + 1);     memcpy(mod + 1, s + 1, m - 1);     mod[m] =  $ ;     memcpy(mod + m + 1, a + 1, n);     zfunc(mod, n + m, za);     for (int i = 1; i <= n; ++i) za[i] = za[i + m];     reverse(s + 1, s + 1 + m);     reverse(b + 1, b + 1 + n);     memcpy(mod + 1, s + 1, m - 1);     mod[m] =  $ ;     memcpy(mod + m + 1, b + 1, n);     zfunc(mod, n + m, zb);     for (int i = 1; i <= n; ++i) zb[i] = zb[i + m];     reverse(zb + 1, zb + 1 + n);     int cur = 1;     long long ans = 0;     for (int i = 1; i <= n; ++i) {       while (cur <= min(i + m - 2, n))         b1.add(m - 1 - zb[cur], 1), b2.add(m - 1 - zb[cur], zb[cur]), ++cur;       ans += 1ll * b1.query(za[i]) * (za[i] - m + 1) + b2.query(za[i]);       b1.add(m - 1 - zb[i], -1), b2.add(m - 1 - zb[i], -zb[i]);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int dec(string s, int n) {     long long int r = 0, p = 0, l = s.size() - 1, tmp;     while (l >= 0) {       if (isalpha(s[l]))         tmp = s[l] - 55;       else         tmp = s[l] - 48;       int prod = 1;       for (int k = 0; k < p; k++) prod *= n;       r += prod * tmp;       p++;       l--;     }     return r;   }   int main() {     string s, a, b;     int mx = 0;     cin >> s;     int i = 0;     while (s[i] !=  : ) {       a.push_back(s[i]);       if (mx < s[i]) mx = s[i];       i++;     }     i++;     while (s[i] !=   0 ) {       b.push_back(s[i]);       if (mx < s[i]) mx = s[i];       i++;     }     int bg;     bg = mx < 65 ? mx - 48 : mx - 55;     int beg = max(2, bg + 1);     if (dec(a, beg) >= 24 || dec(b, beg) >= 60) {       cout << 0 << endl;       return 0;     }     if (dec(a, 100) < 24 && dec(b, 100) < 60) {       cout << -1 << endl;       return 0;     }     for (i = beg;; i++) {       if (dec(a, i) < 24 && dec(b, i) < 60) {         cout << i <<    ;       } else         break;     }     return 0;   }