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.awt.event.MouseAdapter;
import java.io.*;
import java.util.*;

public class f
{
    public static void print(String str,int val){
        System.out.println(str+"  "+val);
    }

    public long gcd(long a, long b) {
        if (b==0L) return a;
        return gcd(b,a%b);
    }

    public static void debug(long[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(int[][] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(Arrays.toString(arr[i]));
        }
    }
    public static void debug(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.println(arr[i]);
        }
    }

    public static void print(int[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(String[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }
    public static void print(long[] arr){
        int len = arr.length;
        for(int i=0;i<len;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.print('\n');
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
        public FastReader(String path) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(path));
        }

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

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

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

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

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


    public static void main(String[] args)
    {
        FastReader s=new FastReader();
        String s1 = s.nextLine();
        String s2 = s.nextLine();
        int l1 = s1.length();
        int l2 = s2.length();
        //find divisors of l1
        ArrayList<Integer> divisors_1 = new ArrayList<>();
        for(int i=1;i<=Math.sqrt(l1);i++){
            if(l1%i==0){

                    divisors_1.add(i);
                    divisors_1.add((l1/i));

            }
        }
        ArrayList<Integer> divisors_2 = new ArrayList<>();
        for(int i=1;i<=Math.sqrt(l2);i++){
            if(l2%i==0){


                    divisors_2.add(i);
                    divisors_2.add(l2/i);

            }
        }
        //go through all divisors and chcek if it works
        TreeSet<String> set1 = new TreeSet<>();
        TreeSet<String> set2 = new TreeSet<>();

        for(int lenght:divisors_1){
            boolean isposs = true;
            String subs = s1.substring(0,lenght);
            for(int i=0;i+lenght-1<l1;i=i+lenght){
                if(!subs.equals(s1.substring(i,i+lenght))){
                    isposs = false;
                    break;
                }
            }
            if(isposs){
                set1.add(subs);
            }
        }

        for(int lenght:divisors_2){
            boolean isposs = true;
            String subs = s2.substring(0,lenght);
            for(int i=0;i+lenght-1<l2;i=i+lenght){
                if(!subs.equals(s2.substring(i,i+lenght))){
                    isposs = false;
                    break;
                }
            }
            if(isposs){
                set2.add(subs);
            }
        }
//        System.out.println(divisors_1);
//        System.out.println(divisors_2);
//        System.out.println(set1);
//        System.out.println(set2);


        set1.retainAll(set2);
        System.out.println(set1.size());
    }




//    OutputStream out = new BufferedOutputStream( System.out );
//        for(int i=1;i<n;i++){
//    out.write((arr[i]+" ").getBytes());
//}
//        out.flush();

    //  long start = System.currentTimeMillis();
//  long end = System.currentTimeMillis();
//  System.out.println((end - start) + "ms");



}
