#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int n, m;
  n = s.length();
  m = t.length();
  bool fail = false;
  int i, j, k;
  int a, b;
  i = 0;
  j = 0;
  for (; j < m && i < n; j++)
    if (s[i] == t[j]) i++;
  if (i < n) fail = true;
  a = j;
  i = n - 1;
  j = m - 1;
  for (; j >= 0 && i >= 0; j--)
    if (s[i] == t[j]) i--;
  if (i >= 0) fail = true;
  b = j;
  if (fail)
    cout << 0 << endl;
  else {
    int r = b - a + 2;
    if (r < 0) r = 0;
    cout << r << endl;
  }
  return 0;
}
