#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char s1[1050];
  char s2[1050];
  scanf("%s%s", s1, s2);
  int l1 = strlen(s1);
  int l2 = strlen(s2);
  int nok = l1 * l2;
  int m = n % nok;
  int nik = 0;
  int pol = 0;
  int resnik = 0;
  int respol = 0;
  for (int i = 0; i < nok; i++) {
    int cnik = i % l1;
    int cpol = i % l2;
    if (s1[cnik] == 'R' && s2[cpol] == 'S') pol++;
    if (s1[cnik] == 'R' && s2[cpol] == 'P') nik++;
    if (s1[cnik] == 'S' && s2[cpol] == 'R') nik++;
    if (s1[cnik] == 'S' && s2[cpol] == 'P') pol++;
    if (s1[cnik] == 'P' && s2[cpol] == 'R') pol++;
    if (s1[cnik] == 'P' && s2[cpol] == 'S') nik++;
    if (i == m - 1) {
      resnik += nik;
      respol += pol;
    }
  }
  resnik += nik * (n / nok);
  respol += pol * (n / nok);
  cout << resnik << " " << respol << endl;
  return 0;
}
