#include <bits/stdc++.h>
using namespace std;
int mcd(int a, int b) {
  int c;
  while (a != b) {
    if (a > b)
      a = a - b;
    else
      b = b - a;
  }
  c = a;
  return c;
}
void comp(char A, char B, long long cont1, long long cont2) {
  if (A == 'P' && B == 'S')
    cont1++;
  else if (A == 'S' && B == 'P')
    cont2++;
  else if (A == 'R' && B == 'P')
    cont1++;
  else if (A == 'P' && B == 'R')
    cont2++;
  else if (A == 'S' && B == 'R')
    cont1++;
  else if (A == 'R' && B == 'S')
    cont2++;
}
int main() {
  long long n;
  cin >> n;
  string A, B;
  cin >> A >> B;
  string aux = A, aux2 = B;
  int num = (A.size() * B.size()) / mcd(A.size(), B.size());
  for (int i = 1; i < num / aux.size(); i++) A += aux;
  A += aux.substr(0, num % aux.size());
  for (int i = 1; i < num / aux2.size(); i++) B += aux2;
  B += aux2.substr(0, num % aux2.size());
  long long cont1 = 0, cont2 = 0;
  if (n <= num) {
    for (int i = 0; i < n; i++) {
      if (A[i] == 'P' && B[i] == 'S')
        cont1++;
      else if (A[i] == 'S' && B[i] == 'P')
        cont2++;
      else if (A[i] == 'R' && B[i] == 'P')
        cont1++;
      else if (A[i] == 'P' && B[i] == 'R')
        cont2++;
      else if (A[i] == 'S' && B[i] == 'R')
        cont1++;
      else if (A[i] == 'R' && B[i] == 'S')
        cont2++;
    }
  } else {
    for (int i = 0; i < num; i++) {
      if (A[i] == 'P' && B[i] == 'S')
        cont1++;
      else if (A[i] == 'S' && B[i] == 'P')
        cont2++;
      else if (A[i] == 'R' && B[i] == 'P')
        cont1++;
      else if (A[i] == 'P' && B[i] == 'R')
        cont2++;
      else if (A[i] == 'S' && B[i] == 'R')
        cont1++;
      else if (A[i] == 'R' && B[i] == 'S')
        cont2++;
    }
    cont1 = cont1 * (n / num);
    cont2 = cont2 * (n / num);
    for (int i = 0; i < n % num; i++) {
      if (A[i] == 'P' && B[i] == 'S')
        cont1++;
      else if (A[i] == 'S' && B[i] == 'P')
        cont2++;
      else if (A[i] == 'R' && B[i] == 'P')
        cont1++;
      else if (A[i] == 'P' && B[i] == 'R')
        cont2++;
      else if (A[i] == 'S' && B[i] == 'R')
        cont1++;
      else if (A[i] == 'R' && B[i] == 'S')
        cont2++;
    }
  }
  cout << cont1 << " " << cont2 << endl;
  return 0;
}
