#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t1, t2;
  cin >> t1 >> s;
  t2 = t1;
  reverse(t2.begin(), t2.end());
  int n = s.length(), i, j, k, p, x, y, ans;
  x = -1;
  y = -1;
  p = 0;
  for (i = 0; i < n; i++) {
    if ((p < t1.length()) && (s[i] == t1[p])) {
      p++;
      if (p == t1.length()) {
        x = i;
        break;
      }
    }
  }
  p = 0;
  for (i = n - 1; i >= 0; i--) {
    if ((p < t2.length()) && (s[i] == t2[p])) {
      p++;
      if (p == t2.length()) {
        y = i;
        break;
      }
    }
  }
  if ((x == -1) || (x >= y))
    ans = 0;
  else
    ans = y - x;
  cout << ans << "\n";
  return 0;
}
