#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
string s, t;
struct hash {
  long long P;
  vector<long long> pp;
  vector<long long> h;
  long long n;
  long long mul(long long a, long long b) { return a * b % P; }
  void add(long long &a, long long b) {
    a += b;
    if (a >= P) a -= P;
  }
  long long buduj(long long p, long long base, string &z) {
    P = p;
    n = ((long long)(z).size());
    pp.resize(n + 1);
    h.resize(n + 1);
    pp[0] = 1;
    h[0] = 0;
    for (long long i = (0); i <= ((long long)(n)-1); i++) {
      pp[i + 1] = mul(pp[i], base);
      h[i + 1] = mul(h[i], base);
      add(h[i + 1], z[i]);
    }
    return h[n];
  }
  long long get(long long a, long long dl) {
    long long res = h[a + dl] - mul(h[a], pp[dl]);
    if (res < 0) res += P;
    return res;
  }
  bool spr(long long dl0, long long dl1) {
    long long ak = 0;
    long long xx = 0;
    long long h0 = -1;
    long long h1 = -1;
    for (long long i = (0); i <= ((long long)(((long long)(s).size())) - 1);
         i++) {
      if (s[i] == 0) {
        if (h0 == -1) {
          h0 = get(ak, dl0);
        }
        ak += dl0;
        xx = mul(xx, pp[dl0]);
        add(xx, h0);
      } else {
        if (h1 == -1) {
          h1 = get(ak, dl1);
        }
        ak += dl1;
        xx = mul(xx, pp[dl1]);
        add(xx, h1);
      }
    }
    (dl0, dl1, xx, h0, h[n]);
    return xx == h[n] && h0 != h1;
  }
} h1, h2;
long long il0 = 0, il1 = 0;
long long res;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> s >> t;
  h1.buduj(1e9 + 7, 1000, t);
  h2.buduj(1e9 + 9, 51321351, t);
  for (long long i = (0); i <= ((long long)(((long long)(s).size())) - 1);
       i++) {
    char &el = s[i];
    el -= '0';
    if (el == 0) {
      il0++;
    } else {
      il1++;
    }
  }
  for (long long dl0 = (0); dl0 <= ((long long)(((long long)(t).size())) - 1);
       dl0++) {
    if (dl0 == 0) continue;
    long long pom = ((long long)(t).size()) - dl0 * il0;
    if (pom <= 0 || pom % il1 != 0) continue;
    if (h1.spr(dl0, pom / il1) && h2.spr(dl0, pom / il1)) {
      res++;
    }
  }
  cout << res << "\n";
}

### Prompt

Create a solution in Cpp for 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>
#pragma GCC optimize("O3")
using namespace std;
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
string s, t;
struct hash {
  long long P;
  vector<long long> pp;
  vector<long long> h;
  long long n;
  long long mul(long long a, long long b) { return a * b % P; }
  void add(long long &a, long long b) {
    a += b;
    if (a >= P) a -= P;
  }
  long long buduj(long long p, long long base, string &z) {
    P = p;
    n = ((long long)(z).size());
    pp.resize(n + 1);
    h.resize(n + 1);
    pp[0] = 1;
    h[0] = 0;
    for (long long i = (0); i <= ((long long)(n)-1); i++) {
      pp[i + 1] = mul(pp[i], base);
      h[i + 1] = mul(h[i], base);
      add(h[i + 1], z[i]);
    }
    return h[n];
  }
  long long get(long long a, long long dl) {
    long long res = h[a + dl] - mul(h[a], pp[dl]);
    if (res < 0) res += P;
    return res;
  }
  bool spr(long long dl0, long long dl1) {
    long long ak = 0;
    long long xx = 0;
    long long h0 = -1;
    long long h1 = -1;
    for (long long i = (0); i <= ((long long)(((long long)(s).size())) - 1);
         i++) {
      if (s[i] == 0) {
        if (h0 == -1) {
          h0 = get(ak, dl0);
        }
        ak += dl0;
        xx = mul(xx, pp[dl0]);
        add(xx, h0);
      } else {
        if (h1 == -1) {
          h1 = get(ak, dl1);
        }
        ak += dl1;
        xx = mul(xx, pp[dl1]);
        add(xx, h1);
      }
    }
    (dl0, dl1, xx, h0, h[n]);
    return xx == h[n] && h0 != h1;
  }
} h1, h2;
long long il0 = 0, il1 = 0;
long long res;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> s >> t;
  h1.buduj(1e9 + 7, 1000, t);
  h2.buduj(1e9 + 9, 51321351, t);
  for (long long i = (0); i <= ((long long)(((long long)(s).size())) - 1);
       i++) {
    char &el = s[i];
    el -= '0';
    if (el == 0) {
      il0++;
    } else {
      il1++;
    }
  }
  for (long long dl0 = (0); dl0 <= ((long long)(((long long)(t).size())) - 1);
       dl0++) {
    if (dl0 == 0) continue;
    long long pom = ((long long)(t).size()) - dl0 * il0;
    if (pom <= 0 || pom % il1 != 0) continue;
    if (h1.spr(dl0, pom / il1) && h2.spr(dl0, pom / il1)) {
      res++;
    }
  }
  cout << res << "\n";
}

```