#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long sum(long long a, long long b, long long mod) {
  long long ans = a + b;
  if (ans > mod) ans -= mod;
  return ans;
}
long long mul(long long a, long long b, long long mod) { return (a * b) % mod; }
long long dif(long long a, long long b, long long mod) {
  long long res = a - b;
  if (res < 0) res += mod;
  return res;
}
long long binpow(long long a, long long b, long long mod) {
  if (b == 1) return a;
  if (b % 2 == 0) {
    long long bb = binpow(a, b / 2, mod);
    return mul(bb, bb, mod);
  }
  if (b % 2 == 1) {
    long long bb = binpow(a, b / 2, mod);
    bb = mul(bb, bb, mod);
    return mul(bb, a, mod);
  }
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    if (i != 0) os << ' ';
    os << V[i];
  }
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    is >> V[i];
  }
  return is;
}
const long long maxn = 1000000;
const int bases[2] = {31, 29};
const int mods[2] = {1000000007, 1000000009};
long long pows[maxn][2];
int n;
long long hashes[maxn + 1][2];
long long inv(long long num, long long mod) {
  return binpow(num, mod - 2, mod);
}
vector<long long> get_hash(int l, int r) {
  vector<long long> ans(2);
  for (int j = 0; j < 2; ++j) {
    ans[j] = hashes[r][j];
    if (l != 0) ans[j] = dif(ans[j], hashes[l - 1][j], mods[j]);
    ans[j] = mul(ans[j], pows[n - l - 1][j], mods[j]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  int occ[2] = {0, 0};
  n = t.length();
  for (int i = 0; i < s.length(); ++i) occ[s[i] - '0']++;
  pows[0][0] = pows[0][1] = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 2; ++j) {
      pows[i][j] = mul(pows[i - 1][j], bases[j], mods[j]);
    }
  }
  hashes[0][0] = hashes[0][1] = t[0] - 'a';
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 2; ++j) {
      hashes[i][j] =
          sum(hashes[i - 1][j], mul(pows[i][j], (long long)t[i] - 'a', mods[j]),
              mods[j]);
    }
  }
  int ans = 0;
  if (occ[0] > occ[1]) {
    for (int i = 1; i * occ[0] <= n; ++i) {
      int jj = n - i * occ[0];
      if (jj % occ[1] != 0) continue;
      if (jj == 0) continue;
      int len2 = jj / occ[1];
      int len1 = i;
      int zero_first = -1;
      int one_first = -1;
      bool ok = true;
      int cur = 0;
      for (int j = 0; j < s.length(); ++j) {
        if (s[j] == '0') {
          if (zero_first == -1) {
            zero_first = cur;
          } else if (get_hash(cur, cur + len1 - 1) !=
                     get_hash(zero_first, zero_first + len1 - 1)) {
            ok = false;
          }
          cur += len1;
        } else {
          if (one_first == -1) {
            one_first = cur;
          } else if (get_hash(cur, cur + len2 - 1) !=
                     get_hash(one_first, one_first + len2 - 1)) {
            ok = false;
          }
          cur += len2;
        }
      }
      if (len1 == len2 && get_hash(zero_first, zero_first + len1 - 1) ==
                              get_hash(one_first, one_first + len2 - 1)) {
        ok = false;
      }
      if (ok) ans++;
    }
  } else {
    for (int i = 1; i * occ[1] <= n; ++i) {
      int jj = n - i * occ[1];
      if (jj % occ[0] != 0) continue;
      if (jj == 0) continue;
      int len1 = jj / occ[0];
      int len2 = i;
      int zero_first = -1;
      int one_first = -1;
      bool ok = true;
      int cur = 0;
      for (int j = 0; j < s.length(); ++j) {
        if (s[j] == '0') {
          if (zero_first == -1) {
            zero_first = cur;
          } else if (get_hash(cur, cur + len1 - 1) !=
                     get_hash(zero_first, zero_first + len1 - 1)) {
            ok = false;
          }
          cur += len1;
        } else {
          if (one_first == -1) {
            one_first = cur;
          } else if (get_hash(cur, cur + len2 - 1) !=
                     get_hash(one_first, one_first + len2 - 1)) {
            ok = false;
          }
          cur += len2;
        }
      }
      if (len1 == len2 && get_hash(zero_first, zero_first + len1 - 1) ==
                              get_hash(one_first, one_first + len2 - 1)) {
        ok = false;
      }
      if (ok) ans++;
    }
  }
  cout << ans;
  return 0;
}

### Prompt

Please formulate 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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long sum(long long a, long long b, long long mod) {
  long long ans = a + b;
  if (ans > mod) ans -= mod;
  return ans;
}
long long mul(long long a, long long b, long long mod) { return (a * b) % mod; }
long long dif(long long a, long long b, long long mod) {
  long long res = a - b;
  if (res < 0) res += mod;
  return res;
}
long long binpow(long long a, long long b, long long mod) {
  if (b == 1) return a;
  if (b % 2 == 0) {
    long long bb = binpow(a, b / 2, mod);
    return mul(bb, bb, mod);
  }
  if (b % 2 == 1) {
    long long bb = binpow(a, b / 2, mod);
    bb = mul(bb, bb, mod);
    return mul(bb, a, mod);
  }
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    if (i != 0) os << ' ';
    os << V[i];
  }
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &V) {
  for (int i = 0; i < (int)V.size(); ++i) {
    is >> V[i];
  }
  return is;
}
const long long maxn = 1000000;
const int bases[2] = {31, 29};
const int mods[2] = {1000000007, 1000000009};
long long pows[maxn][2];
int n;
long long hashes[maxn + 1][2];
long long inv(long long num, long long mod) {
  return binpow(num, mod - 2, mod);
}
vector<long long> get_hash(int l, int r) {
  vector<long long> ans(2);
  for (int j = 0; j < 2; ++j) {
    ans[j] = hashes[r][j];
    if (l != 0) ans[j] = dif(ans[j], hashes[l - 1][j], mods[j]);
    ans[j] = mul(ans[j], pows[n - l - 1][j], mods[j]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s, t;
  cin >> s >> t;
  int occ[2] = {0, 0};
  n = t.length();
  for (int i = 0; i < s.length(); ++i) occ[s[i] - '0']++;
  pows[0][0] = pows[0][1] = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 2; ++j) {
      pows[i][j] = mul(pows[i - 1][j], bases[j], mods[j]);
    }
  }
  hashes[0][0] = hashes[0][1] = t[0] - 'a';
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 2; ++j) {
      hashes[i][j] =
          sum(hashes[i - 1][j], mul(pows[i][j], (long long)t[i] - 'a', mods[j]),
              mods[j]);
    }
  }
  int ans = 0;
  if (occ[0] > occ[1]) {
    for (int i = 1; i * occ[0] <= n; ++i) {
      int jj = n - i * occ[0];
      if (jj % occ[1] != 0) continue;
      if (jj == 0) continue;
      int len2 = jj / occ[1];
      int len1 = i;
      int zero_first = -1;
      int one_first = -1;
      bool ok = true;
      int cur = 0;
      for (int j = 0; j < s.length(); ++j) {
        if (s[j] == '0') {
          if (zero_first == -1) {
            zero_first = cur;
          } else if (get_hash(cur, cur + len1 - 1) !=
                     get_hash(zero_first, zero_first + len1 - 1)) {
            ok = false;
          }
          cur += len1;
        } else {
          if (one_first == -1) {
            one_first = cur;
          } else if (get_hash(cur, cur + len2 - 1) !=
                     get_hash(one_first, one_first + len2 - 1)) {
            ok = false;
          }
          cur += len2;
        }
      }
      if (len1 == len2 && get_hash(zero_first, zero_first + len1 - 1) ==
                              get_hash(one_first, one_first + len2 - 1)) {
        ok = false;
      }
      if (ok) ans++;
    }
  } else {
    for (int i = 1; i * occ[1] <= n; ++i) {
      int jj = n - i * occ[1];
      if (jj % occ[0] != 0) continue;
      if (jj == 0) continue;
      int len1 = jj / occ[0];
      int len2 = i;
      int zero_first = -1;
      int one_first = -1;
      bool ok = true;
      int cur = 0;
      for (int j = 0; j < s.length(); ++j) {
        if (s[j] == '0') {
          if (zero_first == -1) {
            zero_first = cur;
          } else if (get_hash(cur, cur + len1 - 1) !=
                     get_hash(zero_first, zero_first + len1 - 1)) {
            ok = false;
          }
          cur += len1;
        } else {
          if (one_first == -1) {
            one_first = cur;
          } else if (get_hash(cur, cur + len2 - 1) !=
                     get_hash(one_first, one_first + len2 - 1)) {
            ok = false;
          }
          cur += len2;
        }
      }
      if (len1 == len2 && get_hash(zero_first, zero_first + len1 - 1) ==
                              get_hash(one_first, one_first + len2 - 1)) {
        ok = false;
      }
      if (ok) ans++;
    }
  }
  cout << ans;
  return 0;
}

```