#include <bits/stdc++.h>
using namespace std;
int who(char a, char b) {
  if (a == b) return 0;
  if (a == 'R' && b == 'S') return 1;
  if (a == 'S' && b == 'P') return 1;
  if (a == 'P' && b == 'R') return 1;
  return -1;
}
bool solve() {
  int n;
  if (scanf("%d", &n) == EOF) return false;
  char a[1100], b[1100];
  scanf("%s%s", a, b);
  int m = strlen(a), k = strlen(b);
  int n1 = 0, n2 = 0;
  for (int i = 0; i < m * k; ++i) {
    switch (who(a[i % m], b[i % k])) {
      case 1:
        n1++;
        break;
      case -1:
        n2++;
        break;
    }
  }
  n1 *= n / (m * k);
  n2 *= n / (m * k);
  for (int i = 0; i < n % (m * k); ++i) {
    switch (who(a[i % m], b[i % k])) {
      case 1:
        n1++;
        break;
      case -1:
        n2++;
        break;
    }
  }
  printf("%d %d\n", n2, n1);
  return true;
}
int main() {
  solve();
  return 0;
}
