#include <bits/stdc++.h>
using namespace std;
int main() {
  int games;
  cin >> games;
  char a[1001], b[1001];
  scanf("%s %s", a, b);
  int alen = strlen(a);
  int blen = strlen(b);
  int loop_game = alen * blen;
  int loop_num = games / loop_game;
  int last_game = games % loop_game;
  int last_a_point = 0;
  int last_b_point = 0;
  int loop_a_point = 0;
  int loop_b_point = 0;
  for (int i = 0; i < loop_game; i++) {
    int ai = i % alen;
    int bi = i % blen;
    if (last_game == i) {
      last_a_point = loop_a_point;
      last_b_point = loop_b_point;
    }
    switch (a[ai] - b[bi]) {
      case 'R' - 'S':
      case 'S' - 'P':
      case 'P' - 'R':
        loop_b_point++;
        break;
      case 0:
        break;
      default:
        loop_a_point++;
    }
  }
  printf("%d %d\n", loop_a_point * loop_num + last_a_point,
         loop_b_point * loop_num + last_b_point);
}
