#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a == 0)
    return b;
  else {
    gcd(b % a, a);
  }
}
int main() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  int a1 = a.size(), b1 = b.size();
  int f = (a1 * b1) / gcd(min(a1, b1), max(b1, a1));
  int arr[f];
  for (int i = 0; i < f; i++) {
    if (a[i % a1] == 'R' && b[i % b1] == 'P') arr[i] = 1;
    if (a[i % a1] == 'R' && b[i % b1] == 'S') arr[i] = 0;
    if (a[i % a1] == 'P' && b[i % b1] == 'R') arr[i] = 0;
    if (a[i % a1] == 'P' && b[i % b1] == 'S') arr[i] = 1;
    if (a[i % a1] == 'S' && b[i % b1] == 'P') arr[i] = 0;
    if (a[i % a1] == 'S' && b[i % b1] == 'R') arr[i] = 1;
    if (a[i % a1] == 'S' && b[i % b1] == 'S') arr[i] = 2;
    if (a[i % a1] == 'R' && b[i % b1] == 'R') arr[i] = 2;
    if (a[i % a1] == 'P' && b[i % b1] == 'P') arr[i] = 2;
  }
  int first = 0, second = 0;
  for (int i = 0; i < f; i++) {
    if (arr[i] == 0) first++;
    if (arr[i] == 1) second++;
  }
  first *= n / f;
  second *= n / f;
  int k = n % f;
  for (int i = 0; i < k; i++) {
    if (arr[i] == 0) first++;
    if (arr[i] == 1) second++;
  }
  cout << second << " " << first;
  return 0;
}
