#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
const int N = 1000005;
const int M = 1005;
int res1[N], res2[N], n1, n2, n, d1, d2, nw, i;
char t1[M], t2[M];
string s1, s2;
char c1, c2;
int nwd(int a, int b) {
  if (b == 0) return a;
  return nwd(b, a % b);
}
int nww(int a, int b) { return a * b / nwd(a, b); }
bool better(char c1, char c2) {
  if (c1 == 'R') return (c2 == 'S');
  if (c1 == 'S') return (c2 == 'P');
  if (c1 == 'P') return (c2 == 'R');
}
int main() {
  scanf("%d %s %s", &n, t1, t2);
  s1 = t1;
  s2 = t2;
  n1 = s1.size();
  n2 = s2.size();
  nw = nww(n1, n2);
  d1 = d2 = 0;
  for (i = 0; i < nw; i++) {
    c1 = s1[i % n1];
    c2 = s2[i % n2];
    if (better(c1, c2))
      d2++;
    else if (better(c2, c1))
      d1++;
    res1[i + 1] = d1;
    res2[i + 1] = d2;
  }
  printf("%d %d\n", res1[nw] * (n / nw) + res1[n % nw],
         res2[nw] * (n / nw) + res2[n % nw]);
  return 0;
}
