#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s >> t;
  int i = 0, j = 0, cnt = 0, l, r;
  while (i < s.length() && j < t.length()) {
    if (s[i] == t[j])
      i++, j++, cnt++;
    else
      j++;
    if (cnt == s.length()) break;
  }
  l = j - 1;
  i = s.length() - 1;
  j = t.length() - 1;
  cnt = 0;
  while (i >= 0 && j >= 0) {
    if (s[i] == t[j])
      i--, j--, cnt++;
    else
      j--;
    if (cnt == s.length()) break;
  }
  r = j + 1;
  cout << (r > l ? r - l : 0);
  return 0;
}
