#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int lcm(int x, int y) { return x * y / gcd(x, y); }
int main() {
  int n, cnta = 0, cntb = 0;
  string a, b;
  cin >> n;
  cin >> a >> b;
  int lena = a.size(), lenb = b.size();
  int len = lcm(lena, lenb);
  for (int i = 0; i <= len - 1; i++) {
    int ia = i % lena, ib = i % lenb;
    if (a[ia] == b[ib])
      continue;
    else if (a[ia] == 'R' && b[ib] == 'S' || a[ia] == 'S' && b[ib] == 'P' ||
             a[ia] == 'P' && b[ib] == 'R')
      cntb++;
    else
      cnta++;
  }
  cnta = cnta * (n / len);
  cntb = cntb * (n / len);
  for (int i = 0; i < n % len; i++) {
    int ia = i % lena, ib = i % lenb;
    if (a[ia] == b[ib])
      continue;
    else if (a[ia] == 'R' && b[ib] == 'S' || a[ia] == 'S' && b[ib] == 'P' ||
             a[ia] == 'P' && b[ib] == 'R')
      cntb++;
    else
      cnta++;
  }
  cout << cnta << " " << cntb << endl;
  return 0;
}
