#include <bits/stdc++.h>
using namespace std;
string s, t;
int le;
int re;
int main() {
  cin >> s >> t;
  int pos = 0;
  le = 0;
  while (le < (int)t.size() && pos < (int)s.size()) {
    if (s[pos] == t[le]) pos++;
    if (pos < (int)s.size()) le++;
  }
  if (pos < (int)s.size()) return !printf("0");
  pos = (int)s.size() - 1;
  re = (int)t.size() - 1;
  while (re >= 0 && pos >= 0) {
    if (s[pos] == t[re]) pos--;
    if (pos >= 0) re--;
  }
  printf("%d", max(0, re - le));
  return 0;
}
