#include <bits/stdc++.h>
using namespace std;
template <class A>
void rd(vector<A> &v);
template <class T>
void rd(T &x) {
  cin >> x;
}
template <class H, class... T>
void rd(H &h, T &...t) {
  rd(h);
  rd(t...);
}
template <class A>
void rd(vector<A> &x) {
  for (auto &a : x) rd(a);
}
template <class T>
bool ckmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
void __p(T a) {
  cout << a;
}
template <typename T, typename F>
void __p(pair<T, F> a) {
  cout << "{";
  __p(a.first);
  cout << ",";
  __p(a.second);
  cout << "}\n";
}
template <typename T>
void __p(std::vector<T> a) {
  cout << "{";
  for (auto it = a.begin(); it < a.end(); it++)
    __p(*it), cout << ",}\n"[it + 1 == a.end()];
}
template <typename T, typename... Arg>
void __p(T a1, Arg... a) {
  __p(a1);
  __p(a...);
}
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : ";
  __p(arg1);
  cout << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  int bracket = 0, i = 0;
  for (;; i++)
    if (names[i] == ',' && bracket == 0)
      break;
    else if (names[i] == '(')
      bracket++;
    else if (names[i] == ')')
      bracket--;
  const char *comma = names + i;
  cout.write(names, comma - names) << " : ";
  __p(arg1);
  cout << " | ";
  __f(comma + 1, args...);
}
void setIO(string s = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.exceptions(cin.failbit);
  cout.precision(15);
  cout << fixed;
  if (((int)(s).size())) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
  }
}
template <const unsigned &MOD>
struct _m_uint {
  unsigned val;
  _m_uint(int64_t v = 0) {
    if (v < 0) v = v % MOD + MOD;
    if (v >= MOD) v %= MOD;
    val = unsigned(v);
  }
  _m_uint(uint64_t v) {
    if (v >= MOD) v %= MOD;
    val = unsigned(v);
  }
  _m_uint(int v) : _m_uint(int64_t(v)) {}
  _m_uint(unsigned v) : _m_uint(uint64_t(v)) {}
  explicit operator unsigned() const { return val; }
  explicit operator int64_t() const { return val; }
  explicit operator uint64_t() const { return val; }
  explicit operator double() const { return val; }
  explicit operator long double() const { return val; }
  _m_uint &operator+=(const _m_uint &other) {
    val = val < MOD - other.val ? val + other.val : val - (MOD - other.val);
    return *this;
  }
  _m_uint &operator-=(const _m_uint &other) {
    val = val < other.val ? val + (MOD - other.val) : val - other.val;
    return *this;
  }
  static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
    return unsigned(x % m);
    unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
    unsigned quot, rem;
    asm("divl %4\n" : "=a"(quot), "=d"(rem) : "d"(x_high), "a"(x_low), "r"(m));
    return rem;
  }
  _m_uint &operator*=(const _m_uint &other) {
    val = fast_mod(uint64_t(val) * other.val);
    return *this;
  }
  _m_uint &operator/=(const _m_uint &other) { return *this *= other.inv(); }
  friend _m_uint operator+(const _m_uint &a, const _m_uint &b) {
    return _m_uint(a) += b;
  }
  friend _m_uint operator-(const _m_uint &a, const _m_uint &b) {
    return _m_uint(a) -= b;
  }
  friend _m_uint operator*(const _m_uint &a, const _m_uint &b) {
    return _m_uint(a) *= b;
  }
  friend _m_uint operator/(const _m_uint &a, const _m_uint &b) {
    return _m_uint(a) /= b;
  }
  _m_uint &operator++() {
    val = val == MOD - 1 ? 0 : val + 1;
    return *this;
  }
  _m_uint &operator--() {
    val = val == 0 ? MOD - 1 : val - 1;
    return *this;
  }
  _m_uint operator++(int) {
    _m_uint before = *this;
    ++*this;
    return before;
  }
  _m_uint operator--(int) {
    _m_uint before = *this;
    --*this;
    return before;
  }
  _m_uint operator-() const { return val == 0 ? 0 : MOD - val; }
  friend bool operator==(const _m_uint &a, const _m_uint &b) {
    return a.val == b.val;
  }
  friend bool operator!=(const _m_uint &a, const _m_uint &b) {
    return a.val != b.val;
  }
  friend bool operator<(const _m_uint &a, const _m_uint &b) {
    return a.val < b.val;
  }
  friend bool operator>(const _m_uint &a, const _m_uint &b) {
    return a.val > b.val;
  }
  friend bool operator<=(const _m_uint &a, const _m_uint &b) {
    return a.val <= b.val;
  }
  friend bool operator>=(const _m_uint &a, const _m_uint &b) {
    return a.val >= b.val;
  }
  static const int SAVE_INV = int(1e6) + 5;
  static _m_uint save_inv[SAVE_INV];
  static void prepare_inv() {
    for (int64_t p = 2; p * p <= MOD; p += p % 2 + 1) {
      assert(MOD % p != 0);
    }
    save_inv[0] = 0;
    save_inv[1] = 1;
    for (int i = 2; i < SAVE_INV; i++) {
      save_inv[i] = save_inv[MOD % i] * (MOD - MOD / i);
    }
  }
  _m_uint inv() const {
    if (save_inv[1] == 0) prepare_inv();
    if (val < SAVE_INV) return save_inv[val];
    _m_uint product = 1;
    unsigned v = val;
    while (v >= SAVE_INV) {
      product *= MOD - MOD / v;
      v = MOD % v;
    }
    return product * save_inv[v];
  }
  _m_uint pow(int64_t p) const {
    if (p < 0) return inv().pow(-p);
    _m_uint a = *this, result = 1;
    while (p > 0) {
      if (p & 1) result *= a;
      p >>= 1;
      if (p > 0) a *= a;
    }
    return result;
  }
  friend ostream &operator<<(ostream &os, const _m_uint &m) {
    return os << m.val;
  }
};
template <const unsigned &MOD>
_m_uint<MOD> _m_uint<MOD>::save_inv[_m_uint<MOD>::SAVE_INV];
auto random_address = [] {
  char *p = new char;
  delete p;
  return uint64_t(p);
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() *
               (random_address() | 1));
extern const unsigned HASH_P = unsigned(-13337);
using hash_int = _m_uint<HASH_P>;
using hash_t = uint64_t;
const uint64_t HASH_P2 = uint64_t(HASH_P) * HASH_P;
const int HASH_COUNT = 2;
uniform_int_distribution<unsigned> MULT_DIST(unsigned(0.1 * HASH_P),
                                             unsigned(0.9 * HASH_P));
const hash_int HASH_MULT[] = {MULT_DIST(rng), MULT_DIST(rng)};
const hash_int HASH_INV[] = {1 / HASH_MULT[0], 1 / HASH_MULT[1]};
vector<hash_int> hash_pow[] = {{1}, {1}};
const int INF = int(1e9) + 5;
template <typename T_string = string>
struct string_hash {
  static const bool BUILD_REVERSE = false;
  static uint64_t hash(const T_string &str) {
    uint64_t result = 0;
    for (int h = 0; h < HASH_COUNT; h++) {
      uint64_t value = 1;
      for (const auto &x : str) {
        value = (uint64_t(HASH_MULT[h]) * value + x) % HASH_P;
      }
      result += value << (32 * h);
    }
    return result;
  }
  T_string str;
  vector<hash_int> _prefix[HASH_COUNT];
  vector<hash_int> _inv_prefix[HASH_COUNT];
  string_hash() { build({}); }
  string_hash(const T_string &_str) { build(_str); }
  int length() const { return int(_prefix[0].size()) - 1; }
  template <typename T_char>
  void add_char(const T_char &c) {
    str.push_back(c);
    for (int h = 0; h < HASH_COUNT; h++) {
      _prefix[h].push_back(HASH_MULT[h] * _prefix[h].back() + c);
      if (hash_pow[h].size() < _prefix[h].size()) {
        hash_pow[h].push_back(HASH_MULT[h] * hash_pow[h].back());
      }
      if (BUILD_REVERSE) {
        _inv_prefix[h].push_back((_inv_prefix[h].back() + c) * HASH_INV[h]);
      }
    }
  }
  void pop_char() {
    str.pop_back();
    for (int h = 0; h < HASH_COUNT; h++) {
      _prefix[h].pop_back();
      if (BUILD_REVERSE) {
        _inv_prefix[h].pop_back();
      }
    }
  }
  void build(const T_string &_str) {
    str = {};
    str.reserve(_str.size());
    for (int h = 0; h < HASH_COUNT; h++) {
      hash_pow[h].reserve(_str.size() + 1);
      _prefix[h] = {0};
      _prefix[h].reserve(_str.size() + 1);
      if (BUILD_REVERSE) {
        _inv_prefix[h] = {0};
        _inv_prefix[h].reserve(_str.size() + 1);
      }
    }
    for (auto &c : _str) add_char(c);
  }
  uint64_t _single_hash(int h, int start, int end) const {
    uint64_t power = uint64_t(hash_pow[h][end - start]);
    return (power + uint64_t(_prefix[h][end]) + HASH_P2 -
            uint64_t(_prefix[h][start]) * power) %
           HASH_P;
  }
  uint64_t substring_hash(int start, int end) const {
    assert(0 <= start && start <= end && end <= length());
    return _single_hash(0, start, end) +
           (HASH_COUNT > 1 ? _single_hash(1, start, end) << 32 : 0);
  }
  uint64_t complete_hash() const { return substring_hash(0, length()); }
  uint64_t _reverse_single_hash(int h, int start, int end) const {
    uint64_t power = uint64_t(hash_pow[h][end - start]);
    return (power + uint64_t(_inv_prefix[h][end]) * power + HASH_P -
            uint64_t(_inv_prefix[h][start])) %
           HASH_P;
  }
  uint64_t reverse_substring_hash(int start, int end) const {
    assert(0 <= start && start <= end && end <= length());
    return _reverse_single_hash(0, start, end) +
           (HASH_COUNT > 1 ? _reverse_single_hash(1, start, end) << 32 : 0);
  }
  uint64_t reverse_complete_hash() const {
    return reverse_substring_hash(0, length());
  }
  bool equal(int start1, int start2, int length) const {
    return substring_hash(start1, start1 + length) ==
           substring_hash(start2, start2 + length);
  }
  bool is_palindrome(int start, int end) const {
    return substring_hash(start, end) == reverse_substring_hash(start, end);
  }
  int compare(int start1, int start2, int max_length = INF) const;
};
signed main() {
  setIO();
  string s, t;
  rd(s, t);
  string_hash<string> string_h;
  string_h.build(t);
  int64_t a = 0, b = 0;
  for (auto c : s) (c == '1' ? a : b)++;
  int64_t ans = 0;
  for (int64_t x = 1; x <= ((int64_t)(t).size()); ++x) {
    int64_t y = (((int64_t)(t).size()) - a * x) / b;
    if (y >= 1 && a * x + b * y == ((int64_t)(t).size())) {
      int64_t len = 0;
      vector<hash_t> h0, h1;
      for (auto c : s) {
        if (c == '1') {
          h1.push_back(string_h.substring_hash(len, len + x));
          len += x;
        } else {
          h0.push_back(string_h.substring_hash(len, len + y));
          len += y;
        }
      }
      sort((h0).begin(), (h0).end());
      sort((h1).begin(), (h1).end());
      ans += h0.back() == h0.front() && h1.back() == h1.front() &&
             h0.front() != h1.front();
    }
  }
  cout << ans;
}

### Prompt

In Cpp, your task is to solve 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;
template <class A>
void rd(vector<A> &v);
template <class T>
void rd(T &x) {
  cin >> x;
}
template <class H, class... T>
void rd(H &h, T &...t) {
  rd(h);
  rd(t...);
}
template <class A>
void rd(vector<A> &x) {
  for (auto &a : x) rd(a);
}
template <class T>
bool ckmin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
void __p(T a) {
  cout << a;
}
template <typename T, typename F>
void __p(pair<T, F> a) {
  cout << "{";
  __p(a.first);
  cout << ",";
  __p(a.second);
  cout << "}\n";
}
template <typename T>
void __p(std::vector<T> a) {
  cout << "{";
  for (auto it = a.begin(); it < a.end(); it++)
    __p(*it), cout << ",}\n"[it + 1 == a.end()];
}
template <typename T, typename... Arg>
void __p(T a1, Arg... a) {
  __p(a1);
  __p(a...);
}
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : ";
  __p(arg1);
  cout << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  int bracket = 0, i = 0;
  for (;; i++)
    if (names[i] == ',' && bracket == 0)
      break;
    else if (names[i] == '(')
      bracket++;
    else if (names[i] == ')')
      bracket--;
  const char *comma = names + i;
  cout.write(names, comma - names) << " : ";
  __p(arg1);
  cout << " | ";
  __f(comma + 1, args...);
}
void setIO(string s = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.exceptions(cin.failbit);
  cout.precision(15);
  cout << fixed;
  if (((int)(s).size())) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
  }
}
template <const unsigned &MOD>
struct _m_uint {
  unsigned val;
  _m_uint(int64_t v = 0) {
    if (v < 0) v = v % MOD + MOD;
    if (v >= MOD) v %= MOD;
    val = unsigned(v);
  }
  _m_uint(uint64_t v) {
    if (v >= MOD) v %= MOD;
    val = unsigned(v);
  }
  _m_uint(int v) : _m_uint(int64_t(v)) {}
  _m_uint(unsigned v) : _m_uint(uint64_t(v)) {}
  explicit operator unsigned() const { return val; }
  explicit operator int64_t() const { return val; }
  explicit operator uint64_t() const { return val; }
  explicit operator double() const { return val; }
  explicit operator long double() const { return val; }
  _m_uint &operator+=(const _m_uint &other) {
    val = val < MOD - other.val ? val + other.val : val - (MOD - other.val);
    return *this;
  }
  _m_uint &operator-=(const _m_uint &other) {
    val = val < other.val ? val + (MOD - other.val) : val - other.val;
    return *this;
  }
  static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
    return unsigned(x % m);
    unsigned x_high = unsigned(x >> 32), x_low = unsigned(x);
    unsigned quot, rem;
    asm("divl %4\n" : "=a"(quot), "=d"(rem) : "d"(x_high), "a"(x_low), "r"(m));
    return rem;
  }
  _m_uint &operator*=(const _m_uint &other) {
    val = fast_mod(uint64_t(val) * other.val);
    return *this;
  }
  _m_uint &operator/=(const _m_uint &other) { return *this *= other.inv(); }
  friend _m_uint operator+(const _m_uint &a, const _m_uint &b) {
    return _m_uint(a) += b;
  }
  friend _m_uint operator-(const _m_uint &a, const _m_uint &b) {
    return _m_uint(a) -= b;
  }
  friend _m_uint operator*(const _m_uint &a, const _m_uint &b) {
    return _m_uint(a) *= b;
  }
  friend _m_uint operator/(const _m_uint &a, const _m_uint &b) {
    return _m_uint(a) /= b;
  }
  _m_uint &operator++() {
    val = val == MOD - 1 ? 0 : val + 1;
    return *this;
  }
  _m_uint &operator--() {
    val = val == 0 ? MOD - 1 : val - 1;
    return *this;
  }
  _m_uint operator++(int) {
    _m_uint before = *this;
    ++*this;
    return before;
  }
  _m_uint operator--(int) {
    _m_uint before = *this;
    --*this;
    return before;
  }
  _m_uint operator-() const { return val == 0 ? 0 : MOD - val; }
  friend bool operator==(const _m_uint &a, const _m_uint &b) {
    return a.val == b.val;
  }
  friend bool operator!=(const _m_uint &a, const _m_uint &b) {
    return a.val != b.val;
  }
  friend bool operator<(const _m_uint &a, const _m_uint &b) {
    return a.val < b.val;
  }
  friend bool operator>(const _m_uint &a, const _m_uint &b) {
    return a.val > b.val;
  }
  friend bool operator<=(const _m_uint &a, const _m_uint &b) {
    return a.val <= b.val;
  }
  friend bool operator>=(const _m_uint &a, const _m_uint &b) {
    return a.val >= b.val;
  }
  static const int SAVE_INV = int(1e6) + 5;
  static _m_uint save_inv[SAVE_INV];
  static void prepare_inv() {
    for (int64_t p = 2; p * p <= MOD; p += p % 2 + 1) {
      assert(MOD % p != 0);
    }
    save_inv[0] = 0;
    save_inv[1] = 1;
    for (int i = 2; i < SAVE_INV; i++) {
      save_inv[i] = save_inv[MOD % i] * (MOD - MOD / i);
    }
  }
  _m_uint inv() const {
    if (save_inv[1] == 0) prepare_inv();
    if (val < SAVE_INV) return save_inv[val];
    _m_uint product = 1;
    unsigned v = val;
    while (v >= SAVE_INV) {
      product *= MOD - MOD / v;
      v = MOD % v;
    }
    return product * save_inv[v];
  }
  _m_uint pow(int64_t p) const {
    if (p < 0) return inv().pow(-p);
    _m_uint a = *this, result = 1;
    while (p > 0) {
      if (p & 1) result *= a;
      p >>= 1;
      if (p > 0) a *= a;
    }
    return result;
  }
  friend ostream &operator<<(ostream &os, const _m_uint &m) {
    return os << m.val;
  }
};
template <const unsigned &MOD>
_m_uint<MOD> _m_uint<MOD>::save_inv[_m_uint<MOD>::SAVE_INV];
auto random_address = [] {
  char *p = new char;
  delete p;
  return uint64_t(p);
};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() *
               (random_address() | 1));
extern const unsigned HASH_P = unsigned(-13337);
using hash_int = _m_uint<HASH_P>;
using hash_t = uint64_t;
const uint64_t HASH_P2 = uint64_t(HASH_P) * HASH_P;
const int HASH_COUNT = 2;
uniform_int_distribution<unsigned> MULT_DIST(unsigned(0.1 * HASH_P),
                                             unsigned(0.9 * HASH_P));
const hash_int HASH_MULT[] = {MULT_DIST(rng), MULT_DIST(rng)};
const hash_int HASH_INV[] = {1 / HASH_MULT[0], 1 / HASH_MULT[1]};
vector<hash_int> hash_pow[] = {{1}, {1}};
const int INF = int(1e9) + 5;
template <typename T_string = string>
struct string_hash {
  static const bool BUILD_REVERSE = false;
  static uint64_t hash(const T_string &str) {
    uint64_t result = 0;
    for (int h = 0; h < HASH_COUNT; h++) {
      uint64_t value = 1;
      for (const auto &x : str) {
        value = (uint64_t(HASH_MULT[h]) * value + x) % HASH_P;
      }
      result += value << (32 * h);
    }
    return result;
  }
  T_string str;
  vector<hash_int> _prefix[HASH_COUNT];
  vector<hash_int> _inv_prefix[HASH_COUNT];
  string_hash() { build({}); }
  string_hash(const T_string &_str) { build(_str); }
  int length() const { return int(_prefix[0].size()) - 1; }
  template <typename T_char>
  void add_char(const T_char &c) {
    str.push_back(c);
    for (int h = 0; h < HASH_COUNT; h++) {
      _prefix[h].push_back(HASH_MULT[h] * _prefix[h].back() + c);
      if (hash_pow[h].size() < _prefix[h].size()) {
        hash_pow[h].push_back(HASH_MULT[h] * hash_pow[h].back());
      }
      if (BUILD_REVERSE) {
        _inv_prefix[h].push_back((_inv_prefix[h].back() + c) * HASH_INV[h]);
      }
    }
  }
  void pop_char() {
    str.pop_back();
    for (int h = 0; h < HASH_COUNT; h++) {
      _prefix[h].pop_back();
      if (BUILD_REVERSE) {
        _inv_prefix[h].pop_back();
      }
    }
  }
  void build(const T_string &_str) {
    str = {};
    str.reserve(_str.size());
    for (int h = 0; h < HASH_COUNT; h++) {
      hash_pow[h].reserve(_str.size() + 1);
      _prefix[h] = {0};
      _prefix[h].reserve(_str.size() + 1);
      if (BUILD_REVERSE) {
        _inv_prefix[h] = {0};
        _inv_prefix[h].reserve(_str.size() + 1);
      }
    }
    for (auto &c : _str) add_char(c);
  }
  uint64_t _single_hash(int h, int start, int end) const {
    uint64_t power = uint64_t(hash_pow[h][end - start]);
    return (power + uint64_t(_prefix[h][end]) + HASH_P2 -
            uint64_t(_prefix[h][start]) * power) %
           HASH_P;
  }
  uint64_t substring_hash(int start, int end) const {
    assert(0 <= start && start <= end && end <= length());
    return _single_hash(0, start, end) +
           (HASH_COUNT > 1 ? _single_hash(1, start, end) << 32 : 0);
  }
  uint64_t complete_hash() const { return substring_hash(0, length()); }
  uint64_t _reverse_single_hash(int h, int start, int end) const {
    uint64_t power = uint64_t(hash_pow[h][end - start]);
    return (power + uint64_t(_inv_prefix[h][end]) * power + HASH_P -
            uint64_t(_inv_prefix[h][start])) %
           HASH_P;
  }
  uint64_t reverse_substring_hash(int start, int end) const {
    assert(0 <= start && start <= end && end <= length());
    return _reverse_single_hash(0, start, end) +
           (HASH_COUNT > 1 ? _reverse_single_hash(1, start, end) << 32 : 0);
  }
  uint64_t reverse_complete_hash() const {
    return reverse_substring_hash(0, length());
  }
  bool equal(int start1, int start2, int length) const {
    return substring_hash(start1, start1 + length) ==
           substring_hash(start2, start2 + length);
  }
  bool is_palindrome(int start, int end) const {
    return substring_hash(start, end) == reverse_substring_hash(start, end);
  }
  int compare(int start1, int start2, int max_length = INF) const;
};
signed main() {
  setIO();
  string s, t;
  rd(s, t);
  string_hash<string> string_h;
  string_h.build(t);
  int64_t a = 0, b = 0;
  for (auto c : s) (c == '1' ? a : b)++;
  int64_t ans = 0;
  for (int64_t x = 1; x <= ((int64_t)(t).size()); ++x) {
    int64_t y = (((int64_t)(t).size()) - a * x) / b;
    if (y >= 1 && a * x + b * y == ((int64_t)(t).size())) {
      int64_t len = 0;
      vector<hash_t> h0, h1;
      for (auto c : s) {
        if (c == '1') {
          h1.push_back(string_h.substring_hash(len, len + x));
          len += x;
        } else {
          h0.push_back(string_h.substring_hash(len, len + y));
          len += y;
        }
      }
      sort((h0).begin(), (h0).end());
      sort((h1).begin(), (h1).end());
      ans += h0.back() == h0.front() && h1.back() == h1.front() &&
             h0.front() != h1.front();
    }
  }
  cout << ans;
}

```