#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  string sr = s;
  string tr = t;
  reverse(sr.begin(), sr.end());
  reverse(tr.begin(), tr.end());
  int k1 = -1, k2 = -1;
  {
    int h = 0;
    for (int i = 0; i < (int)t.length(); i++) {
      if (s[h] == t[i]) {
        ++h;
      }
      if (h == (int)s.length()) {
        k1 = i;
        break;
      }
    }
  }
  {
    int h = 0;
    for (int i = 0; i < (int)tr.length(); i++) {
      if (sr[h] == tr[i]) {
        ++h;
      }
      if (h == (int)sr.length()) {
        k2 = i;
        break;
      }
    }
    k2 = (int)tr.length() - k2 - 1;
  }
  if (k1 == -1 || k2 == -1 || k1 > k2) {
    cout << 0 << endl;
  } else {
    cout << k2 - k1 << endl;
  }
}
