#include <bits/stdc++.h>
int getcd(int a, int b) {
  if (a % b) return getcd(b, a % b);
  return b;
}
int get(char a, char b) {
  if (a ^ b) {
    switch (a) {
      case 'R':
        return b == 'S' ? 1 : -1;
      case 'S':
        return b == 'P' ? 1 : -1;
      case 'P':
        return b == 'R' ? 1 : -1;
    }
  }
  return 0;
}
int main() {
  int n;
  char sa[1001], sb[1001];
  int la, lb;
  int len;
  int i;
  int ra, rb, resa, resb;
  int res;
  while (scanf("%d", &n) != EOF) {
    res = ra = rb = resa = resb = 0;
    scanf("%s%s", sa, sb);
    la = strlen(sa);
    lb = strlen(sb);
    len = la / getcd(la, lb) * lb;
    res = n % len;
    for (i = 0; i < res; ++i) {
      switch (get(sa[i % la], sb[i % lb])) {
        case 1:
          ++resa;
          break;
        case -1:
          ++resb;
          break;
      }
    }
    ra = resa;
    rb = resb;
    for (i = res; i < len; ++i) {
      switch (get(sa[i % la], sb[i % lb])) {
        case 1:
          ++ra;
          break;
        case -1:
          ++rb;
          break;
      }
    }
    printf("%d %d\n", rb * (n / len) + resb, ra * (n / len) + resa);
  }
  return 0;
}
