#include <bits/stdc++.h>
using namespace std;
int rsp(char a, char b) {
  if (a == b) return 0;
  if (a == 'R') {
    if (b == 'S') return 1;
    return -1;
  }
  if (a == 'S') {
    if (b == 'P') return 1;
    return -1;
  }
  if (a == 'P') {
    if (b == 'R') return 1;
    return -1;
  }
}
int kmm(string s1, string s2) {
  int a = s1.size(), b = s2.size();
  for (int i = max(a, b); i > 0; i--) {
    if (a % i == 0 && b % i == 0) return a * b / i;
  }
}
int main() {
  long long int n;
  string a, b;
  cin >> n >> a >> b;
  long long int ac = 0, bc = 0, redA = 0, redB = 0, k = kmm(a, b);
  if (k > n) {
    for (int i = 0; i < n; i++) {
      if (rsp(a[ac], b[bc]) == 1)
        redB++;
      else if (rsp(a[ac], b[bc]) == -1)
        redA++;
      ac = (ac + 1) % a.size();
      bc = (bc + 1) % b.size();
    }
  } else {
    for (int i = 0; i < k; i++) {
      if (rsp(a[ac], b[bc]) == 1)
        redB++;
      else if (rsp(a[ac], b[bc]) == -1)
        redA++;
      ac = (ac + 1) % a.size();
      bc = (bc + 1) % b.size();
    }
    redA *= n / k, redB *= n / k;
    ac = 0, bc = 0;
    for (int i = 0; i < n % k; i++) {
      if (rsp(a[ac], b[bc]) == 1)
        redB++;
      else if (rsp(a[ac], b[bc]) == -1)
        redA++;
      ac = (ac + 1) % a.size();
      bc = (bc + 1) % b.size();
    }
  }
  cout << redA << " " << redB;
}
