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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Stream;

public class Solution implements Runnable {

	static final long MOD = Long.MAX_VALUE;
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	StringBuilder answer = new StringBuilder();

	public static void main(String[] args) {
		// long startt = System.nanoTime();
		new Thread(null, new Solution(), "persefone", 1 << 28).start();
		// out.println((System.nanoTime() - startt));

	}

	@Override
	public void run() {
		solve(in.next(), in.next());
		printf();
	}

	void solve(String s, String w) {
		int ls = s.length(), lw = w.length();
		if (ls == lw && !s.equals(w)) {
			printf(0);
			return;
		}
		int ll = Math.max(ls, lw), li = Math.min(ls, lw);
		long[] hs = new long[ls + 1];
		computeHashArray(hs, s, ls);
		long[] hw = new long[lw + 1];
		computeHashArray(hw, w, lw);
		long[] mod = new long[ll + 1];
		computeModArray(mod, ll);
		List<Integer> list = new ArrayList<>();
		for (int i = 1; i <= Math.sqrt(li); i++) {
			if (li % i == 0) {
				if (ll % i == 0)
					list.add(i);
				if (li != i * i && ll % (li / i) == 0)
					list.add(li/i);
			}
		}
	//	printf(list);
		printf(list.stream().filter(i -> checkStringDivisor(hs, hw, mod, i)).count());
		
	}

	boolean checkStringDivisor(long[] hs, long[] hw, long[] mod, int n) {
		Set<Long> set = new HashSet<>();
		for (int i = 0; i <= hs.length - n - 1; i += n) {
			set.add(getHash(hs, mod, i, i + n));
			if (set.size() > 1) return false;
		}
		for (int i = 0; i <= hw.length - n - 1; i += n) {
			set.add(getHash(hw, mod, i, i + n));
			if (set.size() > 1)	 return false;
		}
		return true;
	}

	void computeHashArray(long[] hash, String s, int n) {
		for (int i = 1; i <= n; i++)
			hash[i] = (31 * hash[i - 1] + s.charAt(i - 1) - 'a') % MOD;
	}

	void computeModArray(long[] mod, int n) {
		mod[0] = 1;
		for (int i = 1; i <= n; i++)
			mod[i] = (mod[i - 1] * 31) % MOD;
	}

	long getHash(long[] hash, long[] mod, int i, int j) {
		return (hash[j] - hash[i] * mod[j - i]) % MOD;
	}

	long getHash(String s) {
		long hash = 0;
		for (int i = 0; i < s.length(); i++)
			hash = (hash * 31 + s.charAt(i) - 'a') % MOD;
		return hash;
	}

	void printf() {
		out.print(answer);
		out.close();
	}

	void printf(Stream<?> str) {
		str.forEach(o -> add(o, " "));
		add("\n");
	}

	void printf(Object... obj) {
		if (obj.getClass().isPrimitive()) {
			add(obj, "\n");
			return;
		}
		if (obj.length > 1) {
			printf(Arrays.stream(obj));
			return;
		}

		if (obj.length == 1) {
			Object o = obj[0];
			if (o instanceof int[])
				printf(Arrays.stream((int[]) o).boxed());
			else if (o instanceof char[])
				printf(String.valueOf(o).chars());
			else if (o instanceof long[])
				printf(Arrays.stream((long[]) o).boxed());
			else if (o instanceof double[])
				printf(Arrays.stream((double[]) o).boxed());
			else
				add(o, "\n");
		}
	}

	void printf(Collection<?> col) {
		printf(col.stream());
	}

	<T, K> void add(T t, K k) {
		if (t instanceof Collection<?>) {
			((Collection<?>) t).forEach(i -> add(i, " "));
		} else if (t instanceof Object[]) {
			Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
		} else
			add(t);
		add(k);
	}

	<T> void add(T t) {
		answer.append(t);
	}

	static class Node {
		private int x, y;

		Node(int x, int y) {
			this.x = x;
			this.y = y;
		}

		int getX() {
			return x;
		}

		int getY() {
			return y;
		}

		@Override
		public String toString() {
			return x + " " + y;
		}
	}

	static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
			implements Comparable<Pair<K, V>> {
		private K k;
		private V v;

		Pair() {
		}

		Pair(K k, V v) {
			this.k = k;
			this.v = v;
		}

		K getK() {
			return k;
		}

		V getV() {
			return v;
		}

		void setK(K k) {
			this.k = k;
		}

		void setV(V v) {
			this.v = v;
		}

		void setKV(K k, V v) {
			this.k = k;
			this.v = v;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object o) {
			if (this == o)
				return true;
			if (o == null || !(o instanceof Pair))
				return false;
			Pair<K, V> p = (Pair<K, V>) o;
			return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
		}

		@Override
		public int hashCode() {
			int hash = 31;
			hash = hash * 89 + k.hashCode();
			hash = hash * 89 + v.hashCode();
			return hash;
		}

		@Override
		public int compareTo(Pair<K, V> pair) {
			return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
		}

		@Override
		public Pair<K, V> clone() {
			return new Pair<K, V>(this.k, this.v);
		}

		@Override
		public String toString() {
			return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
		}
	}

	static class Reader {
		private BufferedReader br;
		private StringTokenizer st;

		Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			try {
				while (st == null || !st.hasMoreTokens()) {
					st = new StringTokenizer(br.readLine());
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			return st.nextToken();
		}

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

		int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}

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

		String nextLine() {
			String s = "";
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;
		}
	}
}