#include <bits/stdc++.h>
using namespace std;
char s[2111111];
char t[2111111];
long long P = 257;
long long MOD1 = 1e9 + 7;
long long MOD2 = 1e9 + 9;
int n, m;
long long po1[2111111];
long long po2[2111111];
long long hash1[2111111];
long long hash2[2111111];
int c0, c1;
long long getHash(int start, int len) {
  long long ans1 =
      ((hash1[start + len] - hash1[start] * po1[len]) % MOD1 + MOD1) % MOD1;
  long long ans2 =
      ((hash2[start + len] - hash2[start] * po2[len]) % MOD2 + MOD2) % MOD2;
  return ans1 * MOD2 + ans2;
}
int main() {
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  m = strlen(t);
  po1[0] = po2[0] = 1;
  for (int i = 1; i <= m; i++) {
    po1[i] = po1[i - 1] * P % MOD1;
    po2[i] = po2[i - 1] * P % MOD2;
    hash1[i] = (hash1[i - 1] * P + t[i - 1] - 'a' + 1) % MOD1;
    hash2[i] = (hash2[i - 1] * P + t[i - 1] - 'a' + 1) % MOD2;
  }
  for (int i = 0; i < n; i++)
    if (s[i] == '0')
      c0++;
    else
      c1++;
  int ans = 0;
  if (c0 >= c1) {
    for (int l0 = 1; l0 <= m; l0++) {
      long long rem = m - 1ll * c0 * l0;
      if (rem <= 0 || rem % c1 != 0) continue;
      int l1 = rem / c1;
      long long last0 = -1;
      long long last1 = -1;
      int pos = 0;
      bool valid = true;
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
          long long cur = getHash(pos, l0);
          if (last0 == -1) last0 = cur;
          if (cur != last0) valid = false;
          pos += l0;
        } else {
          long long cur = getHash(pos, l1);
          if (last1 == -1) last1 = cur;
          if (cur != last1) valid = false;
          pos += l1;
        }
      }
      if (last0 == last1) valid = false;
      ans += valid;
    }
  } else {
    for (int l1 = 1; l1 <= m; l1++) {
      long long rem = m - 1ll * c1 * l1;
      if (rem <= 0 || rem % c0 != 0) continue;
      int l0 = rem / c0;
      long long last0 = -1;
      long long last1 = -1;
      int pos = 0;
      bool valid = true;
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
          long long cur = getHash(pos, l0);
          if (last0 == -1) last0 = cur;
          if (cur != last0) valid = false;
          pos += l0;
        } else {
          long long cur = getHash(pos, l1);
          if (last1 == -1) last1 = cur;
          if (cur != last1) valid = false;
          pos += l1;
        }
      }
      if (last0 == last1) valid = false;
      ans += valid;
    }
  }
  cout << ans << endl;
  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;
char s[2111111];
char t[2111111];
long long P = 257;
long long MOD1 = 1e9 + 7;
long long MOD2 = 1e9 + 9;
int n, m;
long long po1[2111111];
long long po2[2111111];
long long hash1[2111111];
long long hash2[2111111];
int c0, c1;
long long getHash(int start, int len) {
  long long ans1 =
      ((hash1[start + len] - hash1[start] * po1[len]) % MOD1 + MOD1) % MOD1;
  long long ans2 =
      ((hash2[start + len] - hash2[start] * po2[len]) % MOD2 + MOD2) % MOD2;
  return ans1 * MOD2 + ans2;
}
int main() {
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  m = strlen(t);
  po1[0] = po2[0] = 1;
  for (int i = 1; i <= m; i++) {
    po1[i] = po1[i - 1] * P % MOD1;
    po2[i] = po2[i - 1] * P % MOD2;
    hash1[i] = (hash1[i - 1] * P + t[i - 1] - 'a' + 1) % MOD1;
    hash2[i] = (hash2[i - 1] * P + t[i - 1] - 'a' + 1) % MOD2;
  }
  for (int i = 0; i < n; i++)
    if (s[i] == '0')
      c0++;
    else
      c1++;
  int ans = 0;
  if (c0 >= c1) {
    for (int l0 = 1; l0 <= m; l0++) {
      long long rem = m - 1ll * c0 * l0;
      if (rem <= 0 || rem % c1 != 0) continue;
      int l1 = rem / c1;
      long long last0 = -1;
      long long last1 = -1;
      int pos = 0;
      bool valid = true;
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
          long long cur = getHash(pos, l0);
          if (last0 == -1) last0 = cur;
          if (cur != last0) valid = false;
          pos += l0;
        } else {
          long long cur = getHash(pos, l1);
          if (last1 == -1) last1 = cur;
          if (cur != last1) valid = false;
          pos += l1;
        }
      }
      if (last0 == last1) valid = false;
      ans += valid;
    }
  } else {
    for (int l1 = 1; l1 <= m; l1++) {
      long long rem = m - 1ll * c1 * l1;
      if (rem <= 0 || rem % c0 != 0) continue;
      int l0 = rem / c0;
      long long last0 = -1;
      long long last1 = -1;
      int pos = 0;
      bool valid = true;
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
          long long cur = getHash(pos, l0);
          if (last0 == -1) last0 = cur;
          if (cur != last0) valid = false;
          pos += l0;
        } else {
          long long cur = getHash(pos, l1);
          if (last1 == -1) last1 = cur;
          if (cur != last1) valid = false;
          pos += l1;
        }
      }
      if (last0 == last1) valid = false;
      ans += valid;
    }
  }
  cout << ans << endl;
  return 0;
}

```