#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
int n, m;
char s[maxn];
char t[maxn];
int main() {
  cin >> (s + 1);
  n = strlen(s + 1);
  cin >> (t + 1);
  m = strlen(t + 1);
  int l = -1;
  int j = 1;
  for (int i = 1; i <= m; i++) {
    if (t[i] == s[j]) {
      j++;
      if (j == n + 1) {
        l = i;
        break;
      }
    }
  }
  int r = -1;
  j = n;
  for (int i = m; i >= 1; i--) {
    if (t[i] == s[j]) {
      j--;
      if (j == 0) {
        r = i;
        break;
      }
    }
  }
  if (l == -1 || r == -1 || l > r) {
    cout << 0 << "\n";
  } else {
    cout << r - l << "\n";
  }
  return 0;
}
