#include <bits/stdc++.h>
using namespace std;
const int MD = 3;
const int MAX_POW = 1000010;
mt19937 mt(time(0));
int md[MD], p[MD];
int pows[MD][MAX_POW + 10];
void modAdd(int &a, int b, int md) {
  a += b;
  if (a >= md) a -= md;
}
void modSub(int &a, int b, int md) {
  a -= b;
  if (a < 0) a += md;
}
void modMul(int &a, int b, int md) { a = (1ll * a * b) % md; }
bool isPrime(int x) {
  for (int j = 2; j * j <= x; j++) {
    if (x % j == 0) return false;
  }
  return true;
}
void gen() {
  for (int j = 0; j < MD; j++) {
    for (int i = mt() % 2345 + 10000;; i++) {
      if (isPrime(i)) {
        p[j] = i;
        break;
      }
    }
    for (int i = mt() % 23456789 + 1000000000;; i++) {
      if (isPrime(i)) {
        md[j] = i;
        break;
      }
    }
  }
  for (int i = 0; i < MD; i++) pows[i][0] = 1;
  for (int i = 1; i <= MAX_POW; i++) {
    for (int j = 0; j < MD; j++) {
      pows[j][i] = pows[j][i - 1];
      modMul(pows[j][i], p[j], md[j]);
    }
  }
}
vector<int> get_hash(int l, int r, const vector<vector<int> > &pref_hashes) {
  vector<int> result;
  for (int i = 0; i < MD; i++) {
    result.push_back(pref_hashes[i][r]);
  }
  if (l) {
    for (int i = 0; i < MD; i++) {
      modSub(result[i], pref_hashes[i][l - 1], md[i]);
    }
  }
  for (int i = 0; i < MD; i++) {
    modMul(result[i], pows[i][MAX_POW - r], md[i]);
  }
  return result;
}
vector<vector<int> > build_hash(const string &t) {
  int m = t.length();
  vector<vector<int> > pref_hashes(MD, vector<int>(m));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < MD; j++) {
      if (i != 0) modAdd(pref_hashes[j][i], pref_hashes[j][i - 1], md[j]);
      int add = t[i];
      modMul(add, pows[j][i], md[j]);
      modAdd(pref_hashes[j][i], add, md[j]);
    }
  }
  return pref_hashes;
}
string s, t;
int n, m;
int first0 = -1, first1 = -1;
bool check(int r0, int r1, const vector<vector<int> > &pref_hashes) {
  int l_0 = first0 * r1, r_0 = l_0 + r0 - 1;
  int l_1 = first1 * r0, r_1 = l_1 + r1 - 1;
  auto v1 = get_hash(l_0, r_0, pref_hashes);
  auto v2 = get_hash(l_1, r_1, pref_hashes);
  if (v1 == v2) return false;
  int cur = 0;
  for (int j = 0; j < n; j++) {
    if (s[j] == '0') {
      int l = cur, r = cur + r0 - 1;
      auto v = get_hash(l, r, pref_hashes);
      if (v != v1) return false;
      cur += r0;
    } else {
      int l = cur, r = cur + r1 - 1;
      auto v = get_hash(l, r, pref_hashes);
      if (v != v2) return false;
      cur += r1;
    }
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  gen();
  cin >> s >> t;
  n = s.length();
  m = t.length();
  auto pref_hashes = build_hash(t);
  int cnt0 = 0, cnt1 = 0;
  for (auto u : s) {
    if (u == '1')
      cnt1++;
    else
      cnt0++;
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == '0' && first0 == -1) first0 = i;
    if (s[i] == '1' && first1 == -1) first1 = i;
  }
  int an = 0;
  for (int r0 = 1; r0 <= m; r0++) {
    if (1ll * r0 * cnt0 >= m) break;
    if ((m - r0 * cnt0) % cnt1 == 0) {
      int r1 = (m - r0 * cnt0) / cnt1;
      if (check(r0, r1, pref_hashes)) an++;
    }
  }
  cout << an;
  return 0;
}

### 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;
const int MD = 3;
const int MAX_POW = 1000010;
mt19937 mt(time(0));
int md[MD], p[MD];
int pows[MD][MAX_POW + 10];
void modAdd(int &a, int b, int md) {
  a += b;
  if (a >= md) a -= md;
}
void modSub(int &a, int b, int md) {
  a -= b;
  if (a < 0) a += md;
}
void modMul(int &a, int b, int md) { a = (1ll * a * b) % md; }
bool isPrime(int x) {
  for (int j = 2; j * j <= x; j++) {
    if (x % j == 0) return false;
  }
  return true;
}
void gen() {
  for (int j = 0; j < MD; j++) {
    for (int i = mt() % 2345 + 10000;; i++) {
      if (isPrime(i)) {
        p[j] = i;
        break;
      }
    }
    for (int i = mt() % 23456789 + 1000000000;; i++) {
      if (isPrime(i)) {
        md[j] = i;
        break;
      }
    }
  }
  for (int i = 0; i < MD; i++) pows[i][0] = 1;
  for (int i = 1; i <= MAX_POW; i++) {
    for (int j = 0; j < MD; j++) {
      pows[j][i] = pows[j][i - 1];
      modMul(pows[j][i], p[j], md[j]);
    }
  }
}
vector<int> get_hash(int l, int r, const vector<vector<int> > &pref_hashes) {
  vector<int> result;
  for (int i = 0; i < MD; i++) {
    result.push_back(pref_hashes[i][r]);
  }
  if (l) {
    for (int i = 0; i < MD; i++) {
      modSub(result[i], pref_hashes[i][l - 1], md[i]);
    }
  }
  for (int i = 0; i < MD; i++) {
    modMul(result[i], pows[i][MAX_POW - r], md[i]);
  }
  return result;
}
vector<vector<int> > build_hash(const string &t) {
  int m = t.length();
  vector<vector<int> > pref_hashes(MD, vector<int>(m));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < MD; j++) {
      if (i != 0) modAdd(pref_hashes[j][i], pref_hashes[j][i - 1], md[j]);
      int add = t[i];
      modMul(add, pows[j][i], md[j]);
      modAdd(pref_hashes[j][i], add, md[j]);
    }
  }
  return pref_hashes;
}
string s, t;
int n, m;
int first0 = -1, first1 = -1;
bool check(int r0, int r1, const vector<vector<int> > &pref_hashes) {
  int l_0 = first0 * r1, r_0 = l_0 + r0 - 1;
  int l_1 = first1 * r0, r_1 = l_1 + r1 - 1;
  auto v1 = get_hash(l_0, r_0, pref_hashes);
  auto v2 = get_hash(l_1, r_1, pref_hashes);
  if (v1 == v2) return false;
  int cur = 0;
  for (int j = 0; j < n; j++) {
    if (s[j] == '0') {
      int l = cur, r = cur + r0 - 1;
      auto v = get_hash(l, r, pref_hashes);
      if (v != v1) return false;
      cur += r0;
    } else {
      int l = cur, r = cur + r1 - 1;
      auto v = get_hash(l, r, pref_hashes);
      if (v != v2) return false;
      cur += r1;
    }
  }
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  gen();
  cin >> s >> t;
  n = s.length();
  m = t.length();
  auto pref_hashes = build_hash(t);
  int cnt0 = 0, cnt1 = 0;
  for (auto u : s) {
    if (u == '1')
      cnt1++;
    else
      cnt0++;
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == '0' && first0 == -1) first0 = i;
    if (s[i] == '1' && first1 == -1) first1 = i;
  }
  int an = 0;
  for (int r0 = 1; r0 <= m; r0++) {
    if (1ll * r0 * cnt0 >= m) break;
    if ((m - r0 * cnt0) % cnt1 == 0) {
      int r1 = (m - r0 * cnt0) / cnt1;
      if (check(r0, r1, pref_hashes)) an++;
    }
  }
  cout << an;
  return 0;
}

```