#include <bits/stdc++.h>
char a[1010];
char b[1010];
int c[1000010];
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
  int n, i, j, k;
  scanf("%d", &n);
  scanf("%s%s", a, b);
  int la = strlen(a);
  int lb = strlen(b);
  int lc = la * lb / gcd(la, lb);
  for (i = 0; i < lc; i++) {
    if (a[i % la] == b[i % lb])
      c[i] = 0;
    else {
      if (a[i % la] == 'R') {
        if (b[i % lb] == 'S')
          c[i] = 1;
        else
          c[i] = -1;
      } else if (a[i % la] == 'S') {
        if (b[i % lb] == 'P')
          c[i] = 1;
        else
          c[i] = -1;
      } else {
        if (b[i % lb] == 'R')
          c[i] = 1;
        else
          c[i] = -1;
      }
    }
  }
  n--;
  int x = 0, y = 0;
  for (i = 0; i < lc; i++) {
    if (c[i] == 1)
      x++;
    else if (c[i] == -1)
      y++;
  }
  x *= n / lc;
  y *= n / lc;
  int m = n % lc;
  for (i = 0; i <= m; i++) {
    if (c[i] == 1)
      x++;
    else if (c[i] == -1)
      y++;
  }
  printf("%d %d\n", y, x);
  return 0;
}
