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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DCommonDivisors solver = new DCommonDivisors();
        solver.solve(1, in, out);
        out.close();
    }

    static class DCommonDivisors {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            String str1 = s.nextString();
            String str2 = s.nextString();

            if (str1.length() > str2.length()) {
                String str3 = new StringBuilder(str1).toString();
                str1 = new StringBuilder(str2).toString();
                str2 = str3;
            }

            int len1 = str1.length();
            int len2 = str2.length();

            ArrayList<Integer> div1 = DCommonDivisors.Maths.printDivisors(len1);
            ArrayList<Integer> div2 = DCommonDivisors.Maths.printDivisors(len2);

            HashSet<String> ans = new HashSet<>();
            for (Integer divisor : div1) {
                String str = str1.substring(0, divisor);
                int rep = len1 / str.length();

                boolean ok = true;
                outer:
                for (int i = 0; i < str.length(); i++) {
                    for (int j = 0; j < rep; j++) {
                        if (str1.charAt((j * str.length()) + i) != str1.charAt(i)) {
                            ok = false;
                            break outer;
                        }
                    }
                }

                if (ok) {
                    ans.add(str);
                }
            }

            HashSet<String> ans1 = new HashSet<>();
            for (Integer divisor : div2) {
                String str = str2.substring(0, divisor);
                int rep = len2 / str.length();

                boolean ok = true;
                outer:
                for (int i = 0; i < str.length(); i++) {
                    for (int j = 0; j < rep; j++) {
                        if (str2.charAt((j * str.length()) + i) != str2.charAt(i)) {
                            ok = false;
                            break outer;
                        }
                    }
                }

                if (ok) {
                    ans1.add(str);
                }
            }

            Iterator<String> iter = ans1.iterator();
            int ans2 = 0;
            while (iter.hasNext()) {
                String str = iter.next();
                if (ans.contains(str)) {
                    ans2++;
                }
            }
            out.println(ans2);
        }

        private static class Maths {
            static ArrayList<Integer> printDivisors(int n) {
                // Note that this loop runs till square root
                ArrayList<Integer> list = new ArrayList<>();
                for (int i = 1; i <= Math.sqrt(n); i++) {
                    if (n % i == 0) {
                        if (n / i == i) {
                            list.add(i);
                        } else {
                            list.add(i);
                            list.add(n / i);
                        }
                    }
                }
                Collections.sort(list);
                return list;
            }

        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(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 String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

