#include <bits/stdc++.h>
#pragma comment(linker, "/stack:225450978")
#pragma GCC optimize("Ofast")
using namespace std;
const long long Mod = 2100003221LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9,
                  Gold = ((1 + sqrt(5)) / 2);
long long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
long long keyCount = sizeof(keymod) / sizeof(long long);
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcountll(s);
}
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
string cppstr_infile = "FILE.IN";
string cppstr_outfile = "FILE.OUT";
string s, t;
long long n, m, Base = 31;
vector<long long> Hash, HashInv, HashPow;
long long modPow(long long a, long long b) {
  if (b == 0) return 1;
  long long tmp = modPow(a, b / 2);
  if (b % 2 == 0) return ((tmp * tmp) % Mod);
  return ((((tmp * tmp) % Mod) * a) % Mod);
}
void GenerateHash() {
  Hash.resize(m, 0);
  HashInv.resize(m, 0);
  HashPow.resize(m, 0);
  Hash[0] = (t[0] - 'a');
  HashInv[0] = modPow(Base, Mod - 2);
  HashPow[0] = Base;
  for (long long i = 1; i < m; i++) HashPow[i] = (HashPow[i - 1] * Base) % Mod;
  for (long long i = 1; i < m; i++)
    Hash[i] = (Hash[i - 1] + (HashPow[i - 1] * (t[i] - 'a')) % Mod) % Mod;
  for (long long i = 1; i < m; i++)
    HashInv[i] = (HashInv[i - 1] * HashInv[0]) % Mod;
}
long long GetHash(long long l, long long r) {
  long long val = Hash[r];
  if (l > 0) {
    val -= Hash[l - 1];
    val %= Mod;
    while (val < 0) val += Mod;
    val *= HashInv[l - 1];
    val %= Mod;
  }
  return val;
}
bool validate(long long x, long long y) {
  long long L = 0, ZeroHash = -1, IchiHash = -1;
  for (long long i = 0; i < n; i++) {
    long long R = 0;
    if (s[i] == '0')
      R = L + x - 1;
    else
      R = L + y - 1;
    long long Decoded = GetHash(L, R);
    if (s[i] == '0') {
      if (ZeroHash == -1)
        ZeroHash = Decoded;
      else if (ZeroHash != Decoded)
        return false;
    }
    if (s[i] == '1') {
      if (IchiHash == -1)
        IchiHash = Decoded;
      else if (IchiHash != Decoded)
        return false;
    }
    L = R + 1;
  }
  if (x == y)
    return (ZeroHash != IchiHash);
  else
    return true;
}
void Input() {
  cin >> s >> t;
  n = s.size();
  m = t.size();
}
void Solve() {
  GenerateHash();
  long long ans = 0;
  long long Zero = 0, Ichi = 0;
  for (long long i = 0; i < n; i++) {
    Zero += (s[i] == '0');
    Ichi += (s[i] == '1');
  }
  for (long long i = 1; Zero * i < m; i++) {
    if ((m - Zero * i) % Ichi != 0) continue;
    long long j = (m - Zero * i) / Ichi;
    ans += validate(i, j);
  }
  cout << ans;
}
int main(int argc, char* argv[]) {
  ControlIO(argc, argv);
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  Input();
  TimerStart();
  Solve();
  TimerStop();
  return 0;
}
void ControlIO(int argc, char* argv[]) {
  char* infile = new char[cppstr_infile.size() + 1];
  char* outfile = new char[cppstr_outfile.size() + 1];
  strcpy(infile, cppstr_infile.c_str());
  strcpy(outfile, cppstr_outfile.c_str());
}
void TimerStart() {}
void TimerStop() {}
void Exit() {
  TimerStop();
  exit(0);
}

### Prompt

Create a solution in cpp for 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>
#pragma comment(linker, "/stack:225450978")
#pragma GCC optimize("Ofast")
using namespace std;
const long long Mod = 2100003221LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9,
                  Gold = ((1 + sqrt(5)) / 2);
long long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
long long keyCount = sizeof(keymod) / sizeof(long long);
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return __builtin_popcountll(s);
}
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
string cppstr_infile = "FILE.IN";
string cppstr_outfile = "FILE.OUT";
string s, t;
long long n, m, Base = 31;
vector<long long> Hash, HashInv, HashPow;
long long modPow(long long a, long long b) {
  if (b == 0) return 1;
  long long tmp = modPow(a, b / 2);
  if (b % 2 == 0) return ((tmp * tmp) % Mod);
  return ((((tmp * tmp) % Mod) * a) % Mod);
}
void GenerateHash() {
  Hash.resize(m, 0);
  HashInv.resize(m, 0);
  HashPow.resize(m, 0);
  Hash[0] = (t[0] - 'a');
  HashInv[0] = modPow(Base, Mod - 2);
  HashPow[0] = Base;
  for (long long i = 1; i < m; i++) HashPow[i] = (HashPow[i - 1] * Base) % Mod;
  for (long long i = 1; i < m; i++)
    Hash[i] = (Hash[i - 1] + (HashPow[i - 1] * (t[i] - 'a')) % Mod) % Mod;
  for (long long i = 1; i < m; i++)
    HashInv[i] = (HashInv[i - 1] * HashInv[0]) % Mod;
}
long long GetHash(long long l, long long r) {
  long long val = Hash[r];
  if (l > 0) {
    val -= Hash[l - 1];
    val %= Mod;
    while (val < 0) val += Mod;
    val *= HashInv[l - 1];
    val %= Mod;
  }
  return val;
}
bool validate(long long x, long long y) {
  long long L = 0, ZeroHash = -1, IchiHash = -1;
  for (long long i = 0; i < n; i++) {
    long long R = 0;
    if (s[i] == '0')
      R = L + x - 1;
    else
      R = L + y - 1;
    long long Decoded = GetHash(L, R);
    if (s[i] == '0') {
      if (ZeroHash == -1)
        ZeroHash = Decoded;
      else if (ZeroHash != Decoded)
        return false;
    }
    if (s[i] == '1') {
      if (IchiHash == -1)
        IchiHash = Decoded;
      else if (IchiHash != Decoded)
        return false;
    }
    L = R + 1;
  }
  if (x == y)
    return (ZeroHash != IchiHash);
  else
    return true;
}
void Input() {
  cin >> s >> t;
  n = s.size();
  m = t.size();
}
void Solve() {
  GenerateHash();
  long long ans = 0;
  long long Zero = 0, Ichi = 0;
  for (long long i = 0; i < n; i++) {
    Zero += (s[i] == '0');
    Ichi += (s[i] == '1');
  }
  for (long long i = 1; Zero * i < m; i++) {
    if ((m - Zero * i) % Ichi != 0) continue;
    long long j = (m - Zero * i) / Ichi;
    ans += validate(i, j);
  }
  cout << ans;
}
int main(int argc, char* argv[]) {
  ControlIO(argc, argv);
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  Input();
  TimerStart();
  Solve();
  TimerStop();
  return 0;
}
void ControlIO(int argc, char* argv[]) {
  char* infile = new char[cppstr_infile.size() + 1];
  char* outfile = new char[cppstr_outfile.size() + 1];
  strcpy(infile, cppstr_infile.c_str());
  strcpy(outfile, cppstr_outfile.c_str());
}
void TimerStart() {}
void TimerStop() {}
void Exit() {
  TimerStop();
  exit(0);
}

```