#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
long long hs[N], pw[N], p = 31;
int n, m, ans, cur, cnt0, cnt1, idx, idx1, sz0, sz1, mod = 1e9 + 7;
string s1, s2;
long long ss;
long long str0, str1;
long long f_p(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power % 2 == 1) result = (result * base) % mod;
    base = (base * base) % mod;
    power = power / 2;
  }
  return result;
}
int in(char second) { return int(second - 'a' + 1); }
long long gethsh(int le, int ri) {
  return (((hs[ri] - hs[le - 1]) * f_p(pw[le - 1], mod - 2)) % mod + mod) % mod;
}
int main() {
  std::ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> s1 >> s2;
  n = s1.size();
  m = s2.size();
  s1 = "@" + s1;
  s2 = "@" + s2;
  for (int i = 1; i <= n; i++) {
    if (s1[i] == '0') {
      cnt0++;
      if (!idx) idx = i;
    } else {
      cnt1++;
      if (!idx1) idx1 = i;
    }
  }
  pw[0] = 1;
  for (int i = 1; i <= m; i++) {
    pw[i] = pw[i - 1] * p;
    pw[i] %= mod;
  }
  for (int i = 1; i <= m; i++) {
    hs[i] = hs[i - 1] + pw[i - 1] * in(s2[i]);
    hs[i] %= mod;
  }
  if (cnt0 >= cnt1) {
    for (int sz = 1; sz <= m / cnt0; sz++) {
      sz0 = cnt0 * sz;
      if ((m - sz0) % cnt1) continue;
      sz1 = (m - sz0) / cnt1;
      cur = 1;
      ss = 0;
      str1 = 0;
      str0 = 0;
      if (sz1 == 0) continue;
      str0 = gethsh((idx - 1) * sz1 + 1, (idx - 1) * sz1 + sz);
      str1 = gethsh((idx1 - 1) * sz + 1, (idx1 - 1) * sz + sz1);
      if (str0 == str1) continue;
      cur = 1;
      for (int j = 1; j <= n; j++) {
        if (s1[j] == '0')
          ss += (str0 * pw[cur - 1]) % mod, cur += sz;
        else
          ss += (str1 * pw[cur - 1]) % mod, cur += sz1;
        ss %= mod;
      }
      if (ss == hs[m]) ans++;
    }
    cout << ans;
  } else {
    for (int sz = 1; sz <= m / cnt1; sz++) {
      sz1 = cnt1 * sz;
      if ((m - sz1) % cnt0) continue;
      sz1 = (m - sz1) / cnt0;
      cur = 1;
      ss = 0;
      str1 = 0;
      str0 = 0;
      if (sz1 == 0) continue;
      str0 = gethsh((idx - 1) * sz + 1, (idx - 1) * sz + sz1);
      str1 = gethsh((idx1 - 1) * sz1 + 1, (idx1 - 1) * sz1 + sz);
      if (str0 == str1) continue;
      cur = 1;
      for (int j = 1; j <= n; j++) {
        if (s1[j] == '0')
          ss += (str0 * pw[cur - 1]) % mod, cur += sz1;
        else
          ss += (str1 * pw[cur - 1]) % mod, cur += sz;
        ss %= mod;
      }
      if (ss == hs[m]) ans++;
    }
    cout << ans;
  }
}
