#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline unsigned long long isqrt(unsigned long long k) {
  unsigned long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int myrand() { return abs((int)mt()); }
const int maxn = 1e6 + 5;
int pr;
int base = 257;
int p[maxn];
string s, t;
int f[maxn];
int ispr(int k) {
  for (int i = 2; i * i <= k; i++) {
    if (k % i == 0) {
      return 0;
    }
  }
  return 1;
}
int calc(int l, int r) {
  int res = f[r];
  if (l) submod(res, f[l - 1], pr);
  return mult(res, p[maxn - l - 1], pr);
}
void chemthan() {
  pr = INF - myrand() % INF / 10;
  while (!ispr(pr)) pr++;
  p[0] = 1;
  for (int i = (1); i < (maxn); ++i) p[i] = mult(p[i - 1], base, pr);
  cin >> s >> t;
  for (int i = (0); i < (int((t).size())); ++i) {
    if (i) {
      f[i] = f[i - 1];
    }
    addmod(f[i], mult(t[i], p[i], pr), pr);
  }
  int a = 0, b = 0;
  for (char c : s) {
    if (c == '0') {
      a++;
    } else {
      b++;
    }
  }
  int res = 0;
  for (int x = 1; x * a < int((t).size()); x++) {
    int r = int((t).size()) - x * a;
    if (r % b == 0) {
      int y = r / b;
      vector<int> pos0, pos1;
      int num = 0;
      for (int i = (0); i < (int((s).size())); ++i) {
        if (s[i] == '0') {
          pos0.push_back(num);
          num += x;
        } else {
          pos1.push_back(num);
          num += y;
        }
      }
      int found = 0;
      for (int i = (1); i < (int((pos0).size())); ++i) {
        int u = pos0[0];
        int v = pos0[i];
        if (calc(u, u + x - 1) != calc(v, v + x - 1)) {
          found = 1;
          break;
        }
      }
      for (int i = (1); i < (int((pos1).size())); ++i) {
        int u = pos1[0];
        int v = pos1[i];
        if (calc(u, u + y - 1) != calc(v, v + y - 1)) {
          found = 1;
          break;
        }
      }
      int u = pos0[0];
      int v = pos1[0];
      if (calc(u, u + x - 1) == calc(v, v + y - 1)) {
        found = 1;
      }
      if (!found) res++;
    }
  }
  cout << res << "\n";
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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 MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline unsigned long long isqrt(unsigned long long k) {
  unsigned long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int myrand() { return abs((int)mt()); }
const int maxn = 1e6 + 5;
int pr;
int base = 257;
int p[maxn];
string s, t;
int f[maxn];
int ispr(int k) {
  for (int i = 2; i * i <= k; i++) {
    if (k % i == 0) {
      return 0;
    }
  }
  return 1;
}
int calc(int l, int r) {
  int res = f[r];
  if (l) submod(res, f[l - 1], pr);
  return mult(res, p[maxn - l - 1], pr);
}
void chemthan() {
  pr = INF - myrand() % INF / 10;
  while (!ispr(pr)) pr++;
  p[0] = 1;
  for (int i = (1); i < (maxn); ++i) p[i] = mult(p[i - 1], base, pr);
  cin >> s >> t;
  for (int i = (0); i < (int((t).size())); ++i) {
    if (i) {
      f[i] = f[i - 1];
    }
    addmod(f[i], mult(t[i], p[i], pr), pr);
  }
  int a = 0, b = 0;
  for (char c : s) {
    if (c == '0') {
      a++;
    } else {
      b++;
    }
  }
  int res = 0;
  for (int x = 1; x * a < int((t).size()); x++) {
    int r = int((t).size()) - x * a;
    if (r % b == 0) {
      int y = r / b;
      vector<int> pos0, pos1;
      int num = 0;
      for (int i = (0); i < (int((s).size())); ++i) {
        if (s[i] == '0') {
          pos0.push_back(num);
          num += x;
        } else {
          pos1.push_back(num);
          num += y;
        }
      }
      int found = 0;
      for (int i = (1); i < (int((pos0).size())); ++i) {
        int u = pos0[0];
        int v = pos0[i];
        if (calc(u, u + x - 1) != calc(v, v + x - 1)) {
          found = 1;
          break;
        }
      }
      for (int i = (1); i < (int((pos1).size())); ++i) {
        int u = pos1[0];
        int v = pos1[i];
        if (calc(u, u + y - 1) != calc(v, v + y - 1)) {
          found = 1;
          break;
        }
      }
      int u = pos0[0];
      int v = pos1[0];
      if (calc(u, u + x - 1) == calc(v, v + y - 1)) {
        found = 1;
      }
      if (!found) res++;
    }
  }
  cout << res << "\n";
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}

```