#include <bits/stdc++.h>
int main() {
  std::string s, t;
  std::cin >> s >> t;
  int l = 0, spos = 0;
  for (; l < t.size(); ++l)
    if (t[l] == s[spos] && ++spos == s.size()) break;
  if (spos != s.size()) l = t.size();
  int r = t.size() - 1;
  spos = s.size() - 1;
  for (; r >= 0; --r)
    if (t[r] == s[spos] && !spos--) break;
  if (spos >= 0) r = -1;
  if (r < l)
    std::cout << "0\n";
  else
    std::cout << r - l << '\n';
}
