#include <bits/stdc++.h>
using namespace std;
char s[100010], t[10 * 100010];
long long t_hash[10 * 100010], p[10 * 100010], o = 31, p_inverse[10 * 100010],
                                               pinv = 129032259, lens, lent;
void init_hash() {
  p[0] = 1;
  t_hash[0] = t[0];
  for (long long i = 1; i < lent; i++)
    p[i] = p[i - 1] * o % 1000000007,
    t_hash[i] = (t_hash[i - 1] + p[i] * t[i] % 1000000007) % 1000000007;
  p_inverse[0] = 1;
  for (long long i = 1; i <= lent; i++)
    p_inverse[i] = (p_inverse[i - 1] * pinv) % 1000000007;
}
long long get_hash(long long l, long long r) {
  if (l == 0) return t_hash[r];
  long long tmp = t_hash[r] - t_hash[l - 1];
  if (tmp < 0) tmp += 1000000007;
  return (tmp * p_inverse[l]) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  cin >> t;
  lens = strlen(s), lent = strlen(t);
  init_hash();
  long long cnt_0 = count(s, s + lens, '0'), cnt_1 = count(s, s + lens, '1');
  if (cnt_0 < cnt_1) {
    for (long long i = 0; i < lens; i++) {
      if (s[i] == '1')
        s[i] = '0';
      else
        s[i] = '1';
    }
    swap(cnt_1, cnt_0);
  }
  long long first_0 = 100010, first_1 = 100010;
  for (long long i = 0; i < lens; i++) {
    if (s[i] == '0' and i < first_0) first_0 = i;
    if (s[i] == '1' and i < first_1) first_1 = i;
  }
  long long res = 0;
  for (long long i = 1; i <= (lent / cnt_0); i++) {
    if ((lent - i * cnt_0) % cnt_1 != 0) continue;
    long long len_r0 = i, len_r1 = (lent - i * cnt_0) / cnt_1;
    if (len_r1 <= 0) continue;
    long long r0 = -1, r1 = -1;
    if (s[0] == '0') {
      r0 = get_hash(0, len_r0 - 1);
      r1 = get_hash(len_r0 * first_1, len_r0 * first_1 + len_r1 - 1);
    } else {
      r1 = get_hash(0, len_r1 - 1);
      r0 = get_hash(len_r1 * first_0, len_r1 * first_0 + len_r0 - 1);
    }
    if (r0 == r1) continue;
    bool flag = true;
    long long idx = 0;
    for (long long j = 0; j < lens; j++) {
      if (s[j] == '1') {
        if (get_hash(idx, idx + len_r1 - 1) != r1) {
          flag = false;
          break;
        }
        idx += len_r1;
      } else {
        if (get_hash(idx, idx + len_r0 - 1) != r0) {
          flag = false;
          break;
        }
        idx += len_r0;
      }
    }
    if (flag) res += 1;
  }
  cout << res << '\n';
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

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;
char s[100010], t[10 * 100010];
long long t_hash[10 * 100010], p[10 * 100010], o = 31, p_inverse[10 * 100010],
                                               pinv = 129032259, lens, lent;
void init_hash() {
  p[0] = 1;
  t_hash[0] = t[0];
  for (long long i = 1; i < lent; i++)
    p[i] = p[i - 1] * o % 1000000007,
    t_hash[i] = (t_hash[i - 1] + p[i] * t[i] % 1000000007) % 1000000007;
  p_inverse[0] = 1;
  for (long long i = 1; i <= lent; i++)
    p_inverse[i] = (p_inverse[i - 1] * pinv) % 1000000007;
}
long long get_hash(long long l, long long r) {
  if (l == 0) return t_hash[r];
  long long tmp = t_hash[r] - t_hash[l - 1];
  if (tmp < 0) tmp += 1000000007;
  return (tmp * p_inverse[l]) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  cin >> t;
  lens = strlen(s), lent = strlen(t);
  init_hash();
  long long cnt_0 = count(s, s + lens, '0'), cnt_1 = count(s, s + lens, '1');
  if (cnt_0 < cnt_1) {
    for (long long i = 0; i < lens; i++) {
      if (s[i] == '1')
        s[i] = '0';
      else
        s[i] = '1';
    }
    swap(cnt_1, cnt_0);
  }
  long long first_0 = 100010, first_1 = 100010;
  for (long long i = 0; i < lens; i++) {
    if (s[i] == '0' and i < first_0) first_0 = i;
    if (s[i] == '1' and i < first_1) first_1 = i;
  }
  long long res = 0;
  for (long long i = 1; i <= (lent / cnt_0); i++) {
    if ((lent - i * cnt_0) % cnt_1 != 0) continue;
    long long len_r0 = i, len_r1 = (lent - i * cnt_0) / cnt_1;
    if (len_r1 <= 0) continue;
    long long r0 = -1, r1 = -1;
    if (s[0] == '0') {
      r0 = get_hash(0, len_r0 - 1);
      r1 = get_hash(len_r0 * first_1, len_r0 * first_1 + len_r1 - 1);
    } else {
      r1 = get_hash(0, len_r1 - 1);
      r0 = get_hash(len_r1 * first_0, len_r1 * first_0 + len_r0 - 1);
    }
    if (r0 == r1) continue;
    bool flag = true;
    long long idx = 0;
    for (long long j = 0; j < lens; j++) {
      if (s[j] == '1') {
        if (get_hash(idx, idx + len_r1 - 1) != r1) {
          flag = false;
          break;
        }
        idx += len_r1;
      } else {
        if (get_hash(idx, idx + len_r0 - 1) != r0) {
          flag = false;
          break;
        }
        idx += len_r0;
      }
    }
    if (flag) res += 1;
  }
  cout << res << '\n';
  return 0;
}

```