#include <bits/stdc++.h>
using namespace std;
string s, t;
int slen, tlen;
int ans = 0;
int p1 = 0, p2 = 0;
int main() {
  cin >> s >> t;
  slen = s.size();
  tlen = t.size();
  int i, j;
  for (i = 0; i < tlen; i++) {
    if (t[i] == s[p1]) p1++;
    if (p1 == slen) break;
  }
  for (j = tlen - 1; j >= 0; j--) {
    if (t[j] == s[slen - 1 - p2]) p2++;
    if (p2 == slen) break;
  }
  if (j > i) ans = j - i;
  cout << ans << endl;
  return 0;
}
