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.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream stdin = System.in;
        OutputStream stdout = System.out;

        /*
         * InputStream fileIn = new FileInputStream(new File("input.txt"));
         * OutputStream fileOut = new FileOutputStream(new File("output.txt"));
         */

        InputReader in = new InputReader(stdin);
        OutputWriter out = new OutputWriter(stdout);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {
    
    static int p;
    static long[]p_pow;
    static long[]ha;
    static long[]hb;
    static String a;
    static String b;
    
    public void solve(int testNumber, InputReader in, OutputWriter out) {

        a = in.readString();
        b = in.readString();

        int aa = a.length();
        int bb = b.length();
        int len = Math.min(aa, bb);
        
        String s;
        
        if (a.length() == len) {
            s = a;
        }
        else {
            s = b;
        }
        
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i = 1; i <= len; i++) {
            if (aa % i == 0 && bb % i == 0) {
                list.add(i);
            }
        }

        p = 31;
        p_pow = new long[Math.max(aa, bb)];
        p_pow[0] = 1;
        for (int i = 1; i < p_pow.length; ++i)
            p_pow[i] = p_pow[i - 1] * p;

        ha = new long[a.length()];
        for (int i = 0; i < a.length(); ++i) {
            ha[i] = (a.charAt(i) - 'a' + 1) * p_pow[i];
            if (i != 0)
                ha[i] += ha[i - 1];
        }

        hb = new long[b.length()];
        for (int i = 0; i < b.length(); ++i) {
            hb[i] = (b.charAt(i) - 'a' + 1) * p_pow[i];
            if (i != 0)
                hb[i] += hb[i - 1];
        }
        
        
        
        int answer = 0;
        for (int i = 0; i < list.size(); i++) {
            int div = list.get(i);
            boolean ans = isAnswer(s.substring(0, div), div);
//          System.out.println(s.substring(0, div) + "   " + div + "    " + ans);
            if (ans) answer++;
        }
        
        out.printLine(answer);
    
    }
    
    public boolean isAnswer(String s, int n) {
        int prev = -1;
        int next = -1;
        long h_s = 0;
        for (int i=0; i<s.length(); ++i)
            h_s += (s.charAt(i) - 'a' + 1) * p_pow[i];


        
        for (int i = 0; i + s.length() - 1 < a.length(); ++i)
        {
            long cur_h = ha[i+s.length()-1];
            if (i!=0)  cur_h -= ha[i-1];
            if (cur_h == h_s * p_pow[i]) {
                
                if (prev == -1) {
                    prev = i;
                    next = i;
                    if (a.length() == n) break;
                    continue;
                }
                else {
                    next = i;
                    if (next - prev != n) {
                        if (next - prev < n) continue;
                        else return false;
                    }
                    else {
                        prev = next;
                    }
                }
            }
        }
        
        if (next != a.length() - n) return false;
        
        
        prev = -1;
        next = -1;
        for (int i = 0; i + s.length() - 1 < b.length(); ++i)
        {
            long cur_h = hb[i+s.length()-1];
            if (i!=0)  cur_h -= hb[i-1];
            if (cur_h == h_s * p_pow[i]) {
                
                if (prev == -1) {
                    prev = i;
                    next = i;
                    if (b.length() == n) return true;
                    continue;
                }
                else {
                    next = i;
                    if (next - prev != n) {
                        if (next - prev < n) continue;
                        else return false;
                    }
                    else {
                        prev = next;
                    }
                }
            }
        }
        if (next != b.length() - n) 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 long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long 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;
    }

}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(outputStream);
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }
}

class StringUtil {
    public static int[] prefixFunction(String s) {
        int n = s.length();
        int[] p = new int[n];
        for (int i = 1; i < n; i++) {
            int k = p[i - 1];
            while (k > 0 && s.charAt(k) != s.charAt(i)) {
                k = p[k - 1];
            }
            p[i] = k + (s.charAt(k) == s.charAt(i) ? 1 : 0);
        }
        return p;
    }

    public static int kmpMatcher(String s, String pattern) {
        int m = pattern.length();
        if (m == 0) {
            return 0;
        }
        int n = s.length();
        int[] p = prefixFunction(pattern);
        int k = 0;
        for (int i = 0; i < n; i++) {
            while (k > 0 && s.charAt(i) != pattern.charAt(k)) {
                k = p[k - 1];
            }
            if (s.charAt(i) == pattern.charAt(k)) {
                k++;
            }
            if (k == m) {
                return i - m + 1;
            }
        }
        return -1;
    }
}