Nikephoros and Polycarpus play rock-paper-scissors. The loser gets pinched (not too severely!).

Let us remind you the rules of this game. Rock-paper-scissors is played by two players. In each round the players choose one of three items independently from each other. They show the items with their hands: a rock, scissors or paper. The winner is determined by the following rules: the rock beats the scissors, the scissors beat the paper and the paper beats the rock. If the players choose the same item, the round finishes with a draw.

Nikephoros and Polycarpus have played n rounds. In each round the winner gave the loser a friendly pinch and the loser ended up with a fresh and new red spot on his body. If the round finished in a draw, the players did nothing and just played on.

Nikephoros turned out to have worked out the following strategy: before the game began, he chose some sequence of items A = (a1, a2, ..., am), and then he cyclically showed the items from this sequence, starting from the first one. Cyclically means that Nikephoros shows signs in the following order: a1, a2, ..., am, a1, a2, ..., am, a1, ... and so on. Polycarpus had a similar strategy, only he had his own sequence of items B = (b1, b2, ..., bk).

Determine the number of red spots on both players after they've played n rounds of the game. You can consider that when the game began, the boys had no red spots on them.

Input

The first line contains integer n (1 ≤ n ≤ 2·109) — the number of the game's rounds.

The second line contains sequence A as a string of m characters and the third line contains sequence B as a string of k characters (1 ≤ m, k ≤ 1000). The given lines only contain characters "R", "S" and "P". Character "R" stands for the rock, character "S" represents the scissors and "P" represents the paper.

Output

Print two space-separated integers: the numbers of red spots Nikephoros and Polycarpus have.

Examples

Input

7
RPS
RSPP


Output

3 2

Input

5
RRRRRRRR
R


Output

0 0

Note

In the first sample the game went like this:

  * R - R. Draw. 
  * P - S. Nikephoros loses. 
  * S - P. Polycarpus loses. 
  * R - P. Nikephoros loses. 
  * P - R. Polycarpus loses. 
  * S - S. Draw. 
  * R - P. Nikephoros loses. 



Thus, in total Nikephoros has 3 losses (and 3 red spots), and Polycarpus only has 2.
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class KrokA {

	private static InputReader in;
	private static PrintWriter out;

	public static void main(String[] args) {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
		run();
		out.close();
	}

	public static void run() {
		int n = in.readInt();
		String s1 = in.readString();
		int m = s1.length();
		String s2 = in.readString();
		int k = s2.length();
		
		int km = m * k / gcd(m, k);
		int[] arr = new int[km];
		int[] brr = new int[km];
		int ai = 0;
		int bi = 0;
		if (s1.charAt(ai) == 'R' && s2.charAt(bi) == 'S' || s1.charAt(ai) == 'S' && s2.charAt(bi) == 'P' || s1.charAt(ai) == 'P' && s2.charAt(bi) == 'R') {
			arr[0] = 1; 
		} else if (s2.charAt(ai) == 'R' && s1.charAt(bi) == 'S' || s2.charAt(ai) == 'S' && s1.charAt(bi) == 'P' || s2.charAt(ai) == 'P' && s1.charAt(bi) == 'R') {
			brr[0] = 1; 
		} 
		ai = (ai+1) % m; 
		bi = (bi+1) % k; 
		for(int i = 1; i < km;i++) {
			if (s1.charAt(ai) == 'R' && s2.charAt(bi) == 'S' || s1.charAt(ai) == 'S' && s2.charAt(bi) == 'P' || s1.charAt(ai) == 'P' && s2.charAt(bi) == 'R') {
				arr[i] = arr[i-1] + 1; brr[i] = brr[i-1];
			} else if (s2.charAt(bi) == 'R' && s1.charAt(ai) == 'S' || s2.charAt(bi) == 'S' && s1.charAt(ai) == 'P' || s2.charAt(bi) == 'P' && s1.charAt(ai) == 'R') {
				brr[i] = brr[i-1] + 1; arr[i] = arr[i-1];
			} else {
				arr[i] = arr[i-1];
				brr[i] = brr[i-1];
			}
			ai = (ai+1) % m; 
			bi = (bi+1) % k; 
		}
		int resa = 0;
		int resb = 0;
		resa = arr[km-1] * (n/km);
		if (n % km != 0) {
			resa+=arr[n % km - 1];
		}
		resb = brr[km-1] * (n/km);
		if (n % km != 0) {
			resb+=brr[n % km - 1];
		}
		out.print(resb + " " + resa);
	}
	
	public static int gcd(int p, int q) {
		if (q == 0) {
			return p;
		}
		return gcd(q, p % q);
	}
}

class Pair {
	int x;
	int ind;

	public Pair(int x, int ind) {
		super();
		this.x = x;
		this.ind = ind;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ind;
		result = prime * result + x;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pair other = (Pair) obj;
		if (ind != other.ind)
			return false;
		if (x != other.x)
			return false;
		return true;
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}
}
