#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
struct hasher {
  ll P, mod1, mod2;
  string s;
  int n;
  vector<ll> pacc1, pacc2;
  vector<ll> h1, h2;
  bool isprime(ll x) {
    for (ll i = 2; i * i <= x; i++) {
      if (x % i == 0) return false;
    }
    return true;
  }
  ll randprime() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    ll p = rng();
    while (!isprime(p)) p++;
    return p;
  }
  void init(string _s) {
    P = 39;
    mod1 = 1e9 + 7;
    mod2 = 1e9 + 9;
    s = _s;
    n = s.length();
    pacc1.resize(n + 10);
    pacc2.resize(n + 10);
    h1.resize(n + 10);
    h2.resize(n + 10);
    pacc1[0] = pacc2[0] = 1;
    for (int i = 1; i < n; i++) {
      pacc1[i] = P * pacc1[i - 1] % mod1;
      pacc2[i] = P * pacc2[i - 1] % mod2;
    }
    h1[0] = h2[0] = 1;
    for (int i = 0; i < n; i++) {
      h1[i + 1] = (h1[i] * P + s[i]) % mod1;
      h2[i + 1] = (h2[i] * P + s[i]) % mod2;
    }
  }
  ll substr(int i, int len) {
    assert(i >= 0);
    assert(i < n);
    assert(len >= 0);
    assert(len <= n);
    ll res1 = ((h1[i + len] - pacc1[len] * h1[i] % mod1) + mod1) % mod1;
    ll res2 = ((h2[i + len] - pacc2[len] * h2[i] % mod2) + mod2) % mod2;
    return res1 * mod2 + res2;
  }
};
const int maxn = 1e6 + 5;
string s, t;
int n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> t;
  n = s.length();
  m = t.length();
  hasher ha;
  ha.init(t);
  int c0 = 0;
  int c1 = 0;
  for (char c : s) {
    if (c == '0') c0++;
    if (c == '1') c1++;
  }
  int res = 0;
  for (int len0 = 1; len0 * c0 <= m; len0++) {
    if ((m - len0 * c0) % c1) continue;
    int len1 = (m - len0 * c0) / c1;
    if (len0 > 0 && len1 > 0 && (len0 * c0 + len1 * c1) == m) {
      bool ok = true;
      int j = 0;
      ll h0 = -1;
      ll h1 = -1;
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
          ll cur = ha.substr(j, len0);
          if (h0 == -1) {
            h0 = cur;
          } else if (h0 != cur) {
            ok = false;
            break;
          }
          j += len0;
        }
        if (s[i] == '1') {
          ll cur = ha.substr(j, len1);
          if (h1 == -1) {
            h1 = cur;
          } else if (h1 != cur) {
            ok = false;
            break;
          }
          j += len1;
        }
      }
      if (h0 == h1) {
        ok = false;
      }
      res += ok;
    }
  }
  cout << res << endl;
  return 0;
}
