#include <bits/stdc++.h>
using namespace std;
int yu(int a, int b) {
  if (b == 0) return a;
  return yu(b, a % b);
}
int judge(char a, char b) {
  if (a == b) return 0;
  if (a == 'R') {
    if (b == 'S')
      return 1;
    else
      return -1;
  }
  if (a == 'S') {
    if (b == 'P')
      return 1;
    else
      return -1;
  }
  if (a == 'P') {
    if (b == 'R')
      return 1;
    else
      return -1;
  }
}
int main() {
  int n, i, j, lena, lenb, k, numa, numb, nn, ans;
  char cha[1001], chb[1001], flag;
  while (scanf("%d", &n) != EOF) {
    scanf("%s%s", cha, chb);
    lena = strlen(cha);
    lenb = strlen(chb);
    numa = numb = 0;
    nn = lena * lenb / yu(lena, lenb);
    ans = n / nn;
    for (i = 0; i < nn; i++) {
      flag = judge(cha[i % lena], chb[i % lenb]);
      if (flag == 0) continue;
      if (flag == 1)
        numa++;
      else
        numb++;
    }
    numa *= ans;
    numb *= ans;
    for (i = 0; i < n - ans * nn; i++) {
      flag = judge(cha[i % lena], chb[i % lenb]);
      if (flag == 0) continue;
      if (flag == 1)
        numa++;
      else
        numb++;
    }
    printf("%d %d\n", numb, numa);
  }
  return 0;
}
