#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool Up(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool Down(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int N, l, l1, l2;
int sum1[1024 * 1024], sum2[1024 * 1024], beat[256][256];
char s1[1024], s2[1024];
inline int Gcd(int a, int b) {
  for (int c; c = a % b; a = b, b = c)
    ;
  return b;
}
inline int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
void Work() {
  l = Lcm(l1, l2);
  for (int i = (0); i < (l); ++i) {
    int a = s1[i % l1], b = s2[i % l2];
    sum1[i] = sum2[i] = 0;
    if (beat[a][b])
      sum1[i] = 0, sum2[i] = 1;
    else if (beat[b][a])
      sum1[i] = 1, sum2[i] = 0;
    else
      sum1[i] = sum2[i] = 0;
    if (i) {
      sum1[i] += sum1[i - 1];
      sum2[i] += sum2[i - 1];
    }
  }
  int x, y;
  x = sum1[l - 1] * (N / l);
  y = sum1[N % l - 1];
  printf("%d ", x + y);
  x = sum2[l - 1] * (N / l);
  y = sum2[N % l - 1];
  printf("%d\n", x + y);
}
void Init() {
  memset(beat, 0, sizeof(beat));
  scanf("%d", &N);
  scanf("%s", s1);
  scanf("%s", s2);
  l1 = strlen(s1);
  l2 = strlen(s2);
  beat['R']['S'] = 1;
  beat['S']['P'] = 1;
  beat['P']['R'] = 1;
}
int main() {
  Init();
  Work();
  return 0;
}
