#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
  getline(cin, s);
  int lens = s.size();
  s = '*' + s;
  getline(cin, t);
  int lent = t.size();
  t = '*' + t;
  int pos1 = -1, pos2 = -1, tmp;
  tmp = 1;
  for (int i = 1; i <= lent; i++) {
    if (s[tmp] == t[i]) tmp++;
    if (tmp > lens) {
      pos1 = i;
      break;
    }
  }
  tmp = lens;
  for (int i = lent; i >= 1; i--) {
    if (s[tmp] == t[i]) tmp--;
    if (tmp == 0) {
      pos2 = i;
      break;
    }
  }
  if (pos1 == -1 || pos2 == -1 || pos1 > pos2) {
    puts("0");
    return 0;
  }
  printf("%d", pos2 - pos1);
  return 0;
}
