#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-5;
const int p = 131;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int N = 1e7 + 10;
long long Hash[N], fac[N];
char s[N], ss[N];
long long get(int l, int r) {
  return (Hash[r] - Hash[l - 1] * fac[r - l + 1] % mod + mod) % mod;
}
void run() {
  scanf("%s %s", s + 1, ss + 1);
  int len1 = strlen(s + 1);
  int len2 = strlen(ss + 1);
  fac[0] = 1;
  int n0 = 0, n1 = 0;
  for (int i = 1; i <= len1; i++) {
    n0 += (s[i] == '0');
    n1 += (s[i] == '1');
  }
  for (int i = 1; i <= len2; i++) {
    Hash[i] = (Hash[i - 1] * p % mod + ss[i] - 'a' + 1) % mod;
    fac[i] = fac[i - 1] * p % mod;
  }
  int res = 0;
  for (int l0 = 1, l1; l0 < len2; l0++) {
    if (l0 * n0 >= len2) break;
    if ((len2 - l0 * n0) % n1) continue;
    l1 = (len2 - l0 * n0) / n1;
    long long hash0 = -1, hash1 = -1;
    int idx = 1;
    int flag = 1;
    for (int j = 1; j <= len1; j++) {
      if (s[j] == '1') {
        if (hash1 == -1) {
          hash1 = get(idx, idx + l1 - 1);
        } else if (hash1 != get(idx, idx + l1 - 1)) {
          flag = 0;
          break;
        }
        idx += l1;
      } else {
        if (hash0 == -1) {
          hash0 = get(idx, idx + l0 - 1);
        } else if (hash0 != get(idx, idx + l0 - 1)) {
          flag = 0;
          break;
        }
        idx += l0;
      }
      if (~hash0 && ~hash1 && hash0 == hash1) {
        flag = 0;
        break;
      }
    }
    if (flag) res++;
  }
  printf("%d\n", res);
}
int main() {
  run();
  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;
const double eps = 1e-5;
const int p = 131;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int N = 1e7 + 10;
long long Hash[N], fac[N];
char s[N], ss[N];
long long get(int l, int r) {
  return (Hash[r] - Hash[l - 1] * fac[r - l + 1] % mod + mod) % mod;
}
void run() {
  scanf("%s %s", s + 1, ss + 1);
  int len1 = strlen(s + 1);
  int len2 = strlen(ss + 1);
  fac[0] = 1;
  int n0 = 0, n1 = 0;
  for (int i = 1; i <= len1; i++) {
    n0 += (s[i] == '0');
    n1 += (s[i] == '1');
  }
  for (int i = 1; i <= len2; i++) {
    Hash[i] = (Hash[i - 1] * p % mod + ss[i] - 'a' + 1) % mod;
    fac[i] = fac[i - 1] * p % mod;
  }
  int res = 0;
  for (int l0 = 1, l1; l0 < len2; l0++) {
    if (l0 * n0 >= len2) break;
    if ((len2 - l0 * n0) % n1) continue;
    l1 = (len2 - l0 * n0) / n1;
    long long hash0 = -1, hash1 = -1;
    int idx = 1;
    int flag = 1;
    for (int j = 1; j <= len1; j++) {
      if (s[j] == '1') {
        if (hash1 == -1) {
          hash1 = get(idx, idx + l1 - 1);
        } else if (hash1 != get(idx, idx + l1 - 1)) {
          flag = 0;
          break;
        }
        idx += l1;
      } else {
        if (hash0 == -1) {
          hash0 = get(idx, idx + l0 - 1);
        } else if (hash0 != get(idx, idx + l0 - 1)) {
          flag = 0;
          break;
        }
        idx += l0;
      }
      if (~hash0 && ~hash1 && hash0 == hash1) {
        flag = 0;
        break;
      }
    }
    if (flag) res++;
  }
  printf("%d\n", res);
}
int main() {
  run();
  return 0;
}

```