#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto &x : v) {
    if (!f) r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
inline int add(int x, int y, int mod = inf) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int mul(int x, int y, int mod = inf) { return (x * 1LL * y) % mod; }
struct Hash {
  int base, mod;
  string s;
  int l;
  vector<int> pp, hf;
  Hash(const string &s, int base = 101, int mod = 1000000009)
      : base(base), mod(mod), s(s), l(s.length()), pp(l), hf(l) {
    pp[0] = 1;
    for (auto i = (1); i <= (l - 1); ++i) pp[i] = mul(pp[i - 1], base, mod);
    hf[0] = s[0] - 'a';
    for (auto i = (1); i <= (l - 1); ++i)
      hf[i] = add(mul(hf[i - 1], base, mod), s[i] - 'a', mod);
  }
  inline int get(int i, int j) {
    if (i == 0) return hf[j];
    return add(hf[j], mod - mul(hf[i - 1], pp[j - i + 1], mod), mod);
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  Hash H(t);
  int z = count((s).begin(), (s).end(), '0'), o = int(s.size()) - z;
  int ans = 0;
  for (auto i = (1); i <= (int(t.size()) / z); ++i)
    if (int(t.size()) > i * z) {
      if ((int(t.size()) - i * z) % o == 0) {
        int j = (int(t.size()) - i * z) / o;
        int h[2] = {-1, -1};
        bool can = true;
        int pos = 0;
        for (auto k = (0); k <= (int(s.size()) - 1); ++k) {
          int c = s[k] - '0';
          if (h[c] == -1) {
            h[c] = H.get(pos, pos + (c ? j : i) - 1);
          } else if (h[c] != H.get(pos, pos + (c ? j : i) - 1)) {
            can = false;
            break;
          }
          pos += c ? j : i;
        }
        if (i == j and h[0] == h[1]) can = false;
        ans += can;
      }
    }
  cout << ans << "\n";
  return 0;
}

### Prompt

Generate 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 int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto &x : v) {
    if (!f) r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
inline int add(int x, int y, int mod = inf) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int mul(int x, int y, int mod = inf) { return (x * 1LL * y) % mod; }
struct Hash {
  int base, mod;
  string s;
  int l;
  vector<int> pp, hf;
  Hash(const string &s, int base = 101, int mod = 1000000009)
      : base(base), mod(mod), s(s), l(s.length()), pp(l), hf(l) {
    pp[0] = 1;
    for (auto i = (1); i <= (l - 1); ++i) pp[i] = mul(pp[i - 1], base, mod);
    hf[0] = s[0] - 'a';
    for (auto i = (1); i <= (l - 1); ++i)
      hf[i] = add(mul(hf[i - 1], base, mod), s[i] - 'a', mod);
  }
  inline int get(int i, int j) {
    if (i == 0) return hf[j];
    return add(hf[j], mod - mul(hf[i - 1], pp[j - i + 1], mod), mod);
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  Hash H(t);
  int z = count((s).begin(), (s).end(), '0'), o = int(s.size()) - z;
  int ans = 0;
  for (auto i = (1); i <= (int(t.size()) / z); ++i)
    if (int(t.size()) > i * z) {
      if ((int(t.size()) - i * z) % o == 0) {
        int j = (int(t.size()) - i * z) / o;
        int h[2] = {-1, -1};
        bool can = true;
        int pos = 0;
        for (auto k = (0); k <= (int(s.size()) - 1); ++k) {
          int c = s[k] - '0';
          if (h[c] == -1) {
            h[c] = H.get(pos, pos + (c ? j : i) - 1);
          } else if (h[c] != H.get(pos, pos + (c ? j : i) - 1)) {
            can = false;
            break;
          }
          pos += c ? j : i;
        }
        if (i == j and h[0] == h[1]) can = false;
        ans += can;
      }
    }
  cout << ans << "\n";
  return 0;
}

```