#include <bits/stdc++.h>
using namespace std;
string s, t;
int getp() {
  int p0 = 0;
  for (int i = 0; i < s.size(); i++) {
    while (p0 < t.size() && s[i] != t[p0]) p0++;
    if (p0 == t.size()) {
      return -1;
    }
    p0++;
  }
  return p0 - 1;
}
int main() {
  cin >> s >> t;
  int p0 = getp();
  if (p0 == -1) {
    cout << 0;
    return 0;
  }
  reverse(s.begin(), s.end());
  reverse(t.begin(), t.end());
  int p1 = t.size() - getp();
  cout << max(0, p1 - p0 - 1);
  return 0;
}
