#include <bits/stdc++.h>
using namespace std;
using LD = long double;
using PLL = pair<long long, long long>;
using VII = vector<pair<int, int> >;
template <class T>
bool power_2(T v) {
  static_assert(std::is_integral<T>::value, "type should be integral");
  return v && !(v & (v - 1));
}
template <class T>
istream& operator>>(istream& st, vector<T>& container) {
  for (auto& u : container) st >> u;
  return st;
}
template <class T>
ostream& operator<<(ostream& st, const vector<T>& container) {
  for (auto& u : container) st << u << '\n';
  return st;
}
template <class T, size_t N>
istream& operator>>(istream& st, array<T, N>& container) {
  for (auto& u : container) st >> u;
  return st;
}
template <class T, size_t N>
ostream& operator<<(ostream& st, const array<T, N>& container) {
  for (auto u : container) st << u << ' ';
  return st;
}
template <class T, class U>
istream& operator>>(istream& st, pair<T, U>& p) {
  st >> p.first >> p.second;
  return st;
}
template <class T, class U>
ostream& operator<<(ostream& st, pair<T, U> p) {
  st << p.first << ' ' << p.second;
  return st;
}
template <class T, class U, class V>
pair<T, U> operator*(pair<T, U> p, V val) {
  return {p.first * val, p.second * val};
}
template <class T, class U, class V>
pair<T, U> operator/(pair<T, U> p, V val) {
  return {p.first / val, p.second / val};
}
template <class T, class U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
  return {a.first - b.first, a.second - b.second};
}
template <class T, class U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
  return {a.first + b.first, a.second + b.second};
}
template <class T>
T dotProduct(pair<T, T> a, pair<T, T> b) {
  return a.first * b.first + a.second * b.second;
}
template <class T>
T crossProduct(pair<T, T> a, pair<T, T> b) {
  return a.first * b.second - a.second * b.first;
}
template <class T>
T lengthPow(pair<T, T> a) {
  return a.first * a.first + a.second * a.second;
}
template <class T>
LD length(pair<T, T> a) {
  return sqrt(lengthPow(a));
}
const int N = 1e6 + 57, inf = 1e9 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 7;
const long double PI = acos(-1);
const LD EPS = 1e-12;
const int pod = 29;
long long hasz[N];
long long potegi[N];
char start;
string s, t;
int pos1 = 0, pos2 = 0;
bool teSame(int a, int b, int c, int d) {
  if (b - a != d - c) return 0;
  long long odej = 0;
  if (a > 0) odej = hasz[a - 1] * potegi[b - a + 1] % MOD;
  long long l = (hasz[b] - odej + MOD) % MOD;
  if (c > 0) odej = hasz[c - 1] * potegi[d - c + 1] % MOD;
  long long p = (hasz[d] - odej + MOD) % MOD;
  if (l == p) {
    return 1;
    int zmiana = (d - c) / 6;
    for (int i = 0; i < 6; ++i) {
      if (t[a + i * zmiana] != t[c + i * zmiana]) return 0;
    }
    return 1;
  }
  return 0;
}
bool check(int dl1, int dl2) {
  int pos = 0;
  int posS = 0;
  int posT = pos2 * dl1;
  if (teSame(0, dl1 - 1, posT, posT + dl2 - 1)) return 0;
  while (pos < t.size()) {
    if (s[posS] == start) {
      if (!teSame(0, dl1 - 1, pos, pos + dl1 - 1)) return 0;
      pos += dl1;
    } else {
      if (!teSame(posT, posT + dl2 - 1, pos, pos + dl2 - 1)) return 0;
      pos += dl2;
    }
    ++posS;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout << fixed << setprecision(9);
  cin >> s >> t;
  int n = t.size();
  potegi[0] = 1;
  for (int i = 1; i <= t.size(); ++i) {
    potegi[i] = potegi[i - 1] * pod % MOD;
  }
  for (int i = 0; i < t.size(); ++i) {
    if (i > 0) hasz[i] = hasz[i - 1] * pod % MOD;
    hasz[i] += (t[i] - 'a' + 1);
    hasz[i] %= MOD;
  }
  start = s[0];
  long long zera = 0, jed = 0;
  for (auto u : s) {
    if (u == start)
      ++zera;
    else
      ++jed;
  }
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != start) {
      pos2 = i;
      break;
    }
  }
  int res = 0;
  long long dl = 1;
  while (dl * zera + jed <= t.size()) {
    int zostalo = t.size() - dl * zera;
    if (zostalo % jed != 0) {
      ++dl;
      continue;
    }
    int dl2 = zostalo / jed;
    if (check(dl, dl2)) ++res;
    ++dl;
  }
  cout << res;
  return 0;
}

### Prompt

Your challenge is to write 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;
using LD = long double;
using PLL = pair<long long, long long>;
using VII = vector<pair<int, int> >;
template <class T>
bool power_2(T v) {
  static_assert(std::is_integral<T>::value, "type should be integral");
  return v && !(v & (v - 1));
}
template <class T>
istream& operator>>(istream& st, vector<T>& container) {
  for (auto& u : container) st >> u;
  return st;
}
template <class T>
ostream& operator<<(ostream& st, const vector<T>& container) {
  for (auto& u : container) st << u << '\n';
  return st;
}
template <class T, size_t N>
istream& operator>>(istream& st, array<T, N>& container) {
  for (auto& u : container) st >> u;
  return st;
}
template <class T, size_t N>
ostream& operator<<(ostream& st, const array<T, N>& container) {
  for (auto u : container) st << u << ' ';
  return st;
}
template <class T, class U>
istream& operator>>(istream& st, pair<T, U>& p) {
  st >> p.first >> p.second;
  return st;
}
template <class T, class U>
ostream& operator<<(ostream& st, pair<T, U> p) {
  st << p.first << ' ' << p.second;
  return st;
}
template <class T, class U, class V>
pair<T, U> operator*(pair<T, U> p, V val) {
  return {p.first * val, p.second * val};
}
template <class T, class U, class V>
pair<T, U> operator/(pair<T, U> p, V val) {
  return {p.first / val, p.second / val};
}
template <class T, class U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
  return {a.first - b.first, a.second - b.second};
}
template <class T, class U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
  return {a.first + b.first, a.second + b.second};
}
template <class T>
T dotProduct(pair<T, T> a, pair<T, T> b) {
  return a.first * b.first + a.second * b.second;
}
template <class T>
T crossProduct(pair<T, T> a, pair<T, T> b) {
  return a.first * b.second - a.second * b.first;
}
template <class T>
T lengthPow(pair<T, T> a) {
  return a.first * a.first + a.second * a.second;
}
template <class T>
LD length(pair<T, T> a) {
  return sqrt(lengthPow(a));
}
const int N = 1e6 + 57, inf = 1e9 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 7;
const long double PI = acos(-1);
const LD EPS = 1e-12;
const int pod = 29;
long long hasz[N];
long long potegi[N];
char start;
string s, t;
int pos1 = 0, pos2 = 0;
bool teSame(int a, int b, int c, int d) {
  if (b - a != d - c) return 0;
  long long odej = 0;
  if (a > 0) odej = hasz[a - 1] * potegi[b - a + 1] % MOD;
  long long l = (hasz[b] - odej + MOD) % MOD;
  if (c > 0) odej = hasz[c - 1] * potegi[d - c + 1] % MOD;
  long long p = (hasz[d] - odej + MOD) % MOD;
  if (l == p) {
    return 1;
    int zmiana = (d - c) / 6;
    for (int i = 0; i < 6; ++i) {
      if (t[a + i * zmiana] != t[c + i * zmiana]) return 0;
    }
    return 1;
  }
  return 0;
}
bool check(int dl1, int dl2) {
  int pos = 0;
  int posS = 0;
  int posT = pos2 * dl1;
  if (teSame(0, dl1 - 1, posT, posT + dl2 - 1)) return 0;
  while (pos < t.size()) {
    if (s[posS] == start) {
      if (!teSame(0, dl1 - 1, pos, pos + dl1 - 1)) return 0;
      pos += dl1;
    } else {
      if (!teSame(posT, posT + dl2 - 1, pos, pos + dl2 - 1)) return 0;
      pos += dl2;
    }
    ++posS;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout << fixed << setprecision(9);
  cin >> s >> t;
  int n = t.size();
  potegi[0] = 1;
  for (int i = 1; i <= t.size(); ++i) {
    potegi[i] = potegi[i - 1] * pod % MOD;
  }
  for (int i = 0; i < t.size(); ++i) {
    if (i > 0) hasz[i] = hasz[i - 1] * pod % MOD;
    hasz[i] += (t[i] - 'a' + 1);
    hasz[i] %= MOD;
  }
  start = s[0];
  long long zera = 0, jed = 0;
  for (auto u : s) {
    if (u == start)
      ++zera;
    else
      ++jed;
  }
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != start) {
      pos2 = i;
      break;
    }
  }
  int res = 0;
  long long dl = 1;
  while (dl * zera + jed <= t.size()) {
    int zostalo = t.size() - dl * zera;
    if (zostalo % jed != 0) {
      ++dl;
      continue;
    }
    int dl2 = zostalo / jed;
    if (check(dl, dl2)) ++res;
    ++dl;
  }
  cout << res;
  return 0;
}

```