#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool umin(T1& x, const T2& y) {
  return x > y ? x = y, true : false;
}
template <typename T1, typename T2>
inline bool umax(T1& x, const T2& y) {
  return x < y ? x = y, true : false;
}
const int N = (int)1e6 + 7;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 17;
const long long LLINF = (long long)1e18 + 17;
int n, m;
int H[2][N];
const int P[] = {449, 37};
const int Q[] = {999988901, 888888901};
int pw[2][N];
int inv[2][N];
inline void init() {
  auto binpow = [](int x, int y, int mod) {
    int ret = 1;
    while (y > 0) {
      if (y % 2 == 1) ret = 1ll * ret * x % mod;
      x = 1ll * x * x % mod;
      y /= 2;
    }
    return ret;
  };
  pw[0][0] = pw[1][0] = 1;
  inv[0][0] = inv[1][0] = 1;
  for (int j = (0); j < (2); ++j)
    for (int i = (1); i < (N); ++i) {
      pw[j][i] = 1ll * pw[j][i - 1] * P[j] % Q[j];
      inv[j][i] = binpow(pw[j][i], Q[j] - 2, Q[j]);
    }
}
inline pair<int, int> gethash(int l, int r) {
  int h0 = H[0][r] - (l > 0 ? H[0][l - 1] : 0);
  if (h0 < 0) h0 += Q[0];
  h0 = 1ll * h0 * inv[0][l] % Q[0];
  int h1 = H[1][r] - (l > 0 ? H[1][l - 1] : 0);
  if (h1 < 0) h1 += Q[1];
  h1 = 1ll * h1 * inv[1][l] % Q[1];
  return make_pair(h0, h1);
}
bool match(const string& s, pair<int, int> hZero, int sz0, pair<int, int> hOne,
           int sz1) {
  if (hZero == hOne) return false;
  if (sz0 == 0 || sz1 == 0) return false;
  int tl = 0;
  for (char ch : s) {
    if (ch == '0') {
      int tr = tl + sz0 - 1;
      if (gethash(tl, tr) != hZero) return false;
      tl += sz0;
    } else {
      int tr = tl + sz1 - 1;
      if (gethash(tl, tr) != hOne) return false;
      tl += sz1;
    }
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  string s, t;
  cin >> s >> t;
  int cnt[] = {0, 0};
  for (char ch : s) {
    ++cnt[ch - '0'];
  }
  int firstDiffer = 0;
  for (int i = (1); i < (s.length()); ++i) {
    if (s[0] != s[i]) {
      firstDiffer = i;
      break;
    }
  }
  init();
  for (int j = (0); j < (2); ++j)
    for (int i = (0); i < (t.length()); ++i) {
      H[j][i] =
          ((i > 0 ? H[j][i - 1] : 0) + 1ll * pw[j][i] * (t[i] - 'a' + 1)) %
          Q[j];
    }
  int res = 0;
  for (int sz0 = (1); sz0 < (t.length()); ++sz0) {
    if (sz0 * cnt[0] > t.length()) break;
    int sz1 = (t.length() - sz0 * cnt[0]) / cnt[1];
    if (sz0 * cnt[0] + sz1 * cnt[1] != t.length()) continue;
    pair<int, int> hZero, hOne;
    if (s[0] == '0') {
      hZero = gethash(0, sz0 - 1);
      hOne = gethash(sz0 * firstDiffer, sz0 * firstDiffer + sz1 - 1);
    } else {
      hZero = gethash(sz1 * firstDiffer, sz1 * firstDiffer + sz0 - 1);
      hOne = gethash(0, sz1 - 1);
    }
    res += match(s, hZero, sz0, hOne, sz1);
  }
  cout << res << endl;
  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;
template <typename T1, typename T2>
inline bool umin(T1& x, const T2& y) {
  return x > y ? x = y, true : false;
}
template <typename T1, typename T2>
inline bool umax(T1& x, const T2& y) {
  return x < y ? x = y, true : false;
}
const int N = (int)1e6 + 7;
const int mod = (int)1e9 + 7;
const int INF = (int)1e9 + 17;
const long long LLINF = (long long)1e18 + 17;
int n, m;
int H[2][N];
const int P[] = {449, 37};
const int Q[] = {999988901, 888888901};
int pw[2][N];
int inv[2][N];
inline void init() {
  auto binpow = [](int x, int y, int mod) {
    int ret = 1;
    while (y > 0) {
      if (y % 2 == 1) ret = 1ll * ret * x % mod;
      x = 1ll * x * x % mod;
      y /= 2;
    }
    return ret;
  };
  pw[0][0] = pw[1][0] = 1;
  inv[0][0] = inv[1][0] = 1;
  for (int j = (0); j < (2); ++j)
    for (int i = (1); i < (N); ++i) {
      pw[j][i] = 1ll * pw[j][i - 1] * P[j] % Q[j];
      inv[j][i] = binpow(pw[j][i], Q[j] - 2, Q[j]);
    }
}
inline pair<int, int> gethash(int l, int r) {
  int h0 = H[0][r] - (l > 0 ? H[0][l - 1] : 0);
  if (h0 < 0) h0 += Q[0];
  h0 = 1ll * h0 * inv[0][l] % Q[0];
  int h1 = H[1][r] - (l > 0 ? H[1][l - 1] : 0);
  if (h1 < 0) h1 += Q[1];
  h1 = 1ll * h1 * inv[1][l] % Q[1];
  return make_pair(h0, h1);
}
bool match(const string& s, pair<int, int> hZero, int sz0, pair<int, int> hOne,
           int sz1) {
  if (hZero == hOne) return false;
  if (sz0 == 0 || sz1 == 0) return false;
  int tl = 0;
  for (char ch : s) {
    if (ch == '0') {
      int tr = tl + sz0 - 1;
      if (gethash(tl, tr) != hZero) return false;
      tl += sz0;
    } else {
      int tr = tl + sz1 - 1;
      if (gethash(tl, tr) != hOne) return false;
      tl += sz1;
    }
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  string s, t;
  cin >> s >> t;
  int cnt[] = {0, 0};
  for (char ch : s) {
    ++cnt[ch - '0'];
  }
  int firstDiffer = 0;
  for (int i = (1); i < (s.length()); ++i) {
    if (s[0] != s[i]) {
      firstDiffer = i;
      break;
    }
  }
  init();
  for (int j = (0); j < (2); ++j)
    for (int i = (0); i < (t.length()); ++i) {
      H[j][i] =
          ((i > 0 ? H[j][i - 1] : 0) + 1ll * pw[j][i] * (t[i] - 'a' + 1)) %
          Q[j];
    }
  int res = 0;
  for (int sz0 = (1); sz0 < (t.length()); ++sz0) {
    if (sz0 * cnt[0] > t.length()) break;
    int sz1 = (t.length() - sz0 * cnt[0]) / cnt[1];
    if (sz0 * cnt[0] + sz1 * cnt[1] != t.length()) continue;
    pair<int, int> hZero, hOne;
    if (s[0] == '0') {
      hZero = gethash(0, sz0 - 1);
      hOne = gethash(sz0 * firstDiffer, sz0 * firstDiffer + sz1 - 1);
    } else {
      hZero = gethash(sz1 * firstDiffer, sz1 * firstDiffer + sz0 - 1);
      hOne = gethash(0, sz1 - 1);
    }
    res += match(s, hZero, sz0, hOne, sz1);
  }
  cout << res << endl;
  return 0;
}

```