#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
char a[2000000], b[2000000];
int main() {
  int i, j, k;
  scanf("%s%s", a, b);
  n = strlen(a), m = strlen(b);
  int now = 0;
  for (i = 0; i < m; i++) {
    if (b[i] == a[now]) {
      now++;
      if (now == n) break;
    }
  }
  int c1, c2;
  c1 = i;
  now = n - 1;
  for (i = m - 1; i >= 0; i--) {
    if (b[i] == a[now]) {
      now--;
      if (now == -1) break;
    }
  }
  c2 = i;
  printf("%d", max(0, c2 - c1));
  return 0;
}
