#include <bits/stdc++.h>
using namespace std;
string s, t;
int sz_s, sz_t;
int pos_L() {
  int it_s = 0;
  for (int it_t = 0; it_t < sz_t; it_t++) {
    if (s[it_s] == t[it_t]) {
      it_s++;
      if (it_s == sz_s) return it_t;
    }
  }
  return sz_t + 100;
}
int pos_R() {
  int it_s = sz_s - 1;
  for (int it_t = sz_t - 1; it_t >= 0; it_t--) {
    if (s[it_s] == t[it_t]) {
      it_s--;
      if (it_s == -1) return it_t;
    }
  }
  return -100;
}
int main() {
  cin >> s;
  cin >> t;
  sz_s = s.size();
  sz_t = t.size();
  int diff = pos_R() - pos_L();
  if (diff < 0) diff = 0;
  cout << diff;
  return 0;
}
