#include <bits/stdc++.h>
using namespace std;
int n, cnt[1000005][2];
int ls, lt;
char s[1005], t[1005];
int res[3][3] = {{0, -1, 1}, {1, 0, -1}, {-1, 1, 0}};
int main() {
  scanf("%d\n%s\n%s", &n, s, t);
  ls = strlen(s);
  lt = strlen(t);
  memset(cnt, 0, sizeof(cnt));
  for (int i = (0); i <= (ls * lt - 1); i++) {
    if (i) cnt[i][0] = cnt[i - 1][0], cnt[i][1] = cnt[i - 1][1];
    int n1, n2;
    if (s[i % ls] == 'R')
      n1 = 0;
    else if (s[i % ls] == 'P')
      n1 = 1;
    else if (s[i % ls] == 'S')
      n1 = 2;
    if (t[i % lt] == 'R')
      n2 = 0;
    else if (t[i % lt] == 'P')
      n2 = 1;
    else if (t[i % lt] == 'S')
      n2 = 2;
    if (res[n1][n2] == -1) cnt[i][0]++;
    if (res[n1][n2] == 1) cnt[i][1]++;
  }
  for (int i = (ls * lt); i >= (1); i--)
    cnt[i][0] = cnt[i - 1][0], cnt[i][1] = cnt[i - 1][1];
  cnt[0][0] = cnt[0][1] = 0;
  printf("%d %d\n", n / (ls * lt) * cnt[ls * lt][0] + cnt[n % (ls * lt)][0],
         n / (ls * lt) * cnt[ls * lt][1] + cnt[n % (ls * lt)][1]);
  return 0;
}
