#include <bits/stdc++.h>
using namespace std;
int main(void) {
  char a[1024], b[1024];
  int n, k;
  cin >> n >> a >> b;
  int i = 0, j = 0, awin = 0, bwin = 0;
  for (k = 0; k < n; k++) {
    if (a[i] == '\0') {
      i = 0;
    }
    if (b[j] == '\0') {
      j = 0;
    }
    if (k != 0 && i == 0 && j == 0) {
      int repeat = (n - k) / k;
      awin += awin * repeat;
      bwin += bwin * repeat;
      k += repeat * k;
      if (k == n) {
        break;
      }
    }
    if (a[i] == 'R') {
      if (b[j] == 'S') {
        awin++;
      } else if (b[j] == 'P') {
        bwin++;
      }
    } else if (a[i] == 'P') {
      if (b[j] == 'R') {
        awin++;
      } else if (b[j] == 'S') {
        bwin++;
      }
    } else {
      if (b[j] == 'P') {
        awin++;
      } else if (b[j] == 'R') {
        bwin++;
      }
    }
    i++;
    j++;
  }
  cout << bwin << " " << awin;
  return 0;
}
