#include <bits/stdc++.h>
using namespace std;
bool beat(char c, char d) {
  if (c == 'R' && d == 'S' || c == 'S' && d == 'P' || c == 'P' && d == 'R')
    return true;
  return false;
}
int main() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  int m = a.size(), k = b.size();
  int as = 0, bs = 0;
  for (int i = 0; i < m * k; i++) {
    if (beat(a[i % a.size()], b[i % b.size()])) bs++;
    if (beat(b[i % b.size()], a[i % a.size()])) as++;
  }
  as *= n / (m * k), bs *= n / (m * k);
  n = n % (m * k);
  for (int i = 0; i < n; i++) {
    if (beat(a[i % a.size()], b[i % b.size()])) bs++;
    if (beat(b[i % b.size()], a[i % a.size()])) as++;
  }
  cout << as << ' ' << bs << endl;
  return 0;
}
