#include <bits/stdc++.h>
int findIndex(const std::string& s, const std::string& t) {
  for (size_t i = 0, j = 0; i < t.length(); ++i) {
    if (t[i] == s[j]) {
      if (j == s.length() - 1) {
        return i;
      }
      ++j;
    }
  }
  return -1;
}
int main() {
  std::string s, t;
  std::cin >> s >> t;
  int minEnd = findIndex(s, t);
  if (minEnd == -1) {
    std::cout << 0 << std::endl;
    return 0;
  }
  std::reverse(s.begin(), s.end());
  std::reverse(t.begin(), t.end());
  int maxBegin = t.length() - findIndex(s, t) - 1;
  if (minEnd >= maxBegin) {
    std::cout << 0 << std::endl;
    return 0;
  }
  std::cout << maxBegin - minEnd << std::endl;
  return 0;
}
