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.*;
import java.lang.*;
import java.util.*;
import java.math.*;
 
public class code
{
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        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; 
        } 
    } 
 
     static class FastWriter
    {
        OutputStream os;
 
        public FastWriter()
        {
            os = new BufferedOutputStream(System.out);
        }
 
        void println(String content)throws IOException
        {
            print(content);
            print("\n");
        }
 
        void print(String content)throws IOException
        {
            os.write(content.getBytes());
        }
 
        void flush()throws IOException
        {
            os.flush();
        }
    }
    
    static long P = 1000000007L;
    public static void main(String args[])throws IOException
    {
        FastReader scn = new FastReader();
        
        String a = scn.nextLine();
        String b = scn.nextLine();

        int a_length = a.length();
        int b_length = b.length();

        int gcd = gcd(a_length, b_length);

        ArrayList<Integer> possible = new ArrayList<Integer>();
        for(int i = 1; i <= Math.sqrt(gcd) + 1; i++)
        {
            if(gcd%i != 0)
                continue;

            int factor1 = i;
            int factor2 = gcd/i;

            if(factor1 < factor2)
            {
                possible.add(factor1);
                possible.add(factor2);
            }
            else if(factor1 == factor2)
            {
                possible.add(factor1);
            }
            else break;
        }
        Collections.sort(possible, Collections.reverseOrder());

        int count = 0;
        for(int possible_length: possible)
        {
            String candidate = a.substring(0, possible_length);

            if(a_length < b_length)
            {
                boolean satisfied = true;
                for(int i = 0; (i < a_length) && satisfied; i++)
                {
                    if(a.charAt(i) != candidate.charAt(i%possible_length))
                        satisfied = false;
                }

                for(int i = 0; (i < b_length)&&satisfied; i++)
                {
                    if(b.charAt(i) != candidate.charAt(i%possible_length))
                        satisfied = false;
                }

                if(satisfied)
                    count++;
            }
            else
            {
                boolean satisfied = true;
                for(int i = 0; (i < b_length) && satisfied; i++)
                {
                    if(b.charAt(i) != candidate.charAt(i%possible_length))
                        satisfied = false;
                }

                for(int i = 0; (i < a_length)&&satisfied; i++)
                {
                    if(a.charAt(i) != candidate.charAt(i%possible_length))
                        satisfied = false;
                }

                if(satisfied)
                    count++;
            }       
        }
        System.out.println(count);
    }
 
    public static int gcd(int a, int b)
    {
        if(a==0 || a==b)
            return b;
        if(b==0)
            return a;

        if(a > b)
            return gcd(b, a%b);
        else
            return gcd(a, b%a);
    }
 
    // public static long dfs(Node current, int l, int r, Node[] nodes)
    // {
    //     current.visited = true;
        
    //     long ans = 1;
    //     for(Node next: current.neighbors)
    //     {
    //         if(!next.visited && next.sorted_index <= r && next.sorted_index >= l)
    //         {
    //             long p = dfs(next, l, r, nodes);
    //             ans = (ans * ( p + 1))%P;
    //         }
    //     }
 
    //     current.visited = false;
    //     return ans;
    // }
}
 
class Pair
{
    int a, b;
    public Pair(int a, int b)
    {
        this.a = a;
        this.b = b;
    }
}
 
// class Node implements Comparable<Node>
// {
//     int weight;
//     int sorted_index;
//     ArrayList<Node> neighbors;
//     boolean visited;
//     public Node()
//     {
//         neighbors = new ArrayList<>();
//     }
 
//     public int compareTo(Node n)
//     {
//         return this.weight - n.weight;
//     }
 
// }
 
// class MutableInt
// {
//     int count;
//     ArrayList<Integer> list;
//     public MutableInt()
//     {
//         list = new ArrayList<>();
//     }
// }
 
// class TrieNode
// {
//     HashMap<Character, TrieNode> map;
//     boolean visited;
//     int cost;
 
//     public TrieNode()
//     {
//         map = new HashMap<>();
//     }
 
//     public TrieNode add(char c, boolean isGood, MutableInt result, int k)
//     {
//         if(map.containsKey(c))
//         {
//             TrieNode n = map.get(c);
//             return n;
//         }
//         else
//         {
//             TrieNode n = new TrieNode();
//             if(!isGood)
//                 n.cost = this.cost + 1;
//             else
//                 n.cost = this.cost;
 
//             if(n.cost <= k)
//                 result.count = result.count + 1;
 
//             map.put(c, n);
//             return n;
//         }
//     }
// }