#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  ios_base::sync_with_stdio(0);
  string s, t;
  cin >> s >> t;
  long long x1 = s.length(), x2 = 0, k = 0;
  for (long long i = 0; i < t.length(); i++) {
    if (s[k] == t[i]) {
      k++;
      if (k == s.length()) {
        x1 = i;
        break;
      }
    }
  }
  k = s.length() - 1;
  for (long long i = t.length(); i >= 0; i--) {
    if (s[k] == t[i]) {
      k--;
      if (k == -1) {
        x2 = i;
        break;
      }
    }
  }
  cout << max(x2 - x1, (long long)0);
}
