#include <bits/stdc++.h>
using namespace std;
string t, s;
string reversedt, reverseds;
int ans;
int main() {
  cin >> s;
  cin >> t;
  int pos = 0;
  int F = 0, S = 0;
  for (int i = 0; i < t.size(); ++i) {
    if (s[pos] == t[i]) {
      pos++;
      if (pos == s.size()) {
        F = i;
        break;
      }
    }
  }
  if (pos != s.size()) {
    cout << 0 << endl;
    return 0;
  }
  reversedt = t;
  reverse(reversedt.begin(), reversedt.end());
  reverseds = s;
  reverse(reverseds.begin(), reverseds.end());
  pos = 0;
  for (int i = 0; i < reversedt.size(); ++i) {
    if (reverseds[pos] == reversedt[i]) {
      pos++;
      if (pos == reverseds.size()) {
        S = i;
        break;
      }
    }
  }
  if (pos != s.size()) {
    cout << 0 << endl;
    return 0;
  }
  ans = t.size() - 1 - S;
  if (F >= ans) {
    cout << 0 << endl;
    return 0;
  }
  cout << ans - F << endl;
  return 0;
}
