#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
struct Hash {
  const long long int mod = 1791791791;
  const long long int base = 255;
  vector<long long int> h, p;
  Hash(const string& s) {
    long long int n = s.size();
    h.resize(n + 1);
    p.resize(n + 1, 1);
    for (long long int i = 1; i <= n; i++) {
      h[i] = (h[i - 1] * base + s[i - 1]) % mod;
      p[i] = (p[i - 1] * base) % mod;
    }
  }
  long long int getSub(long long int l, long long int r) {
    return (h[r] - (h[l - 1] * p[r - l + 1]) % mod + mod) % mod;
  }
  ~Hash(){};
};
void rev(string& s) {
  for (auto& i : s) {
    if (i == '0')
      i = '1';
    else
      i = '0';
  }
}
signed main() {
  string s, t;
  cin >> s >> t;
  long long int n = t.size();
  Hash h(t);
  long long int cnt0 = 0, cnt1 = 0;
  for (auto i : s) {
    cnt0 += (i == '0');
    cnt1 += (i == '1');
  }
  if (cnt0 < cnt1) {
    swap(cnt0, cnt1);
    rev(s);
  }
  long long int ans = 0;
  for (long long int len0 = 1; len0 < t.size() / cnt0; len0++) {
    if (cnt1 == 0 || (n - len0 * cnt0) % cnt1 == 0) {
      long long int len1 = 0;
      if (cnt1 > 0) len1 = (n - len0 * cnt0) / cnt1;
      long long int last = 1;
      unordered_set<long long int> se0, se1;
      for (long long int j = 0; j < s.size(); j++) {
        if (s[j] == '0') {
          se0.insert(h.getSub(last, last + len0 - 1));
          last += len0;
        } else {
          se1.insert(h.getSub(last, last + len1 - 1));
          last += len1;
        }
      }
      if (se0.size() <= 1 && se1.size() <= 1) ans++;
      if (se0.size() == 1 && se1.size() == 1 &&
          (*se1.begin()) == (*se0.begin()))
        ans--;
    }
  }
  cout << ans;
  return 0;
}
