#include <bits/stdc++.h>
using namespace std;
long long val1[1000005];
long long val2[1000005];
long long prime1[1000005];
long long prime2[1000005];
long long int cnt[2];
pair<long long, long long> getHash(int a, int b) {
  long long v1 = (val1[b] - val1[a - 1] * prime1[b - a + 1]) % 1000000009;
  v1 = (v1 + 1000000009) % 1000000009;
  long long v2 = (val2[b] - val2[a - 1] * prime2[b - a + 1]) % 1000000007;
  v2 = (v2 + 1000000007) % 1000000007;
  return make_pair(v1, v2);
}
long long power(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  long long f = power(a, b / 2, mod);
  f = (f * f) % mod;
  if (b % 2) return (a * f) % mod;
  return f;
}
long long zero1, zero2;
long long one1, one2;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); ++i) {
    ++cnt[s[i] - '0'];
  }
  prime1[0] = prime2[0] = 1;
  for (int i = 0; i < t.size(); ++i) {
    val1[i + 1] = (val1[i] * 1299821 + t[i] - 'a' + 1) % 1000000009;
    val2[i + 1] = (val2[i] * 1300709 + t[i] - 'a' + 1) % 1000000007;
    prime1[i + 1] = (prime1[i] * 1299821) % 1000000009;
    prime2[i + 1] = (prime2[i] * 1300709) % 1000000007;
  }
  int st = s[0] - '0';
  int wo = 0;
  for (int j = 0; j < s.size(); ++j) {
    if (s[j] == s[0])
      ++wo;
    else
      break;
  }
  int vua = s.size();
  for (int j = wo; j < s.size(); ++j) {
    if (s[j] == s[0]) {
      vua = j;
      break;
    }
  }
  long long ans = 0;
  for (long long int i = 1; i < t.size(); ++i) {
    long long v = cnt[st] * i;
    int ot = st ^ 1;
    long long rem = (long long)t.size() - v;
    if (rem <= 0 || rem % cnt[ot]) continue;
    long long w = rem / cnt[ot];
    auto u = getHash(1, i);
    long long v1 = (power(1299821, i * wo, 1000000009) - 1) *
                   (power(prime1[i] - 1, 1000000009 - 2, 1000000009));
    v1 = (v1 % 1000000009 + 1000000009) % 1000000009;
    long long v2 = (power(1300709, i * wo, 1000000007) - 1) *
                   (power(prime2[i] - 1, 1000000007 - 2, 1000000007));
    v2 = (v2 % 1000000007 + 1000000007) % 1000000007;
    auto qw = getHash(1, i * wo);
    auto u1 = getHash(i * wo + 1, i * wo + w);
    if (u == u1) continue;
    long long ans1 = 0;
    long long ans2 = 0;
    long long dig = 0;
    for (int j = 0; j < s.size(); ++j) {
      if (s[j] == '0' + st) {
        ans1 = (ans1 * prime1[i] + u.first) % 1000000009;
        ans2 = (ans2 * prime2[i] + u.second) % 1000000007;
        dig += i;
      } else {
        ans1 = (ans1 * prime1[w] + u1.first) % 1000000009;
        ans2 = (ans2 * prime2[w] + u1.second) % 1000000007;
        dig += w;
      }
      if (getHash(1, dig) != make_pair(ans1, ans2)) break;
    }
    if (make_pair(ans1, ans2) == getHash(1, t.size())) ++ans;
  }
  cout << ans << endl;
  return 0;
}

### Prompt

In CPP, your task is to solve 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;
long long val1[1000005];
long long val2[1000005];
long long prime1[1000005];
long long prime2[1000005];
long long int cnt[2];
pair<long long, long long> getHash(int a, int b) {
  long long v1 = (val1[b] - val1[a - 1] * prime1[b - a + 1]) % 1000000009;
  v1 = (v1 + 1000000009) % 1000000009;
  long long v2 = (val2[b] - val2[a - 1] * prime2[b - a + 1]) % 1000000007;
  v2 = (v2 + 1000000007) % 1000000007;
  return make_pair(v1, v2);
}
long long power(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  long long f = power(a, b / 2, mod);
  f = (f * f) % mod;
  if (b % 2) return (a * f) % mod;
  return f;
}
long long zero1, zero2;
long long one1, one2;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); ++i) {
    ++cnt[s[i] - '0'];
  }
  prime1[0] = prime2[0] = 1;
  for (int i = 0; i < t.size(); ++i) {
    val1[i + 1] = (val1[i] * 1299821 + t[i] - 'a' + 1) % 1000000009;
    val2[i + 1] = (val2[i] * 1300709 + t[i] - 'a' + 1) % 1000000007;
    prime1[i + 1] = (prime1[i] * 1299821) % 1000000009;
    prime2[i + 1] = (prime2[i] * 1300709) % 1000000007;
  }
  int st = s[0] - '0';
  int wo = 0;
  for (int j = 0; j < s.size(); ++j) {
    if (s[j] == s[0])
      ++wo;
    else
      break;
  }
  int vua = s.size();
  for (int j = wo; j < s.size(); ++j) {
    if (s[j] == s[0]) {
      vua = j;
      break;
    }
  }
  long long ans = 0;
  for (long long int i = 1; i < t.size(); ++i) {
    long long v = cnt[st] * i;
    int ot = st ^ 1;
    long long rem = (long long)t.size() - v;
    if (rem <= 0 || rem % cnt[ot]) continue;
    long long w = rem / cnt[ot];
    auto u = getHash(1, i);
    long long v1 = (power(1299821, i * wo, 1000000009) - 1) *
                   (power(prime1[i] - 1, 1000000009 - 2, 1000000009));
    v1 = (v1 % 1000000009 + 1000000009) % 1000000009;
    long long v2 = (power(1300709, i * wo, 1000000007) - 1) *
                   (power(prime2[i] - 1, 1000000007 - 2, 1000000007));
    v2 = (v2 % 1000000007 + 1000000007) % 1000000007;
    auto qw = getHash(1, i * wo);
    auto u1 = getHash(i * wo + 1, i * wo + w);
    if (u == u1) continue;
    long long ans1 = 0;
    long long ans2 = 0;
    long long dig = 0;
    for (int j = 0; j < s.size(); ++j) {
      if (s[j] == '0' + st) {
        ans1 = (ans1 * prime1[i] + u.first) % 1000000009;
        ans2 = (ans2 * prime2[i] + u.second) % 1000000007;
        dig += i;
      } else {
        ans1 = (ans1 * prime1[w] + u1.first) % 1000000009;
        ans2 = (ans2 * prime2[w] + u1.second) % 1000000007;
        dig += w;
      }
      if (getHash(1, dig) != make_pair(ans1, ans2)) break;
    }
    if (make_pair(ans1, ans2) == getHash(1, t.size())) ++ans;
  }
  cout << ans << endl;
  return 0;
}

```