#include <bits/stdc++.h>
using namespace std;
const int MAXL = 1111;
int N, A, B;
char a[MAXL], b[MAXL];
int game(char x, char y) {
  if (x == y)
    return 0;
  else if (x == 'R' && y == 'S' || x == 'S' && y == 'P' || x == 'P' && y == 'R')
    return 0;
  else
    return 1;
}
int main() {
  scanf("%d", &N);
  scanf("%s %s", a, b);
  A = strlen(a);
  B = strlen(b);
  int rep = A * B;
  int score1 = 0, score2 = 0;
  for (int i = 0; i < rep; i++) {
    score1 += game(a[i % A], b[i % B]);
    score2 += game(b[i % B], a[i % A]);
  }
  score1 *= N / rep;
  score2 *= N / rep;
  N %= rep;
  for (int i = 0; i < N; i++) {
    score1 += game(a[i % A], b[i % B]);
    score2 += game(b[i % B], a[i % A]);
  }
  printf("%d %d\n", score1, score2);
  return 0;
}
