#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[1001], t[1000001];
  cin >> s >> t;
  long long sLen = strlen(s), tLen = strlen(t);
  long long i = 0, j = 0, cntName = 0, l = 0, r = 0, ans = 0;
  bool found = false;
  while (i < tLen && !found) {
    if (t[i] == s[j]) j++;
    if (j == sLen) {
      found = true;
      l = i;
    }
    i++;
  }
  i = tLen - 1;
  j = sLen - 1;
  found = false;
  while (i > l && !found) {
    if (t[i] == s[j]) j--;
    if (j == -1) {
      found = true;
      r = i;
    }
    i--;
  }
  if (found)
    cout << r - l;
  else
    cout << 0;
  return 0;
}
