#include <bits/stdc++.h>
using namespace std;
long long hashvals[1111111 + 2];
long long pwr[1111111 + 2];
long long GetHash(int p1, int p2) {
  if (p1 == 0) {
    return hashvals[p2];
  } else {
    long long h =
        (hashvals[p2] - hashvals[p1 - 1] * pwr[p2 - p1 + 1]) % 1000000007;
    if (h < 0) {
      h += 1000000007;
    }
    return h;
  }
}
bool Can(const string& S, const string& T, int L0, int L1) {
  long long hashvals[2];
  hashvals[0] = hashvals[1] = -1;
  int p1 = 0;
  int p2 = 0;
  while (p1 < S.size()) {
    int id = S[p1] - '0';
    int curr_len = (id == 0 ? L0 : L1);
    long long h = GetHash(p2, p2 + curr_len - 1);
    if (hashvals[id] == -1) {
      hashvals[id] = h;
    } else if (hashvals[id] != h) {
      return false;
    }
    p1++;
    p2 += curr_len;
  }
  if (L0 == L1 && hashvals[0] == hashvals[1]) return false;
  return true;
}
int main() {
  string S;
  cin >> S;
  int N0 = 0;
  int N1 = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '0')
      N0++;
    else
      N1++;
  }
  string T;
  cin >> T;
  int n = S.size();
  int m = T.size();
  hashvals[0] = T[0] - 'a';
  for (int i = 1; i < m; i++) {
    hashvals[i] = (hashvals[i - 1] * 30 + T[i] - 'a') % 1000000007;
  }
  pwr[0] = 1;
  for (int i = 1; i <= m; i++) pwr[i] = (pwr[i - 1] * 30) % 1000000007;
  long long ans = 0;
  for (long long L0 = 1; L0 <= m; L0++) {
    if (L0 * N0 > m) break;
    long long L1 = (m - L0 * N0) / N1;
    if (L1 >= 1 && L0 * N0 + L1 * N1 == m) {
      if (Can(S, T, L0, L1)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

### 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 hashvals[1111111 + 2];
long long pwr[1111111 + 2];
long long GetHash(int p1, int p2) {
  if (p1 == 0) {
    return hashvals[p2];
  } else {
    long long h =
        (hashvals[p2] - hashvals[p1 - 1] * pwr[p2 - p1 + 1]) % 1000000007;
    if (h < 0) {
      h += 1000000007;
    }
    return h;
  }
}
bool Can(const string& S, const string& T, int L0, int L1) {
  long long hashvals[2];
  hashvals[0] = hashvals[1] = -1;
  int p1 = 0;
  int p2 = 0;
  while (p1 < S.size()) {
    int id = S[p1] - '0';
    int curr_len = (id == 0 ? L0 : L1);
    long long h = GetHash(p2, p2 + curr_len - 1);
    if (hashvals[id] == -1) {
      hashvals[id] = h;
    } else if (hashvals[id] != h) {
      return false;
    }
    p1++;
    p2 += curr_len;
  }
  if (L0 == L1 && hashvals[0] == hashvals[1]) return false;
  return true;
}
int main() {
  string S;
  cin >> S;
  int N0 = 0;
  int N1 = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '0')
      N0++;
    else
      N1++;
  }
  string T;
  cin >> T;
  int n = S.size();
  int m = T.size();
  hashvals[0] = T[0] - 'a';
  for (int i = 1; i < m; i++) {
    hashvals[i] = (hashvals[i - 1] * 30 + T[i] - 'a') % 1000000007;
  }
  pwr[0] = 1;
  for (int i = 1; i <= m; i++) pwr[i] = (pwr[i - 1] * 30) % 1000000007;
  long long ans = 0;
  for (long long L0 = 1; L0 <= m; L0++) {
    if (L0 * N0 > m) break;
    long long L1 = (m - L0 * N0) / N1;
    if (L1 >= 1 && L0 * N0 + L1 * N1 == m) {
      if (Can(S, T, L0, L1)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

```