#include <bits/stdc++.h>
using namespace std;
long long mod = 1005241043;
char s[100005], t[1000005];
long long cum[1000005] = {}, po = 1;
long long fpo(long long x, long long y) {
  if (y == 0)
    return 1;
  else {
    long long tem = fpo(x, y / 2);
    if (y % 2 == 0)
      return (tem * tem) % mod;
    else
      return (((tem * tem) % mod) * x) % mod;
  }
}
int main() {
  scanf("%s%s", &s, &t);
  int n0 = 0, n1 = 0, nt = 0;
  for (int i = 0; s[i] != '\0'; i++) {
    if (s[i] == '0')
      n0++;
    else
      n1++;
  }
  for (nt = 0; t[nt] != '\0'; nt++)
    ;
  for (int i = 0; i < nt; i++) {
    long long x = t[i] - 'a';
    x++;
    cum[i + 1] = (cum[i] + (x * po) % mod) % mod;
    po = (po * 31) % mod;
  }
  int ans = 0;
  for (int j = 1; j < nt; j++) {
    int r0 = j, rem = nt - r0 * n0, r1;
    if (rem <= 0)
      break;
    else if (rem % n1 == 0) {
      bool f = true;
      r1 = rem / n1;
      int curr = 0;
      long long sr0 = -1, sr1 = -1;
      int pos0 = -1, pos1 = -1;
      for (int i = 0; s[i] != '\0'; i++) {
        if (s[i] == '0') {
          if (sr0 != -1) {
            long long tem = (mod + cum[curr + r0] - cum[curr]) % mod;
            long long tem2 = (sr0 * fpo(31, curr - pos0)) % mod;
            if (tem != tem2) {
              f = false;
              break;
            }
            curr += r0;
          } else {
            sr0 = (mod + cum[curr + r0] - cum[curr]) % mod;
            pos0 = curr;
            curr += r0;
          }
        } else {
          if (sr1 != -1) {
            long long tem = (mod + cum[curr + r1] - cum[curr]) % mod;
            long long tem2 = (sr1 * fpo(31, curr - pos1)) % mod;
            if (tem != tem2) {
              f = false;
              break;
            }
            curr += r1;
          } else {
            sr1 = (mod + cum[curr + r1] - cum[curr]) % mod;
            pos1 = curr;
            curr += r1;
          }
        }
      }
      long long tem0 = (sr0 * fpo(31, pos1)) % mod,
                tem1 = (sr1 * fpo(31, pos0)) % mod;
      if (tem0 == tem1) {
        f = false;
      }
      if (f) {
        ans++;
      }
    }
  }
  printf("%i\n", ans);
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

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;
long long mod = 1005241043;
char s[100005], t[1000005];
long long cum[1000005] = {}, po = 1;
long long fpo(long long x, long long y) {
  if (y == 0)
    return 1;
  else {
    long long tem = fpo(x, y / 2);
    if (y % 2 == 0)
      return (tem * tem) % mod;
    else
      return (((tem * tem) % mod) * x) % mod;
  }
}
int main() {
  scanf("%s%s", &s, &t);
  int n0 = 0, n1 = 0, nt = 0;
  for (int i = 0; s[i] != '\0'; i++) {
    if (s[i] == '0')
      n0++;
    else
      n1++;
  }
  for (nt = 0; t[nt] != '\0'; nt++)
    ;
  for (int i = 0; i < nt; i++) {
    long long x = t[i] - 'a';
    x++;
    cum[i + 1] = (cum[i] + (x * po) % mod) % mod;
    po = (po * 31) % mod;
  }
  int ans = 0;
  for (int j = 1; j < nt; j++) {
    int r0 = j, rem = nt - r0 * n0, r1;
    if (rem <= 0)
      break;
    else if (rem % n1 == 0) {
      bool f = true;
      r1 = rem / n1;
      int curr = 0;
      long long sr0 = -1, sr1 = -1;
      int pos0 = -1, pos1 = -1;
      for (int i = 0; s[i] != '\0'; i++) {
        if (s[i] == '0') {
          if (sr0 != -1) {
            long long tem = (mod + cum[curr + r0] - cum[curr]) % mod;
            long long tem2 = (sr0 * fpo(31, curr - pos0)) % mod;
            if (tem != tem2) {
              f = false;
              break;
            }
            curr += r0;
          } else {
            sr0 = (mod + cum[curr + r0] - cum[curr]) % mod;
            pos0 = curr;
            curr += r0;
          }
        } else {
          if (sr1 != -1) {
            long long tem = (mod + cum[curr + r1] - cum[curr]) % mod;
            long long tem2 = (sr1 * fpo(31, curr - pos1)) % mod;
            if (tem != tem2) {
              f = false;
              break;
            }
            curr += r1;
          } else {
            sr1 = (mod + cum[curr + r1] - cum[curr]) % mod;
            pos1 = curr;
            curr += r1;
          }
        }
      }
      long long tem0 = (sr0 * fpo(31, pos1)) % mod,
                tem1 = (sr1 * fpo(31, pos0)) % mod;
      if (tem0 == tem1) {
        f = false;
      }
      if (f) {
        ans++;
      }
    }
  }
  printf("%i\n", ans);
  return 0;
}

```