#include <bits/stdc++.h>
using namespace std;
char st1[10000], st2[10000], ch1, ch2;
int n, len1, len2, lens, i, s1, s2, sum1, sum2, a1[2000000], a2[20000000];
int main() {
  scanf("%d", &n);
  scanf("%s", st1);
  scanf("%s", st2);
  lens = strlen(st1) * strlen(st2);
  len1 = strlen(st1);
  len2 = strlen(st2);
  for (i = 1; i <= lens; i++) {
    ch1 = st1[(i - 1) % len1];
    ch2 = st2[(i - 1) % len2];
    if (ch1 == 'R' && ch2 == 'S') {
      a2[i] = 1;
      sum2++;
    }
    if (ch1 == 'R' && ch2 == 'P') {
      a1[i] = 1;
      sum1++;
    }
    if (ch1 == 'P' && ch2 == 'S') {
      a1[i] = 1;
      sum1++;
    }
    if (ch1 == 'P' && ch2 == 'R') {
      a2[i] = 1;
      sum2++;
    }
    if (ch1 == 'S' && ch2 == 'P') {
      a2[i] = 1;
      sum2++;
    }
    if (ch1 == 'S' && ch2 == 'R') {
      a1[i] = 1;
      sum1++;
    }
  }
  for (i = 1; i <= n % lens; i++) {
    s1 += a1[i];
    s2 += a2[i];
  }
  printf("%d %d", n / lens * sum1 + s1, n / lens * sum2 + s2);
}
