#include <bits/stdc++.h>
using namespace std;
char s[1111], t[1000111];
int n, m, l, r;
int main() {
  gets(s);
  gets(t);
  n = strlen(s);
  m = strlen(t);
  l = (int)1e7;
  r = -1;
  int need = 0;
  for (int i = 0; i < m; ++i) {
    if (t[i] == s[need]) ++need;
    if (need == n) {
      l = i;
      break;
    }
  }
  need = n;
  for (int i = m - 1; i >= 0; --i) {
    if (t[i] == s[need - 1]) need--;
    if (!need) {
      r = i;
      break;
    }
  }
  printf("%d\n", max(0, r - l));
  return 0;
}
