#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
long long mod;
bool isPrime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int n;
string s, t;
long long sufSum[1000001];
long long pow30[1000001];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  while (mod < 1e9) mod = rand() * rand();
  while (!isPrime(mod)) mod++;
  cin >> s >> t;
  int n = t.size();
  long long p = 1;
  pow30[0] = 1;
  for (int i = n - 1; i >= 0; i--) {
    sufSum[i] = ((long long)(t[i] - 'a' + 1) * p) % mod;
    sufSum[i] += sufSum[i + 1];
    sufSum[i] %= mod;
    p *= 30ll;
    p %= mod;
    pow30[n - i] = p;
  }
  long long cnt0 = 0, cnt1 = 0;
  for (char i : s) {
    if (i == '0')
      cnt0++;
    else
      cnt1++;
  }
  int ans = 0;
  for (long long i = 1; i <= n; i++) {
    if ((n - i * cnt0) % cnt1 == 0 && n - i * cnt0 > 0) {
      long long len0 = i;
      long long len1 = (n - i * cnt0) / cnt1;
      int c0 = 0;
      int c1 = 0;
      int pos = 0;
      long long hash0 = -1;
      long long hash1 = -1;
      for (char j : s) {
        if (j == '0') {
          if (hash0 == -1) {
            hash0 = (sufSum[pos] - sufSum[pos + len0] + mod) % mod;
            hash0 *= pow30[pos + len0];
            hash0 %= mod;
          }
          pos += len0;
        } else {
          if (hash1 == -1) {
            hash1 = (sufSum[pos] - sufSum[pos + len1] + mod) % mod;
            hash1 *= pow30[pos + len1];
            hash1 %= mod;
          }
          pos += len1;
        }
      }
      if (hash0 == hash1) continue;
      long long curhash = 0;
      for (int j : s) {
        if (j == '0') {
          curhash *= pow30[len0];
          curhash %= mod;
          curhash += hash0;
          curhash %= mod;
        } else {
          curhash *= pow30[len1];
          curhash %= mod;
          curhash += hash1;
          curhash %= mod;
        }
      }
      if ((sufSum[0] * pow30[n]) % mod == curhash) {
        ans++;
      }
    }
  }
  cout << ans;
}

### Prompt

Generate 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 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
long long mod;
bool isPrime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int n;
string s, t;
long long sufSum[1000001];
long long pow30[1000001];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  while (mod < 1e9) mod = rand() * rand();
  while (!isPrime(mod)) mod++;
  cin >> s >> t;
  int n = t.size();
  long long p = 1;
  pow30[0] = 1;
  for (int i = n - 1; i >= 0; i--) {
    sufSum[i] = ((long long)(t[i] - 'a' + 1) * p) % mod;
    sufSum[i] += sufSum[i + 1];
    sufSum[i] %= mod;
    p *= 30ll;
    p %= mod;
    pow30[n - i] = p;
  }
  long long cnt0 = 0, cnt1 = 0;
  for (char i : s) {
    if (i == '0')
      cnt0++;
    else
      cnt1++;
  }
  int ans = 0;
  for (long long i = 1; i <= n; i++) {
    if ((n - i * cnt0) % cnt1 == 0 && n - i * cnt0 > 0) {
      long long len0 = i;
      long long len1 = (n - i * cnt0) / cnt1;
      int c0 = 0;
      int c1 = 0;
      int pos = 0;
      long long hash0 = -1;
      long long hash1 = -1;
      for (char j : s) {
        if (j == '0') {
          if (hash0 == -1) {
            hash0 = (sufSum[pos] - sufSum[pos + len0] + mod) % mod;
            hash0 *= pow30[pos + len0];
            hash0 %= mod;
          }
          pos += len0;
        } else {
          if (hash1 == -1) {
            hash1 = (sufSum[pos] - sufSum[pos + len1] + mod) % mod;
            hash1 *= pow30[pos + len1];
            hash1 %= mod;
          }
          pos += len1;
        }
      }
      if (hash0 == hash1) continue;
      long long curhash = 0;
      for (int j : s) {
        if (j == '0') {
          curhash *= pow30[len0];
          curhash %= mod;
          curhash += hash0;
          curhash %= mod;
        } else {
          curhash *= pow30[len1];
          curhash %= mod;
          curhash += hash1;
          curhash %= mod;
        }
      }
      if ((sufSum[0] * pow30[n]) % mod == curhash) {
        ans++;
      }
    }
  }
  cout << ans;
}

```