#include <bits/stdc++.h>
using namespace std;
const int maxm = (2e6 + 10), mod = 98765431, H = 131;
int num[2], pre[maxm], p[maxm], n, m, cnt[2][maxm], ans;
string s, t;
vector<int> v[2];
int get_hash(int l, int r) {
  int ex = (1ll * pre[l - 1] * p[r - l + 1]) % mod;
  return (1ll + ex - pre[r] + 2 * mod) % mod;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s >> t;
  n = s.size(), m = t.size();
  int ch = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == '0') ch++;
  if (ch < (n >> 1))
    for (int i = 0; i < n; i++) s[i] = (char)((int)('1' - s[i]) + '0');
  for (int i = 0; i < n; i++) {
    num[s[i] - '0']++;
    v[s[i] - '0'].push_back(i + 1);
    for (int j = 0; j < 2; j++) cnt[j][i + 1] = cnt[j][i];
    cnt[s[i] - '0'][i + 1]++;
  }
  p[0] = 1;
  for (int i = 1; i <= m; i++) p[i] = (1ll * p[i - 1] * H) % mod;
  for (int i = 1; i <= m; i++)
    pre[i] = ((1ll * pre[i - 1] * H) % mod + (int)t[i - 1]) % mod;
  int m0 = m / num[0], m1 = m / num[1];
  for (int r0 = 1; r0 <= m0; r0++) {
    if ((m - (r0 * num[0])) % num[1]) continue;
    int r1 = (m - (r0 * num[0])) / num[1], res1 = cnt[0][v[1][0]] * r0 + 1,
        res0 = cnt[1][v[0][0]] * r1 + 1;
    if (r1 >= m1 || !r1) continue;
    res1 = get_hash(res1, res1 + r1 - 1), res0 = get_hash(res0, res0 + r0 - 1);
    if (res0 == res1) continue;
    bool flg = 0;
    for (auto j : v[0]) {
      int res = cnt[0][j - 1] * r0 + cnt[1][j - 1] * r1 + 1;
      if (get_hash(res, res + r0 - 1) != res0) {
        flg = 1;
        break;
      }
    }
    if (flg) continue;
    for (auto j : v[1]) {
      int res = cnt[0][j - 1] * r0 + cnt[1][j - 1] * r1 + 1;
      if (get_hash(res, res + r1 - 1) != res1) {
        flg = 1;
        break;
      }
    }
    if (flg) continue;
    ans++;
  }
  cout << ans << '\n';
  return 0;
}

### 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;
const int maxm = (2e6 + 10), mod = 98765431, H = 131;
int num[2], pre[maxm], p[maxm], n, m, cnt[2][maxm], ans;
string s, t;
vector<int> v[2];
int get_hash(int l, int r) {
  int ex = (1ll * pre[l - 1] * p[r - l + 1]) % mod;
  return (1ll + ex - pre[r] + 2 * mod) % mod;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s >> t;
  n = s.size(), m = t.size();
  int ch = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == '0') ch++;
  if (ch < (n >> 1))
    for (int i = 0; i < n; i++) s[i] = (char)((int)('1' - s[i]) + '0');
  for (int i = 0; i < n; i++) {
    num[s[i] - '0']++;
    v[s[i] - '0'].push_back(i + 1);
    for (int j = 0; j < 2; j++) cnt[j][i + 1] = cnt[j][i];
    cnt[s[i] - '0'][i + 1]++;
  }
  p[0] = 1;
  for (int i = 1; i <= m; i++) p[i] = (1ll * p[i - 1] * H) % mod;
  for (int i = 1; i <= m; i++)
    pre[i] = ((1ll * pre[i - 1] * H) % mod + (int)t[i - 1]) % mod;
  int m0 = m / num[0], m1 = m / num[1];
  for (int r0 = 1; r0 <= m0; r0++) {
    if ((m - (r0 * num[0])) % num[1]) continue;
    int r1 = (m - (r0 * num[0])) / num[1], res1 = cnt[0][v[1][0]] * r0 + 1,
        res0 = cnt[1][v[0][0]] * r1 + 1;
    if (r1 >= m1 || !r1) continue;
    res1 = get_hash(res1, res1 + r1 - 1), res0 = get_hash(res0, res0 + r0 - 1);
    if (res0 == res1) continue;
    bool flg = 0;
    for (auto j : v[0]) {
      int res = cnt[0][j - 1] * r0 + cnt[1][j - 1] * r1 + 1;
      if (get_hash(res, res + r0 - 1) != res0) {
        flg = 1;
        break;
      }
    }
    if (flg) continue;
    for (auto j : v[1]) {
      int res = cnt[0][j - 1] * r0 + cnt[1][j - 1] * r1 + 1;
      if (get_hash(res, res + r1 - 1) != res1) {
        flg = 1;
        break;
      }
    }
    if (flg) continue;
    ans++;
  }
  cout << ans << '\n';
  return 0;
}

```