#include <bits/stdc++.h>
char s[1000010], t[1000010], a;
using namespace std;
int main() {
  long long l = 6666666, r = 0;
  cin >> s >> t;
  long long j = 0;
  for (int i = 0; i < strlen(t); ++i) {
    if (s[j] == t[i]) ++j;
    if (j == strlen(s)) {
      l = i;
      break;
    }
  }
  j = strlen(s) - 1;
  for (int i = strlen(t) - 1; i >= 0; --i) {
    if (s[j] == t[i]) --j;
    if (j == -1) {
      r = i;
      break;
    }
  }
  cout << max((int)(r - l), 0) << endl;
  cin >> s >> t;
  return 0;
}
