#include <bits/stdc++.h>
using namespace std;
const int MOD[] = {1000000007, 1000000009};
const int BASE[] = {283, 293};
pair<long long, long long> SFT[1000010 + 1];
void prepare() {
  SFT[0] = make_pair(1, 1);
  for (int i = 1; i <= 1000010; ++i)
    SFT[i] = make_pair((SFT[i - 1].first * BASE[0]) % MOD[0],
                       (SFT[i - 1].second * BASE[1]) % MOD[1]);
}
pair<long long, long long> add(const pair<long long, long long>& a,
                               const pair<long long, long long>& b) {
  pair<long long, long long> ret(a.first + b.first, a.second + b.second);
  if (ret.first >= MOD[0]) ret.first -= MOD[0];
  if (ret.second >= MOD[1]) ret.second -= MOD[1];
  return ret;
}
pair<long long, long long> sub(const pair<long long, long long>& a,
                               const pair<long long, long long>& b) {
  pair<long long, long long> ret(a.first - b.first, a.second - b.second);
  if (ret.first < 0) ret.first += MOD[0];
  if (ret.second < 0) ret.second += MOD[1];
  return ret;
}
pair<long long, long long> shift(const pair<long long, long long>& a, int how) {
  return make_pair((a.first * SFT[how].first) % MOD[0],
                   (a.second * SFT[how].second) % MOD[1]);
}
struct HASH {
  vector<pair<long long, long long> > hc;
  void load(const string& w) {
    hc.resize(((int)(w).size()));
    pair<long long, long long> old(0, 0);
    for (int i = 0; i < ((int)(w).size()); ++i)
      old = add(shift(old, 1), make_pair(w[i], w[i])), hc[i] = old;
  }
  pair<long long, long long> code(int l, int r) {
    if (l > r) return make_pair(0, 0);
    if (l == 0) return hc[r];
    return sub(hc[r], shift(hc[l - 1], r - l + 1));
  }
};
void Write(const pair<long long, long long>& w) {
  cout << w.first << ' ' << w.second << endl;
}
HASH h;
char s[1000010];
char t[1000010];
int n, m;
int lo[1000010], hi[1000010];
bool Same(int a1, int b1, int a2, int b2) {
  if (b1 - a1 != b2 - a2) return false;
  return h.code(a1, b1) == h.code(a2, b2);
}
int main() {
  prepare();
  scanf("%s", &s[0]);
  scanf("%s", &t[0]);
  n = strlen(s);
  m = strlen(t);
  h.load(string(t));
  if (count(s, s + n, '0') < count(s, s + n, '1')) {
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0')
        s[i] = '1';
      else
        s[i] = '0';
    }
  }
  long long c0 = count(s, s + n, '0');
  long long c1 = n - c0;
  int p0, p1;
  for (int i = 0; i < n; ++i)
    if (s[i] == '0')
      p0 = i;
    else
      p1 = i;
  int answer = 0;
  for (long long take0 = 1; take0 <= m; ++take0) {
    if (take0 * c0 > m) break;
    long long left = m - take0 * c0;
    if (left % c1 != 0) continue;
    long long take1 = left / c1;
    if (take1 < 1) continue;
    int pos = 0;
    for (int i = 0; i < n; ++i) {
      int dist;
      if (s[i] == '0')
        dist = take0;
      else
        dist = take1;
      lo[i] = pos;
      hi[i] = pos + dist - 1;
      pos += dist;
    }
    if (!Same(lo[p0], hi[p0], lo[p1], hi[p1])) {
      bool fine = true;
      for (int i = 0; i < n; ++i) {
        if (s[i] == '0' && !Same(lo[i], hi[i], lo[p0], hi[p0])) {
          fine = false;
          break;
        }
        if (s[i] == '1' && !Same(lo[i], hi[i], lo[p1], hi[p1])) {
          fine = false;
          break;
        }
      }
      if (fine) ++answer;
    }
  }
  printf("%d\n", answer);
  return 0;
}
