#include <bits/stdc++.h>
using namespace std;
bool DBG;
struct dbg {
  template <typename T>
  dbg& operator,(const T& v) {
    if (DBG) cerr << v << " ";
    return *this;
  }
  ~dbg() {
    if (DBG) cerr << endl;
  }
};
unsigned int gcd(unsigned int a, unsigned int b) {
  unsigned int c;
  while (b) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
unsigned int lcm(unsigned int a, unsigned int b) {
  return ((a / gcd(a, b)) * b);
}
map<char, map<char, int> > RPS;
int main(int argc, char* argv[]) {
  if (argc > 1) DBG = ((*argv[1] == '0') ? 0 : 1);
  RPS['P']['R'] = 1;
  RPS['R']['P'] = -1;
  RPS['R']['S'] = 1;
  RPS['S']['R'] = -1;
  RPS['S']['P'] = 1;
  RPS['P']['S'] = -1;
  RPS['P']['P'] = 0;
  RPS['R']['R'] = 0;
  RPS['S']['S'] = 0;
  unsigned int n;
  scanf("%u", &n);
  string N, P;
  cin >> N >> P;
  unsigned int m = N.length(), k = P.length(), p = lcm(m, k), spotsN = 0,
               spotsP = 0, c = ((n < p) ? n : p);
  unsigned int sp = 0, sn = 0;
  for (int i = 0; i < c; i++) {
    if (RPS[N[i % m]][P[i % k]] == 1)
      sp++;
    else if (RPS[N[i % m]][P[i % k]] == -1)
      sn++;
  }
  spotsP = (n / p) * sp;
  spotsN = (n / p) * sn;
  for (int i = 0; i < n % p; i++) {
    if (RPS[N[i % m]][P[i % k]] == 1)
      spotsP++;
    else if (RPS[N[i % m]][P[i % k]] == -1)
      spotsN++;
  }
  printf("%u %u\n", spotsN, spotsP);
  return 0;
}
