#include <bits/stdc++.h>
int main() {
  char t[1000009], s[1009];
  long int i, j = 0, ans = 0, pr, pl, l, kak;
  scanf("%s", &s);
  scanf("%s", &t);
  l = strlen(t);
  kak = strlen(s);
  for (i = 0; i < l; i++) {
    if (s[j] == t[i]) j++;
    if (j == kak) {
      ans++;
      j = 0;
      if (ans == 1) pl = i;
      if (ans == 2) break;
    }
  }
  if (ans < 2)
    printf("0\n");
  else {
    j = kak - 1;
    for (i = l - 1; i >= 0; i--) {
      if (s[j] == t[i]) j--;
      if (j == -1) {
        pr = i;
        break;
      }
    }
    printf("%ld\n", pr - pl);
  }
  return 0;
}
