#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 10;
int k, p, n, m, g1, g2;
char s[N], t[N];
bool win(char c1, char c2) {
  return (c1 == 'R') && (c2 == 'S') || (c1 == 'S') && (c2 == 'P') ||
         (c1 == 'P') && (c2 == 'R');
}
int main() {
  scanf("%d%s%s", &k, s, t);
  n = strlen(s), m = strlen(t), p = n * m;
  for (int i = 0; i < p - n; ++i) s[i + n] = s[i];
  for (int i = 0; i < p - m; ++i) t[i + m] = t[i];
  g1 = 0, g2 = 0;
  for (int i = 0; i < p; ++i) {
    g1 += win(s[i], t[i]) * k / p;
    g2 += win(t[i], s[i]) * k / p;
    if (i < k % p) {
      g1 += win(s[i], t[i]);
      g2 += win(t[i], s[i]);
    }
  }
  printf("%d %d\n", g2, g1);
  return 0;
}
