#include <bits/stdc++.h>
using namespace std;
int winner(char a, char b) {
  if ((a == 'R' && b == 'S') || (a == 'P' && b == 'R') ||
      (a == 'S' && b == 'P'))
    return 1;
  return 0;
}
int main() {
  long int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  int p[2] = {0};
  for (long int i = 0; i < a.size() * b.size() && i < n; i++)
    if (a[i % a.size()] != b[i % b.size()])
      p[winner(a[i % a.size()], b[i % b.size()])]++;
  p[0] *= (n / (a.size() * b.size()));
  p[1] *= (n / (a.size() * b.size()));
  for (int i = 0; i < n % (a.size() * b.size()); i++)
    if (a[i % a.size()] != b[i % b.size()])
      p[winner(a[i % a.size()], b[i % b.size()])]++;
  cout << p[0] << " " << p[1];
}
