#include <bits/stdc++.h>
int main() {
  std::string name;
  std::string str;
  std::cin >> name >> str;
  unsigned int position = 0;
  int position_start = -1;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == name[position]) position++;
    if (position == name.length()) {
      position_start = i;
      break;
    }
  }
  position = name.length() - 1;
  int position_end = -1;
  for (int i = str.length(); i >= 0; i--) {
    if (str[i] == name[position]) position--;
    if (position == -1) {
      position_end = i;
      break;
    }
  }
  if (position_start == -1 || position_end == -1 ||
      position_end <= position_start)
    std::cout << 0;
  else
    std::cout << position_end - position_start;
  return 0;
}
