#include <bits/stdc++.h>
using namespace std;
int qqqqq;
int kto(char a, char b) {
  if (a == 'R' && b == 'S') return 1;
  if (a == 'R' && b == 'P') return -1;
  if (a == 'S' && b == 'P') return 1;
  if (a == 'S' && b == 'R') return -1;
  if (a == 'P' && b == 'S') return -1;
  if (a == 'P' && b == 'R') return 1;
  return 0;
}
char s1[1100], s2[1100];
int n;
int nod(int a, int b) {
  if (a % b == 0)
    return b;
  else
    return nod(b, a % b);
}
int main() {
  cin >> n >> s1 >> s2;
  int l1 = strlen(s1), l2 = strlen(s2);
  int len = l1 * l2 / nod(l1, l2);
  int r1 = 0, r2 = 0;
  for (int i = 0; i < len; i++) {
    if (kto(s1[i % l1], s2[i % l2]) == 1) r2++;
    if (kto(s1[i % l1], s2[i % l2]) == -1) r1++;
  }
  int ans1, ans2;
  ans1 = n / len * r1;
  ans2 = n / len * r2;
  for (int i = 0; i < n % len; i++) {
    if (kto(s1[i % l1], s2[i % l2]) == 1) ans2++;
    if (kto(s1[i % l1], s2[i % l2]) == -1) ans1++;
  }
  cout << ans1 << " " << ans2 << endl;
}
