#include <bits/stdc++.h>
using namespace std;
int t, n, m, k;
string a, b;
int gcd(int x, int y) {
  while (x && y)
    if (x > y)
      x %= y;
    else
      y %= x;
  return x + y;
}
int func(char x, char y) {
  if (x == y) return 0;
  if (x == 'R' && y == 'S') return 1;
  if (x == 'S' && y == 'P') return 1;
  if (x == 'P' && y == 'R') return 1;
  return -1;
}
int main() {
  scanf("%d\n", &k);
  getline(cin, a);
  getline(cin, b);
  n = a.size();
  m = b.size();
  int rt = (n / gcd(n, m)) * m;
  int ans1 = 0, ans2 = 0;
  int _ans1 = 0, _ans2 = 0;
  int need = (k % rt);
  int count = k / rt;
  for (int i = 0; i < rt; i++) {
    int ii = i % n;
    int jj = i % m;
    int res = func(a[ii], b[jj]);
    if (res == 1) ans1++;
    if (res == -1) ans2++;
    if ((i + 1) == need) {
      _ans1 = ans1;
      _ans2 = ans2;
    }
  }
  ans1 *= count;
  ans2 *= count;
  cout << ans2 + _ans2 << " " << ans1 + _ans1 << endl;
  return 0;
}
