#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int INF = 1000000000;
const long long LINF = 4000000000000000000ll;
void prepare() {}
int n;
char a[1005];
char b[1005];
int m, k;
inline int win(char x, char y) {
  if (x == y) return 0;
  if (x == 'R' && y == 'P') return -1;
  if (x == 'P' && y == 'R') return 1;
  if (x == 'P' && y == 'S') return -1;
  if (x == 'S' && y == 'P') return 1;
  if (x == 'S' && y == 'R') return -1;
  if (x == 'R' && y == 'S') return 1;
}
bool solve() {
  scanf("%d%s%s", &n, a, b);
  m = strlen(a);
  k = strlen(b);
  int ac = 0, bc = 0;
  int apos = 0, bpos = 0;
  int period = m * k;
  for (int i = 0; i < period; i++) {
    int w = win(a[apos], b[bpos]);
    if (w == 1)
      bc++;
    else if (w == -1)
      ac++;
    apos++;
    if (apos == m) apos = 0;
    bpos++;
    if (bpos == k) bpos = 0;
  }
  ac *= n / period;
  bc *= n / period;
  apos = bpos = 0;
  int left = n % period;
  for (int i = 0; i < left; i++) {
    int w = win(a[apos], b[bpos]);
    if (w == 1)
      bc++;
    else if (w == -1)
      ac++;
    apos++;
    if (apos == m) apos = 0;
    bpos++;
    if (bpos == k) bpos = 0;
  }
  printf("%d %d\n", ac, bc);
  return false;
}
int main() {
  prepare();
  while (solve())
    ;
  return 0;
}
