#include <bits/stdc++.h>
using namespace std;
const int inf = (long long)1e9;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
const int P = 918357;
const int p[2] = {37, 257};
int c0, c1;
vector<int> cn[2];
string second, t;
long long hval1[1003000], hval2[1003000];
long long cpow1[1003000], cpow2[1003000];
long long ghash(int cloc, int len) {
  long long h1 =
      ((hval1[cloc + len] - cpow1[len] * hval1[cloc]) % MOD1 + MOD1) % MOD1;
  long long h2 =
      ((hval2[cloc + len] - cpow2[len] * hval2[cloc]) % MOD2 + MOD2) % MOD2;
  return h1 * MOD2 + h2;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cpow1[0] = cpow2[0] = 1;
  for (int i = 1; i < 1003000; i++) {
    cpow1[i] = (cpow1[i - 1] * P) % MOD1;
    cpow2[i] = (cpow2[i - 1] * P) % MOD2;
  }
  cin >> second >> t;
  int szs = (int)second.size();
  int szt = (int)t.size();
  if (second[0] == '1') {
    for (int i = 0; i < szs; ++i) second[i] = char('1' - second[i] + '0');
  }
  for (int i = 0; i < szs; ++i) cn[second[i] - '0'].push_back(i);
  hval1[0] = hval2[0] = 0;
  for (int i = 0; i < szt; i++) {
    hval1[i + 1] = (hval1[i] * P + t[i]) % MOD1;
    hval2[i + 1] = (hval2[i] * P + t[i]) % MOD2;
  }
  for (int i = 0; i < szs; ++i) {
    if (second[i] == '0')
      ++c0;
    else
      ++c1;
  }
  int ans = 0;
  for (int l0 = 1; l0 * c0 < szt; ++l0) {
    bool bad = 0;
    if ((szt - l0 * c0) % c1 != 0) continue;
    int l1 = (szt - l0 * c0) / c1;
    int pos = l0;
    long long h1 = ghash(0, l0);
    long long h2 = -1;
    int turn = 1;
    while (pos < szt) {
      if (second[turn] == '0') {
        long long cur = ghash(pos, l0);
        if (cur != h1) {
          bad = 1;
          break;
        }
        pos += l0;
      } else {
        long long cur = ghash(pos, l1);
        if (h2 == -1) {
          h2 = cur;
        } else if (h2 != cur) {
          bad = 1;
          break;
        }
        pos += l1;
      }
      ++turn;
    }
    if (bad == 1 || h1 == h2) bad = 1;
    ans += (int)(bad == 0);
  }
  cout << ans << "\n";
  return 0;
}
