malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 20;   const int inf = 1e9;   int dp[maxn][maxn][maxn];   int vis[maxn][maxn][maxn];   int path[maxn][maxn][maxn];   int n, a, b;   int h[maxn];   int dfs(int i, int cur, int pre) {     cur = cur < 0 ? 0 : cur;     pre = pre < 0 ? 0 : pre;     if (i == n) {       if (cur == 0)         return 0;       else         return inf;     }     if (vis[i][cur][pre]) return dp[i][cur][pre];     vis[i][cur][pre] = 1;     int &ans = dp[i][cur][pre];     ans = inf;     int lb = (pre + b - 1) / b,         hb = max(lb, max((cur + a - 1) / a, (h[i + 1] + b) / b));     int p;     for (int j = lb; j <= hb; j++) {       int tmp = j + dfs(i + 1, h[i + 1] + 1 - j * b, cur - j * a);       if (ans > tmp) {         ans = tmp;         path[i][cur][pre] = j;       }     }     return ans;   }   void print(int i, int cur, int pre) {     cur = cur < 0 ? 0 : cur;     pre = pre < 0 ? 0 : pre;     if (i == n) return;     int tmp = path[i][cur][pre], cnt = tmp;     while (cnt--) printf( %d  , i);     print(i + 1, h[i + 1] + 1 - tmp * b, cur - tmp * a);   }   int main() {     cin >> n >> a >> b;     for (int i = 1; i <= n; i++) cin >> h[i];     memset(vis, 0, sizeof(vis));     int ans = dfs(2, h[2] + 1, h[1] + 1);     cout << ans <<   n ;     print(2, h[2] + 1, h[1] + 1);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s, s1, s2, s3;   int sa[300010][20], lcp[300010], rnk[300010], root[300010], cnt[300010][4],       col[300010], n;   pair<pair<int, int>, int> q[300010];   pair<int, pair<int, int> > lcp_pair[300010];   vector<long long> ansvec;   long long ans, mod = 1e9 + 7;   int get(int x) { return root[x] = (x == root[x] ? x : get(root[x])); }   void merge(int x, int y) {     root[y] = x;     ans -= (1LL * cnt[y][1] * cnt[y][2] * cnt[y][3]) % mod +            (1LL * cnt[x][1] * cnt[x][2] * cnt[x][3]) % mod;     while (ans < 0) ans += mod;     for (int i = 1; i <= 3; ++i) cnt[x][i] += cnt[y][i];     ans = (ans + 1LL * cnt[x][1] * cnt[x][2] * cnt[x][3]) % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s1 >> s2 >> s3;     n = min(s1.size(), min(s2.size(), s3.size()));     s = s1 +  1  + s2 +  2  + s3;     for (int i = 0; i < s1.size(); ++i) col[i] = 1;     for (int i = s1.size() + 1; i < s1.size() + 1 + s2.size(); ++i) col[i] = 2;     for (int i = s.size() - s3.size(); i < s.size(); ++i) col[i] = 3;     for (int i = 0; i < s.size(); ++i) sa[i][0] = s[i];     for (int i = 1; i < 20; ++i) {       for (int j = 0; j < s.size(); ++j)         if (j + (1 << i - 1) < s.size())           q[j] =               make_pair(make_pair(sa[j][i - 1], sa[j + (1 << i - 1)][i - 1]), j);         else           q[j] = make_pair(make_pair(sa[j][i - 1], -1), j);       sort(q, q + s.size());       int cnt = 0;       for (int j = 0; j < s.size(); ++j) {         if (j && q[j].first != q[j - 1].first) ++cnt;         sa[q[j].second][i] = cnt;       }     }     for (int i = 0; i < s.size(); ++i) {       rnk[sa[i][19]] = i;       root[i] = i;       cnt[i][col[i]] = 1;     }     int cnt = 0, index, ii = 0;     for (int i = 0; i < s.size(); ++i) {       index = sa[i][19];       if (index == s.size() - 1) {         cnt = 0;         continue;       }       while (i + cnt < s.size() && rnk[index + 1] + cnt < s.size() &&              s[i + cnt] == s[rnk[index + 1] + cnt])         ++cnt;       lcp[i] = cnt;       lcp_pair[ii] = make_pair(lcp[i], make_pair(i, rnk[index + 1]));       if (cnt) --cnt;       ++ii;     }     sort(lcp_pair, lcp_pair + s.size() - 1);     reverse(lcp_pair, lcp_pair + s.size() - 1);     for (int i = n, j = 0; i >= 1; --i) {       int x, y;       while (j < s.size() - 1 && lcp_pair[j].first >= i) {         x = get(lcp_pair[j].second.first);         y = get(lcp_pair[j].second.second);         merge(x, y);         ++j;       }       ansvec.push_back(ans);     }     for (int i = ansvec.size() - 1; i >= 0; --i) cout << ansvec[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   vector<string> v;   string s;   const int N = 1000001;   int n;   long long d, arr[N];   unsigned long long gcd(long long x, long long y) {     if (y == 0) {       return x;     }     return gcd(y, x % y);   }   void gen(long long ind, string t) {     if (ind == s.size()) {       if (t.size() == 3) v.push_back(t);       return;     }     gen(ind + 1, t + s[ind]);     gen(ind + 1, t);   }   long long check() {     long long res = 0;     for (long long i = 0; i < v.size(); ++i) {       if (((v[i][v[i].size() - 1] -  0 ) - (v[i][0] -  0 )) <= d) {         res++;       }     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, l, r;     bool lie = 0;     cin >> n >> l >> r;     int v[n], s[n];     for (int i = 1; i <= n; ++i) {       cin >> v[i];     }     for (int i = 1; i <= n; ++i) {       cin >> s[i];     }     for (int i = 1; i < l; ++i) {       if (v[i] != s[i]) {         lie = 1;         break;       }     }     if (!lie) {       for (int i = r + 1; i <= n; ++i) {         if (v[i] != s[i]) {           lie = 1;           break;         }       }     }     if (lie) {       cout <<  LIE n ;     } else {       cout <<  TRUTH n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 + 9e6;   const int inf = 0x3f3f3f;   vector<bool> dp[24];   int n;   int a[23];   vector<pair<int, int> > pre[23];   int ans;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < 24; i++) dp[i].resize(1 << n);     for (int i = 1; i < n; ++i) {       for (int j = 0; j < i; ++j) {         for (int k = j; k < i; ++k) {           if (a[j] + a[k] == a[i]) {             pre[i].push_back({j, k});           }         }       }     }     dp[0][0] = 0;     dp[0][1] = 1;     for (int i = 0; i < n - 1; ++i) {       for (int mask = 0; mask < (1 << n); ++mask) {         if (dp[i][mask]) {           for (int j = 0; j < pre[i + 1].size(); ++j) {             int u = pre[i + 1][j].first;             int v = pre[i + 1][j].second;             if (((mask >> u) & 1) && ((mask >> v) & 1)) {               int bit = mask + (1 << (i + 1));               dp[i + 1][bit] = 1;               for (int k = 0; k < i + 1; ++k) {                 if (((bit >> k) & 1)) {                   dp[i + 1][bit ^ (1 << k)] = 1;                 }               }             }           }         }       }     }     ans = inf;     for (int mask = 0; mask < (1 << n); ++mask) {       if (dp[n - 1][mask]) {         ans = min(ans, (int)(__builtin_popcount(mask)));       }     }     if (ans == inf)       cout << -1;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string onezero(int n) {     string s =  1 ;     for (int i = 1; i < n; ++i) {       s +=  0 ;     }     return s;   }   string findSum(string str1, string str2) {     if (str1.length() > str2.length()) swap(str1, str2);     string str =   ;     int n1 = str1.length(), n2 = str2.length();     reverse(str1.begin(), str1.end());     reverse(str2.begin(), str2.end());     int carry = 0;     for (int i = 0; i < n1; i++) {       int sum = ((str1[i] -  0 ) + (str2[i] -  0 ) + carry);       str.push_back(sum % 10 +  0 );       carry = sum / 10;     }     for (int i = n1; i < n2; i++) {       int sum = ((str2[i] -  0 ) + carry);       str.push_back(sum % 10 +  0 );       carry = sum / 10;     }     if (carry) str.push_back(carry +  0 );     reverse(str.begin(), str.end());     return str;   }   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     int l;     string s, ans;     cin >> l >> s;     if (s.size() % l != 0) {       string zero = onezero(l);       for (int i = 0; i < s.size() / l + 1; ++i) {         ans += zero;       }     } else {       string temp = s.substr(0, l);       for (int i = 0; i < s.size() / l; ++i) {         ans += temp;       }       if (ans <= s) {         ans =   ;         temp = findSum(temp,  1 );         if (temp.size() != l) {           temp = onezero(l);           ans = onezero(l);         }         for (int i = 0; i < s.size() / l; ++i) {           ans += temp;         }       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 1;   long long int n, m, i, j, l, k, x, y, a, b, cnt[3], sum[3];   void solve() {     string s;     cin >> s;     long long int n = s.length();     long long int lst = 0, maxi = -1;     long long int val = 0;     for (long long int i = 0; i < n; i++) {       if (s[i] ==  L ) {         val++;       } else {         maxi = max(maxi, val);         val = 0;       }     }     maxi = max(maxi, val);     cout << maxi + 1 <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int a[1010], d[1010];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       d[a[i]]++;     }     int mx = 0, mxi = 0;     for (int i = 1; i <= n; i++) {       if (d[a[i]] > mx) mx = d[a[i]];       if (d[a[i]] != 0) {         mxi++;         d[a[i]] = 0;       }     }     cout << mx <<     << mxi;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long answer = 0;     for (int i = s.length() - 1; i > 0; i--) {       string temp = s.substr(i - 1, 2);       if (stoi(temp) % 4 == 0) {         answer += i;       }     }     for (int i = 0; i < s.length(); i++) {       if (stoi(s.substr(i, 1)) % 4 == 0) {         answer++;       }     }     cout << answer;   }
#include <bits/stdc++.h>   using namespace std;   int c[1005];   int a[12] = {0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292};   int main() {     long long n;     while (cin >> n) {       if (n <= 11) {         cout << a[n] << endl;       } else {         long long m;         m = a[11] + (n - 11) * 49;         cout << m << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int ret = 0, flag = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) flag = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) ret = ret * 10 + (c ^  0 ), c = getchar();     return flag * ret;   }   struct use {     int x, dis;   };   const int N = 5e3 + 5;   int T, n, d;   vector<int> edge[N];   int dad[N];   int build(int x, int dis) {     int sum = 0;     if ((x << 1) <= n) {       edge[x].push_back(x << 1);       sum += dis + 1;       sum += build(x << 1, dis + 1);     }     if ((x << 1 | 1) <= n) {       edge[x].push_back(x << 1 | 1);       sum += dis + 1;       sum += build(x << 1 | 1, dis + 1);     }     return sum;   }   void bfs() {     queue<use> q;     q.push({1, 0});     int now = 0;     vector<int> p1, p2;     while (q.empty() == 0) {       int x = q.front().x, dis = q.front().dis;       q.pop();       if (now != dis) {         now = dis, p1.clear(), p2.clear();       }       for (auto it = edge[x].begin(); it != edge[x].end(); it++) {         int y = *it;         if (edge[y].size() == 0) {           p1.push_back(y);           if (p2.size()) {             edge[p2[0]].push_back(y);             edge[x].erase(it);             return;           }         }         if (edge[y].size() != 2) p2.push_back(y);         q.push({y, dis + 1});       }     }   }   int main() {     T = read();     while (T--) {       n = read(), d = read();       for (int i = 1; i <= n; i++) edge[i].clear();       int mn = build(1, 0);       int mx = (n - 1) * n / 2;       if (!(mn <= d && d <= mx)) {         printf( NO n );         continue;       }       int now = mn;       while (now < d) {         bfs();         now++;       }       for (int i = 1; i <= n; i++) {         for (int j = 0; j < edge[i].size(); j++) dad[edge[i][j]] = i;       }       printf( YES n );       for (int i = 2; i <= n; i++) printf( %d  , dad[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double ans, m;   int n;   double binpow(double a, int b) {     if (b == 0)       return 1;     else if (b == 1)       return a;     else if (b % 2 == 0) {       double t = binpow(a, b / 2);       return t * t;     } else       return a * binpow(a, b - 1);   }   int main() {     cin >> m >> n;     for (double i = 1; i <= m; i++) {       ans += i * binpow(i / m, n) * (1 - binpow((i - 1) / i, n));     }     cout << fixed << setprecision(15) << ans;   }
#include <bits/stdc++.h>   int main() {     int i;     for (i = 0; i < 10; i++) {       printf( ??%d>>%d?? n , i, i);     }     printf( ??>>? n );     for (i = 0; i < 9; i++) {       printf( %d?<>%d n , i, i + 1);     }     printf( 9?>>?0 n?<>1 n>>?? n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     long long t = n;     vector<pair<int, int> > laptop;     for (int i = 0; i < n; i++) {       long long temp1, temp2;       cin >> temp1 >> temp2;       laptop.push_back(make_pair(temp1, temp2));     }     sort(laptop.begin(), laptop.end());     int cur = laptop[0].second;     for (int i = 1; i < n; ++i) {       if (cur > laptop[i].second) {         cout <<  Happy Alex n ;         return 0;       }       cur = laptop[i].second;     }     cout <<  Poor Alex n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 7, M = 1e9 + 7;   vector<int> primes;   bool isp[N];   void sieve() {     fill(isp, isp + N, 1);     isp[0] = isp[1] = 0;     for (int i = 2; i * i < N; i++)       if (isp[i])         for (int j = i * i; j < N; j += i) isp[j] = 0;     for (int i = 2; i < N; i++)       if (isp[i]) primes.push_back(i);   }   vector<pair<int, int> > factorize(int x) {     vector<pair<int, int> > ans;     for (int i = 2; i * i <= x; i++) {       int cnt = 0;       while (x % i == 0) cnt++, x /= i;       if (cnt) ans.push_back(make_pair(i, cnt));     }     if (x > 1) ans.push_back(make_pair(x, 1));     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     long long ans = 1;     map<int, int> fac;     map<int, int> cnt;     vector<vector<pair<int, int> > > factors;     int pp[n];     for (int i = 0; i < n; i++) cin >> pp[i];     sort(pp, pp + n);     reverse(pp, pp + n);     for (int i = 1; i <= n; i++) {       int p = pp[i - 1];       if (fac.count(p) == 0) {         ans = (ans * p) % M;         fac[p] = 1;         cnt[p] = 1;         vector<pair<int, int> > v;         v.push_back(make_pair(p, 1));         factors.push_back(v);       } else {         vector<pair<int, int> > pf = factorize(p - 1);         factors.push_back(pf);         for (auto pr : pf) {           int p = pr.first;           int e = pr.second;           int dif = e - fac[p];           if (dif < 0) continue;           if (dif == 0) {             cnt[p]++;             continue;           }           fac[p] += dif;           cnt[p] = 1;           for (int i = 0; i < dif; i++) ans = (ans * p) % M;         }       }     }     for (auto pf : factors) {       bool found = true;       for (auto pr : pf) {         int p = pr.first;         int e = pr.second;         int mx = fac[p];         assert(e <= mx);         if (e == mx && cnt[p] == 1) {           found = false;           break;         }       }       if (found) {         ans++;         break;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long n, k, b1, b2, b[200007], ans, dl, dll[200007], an[200007];   map<unsigned long long, unsigned long long> a[11];   int main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     cin >> n >> k;     for (unsigned long long i = 1; i <= n; i++) {       cin >> b[i];       b1 = b[i];       dl = 0;       while (b1 > 0) {         dl++;         b1 = b1 / 10;       }       dll[i] = dl;       b1 = b[i];       a[dl][b[i] % k]++;     }     for (unsigned long long i = 1; i <= n; i++) {       b1 = 1;       for (unsigned long long j = 1; j <= 10; j++) {         b1 *= 10;         b2 = b[i] * b1;         b2 %= k;         b2 = k - b2;         if (b2 == k) b2 = 0;         if (a[j].find(b2) != a[j].end()) {           ans += a[j][b2];           if (dll[i] == j && b2 == b[i] % k) ans--;         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = int(1e6) + 100;   const long long inf = 1e6;   int n, m;   int a[maxn], cnt[maxn], b[maxn];   void read() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) b[i] = a[i];   }   long long POW(long long num, int times) {     long long ans = 1;     while (times) {       if (times & 1) ans = ans * num;       num = num * num;       if (ans >= inf) return inf;       if (num >= inf) num = inf;       times >>= 1;     }     return ans;   }   void solve() {     long long ans = 0;     for (int i = 1; i <= n; ++i) {       int num = a[i];       a[i] = 1;       long long inv = 1;       for (int j = 2; j * j <= num && num != 1; ++j)         if (num % j == 0) {           int k = 0;           int x = a[i];           while (num % j == 0) {             k++;             if (k == m) k = 0;             if (k == 0)               a[i] = x;             else               a[i] *= j;             num /= j;           }           int tmp = POW(j, (m - k) % m);           if (tmp == inf)             inv = inf;           else             inv *= tmp;           if (inv >= inf) inv = inf;         }       if (num != 1) a[i] *= num, inv *= POW(num, m - 1);       if (inv < inf) ans += cnt[inv];       ++cnt[a[i]];     }     printf( %lld n , ans);   }   int main() {     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 300000;   int n, arr[MX], bit[MX], ans = 0, lis;   void update(int x, int V) {     while (x <= n) {       bit[x] = max(bit[x], V);       x += x & -x;     }   }   int get(int x) {     int ret = 0;     while (x > 0) {       ret = max(ret, bit[x]);       x -= x & -x;     }     return ret;   }   int main() {     scanf( %d , &n);     memset(bit, 0, sizeof(bit));     for (int j = 1; j <= n; j++) {       scanf( %d , &arr[j]);       lis = get(arr[j]) + 1;       update(arr[j] + 1, lis);       ans = max(ans, lis);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<long long, std::vector<long long>, std::greater<long long> > pqs;   queue<long long> q;   stack<long long> sta;   set<long long> st;   set<long long>::iterator P;   long long i, j, n, m, t, k, a, b, c, x, mx, mn;   string s, s1;   char z;   vector<pair<long long, long long> > v;   map<pair<long long, long long>, long long> mp, pm;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int T = 1;     cin >> T;     while (T--) {       i = j = n = m = t = k = a = b = c = x = mx = mn = 0;       cin >> n >> m;       m += 2 * n;       for (i = 1; i <= n && m; i++)         for (j = i + 1; j <= n && m; j++) cout << i <<     << j << endl, m--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     Node *arr[26];     int state;     bool isEnd = false;     Node() {       for (int i = 0; i < 26; i++) arr[i] = nullptr;       isEnd = true;     }   };   void insert(const string &s, Node *root) {     Node *curr = root;     for (char c : s) {       if (curr->arr[c -  a ] == nullptr) curr->arr[c -  a ] = new Node();       curr = curr->arr[c -  a ];     }     curr->isEnd = true;   }   int find_state(Node *curr, bool leaf = true) {     bool winning = false;     int cnt = 0;     for (int i = 0; i < 26; i++) {       if (curr->arr[i] != nullptr) {         cnt++;         if (find_state(curr->arr[i], leaf) == 0) winning = true;       }     }     if (cnt == 0) winning = leaf;     return curr->state = winning ? 1 : 0;   }   int main() {     int n, k;     cin >> n >> k;     Node *root = new Node();     for (int i = 0; i < n; i++) {       string s;       cin >> s;       insert(s, root);     }     int st1 = find_state(root, false);     if (k == 1) {       cout << (st1 == 1 ?  First  :  Second ) << endl;     } else {       int st2 = find_state(root, true);       if (st2 == 1 && st1 == 1) {         cout <<  First  << endl;       } else if (st2 == 1 && st1 == 0) {         cout <<  Second  << endl;       } else if (st2 == 0 && st1 == 1) {         cout << (k % 2 == 0 ?  Second  :  First ) << endl;       } else {         cout <<  Second  << endl <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n;     while (cin >> n) {       int ans = 0;       for (int i = 1; i < n; i++) {         int x, y;         cin >> x >> y;         ans += a[x] + a[y];         a[x]++, a[y]++;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = pow(10, 9) + 7;   const long long MAX = LONG_LONG_MAX;   void solve() {     int n;     cin >> n;     vector<string> a(n,   );     for (int i = 0; i < n; i += 1) cin >> a[i];     for (int i = 0; i < n; i += 1) {       for (int j = 0; j < n; j += 1) {         if (a[i][j] ==  1 ) {           if (i == n - 1 || j == n - 1) {             continue;           }           if (a[i + 1][j] ==  1  || a[i][j + 1] ==  1 ) {             continue;           } else {             cout <<  NO ;             return;           }         }       }     }     cout <<  YES ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t > 0) {       solve();       t--;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int8_t sign(int a, int b, int &c, int x, int y) {     return a * 1LL * x + b * 1LL * y + c < 0LL ? -1 : 1;   }   void solve() {     int x, y, x1, y1;     cin >> x >> y >> x1 >> y1;     int16_t ans = 0;     int16_t n;     cin >> n;     for (int i = 0, u, v, c; i < n; i++) {       cin >> u >> v >> c;       ans += sign(u, v, c, x, y) != sign(u, v, c, x1, y1);     }     cout << ans;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tkd = 1;     while (tkd-- > 0) {       solve();     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64777216 )   using namespace std;   template <class T>   inline T sqr(T x) {     return x * x;   }   const double pi = acos(-1.0), eps = 1e-9;   const int INF = 1000 * 1000 * 1000, MAXN = 1000005, MOD = 1000000007;   const long long INFL = 1000000000000000000;   long long n, m, cnt[MAXN][26];   string x, y;   void prepare(string s) {     if ((int)s.size() != 0) {       freopen((s +  .in ).c_str(),  r , stdin);       freopen((s +  .out ).c_str(),  w , stdout);     }   }   long long gcd(long long a, long long b) { return (b) ? gcd(b, a % b) : a; }   long long lca(long long a, long long b) { return a / gcd(a, b) * b; }   void get_data() { cin >> n >> m >> x >> y; }   void solve() {     long long L = lca((int)x.size(), (int)y.size());     long long g = gcd((int)x.size(), (int)y.size());     long long ans = L;     for (int i = 0; i < (int)y.size(); ++i) cnt[i % g][y[i] -  a ]++;     for (int j = 0; j < (int)x.size(); ++j) ans -= cnt[j % g][x[j] -  a ];     cout << ans * (n * (int)x.size() / L);   }   int main() {     prepare(  );     get_data();     solve();     return 0;   }