#include <bits/stdc++.h>
using namespace std;
char s[1010], t[1000010];
int main() {
  scanf("%s%s", s, t);
  int n = strlen(t), m = strlen(s);
  int j = 0, lst = -1, frnt = -1;
  for (int i = 0; i < n; i++) {
    if (s[j] == t[i]) {
      j++;
      if (j == m) {
        lst = i;
        break;
      }
    }
  }
  j = m - 1;
  for (int i = n - 1; i > lst; i--) {
    if (s[j] == t[i]) {
      j--;
      if (j < 0) {
        frnt = i;
        break;
      }
    }
  }
  if ((lst == -1) || (frnt == -1))
    printf("0");
  else
    printf("%d", frnt - lst);
  return 0;
}
