#include <bits/stdc++.h>
using namespace std;
int n;
int sum1 = 0;
int sum2 = 0;
char str1[2000];
char str2[2000];
int judge(char a, char b) {
  if ((a == 'R' && b == 'S') || (a == 'P' && b == 'R') ||
      (a == 'S' && b == 'P'))
    return 1;
  else if (a == b)
    return -1;
  else
    return 0;
}
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
int main() {
  scanf("%d", &n);
  scanf("%s", str1);
  scanf("%s", str2);
  int len1 = strlen(str1);
  int len2 = strlen(str2);
  int ind1 = 0;
  int ind2 = 0;
  int k = (len1 * len2) / gcd(len1, len2);
  int tmp = n % k;
  int fuck = n / k;
  while (k--) {
    ind1 %= len1;
    ind2 %= len2;
    if (judge(str1[ind1], str2[ind2]) == 1)
      sum1++;
    else if (judge(str1[ind1], str2[ind2]) == 0)
      sum2++;
    ind1++;
    ind2++;
  }
  sum1 = fuck * sum1;
  sum2 = fuck * sum2;
  ind1 = 0;
  ind2 = 0;
  while (tmp--) {
    ind1 %= len1;
    ind2 %= len2;
    if (judge(str1[ind1], str2[ind2]) == 1)
      sum1++;
    else if (judge(str1[ind1], str2[ind2]) == 0)
      sum2++;
    ind1++;
    ind2++;
  }
  printf("%d %d\n", sum2, sum1);
  return 0;
}
