#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000500;
template <long long MOD>
long long norm(long long x) {
  x %= MOD;
  if (x < 0) {
    x += MOD;
  }
  return x;
}
const long long M1 = static_cast<long long>(1000002637);
const long long M2 = static_cast<long long>(1000002649);
struct hs {
  long long l;
  long long r;
  hs(long long cl, long long cr) : l(norm<M1>(cl)), r(norm<M2>(cr)) {}
  hs(long long x = 0) : l(x), r(x) {}
  hs operator+(const hs& rhs) const { return {l + rhs.l, r + rhs.r}; }
  hs operator*(const hs& rhs) const { return {l * rhs.l, r * rhs.r}; }
  hs operator-(const hs& rhs) const { return {l - rhs.l, r - rhs.r}; }
  bool operator!=(const hs& rhs) const { return l != rhs.l || r != rhs.r; }
};
hs h[maxn], pw[maxn];
hs ba = 56;
hs getSub(int l, int r) { return pw[l] * (h[r] - h[l]); }
char s[maxn], t[maxn];
int main() {
  pw[0] = 1;
  scanf("%s%s", s, t);
  int n = strlen(s), m = strlen(t);
  for (int i = 0; i < (int)(m + 1); ++i) pw[i + 1] = pw[i] * ba;
  for (int i = 0; i < (int)(m); ++i)
    h[i + 1] = h[i] + pw[m - i] * (t[i] - 'a' + 1);
  int c0 = 0;
  for (int i = 0; i < (int)(n); ++i) c0 += s[i] == '0';
  int c1 = n - c0;
  int ret = 0;
  hs s1, s2;
  for (int l0 = 1; l0 * c0 < m; l0++) {
    int l1 = (m - l0 * c0) / c1;
    if (l1 * c1 + l0 * c0 != m) continue;
    int si = 0;
    bool f = 1;
    bool f1 = 0, f2 = 0;
    for (int i = 0; i < (int)(n); ++i) {
      if (s[i] == '0') {
        hs hsv = getSub(si, si + l0);
        si += l0;
        if (!f1)
          f1 = 1, s1 = hsv;
        else {
          if (s1 != hsv) f = 0;
        }
      } else {
        hs hsv = getSub(si, si + l1);
        si += l1;
        if (!f2)
          f2 = 1, s2 = hsv;
        else {
          if (s2 != hsv) f = 0;
        }
      }
    }
    if (l0 == l1 && !(s1 != s2)) f = 0;
    ret += f;
  }
  printf("%d\n", ret);
}

### 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>
using namespace std;
const int maxn = 2000500;
template <long long MOD>
long long norm(long long x) {
  x %= MOD;
  if (x < 0) {
    x += MOD;
  }
  return x;
}
const long long M1 = static_cast<long long>(1000002637);
const long long M2 = static_cast<long long>(1000002649);
struct hs {
  long long l;
  long long r;
  hs(long long cl, long long cr) : l(norm<M1>(cl)), r(norm<M2>(cr)) {}
  hs(long long x = 0) : l(x), r(x) {}
  hs operator+(const hs& rhs) const { return {l + rhs.l, r + rhs.r}; }
  hs operator*(const hs& rhs) const { return {l * rhs.l, r * rhs.r}; }
  hs operator-(const hs& rhs) const { return {l - rhs.l, r - rhs.r}; }
  bool operator!=(const hs& rhs) const { return l != rhs.l || r != rhs.r; }
};
hs h[maxn], pw[maxn];
hs ba = 56;
hs getSub(int l, int r) { return pw[l] * (h[r] - h[l]); }
char s[maxn], t[maxn];
int main() {
  pw[0] = 1;
  scanf("%s%s", s, t);
  int n = strlen(s), m = strlen(t);
  for (int i = 0; i < (int)(m + 1); ++i) pw[i + 1] = pw[i] * ba;
  for (int i = 0; i < (int)(m); ++i)
    h[i + 1] = h[i] + pw[m - i] * (t[i] - 'a' + 1);
  int c0 = 0;
  for (int i = 0; i < (int)(n); ++i) c0 += s[i] == '0';
  int c1 = n - c0;
  int ret = 0;
  hs s1, s2;
  for (int l0 = 1; l0 * c0 < m; l0++) {
    int l1 = (m - l0 * c0) / c1;
    if (l1 * c1 + l0 * c0 != m) continue;
    int si = 0;
    bool f = 1;
    bool f1 = 0, f2 = 0;
    for (int i = 0; i < (int)(n); ++i) {
      if (s[i] == '0') {
        hs hsv = getSub(si, si + l0);
        si += l0;
        if (!f1)
          f1 = 1, s1 = hsv;
        else {
          if (s1 != hsv) f = 0;
        }
      } else {
        hs hsv = getSub(si, si + l1);
        si += l1;
        if (!f2)
          f2 = 1, s2 = hsv;
        else {
          if (s2 != hsv) f = 0;
        }
      }
    }
    if (l0 == l1 && !(s1 != s2)) f = 0;
    ret += f;
  }
  printf("%d\n", ret);
}

```