#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
char c[maxn];
char s[1005];
struct node {
  int a, b;
};
int main() {
  scanf("%s%s", s, c);
  int len = strlen(s);
  int j = 0;
  int p = 0;
  for (int i = 0; c[i]; i++) {
    if (c[i] == s[j]) {
      j++;
    }
    if (j == len) {
      p = i;
      break;
    }
  }
  j = len - 1;
  int ln = strlen(c);
  int q = 0;
  for (int i = ln - 1; i >= 0; i--) {
    if (c[i] == s[j]) {
      j--;
    }
    if (j == -1) {
      q = i;
      break;
    }
  }
  printf("%d\n", max(q - p, 0));
  return 0;
}
