#include <bits/stdc++.h>
using namespace std;
int n, n1, n2;
string s1;
string s2;
int result_1[1000001];
int result_2[1000001];
string TMP = "RSPR";
int whoLoss(char c1, char c2) {
  for (int i = 0; i < 3; i++) {
    if (c1 == TMP[i] && c2 == TMP[i + 1]) return 2;
    if (c2 == TMP[i] && c1 == TMP[i + 1]) return 1;
  }
  return 0;
}
int main() {
  ios ::sync_with_stdio(false);
  cin >> n;
  cin >> s1 >> s2;
  n1 = s1.length();
  n2 = s2.length();
  int cycle = n1 * n2;
  int cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < cycle; i++) {
    int res = whoLoss(s1[i % n1], s2[i % n2]);
    result_1[i] = (res == 1);
    result_2[i] = (res == 2);
    cnt1 += result_1[i];
    cnt2 += result_2[i];
  }
  int nCycle = n / cycle;
  int ans1 = nCycle * cnt1;
  int ans2 = nCycle * cnt2;
  for (int i = 0; i < (n - nCycle * cycle); i++) {
    ans1 += result_1[i];
    ans2 += result_2[i];
  }
  cout << ans1 << " " << ans2 << endl;
  return 0;
}
