#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int last = 0;
  int fnd = -1;
  for (int i = 0; i < t.length(); i++) {
    if (s[last] == t[i]) {
      last++;
      if (last == s.length()) {
        fnd = i;
        break;
      }
    }
  }
  int first = s.length();
  int ffnd = -1;
  for (int i = t.length() - 1; i >= 0; i--) {
    if (s[first - 1] == t[i]) {
      first--;
      if (first == 0) {
        ffnd = i;
        break;
      }
    }
  }
  if (fnd == -1)
    cout << "0" << endl;
  else if (ffnd <= fnd)
    cout << "0" << endl;
  else
    cout << ffnd - fnd;
  return 0;
}
