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".
/**
 * Created by IntelliJ IDEA.
 * User: SONY
 * Date: 08.04.12
 * Time: 17:55
 * To change this template use File | Settings | File Templates.
 */

import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;

public class TaskD extends Thread {
    public TaskD(String inputFileName, String outputFileName) {
        try {
            if (inputFileName != null) {
                this.input = new BufferedReader(new FileReader(inputFileName));
            } else {
                this.input = new BufferedReader(new InputStreamReader(System.in));
            }
            if (outputFileName != null) {
                this.output = new PrintWriter(outputFileName);
            } else {
                this.output = new PrintWriter(System.out);
            }
            this.setPriority(Thread.MAX_PRIORITY);
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        }
    }


    static final int gcd(int a, int b) {
        return b != 0 ? gcd(b, a % b) : a;
    }
    
    static int[] getPrefixFunction(String s) {
        int []p = new int[s.length()];
        for (int i = 1; i < s.length(); ++i) {
            int j = p[i - 1];
            while (j > 0 && s.charAt(i) != s.charAt(j)) {
                j = p[j - 1];
            }
            if (s.charAt(i) == s.charAt(j) ) ++j;
            p[i] = j;
        }
        return p;
    }


    private void solve() throws Throwable {
        String s1 = next(), s2 = next();
        int A = s1.length(), B = s2.length();
        long biggest = gcd(A, B);
        int can = 0;
        for (int i = 1; i <= biggest; ++i) {
            if (s1.charAt(i - 1) != s2.charAt(i - 1)) {
                break;
            }
            can = i;
        }
        int p1[] = getPrefixFunction(s1),
                p2[] = getPrefixFunction(s2);
        int k1 = s1.length() - p1[s1.length() - 1],
                k2 = s2.length() - p2[s2.length() - 1];
        if (s1.length() % k1 != 0) k1 = s1.length();
        if (s2.length() % k2 != 0) k2 = s2.length();
        long minstart = (long)k1 / gcd(k1, k2) * k2;
        long ans = 0, limit = Math.min(can, biggest);
        long current = minstart;
        for (long maybe = minstart; maybe <= limit; maybe += minstart) {
            if (biggest % maybe == 0) ++ans;

        }
        output.println(ans);
        
    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.close();
        }
    }

    public static void main(String... args) {
        new TaskD(null, null).start();
    }

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

    private double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

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

    private String next() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }

    private StringTokenizer tokens;
    private BufferedReader input;
    private PrintWriter output;
}