#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s, a;
  cin >> s >> a;
  int n = a.size(), x = 0, y = s.size(), pos = 0, pos1 = n;
  for (int i = 0; i < n; i++) {
    if (a[i] == s[x]) x++;
    if (x == y) {
      pos = i;
      break;
    }
  }
  if (x == y) {
    x--;
    for (int i = n - 1; i >= pos + 1; i--) {
      if (a[i] == s[x]) x--;
      if (x == -1) {
        pos1 = i;
        break;
      }
    }
  }
  if (pos1 != n)
    cout << pos1 - pos;
  else
    cout << "0";
}
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
