#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
  string s, t;
  int ans = 0;
  cin >> s >> t;
  int j = 0, l;
  for (int i = 0; i < s.size(); ++i) {
    while (j < t.size() && t[j] != s[i]) ++j;
    if (t[j] != s[i]) {
      ans = -1;
      break;
    }
    ++j;
  }
  l = t.size() - 1;
  for (int i = s.size() - 1; i >= 0; --i) {
    while (l >= 0 && t[l] != s[i]) --l;
    if (t[l] != s[i]) {
      ans = -1;
      break;
    }
    --l;
  }
  if (ans == -1) {
    cout << 0 << endl;
  } else {
    cout << max(l - j + 2, 0) << endl;
  }
  return 0;
}
