#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int its = 0, itt = 0, mark1;
  for (; itt < t.size(); ++itt) {
    if (t[itt] == s[its]) {
      ++its;
      if (its >= s.size()) break;
    }
  }
  mark1 = itt;
  its = s.size() - 1;
  itt = t.size() - 1;
  for (; itt >= 0; --itt) {
    if (t[itt] == s[its]) {
      --its;
      if (its < 0) break;
    }
  }
  if (itt < mark1) {
    cout << "0";
  } else {
    cout << itt - mark1;
  }
}
