#include <bits/stdc++.h>
using namespace std;
long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long mod = 1e9 + 7;
const long long N = 300050;
long long power(long long a, long long b, long long m = 1000000007LL) {
  long long ans = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) {
      ans = (1LL * a * ans) % m;
    }
    b >>= 1LL;
    a = (1LL * a * a) % m;
  }
  return ans;
}
void solve() {
  string s, t;
  cin >> s >> t;
  long long zero = 0, one = 0;
  for (long long i = 0; i < s.size(); i++) {
    zero += (s[i] == '0');
    one += (s[i] == '1');
  }
  const long long p = 31;
  const long long m1 = 1000000123;
  const long long m2 = 1000000321;
  long long h_val1 = 0, h_val2 = 0, n = t.size();
  long long p_pow1[n], p_pow2[n];
  long long hash_value1[n], hash_value2[n];
  p_pow1[0] = 1, p_pow2[0] = 1;
  for (long long i = 1; i < n; i++) {
    p_pow1[i] = (p_pow1[i - 1] * p) % m1;
    p_pow2[i] = (p_pow2[i - 1] * p) % m2;
  }
  for (long long i = 0; i < n; i++) {
    h_val1 = (h_val1 + (t[i] - 'a' + 1) * p_pow1[i]) % m1;
    h_val2 = (h_val2 + (t[i] - 'a' + 1) * p_pow2[i]) % m2;
    hash_value1[i] = h_val1;
    hash_value2[i] = h_val2;
  }
  function<pair<long long, long long>(long long, long long)> find_hash =
      [&](long long l, long long r) {
        long long x = (l ? hash_value1[l - 1] : 0LL);
        long long y = hash_value1[r];
        long long val1 = (y - x) % m1;
        val1 = (val1 + m1) % m1;
        val1 = (val1 * power(p_pow1[l], m1 - 2, m1)) % m1;
        x = (l ? hash_value2[l - 1] : 0LL);
        y = hash_value2[r];
        long long val2 = (y - x) % m2;
        val2 = (val2 + m2) % m2;
        val2 = (val2 * power(p_pow2[l], m2 - 2, m2)) % m2;
        pair<long long, long long> ret = {val1, val2};
        return ret;
      };
  long long ans = 0;
  for (long long r0 = 1; r0 <= n; r0++) {
    long long r1 = (n - r0 * zero);
    if (r1 % one || r1 <= 0) continue;
    r1 /= one;
    long long idx = 0;
    set<pair<long long, long long> > vec0, vec1;
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == '0') {
        auto temp = find_hash(idx, idx + r0 - 1);
        vec0.insert(temp);
        idx += r0;
      } else {
        auto temp = find_hash(idx, idx + r1 - 1);
        vec1.insert(temp);
        idx += r1;
      }
    }
    if ((long long)vec0.size() == 1 && (long long)vec1.size() == 1 &&
        *(vec0.begin()) != *(vec1.begin())) {
      ans++;
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long test = 1;
  while (test--) {
    solve();
  }
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

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;
long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long mod = 1e9 + 7;
const long long N = 300050;
long long power(long long a, long long b, long long m = 1000000007LL) {
  long long ans = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) {
      ans = (1LL * a * ans) % m;
    }
    b >>= 1LL;
    a = (1LL * a * a) % m;
  }
  return ans;
}
void solve() {
  string s, t;
  cin >> s >> t;
  long long zero = 0, one = 0;
  for (long long i = 0; i < s.size(); i++) {
    zero += (s[i] == '0');
    one += (s[i] == '1');
  }
  const long long p = 31;
  const long long m1 = 1000000123;
  const long long m2 = 1000000321;
  long long h_val1 = 0, h_val2 = 0, n = t.size();
  long long p_pow1[n], p_pow2[n];
  long long hash_value1[n], hash_value2[n];
  p_pow1[0] = 1, p_pow2[0] = 1;
  for (long long i = 1; i < n; i++) {
    p_pow1[i] = (p_pow1[i - 1] * p) % m1;
    p_pow2[i] = (p_pow2[i - 1] * p) % m2;
  }
  for (long long i = 0; i < n; i++) {
    h_val1 = (h_val1 + (t[i] - 'a' + 1) * p_pow1[i]) % m1;
    h_val2 = (h_val2 + (t[i] - 'a' + 1) * p_pow2[i]) % m2;
    hash_value1[i] = h_val1;
    hash_value2[i] = h_val2;
  }
  function<pair<long long, long long>(long long, long long)> find_hash =
      [&](long long l, long long r) {
        long long x = (l ? hash_value1[l - 1] : 0LL);
        long long y = hash_value1[r];
        long long val1 = (y - x) % m1;
        val1 = (val1 + m1) % m1;
        val1 = (val1 * power(p_pow1[l], m1 - 2, m1)) % m1;
        x = (l ? hash_value2[l - 1] : 0LL);
        y = hash_value2[r];
        long long val2 = (y - x) % m2;
        val2 = (val2 + m2) % m2;
        val2 = (val2 * power(p_pow2[l], m2 - 2, m2)) % m2;
        pair<long long, long long> ret = {val1, val2};
        return ret;
      };
  long long ans = 0;
  for (long long r0 = 1; r0 <= n; r0++) {
    long long r1 = (n - r0 * zero);
    if (r1 % one || r1 <= 0) continue;
    r1 /= one;
    long long idx = 0;
    set<pair<long long, long long> > vec0, vec1;
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == '0') {
        auto temp = find_hash(idx, idx + r0 - 1);
        vec0.insert(temp);
        idx += r0;
      } else {
        auto temp = find_hash(idx, idx + r1 - 1);
        vec1.insert(temp);
        idx += r1;
      }
    }
    if ((long long)vec0.size() == 1 && (long long)vec1.size() == 1 &&
        *(vec0.begin()) != *(vec1.begin())) {
      ans++;
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long test = 1;
  while (test--) {
    solve();
  }
  return 0;
}

```