#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-12;
const int N = 1007, MOD = 1000000007;
int i, j, l, r, ind;
char s[N], t[1000 * N];
int main() {
  gets(s);
  gets(t);
  l = r = -1;
  int slen = strlen(s);
  int tlen = strlen(t);
  for (i = 0; i < tlen; i++)
    if (t[i] == s[ind]) {
      ind++;
      if (ind == slen) {
        l = i;
        break;
      }
    }
  ind = slen - 1;
  for (i = tlen - 1; i >= 0; i--)
    if (t[i] == s[ind]) {
      ind--;
      if (ind == -1) {
        r = i;
        break;
      }
    }
  if (l == -1 || r == -1 || r - l <= 0) return cout << 0, 0;
  cout << r - l;
  return 0;
}
