#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int firstIdx = -1, secondIdx = -1;
  int j = 0;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == s[j]) ++j;
    if (j == s.size()) {
      firstIdx = i;
      break;
    }
  }
  reverse(t.begin(), t.end());
  reverse(s.begin(), s.end());
  j = 0;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == s[j]) ++j;
    if (j == s.size()) {
      secondIdx = t.size() - i - 1;
      break;
    }
  }
  if (secondIdx < firstIdx || firstIdx == -1)
    cout << 0;
  else
    cout << secondIdx - firstIdx;
}
