#include <bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 1e6 + 7;
const int maxm = 1e5 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-8;
long long base = 131;
long long h[maxn];
void hashs(char s[]) {
  int len = strlen(s + 1);
  h[0] = 0;
  for (int i = 1; i <= len; i++) {
    h[i] = (h[i - 1] * base + (s[i] - 'a' + 1)) % mod;
  }
  return;
}
long long poww(long long a, long long b) {
  long long ans = 1, base = a;
  while (b != 0) {
    if (b & 1 != 0) ans = (ans * base) % mod;
    base = (base * base) % mod;
    b >>= 1;
  }
  return ans % mod;
}
long long get(int l, int r) {
  return (h[r] - h[l - 1] * poww(base, r - l + 1) % mod + mod) % mod;
}
char s[maxn], t[maxn];
long long cnt0, cnt1;
long long ans;
int main(int argc, char const *argv[]) {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  hashs(t);
  long long lens = strlen(s + 1);
  long long lent = strlen(t + 1);
  for (int i = 1; i <= lens; i++) {
    if (s[i] == '1')
      cnt1++;
    else
      cnt0++;
  }
  long long r0, r1;
  for (r0 = 1; r0 <= lent; r0++) {
    if ((lent - cnt0 * r0) > 0 && ((lent - cnt0 * r0) % cnt1) == 0) {
      r1 = (lent - cnt0 * r0) / cnt1;
      int flag = 1;
      int p = 1;
      long long ans0 = 0, ans1 = 0;
      int flag0 = 0, flag1 = 0;
      for (int i = 1; i <= lens; i++) {
        if (s[i] == '0' && flag0 == 0) {
          flag0 = 1;
          ans0 = get(p, p + r0 - 1);
          p = p + r0;
          continue;
        } else if (s[i] == '1' && flag1 == 0) {
          flag1 = 1;
          ans1 = get(p, p + r1 - 1);
          p = p + r1;
          continue;
        } else if (s[i] == '0') {
          long long tmp0 = get(p, p + r0 - 1);
          if (tmp0 != ans0) {
            flag = 0;
            break;
          }
          p = p + r0;
          continue;
        } else {
          long long tmp1 = get(p, p + r1 - 1);
          if (tmp1 != ans1) {
            flag = 0;
            break;
          }
          p = p + r1;
          continue;
        }
      }
      if (ans1 == ans0) flag = 0;
      if (flag) ans++;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

### Prompt

Your challenge is to write 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;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 1e6 + 7;
const int maxm = 1e5 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-8;
long long base = 131;
long long h[maxn];
void hashs(char s[]) {
  int len = strlen(s + 1);
  h[0] = 0;
  for (int i = 1; i <= len; i++) {
    h[i] = (h[i - 1] * base + (s[i] - 'a' + 1)) % mod;
  }
  return;
}
long long poww(long long a, long long b) {
  long long ans = 1, base = a;
  while (b != 0) {
    if (b & 1 != 0) ans = (ans * base) % mod;
    base = (base * base) % mod;
    b >>= 1;
  }
  return ans % mod;
}
long long get(int l, int r) {
  return (h[r] - h[l - 1] * poww(base, r - l + 1) % mod + mod) % mod;
}
char s[maxn], t[maxn];
long long cnt0, cnt1;
long long ans;
int main(int argc, char const *argv[]) {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  hashs(t);
  long long lens = strlen(s + 1);
  long long lent = strlen(t + 1);
  for (int i = 1; i <= lens; i++) {
    if (s[i] == '1')
      cnt1++;
    else
      cnt0++;
  }
  long long r0, r1;
  for (r0 = 1; r0 <= lent; r0++) {
    if ((lent - cnt0 * r0) > 0 && ((lent - cnt0 * r0) % cnt1) == 0) {
      r1 = (lent - cnt0 * r0) / cnt1;
      int flag = 1;
      int p = 1;
      long long ans0 = 0, ans1 = 0;
      int flag0 = 0, flag1 = 0;
      for (int i = 1; i <= lens; i++) {
        if (s[i] == '0' && flag0 == 0) {
          flag0 = 1;
          ans0 = get(p, p + r0 - 1);
          p = p + r0;
          continue;
        } else if (s[i] == '1' && flag1 == 0) {
          flag1 = 1;
          ans1 = get(p, p + r1 - 1);
          p = p + r1;
          continue;
        } else if (s[i] == '0') {
          long long tmp0 = get(p, p + r0 - 1);
          if (tmp0 != ans0) {
            flag = 0;
            break;
          }
          p = p + r0;
          continue;
        } else {
          long long tmp1 = get(p, p + r1 - 1);
          if (tmp1 != ans1) {
            flag = 0;
            break;
          }
          p = p + r1;
          continue;
        }
      }
      if (ans1 == ans0) flag = 0;
      if (flag) ans++;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

```