#include <bits/stdc++.h>
using namespace std;
bool isp(int n) {
  if (n % 2 == 0) {
    return false;
  }
  for (int d = 3; d * d <= n; d += 2) {
    if (n % d == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  srand(time(0));
  long long mod = 1000 * 1000 * 1000 + ((rand() % 100) + 1) * 100000;
  while (!isp(mod)) {
    mod--;
  }
  string s, t;
  cin >> s >> t;
  vector<int> zeros, ones;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      zeros.push_back(i);
    } else {
      ones.push_back(i);
    }
  }
  vector<pair<int, int> > goodPairs;
  for (int lenZero = 1; lenZero * zeros.size() < t.length(); lenZero++) {
    int rest = (int)t.length() - lenZero * zeros.size();
    if (rest % ones.size() == 0 && rest > 0) {
      goodPairs.push_back({lenZero, rest / ones.size()});
    }
  }
  vector<pair<int, int> > cntBefore(s.length());
  cntBefore[0] = {0, 0};
  for (int i = 1; i < s.length(); i++) {
    cntBefore[i] = cntBefore[i - 1];
    if (s[i - 1] == '0') {
      cntBefore[i].first++;
    } else {
      cntBefore[i].second++;
    }
  }
  long long p = 100 * ((rand() % 100) + 1);
  while (!isp(p)) {
    p++;
  }
  vector<long long> p_pow(t.length());
  p_pow[0] = 1;
  for (size_t i = 1; i < p_pow.size(); ++i) {
    p_pow[i] = p_pow[i - 1] * p;
    p_pow[i] %= mod;
  }
  vector<long long> h(t.length());
  for (size_t i = 0; i < t.length(); ++i) {
    h[i] = (t[i] - 'a' + 1) * p_pow[i];
    h[i] %= mod;
    if (i) h[i] += h[i - 1];
    h[i] %= mod;
  }
  int ans = 0;
  auto getHash = [&h, &p_pow, mod](int l, int r, int powMul) {
    long long res = h[r];
    if (l > 0) {
      res -= h[l - 1];
    }
    res += mod;
    res %= mod;
    res *= p_pow[powMul];
    res %= mod;
    return res;
  };
  auto getPos = [&s, &cntBefore](int id, int lenZero, int lenOne) {
    int effectivePos =
        cntBefore[id].first * lenZero + cntBefore[id].second * lenOne;
    int end = effectivePos + (s[id] == '0' ? lenZero : lenOne) - 1;
    return pair<int, int>(effectivePos, end);
  };
  for (int i = 0; i < goodPairs.size(); i++) {
    int lenZero = goodPairs[i].first;
    int lenOne = goodPairs[i].second;
    bool ok = true;
    if (ones.size() > 1) {
      auto refPos = getPos(ones[0], lenZero, lenOne);
      for (int j = 1; j < ones.size(); j++) {
        auto curPos = getPos(ones[j], lenZero, lenOne);
        auto refHash =
            getHash(refPos.first, refPos.second, curPos.first - refPos.first);
        auto curHash = getHash(curPos.first, curPos.second, 0);
        if (refHash != curHash) {
          ok = false;
          break;
        }
      }
    }
    if (zeros.size() > 1 && ok) {
      auto refPos = getPos(zeros[0], lenZero, lenOne);
      for (int j = 1; j < zeros.size(); j++) {
        auto curPos = getPos(zeros[j], lenZero, lenOne);
        auto refHash =
            getHash(refPos.first, refPos.second, curPos.first - refPos.first);
        auto curHash = getHash(curPos.first, curPos.second, 0);
        if (refHash != curHash) {
          ok = false;
          break;
        }
      }
    }
    if (ok && lenOne == lenZero) {
      auto posZero = getPos(zeros[0], lenZero, lenOne);
      auto posOne = getPos(ones[0], lenZero, lenOne);
      long long hashZero, hashOne;
      if (s[0] == '0') {
        hashZero = getHash(posZero.first, posZero.second,
                           posOne.first - posZero.first);
        hashOne = getHash(posOne.first, posOne.second, 0);
      } else {
        hashZero = getHash(posZero.first, posZero.second, 0);
        hashOne =
            getHash(posOne.first, posOne.second, posZero.first - posOne.first);
      }
      if (hashOne == hashZero) {
        ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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;
bool isp(int n) {
  if (n % 2 == 0) {
    return false;
  }
  for (int d = 3; d * d <= n; d += 2) {
    if (n % d == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  srand(time(0));
  long long mod = 1000 * 1000 * 1000 + ((rand() % 100) + 1) * 100000;
  while (!isp(mod)) {
    mod--;
  }
  string s, t;
  cin >> s >> t;
  vector<int> zeros, ones;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      zeros.push_back(i);
    } else {
      ones.push_back(i);
    }
  }
  vector<pair<int, int> > goodPairs;
  for (int lenZero = 1; lenZero * zeros.size() < t.length(); lenZero++) {
    int rest = (int)t.length() - lenZero * zeros.size();
    if (rest % ones.size() == 0 && rest > 0) {
      goodPairs.push_back({lenZero, rest / ones.size()});
    }
  }
  vector<pair<int, int> > cntBefore(s.length());
  cntBefore[0] = {0, 0};
  for (int i = 1; i < s.length(); i++) {
    cntBefore[i] = cntBefore[i - 1];
    if (s[i - 1] == '0') {
      cntBefore[i].first++;
    } else {
      cntBefore[i].second++;
    }
  }
  long long p = 100 * ((rand() % 100) + 1);
  while (!isp(p)) {
    p++;
  }
  vector<long long> p_pow(t.length());
  p_pow[0] = 1;
  for (size_t i = 1; i < p_pow.size(); ++i) {
    p_pow[i] = p_pow[i - 1] * p;
    p_pow[i] %= mod;
  }
  vector<long long> h(t.length());
  for (size_t i = 0; i < t.length(); ++i) {
    h[i] = (t[i] - 'a' + 1) * p_pow[i];
    h[i] %= mod;
    if (i) h[i] += h[i - 1];
    h[i] %= mod;
  }
  int ans = 0;
  auto getHash = [&h, &p_pow, mod](int l, int r, int powMul) {
    long long res = h[r];
    if (l > 0) {
      res -= h[l - 1];
    }
    res += mod;
    res %= mod;
    res *= p_pow[powMul];
    res %= mod;
    return res;
  };
  auto getPos = [&s, &cntBefore](int id, int lenZero, int lenOne) {
    int effectivePos =
        cntBefore[id].first * lenZero + cntBefore[id].second * lenOne;
    int end = effectivePos + (s[id] == '0' ? lenZero : lenOne) - 1;
    return pair<int, int>(effectivePos, end);
  };
  for (int i = 0; i < goodPairs.size(); i++) {
    int lenZero = goodPairs[i].first;
    int lenOne = goodPairs[i].second;
    bool ok = true;
    if (ones.size() > 1) {
      auto refPos = getPos(ones[0], lenZero, lenOne);
      for (int j = 1; j < ones.size(); j++) {
        auto curPos = getPos(ones[j], lenZero, lenOne);
        auto refHash =
            getHash(refPos.first, refPos.second, curPos.first - refPos.first);
        auto curHash = getHash(curPos.first, curPos.second, 0);
        if (refHash != curHash) {
          ok = false;
          break;
        }
      }
    }
    if (zeros.size() > 1 && ok) {
      auto refPos = getPos(zeros[0], lenZero, lenOne);
      for (int j = 1; j < zeros.size(); j++) {
        auto curPos = getPos(zeros[j], lenZero, lenOne);
        auto refHash =
            getHash(refPos.first, refPos.second, curPos.first - refPos.first);
        auto curHash = getHash(curPos.first, curPos.second, 0);
        if (refHash != curHash) {
          ok = false;
          break;
        }
      }
    }
    if (ok && lenOne == lenZero) {
      auto posZero = getPos(zeros[0], lenZero, lenOne);
      auto posOne = getPos(ones[0], lenZero, lenOne);
      long long hashZero, hashOne;
      if (s[0] == '0') {
        hashZero = getHash(posZero.first, posZero.second,
                           posOne.first - posZero.first);
        hashOne = getHash(posOne.first, posOne.second, 0);
      } else {
        hashZero = getHash(posZero.first, posZero.second, 0);
        hashOne =
            getHash(posOne.first, posOne.second, posZero.first - posOne.first);
      }
      if (hashOne == hashZero) {
        ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}

```