Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.

String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string "abab" has two divisors — "ab" and "abab".

Now Vasya wants to write a program that calculates the number of common divisors of two strings. Please help him.

Input

The first input line contains a non-empty string s1.

The second input line contains a non-empty string s2.

Lengths of strings s1 and s2 are positive and do not exceed 105. The strings only consist of lowercase Latin letters.

Output

Print the number of common divisors of strings s1 and s2. 

Examples

Input

abcdabcd
abcdabcdabcdabcd


Output

2


Input

aaa
aa


Output

1

Note

In first sample the common divisors are strings "abcd" and "abcdabcd".

In the second sample the common divisor is a single string "a". String "aa" isn't included in the answer as it isn't a divisor of string "aaa".
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Scanner;

public class CommonDivisors {
	String s1;
	String s2;
	long base = 29;
	long p = (1L << 31) - 1;
	
	long totalHash(String s) {
		long hash = 0;
		for (int i = 0; i < s.length(); i++)
			hash = (base * hash + s.charAt(i) - 'a') % p;
		return hash;
	}

	int solve() {
		int n1 = s1.length();
		int n2 = s2.length();
		int n = Math.min(n1, n2);
		int count = 0;
		long totalHash1 = totalHash(s1);
		long totalHash2 = totalHash(s2);
		long base_n1_min_1 = modPower(base, n1) - 1; // base^n1 - 1
		long base_n2_min_1 = modPower(base, n2) - 1; // base^n2 - 1
		long base_i = 1; // base^i
		long hash1 = 0;
		long hash2 = 0;
		for (int i = 1; i <= n; i++) {
			if (s1.charAt(i - 1) != s2.charAt(i - 1))
				return count;
			base_i = (base * base_i) % p;
			hash1 = (base * hash1 + s1.charAt(i - 1) - 'a') % p; // h(first i characters of s1)
			hash2 = (base * hash2 + s2.charAt(i - 1) - 'a') % p; // h(first i characters of s2)
			if (n1 % i != 0 || n2 % i != 0)
				continue;
			long inverse = modPower(base_i - 1, p - 2); // 1/(base^i - 1)
			// h(n1/i copies of first i characters of s1)
			// = h(first i characters of s1) * (1 + x + ... + x^(n1/i-1) where x=base^i
			// = hash1 * (1 + x + ... + x^(n1/i-1)
			// = hash1 * (x^n1/i - 1)/(x - 1)
			// = hash1 * (base^n1 - 1)/(base^i - 1)
			long extended1 = ((base_n1_min_1 * inverse) % p * hash1) % p;
			long extended2 = ((base_n2_min_1 * inverse) % p * hash2) % p;
			if (extended1 != totalHash1 || extended2 != totalHash2)
				continue;
			if (isDivisor(i, s1) && isDivisor(i, s2))
				count++;
		}
		return count;
	}

	boolean isDivisor(int m, String s) {
		if (s.length() % m != 0)
			return false;
		for (int j = 0; j < m; j++)
			if (s1.charAt(j) != s2.charAt(j))
				return false;
		for (int i = 1; i < s.length() / m; i++)
			for (int j = 0; j < m; j++)
				if (s.charAt(j) != s.charAt(i * m + j))
					return false;
		return true;
	}

	void parse(Scanner sc) {
		s1 = sc.nextLine();
		s2 = sc.nextLine();
	}

	void solveOne(InputStream in, PrintWriter pw) {
		Locale.setDefault(Locale.ROOT);
		try (Scanner sc = new Scanner(in)) {
			parse(sc);
		}
		pw.println(solve());
	}

	public static void main(String[] args) {
		try (PrintWriter pw = new PrintWriter(System.out)) {
			new CommonDivisors().solveOne(System.in, pw);
			pw.flush();
		}
	}

	long modPower(long n, long e) {
		if (e == 0)
			return n == 0 ? 0 : 1;
		long y = 1;
		while (e > 1) {
			if ((e & 1) == 1)
				y = (n * y) % p;
			n = (n * n) % p;
			e /= 2;

		}
		return (n * y) % p;
	}
}