#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string t;
  cin >> t;
  int j = 0;
  if (s.length() > t.length() / 2) {
    cout << 0;
    return 0;
  }
  int l = -1, r = -1;
  for (int i = 0; i < t.length(); i++) {
    if (t[i] == s[j]) {
      j++;
      if (j == s.length()) {
        l = i;
        break;
      }
    }
  }
  reverse(s.begin(), s.end());
  j = 0;
  for (int i = t.length() - 1; i >= 0; i--) {
    if (t[i] == s[j]) {
      j++;
      if (j == s.length()) {
        r = i;
        break;
      }
    }
  }
  cout << max(0, r - l);
  return 0;
}
