#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
char w[128][128], a[1002], b[1002];
int main() {
  int n, m, r, i, j, k, w1 = 0, w2 = 0, i1, i2, repeat;
  scanf("%d", &r);
  scanf("%s%s", a, b);
  n = strlen(a);
  m = strlen(b);
  i1 = i2 = 0;
  w['R']['S'] = 1;
  w['S']['P'] = 1;
  w['P']['R'] = 1;
  for (i = 0; i < n * m; ++i) {
    if (a[i1] != b[i2])
      if (w[a[i1]][b[i2]])
        ++w1;
      else
        ++w2;
    i1 = (i1 + 1) % n;
    i2 = (i2 + 1) % m;
  }
  repeat = r / (n * m);
  w1 *= repeat;
  w2 *= repeat;
  r %= n * m;
  for (i = 0; i < r; ++i) {
    if (a[i1] != b[i2])
      if (w[a[i1]][b[i2]])
        ++w1;
      else
        ++w2;
    i1 = (i1 + 1) % n;
    i2 = (i2 + 1) % m;
  }
  printf("%d ", w2);
  printf("%d ", w1);
  return 0;
}
