#include <bits/stdc++.h>
using namespace std;
char a[1010];
char t[1000010];
int F1(int aLen, int tLen) {
  int curA = 0;
  int curT = 0;
  while (curA < aLen && curT < tLen) {
    if (a[curA] == t[curT]) {
      curA++;
      curT++;
      continue;
    }
    curT++;
  }
  if (curA == aLen) return curT - 1;
  return -1;
}
int F2(int aLen, int tLen) {
  int curA = aLen;
  int curT = tLen;
  while (curA >= 0 && curT >= 0) {
    if (a[curA] == t[curT]) {
      curA--;
      curT--;
      continue;
    }
    curT--;
  }
  if (curA == -1) return curT + 1;
  return -1;
}
int main() {
  cin >> a;
  cin >> t;
  int aLen = strlen(a);
  int tLen = strlen(t);
  int l = F1(aLen, tLen);
  int r = F2(aLen, tLen);
  if (l == -1 || r == -1) {
    printf("0");
    return 0;
  }
  printf("%d", max(0, r - l));
  return 0;
}
