#include <bits/stdc++.h>
using namespace std;
const int md = 481598279;
int p[1000001], w[1000001];
char c[100010], s[1000010];
int n, m;
int cx(int l, int r) {
  return ((w[r] - 1ll * w[l - 1] * p[r - l + 1]) % md + md) % md;
}
int pd(int u, int v) {
  int o0 = -1, o1 = -1;
  int z = 0;
  for (int i = 1; i <= n; i++)
    if (c[i] == '0') {
      if (o0 == -1)
        o0 = z;
      else if (cx(z + 1, z + u) != cx(o0 + 1, o0 + u))
        return 0;
      z += u;
    } else {
      if (o1 == -1)
        o1 = z;
      else if (cx(z + 1, z + v) != cx(o1 + 1, o1 + v))
        return 0;
      z += v;
    }
  return u != v || cx(o0 + 1, o0 + u) != cx(o1 + 1, o1 + v);
}
int main() {
  scanf("%s%s", c + 1, s + 1);
  n = strlen(c + 1), m = strlen(s + 1);
  for (int i = p[0] = 1; i <= m; i++)
    p[i] = 1ll * p[i - 1] * 10007 % md,
    w[i] = (1ll * w[i - 1] * 10007 + s[i]) % md;
  if (c[1] == '1')
    for (int i = 1; i <= n; i++) c[i] = 97 - c[i];
  int gs0 = 0, gs1 = 0;
  for (int i = 1; i <= n; i++)
    if (c[i] == '1')
      gs1++;
    else
      gs0++;
  int ans = 0;
  if (gs0 > gs1) {
    if (!gs1)
      ans = m % gs0 == 0 && cx(1, m - m / gs0) == cx(m / gs0 + 1, m);
    else
      for (int i = 1; i * gs0 < m; i++)
        if ((m - i * gs0) % gs1 == 0) ans += pd(i, (m - i * gs0) / gs1);
  } else {
    for (int i = 1; i * gs1 < m; i++)
      if ((m - i * gs1) % gs0 == 0) ans += pd((m - i * gs1) / gs0, i);
  }
  printf("%d\n", ans);
}

### Prompt

Please formulate 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 md = 481598279;
int p[1000001], w[1000001];
char c[100010], s[1000010];
int n, m;
int cx(int l, int r) {
  return ((w[r] - 1ll * w[l - 1] * p[r - l + 1]) % md + md) % md;
}
int pd(int u, int v) {
  int o0 = -1, o1 = -1;
  int z = 0;
  for (int i = 1; i <= n; i++)
    if (c[i] == '0') {
      if (o0 == -1)
        o0 = z;
      else if (cx(z + 1, z + u) != cx(o0 + 1, o0 + u))
        return 0;
      z += u;
    } else {
      if (o1 == -1)
        o1 = z;
      else if (cx(z + 1, z + v) != cx(o1 + 1, o1 + v))
        return 0;
      z += v;
    }
  return u != v || cx(o0 + 1, o0 + u) != cx(o1 + 1, o1 + v);
}
int main() {
  scanf("%s%s", c + 1, s + 1);
  n = strlen(c + 1), m = strlen(s + 1);
  for (int i = p[0] = 1; i <= m; i++)
    p[i] = 1ll * p[i - 1] * 10007 % md,
    w[i] = (1ll * w[i - 1] * 10007 + s[i]) % md;
  if (c[1] == '1')
    for (int i = 1; i <= n; i++) c[i] = 97 - c[i];
  int gs0 = 0, gs1 = 0;
  for (int i = 1; i <= n; i++)
    if (c[i] == '1')
      gs1++;
    else
      gs0++;
  int ans = 0;
  if (gs0 > gs1) {
    if (!gs1)
      ans = m % gs0 == 0 && cx(1, m - m / gs0) == cx(m / gs0 + 1, m);
    else
      for (int i = 1; i * gs0 < m; i++)
        if ((m - i * gs0) % gs1 == 0) ans += pd(i, (m - i * gs0) / gs1);
  } else {
    for (int i = 1; i * gs1 < m; i++)
      if ((m - i * gs1) % gs0 == 0) ans += pd((m - i * gs1) / gs0, i);
  }
  printf("%d\n", ans);
}

```