#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000020;
int cycn[MAXN];
int cycpos[MAXN];
int charcnt[MAXN + 1][26];
int partcnt(const vector<int> &cyc, int partlen, int c, int startpos) {
  if (startpos == 0 || partlen == 0) {
    return charcnt[cyc[partlen]][c];
  } else {
    int end = startpos + partlen;
    if (end < int(cyc.size())) {
      return charcnt[cyc[end]][c] - charcnt[cyc[startpos]][c];
    } else {
      return charcnt[cyc.back()][c] - charcnt[cyc[startpos]][c] +
             charcnt[cyc[end % (cyc.size() - 1)]][c];
    }
  }
}
int main() {
  long long cntx, cnty;
  cin >> cntx >> cnty;
  string x, y;
  cin >> x >> y;
  int n = x.size();
  int m = y.size();
  for (int i = 0; i < n; ++i) {
    cycn[i] = -1;
  }
  int ncyc = 0;
  vector<vector<int> > cycs;
  for (int start = 0; start < n; ++start) {
    if (cycn[start] != -1) continue;
    int at = start;
    cycs.push_back(vector<int>(1, n));
    vector<int> &cyc = cycs.back();
    int pos = 0;
    while (cycn[at] == -1) {
      cycn[at] = ncyc;
      cycpos[at] = pos++;
      for (int c = 0; c < 26; ++c) {
        charcnt[at][c] = charcnt[cyc.back()][c];
      }
      ++charcnt[at][x[at] - 'a'];
      cyc.push_back(at);
      at = (at + m) % n;
    }
    ++ncyc;
  }
  long long sol = 0;
  for (int i = 0; i < m; ++i) {
    int start = i % n;
    const vector<int> &cyc = cycs[cycn[start]];
    const int cyclen = cyc.size() - 1;
    const int c = y[i] - 'a';
    const long long eqtimes =
        cnty / cyclen * charcnt[cyc.back()][c] +
        partcnt(cyc, int(cnty % cyclen), c, cycpos[start]);
    sol += cnty - eqtimes;
  }
  cout << sol << '\n';
  return 0;
}
