#include <bits/stdc++.h>
const int MaxS = 1005;
const int MaxT = 1000500;
char s[MaxS], t[MaxT];
int ls, lt;
int main() {
  int i, j, p1 = 0, p2 = 0;
  scanf("%s%s", s, t);
  ls = strlen(s);
  lt = strlen(t);
  int start = 0, finish = 0;
  for (i = 0; i < lt; i++) {
    if (t[i] == s[p1]) {
      p1++;
      start = i;
    }
    if (p1 == ls) break;
  }
  if (p1 < ls) {
    printf("0\n");
    return 0;
  }
  for (i = lt - 1; i >= 0; i--) {
    if (t[i] == s[ls - p2 - 1]) {
      p2++;
      finish = i;
    }
    if (p2 == ls) break;
  }
  if (start >= finish)
    printf("0\n");
  else
    printf("%d\n", finish - start);
  return 0;
}
