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.*;
import java.util.*;

public class D {
	public static TreeSet<Integer> primeFactors(int n) {
		TreeSet<Integer>res = new TreeSet<>();
		//res.add(1);
		//res.add(n);
		for(int i=1;i<=Math.sqrt(n)+4;i++){
			if(n%i==0){
				res.add(i);
				res.add(n/i);
			}
		}
		return res;
	}
	public static String f(String s){
		TreeSet<Integer> p1 = primeFactors(s.length());
		p1.add(s.length());
		//System.out.println(p1);
		while (!p1.isEmpty()){
			int t = p1.pollFirst();
			//System.out.println(t);
			boolean f = true;
			for(int j=0;j<s.length()-t;j++){
				if(s.charAt(j)!=s.charAt(j+t)){
					f = false;
					break;
				}
			}
			if(f){
				return s.substring(0,t);
			}
		}
		return s;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		String a = sc.next();
		String b = sc.next();
		String t1 = f(a);
		String t2 = f(b);
		//System.out.println(t1 + " " + t2);
		if(t1.equals(t2)){
			int res = 0;
			TreeSet<Integer> tr1 = primeFactors(a.length());
			int c1 = 0;
			TreeSet<Integer> tt1 = new TreeSet<>();
			while(!tr1.isEmpty()){
				int tmp = tr1.pollFirst();
				if(tmp%t1.length()==0){
					tt1.add(tmp);
				}
			}
			TreeSet<Integer> tr2 = primeFactors(b.length());
			int c2 = 0;
			while(!tr2.isEmpty()){
				int tmp = tr2.pollFirst();
				if(tmp%t1.length()==0 && tt1.contains(tmp)){
					c2++;
				}
			}
			res = c2;
			pw.println(res);
		}else{
			pw.println(0);
		}

		pw.flush();
		pw.close();
	}
	static HashMap<Character,Integer> h = new HashMap<>();

	private static boolean compareString(String a, String b) {
		for(int i=0;i<Math.min(a.length(),b.length());i++){
			if(a.charAt(i)>b.charAt(i)){
				return false;
			}else if(a.charAt(i)<b.charAt(i)){
				return true;
			}
		}
		if(a.length()>b.length())return false;
		return true;
	}
	static int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);

	}
	static class Pair implements Comparable<Pair>{
		int x,y;
		public Pair(int x,int y){
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(Pair o) {
			if(Integer.compare(this.x,o.x)==0){
				return Integer.compare(this.y,o.y);
			}
			return Integer.compare(this.x,o.x);
		}
		public String toString(){
			return x + " " + y;
		}
	}

	static class line{
		HashSet<Point> points;
		int a,b;//a /b
		public line(int a1,int b1){
			this.a =a1/gcd(a1,b1);
			this.b= b1/gcd(a1,b1);

			points = new HashSet<>();
		}
		public boolean equals(line l){
			if(this.a == l.a && this.b==l.b)
				return true;
			return false;
		}
	}
	static class Point{
		int x,y;
		public Point(int x,int y){
			this.x = x;
			this.y = y;
		}
		public boolean equals(Point a){
			if(this.x == a.x && this.y ==a.y)
				return true;
			return false;
		}
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
	double res = 0, f = 1;
	boolean dec = false, neg = false;
	int start = 0;
	if (x.charAt(0) == '-') {
		neg = true;
		start++;
	}
	for (int i = start; i < x.length(); i++)
		if (x.charAt(i) == '.') {
			res = Long.parseLong(sb.toString());
			sb = new StringBuilder("0");
				dec = true;
			} else {
				sb.append(x.charAt(i));
				if (dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg ? -1 : 1);
	}

	public boolean ready() throws IOException {
		return br.ready();

	}
	}
}