#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
  cin >> s >> t;
  int p1 = 0, p2 = t.length() - 1;
  for (int i = 0; i < s.length(); i++) {
    while ((p1 < t.length()) && (t[p1] != s[i])) p1++;
    if (p1 >= t.length()) {
      cout << 0;
      return 0;
    }
    p1++;
  }
  for (int i = s.length() - 1; i >= 0; i--) {
    while (t[p2] != s[i]) p2--;
    p2--;
  }
  if (p2 - p1 + 2 > 0)
    cout << p2 - p1 + 2;
  else
    cout << 0;
  return 0;
}
