#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
char s[N], t[N];
int sa[N], rk[N], od[N], cnt[N], id[N], px[N];
long long h[N];
long long f[N][26];
long long lg[N];
bool cmp(int x, int y, int w) {
  return od[x] == od[y] && od[x + w] == od[y + w];
}
void da(int n, int m) {
  int i;
  memset(cnt, 0, sizeof cnt);
  for (i = 1; i <= n; i++) cnt[rk[i] = t[i]]++;
  for (i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
  for (i = n; i >= 1; i--) sa[cnt[rk[i]]--] = i;
  int p;
  for (int w = 1; w < n; w <<= 1, m = p) {
    p = 0;
    for (i = n; i > n - w; i--) id[++p] = i;
    for (i = 1; i <= n; i++)
      if (sa[i] > w) id[++p] = sa[i] - w;
    memset(cnt, 0, sizeof cnt);
    for (i = 1; i <= n; i++) cnt[px[i] = rk[id[i]]]++;
    for (i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
    for (i = n; i >= 1; i--) sa[cnt[px[i]]--] = id[i];
    for (i = 0; i <= n; i++) od[i] = rk[i];
    for (p = 0, i = 1; i <= n; i++) {
      rk[sa[i]] = cmp(sa[i - 1], sa[i], w) ? p : ++p;
    }
  }
}
void st(int n) {
  int i, j;
  for (i = 1; i <= n; i++) f[i][0] = h[i];
  lg[1] = 0;
  for (i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
  for (j = 1; j <= lg[n]; j++) {
    for (i = 1; i + (1 << j) - 1 <= n; i++) {
      f[i][j] = min(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
    }
  }
}
int query(int l, int r) {
  if (l > r) swap(l, r);
  l++;
  int len = lg[r - l + 1];
  return min(f[l][len], f[r - (1 << len) + 1][len]);
}
void get_height(int n) {
  int i;
  for (i = 1; i <= n; i++) {
    if (rk[i] == 1) continue;
    int a = max(h[rk[i - 1]] - 1, 1ll * 0);
    while (i + a <= n && t[i + a] == t[sa[rk[i] - 1] + a]) a++;
    h[rk[i]] = a;
  }
  st(n);
}
int main() {
  scanf("%s%s", s + 1, t + 1);
  int lent = strlen(t + 1);
  int lens = strlen(s + 1);
  da(lent, 128);
  get_height(lent);
  int cnt0 = 0, cnt1 = 0;
  for (int i = 1; i <= lens; i++) {
    if (s[i] == '0')
      cnt0++;
    else
      cnt1++;
  }
  long long ans = 0;
  for (long long i = 1; i * cnt0 <= lent; ++i) {
    if ((lent - i * cnt0) % (lens - cnt0)) continue;
    long long start0 = 0, start1 = 0, pos = 1, flag = 1;
    long long k = (lent - i * cnt0) / (lens - cnt0);
    for (long long j = 1; j <= lens; ++j) {
      if (s[j] == '0') {
        if (!start0)
          start0 = pos;
        else if (query(rk[start0], rk[pos]) < i)
          flag = 0;
        pos += i;
      } else {
        if (!start1)
          start1 = pos;
        else if (query(rk[start1], rk[pos]) < k)
          flag = 0;
        if (!k) flag = 0;
        pos += k;
      }
    }
    if (flag && (i != k || query(rk[start0], rk[start1]) < i)) ++ans;
  }
  cout << ans << endl;
  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;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
char s[N], t[N];
int sa[N], rk[N], od[N], cnt[N], id[N], px[N];
long long h[N];
long long f[N][26];
long long lg[N];
bool cmp(int x, int y, int w) {
  return od[x] == od[y] && od[x + w] == od[y + w];
}
void da(int n, int m) {
  int i;
  memset(cnt, 0, sizeof cnt);
  for (i = 1; i <= n; i++) cnt[rk[i] = t[i]]++;
  for (i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
  for (i = n; i >= 1; i--) sa[cnt[rk[i]]--] = i;
  int p;
  for (int w = 1; w < n; w <<= 1, m = p) {
    p = 0;
    for (i = n; i > n - w; i--) id[++p] = i;
    for (i = 1; i <= n; i++)
      if (sa[i] > w) id[++p] = sa[i] - w;
    memset(cnt, 0, sizeof cnt);
    for (i = 1; i <= n; i++) cnt[px[i] = rk[id[i]]]++;
    for (i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
    for (i = n; i >= 1; i--) sa[cnt[px[i]]--] = id[i];
    for (i = 0; i <= n; i++) od[i] = rk[i];
    for (p = 0, i = 1; i <= n; i++) {
      rk[sa[i]] = cmp(sa[i - 1], sa[i], w) ? p : ++p;
    }
  }
}
void st(int n) {
  int i, j;
  for (i = 1; i <= n; i++) f[i][0] = h[i];
  lg[1] = 0;
  for (i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
  for (j = 1; j <= lg[n]; j++) {
    for (i = 1; i + (1 << j) - 1 <= n; i++) {
      f[i][j] = min(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
    }
  }
}
int query(int l, int r) {
  if (l > r) swap(l, r);
  l++;
  int len = lg[r - l + 1];
  return min(f[l][len], f[r - (1 << len) + 1][len]);
}
void get_height(int n) {
  int i;
  for (i = 1; i <= n; i++) {
    if (rk[i] == 1) continue;
    int a = max(h[rk[i - 1]] - 1, 1ll * 0);
    while (i + a <= n && t[i + a] == t[sa[rk[i] - 1] + a]) a++;
    h[rk[i]] = a;
  }
  st(n);
}
int main() {
  scanf("%s%s", s + 1, t + 1);
  int lent = strlen(t + 1);
  int lens = strlen(s + 1);
  da(lent, 128);
  get_height(lent);
  int cnt0 = 0, cnt1 = 0;
  for (int i = 1; i <= lens; i++) {
    if (s[i] == '0')
      cnt0++;
    else
      cnt1++;
  }
  long long ans = 0;
  for (long long i = 1; i * cnt0 <= lent; ++i) {
    if ((lent - i * cnt0) % (lens - cnt0)) continue;
    long long start0 = 0, start1 = 0, pos = 1, flag = 1;
    long long k = (lent - i * cnt0) / (lens - cnt0);
    for (long long j = 1; j <= lens; ++j) {
      if (s[j] == '0') {
        if (!start0)
          start0 = pos;
        else if (query(rk[start0], rk[pos]) < i)
          flag = 0;
        pos += i;
      } else {
        if (!start1)
          start1 = pos;
        else if (query(rk[start1], rk[pos]) < k)
          flag = 0;
        if (!k) flag = 0;
        pos += k;
      }
    }
    if (flag && (i != k || query(rk[start0], rk[start1]) < i)) ++ans;
  }
  cout << ans << endl;
  return 0;
}

```