#include <bits/stdc++.h>
using namespace std;
int f[5];
int m, k, n;
string a, b;
int win(char r1, char r2) {
  if (r1 == r2) return 0;
  switch (r1) {
    case 'R':
      return r2 == 'S' ? 2 : 1;
    case 'S':
      return r2 == 'P' ? 2 : 1;
    default:
      return r2 == 'R' ? 2 : 1;
  }
}
int main() {
  cin >> n >> a >> b;
  m = a.size();
  k = b.size();
  for (int i = 0; i < n && i < m * k; i++) {
    f[win(a[i % m], b[i % k])] += (n - i + m * k - 1) / (m * k);
  }
  cout << f[1] << " " << f[2];
  return 0;
}
