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.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;

public class Solution {

    public static void main(String[] args) {
        try (PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
            _Scanner sc = new _Scanner(System.in);

            String s1 = sc.next();
            String s2 = sc.next();

            Stats stats1 = compute(s1);
            Stats stats2 = compute(s2);
//            System.out.println(String.format("stats1 = %s", stats1));
//            System.out.println(String.format("stats2 = %s", stats2));

//            stats1.factors.retainAll(stats2.factors);
            stats1.primeStrings.retainAll(stats2.primeStrings);

//            Map<Integer, Integer> cnts = cntPrimes(stats1.factors);
//
//            long ret = 0L;
//            for (String primeString : stats1.primeStrings) {
//                long total = 1L;
//                for (Entry<Integer, Integer> entry : cnts.entrySet()) {
//                    if (entry.getKey() == primeString.length()) {
//                        total *= entry.getValue();
//                    } else {
//                        total *= entry.getValue() + 1;
//                    }
//                }
//                ret += total;
//            }

            out.println(stats1.primeStrings.size());
        }
    }

    private static Map<Integer, Integer> cntPrimes(List<Integer> factors) {
        Map<Integer, Integer> cnts = new HashMap<>();
        for (Integer factor : factors) {
            Integer cnt = cnts.getOrDefault(factor, 0);
            cnts.put(factor, cnt + 1);
        }
        return cnts;
    }

    private static Stats compute(String s) {
        int len = s.length();
        char[] cs = s.toCharArray();

        List<Integer> factors = factor(len);
        Set<String> primeStrings = new HashSet<>();
        nextFactor:
        for (Integer factor : makeFactors(factors)) {
            for (int i = 0; i < cs.length; i += factor) {
                for (int j = 0; j < factor; j++) {
                    if (cs[j] != cs[i + j]) continue nextFactor;
                }
            }

            primeStrings.add(new String(cs, 0, factor));
        }

        boolean simple = true;
        for (int i = 1; i < cs.length; i++) {
            if (cs[i] != cs[0]) {
                simple = false;
                break;
            } 
        }

        return new Stats(simple, primeStrings, factors);
    }

    private static List<Integer> makeFactors(List<Integer> primes) {
        Map<Integer, Integer> cnts = cntPrimes(primes);
        ArrayList<Entry<Integer, Integer>> entries = new ArrayList<>(cnts.entrySet());

        List<Integer> ret = new ArrayList<>();
        doit(0, 1, entries, ret);
        return ret;
    }

    private static void doit(int i, int val, ArrayList<Entry<Integer, Integer>> cnts, List<Integer> ret) {
        if (i == cnts.size()) {
            ret.add(val);
            return;
        }

        Entry<Integer, Integer> cur = cnts.get(i);
        for (int j = 0; j <= cur.getValue(); j++) {
            doit(i+1, (int) (val * Math.pow(cur.getKey(), j)), cnts, ret);
        }
    }

    private static class Stats {

        private final boolean simple;
        private final Set<String> primeStrings;
        private final List<Integer> factors;

        public Stats(boolean simple, Set<String> primeStrings, List<Integer> factors) {
            this.simple = simple;
            this.primeStrings = primeStrings;
            this.factors = factors;
        }

        @Override
        public String toString() {
            return "Stats{" +
                    "simple=" + simple +
                    ", primeStrings=" + primeStrings +
                    ", factors=" + factors +
                    '}';
        }
    }

    private static List<Integer> factor(int v) {
        List<Integer> primes = new ArrayList<>();
        for (int i = 2; i * i <= v; i++) {
            while (v % i == 0) {
                primes.add(i);
                v /= i;
            }
        }
        if (v > 1) primes.add(v);
        return primes;
    }

    private static void reverse(int[] vs) {
        for (int i = 0; i < vs.length / 2; i++) {
            swap(vs, i, vs.length - 1 - i);
        }
    }

    static class _Scanner {
        InputStream is;
        _Scanner(InputStream is) {
            this.is = is;
        }
        byte[] bb = new byte[1 << 15];
        int k, l;
        byte getc() {
            try {
                if (k >= l) {
                    k = 0;
                    l = is.read(bb);
                    if (l < 0) return -1;
                }
                return bb[k++];
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        byte skip() {
            byte b;
            while ((b = getc()) <= 32)
                ;
            return b;
        }

        int nextInt() {
            int n = 0;
            int sig = 1;
            for (byte b = skip(); b > 32; b = getc()) {
                if (b == '-') {
                    sig = -1;
                } else {
                    n = n * 10 + b - '0';
                }
            }
            return sig * n;
        }

        long nextLong() {
            long n = 0;
            long sig = 1;
            for (byte b = skip(); b > 32; b = getc()) {
                if (b == '-') {
                    sig = -1;
                } else {
                    n = n * 10 + b - '0';
                }
            }
            return sig * n;
        }

        public String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); b > 32; b = getc()) {
                sb.append(((char) b));
            }
            return sb.toString();
        }
    }

    private static void shuffle(int[] ar) {
        Random rnd = new Random();
        for (int i = 0; i < ar.length; i++) {
            int j = i + rnd.nextInt(ar.length - i);
            swap(ar, i, j);
        }
    }

    private static void shuffle(Object[] ar) {
        Random rnd = new Random();
        for (int i = 0; i < ar.length; i++) {
            int j = i + rnd.nextInt(ar.length - i);
            swap(ar, i, j);
        }
    }

    private static void swap(int[] ar, int i, int j) {
        int t = ar[i];
        ar[i] = ar[j];
        ar[j] = t;
    }

    private static void swap(Object[] ar, int i, int j) {
        Object t = ar[i];
        ar[i] = ar[j];
        ar[j] = t;
    }

}
