#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long x, y;
int n, m;
const int MAXN = 3000100;
long long prop[MAXN], sum[MAXN], cnt[MAXN];
char a[MAXN], b[MAXN];
int main() {
  scanf("%I64d%I64d%s%s", &x, &y, a, b);
  n = strlen(a), m = strlen(b);
  if (n > m) {
    swap(n, m);
    swap(x, y);
    for (int i = 0; i < max(m, n); ++i) swap(a[i], b[i]);
  }
  long long g = gcd(n, m);
  long long ans = 0;
  for (int i = 0; i < 26; ++i) {
    memset(cnt, 0, sizeof cnt);
    memset(prop, 0, sizeof prop);
    memset(sum, 0, sizeof sum);
    for (int j = 0; j < n; ++j)
      cnt[j] = (a[j] == i + 'a') * (long long)x * n / ((long long)n * m / g);
    for (int j = 0; j < m; ++j) {
      sum[j] = cnt[j] + prop[j];
      prop[j + g] += sum[j];
    }
    for (int j = 0; j < m; ++j) {
      prop[j + m] -= cnt[j];
      sum[j + m] += prop[j + m];
      prop[j + g + m] += sum[j + m];
    }
    for (int j = 0; j < m; ++j)
      ans += (i + 'a' != b[j]) * (sum[j] + sum[j + m]);
  }
  printf("%I64d\n", ans);
  return 0;
}
