#include <bits/stdc++.h>
char a[1003], b[1003];
int gcd(int a, int b) {
  while (a && b) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}
inline int cmp(char a, char b) {
  if (a == 'R') {
    if (b == 'S')
      return 1;
    else if (b == 'P')
      return -1;
    else
      return 0;
  } else if (a == 'S') {
    if (b == 'R')
      return -1;
    else if (b == 'P')
      return 1;
    else
      return 0;
  } else {
    if (b == 'S')
      return -1;
    else if (b == 'R')
      return 1;
    else
      return 0;
  }
}
int main(int argc, char *argv[]) {
  int d, ap, bp, n;
  scanf("%d%s%s", &n, a, b);
  int i, j, k, al, bl, t;
  al = strlen(a);
  bl = strlen(b);
  d = al * bl / gcd(al, bl);
  ap = 0, bp = 0;
  for (k = 0, i = 0, j = 0; k < d; ++k, i = (i + 1) % al, j = (j + 1) % bl) {
    t = cmp(a[i], b[j]);
    if (t < 0)
      ++ap;
    else if (t > 0)
      ++bp;
  }
  int ar = n / d * ap, br = n / d * bp;
  int td = n % d;
  ap = 0, bp = 0;
  for (k = 0, i = 0, j = 0; k < td; ++k, i = (i + 1) % al, j = (j + 1) % bl) {
    t = cmp(a[i], b[j]);
    if (t < 0)
      ++ap;
    else if (t > 0)
      ++bp;
  }
  printf("%d %d\n", ar + ap, br + bp);
  return 0;
}
