#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
int n, m, cnt[2], ans;
long long h1[N], h2[N], pw[N], pww[N], mod = 1e9 + 7, pr = 1000003, prr;
char a[N], b[N];
pair<int, int> get(int l, int r) {
  pair<int, int> h = {h1[r] - h1[l - 1], h2[r] - h2[l - 1]};
  if (h.first < 0) h.first += mod;
  if (h.second < 0) h.second += mod;
  h.first = (h.first * 1ll * pw[N - l]) % mod;
  h.second = (h.second * 1ll * pww[N - l]) % mod;
  return h;
}
int main() {
  for (int i = 1e8 + (rand() % 100);; i++) {
    int cnt = 0;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        cnt = 1;
        break;
      }
    }
    if (!cnt) {
      prr = i;
      break;
    }
  }
  pww[0] = prr;
  pw[0] = pr;
  for (int i = 1; i < N; i++) {
    pw[i] = (pw[i - 1] * 1ll * pr) % mod;
    pww[i] = (pww[i - 1] * 1ll * prr) % mod;
  }
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for (int i = 1; i <= m; i++) {
    h1[i] = (h1[i - 1] + pw[i] * 1ll * b[i]) % mod;
    h2[i] = (h2[i - 1] + pww[i] * 1ll * b[i]) % mod;
  }
  for (int i = 1; i <= n; i++) cnt[a[i] - '0']++;
  for (int i = 1; i <= m; i++) {
    long long a1 = i * 1ll * cnt[0], a2;
    if (a1 > m) break;
    a2 = (m - a1) / cnt[1];
    if ((m - a1) % cnt[1] == 0 && a2 > 0) {
      int f = i, s = a2;
      int pos = 1, ok = 1;
      pair<int, int> s0 = {-1, -1}, s1 = {-1, -1};
      for (int j = 1; j <= n; j++) {
        if (a[j] == '0') {
          if (s0.first == -1) {
            s0 = get(pos, pos + f - 1);
            pos += f;
          } else if (s0 == get(pos, pos + f - 1)) {
            pos += f;
          } else {
            ok = 0;
            break;
          }
        } else {
          if (s1.first == -1) {
            s1 = get(pos, pos + s - 1);
            pos += s;
          } else if (s1 == get(pos, pos + s - 1)) {
            pos += s;
          } else {
            ok = 0;
            break;
          }
        }
      }
      if (s1 != s0) ans += ok;
    }
  }
  cout << ans << endl;
}

### Prompt

Your task is to create 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 = 1e6 + 2;
int n, m, cnt[2], ans;
long long h1[N], h2[N], pw[N], pww[N], mod = 1e9 + 7, pr = 1000003, prr;
char a[N], b[N];
pair<int, int> get(int l, int r) {
  pair<int, int> h = {h1[r] - h1[l - 1], h2[r] - h2[l - 1]};
  if (h.first < 0) h.first += mod;
  if (h.second < 0) h.second += mod;
  h.first = (h.first * 1ll * pw[N - l]) % mod;
  h.second = (h.second * 1ll * pww[N - l]) % mod;
  return h;
}
int main() {
  for (int i = 1e8 + (rand() % 100);; i++) {
    int cnt = 0;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        cnt = 1;
        break;
      }
    }
    if (!cnt) {
      prr = i;
      break;
    }
  }
  pww[0] = prr;
  pw[0] = pr;
  for (int i = 1; i < N; i++) {
    pw[i] = (pw[i - 1] * 1ll * pr) % mod;
    pww[i] = (pww[i - 1] * 1ll * prr) % mod;
  }
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for (int i = 1; i <= m; i++) {
    h1[i] = (h1[i - 1] + pw[i] * 1ll * b[i]) % mod;
    h2[i] = (h2[i - 1] + pww[i] * 1ll * b[i]) % mod;
  }
  for (int i = 1; i <= n; i++) cnt[a[i] - '0']++;
  for (int i = 1; i <= m; i++) {
    long long a1 = i * 1ll * cnt[0], a2;
    if (a1 > m) break;
    a2 = (m - a1) / cnt[1];
    if ((m - a1) % cnt[1] == 0 && a2 > 0) {
      int f = i, s = a2;
      int pos = 1, ok = 1;
      pair<int, int> s0 = {-1, -1}, s1 = {-1, -1};
      for (int j = 1; j <= n; j++) {
        if (a[j] == '0') {
          if (s0.first == -1) {
            s0 = get(pos, pos + f - 1);
            pos += f;
          } else if (s0 == get(pos, pos + f - 1)) {
            pos += f;
          } else {
            ok = 0;
            break;
          }
        } else {
          if (s1.first == -1) {
            s1 = get(pos, pos + s - 1);
            pos += s;
          } else if (s1 == get(pos, pos + s - 1)) {
            pos += s;
          } else {
            ok = 0;
            break;
          }
        }
      }
      if (s1 != s0) ans += ok;
    }
  }
  cout << ans << endl;
}

```