#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string t;
  cin >> t;
  int cnt = 0;
  int kill = 0;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == s[cnt]) cnt++;
    if (cnt == s.size()) {
      kill = i;
      break;
    }
  }
  if (cnt != s.size()) {
    cout << 0 << endl;
    return 0;
  }
  cnt = s.size() - 1;
  int gin;
  for (int i = t.size() - 1; i >= 0; i--) {
    if (i < kill) {
      cout << 0 << endl;
      return 0;
    }
    if (s[cnt] == t[i]) cnt--;
    if (cnt == -1) {
      gin = i;
      break;
    }
  }
  cout << gin - kill << endl;
  return 0;
}
