#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
string s, q;
int main() {
  cin >> s >> q;
  for (int i = 0; i < q.size(); i++) {
    if (q[i] == s[a]) a++;
    if (a == s.size()) a = 0, b++;
  }
  if (b < 2)
    cout << 0 << endl;
  else {
    a = 0;
    for (int i = 0; i < q.size(); i++) {
      if (q[i] == s[a]) a++;
      if (a == s.size()) {
        c = i;
        break;
      }
    }
    a = 0;
    for (int i = q.size() - 1; i >= 0; i--) {
      if (q[i] == s[s.size() - 1 - a]) a++;
      if (a == s.size()) {
        d = i;
        break;
      }
    }
    cout << d - c << endl;
  }
  return 0;
}
