#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, k, n, i, p1 = 0, p2 = 0, l, u, j, t;
  string a, b;
  cin >> n >> a >> b;
  m = a.length();
  k = b.length();
  l = m * k;
  for (i = 1, j = 0, t = 0; i <= l && i <= n; i++, j++, t++) {
    j %= m;
    t %= k;
    if (n % l >= i)
      u = 1;
    else
      u = 0;
    if (a[j] == 'R' && b[t] == 'S')
      p2 += n / l + u;
    else if (a[j] == 'S' && b[t] == 'R')
      p1 += n / l + u;
    else if (a[j] == 'S' && b[t] == 'P')
      p2 += n / l + u;
    else if (a[j] == 'P' && b[t] == 'S')
      p1 += n / l + u;
    else if (a[j] == 'P' && b[t] == 'R')
      p2 += n / l + u;
    else if (a[j] == 'R' && b[t] == 'P')
      p1 += n / l + u;
  }
  cout << p1 << " " << p2 << endl;
  return 0;
}
