#include <bits/stdc++.h>
using namespace std;
string str1, str2, tmp1, tmp2;
int ans[3][1000005];
int gcd(int x, int y) {
  if (!y) return x;
  return gcd(y, x % y);
}
int cal(char p, char q) {
  if (p == q) return 0;
  if ((p == 'R' && q == 'P') || (p == 'P' && q == 'S') ||
      (p == 'S' && q == 'R'))
    return 1;
  return 2;
}
int main() {
  int i, j, k, l1, l2, l, n;
  scanf("%d", &n);
  cin >> tmp1 >> tmp2;
  str1 = str2 = "";
  l1 = tmp1.length();
  l2 = tmp2.length();
  l = l1 * l2 / gcd(l1, l2);
  k = l / l1;
  for (i = 1; i <= k; i++) str1 += tmp1;
  k = l / l2;
  for (i = 1; i <= k; i++) str2 += tmp2;
  for (i = 1; i <= l; i++) {
    ans[cal(str1[i - 1], str2[i - 1])][i]++;
    ans[1][i] += ans[1][i - 1];
    ans[2][i] += ans[2][i - 1];
    if (i == n) break;
  }
  if (n <= l) {
    printf("%d %d\n", ans[1][n], ans[2][n]);
    return 0;
  }
  j = n / l;
  k = n % l;
  printf("%d %d\n", ans[1][l] * j + ans[1][k], ans[2][l] * j + ans[2][k]);
  return 0;
}
