#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return a % b ? gcd(b, a % b) : b; }
int main() {
  int n, a[1024], b[1024], ansa, ansb, sa = 0, sb = 0;
  string A, B;
  cin >> n >> A >> B;
  int la = A.size(), lb = B.size(), x = la * lb / gcd(la, lb);
  for (int i = 0; i < la; i++) a[i] = (A[i] == 'R' ? 0 : (A[i] == 'S' ? 1 : 2));
  for (int i = 0; i < lb; i++) b[i] = (B[i] == 'R' ? 0 : (B[i] == 'S' ? 1 : 2));
  for (int i = 0; i < x; i++) {
    if (i == n % x) {
      ansa = sa;
      ansb = sb;
    }
    if ((a[i % la] + 1) % 3 == b[i % lb]) sb++;
    if ((b[i % lb] + 1) % 3 == a[i % la]) sa++;
  }
  cout << (sa * (n / x) + ansa) << ' ' << (sb * (n / x) + ansb) << endl;
  return 0;
}
