#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
  cin >> s >> t;
  int start = 0, cnt = 0;
  bool found = 0;
  for (int i = 0; i < t.size(); ++i) {
    if (t[i] == s[cnt]) {
      cnt++;
      if (cnt == s.size()) {
        found = 1;
        start = i;
        break;
      }
    }
  }
  if (found) {
    int res = 0;
    cnt = s.size() - 1;
    int endo = 0;
    for (int i = t.size() - 1; i >= 0; --i) {
      if (t[i] == s[cnt]) {
        cnt--;
        if (cnt == -1) {
          endo = i;
          break;
        }
      }
    }
    res = (endo - start) > 0 ? endo - start : 0;
    printf("%d\n", res);
  } else {
    printf("0\n");
  }
  return 0;
}
