#include <bits/stdc++.h>
using namespace std;
unsigned long long h1[1000100], h2[1000100], deg1[1000100], deg2[1000100];
string s1, s2;
int n1, n2, k0, k1, ans, f0, f1;
long long getHash1(int l, int r) { return h1[r + 1] - h1[l] * deg1[r - l + 1]; }
long long getHash2(int l, int r) { return h2[r + 1] - h2[l] * deg2[r - l + 1]; }
bool checkHash(int l1, int r1, int l2, int r2) {
  return ((getHash1(l1, r1) == getHash1(l2, r2)) &&
          (getHash2(l1, r1) == getHash2(l2, r2)));
}
bool check(int l0, int l1) {
  if ((l0 == 0) || (l1 == 0)) return 0;
  int p1 = f0 * l1;
  int p2 = p1 + l0;
  for (int i = f0 + 1; i < n1; i++)
    if (s1[i] == '1') {
      p2 += l1;
    } else {
      if (!checkHash(p1, p1 + l0 - 1, p2, p2 + l0 - 1)) return 0;
      p2 += l0;
    }
  p1 = f1 * l0;
  p2 = p1 + l1;
  for (int i = f1 + 1; i < n1; i++)
    if (s1[i] == '0') {
      p2 += l0;
    } else {
      if (!checkHash(p1, p1 + l1 - 1, p2, p2 + l1 - 1)) return 0;
      p2 += l1;
    }
  if (l1 != l0) return 1;
  if (!checkHash(f0 * l1, f0 * l1 + l0 - 1, f1 * l0, f1 * l0 + l0 - 1))
    return 1;
  return 0;
}
int main() {
  getline(cin, s1);
  n1 = s1.length();
  f0 = -1;
  f1 = -1;
  for (int i = 0; i < n1; i++) {
    if (s1[i] == '0') {
      k0++;
      if (f0 == -1) f0 = i;
    } else {
      k1++;
      if (f1 == -1) f1 = i;
    }
  }
  getline(cin, s2);
  n2 = s2.length();
  long long p1 = 1000 * 1000 * 1000 + 7;
  long long p2 = rand() % 10000 + 1000 * 1000 * 1000 + 11;
  deg1[0] = 1;
  deg2[0] = 1;
  for (int i = 0; i < n2; i++) {
    h1[i + 1] = h1[i] * p1 + s2[i];
    h2[i + 1] = h2[i] * p2 + s2[i];
    deg1[i + 1] = deg1[i] * p1;
    deg2[i + 1] = deg2[i] * p2;
  }
  for (int i = 1; i <= n2 / k0; i++)
    if ((n2 - k0 * i) % k1 == 0)
      if (check(i, (n2 - k0 * i) / k1)) ans++;
  printf("%d\n", ans);
  return 0;
}

### Prompt

Your task is to create 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;
unsigned long long h1[1000100], h2[1000100], deg1[1000100], deg2[1000100];
string s1, s2;
int n1, n2, k0, k1, ans, f0, f1;
long long getHash1(int l, int r) { return h1[r + 1] - h1[l] * deg1[r - l + 1]; }
long long getHash2(int l, int r) { return h2[r + 1] - h2[l] * deg2[r - l + 1]; }
bool checkHash(int l1, int r1, int l2, int r2) {
  return ((getHash1(l1, r1) == getHash1(l2, r2)) &&
          (getHash2(l1, r1) == getHash2(l2, r2)));
}
bool check(int l0, int l1) {
  if ((l0 == 0) || (l1 == 0)) return 0;
  int p1 = f0 * l1;
  int p2 = p1 + l0;
  for (int i = f0 + 1; i < n1; i++)
    if (s1[i] == '1') {
      p2 += l1;
    } else {
      if (!checkHash(p1, p1 + l0 - 1, p2, p2 + l0 - 1)) return 0;
      p2 += l0;
    }
  p1 = f1 * l0;
  p2 = p1 + l1;
  for (int i = f1 + 1; i < n1; i++)
    if (s1[i] == '0') {
      p2 += l0;
    } else {
      if (!checkHash(p1, p1 + l1 - 1, p2, p2 + l1 - 1)) return 0;
      p2 += l1;
    }
  if (l1 != l0) return 1;
  if (!checkHash(f0 * l1, f0 * l1 + l0 - 1, f1 * l0, f1 * l0 + l0 - 1))
    return 1;
  return 0;
}
int main() {
  getline(cin, s1);
  n1 = s1.length();
  f0 = -1;
  f1 = -1;
  for (int i = 0; i < n1; i++) {
    if (s1[i] == '0') {
      k0++;
      if (f0 == -1) f0 = i;
    } else {
      k1++;
      if (f1 == -1) f1 = i;
    }
  }
  getline(cin, s2);
  n2 = s2.length();
  long long p1 = 1000 * 1000 * 1000 + 7;
  long long p2 = rand() % 10000 + 1000 * 1000 * 1000 + 11;
  deg1[0] = 1;
  deg2[0] = 1;
  for (int i = 0; i < n2; i++) {
    h1[i + 1] = h1[i] * p1 + s2[i];
    h2[i + 1] = h2[i] * p2 + s2[i];
    deg1[i + 1] = deg1[i] * p1;
    deg2[i + 1] = deg2[i] * p2;
  }
  for (int i = 1; i <= n2 / k0; i++)
    if ((n2 - k0 * i) % k1 == 0)
      if (check(i, (n2 - k0 * i) / k1)) ans++;
  printf("%d\n", ans);
  return 0;
}

```