#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool uin(T& a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
inline bool uax(T& a, T b) {
  return a < b ? (a = b, true) : false;
}
const int nax = 1e6 + 10, base = 31, mod = 1e9 + 7;
int n, m, hs[nax], po[nax];
int get(int l, int r) {
  return (hs[r] - (long long)hs[l] * po[r - l] % mod + mod) % mod;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  po[0] = 1;
  for (int i = 1; i < nax; ++i) po[i] = (long long)base * po[i - 1] % mod;
  string s, t;
  cin >> s >> t;
  n = (int)s.length(), m = (int)t.length();
  for (int i = 0; i < m; ++i)
    hs[i + 1] = ((long long)hs[i] * base + t[i]) % mod;
  int cnt[2], len[2];
  cnt[0] = count(s.begin(), s.end(), '0');
  cnt[1] = count(s.begin(), s.end(), '1');
  int ans = 0;
  for (len[0] = 1; len[0] * cnt[0] < m; ++len[0]) {
    len[1] = m - len[0] * cnt[0];
    if (len[1] % cnt[1] != 0) continue;
    len[1] /= cnt[1];
    int p = 0;
    int r[] = {-1, -1};
    bool fail = false;
    for (char c : s) {
      c -= '0';
      int myh = get(p, p + len[(int)c]);
      if (r[(int)c] == -1) {
        r[(int)c] = myh;
      } else if (r[(int)c] != myh) {
        fail = true;
        break;
      }
      p += len[(int)c];
    }
    if (!fail && r[0] != r[1]) ++ans;
  }
  cout << ans << '\n';
}
