#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int base = 17215;
const int mod = 1000000123;
int n, m;
int cnt[2];
int hs[N], pw[N];
string s, t;
int get(int l, int r) {
  return (hs[r] - 1LL * pw[r - l + 1] * hs[l - 1] % mod + mod) % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> s >> t;
  n = s.size(), m = t.size();
  s = '~' + s;
  t = '~' + t;
  hs[0] = 0, pw[0] = 1;
  for (int i = 1; i <= m; ++i) {
    hs[i] = (1LL * hs[i - 1] * base % mod + (t[i] - 'a' + 5)) % mod;
    pw[i] = 1LL * pw[i - 1] * base % mod;
  }
  if (s[1] == '1') {
    for (int i = 1; i <= n; ++i) s[i] = '0' + '1' - s[i];
  }
  for (int i = 1; i <= n; ++i) cnt[s[i] - '0']++;
  int ans = 0;
  for (int len_r0 = 1; len_r0 <= m; ++len_r0) {
    long long all_r0 = (long long)cnt[0] * len_r0;
    long long all_r1 = (long long)m - all_r0;
    if (all_r1 <= 0 || all_r1 % cnt[1]) continue;
    int len_r1 = all_r1 / cnt[1];
    int hs0 = get(1, len_r0);
    int hs1 = -1;
    int ptr = 1;
    bool flag = true;
    for (int i = 1; i <= n; ++i) {
      if (s[i] == '0') {
        if (get(ptr, ptr + len_r0 - 1) != hs0) {
          flag = false;
          break;
        }
        ptr += len_r0;
      } else {
        if (hs1 == -1) hs1 = get(ptr, ptr + len_r1 - 1);
        if (get(ptr, ptr + len_r1 - 1) != hs1) {
          flag = false;
          break;
        }
        ptr += len_r1;
      }
    }
    if (hs0 == hs1) flag = false;
    ans += flag;
  }
  cout << ans << '\n';
}
