#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s1, s2;
  cin >> n >> s1 >> s2;
  int period = s1.length() * s2.length();
  int l1 = 0;
  int l2 = 0;
  if (n >= period) {
    for (int i = 0; i < period; i++) {
      char c1 = s1[i % s1.length()];
      char c2 = s2[i % s2.length()];
      if ((c1 == 'R' && c2 == 'S') || (c1 == 'S' && c2 == 'P') ||
          (c1 == 'P' && c2 == 'R'))
        l2++;
      else if ((c2 == 'R' && c1 == 'S') || (c2 == 'S' && c1 == 'P') ||
               (c2 == 'P' && c1 == 'R'))
        l1++;
    }
    l1 *= n / period;
    l2 *= n / period;
    n %= period;
  }
  for (int i = 0; i < n; i++) {
    char c1 = s1[i % s1.length()];
    char c2 = s2[i % s2.length()];
    if ((c1 == 'R' && c2 == 'S') || (c1 == 'S' && c2 == 'P') ||
        (c1 == 'P' && c2 == 'R'))
      l2++;
    else if ((c2 == 'R' && c1 == 'S') || (c2 == 'S' && c1 == 'P') ||
             (c2 == 'P' && c1 == 'R'))
      l1++;
  }
  cout << l1 << ' ' << l2;
}
