#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
inline int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int n, m, sz = 128;
int rk[N], sa[N], wr[N], bk[N], wx[N], he[N];
char cc[N];
inline bool cmp(int a, int b, int j) {
  return wr[a] == wr[b] && wr[a + j] == wr[b + j];
}
inline void gSA() {
  for (int i = 1; i <= n; ++i) ++bk[rk[i] = cc[i]];
  for (int i = 1; i <= sz; ++i) bk[i] += bk[i - 1];
  for (int i = n; i; --i) sa[bk[rk[i]]--] = i;
  int tp, j = 1, p = 0;
  while (p < n) {
    tp = 0;
    for (int i = n - j + 1; i <= n; ++i) wx[++tp] = i;
    for (int i = 1; i <= n; ++i)
      if (sa[i] > j) wx[++tp] = sa[i] - j;
    for (int i = 1; i <= n; ++i) wr[i] = rk[wx[i]];
    for (int i = 0; i <= sz; ++i) bk[i] = 0;
    for (int i = 1; i <= n; ++i) ++bk[wr[i]];
    for (int i = 1; i <= sz; ++i) bk[i] += bk[i - 1];
    for (int i = n; i; --i) sa[bk[wr[i]]--] = wx[i];
    for (int i = 1; i <= n; ++i) wr[i] = rk[i];
    rk[sa[1]] = p = 1;
    for (int i = 2; i <= n; ++i)
      rk[sa[i]] = p += (cmp(sa[i], sa[i - 1], j) ^ 1);
    sz = p, j <<= 1;
  }
  for (int i = 1; i <= n; ++i) {
    he[rk[i]] = he[rk[i - 1]] ? he[rk[i - 1]] - 1 : 0;
    j = sa[rk[i] - 1];
    while (cc[i + he[rk[i]]] == cc[j + he[rk[i]]]) ++he[rk[i]];
  }
}
int mi[N][21], hbt[N];
inline int gmi(int l, int r) {
  l = rk[l], r = rk[r];
  if (l > r) swap(l, r);
  ++l;
  if (l > r) return n + 2;
  int k = hbt[r - l + 1];
  return min(mi[l][k], mi[r - (1 << k) + 1][k]);
}
int n0, n1;
char ss[N];
int main() {
  scanf("%s", ss + 1), m = strlen(ss + 1);
  scanf("%s", cc + 1), n = strlen(cc + 1);
  gSA();
  hbt[0] = -1;
  for (int i = 1; i <= n; ++i)
    hbt[i] = hbt[i - 1] + ((i & (-i)) == i), mi[i][0] = he[i];
  for (int j = 1; j <= hbt[n]; ++j)
    for (int i = 1; i <= n - (1 << j) + 1; ++i)
      mi[i][j] = min(mi[i][j - 1], mi[i + (1 << (j - 1))][j - 1]);
  for (int i = 1; i <= m; ++i) n1 += ss[i] - '0';
  n0 = m - n1;
  int ans = 0;
  for (int i = 1; n - i * n0 >= n1; ++i) {
    if ((n - i * n0) % n1) continue;
    int j = (n - i * n0) / n1;
    bool ok = true;
    for (int k = 1, ii = 1, la0 = 0, la1 = 0; k <= m && ok; ++k) {
      if (ss[k] - '0' == 0) {
        if (la0) ok = gmi(ii, la0) >= i;
        la0 = ii, ii += i;
      } else {
        if (la1) ok = gmi(ii, la1) >= j;
        la1 = ii, ii += j;
      }
    }
    if (i == j) {
      bool no = true;
      for (int ii = 1 + i; ii <= n && no; ii += i) no = gmi(ii, ii - i) >= i;
      if (no) ok = false;
    }
    ans += ok;
  }
  printf("%d\n", ans);
  return 0;
}

### Prompt

Your challenge is to write a CPP solution to 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 N = 1000000 + 10;
inline int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int n, m, sz = 128;
int rk[N], sa[N], wr[N], bk[N], wx[N], he[N];
char cc[N];
inline bool cmp(int a, int b, int j) {
  return wr[a] == wr[b] && wr[a + j] == wr[b + j];
}
inline void gSA() {
  for (int i = 1; i <= n; ++i) ++bk[rk[i] = cc[i]];
  for (int i = 1; i <= sz; ++i) bk[i] += bk[i - 1];
  for (int i = n; i; --i) sa[bk[rk[i]]--] = i;
  int tp, j = 1, p = 0;
  while (p < n) {
    tp = 0;
    for (int i = n - j + 1; i <= n; ++i) wx[++tp] = i;
    for (int i = 1; i <= n; ++i)
      if (sa[i] > j) wx[++tp] = sa[i] - j;
    for (int i = 1; i <= n; ++i) wr[i] = rk[wx[i]];
    for (int i = 0; i <= sz; ++i) bk[i] = 0;
    for (int i = 1; i <= n; ++i) ++bk[wr[i]];
    for (int i = 1; i <= sz; ++i) bk[i] += bk[i - 1];
    for (int i = n; i; --i) sa[bk[wr[i]]--] = wx[i];
    for (int i = 1; i <= n; ++i) wr[i] = rk[i];
    rk[sa[1]] = p = 1;
    for (int i = 2; i <= n; ++i)
      rk[sa[i]] = p += (cmp(sa[i], sa[i - 1], j) ^ 1);
    sz = p, j <<= 1;
  }
  for (int i = 1; i <= n; ++i) {
    he[rk[i]] = he[rk[i - 1]] ? he[rk[i - 1]] - 1 : 0;
    j = sa[rk[i] - 1];
    while (cc[i + he[rk[i]]] == cc[j + he[rk[i]]]) ++he[rk[i]];
  }
}
int mi[N][21], hbt[N];
inline int gmi(int l, int r) {
  l = rk[l], r = rk[r];
  if (l > r) swap(l, r);
  ++l;
  if (l > r) return n + 2;
  int k = hbt[r - l + 1];
  return min(mi[l][k], mi[r - (1 << k) + 1][k]);
}
int n0, n1;
char ss[N];
int main() {
  scanf("%s", ss + 1), m = strlen(ss + 1);
  scanf("%s", cc + 1), n = strlen(cc + 1);
  gSA();
  hbt[0] = -1;
  for (int i = 1; i <= n; ++i)
    hbt[i] = hbt[i - 1] + ((i & (-i)) == i), mi[i][0] = he[i];
  for (int j = 1; j <= hbt[n]; ++j)
    for (int i = 1; i <= n - (1 << j) + 1; ++i)
      mi[i][j] = min(mi[i][j - 1], mi[i + (1 << (j - 1))][j - 1]);
  for (int i = 1; i <= m; ++i) n1 += ss[i] - '0';
  n0 = m - n1;
  int ans = 0;
  for (int i = 1; n - i * n0 >= n1; ++i) {
    if ((n - i * n0) % n1) continue;
    int j = (n - i * n0) / n1;
    bool ok = true;
    for (int k = 1, ii = 1, la0 = 0, la1 = 0; k <= m && ok; ++k) {
      if (ss[k] - '0' == 0) {
        if (la0) ok = gmi(ii, la0) >= i;
        la0 = ii, ii += i;
      } else {
        if (la1) ok = gmi(ii, la1) >= j;
        la1 = ii, ii += j;
      }
    }
    if (i == j) {
      bool no = true;
      for (int ii = 1 + i; ii <= n && no; ii += i) no = gmi(ii, ii - i) >= i;
      if (no) ok = false;
    }
    ans += ok;
  }
  printf("%d\n", ans);
  return 0;
}

```