#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, cnt = 0;
  scanf("%d", &n);
  getchar();
  char s1[1005], s2[1005];
  gets(s1);
  gets(s2);
  int l1 = strlen(s1), l2 = strlen(s2);
  int res1 = 0, res2 = 0, resa = 0, resb = 0, c1 = 0, c2 = 0;
  if (n >= l1 * l2) {
    cnt = n / (l1 * l2);
    n = n % (l1 * l2);
  }
  for (c1 = c2 = i = 0; i < n; i++, c1++, c2++) {
    if (c1 == l1) c1 = 0;
    if (c2 == l2) c2 = 0;
    if (s1[c1] == s2[c2]) continue;
    if (s1[c1] == 'R' && s2[c2] == 'S')
      resb++;
    else if (s1[c1] == 'S' && s2[c2] == 'P')
      resb++;
    else if (s1[c1] == 'P' && s2[c2] == 'R')
      resb++;
    else
      resa++;
  }
  for (c1 = c2 = i = 0; i < l1 * l2; i++, c1++, c2++) {
    if (c1 == l1) c1 = 0;
    if (c2 == l2) c2 = 0;
    if (s1[c1] == s2[c2]) continue;
    if (s1[c1] == 'R' && s2[c2] == 'S')
      res2++;
    else if (s1[c1] == 'S' && s2[c2] == 'P')
      res2++;
    else if (s1[c1] == 'P' && s2[c2] == 'R')
      res2++;
    else
      res1++;
  }
  res1 = cnt * res1 + resa;
  res2 = cnt * res2 + resb;
  printf("%d %d\n", res1, res2);
}
