#include <bits/stdc++.h>
using namespace std;
int maxn, minn;
void searches(string s1, string s2) {
  int sub = 0;
  for (int i = 0; i < s2.size(); i++) {
    if (s2[i] == s1[sub]) {
      sub++;
      if (sub >= s1.size()) {
        minn = min(minn, i);
        break;
      }
    }
  }
  sub = s1.size() - 1;
  for (int i = s2.size() - 1; i >= 0; i--) {
    if (s2[i] == s1[sub]) {
      sub--;
      if (sub < 0) {
        maxn = max(maxn, i);
        break;
      }
    }
  }
}
int main() {
  string s1, s2;
  while (cin >> s1) {
    cin >> s2;
    maxn = 0, minn = s2.size();
    searches(s1, s2);
    if (maxn <= minn)
      cout << 0 << endl;
    else
      cout << maxn - minn << endl;
  }
}
