#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> t >> s;
  for (auto& c : s) {
    c = c - 'a';
  }
  long long n = s.length();
  long long log_n = 1;
  while (log_n * 2 <= n) {
    log_n *= 2;
  }
  const long long P = 29;
  const long long Q = 1e9 + 7;
  vector<long long> pows(1e6 + 1, 1);
  for (int i = 1; i < pows.size(); ++i) {
    pows[i] = (pows[i - 1] * P) % Q;
  }
  vector<long long> hashp(s.size() + 1);
  for (int i = 0; i < s.size(); ++i) {
    hashp[i + 1] = (hashp[i] + pows[i] * s[i]) % Q;
  }
  auto hash = [&](int i, int len) {
    long long h = (hashp[i + len] - hashp[i] + Q) % Q;
    return (pows[s.size() - i] * h) % Q;
  };
  const int maxlen = 1e6 + 1;
  auto eq = [&](int i, int j, int f) { return hash(i, f) == hash(j, f); };
  vector<pair<int, int>> met(t.length());
  pair<int, int> now(0, 0);
  vector<int> zeros;
  vector<int> ones;
  for (int i = 0; i < t.size(); ++i) {
    met[i] = now;
    if (t[i] == '0') {
      zeros.push_back(i);
      now.first++;
    } else {
      ones.push_back(i);
      now.second++;
    }
  }
  auto get_pos = [&](int i, int zerol, int onel) {
    return met[i].first * zerol + met[i].second * onel;
  };
  auto check_eq = [&](int zerol, int onel, vector<int>& pos, int len) {
    for (int i = 1; i < pos.size(); ++i) {
      if (!eq(get_pos(pos[0], zerol, onel), get_pos(pos[i], zerol, onel),
              len)) {
        return false;
      }
    }
    return true;
  };
  vector<pair<int, int>> sols;
  if (zeros.empty()) {
    if (n % ones.size() == 0) {
      sols.emplace_back(0, n / ones.size());
    }
  }
  if (ones.empty()) {
    if (n % zeros.size() == 0) {
      sols.emplace_back(n / zeros.size(), 0);
    }
  }
  for (long long i = 1; i < s.size(); ++i) {
    long long b = s.size() - static_cast<long long>(zeros.size()) * i;
    if (b > 0 && b % ones.size() == 0) {
      sols.emplace_back(i, b / ones.size());
    }
  }
  int ans = 0;
  for (auto sol : sols) {
    if (check_eq(sol.first, sol.second, zeros, sol.first) &&
        check_eq(sol.first, sol.second, ones, sol.second)) {
      if (sol.first != sol.second ||
          !eq(get_pos(zeros.front(), sol.first, sol.second),
              get_pos(ones.front(), sol.first, sol.second), sol.first)) {
        ans++;
      }
    }
  }
  cout << ans;
}

### 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;
int main() {
  string s, t;
  cin >> t >> s;
  for (auto& c : s) {
    c = c - 'a';
  }
  long long n = s.length();
  long long log_n = 1;
  while (log_n * 2 <= n) {
    log_n *= 2;
  }
  const long long P = 29;
  const long long Q = 1e9 + 7;
  vector<long long> pows(1e6 + 1, 1);
  for (int i = 1; i < pows.size(); ++i) {
    pows[i] = (pows[i - 1] * P) % Q;
  }
  vector<long long> hashp(s.size() + 1);
  for (int i = 0; i < s.size(); ++i) {
    hashp[i + 1] = (hashp[i] + pows[i] * s[i]) % Q;
  }
  auto hash = [&](int i, int len) {
    long long h = (hashp[i + len] - hashp[i] + Q) % Q;
    return (pows[s.size() - i] * h) % Q;
  };
  const int maxlen = 1e6 + 1;
  auto eq = [&](int i, int j, int f) { return hash(i, f) == hash(j, f); };
  vector<pair<int, int>> met(t.length());
  pair<int, int> now(0, 0);
  vector<int> zeros;
  vector<int> ones;
  for (int i = 0; i < t.size(); ++i) {
    met[i] = now;
    if (t[i] == '0') {
      zeros.push_back(i);
      now.first++;
    } else {
      ones.push_back(i);
      now.second++;
    }
  }
  auto get_pos = [&](int i, int zerol, int onel) {
    return met[i].first * zerol + met[i].second * onel;
  };
  auto check_eq = [&](int zerol, int onel, vector<int>& pos, int len) {
    for (int i = 1; i < pos.size(); ++i) {
      if (!eq(get_pos(pos[0], zerol, onel), get_pos(pos[i], zerol, onel),
              len)) {
        return false;
      }
    }
    return true;
  };
  vector<pair<int, int>> sols;
  if (zeros.empty()) {
    if (n % ones.size() == 0) {
      sols.emplace_back(0, n / ones.size());
    }
  }
  if (ones.empty()) {
    if (n % zeros.size() == 0) {
      sols.emplace_back(n / zeros.size(), 0);
    }
  }
  for (long long i = 1; i < s.size(); ++i) {
    long long b = s.size() - static_cast<long long>(zeros.size()) * i;
    if (b > 0 && b % ones.size() == 0) {
      sols.emplace_back(i, b / ones.size());
    }
  }
  int ans = 0;
  for (auto sol : sols) {
    if (check_eq(sol.first, sol.second, zeros, sol.first) &&
        check_eq(sol.first, sol.second, ones, sol.second)) {
      if (sol.first != sol.second ||
          !eq(get_pos(zeros.front(), sol.first, sol.second),
              get_pos(ones.front(), sol.first, sol.second), sol.first)) {
        ans++;
      }
    }
  }
  cout << ans;
}

```