#include <bits/stdc++.h>
using namespace std;
int n, an, bn, as, bs;
char a[1005], b[1005];
int id[200], c[3][3];
int main() {
  id['S'] = 0;
  id['P'] = 1;
  id['R'] = 2;
  c[0][1] = c[1][2] = c[2][0] = 1;
  scanf("%d", &n);
  scanf("%s", a);
  scanf("%s", b);
  an = strlen(a);
  bn = strlen(b);
  as = bs = 0;
  int m = an * bn;
  if (n >= m) {
    for (int i = 0; i < m; ++i) {
      int p = id[a[i % an]], q = id[b[i % bn]];
      as += c[p][q];
      bs += c[q][p];
    }
    as *= n / m;
    bs *= n / m;
    n %= m;
  }
  for (int i = 0; i < n; ++i) {
    int p = id[a[i % an]], q = id[b[i % bn]];
    as += c[p][q];
    bs += c[q][p];
  }
  printf("%d %d\n", bs, as);
  return 0;
}
