#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (b) swap(a %= b, b);
  return a;
}
int lca(int a, int b) { return a / gcd(a, b) * b; }
bool win(char a, char b) {
  return a == 'R' && b == 'S' || a == 'S' && b == 'P' || a == 'P' && b == 'R';
}
int main() {
  int n;
  string a, b;
  cin >> n >> a >> b;
  int l = lca(a.length(), b.length());
  int x = 0, y = 0;
  for (int i = 0; i < l; i++)
    if (win(a[i % a.length()], b[i % b.length()]))
      y++;
    else if (win(b[i % b.length()], a[i % a.length()]))
      x++;
  int x0 = 0, y0 = 0;
  for (int i = 0; i < n % l; i++)
    if (win(a[i % a.length()], b[i % b.length()]))
      y0++;
    else if (win(b[i % b.length()], a[i % a.length()]))
      x0++;
  cout << x * (n / l) + x0 << " " << y * (n / l) + y0;
  return 0;
}
