#include <bits/stdc++.h>
using namespace std;
const int N = int(2e6) + 5;
const int inf = (int)1e9 + 7;
const int base = 253;
string s, t;
int pw[N], h[N];
int cnt0, cnt1;
int get(int l, int r) {
  return (h[r + 1] - (h[l] * 1ll * pw[r - l + 1] % inf) + inf) % inf;
}
int check(int l0, int l1) {
  int hsh1 = -1, hsh2 = -1;
  int st = 0;
  for (char i : s) {
    if (i == '0') {
      if (st + l0 - 1 >= (int)((t).size())) return 0;
      if (hsh1 == -1) hsh1 = get(st, st + l0 - 1);
      if (hsh1 != get(st, st + l0 - 1)) {
        return 0;
      }
      if (hsh1 == hsh2) return 0;
      st += l0;
    } else {
      if (st + l1 - 1 >= (int)((t).size())) return 0;
      if (hsh2 == -1) hsh2 = get(st, st + l1 - 1);
      if (hsh2 != get(st, st + l1 - 1)) {
        return 0;
      }
      if (hsh1 == hsh2) return 0;
      st += l1;
    }
  }
  return hsh1 != hsh2;
}
int main() {
  cin >> s >> t;
  for (char i : s) cnt0 += i == '0';
  cnt1 = (int)((s).size()) - cnt0;
  for (int i = 0; i <= (int)((t).size()); ++i) {
    pw[i] = (i == 0 ? 1 : pw[i - 1] * 1ll * base % inf);
    if (i != (int)((t).size())) {
      h[i + 1] = (h[i] * 1ll * base + t[i]) % inf;
    }
  }
  int ans = 0;
  for (int l0 = 1; l0 < (int)((t).size()); ++l0) {
    int rem = (int)((t).size()) - cnt0 * l0;
    if (rem <= 0 || rem % cnt1 != 0) {
      continue;
    }
    int l1 = rem / cnt1;
    if (check(l0, l1)) {
      ++ans;
    }
  }
  cout << 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 = int(2e6) + 5;
const int inf = (int)1e9 + 7;
const int base = 253;
string s, t;
int pw[N], h[N];
int cnt0, cnt1;
int get(int l, int r) {
  return (h[r + 1] - (h[l] * 1ll * pw[r - l + 1] % inf) + inf) % inf;
}
int check(int l0, int l1) {
  int hsh1 = -1, hsh2 = -1;
  int st = 0;
  for (char i : s) {
    if (i == '0') {
      if (st + l0 - 1 >= (int)((t).size())) return 0;
      if (hsh1 == -1) hsh1 = get(st, st + l0 - 1);
      if (hsh1 != get(st, st + l0 - 1)) {
        return 0;
      }
      if (hsh1 == hsh2) return 0;
      st += l0;
    } else {
      if (st + l1 - 1 >= (int)((t).size())) return 0;
      if (hsh2 == -1) hsh2 = get(st, st + l1 - 1);
      if (hsh2 != get(st, st + l1 - 1)) {
        return 0;
      }
      if (hsh1 == hsh2) return 0;
      st += l1;
    }
  }
  return hsh1 != hsh2;
}
int main() {
  cin >> s >> t;
  for (char i : s) cnt0 += i == '0';
  cnt1 = (int)((s).size()) - cnt0;
  for (int i = 0; i <= (int)((t).size()); ++i) {
    pw[i] = (i == 0 ? 1 : pw[i - 1] * 1ll * base % inf);
    if (i != (int)((t).size())) {
      h[i + 1] = (h[i] * 1ll * base + t[i]) % inf;
    }
  }
  int ans = 0;
  for (int l0 = 1; l0 < (int)((t).size()); ++l0) {
    int rem = (int)((t).size()) - cnt0 * l0;
    if (rem <= 0 || rem % cnt1 != 0) {
      continue;
    }
    int l1 = rem / cnt1;
    if (check(l0, l1)) {
      ++ans;
    }
  }
  cout << ans;
  return 0;
}

```