#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int a;
  int c = 0;
  for (a = 0; a < t.length(); a++) {
    if (t[a] == s[c]) c++;
    if (c == s.length()) break;
  }
  int b;
  c = s.length();
  for (b = t.length() - 1; b >= 0; b--) {
    if (t[b] == s[c - 1]) c--;
    if (c == 0) break;
  }
  int answ;
  if (b <= a)
    answ = 0;
  else
    answ = b - a;
  cout << answ;
  return 0;
}
