#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  string t;
  cin >> s >> t;
  long j = 0;
  long ans = 0;
  for (long i = 0; i < t.size(); i++) {
    if (t[i] == s[j]) ++j;
    if (j == s.size()) {
      long rj = s.size() - 1;
      for (long k = t.size() - 1; k >= 0; k--) {
        if (t[k] == s[rj]) --rj;
        if (rj == -1) {
          cout << std::max(k - i, long(0));
          return 0;
        }
      }
      break;
    }
  }
  cout << 0;
  return 0;
}
