#include <bits/stdc++.h>
using namespace std;
long long solve(string s, string t) {
  long long l = 0;
  long long n = t.length(), m = s.length();
  for (long long i = 0; i < n; ++i) {
    if (t[i] == s[l]) {
      ++l;
      if (l == m) return i;
    }
  }
  return -1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  string s, t;
  cin >> s >> t;
  long long ind = solve(s, t);
  reverse(s.begin(), s.end());
  reverse(t.begin(), t.end());
  long long ind1 = solve(s, t);
  long long n = t.length();
  ind1 = n - 1 - ind1;
  if (ind == -1 || ind1 == -1) return cout << "0\n", 0;
  cout << max(0ll, ind1 - ind) << '\n';
}
