malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int f = 1, mod;   void calc(int sum, int t) {     for (int i = 1; i <= sum; i++) {       if (i % 2 or !t)         f = (f * i) % mod;       else         f = (f * (i / 2)) % mod, t--;     }   }   int main() {     int n, p, count = 0, a[200001] = {0};     cin >> n;     vector<pair<int, int> > v;     for (int i = 1; i <= n; i++) cin >> p, v.push_back(make_pair(p, i));     for (int i = 1; i <= n; i++) cin >> p, v.push_back(make_pair(p, i));     sort(v.begin(), v.end());     int i = 0;     cin >> mod;     while (i < v.size()) {       int t = 0, sum = 0;       count++;       a[v[i].second] = count;       i++;       while (i < 2 * n and v[i].first == v[i - 1].first) {         if (a[v[i].second] == count) t++;         a[v[i].second] = count;         sum++;         i++;       }       calc(sum + 1, t);     }     cout << f;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 999999999999999999;   const double PI = acos(-1.0);   void stop() { exit(0); }   long long A[200005];   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> A[i];     }     long long res = 1;     long long curr = 1;     for (long long i = 0; i < n - 1; i++) {       if (A[i] * 2 >= A[i + 1]) {         curr++;       } else {         if (curr > res) res = curr;         curr = 1;       }     }     if (curr > res) res = curr;     cout << res;     stop();   }
#include <bits/stdc++.h>   using namespace std;   int abs(int x) {     if (x < 0) return -x;     return x;   }   int n, m;   int x[500], y[500], l[500];   bool used[500];   int placed[500];   int dist(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     for (int i = 0; i < m; i++) cin >> l[i];     if (2 * m + 1 < n || n % 2 == 1) {       cout <<  NO  << endl;       return 0;     }     bool good = true;     for (int k = 0; k < 2; k++) {       if (k == 1 && good) break;       good = true;       memset(used, 0, 500 * sizeof(used[0]));       for (int i = 0; i < n; i++) placed[i] = -2;       for (int i = k; i < n; i += 2) {         int len = dist(i, (i - 1 + n) % n) + dist(i, (i + 1) % n);         bool match = false;         for (int j = 0; j < m; j++) {           if (!used[j] && l[j] == len) {             used[j] = 1;             placed[i] = j;             match = true;             break;           }         }         if (!match) {           good = false;           break;         }       }     }     if (!good)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       cout << placed[0] + 1;       for (int i = 1; i < n; i++) cout <<     << placed[i] + 1;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, sum = 0, s[100005], ans[100005], an = 0;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &s[i]);       sum += s[i];     }     if (sum % k) {       printf( No );       return 0;     }     int m = sum / k;     int now = 0, len = 0;     for (int i = 1; i <= n; i++) {       if (now + s[i] > m) {         printf( No );         return 0;       }       now += s[i];       len++;       if (now == m) {         ans[++an] = len;         now = len = 0;       }     }     printf( Yes n );     for (int i = 1; i <= k; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1e9 + 7;   long long int INF = 1e18;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int i, j, k = 0, m = 0, n, p = 0, l, r, ans = 0, cnt = 0,                         mini = INF, maxi = INF, x, y, a, b, c, low, mid, high, h,                         q, k1, l1, t;     cin >> n >> m;     long long int A[m][n + 1];     long long int B[m][n + 1];     for (j = 0; j < m; j++) {       for (i = 1; i <= n; i++) {         cin >> k;         A[j][i] = k;         B[j][k] = i;       }     }     ans = n;     h = 1;     for (i = 1; i < n; i++) {       j = 0;       l = A[j][i];       r = A[j][i + 1];       p = 0;       for (j = 1; j < m; j++) {         if ((B[j][r] - B[j][l]) != 1) {           h = 1;           p = 1;           break;         }       }       if (p == 0) {         h++;         ans = ans + (h - 1);       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200009;   const long long MOD = 119 << 23 | 1;   class {    public:     bool g[1 << 22];     int a[1 << 22];     int N, M, n, m;     void solve() {       int _;       cin >> _;       while (_--) {         cin >> n >> m;         N = (1 << n) - 1;         M = (1 << m) - 1;         for (int i = 1; i <= N; ++i) cin >> a[i];         for (int i = M + 1; i <= N; ++i) g[i] = 1;         for (int i = M; i; --i) {           if (a[i << 1] < a[i << 1 | 1]) {             g[i] = g[i << 1 | 1];           } else {             g[i] = g[i << 1];           }         }         vector<int> ans;         int rt = 1;         for (int i = 0; i < N - M; ++i) {           while (!g[rt]) rt++;           ans.push_back(rt);           down(rt);         }         long long sum = 0;         for (int i = 1; i <= M; ++i) sum += a[i];         cout << sum <<   n ;         for (int i : ans) cout << i <<    ;         cout <<   n ;         for (int i = 1; i <= N; ++i) g[i] = a[i] = 0;       }     }     void down(int rt) {       int lson = rt << 1, rson = rt << 1 | 1;       if (a[lson] == 0 && a[rson] == 0) {         a[rt] = 0;         g[rt] = 0;         return;       }       if (a[lson] > a[rson]) {         a[rt] = a[lson];         down(lson);       } else {         a[rt] = a[rson];         down(rson);       }       if (rt <= M) {         if (a[lson] > a[rson])           g[rt] = g[lson];         else           g[rt] = g[rson];       }     }   } NSPACE;   int main() {     ;     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     NSPACE.solve();   }
#include <bits/stdc++.h>   using namespace std;   int n, a[200000];   bool st[200000][2];   long long memo[200000][2];   long long solve(int node, int rev) {     if (node < 0 || node >= n) return 0;     if (st[node][rev]) return 0x3f3f3f3f3f3f3f3fll;     if (node == 0) return 0;     long long& val = memo[node][rev];     if (val != 0xc0c0c0c0c0c0c0c0ll) return val;     st[node][rev] = true;     val = solve(node + a[node] * (1 - 2 * rev), 1 - rev);     if (val != 0x3f3f3f3f3f3f3f3fll) val += a[node];     st[node][rev] = false;     return val;   }   int main() {     ios::sync_with_stdio(0);     memset(st, false, sizeof st);     memset(memo, 0xc0c0c0c0c0c0c0c0ll, sizeof memo);     cin >> n;     for (int i = 1; i < n; ++i) cin >> a[i];     for (int i = 1; i < n; ++i) {       st[0][0] = true;       long long ans = solve(i, 1);       if (ans == 0x3f3f3f3f3f3f3f3fll)         ans = -1;       else         ans += i;       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long int a[500005], n, d;   long long int ans = 0;   void func(long long int st, long long int ed) {     if (st + 1 == ed) return;     if (a[st] == a[ed]) {       ans = max(ans, (ed - st) / 2);       for (int i = st; i <= ed; ++i) {         a[i] = a[st];       }     } else {       ans = max(ans, (ed - st) / 2);       for (int i = st + 1; i <= (st + ed) / 2; ++i) {         a[i] = a[st];       }       for (int i = (st + ed) / 2 + 1; i <= ed; ++i) {         a[i] = a[ed];       }     }   }   int main(int argc, char const *argv[]) {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     long long int start, endx;     a[0] = a[1];     start = 1;     endx = n;     for (int i = start; i < endx; ++i) {       if (a[i] == a[i + 1]) {         func(start, i);         start = i + 1;       }     }     func(start, endx);     printf( %lld n , ans);     for (int i = 1; i <= n; ++i) {       cout << a[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     set<string> qq;     string s, q, g[100000];     int h, j = -1;     while (cin >> s) {       h = 3;       q =   ;       q = q + s[0] + s[1] + s[2];       while (h != s.length()) {         while (s[h] !=      && s[h] !=  . ) {           q += s[h];           h++;         }         q +=  / ;         if (s[h] !=  . ) {           j++;           g[j] = q;         } else           break;         h++;       }     }     j++;     sort(g, g + j);     int p = 1, max = 1;     qq.insert(g[0]);     for (int i = 1; i < j; i++) {       if (g[i] == g[i - 1])         p++;       else         p = 1;       if (p > max) max = p;       qq.insert(g[i]);     }     set<string>::iterator it;     string w =   , t =   ;     int r = 0, max2 = 0;     for (it = qq.begin(); it != qq.end(); it++) {       if (w ==   )         w = *it;       else {         t =   ;         p = 1;         for (int i = 0; i < w.length(); i++) {           if (i == (*it).length()) {             p = 0;             break;           }           t += (*it)[i];         }         if (t != w) p = 0;         if (p == 0) {           w = *it;           r = 0;         } else {           r++;         }         if (r > max2) max2 = r;       }     }     cout << max2 <<     << max;     return 0;   }
#include <bits/stdc++.h>   int m(int a) {     int ret = 0, i = 1;     while (a > 0) {       if (a % 10 == 4 || a % 10 == 7) {         ret += (i * (a % 10)), i *= 10;       }       a /= 10;     }     return ret;   }   int main() {     int a, b;     while (scanf( %d%d , &a, &b) != EOF) {       while (1) {         a++;         if (m(a) == b) {           printf( %d n , a);           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       int cnt = 0;       reverse(s.begin(), s.end());       cnt += (s[0] -  0 );       for (int i = 1; i < n; i++) {         if (s[i] !=  0 ) cnt = cnt + 1 + (s[i] -  0 );       }       cout << cnt <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long f[1000001][4][2];   string s;   signed main() {     cin >> s;     for (long long lst = 0; lst < 4; lst++)       f[s.length()][lst][0] = f[s.length()][lst][1] = 0;     f[s.length()][0][0] = f[s.length()][1][0] = f[s.length()][3][0] = 1;     for (long long i = s.length() - 1; i >= 0; --i) {       for (long long lst = 0; lst < 4; lst++) {         f[i][lst][0] = f[i][lst][1] = 0;         if (s[i] ==  * )           f[i][lst][1] = (f[i + 1][3][1] + f[i + 1][3][0]) % 1000000007;         else if (s[i] !=  ? ) {           long long c = s[i] -  0 ;           if (lst == 3) c--;           if (c >= 0 && c < 2) f[i][lst][0] = f[i + 1][s[i] -  0 ][c];         } else {           long long c = (lst == 3);           f[i][lst][0] = (f[i + 1][c][0] + f[i + 1][c + 1][1]) % 1000000007;           f[i][lst][1] = (f[i + 1][3][1] + f[i + 1][3][0]) % 1000000007;         }       }     }     cout << (f[0][0][0] + f[0][1][1]) % 1000000007;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     long long int n, sum = 0, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       sum = sum + (x / k);       if (x % k != 0) sum++;     }     cout << (sum + 1) / 2 << endl;   }
#include <bits/stdc++.h>   int main() {     int a, b, c;     while (~scanf( %d%d%d , &a, &b, &c)) {       int max = 999999999;       int a1 = (c + b) + a;       max = max < a1 ? max : a1;       int a2 = 2 * (c + b);       max = max < a2 ? max : a2;       int b1 = (c + a) * 2;       max = max < b1 ? max : b1;       int b2 = (b + a) * 2;       max = max < b2 ? max : b2;       printf( %d n , max);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   const int MAXM = 100005;   long long res[MAXM];   vector<int> seq[MAXN];   vector<pair<int, int> > qry[MAXN];   int L[MAXN], A[MAXM], H[MAXM];   int n, m;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 2; i <= n; i++) cin >> L[i];     for (int i = 1; i <= m; i++) cin >> A[i] >> H[i];     for (int i = 1; i <= m; i++) {       int a = A[i], h = H[i];       qry[a].push_back(make_pair(h, i));       while (a > 1 && h > 0) {         if ((a ^ 1) <= n && h - L[a] - L[a ^ 1] > 0)           qry[a ^ 1].push_back(make_pair(h - L[a] - L[a ^ 1], i));         if (h - L[a] > 0) res[i] += h - L[a];         h -= L[a], a >>= 1;       }     }     for (int i = n; i >= 1; i--) {       int x = i * 2, y = i * 2 + 1;       seq[i].push_back(0);       if (x <= n && y <= n) {         for (int j = 0; j < seq[x].size(); j++)           seq[i].push_back(seq[x][j] + L[x]);         for (int j = 0; j < seq[y].size(); j++)           seq[i].push_back(seq[y][j] + L[y]);         seq[x].clear(), seq[y].clear();         sort(seq[i].begin(), seq[i].end());       } else if (x <= n) {         for (int j = 0; j < seq[x].size(); j++)           seq[i].push_back(seq[x][j] + L[x]);         seq[x].clear();       }       sort(qry[i].begin(), qry[i].end());       long long sum = 0;       int p = 0;       for (int j = 0; j < seq[i].size(); j++) {         sum += seq[i][j];         while (p != qry[i].size() &&                (j + 1 == seq[i].size() || seq[i][j + 1] > qry[i][p].first)) {           res[qry[i][p].second] += 1ll * (j + 1) * qry[i][p].first - sum;           p++;         }       }     }     for (int i = 1; i <= m; i++) cout << res[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int n;   long long r, a[(1LL << 20)], x, y;   int main() {     scanf( %d %I64d , &n, &r);     long long sum = 0;     double qpw = 1;     for (int i = 1; i <= n; ++i) qpw *= 2;     for (int i = 1; i <= qpw; ++i) {       scanf( %I64d , &a[i]);       sum += a[i];     }     printf( %.6f n , sum * 1.0 / qpw);     double ans = 0;     while (r--) {       scanf( %I64d %I64d , &x, &y);       sum += (y - a[x + 1]);       a[x + 1] = y;       ans = sum * 1.0 / qpw;       printf( %.6f n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 500010;   vector<vector<long long int> > ch, ar;   void multiply(vector<vector<long long int> > &a,                 vector<vector<long long int> > &b) {     vector<vector<long long int> > c;     c.resize(a.size(), vector<long long int>(b[0].size(), 0));     for (long long int i = 0; i < a.size(); ++i) {       for (long long int j = 0; j < b[0].size(); ++j) {         c[i][j] = 0;         for (long long int k = 0; k < a[0].size(); ++k) {           c[i][j] = (c[i][j] + (a[i][k] * b[k][j]) % 1000000007) % 1000000007;         }       }     }     a = c;   }   void power_matrix(long long int n) {     if (n == 1) {       ar = ch;       return;     }     power_matrix(n / 2);     multiply(ar, ar);     if (n % 2 == 1) {       multiply(ar, ch);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, b, k, x;     cin >> n >> b >> k >> x;     long long int bh[10] = {0};     for (long long int i = 0; i < n; ++i) {       long long int a;       cin >> a;       bh[a] += 1;     }     ch.resize(x, vector<long long int>(x, 0));     for (long long int i = 0; i < x; ++i) {       for (long long int j = 0; j < 10; ++j) {         ch[i][(10 * i + j) % x] += bh[j];       }     }     power_matrix(b);     cout << ar[0][k] << endl;     return (0);   }
#include <bits/stdc++.h>   using namespace std;   const int M = 21, N = 1e5 + 5, INF = 123456789;   int dp[(1 << M)], sum[(1 << M)][M];   int cnt[25][25], n, m;   char s[N];   int main() {     scanf( %d%d , &n, &m);     scanf( %s , (s + 1));     int len = strlen(s + 1);     for (int i = 2; i <= len; i++) {       cnt[s[i - 1] -  a  + 1][s[i] -  a  + 1]++;       cnt[s[i] -  a  + 1][s[i - 1] -  a  + 1]++;     }     for (int i = 1; i <= m; i++) cnt[i][i] = 0;     memset(dp, 0x7f, sizeof(dp));     dp[0] = 0;     for (int S = 0; S < (1 << m); S++) {       int summ = 0, T = (S ^ ((1 << m) - 1));       bool ex[M];       for (int x = 1; x <= m; x++) {         if (S & (1 << (x - 1))) {           ex[x] = 1;           summ++;         } else           ex[x] = 0;       }       for (int x = 1; x <= m; x++) {         if (ex[x]) continue;         int tmpsum = 0;         for (int y = 1; y <= m; y++) {           if (!ex[y]) {             tmpsum -= cnt[x][y];           }           if (ex[y]) {             tmpsum += cnt[x][y];           }         }         dp[S | (1 << (x - 1))] = min(1ll * dp[S | (1 << (x - 1))],                                      dp[S] + 1ll * (summ + 1) * (tmpsum));       }     }     printf( %d , dp[(1 << m) - 1]);   }
#include <bits/stdc++.h>   using namespace std;   int n, m, s, k, x, y, z, i, j, ans = 0;   int a[2001][2], b[2001][2];   int main() {     memset(a, 192, sizeof a);     memset(b, 63, sizeof b);     cin >> n >> m >> k >> s;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         cin >> x;         a[x][0] = max(a[x][0], i + j);         b[x][0] = min(b[x][0], i + j);         a[x][1] = max(a[x][1], i - j);         b[x][1] = min(b[x][1], i - j);       }     for (i = 1, z, y; i <= s; i++, y = z) {       cin >> z;       if (i > 1)         ans = max(ans, max(max(a[y][0] - b[z][0], a[z][0] - b[y][0]),                            max(a[y][1] - b[z][1], a[z][1] - b[y][1])));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200100;   const long long inf = 1e8;   long long bit[N];   void up(int x) {     while (x < N) {       bit[x]++;       x += (x & -x);     }   }   int query(int x) {     int sum = 0;     while (x) {       sum += bit[x];       x -= (x & -x);     }     return sum;   }   pair<int, int> a[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, t;     cin >> n >> t;     for (int i = 0; i < n; ++i) {       cin >> a[i].first;       a[i].first -= i + 1;       a[i].second = i + 1;     }     sort(a, a + n);     int ans = 0;     for (int i = 0; i < n; ++i) {       up(a[i].second);       if (a[i].first < 0 && t > 1) ans = max(ans, query(min(t - 1, n)));       if (a[i].first + 1 < t && a[i].first >= 0)         ans = max(ans, query(min(t - a[i].first - 1, n)));     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMax = 110000;   const long long INF = 4294967296LL;   int N, sum[NMax];   char A[NMax];   int S[NMax], L;   unsigned int dp[3][NMax];   int main() {     scanf( %d %s , &N, A);     if (N & 1) {       puts( 0 );       return 0;     }     int cur = 1, cnt = 0;     dp[1][0] = 1;     for (int i = 0; i < N; i++) {       cur = 1 - cur;       int start = 1 - (i & 1), end = min(N / 2, i + 1);       if (A[i] ==  ? )         for (int j = start; j <= end; j += 2)           dp[cur][j] = dp[1 - cur][j + 1] + (j > 0 ? dp[1 - cur][j - 1] : 0);       else {         cnt++;         for (int j = start; j <= end; j += 2)           dp[cur][j] = j > 0 ? dp[1 - cur][j - 1] : 0;       }     }     if (cnt > N / 2) {       puts( 0 );       return 0;     }     cnt = N / 2 - cnt;     while (cnt--) dp[cur][0] *= 25;     printf( %u n , dp[cur][0]);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e5 + 10;   int n, m, a[N];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> a[i];     a[n + 1] = m;     vector<int> pfs(n + 2, 0), pos(n + 2, 0);     for (int i = 1; i <= n + 1; ++i) {       if (i & 1) {         if (i - 2 >= 0) pfs[i] = pfs[i - 2];         pfs[i] += a[i] - a[i - 1];       } else {         pfs[i] = pfs[i - 1];       }     }     if (n & 1) {       for (int i = n; i >= 0; --i) {         if ((n - i) & 1) {           pos[i] = pos[i + 1];         } else {           if (i + 2 <= n) pos[i] = pos[i + 2];           pos[i] += a[i + 1] - a[i];         }       }     } else {       for (int i = n; i >= 0; --i) {         if ((n - i) & 1) {           if (i + 2 <= n) pos[i] = pos[i + 2];           pos[i] += a[i + 1] - a[i];         } else {           pos[i] = pos[i + 1];         }       }     }     int ans = pfs[n + 1];     for (int i = 0; i <= n + 1; ++i) {       if (a[i] - 1 > 0 and a[i] - 1 != a[i - 1]) {         int now_ans;         if (i & 1) {           now_ans = pfs[i] - 1 + pos[i];         } else {           now_ans = pfs[i - 1] + 1 + pos[i];         }         ans = max(ans, now_ans);       }       if (a[i] + 1 < m and a[i] + 1 != a[i + 1]) {         int now_ans;         if (i & 1) {           now_ans = pfs[i] + a[i + 1] - a[i] - 1 + pos[i + 1];         } else {           now_ans = pfs[i] + 1 + pos[i + 1];         }         ans = max(ans, now_ans);       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int abs(int x) {     if (x < 0) return -x;     return x;   }   int up[100005], lo[100005], a[100001][15];   int main() {     int n, m, q;     scanf( %d , &n), scanf( %d , &m);     scanf( %d , &q);     int i, j, x, y;     for (i = (0); i < (n); i++) {       for (j = (0); j < (m); j++) {         scanf( %d , &a[i][j]);       }     }     for (i = (0); i < (q); i++) {       scanf( %d , &x), scanf( %d , &y);       x--, y--;       lo[x]--;       up[y]++;     }     for (i = (0); i < (m); i++) {       for (j = (0); j < (n); j++) {         if (a[j][i]) lo[j] += up[i];       }     }     for (i = (0); i < (n); i++) {       cout << lo[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long gcd(long long n1, long long n2) {     return n2 == 0 ? abs(n1) : gcd(n2, n1 % n2);   }   inline long long lcm(long long n1, long long n2) {     return n1 == 0 || n2 == 0 ? 0 : abs(n1 * (n2 / gcd(n1, n2)));   }   const int INF = 1000000000;   const int MAXN = 1000006;   int mat[MAXN][30];   int mark[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     while (cin >> n >> m) {       string s1, s2;       cin >> s1 >> s2;       long long t1 = (int)s1.size(), t2 = (int)s2.size();       long long x = gcd(t1, t2);       memset(mark, 0, sizeof mark);       memset(mat, 0, sizeof mat);       for (int i = 0; i < t1; ++i) mat[i % x][s1[i] -  a ]++;       long long res = 0LL;       for (int i = 0; i < t2; ++i) res += (t1 / x) - mat[i % x][s2[i] -  a ];       res *= (t1 * n) / lcm(t1, t2);       cout << res << endl;     }   }