#include <bits/stdc++.h>
char a[1024], b[1024];
int r[2], rt[2];
void gao(int i, int j) {
  if (a[i] != b[j]) {
    if (a[i] == 'R' && b[j] == 'S' || a[i] == 'S' && b[j] == 'P' ||
        a[i] == 'P' && b[j] == 'R') {
      ++r[1];
    } else {
      ++r[0];
    }
  }
}
int main(int argc, char const *argv[]) {
  int n;
  scanf("%d", &n);
  scanf("%s", a);
  scanf("%s", b);
  int n1 = strlen(a), n2 = strlen(b);
  int c1 = n1 * n2;
  int c2 = n % c1;
  for (int i = 0; i < c1; ++i) {
    if (i == c2) {
      rt[0] = r[0];
      rt[1] = r[1];
    }
    gao(i % n1, i % n2);
  }
  r[0] = r[0] * (n / c1) + rt[0];
  r[1] = r[1] * (n / c1) + rt[1];
  printf("%d %d\n", r[0], r[1]);
  return 0;
}
