#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
namespace std {
bool operator<(const complex<double>& a, const complex<double>& b) {
  return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}  // namespace std
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int win(char a, char b) {
  if (a == b) return 2;
  if (a == 'R') {
    if (b == 'S') return 0;
    return 1;
  }
  if (a == 'S') {
    if (b == 'R') return 1;
    return 0;
  }
  if (b == 'S') {
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  int m = a.length();
  int k = b.length();
  int l = m * k / gcd(m, k);
  int ansa = 0;
  int ansb = 0;
  for (int i = (0); i < (int)(l); i++) {
    char la = a[i % m];
    char lb = b[i % k];
    ansa += (win(la, lb) == 0) * (n / l);
    ansb += (win(la, lb) == 1) * (n / l);
  }
  for (int i = (0); i < (int)(n % l); i++) {
    char la = a[i % m];
    char lb = b[i % k];
    ansa += (win(la, lb) == 0);
    ansb += (win(la, lb) == 1);
  }
  cout << ansb << " " << ansa << endl;
  return 0;
}
