#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
char a[N], b[N];
int la, lb;
int main() {
  int t, A_win, B_win, tA_win, tB_win;
  while (cin >> t >> a >> b) {
    la = strlen(a);
    lb = strlen(b);
    A_win = B_win = tA_win = tB_win = 0;
    int ok = 1;
    for (int i = 0; i < t && i < la * lb; i++) {
      if (i == t % (la * lb)) ok = 0;
      if ((a[i % la] == 'R' && b[i % lb] == 'S') ||
          (a[i % la] == 'S' && b[i % lb] == 'P') ||
          (a[i % la] == 'P' && b[i % lb] == 'R')) {
        A_win++;
        if (ok) tA_win++;
      } else if ((a[i % la] == 'S' && b[i % lb] == 'R') ||
                 (a[i % la] == 'P' && b[i % lb] == 'S') ||
                 (a[i % la] == 'R' && b[i % lb] == 'P')) {
        B_win++;
        if (ok) tB_win++;
      }
    }
    int ans_A = A_win * (t / (la * lb)) + tA_win;
    int ans_B = B_win * (t / (la * lb)) + tB_win;
    printf("%d %d\n", ans_B, ans_A);
  }
  return 0;
}
