#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int n;
string a, b;
void solve() {
  int an = a.size(), bn = b.size();
  int g = an * bn;
  int aw = 0, bw = 0;
  for (int i = 0, ai = 0, bi = 0; i < min(n, g);
       i++, ai = (ai + 1) % an, bi = (bi + 1) % bn) {
    if ((a[ai] == 'S' && b[bi] == 'P') || (a[ai] == 'P' && b[bi] == 'R') ||
        (a[ai] == 'R' && b[bi] == 'S')) {
      aw++;
    } else if (a[ai] != b[bi]) {
      bw++;
    }
  }
  int t = n / g;
  aw *= t;
  bw *= t;
  int rn = n % g;
  for (int i = 0, ai = 0, bi = 0; i < rn;
       i++, ai = (ai + 1) % an, bi = (bi + 1) % bn) {
    if ((a[ai] == 'S' && b[bi] == 'P') || (a[ai] == 'P' && b[bi] == 'R') ||
        (a[ai] == 'R' && b[bi] == 'S')) {
      aw++;
    } else if (a[ai] != b[bi]) {
      bw++;
    }
  }
  cout << bw << ' ' << aw << endl;
}
int main() {
  while (cin >> n >> a >> b) {
    solve();
  }
}
