#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  long long int poz1, poz2;
  poz1 = poz2 = 0;
  long long int j = 0;
  cin >> s >> t;
  for (long long int i = 0; i < (long long)t.length(); i++) {
    if (s[j] == t[i]) {
      j++;
    }
    if (j == (long long)s.length()) {
      poz1 = i;
      break;
    }
  }
  j = s.length() - 1;
  for (long long int i = (long long)t.length() - 1; i > 0; i--) {
    if (s[j] == t[i]) {
      j--;
    }
    if (j == -1) {
      poz2 = i;
      break;
    }
  }
  cout << ((poz2 - poz1) < 0 ? 0 : (poz2 - poz1));
  return 0;
}
