#include <bits/stdc++.h>
using namespace std;
const int MAXL = 1000111;
char s[MAXL];
char t[MAXL];
int n, m;
const int P = 101;
const int MOD1 = 1E9 + 7, MOD2 = 1E9 + 9;
int p1[MAXL], p2[MAXL];
int hash1[MAXL], hash2[MAXL];
void makeMemLim() {
  vector<int> x;
  for (int i = 0; i < 1000000000; i++) {
    x.push_back(i);
  }
}
inline int mod(int x, int md) {
  while (x < 0) x += md;
  while (x >= md) x -= md;
  return x;
}
inline pair<int, int> getNormedHash(int l, int r) {
  if (l < 0 || l >= m) {
    makeMemLim();
  }
  if (r < 0 || r >= m) {
    makeMemLim();
  }
  int st1 = l == 0 ? 0 : hash1[l - 1];
  int st2 = l == 0 ? 0 : hash2[l - 1];
  int fin1 = hash1[r];
  int fin2 = hash2[r];
  int diff1 = mod(fin1 - st1, MOD1);
  int diff2 = mod(fin2 - st2, MOD2);
  int norm1 = (long long)diff1 * p1[MAXL - 10 - l] % MOD1;
  int norm2 = (long long)diff2 * p2[MAXL - 10 - l] % MOD2;
  return {norm1, norm2};
}
int main() {
  p1[0] = p2[0] = 1;
  for (int i = 1; i < MAXL; i++) {
    p1[i] = (long long)p1[i - 1] * P % MOD1;
    p2[i] = (long long)p2[i - 1] * P % MOD2;
  }
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  m = strlen(t);
  for (int i = 0; i < m; i++) {
    if (i >= MAXL) {
      makeMemLim();
    }
    int prev1;
    if (i == 0) {
      prev1 = 0;
    } else {
      prev1 = hash1[i - 1];
    }
    int prev2;
    if (i == 0) {
      prev2 = 0;
    } else {
      prev2 = hash2[i - 1];
    }
    hash1[i] = ((long long)prev1 + (long long)t[i] * p1[i]) % MOD1;
    hash2[i] = ((long long)prev2 + (long long)t[i] * p2[i]) % MOD2;
  }
  if (m > MAXL - 1) {
    makeMemLim();
  }
  int cnt0 = 0, cnt1 = 0;
  int first0 = 1E9, first1 = 1E9;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      cnt0++;
      first0 = min(first0, i);
    } else {
      cnt1++;
      first1 = min(first1, i);
    }
  }
  int answer = 0;
  for (int len0 = 1; len0 <= m; len0++) {
    int len1 = (m - (long long)len0 * cnt0) / cnt1;
    if (len1 <= 0) {
      break;
    }
    if ((long long)len0 * cnt0 + (long long)len1 * cnt1 != (long long)m) {
      continue;
    }
    pair<int, int> example0, example1;
    int pos = 0;
    bool ok = true;
    for (int i = 0; i < n; i++) {
      if (pos < 0 || pos >= m) {
        makeMemLim();
      }
      pair<int, int> cur;
      if (s[i] == '0') {
        cur = getNormedHash(pos, pos + len0 - 1);
        if (i == first0) {
          example0 = cur;
        } else {
          if (cur != example0) {
            ok = false;
          }
        }
        pos += len0;
      } else {
        cur = getNormedHash(pos, pos + len1 - 1);
        if (i == first1) {
          example1 = cur;
        } else {
          if (cur != example1) {
            ok = false;
          }
        }
        pos += len1;
      }
    }
    if (example0 != example1 && ok) {
      answer++;
    }
  }
  cout << answer << 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 MAXL = 1000111;
char s[MAXL];
char t[MAXL];
int n, m;
const int P = 101;
const int MOD1 = 1E9 + 7, MOD2 = 1E9 + 9;
int p1[MAXL], p2[MAXL];
int hash1[MAXL], hash2[MAXL];
void makeMemLim() {
  vector<int> x;
  for (int i = 0; i < 1000000000; i++) {
    x.push_back(i);
  }
}
inline int mod(int x, int md) {
  while (x < 0) x += md;
  while (x >= md) x -= md;
  return x;
}
inline pair<int, int> getNormedHash(int l, int r) {
  if (l < 0 || l >= m) {
    makeMemLim();
  }
  if (r < 0 || r >= m) {
    makeMemLim();
  }
  int st1 = l == 0 ? 0 : hash1[l - 1];
  int st2 = l == 0 ? 0 : hash2[l - 1];
  int fin1 = hash1[r];
  int fin2 = hash2[r];
  int diff1 = mod(fin1 - st1, MOD1);
  int diff2 = mod(fin2 - st2, MOD2);
  int norm1 = (long long)diff1 * p1[MAXL - 10 - l] % MOD1;
  int norm2 = (long long)diff2 * p2[MAXL - 10 - l] % MOD2;
  return {norm1, norm2};
}
int main() {
  p1[0] = p2[0] = 1;
  for (int i = 1; i < MAXL; i++) {
    p1[i] = (long long)p1[i - 1] * P % MOD1;
    p2[i] = (long long)p2[i - 1] * P % MOD2;
  }
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  m = strlen(t);
  for (int i = 0; i < m; i++) {
    if (i >= MAXL) {
      makeMemLim();
    }
    int prev1;
    if (i == 0) {
      prev1 = 0;
    } else {
      prev1 = hash1[i - 1];
    }
    int prev2;
    if (i == 0) {
      prev2 = 0;
    } else {
      prev2 = hash2[i - 1];
    }
    hash1[i] = ((long long)prev1 + (long long)t[i] * p1[i]) % MOD1;
    hash2[i] = ((long long)prev2 + (long long)t[i] * p2[i]) % MOD2;
  }
  if (m > MAXL - 1) {
    makeMemLim();
  }
  int cnt0 = 0, cnt1 = 0;
  int first0 = 1E9, first1 = 1E9;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      cnt0++;
      first0 = min(first0, i);
    } else {
      cnt1++;
      first1 = min(first1, i);
    }
  }
  int answer = 0;
  for (int len0 = 1; len0 <= m; len0++) {
    int len1 = (m - (long long)len0 * cnt0) / cnt1;
    if (len1 <= 0) {
      break;
    }
    if ((long long)len0 * cnt0 + (long long)len1 * cnt1 != (long long)m) {
      continue;
    }
    pair<int, int> example0, example1;
    int pos = 0;
    bool ok = true;
    for (int i = 0; i < n; i++) {
      if (pos < 0 || pos >= m) {
        makeMemLim();
      }
      pair<int, int> cur;
      if (s[i] == '0') {
        cur = getNormedHash(pos, pos + len0 - 1);
        if (i == first0) {
          example0 = cur;
        } else {
          if (cur != example0) {
            ok = false;
          }
        }
        pos += len0;
      } else {
        cur = getNormedHash(pos, pos + len1 - 1);
        if (i == first1) {
          example1 = cur;
        } else {
          if (cur != example1) {
            ok = false;
          }
        }
        pos += len1;
      }
    }
    if (example0 != example1 && ok) {
      answer++;
    }
  }
  cout << answer << endl;
  return 0;
}

```