#include <bits/stdc++.h>
using namespace std;
const int seed = 131;
const long long LLMAX = 2e18;
const int MOD = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 1e6 + 10;
const int hmod1 = 0x48E2DCE7;
const int hmod2 = 0x60000005;
inline long long sqr(long long x) { return x * x; }
inline int sqr(int x) { return x * x; }
inline double sqr(double x) { return x * x; }
long long __gcd(long long a, long long b) {
  return b == 0 ? a : __gcd(b, a % b);
}
long long qpow(long long a, long long n) {
  long long sum = 1;
  while (n) {
    if (n & 1) sum = sum * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return sum;
}
inline int dcmp(double x) {
  if (fabs(x) < eps) return 0;
  return (x > 0 ? 1 : -1);
}
long long p1[MAXN], p2[MAXN], hash1[MAXN], hash2[MAXN];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  long long n = s.size(), m = t.size(), zero = 0, one = 0, ans = 0;
  s = "#" + s, t = "#" + t;
  for (long long i = 1; i <= n; i++) {
    if (s[i] == '0')
      zero++;
    else
      one++;
  }
  p1[0] = p2[0] = 1;
  for (long long i = 1; i <= m; i++) {
    p1[i] = p1[i - 1] * seed % hmod1;
    p2[i] = p2[i - 1] * seed % hmod2;
    hash1[i] = (hash1[i - 1] * seed + (t[i] - 'a' + 1)) % hmod1;
    hash2[i] = (hash2[i - 1] * seed + (t[i] - 'a' + 1)) % hmod2;
  }
  for (long long len0 = 1; len0 < m; len0++)
    if ((m - zero * len0) % one == 0) {
      long long len1 = (m - zero * len0) / one, sum00 = -1, sum01 = -1,
                sum10 = -1, sum11 = -1, flag = 0;
      if (len1 <= 0) continue;
      for (long long i = 1, j = 0; i <= n && !flag; i++) {
        if (s[i] == '0') {
          j += len0;
          if (sum00 == -1) {
            sum00 =
                (hash1[j] - hash1[j - len0] * p1[len0] % hmod1 + hmod1) % hmod1;
            sum01 =
                (hash2[j] - hash2[j - len0] * p2[len0] % hmod2 + hmod2) % hmod2;
          } else if (sum00 != (hash1[j] - hash1[j - len0] * p1[len0] % hmod1 +
                               hmod1) %
                                  hmod1 ||
                     sum01 != (hash2[j] - hash2[j - len0] * p2[len0] % hmod2 +
                               hmod2) %
                                  hmod2)
            flag = 1;
        } else {
          j += len1;
          if (sum10 == -1) {
            sum10 =
                (hash1[j] - hash1[j - len1] * p1[len1] % hmod1 + hmod1) % hmod1;
            sum11 =
                (hash2[j] - hash2[j - len1] * p2[len1] % hmod2 + hmod2) % hmod2;
          } else if (sum10 != (hash1[j] - hash1[j - len1] * p1[len1] % hmod1 +
                               hmod1) %
                                  hmod1 ||
                     sum11 != (hash2[j] - hash2[j - len1] * p2[len1] % hmod2 +
                               hmod2) %
                                  hmod2)
            flag = 1;
        }
      }
      if ((sum00 != sum10 || sum01 != sum11) && !flag) ans++;
    }
  cout << ans << endl;
  return 0;
}
