#include <bits/stdc++.h>
const long long MAX_N = 1e6 + 7;
const long long MODS[] = {1000000007, 1000000009};
const long long PRIME = 31;
std::vector<std::vector<long long>> pows(2, std::vector<long long>(MAX_N)),
    invs(2, std::vector<long long>(MAX_N));
inline long long fastpow(const long long& base, const long long& pow,
                         const long long& MOD) {
  long long res = 1;
  for (long long n = base, exp = pow; exp;) {
    if (exp & 1) {
      res = (res * n) % MOD;
      exp--;
    } else {
      n = (n * n) % MOD;
      exp /= 2;
    }
  }
  return res;
}
struct hashboi {
  const int n;
  std::vector<std::vector<long long>> pref;
  hashboi(const std::string& str)
      : n(str.length()), pref(2, std::vector<long long>(MAX_N)) {
    for (int p = 0; p < 2; ++p) {
      for (int i = 1; i <= n; ++i) {
        long long val = cval(str[i - 1]);
        val = (val * pows[p][i]) % MODS[p];
        pref[p][i] = (pref[p][i - 1] + val) % MODS[p];
      }
    }
  }
  inline long long cval(const char& c) { return c - 'a' + 1; }
  std::pair<long long, long long> get(const int& left, const int& right) {
    assert(left <= right && right < n && left >= 0);
    std::vector<long long> ret(2);
    for (int p = 0; p < 2; ++p) {
      ret[p] = (pref[p][right + 1] - pref[p][left]) % MODS[p];
      if (ret[p] < 0) ret[p] += MODS[p];
      ret[p] = (ret[p] * invs[p][left]) % MODS[p];
    }
    return std::pair<long long, long long>{ret.front(), ret.back()};
  }
};
void z_values(const std::string& s, long long* z) {
  const long long n = s.length();
  z[0] = n;
  long long L = 0, R = 0;
  std::vector<long long> left(n), right(n);
  for (long long i = 1; i < n; ++i) {
    if (i > R) {
      for (L = R = i; R < n && s[R - L] == s[R]; ++R)
        ;
      z[i] = R-- - L;
    } else {
      long long k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        for (L = i; R < n && s[R - L] == s[R]; ++R)
          ;
        z[i] = R-- - L;
      }
    }
    left[i] = L;
    right[i] = R;
  }
}
long long zval[MAX_N];
std::string s, t;
int main(void) {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  for (int p = 0; p < 2; ++p) {
    invs[p][0] = fastpow(pows[p][0] = 1, MODS[p] - 2, MODS[p]);
    for (int i = 1; i < MAX_N; ++i) {
      pows[p][i] = (pows[p][i - 1] * PRIME) % MODS[p];
      invs[p][i] = fastpow(pows[p][i], MODS[p] - 2, MODS[p]);
    }
  }
  std::cin >> s >> t;
  const long long n = t.length();
  const long long m = s.length();
  z_values(t, zval);
  if (s.front() == '1')
    for (auto& c : s) c = c == '1' ? '0' : '1';
  const long long num_zero = std::count(s.begin(), s.end(), '0');
  const long long num_one = m - num_zero;
  long long first_one = 0;
  for (; first_one < m && s[first_one] == '0'; ++first_one)
    ;
  assert(first_one < m);
  long long ans = 0;
  hashboi hashy(t);
  for (long long z_len = 1; z_len <= n; ++z_len) {
    const long long rem = n - num_zero * z_len;
    const long long o_len = rem / num_one;
    if (rem % num_one || o_len <= 0) continue;
    const std::pair<long long, long long> z_hash = hashy.get(0, z_len - 1);
    const std::pair<long long, long long> o_hash =
        hashy.get(first_one * z_len, first_one * z_len + o_len - 1);
    if (z_hash == o_hash) continue;
    bool good = true;
    for (long long i = 0, cur = 0; i < m; ++i) {
      if (s[i] == '0') {
        good = good && hashy.get(cur, cur + z_len - 1) == z_hash;
        cur += z_len;
      } else {
        good = good && hashy.get(cur, cur + o_len - 1) == o_hash;
        cur += o_len;
      }
    }
    ans += good;
  }
  std::cout << ans << "\n";
  return 0;
}

### Prompt

Create a solution in Cpp for 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>
const long long MAX_N = 1e6 + 7;
const long long MODS[] = {1000000007, 1000000009};
const long long PRIME = 31;
std::vector<std::vector<long long>> pows(2, std::vector<long long>(MAX_N)),
    invs(2, std::vector<long long>(MAX_N));
inline long long fastpow(const long long& base, const long long& pow,
                         const long long& MOD) {
  long long res = 1;
  for (long long n = base, exp = pow; exp;) {
    if (exp & 1) {
      res = (res * n) % MOD;
      exp--;
    } else {
      n = (n * n) % MOD;
      exp /= 2;
    }
  }
  return res;
}
struct hashboi {
  const int n;
  std::vector<std::vector<long long>> pref;
  hashboi(const std::string& str)
      : n(str.length()), pref(2, std::vector<long long>(MAX_N)) {
    for (int p = 0; p < 2; ++p) {
      for (int i = 1; i <= n; ++i) {
        long long val = cval(str[i - 1]);
        val = (val * pows[p][i]) % MODS[p];
        pref[p][i] = (pref[p][i - 1] + val) % MODS[p];
      }
    }
  }
  inline long long cval(const char& c) { return c - 'a' + 1; }
  std::pair<long long, long long> get(const int& left, const int& right) {
    assert(left <= right && right < n && left >= 0);
    std::vector<long long> ret(2);
    for (int p = 0; p < 2; ++p) {
      ret[p] = (pref[p][right + 1] - pref[p][left]) % MODS[p];
      if (ret[p] < 0) ret[p] += MODS[p];
      ret[p] = (ret[p] * invs[p][left]) % MODS[p];
    }
    return std::pair<long long, long long>{ret.front(), ret.back()};
  }
};
void z_values(const std::string& s, long long* z) {
  const long long n = s.length();
  z[0] = n;
  long long L = 0, R = 0;
  std::vector<long long> left(n), right(n);
  for (long long i = 1; i < n; ++i) {
    if (i > R) {
      for (L = R = i; R < n && s[R - L] == s[R]; ++R)
        ;
      z[i] = R-- - L;
    } else {
      long long k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        for (L = i; R < n && s[R - L] == s[R]; ++R)
          ;
        z[i] = R-- - L;
      }
    }
    left[i] = L;
    right[i] = R;
  }
}
long long zval[MAX_N];
std::string s, t;
int main(void) {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  for (int p = 0; p < 2; ++p) {
    invs[p][0] = fastpow(pows[p][0] = 1, MODS[p] - 2, MODS[p]);
    for (int i = 1; i < MAX_N; ++i) {
      pows[p][i] = (pows[p][i - 1] * PRIME) % MODS[p];
      invs[p][i] = fastpow(pows[p][i], MODS[p] - 2, MODS[p]);
    }
  }
  std::cin >> s >> t;
  const long long n = t.length();
  const long long m = s.length();
  z_values(t, zval);
  if (s.front() == '1')
    for (auto& c : s) c = c == '1' ? '0' : '1';
  const long long num_zero = std::count(s.begin(), s.end(), '0');
  const long long num_one = m - num_zero;
  long long first_one = 0;
  for (; first_one < m && s[first_one] == '0'; ++first_one)
    ;
  assert(first_one < m);
  long long ans = 0;
  hashboi hashy(t);
  for (long long z_len = 1; z_len <= n; ++z_len) {
    const long long rem = n - num_zero * z_len;
    const long long o_len = rem / num_one;
    if (rem % num_one || o_len <= 0) continue;
    const std::pair<long long, long long> z_hash = hashy.get(0, z_len - 1);
    const std::pair<long long, long long> o_hash =
        hashy.get(first_one * z_len, first_one * z_len + o_len - 1);
    if (z_hash == o_hash) continue;
    bool good = true;
    for (long long i = 0, cur = 0; i < m; ++i) {
      if (s[i] == '0') {
        good = good && hashy.get(cur, cur + z_len - 1) == z_hash;
        cur += z_len;
      } else {
        good = good && hashy.get(cur, cur + o_len - 1) == o_hash;
        cur += o_len;
      }
    }
    ans += good;
  }
  std::cout << ans << "\n";
  return 0;
}

```