#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() *
               ((uint64_t) new char | 1));
const uint64_t HASH_MULT = (rng() & ~7) + (rng() % 2 ? 3 : 5);
vector<uint64_t> hash_pow;
template <typename T_string>
struct string_hash {
  static const unsigned JUMP = 1024;
  vector<uint64_t> prefix_hash;
  vector<uint64_t> jump_prefix;
  string_hash(const T_string &str = {}) { build(str); }
  uint64_t get_jump_prefix(unsigned index) const {
    return index < JUMP ? 0 : jump_prefix[index - JUMP];
  }
  void build(const T_string &str) {
    if (hash_pow.empty()) hash_pow = {1};
    while (hash_pow.size() <= str.size())
      hash_pow.push_back(HASH_MULT * hash_pow.back());
    prefix_hash.resize(str.size() + 1);
    prefix_hash[0] = 0;
    for (int i = 0; i < (int)str.size(); i++)
      prefix_hash[i + 1] = HASH_MULT * prefix_hash[i] + str[i];
    jump_prefix.resize(str.size());
    for (int i = 0; i < (int)str.size(); i++)
      jump_prefix[i] = HASH_MULT * get_jump_prefix(i) + str[i];
  }
  uint64_t substring_hash(int start, int end) const {
    return prefix_hash[end] - prefix_hash[start] * hash_pow[end - start];
  }
  uint64_t jump_hash(unsigned start, unsigned end) const {
    end += (start - end) & (JUMP - 1);
    return get_jump_prefix(end) -
           get_jump_prefix(start) * hash_pow[(end - start) / JUMP];
  }
  uint64_t combined_hash(int start, int end) const {
    return substring_hash(start, end) +
           jump_hash(start, end) * hash_pow[end - start];
  }
  bool equal(int start1, int start2, int length) const {
    if (substring_hash(start1, start1 + length) !=
        substring_hash(start2, start2 + length))
      return false;
    return jump_hash(start1, start1 + length) ==
           jump_hash(start2, start2 + length);
  }
};
int N, M;
string S, T;
string_hash<string> hasher;
bool check(long long len0, long long len1) {
  int loc0 = -1, loc1 = -1, position = 0;
  for (int i = 0; i < N; i++)
    if (S[i] == '0') {
      if (loc0 == -1)
        loc0 = position;
      else if (!hasher.equal(loc0, position, len0))
        return false;
      position += len0;
    } else {
      if (loc1 == -1)
        loc1 = position;
      else if (!hasher.equal(loc1, position, len1))
        return false;
      position += len1;
    }
  assert(position == M);
  assert(loc0 >= 0 && loc1 >= 0);
  return !(len0 == len1 && hasher.equal(loc0, loc1, len0));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> S >> T;
  N = S.size();
  M = T.size();
  hasher.build(T);
  long long zeros = 0, ones = 0;
  for (int i = 0; i < N; i++)
    if (S[i] == '0')
      zeros++;
    else
      ones++;
  long long total = 0;
  for (long long len0 = 1; len0 <= M; len0++) {
    long long remaining = M - zeros * len0;
    if (remaining > 0 && remaining % ones == 0) {
      long long len1 = remaining / ones;
      if (check(len0, len1)) total++;
    }
  }
  cout << total << '\n';
}

### Prompt

Your task is to create 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_64 rng(chrono::steady_clock::now().time_since_epoch().count() *
               ((uint64_t) new char | 1));
const uint64_t HASH_MULT = (rng() & ~7) + (rng() % 2 ? 3 : 5);
vector<uint64_t> hash_pow;
template <typename T_string>
struct string_hash {
  static const unsigned JUMP = 1024;
  vector<uint64_t> prefix_hash;
  vector<uint64_t> jump_prefix;
  string_hash(const T_string &str = {}) { build(str); }
  uint64_t get_jump_prefix(unsigned index) const {
    return index < JUMP ? 0 : jump_prefix[index - JUMP];
  }
  void build(const T_string &str) {
    if (hash_pow.empty()) hash_pow = {1};
    while (hash_pow.size() <= str.size())
      hash_pow.push_back(HASH_MULT * hash_pow.back());
    prefix_hash.resize(str.size() + 1);
    prefix_hash[0] = 0;
    for (int i = 0; i < (int)str.size(); i++)
      prefix_hash[i + 1] = HASH_MULT * prefix_hash[i] + str[i];
    jump_prefix.resize(str.size());
    for (int i = 0; i < (int)str.size(); i++)
      jump_prefix[i] = HASH_MULT * get_jump_prefix(i) + str[i];
  }
  uint64_t substring_hash(int start, int end) const {
    return prefix_hash[end] - prefix_hash[start] * hash_pow[end - start];
  }
  uint64_t jump_hash(unsigned start, unsigned end) const {
    end += (start - end) & (JUMP - 1);
    return get_jump_prefix(end) -
           get_jump_prefix(start) * hash_pow[(end - start) / JUMP];
  }
  uint64_t combined_hash(int start, int end) const {
    return substring_hash(start, end) +
           jump_hash(start, end) * hash_pow[end - start];
  }
  bool equal(int start1, int start2, int length) const {
    if (substring_hash(start1, start1 + length) !=
        substring_hash(start2, start2 + length))
      return false;
    return jump_hash(start1, start1 + length) ==
           jump_hash(start2, start2 + length);
  }
};
int N, M;
string S, T;
string_hash<string> hasher;
bool check(long long len0, long long len1) {
  int loc0 = -1, loc1 = -1, position = 0;
  for (int i = 0; i < N; i++)
    if (S[i] == '0') {
      if (loc0 == -1)
        loc0 = position;
      else if (!hasher.equal(loc0, position, len0))
        return false;
      position += len0;
    } else {
      if (loc1 == -1)
        loc1 = position;
      else if (!hasher.equal(loc1, position, len1))
        return false;
      position += len1;
    }
  assert(position == M);
  assert(loc0 >= 0 && loc1 >= 0);
  return !(len0 == len1 && hasher.equal(loc0, loc1, len0));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> S >> T;
  N = S.size();
  M = T.size();
  hasher.build(T);
  long long zeros = 0, ones = 0;
  for (int i = 0; i < N; i++)
    if (S[i] == '0')
      zeros++;
    else
      ones++;
  long long total = 0;
  for (long long len0 = 1; len0 <= M; len0++) {
    long long remaining = M - zeros * len0;
    if (remaining > 0 && remaining % ones == 0) {
      long long len1 = remaining / ones;
      if (check(len0, len1)) total++;
    }
  }
  cout << total << '\n';
}

```