#include <bits/stdc++.h>
using namespace std;
char getc() {
  char c = getchar();
  while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
    c = getchar();
  return c;
}
long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return x * f;
}
long long n, m, cnt0, cnt1, ans, Hash[2][2000010], P[2], Q[2][2000010];
char a[2000010], b[2000010];
long long get(long long x, long long y, long long op) {
  return (Hash[op][y] - 1ll * Hash[op][x - 1] * Q[op][y - x + 1] % P[op] +
          P[op]) %
         P[op];
}
signed main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  scanf("%s", b + 1);
  m = strlen(b + 1);
  for (long long i = 1; i <= n; i++)
    if (a[i] == '0')
      cnt0++;
    else
      cnt1++;
  P[0] = 1000000007, P[1] = 19260817;
  for (long long i = 1; i <= m; i++)
    Hash[0][i] = (Hash[0][i - 1] * 509ll + b[i]) % P[0];
  for (long long i = 1; i <= m; i++)
    Hash[1][i] = (Hash[1][i - 1] * 509ll + b[i]) % P[1];
  Q[0][0] = Q[1][0] = 1;
  for (long long i = 1; i <= m; i++) Q[0][i] = Q[0][i - 1] * 509ll % P[0];
  for (long long i = 1; i <= m; i++) Q[1][i] = Q[1][i - 1] * 509ll % P[1];
  for (long long i = 1; i <= m; i++)
    if (m > cnt0 * i && (m - cnt0 * i) % cnt1 == 0) {
      long long j = (m - cnt0 * i) / cnt1;
      long long cur = 1, pos0 = 0, pos1 = 0;
      for (long long x = 1; x <= n; x++)
        if (a[x] == '0')
          pos0 = cur, cur += i;
        else
          pos1 = cur, cur += j;
      cur = 1;
      long long tot = 1;
      if (i == j) {
        tot = 0;
        for (long long x = 1; x <= i; x++)
          if (b[pos0 + x - 1] != b[pos1 + x - 1]) {
            tot = 1;
            break;
          }
      }
      if (tot == 0) continue;
      for (long long x = 1; x <= n; x++)
        if (a[x] == '0') {
          tot = (get(cur, cur + i - 1, 0) == get(pos0, pos0 + i - 1, 0) &&
                 get(cur, cur + i - 1, 1) == get(pos0, pos0 + i - 1, 1));
          cur += i;
          if (tot == 0) break;
        } else {
          tot = (get(cur, cur + j - 1, 0) == get(pos1, pos1 + j - 1, 0) &&
                 get(cur, cur + j - 1, 1) == get(pos1, pos1 + j - 1, 1));
          cur += j;
          if (tot == 0) break;
        }
      ans += tot;
    }
  cout << ans;
  return 0;
}
