#include <bits/stdc++.h>
using namespace std;
const int N = 5000010;
const long long INF = 4e18;
const int M = 5;
int b[5] = {31, 53, 101, 0, 307};
int mods[5] = {1000000007, 1000000009, 1000000103, 1000010029, 0};
bool prime(int x) {
  if (x < 2) return false;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
string s, t;
int n, m;
int h[5][N];
int push_back[5][N];
int product(int a, int b, int mod) { return (1ll * a * b) % mod; }
int sum(int a, int b, int mod) { return (a + b) % mod; }
int diff(int a, int b, int mod) { return (mod + a - b) % mod; }
void calc() {
  for (int i = 0; i < M; i++) h[i][m] = 0;
  for (int i = 0; i < M; i++) {
    for (int j = m - 1; j >= 0; j--) {
      h[i][j] =
          sum(t[j] - 'a' + 1, product(h[i][j + 1], b[i], mods[i]), mods[i]);
    }
  }
  for (int i = 0; i < M; i++) {
    push_back[i][0] = 1;
    for (int j = 1; j <= m; j++)
      push_back[i][j] = product(push_back[i][j - 1], b[i], mods[i]);
  }
}
bool equal(int l1, int r1, int l2, int r2) {
  if (r2 - l2 != r1 - l1) return false;
  for (int i = 0; i < M; i++) {
    int h1 = diff(h[i][l1],
                  product(h[i][r1 + 1], push_back[i][r1 - l1 + 1], mods[i]),
                  mods[i]);
    int h2 = diff(h[i][l2],
                  product(h[i][r2 + 1], push_back[i][r2 - l2 + 1], mods[i]),
                  mods[i]);
    if (h1 != h2) return false;
  }
  return true;
}
bool check(int len0, int len1) {
  int l0 = -1, r0 = -1, l1 = -1, r1 = -1;
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      if (l0 == -1) {
        l0 = j;
        r0 = j + len0 - 1;
      } else {
        if (!equal(l0, r0, j, j + len0 - 1)) return false;
      }
      j += len0;
    } else {
      if (l1 == -1) {
        l1 = j;
        r1 = j + len1 - 1;
      } else {
        if (!equal(l1, r1, j, j + len1 - 1)) return false;
      }
      j += len1;
    }
  }
  if (equal(l0, r0, l1, r1)) return false;
  return true;
}
int main() {
  srand(time(0));
  b[3] = rand() % 200 + 200;
  mods[4] = rand() % (1 << 15) * rand() % (1 << 15);
  cin >> s;
  cin >> t;
  n = s.length();
  m = t.length();
  int cnt[2] = {0, 0};
  for (int i = 0; i < n; i++) {
    cnt[s[i] - '0']++;
  }
  if (cnt[0] > cnt[1]) {
    swap(cnt[0], cnt[1]);
    for (int i = 0; i < n; i++) s[i] = (s[i] == '0' ? 1 : '0');
  }
  calc();
  int ans = 0;
  for (int len1 = 1; cnt[1] * len1 < m; len1++) {
    if ((m - cnt[1] * len1) % cnt[0] != 0) continue;
    int len0 = (m - cnt[1] * len1) / cnt[0];
    if (check(len0, len1)) ans++;
  }
  cout << ans;
  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 = 5000010;
const long long INF = 4e18;
const int M = 5;
int b[5] = {31, 53, 101, 0, 307};
int mods[5] = {1000000007, 1000000009, 1000000103, 1000010029, 0};
bool prime(int x) {
  if (x < 2) return false;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
string s, t;
int n, m;
int h[5][N];
int push_back[5][N];
int product(int a, int b, int mod) { return (1ll * a * b) % mod; }
int sum(int a, int b, int mod) { return (a + b) % mod; }
int diff(int a, int b, int mod) { return (mod + a - b) % mod; }
void calc() {
  for (int i = 0; i < M; i++) h[i][m] = 0;
  for (int i = 0; i < M; i++) {
    for (int j = m - 1; j >= 0; j--) {
      h[i][j] =
          sum(t[j] - 'a' + 1, product(h[i][j + 1], b[i], mods[i]), mods[i]);
    }
  }
  for (int i = 0; i < M; i++) {
    push_back[i][0] = 1;
    for (int j = 1; j <= m; j++)
      push_back[i][j] = product(push_back[i][j - 1], b[i], mods[i]);
  }
}
bool equal(int l1, int r1, int l2, int r2) {
  if (r2 - l2 != r1 - l1) return false;
  for (int i = 0; i < M; i++) {
    int h1 = diff(h[i][l1],
                  product(h[i][r1 + 1], push_back[i][r1 - l1 + 1], mods[i]),
                  mods[i]);
    int h2 = diff(h[i][l2],
                  product(h[i][r2 + 1], push_back[i][r2 - l2 + 1], mods[i]),
                  mods[i]);
    if (h1 != h2) return false;
  }
  return true;
}
bool check(int len0, int len1) {
  int l0 = -1, r0 = -1, l1 = -1, r1 = -1;
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      if (l0 == -1) {
        l0 = j;
        r0 = j + len0 - 1;
      } else {
        if (!equal(l0, r0, j, j + len0 - 1)) return false;
      }
      j += len0;
    } else {
      if (l1 == -1) {
        l1 = j;
        r1 = j + len1 - 1;
      } else {
        if (!equal(l1, r1, j, j + len1 - 1)) return false;
      }
      j += len1;
    }
  }
  if (equal(l0, r0, l1, r1)) return false;
  return true;
}
int main() {
  srand(time(0));
  b[3] = rand() % 200 + 200;
  mods[4] = rand() % (1 << 15) * rand() % (1 << 15);
  cin >> s;
  cin >> t;
  n = s.length();
  m = t.length();
  int cnt[2] = {0, 0};
  for (int i = 0; i < n; i++) {
    cnt[s[i] - '0']++;
  }
  if (cnt[0] > cnt[1]) {
    swap(cnt[0], cnt[1]);
    for (int i = 0; i < n; i++) s[i] = (s[i] == '0' ? 1 : '0');
  }
  calc();
  int ans = 0;
  for (int len1 = 1; cnt[1] * len1 < m; len1++) {
    if ((m - cnt[1] * len1) % cnt[0] != 0) continue;
    int len0 = (m - cnt[1] * len1) / cnt[0];
    if (check(len0, len1)) ans++;
  }
  cout << ans;
  return 0;
}

```