#include <bits/stdc++.h>
using namespace std;
bool win(char x, char y) {
  if (x == 'R' && y == 'S' || x == 'S' && y == 'P' || x == 'P' && y == 'R')
    return true;
  else if (x == 'S' && y == 'R' || x == 'P' && y == 'S' || x == 'R' && y == 'P')
    return false;
  else if (x == 'R' && y == 'R' || x == 'S' && y == 'S' || x == 'P' && y == 'P')
    return false;
}
int main() {
  int n = 0, p = 0, r, i = 0, j = 0;
  char c;
  string nike;
  string poly;
  cin >> r;
  cin >> nike >> poly;
  i = nike.length();
  j = poly.length();
  int m = i * j;
  for (int k = 0; k < m; k++) {
    int x = k % i, y = k % j;
    if (win(nike[x], poly[y]))
      n++;
    else if (win(poly[y], nike[x]))
      p++;
  }
  n *= r / m;
  p *= r / m;
  for (int k = 0; k < r % m; k++) {
    int x = k % i, y = k % j;
    if (win(nike[x], poly[y]))
      n++;
    else if (win(poly[y], nike[x]))
      p++;
  }
  cout << p << " " << n << endl;
  return 0;
}
