#include <bits/stdc++.h>
using namespace std;
struct hashed_str {
  long long n;
  vector<long long> hs;
  vector<long long> pows;
  long long p = 61;
  long long mod = 1e9 + 7;
  hashed_str(string &s) {
    n = s.size();
    long long n1 = (int)s.size();
    pows = {1};
    for (int i = 1; i < n; i++) {
      pows.push_back((pows.back() * p) % mod);
    }
    hs.resize(n1);
    hs[0] = (long long)((s[0] - 'a') + 1);
    for (int i = 1; i < n1; i++) {
      hs[i] =
          (hs[i - 1] % mod + (pows[i] * (long long)(s[i] - 'a' + 1ll)) % mod) %
          mod;
    }
  }
  long long get(long long l, long long r) {
    if (l > r) {
      return 0;
    }
    long long a = (l ? hs[l - 1] : 0);
    long long b = hs[r];
    long long s = (b - a + mod) % mod;
    return (s * pows[n - l - 1]) % mod;
  }
};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  string t;
  string s;
  cin >> s >> t;
  long long n = t.size();
  hashed_str hs(t);
  long long cnt_0 = 0, cnt_1 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      cnt_0++;
    } else {
      cnt_1++;
    }
  }
  char aa = '0';
  char bb = '1';
  long long a = cnt_0;
  long long b = cnt_1;
  if (s[0] == '1') {
    swap(a, b);
    swap(aa, bb);
  }
  if (b == 0) {
    if (n % a != 0) {
      cout << 0;
      return 0;
    }
    long long len_a = n / a;
    long long hash_a = hs.get(0, len_a - 1);
    long long hash_b = -1;
    long long ptr = len_a;
    bool ok = 1;
    for (int i = 1; i < s.size(); i++) {
      long long cur_h = hs.get(ptr, ptr + len_a - 1);
      if (cur_h != hash_a) {
        ok = 0;
        break;
      }
      ptr += len_a;
    }
    cout << ok;
    return 0;
  }
  long long answ = 0;
  for (int i = 0; i < t.size(); i++) {
    long long len_a = i + 1;
    if ((n - len_a * a) % b != 0 || n - len_a * a <= 0) {
      continue;
    }
    long long len_b = (n - len_a * a) / b;
    long long hash_a = hs.get(0, len_a - 1);
    long long hash_b = -1;
    long long ptr = len_a;
    bool ok = 1;
    for (int j = 1; j < s.size(); j++) {
      if (s[j] == aa) {
        long long cur_h = hs.get(ptr, ptr + len_a - 1);
        if (cur_h != hash_a) {
          ok = 0;
          break;
        }
        ptr += len_a;
      } else {
        long long cur_h = hs.get(ptr, ptr + len_b - 1);
        if (hash_b == -1) {
          hash_b = cur_h;
        }
        if (cur_h != hash_b) {
          ok = 0;
          break;
        }
        ptr += len_b;
      }
    }
    if (hash_a == hash_b) {
      ok = 0;
    }
    answ += ok;
  }
  cout << answ;
}

### Prompt

In Cpp, your task is to solve the following problem:

One of Arkady's friends works at a huge radio telescope. A few decades ago the telescope has sent a signal s towards a faraway galaxy. Recently they've received a response t which they believe to be a response from aliens! The scientists now want to check if the signal t is similar to s.

The original signal s was a sequence of zeros and ones (everyone knows that binary code is the universe-wide language). The returned signal t, however, does not look as easy as s, but the scientists don't give up! They represented t as a sequence of English letters and say that t is similar to s if you can replace all zeros in s with some string r_0 and all ones in s with some other string r_1 and obtain t. The strings r_0 and r_1 must be different and non-empty.

Please help Arkady's friend and find the number of possible replacements for zeros and ones (the number of pairs of strings r_0 and r_1) that transform s to t.

Input

The first line contains a string s (2 ≤ |s| ≤ 10^5) consisting of zeros and ones — the original signal.

The second line contains a string t (1 ≤ |t| ≤ 10^6) consisting of lowercase English letters only — the received signal.

It is guaranteed, that the string s contains at least one '0' and at least one '1'.

Output

Print a single integer — the number of pairs of strings r_0 and r_1 that transform s to t.

In case there are no such pairs, print 0.

Examples

Input


01
aaaaaa


Output


4


Input


001
kokokokotlin


Output


2

Note

In the first example, the possible pairs (r_0, r_1) are as follows:

  * "a", "aaaaa" 
  * "aa", "aaaa" 
  * "aaaa", "aa" 
  * "aaaaa", "a" 



The pair "aaa", "aaa" is not allowed, since r_0 and r_1 must be different.

In the second example, the following pairs are possible: 

  * "ko", "kokotlin" 
  * "koko", "tlin" 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct hashed_str {
  long long n;
  vector<long long> hs;
  vector<long long> pows;
  long long p = 61;
  long long mod = 1e9 + 7;
  hashed_str(string &s) {
    n = s.size();
    long long n1 = (int)s.size();
    pows = {1};
    for (int i = 1; i < n; i++) {
      pows.push_back((pows.back() * p) % mod);
    }
    hs.resize(n1);
    hs[0] = (long long)((s[0] - 'a') + 1);
    for (int i = 1; i < n1; i++) {
      hs[i] =
          (hs[i - 1] % mod + (pows[i] * (long long)(s[i] - 'a' + 1ll)) % mod) %
          mod;
    }
  }
  long long get(long long l, long long r) {
    if (l > r) {
      return 0;
    }
    long long a = (l ? hs[l - 1] : 0);
    long long b = hs[r];
    long long s = (b - a + mod) % mod;
    return (s * pows[n - l - 1]) % mod;
  }
};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  string t;
  string s;
  cin >> s >> t;
  long long n = t.size();
  hashed_str hs(t);
  long long cnt_0 = 0, cnt_1 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      cnt_0++;
    } else {
      cnt_1++;
    }
  }
  char aa = '0';
  char bb = '1';
  long long a = cnt_0;
  long long b = cnt_1;
  if (s[0] == '1') {
    swap(a, b);
    swap(aa, bb);
  }
  if (b == 0) {
    if (n % a != 0) {
      cout << 0;
      return 0;
    }
    long long len_a = n / a;
    long long hash_a = hs.get(0, len_a - 1);
    long long hash_b = -1;
    long long ptr = len_a;
    bool ok = 1;
    for (int i = 1; i < s.size(); i++) {
      long long cur_h = hs.get(ptr, ptr + len_a - 1);
      if (cur_h != hash_a) {
        ok = 0;
        break;
      }
      ptr += len_a;
    }
    cout << ok;
    return 0;
  }
  long long answ = 0;
  for (int i = 0; i < t.size(); i++) {
    long long len_a = i + 1;
    if ((n - len_a * a) % b != 0 || n - len_a * a <= 0) {
      continue;
    }
    long long len_b = (n - len_a * a) / b;
    long long hash_a = hs.get(0, len_a - 1);
    long long hash_b = -1;
    long long ptr = len_a;
    bool ok = 1;
    for (int j = 1; j < s.size(); j++) {
      if (s[j] == aa) {
        long long cur_h = hs.get(ptr, ptr + len_a - 1);
        if (cur_h != hash_a) {
          ok = 0;
          break;
        }
        ptr += len_a;
      } else {
        long long cur_h = hs.get(ptr, ptr + len_b - 1);
        if (hash_b == -1) {
          hash_b = cur_h;
        }
        if (cur_h != hash_b) {
          ok = 0;
          break;
        }
        ptr += len_b;
      }
    }
    if (hash_a == hash_b) {
      ok = 0;
    }
    answ += ok;
  }
  cout << answ;
}

```