#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  string s;
  cin >> n >> s;
  int ln = n.length();
  int ls = s.length();
  int i1 = 0;
  int idx = 0;
  for (; i1 < ls; i1++) {
    if (s[i1] == n[idx]) idx++;
    if (idx == ln) break;
  }
  if (idx != ln) {
    cout << "0\n";
    return 0;
  }
  idx = ln - 1;
  int i2 = ls - 1;
  for (; i2 >= 0; i2--) {
    if (s[i2] == n[idx]) idx--;
    if (idx == -1) break;
  }
  if (idx != -1 || i2 < i1) {
    cout << "0\n";
    return 0;
  }
  cout << i2 - i1 << "\n";
  return 0;
}
