#include <bits/stdc++.h>
using namespace std;
char a[1010], b[1000010];
int main() {
  while (~scanf("%s%s", a, b)) {
    int la = strlen(a), lb = strlen(b);
    int l = -1, r = -1;
    for (int i = 0, j = 0; b[i];) {
      if (b[i] == a[j]) {
        while (b[i] == a[j] && i < lb && j < la) i++, j++;
        if (j == la) {
          l = i - 1;
          break;
        }
      } else {
        i++;
      }
    }
    for (int i = lb - 1, j = la - 1; i >= 0;) {
      if (b[i] == a[j]) {
        while (b[i] == a[j] && i >= 0 && j >= 0) i--, j--;
        if (j == -1) {
          r = i + 1;
          break;
        }
      } else {
        i--;
      }
    }
    if (l == -1 || r == -1)
      puts("0");
    else
      printf("%d\n", max(0, r - l));
  }
  return 0;
}
