#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
const int INF = 2000000000;
const int mod = 1000000007;
const int N = 10000005;
int main() {
  map<pair<char, char>, int> a;
  a[make_pair('R', 'S')] = 1;
  a[make_pair('S', 'P')] = 1;
  a[make_pair('P', 'R')] = 1;
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  int l1 = s1.length();
  int l2 = s2.length();
  int l = l1 * l2;
  int res1 = 0, res2 = 0;
  for (int(i) = (0); (i) < (l); (i)++) {
    res1 += a[make_pair(s1[i % l1], s2[i % l2])];
    res2 += a[make_pair(s2[i % l2], s1[i % l1])];
  }
  res1 *= n / l;
  res2 *= n / l;
  for (int(i) = (0); (i) < (n % l); (i)++) {
    res1 += a[make_pair(s1[i % l1], s2[i % l2])];
    res2 += a[make_pair(s2[i % l2], s1[i % l1])];
  }
  cout << res2 << ' ' << res1;
  return 0;
}
