#include <bits/stdc++.h>
using namespace std;
int n, m;
int base;
long long hash1[2000013];
long long hash2[2000013];
long long basepow1[2000013];
long long basepow2[2000013];
int main() {
  if (fopen("FILENAME.in", "r")) {
    freopen("FILENAME.in", "r", stdin);
    freopen("FILENAME.out", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  srand(chrono::steady_clock::now().time_since_epoch().count());
  base = rand() % 100000;
  basepow1[0] = 1;
  basepow2[0] = 1;
  for (int i = 1; i < 2000013; i++) {
    basepow1[i] = basepow1[i - 1] * base;
    basepow2[i] = basepow2[i - 1] * base;
    basepow1[i] %= 1000000007LL;
    basepow2[i] %= 1000000009LL;
  }
  string a, b;
  cin >> a >> b;
  n = a.size();
  m = b.size();
  if (a[0] == '1') {
    for (int i = 0; i < n; i++) {
      if (a[i] == '1') {
        a[i] = '0';
      } else {
        a[i] = '1';
      }
    }
  }
  int oneCount = 0;
  int zeroCount = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == '1') {
      oneCount++;
    } else {
      zeroCount++;
    }
  }
  for (int i = 1; i <= m; i++) {
    hash1[i] = hash1[i - 1] * base + b[i - 1] - 'a' + 1;
    hash2[i] = hash2[i - 1] * base + b[i - 1] - 'a' + 1;
    hash1[i] %= 1000000007LL;
    hash2[i] %= 1000000009LL;
  }
  long long strhash1 = 0;
  long long strhash2 = 0;
  int answer = 0;
  for (int i = 1; i < m; i++) {
    strhash1 = strhash1 * base + b[i - 1] - 'a' + 1;
    strhash2 = strhash2 * base + b[i - 1] - 'a' + 1;
    strhash1 %= 1000000007LL;
    strhash2 %= 1000000009LL;
    int totalLengthOther = m - i * zeroCount;
    if (totalLengthOther % oneCount != 0) continue;
    if (totalLengthOther <= 0) continue;
    int lengthOther = totalLengthOther / oneCount;
    int posA = 0;
    int posB = 0;
    bool seenOther = false;
    long long otherhash1 = 0;
    long long otherhash2 = 0;
    bool bad = false;
    while (posA != n) {
      if (a[posA] == '0') {
        posB += i;
        long long rolledHash1 = hash1[posB] - basepow1[i] * hash1[posB - i];
        long long rolledHash2 = hash2[posB] - basepow2[i] * hash2[posB - i];
        rolledHash1 %= 1000000007LL;
        rolledHash1 += 1000000007LL;
        rolledHash1 %= 1000000007LL;
        rolledHash2 %= 1000000009LL;
        rolledHash2 += 1000000009LL;
        rolledHash2 %= 1000000009LL;
        if (rolledHash1 == strhash1 && rolledHash2 == strhash2) {
        } else {
          bad = true;
          break;
        }
      } else {
        if (!seenOther) {
          posB += lengthOther;
          otherhash1 =
              hash1[posB] - basepow1[lengthOther] * hash1[posB - lengthOther];
          otherhash2 =
              hash2[posB] - basepow2[lengthOther] * hash2[posB - lengthOther];
          otherhash1 %= 1000000007LL;
          otherhash1 += 1000000007LL;
          otherhash1 %= 1000000007LL;
          otherhash2 %= 1000000009LL;
          otherhash2 += 1000000009LL;
          otherhash2 %= 1000000009LL;
          seenOther = true;
        } else {
          posB += lengthOther;
          long long rolledHash1 =
              hash1[posB] - basepow1[lengthOther] * hash1[posB - lengthOther];
          long long rolledHash2 =
              hash2[posB] - basepow2[lengthOther] * hash2[posB - lengthOther];
          rolledHash1 %= 1000000007LL;
          rolledHash1 += 1000000007LL;
          rolledHash1 %= 1000000007LL;
          rolledHash2 %= 1000000009LL;
          rolledHash2 += 1000000009LL;
          rolledHash2 %= 1000000009LL;
          if (rolledHash1 == otherhash1 && rolledHash2 == otherhash2) {
          } else {
            bad = true;
            break;
          }
        }
      }
      posA++;
    }
    if (strhash1 == otherhash1 && strhash2 == otherhash2) {
      bad = true;
    }
    if (!bad) {
      answer++;
    }
  }
  cout << answer << endl;
}

### Prompt

Construct a cpp code solution to the problem outlined:

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;
int n, m;
int base;
long long hash1[2000013];
long long hash2[2000013];
long long basepow1[2000013];
long long basepow2[2000013];
int main() {
  if (fopen("FILENAME.in", "r")) {
    freopen("FILENAME.in", "r", stdin);
    freopen("FILENAME.out", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  srand(chrono::steady_clock::now().time_since_epoch().count());
  base = rand() % 100000;
  basepow1[0] = 1;
  basepow2[0] = 1;
  for (int i = 1; i < 2000013; i++) {
    basepow1[i] = basepow1[i - 1] * base;
    basepow2[i] = basepow2[i - 1] * base;
    basepow1[i] %= 1000000007LL;
    basepow2[i] %= 1000000009LL;
  }
  string a, b;
  cin >> a >> b;
  n = a.size();
  m = b.size();
  if (a[0] == '1') {
    for (int i = 0; i < n; i++) {
      if (a[i] == '1') {
        a[i] = '0';
      } else {
        a[i] = '1';
      }
    }
  }
  int oneCount = 0;
  int zeroCount = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == '1') {
      oneCount++;
    } else {
      zeroCount++;
    }
  }
  for (int i = 1; i <= m; i++) {
    hash1[i] = hash1[i - 1] * base + b[i - 1] - 'a' + 1;
    hash2[i] = hash2[i - 1] * base + b[i - 1] - 'a' + 1;
    hash1[i] %= 1000000007LL;
    hash2[i] %= 1000000009LL;
  }
  long long strhash1 = 0;
  long long strhash2 = 0;
  int answer = 0;
  for (int i = 1; i < m; i++) {
    strhash1 = strhash1 * base + b[i - 1] - 'a' + 1;
    strhash2 = strhash2 * base + b[i - 1] - 'a' + 1;
    strhash1 %= 1000000007LL;
    strhash2 %= 1000000009LL;
    int totalLengthOther = m - i * zeroCount;
    if (totalLengthOther % oneCount != 0) continue;
    if (totalLengthOther <= 0) continue;
    int lengthOther = totalLengthOther / oneCount;
    int posA = 0;
    int posB = 0;
    bool seenOther = false;
    long long otherhash1 = 0;
    long long otherhash2 = 0;
    bool bad = false;
    while (posA != n) {
      if (a[posA] == '0') {
        posB += i;
        long long rolledHash1 = hash1[posB] - basepow1[i] * hash1[posB - i];
        long long rolledHash2 = hash2[posB] - basepow2[i] * hash2[posB - i];
        rolledHash1 %= 1000000007LL;
        rolledHash1 += 1000000007LL;
        rolledHash1 %= 1000000007LL;
        rolledHash2 %= 1000000009LL;
        rolledHash2 += 1000000009LL;
        rolledHash2 %= 1000000009LL;
        if (rolledHash1 == strhash1 && rolledHash2 == strhash2) {
        } else {
          bad = true;
          break;
        }
      } else {
        if (!seenOther) {
          posB += lengthOther;
          otherhash1 =
              hash1[posB] - basepow1[lengthOther] * hash1[posB - lengthOther];
          otherhash2 =
              hash2[posB] - basepow2[lengthOther] * hash2[posB - lengthOther];
          otherhash1 %= 1000000007LL;
          otherhash1 += 1000000007LL;
          otherhash1 %= 1000000007LL;
          otherhash2 %= 1000000009LL;
          otherhash2 += 1000000009LL;
          otherhash2 %= 1000000009LL;
          seenOther = true;
        } else {
          posB += lengthOther;
          long long rolledHash1 =
              hash1[posB] - basepow1[lengthOther] * hash1[posB - lengthOther];
          long long rolledHash2 =
              hash2[posB] - basepow2[lengthOther] * hash2[posB - lengthOther];
          rolledHash1 %= 1000000007LL;
          rolledHash1 += 1000000007LL;
          rolledHash1 %= 1000000007LL;
          rolledHash2 %= 1000000009LL;
          rolledHash2 += 1000000009LL;
          rolledHash2 %= 1000000009LL;
          if (rolledHash1 == otherhash1 && rolledHash2 == otherhash2) {
          } else {
            bad = true;
            break;
          }
        }
      }
      posA++;
    }
    if (strhash1 == otherhash1 && strhash2 == otherhash2) {
      bad = true;
    }
    if (!bad) {
      answer++;
    }
  }
  cout << answer << endl;
}

```