#include <bits/stdc++.h>
using namespace std;
const int rbase[] = {29, 31, 33, 39, 41, 43, 101};
long long Rand(long long l, long long r) {
  return ((long long)rand() * (RAND_MAX + 1) * (RAND_MAX + 1) * (RAND_MAX + 1) +
          (long long)rand() * (RAND_MAX + 1) * (RAND_MAX + 1) +
          (long long)rand() * (RAND_MAX + 1) + (long long)rand()) %
             (r - l + 1) +
         l;
}
long long base[2];
string s, t;
long long Hash[2][1010100], POW[2][1010100];
const long long MOD = 1e9 + 7;
int n, m, a;
void Init() {
  for (int j = 0; j < (2); ++j) {
    Hash[j][0] = 0;
    POW[j][0] = 1;
    for (int i = (1); i <= (m); ++i) {
      POW[j][i] = POW[j][i - 1] * base[j] % MOD;
      Hash[j][i] = (Hash[j][i - 1] * base[j] + (t[i - 1] - 'a' + 1)) % MOD;
    }
  }
}
pair<long long, long long> Get(int l, int r) {
  return pair<long long, long long>(
      (Hash[0][r] - Hash[0][l - 1] * POW[0][r - l + 1] + MOD * MOD) % MOD,
      (Hash[1][r] - Hash[1][l - 1] * POW[1][r - l + 1] + MOD * MOD) % MOD);
}
int Ok(int x, int y) {
  int l = 1;
  pair<long long, long long> h0, h1;
  int ok0 = 0, ok1 = 0;
  for (char c : s) {
    if (c == '0') {
      if (ok0) {
        if (Get(l, l + x - 1) != h0) return 0;
      } else {
        ok0 = 1;
        h0 = Get(l, l + x - 1);
      }
      l += x;
    } else {
      if (ok1) {
        if (Get(l, l + y - 1) != h1) return 0;
      } else {
        ok1 = 1;
        h1 = Get(l, l + y - 1);
      }
      l += y;
    }
  }
  return x != y || h0 != h1;
}
int main() {
  srand(time(NULL));
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  base[0] = Rand(0, 5);
  base[1] = Rand(base[0] + 1, 6);
  base[0] = rbase[base[0]];
  base[1] = rbase[base[1]];
  cin >> s >> t;
  int a = 0;
  for (char c : s)
    if (c == '0') ++a;
  n = s.size();
  m = t.size();
  Init();
  int cnt = 0;
  for (int x = (1); x <= (m); ++x) {
    long long y = m - 1ll * x * a;
    if (y < n - a) continue;
    if (y % (n - a)) continue;
    y /= (n - a);
    if (Ok(x, y)) cnt++;
  }
  cout << cnt;
}

### 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;
const int rbase[] = {29, 31, 33, 39, 41, 43, 101};
long long Rand(long long l, long long r) {
  return ((long long)rand() * (RAND_MAX + 1) * (RAND_MAX + 1) * (RAND_MAX + 1) +
          (long long)rand() * (RAND_MAX + 1) * (RAND_MAX + 1) +
          (long long)rand() * (RAND_MAX + 1) + (long long)rand()) %
             (r - l + 1) +
         l;
}
long long base[2];
string s, t;
long long Hash[2][1010100], POW[2][1010100];
const long long MOD = 1e9 + 7;
int n, m, a;
void Init() {
  for (int j = 0; j < (2); ++j) {
    Hash[j][0] = 0;
    POW[j][0] = 1;
    for (int i = (1); i <= (m); ++i) {
      POW[j][i] = POW[j][i - 1] * base[j] % MOD;
      Hash[j][i] = (Hash[j][i - 1] * base[j] + (t[i - 1] - 'a' + 1)) % MOD;
    }
  }
}
pair<long long, long long> Get(int l, int r) {
  return pair<long long, long long>(
      (Hash[0][r] - Hash[0][l - 1] * POW[0][r - l + 1] + MOD * MOD) % MOD,
      (Hash[1][r] - Hash[1][l - 1] * POW[1][r - l + 1] + MOD * MOD) % MOD);
}
int Ok(int x, int y) {
  int l = 1;
  pair<long long, long long> h0, h1;
  int ok0 = 0, ok1 = 0;
  for (char c : s) {
    if (c == '0') {
      if (ok0) {
        if (Get(l, l + x - 1) != h0) return 0;
      } else {
        ok0 = 1;
        h0 = Get(l, l + x - 1);
      }
      l += x;
    } else {
      if (ok1) {
        if (Get(l, l + y - 1) != h1) return 0;
      } else {
        ok1 = 1;
        h1 = Get(l, l + y - 1);
      }
      l += y;
    }
  }
  return x != y || h0 != h1;
}
int main() {
  srand(time(NULL));
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  base[0] = Rand(0, 5);
  base[1] = Rand(base[0] + 1, 6);
  base[0] = rbase[base[0]];
  base[1] = rbase[base[1]];
  cin >> s >> t;
  int a = 0;
  for (char c : s)
    if (c == '0') ++a;
  n = s.size();
  m = t.size();
  Init();
  int cnt = 0;
  for (int x = (1); x <= (m); ++x) {
    long long y = m - 1ll * x * a;
    if (y < n - a) continue;
    if (y % (n - a)) continue;
    y /= (n - a);
    if (Ok(x, y)) cnt++;
  }
  cout << cnt;
}

```