#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, provera;
  int p = -1, d = -1, brojac = 0;
  bool flag = false;
  cin >> s >> provera;
  for (int i = 0; i < provera.length(); ++i) {
    if (provera[i] == s[brojac]) {
      brojac++;
    }
    if (brojac == s.length()) {
      p = i;
      brojac--;
      break;
    }
  }
  for (int i = provera.length() - 1; i >= 0; --i) {
    if (provera[i] == s[brojac]) brojac--;
    if (brojac < 0) {
      d = i;
      break;
    }
  }
  if ((d - p) > 0)
    cout << d - p << endl;
  else
    cout << 0 << endl;
  return 0;
}
