#include <bits/stdc++.h>
using namespace std;
long long n, a, b, t1, t2, cnt1, cnt2, r2, r1;
char s1[1005], s2[1005];
int p1 = 0, p2 = 0, r = 0;
long long mcd(long long a, long long b) {
  if (b == 0) return a;
  return mcd(b, a % b);
}
void f(int tmp) {
  for (int i = 0; i < tmp; i++) {
    if ((s1[p1] == 'R' && s2[p2] == 'S') || (s1[p1] == 'S' && s2[p2] == 'P') ||
        (s1[p1] == 'P' && s2[p2] == 'R'))
      cnt1++;
    else if (s1[p1] != s2[p2])
      cnt2++;
    p1 = (p1 + 1) % t1;
    p2 = (p2 + 1) % t2;
  }
}
int main() {
  scanf("%I64d", &n);
  scanf("%s%s", s1, s2);
  p1 = 0, p2 = 0, t1 = strlen(s1), t2 = strlen(s2);
  long long tmp = t1 / (mcd(t1, t2)) * t2;
  if (n < tmp) {
    cnt1 = 0;
    cnt2 = 0;
    f(n);
    printf("%I64d %I64d\n", cnt2, cnt1);
  } else {
    r1 = n / tmp;
    cnt1 = 0;
    cnt2 = 0;
    f(tmp);
    r2 = r1 * cnt2;
    r1 = r1 * cnt1;
    cnt1 = 0;
    cnt2 = 0;
    f(n % tmp);
    r1 += cnt1;
    r2 += cnt2;
    printf("%I64d %I64d\n", r2, r1);
  }
  return 0;
}
