#include <bits/stdc++.h>
char s1[2000], s2[2000];
int L1[2000000], L2[2000000];
int main() {
  int n;
  scanf("%d%s%s", &n, s1, s2);
  int m = strlen(s1), k = strlen(s2);
  int p1 = 0, p2 = 0, P = 0;
  do {
    int c1 = 0, c2 = 0;
    if (s1[p1] != s2[p2]) {
      if ((s1[p1] == 'R' && s2[p2] == 'S') ||
          (s1[p1] == 'S' && s2[p2] == 'P') || (s1[p1] == 'P' && s2[p2] == 'R'))
        c1 = 1;
      else
        c2 = 1;
    }
    ++p1;
    if (p1 == m) p1 = 0;
    ++p2;
    if (p2 == k) p2 = 0;
    ++P;
    L1[P] = L1[P - 1] + c1;
    L2[P] = L2[P - 1] + c2;
  } while (p1 || p2);
  printf("%d %d\n", L2[P] * (n / P) + L2[n % P], L1[P] * (n / P) + L1[n % P]);
}
