#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
template <typename T>
T getint() {
  T val = 0;
  char c;
  bool neg = false;
  while ((c = getchar()) && !(c >= '0' && c <= '9')) {
    neg |= c == '-';
  }
  do {
    val = (val * 10) + c - '0';
  } while ((c = getchar()) && (c >= '0' && c <= '9'));
  return val * (neg ? -1 : 1);
}
vector<int> zalgo(string& str) {
  vector<int> z((int)(str).size());
  int L = 0, R = 0;
  for (int i = 1; i < (int)(str).size(); ++i) {
    if (i > R) {
      L = i;
      R = i;
      while (R < (int)(str).size() && str[R] == str[R - L]) R++;
      z[i] = R - L;
      R--;
    } else {
      if (z[i - L] + i < R) {
        z[i] = z[i - L];
      } else {
        L = i;
        while (R < (int)(str).size() && str[R] == str[R - L]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
  return z;
}
long long fastpow(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  long long fele = fastpow(a, b / 2, mod);
  long long ans = (fele * fele) % mod;
  if (b & 1) ans = (ans * a) % mod;
  return ans;
}
struct rolling_hash {
  vector<long long> lst;
  vector<long long> hatv;
  long long p;
  long long mod;
  rolling_hash(string& t, long long p_, long long mod_) {
    lst.resize((int)(t).size());
    hatv.resize((int)(t).size());
    p = p_;
    mod = mod_;
    long long curr = p;
    lst[0] = t[0] % mod;
    hatv[0] = 1;
    for (int i = 1; i < (int)(t).size(); ++i) {
      lst[i] = (lst[i - 1] + curr * t[i]) % mod;
      hatv[i] = curr;
      curr = (curr * p) % mod;
    }
  }
  long long base_hash(long long l, long long r) {
    long long hsh = (lst[r] - (l > 0 ? lst[l - 1] : 0) + mod);
    return (hsh * fastpow(hatv[l], mod - 2, mod)) % mod;
  }
  bool probably_equal(long long l1, long long r1, long long l2, long long r2) {
    if (r1 - l1 != r2 - l2) return false;
    if (l1 > l2) {
      swap(l1, l2);
      swap(r1, r2);
    }
    long long egyik = (lst[r2] - (l2 > 0 ? lst[l2 - 1] : 0) + mod),
              masik = (lst[r1] - (l1 > 0 ? lst[l1 - 1] : 0) + mod);
    return (egyik - (masik * hatv[l2 - l1])) % mod == 0;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string a, b;
  cin >> a >> b;
  int e = 0, n = 0;
  for (auto i : a)
    if (i == '0')
      n++;
    else
      e++;
  rolling_hash r1(b, 31, 1e9 + 7);
  rolling_hash r2(b, 15, 1e9 + 9);
  vector<int> z = zalgo(b);
  int res = 0;
  for (int i = 1; i <= 1000000; ++i) {
    if ((int)b.size() <= i * n) break;
    if (((int)b.size() - i * n) % e == 0) {
      int j = ((int)b.size() - i * n) / e;
      bool ok = true;
      int ind = (a[0] == '1' ? j : i);
      int ref = -1;
      for (int k = 1; k < (int)a.size() && ok; ++k) {
        if (a[k] != a[0]) {
          if (ref == -1)
            ref = ind;
          else {
            ok &= r1.probably_equal(ref, ref + (a[k] == '1' ? j : i) - 1, ind,
                                    ind + (a[k] == '1' ? j : i) - 1) &&
                  r2.probably_equal(ref, ref + (a[k] == '1' ? j : i) - 1, ind,
                                    ind + (a[k] == '1' ? j : i) - 1);
          }
        } else {
          ok &= z[ind] >= (a[0] == '1' ? j : i);
        }
        ind += (a[k] == '1' ? j : i);
      }
      if (i == j) {
        bool van = false;
        for (int k = 0; k < i && !van; ++k) {
          van |= b[k] != b[ref + k];
        }
        ok &= van;
      }
      res += ok;
    }
  }
  cout << res << "\n";
  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 double PI = acos(-1);
template <typename T>
T getint() {
  T val = 0;
  char c;
  bool neg = false;
  while ((c = getchar()) && !(c >= '0' && c <= '9')) {
    neg |= c == '-';
  }
  do {
    val = (val * 10) + c - '0';
  } while ((c = getchar()) && (c >= '0' && c <= '9'));
  return val * (neg ? -1 : 1);
}
vector<int> zalgo(string& str) {
  vector<int> z((int)(str).size());
  int L = 0, R = 0;
  for (int i = 1; i < (int)(str).size(); ++i) {
    if (i > R) {
      L = i;
      R = i;
      while (R < (int)(str).size() && str[R] == str[R - L]) R++;
      z[i] = R - L;
      R--;
    } else {
      if (z[i - L] + i < R) {
        z[i] = z[i - L];
      } else {
        L = i;
        while (R < (int)(str).size() && str[R] == str[R - L]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
  return z;
}
long long fastpow(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  long long fele = fastpow(a, b / 2, mod);
  long long ans = (fele * fele) % mod;
  if (b & 1) ans = (ans * a) % mod;
  return ans;
}
struct rolling_hash {
  vector<long long> lst;
  vector<long long> hatv;
  long long p;
  long long mod;
  rolling_hash(string& t, long long p_, long long mod_) {
    lst.resize((int)(t).size());
    hatv.resize((int)(t).size());
    p = p_;
    mod = mod_;
    long long curr = p;
    lst[0] = t[0] % mod;
    hatv[0] = 1;
    for (int i = 1; i < (int)(t).size(); ++i) {
      lst[i] = (lst[i - 1] + curr * t[i]) % mod;
      hatv[i] = curr;
      curr = (curr * p) % mod;
    }
  }
  long long base_hash(long long l, long long r) {
    long long hsh = (lst[r] - (l > 0 ? lst[l - 1] : 0) + mod);
    return (hsh * fastpow(hatv[l], mod - 2, mod)) % mod;
  }
  bool probably_equal(long long l1, long long r1, long long l2, long long r2) {
    if (r1 - l1 != r2 - l2) return false;
    if (l1 > l2) {
      swap(l1, l2);
      swap(r1, r2);
    }
    long long egyik = (lst[r2] - (l2 > 0 ? lst[l2 - 1] : 0) + mod),
              masik = (lst[r1] - (l1 > 0 ? lst[l1 - 1] : 0) + mod);
    return (egyik - (masik * hatv[l2 - l1])) % mod == 0;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string a, b;
  cin >> a >> b;
  int e = 0, n = 0;
  for (auto i : a)
    if (i == '0')
      n++;
    else
      e++;
  rolling_hash r1(b, 31, 1e9 + 7);
  rolling_hash r2(b, 15, 1e9 + 9);
  vector<int> z = zalgo(b);
  int res = 0;
  for (int i = 1; i <= 1000000; ++i) {
    if ((int)b.size() <= i * n) break;
    if (((int)b.size() - i * n) % e == 0) {
      int j = ((int)b.size() - i * n) / e;
      bool ok = true;
      int ind = (a[0] == '1' ? j : i);
      int ref = -1;
      for (int k = 1; k < (int)a.size() && ok; ++k) {
        if (a[k] != a[0]) {
          if (ref == -1)
            ref = ind;
          else {
            ok &= r1.probably_equal(ref, ref + (a[k] == '1' ? j : i) - 1, ind,
                                    ind + (a[k] == '1' ? j : i) - 1) &&
                  r2.probably_equal(ref, ref + (a[k] == '1' ? j : i) - 1, ind,
                                    ind + (a[k] == '1' ? j : i) - 1);
          }
        } else {
          ok &= z[ind] >= (a[0] == '1' ? j : i);
        }
        ind += (a[k] == '1' ? j : i);
      }
      if (i == j) {
        bool van = false;
        for (int k = 0; k < i && !van; ++k) {
          van |= b[k] != b[ref + k];
        }
        ok &= van;
      }
      res += ok;
    }
  }
  cout << res << "\n";
  return 0;
}

```