#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}
void bubbleSort(long long* array, long long length) {
  long long i, j;
  for (i = 0; i < length; i++) {
    for (j = 0; j < i; j++) {
      if (array[i] < array[j]) {
        long long temp = array[i];
        array[i] = array[j];
        array[j] = temp;
      }
    }
  }
}
void change(char* aa, char* bb, int* a, int* b) {
  if (*aa != *bb) {
    if (((*aa == 'R') && (*bb == 'P')) || ((*aa == 'P') && (*bb == 'S')) ||
        ((*aa == 'S') && (*bb == 'R'))) {
      (*b)++;
    } else {
      (*a)++;
    }
  }
}
int main() {
  int n;
  cin >> n;
  string a1, b1;
  cin >> a1 >> b1;
  int a = 0;
  int b = 0;
  int i = 0;
  int j = 0;
  for (int k = 0; k < min(a1.size() * b1.size(), n); k++) {
    change(&a1[i], &b1[j], &a, &b);
    i = (i + 1) % a1.size();
    j = (j + 1) % b1.size();
  }
  a *= n / (min(a1.size() * b1.size(), n));
  b *= n / (min(a1.size() * b1.size(), n));
  i = 0;
  j = 0;
  for (int k = (n / (min(a1.size() * b1.size(), n))) * a1.size() * b1.size();
       k < n; k++) {
    change(&(a1[i]), &(b1[j]), &a, &b);
    i = (i + 1) % a1.size();
    j = (j + 1) % b1.size();
  }
  cout << b << " " << a;
}
