#include <bits/stdc++.h>
using namespace std;
char s[1001], t[1000001];
int main() {
  int len1, len2, k = 0, m, n;
  gets(s);
  gets(t);
  len1 = strlen(s), len2 = strlen(t);
  for (int i = 0; i < len2; i++) {
    if (s[k] == t[i]) k++;
    if (k == len1) {
      m = i;
      break;
    }
  }
  for (int i = len2 - 1; i >= 0; i--) {
    if (s[k - 1] == t[i]) k--;
    if (k == 0) {
      n = i;
      break;
    }
  }
  if (n - m < 0)
    cout << "0" << endl;
  else
    cout << n - m << endl;
  return 0;
}
