#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::max;
using std::min;
using std::pair;
using std::set;
using std::string;
using std::swap;
using std::vector;
int main() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  int la, lb;
  la = a.length();
  lb = b.length();
  long long ansa = 0, ansb = 0;
  for (int i = 0; i < la * lb; i++) {
    if ((a[i % la] == 'R') && (b[i % lb] == 'P')) {
      ansa++;
      continue;
    }
    if ((a[i % la] == 'R') && (b[i % lb] == 'S')) {
      ansb++;
      continue;
    }
    if ((a[i % la] == 'P') && (b[i % lb] == 'R')) {
      ansb++;
      continue;
    }
    if ((a[i % la] == 'P') && (b[i % lb] == 'S')) {
      ansa++;
      continue;
    }
    if ((a[i % la] == 'S') && (b[i % lb] == 'P')) {
      ansb++;
      continue;
    }
    if ((a[i % la] == 'S') && (b[i % lb] == 'R')) {
      ansa++;
      continue;
    }
  }
  int tmp;
  tmp = n / (la * lb);
  ansa *= tmp;
  ansb *= tmp;
  n %= (la * lb);
  for (int i = 0; i < n; i++) {
    if ((a[i % la] == 'R') && (b[i % lb] == 'P')) {
      ansa++;
      continue;
    }
    if ((a[i % la] == 'R') && (b[i % lb] == 'S')) {
      ansb++;
      continue;
    }
    if ((a[i % la] == 'P') && (b[i % lb] == 'R')) {
      ansb++;
      continue;
    }
    if ((a[i % la] == 'P') && (b[i % lb] == 'S')) {
      ansa++;
      continue;
    }
    if ((a[i % la] == 'S') && (b[i % lb] == 'P')) {
      ansb++;
      continue;
    }
    if ((a[i % la] == 'S') && (b[i % lb] == 'R')) {
      ansa++;
      continue;
    }
  }
  cout << ansa << " " << ansb;
  return 0;
}
