#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string LuckyWords, SeenWords;
  cin >> LuckyWords >> SeenWords;
  unsigned int IndSeenChar = 0, IndLuckyChar = 0;
  unsigned int LengthSeenWords = SeenWords.length(),
               LengthLuckyWords = LuckyWords.length();
  unsigned int LeftLast = 0, RightFirst = 0;
  while (SeenWords[IndSeenChar]) {
    if (SeenWords[IndSeenChar] == LuckyWords[IndLuckyChar]) {
      IndLuckyChar++;
      if (IndLuckyChar == LengthLuckyWords) {
        LeftLast = IndSeenChar;
        break;
      }
    }
    IndSeenChar++;
  }
  IndSeenChar = LengthSeenWords - 1;
  IndLuckyChar = LengthLuckyWords - 1;
  while (IndSeenChar > LeftLast) {
    if (SeenWords[IndSeenChar] == LuckyWords[IndLuckyChar]) {
      if (IndLuckyChar == 0) {
        RightFirst = IndSeenChar;
        break;
      }
      IndLuckyChar--;
    }
    IndSeenChar--;
  }
  if (LeftLast < RightFirst)
    printf("%u\n", RightFirst - LeftLast);
  else
    printf("0\n");
  return 0;
}
