#include <bits/stdc++.h>
using namespace std;
int lcm(int n, int m) {
  int r;
  while ((r = n % m) != 0) {
    n = m;
    m = r;
  }
  return m;
}
int main() {
  int i, j, k, l, n, m;
  char a[2005], b[2005];
  while (scanf("%d", &n) != EOF) {
    int ans1 = 0, ans2 = 0;
    scanf("%s", a);
    scanf("%s", b);
    int pos1 = 0, pos2 = 0;
    int l1 = strlen(a);
    int l2 = strlen(b);
    int minn = l1 * l2 / lcm(l1, l2);
    int xx = minn;
    if (n >= minn) {
      while (xx--) {
        if (a[pos1] == 'R') {
          if (b[pos2] == 'P')
            ans1++;
          else if (b[pos2] == 'S')
            ans2++;
        } else if (a[pos1] == 'S') {
          if (b[pos2] == 'R')
            ans1++;
          else if (b[pos2] == 'P')
            ans2++;
        } else if (a[pos1] == 'P') {
          if (b[pos2] == 'R')
            ans2++;
          else if (b[pos2] == 'S')
            ans1++;
        }
        pos1++, pos2++;
        if (pos1 >= l1) pos1 = 0;
        if (pos2 >= l2) pos2 = 0;
      }
      ans1 *= n / minn;
      ans2 *= n / minn;
      int num = n - n / minn * minn;
      while (num--) {
        if (a[pos1] == 'R') {
          if (b[pos2] == 'P')
            ans1++;
          else if (b[pos2] == 'S')
            ans2++;
        } else if (a[pos1] == 'S') {
          if (b[pos2] == 'R')
            ans1++;
          else if (b[pos2] == 'P')
            ans2++;
        } else if (a[pos1] == 'P') {
          if (b[pos2] == 'R')
            ans2++;
          else if (b[pos2] == 'S')
            ans1++;
        }
        pos1++, pos2++;
        if (pos1 >= l1) pos1 = 0;
        if (pos2 >= l2) pos2 = 0;
      }
    } else {
      while (n--) {
        if (a[pos1] == 'R') {
          if (b[pos2] == 'P')
            ans1++;
          else if (b[pos2] == 'S')
            ans2++;
        } else if (a[pos1] == 'S') {
          if (b[pos2] == 'R')
            ans1++;
          else if (b[pos2] == 'P')
            ans2++;
        } else if (a[pos1] == 'P') {
          if (b[pos2] == 'R')
            ans2++;
          else if (b[pos2] == 'S')
            ans1++;
        }
        pos1++, pos2++;
        if (pos1 >= l1) pos1 = 0;
        if (pos2 >= l2) pos2 = 0;
      }
    }
    cout << ans1 << " " << ans2 << endl;
  }
  return 0;
}
