#include <bits/stdc++.h>
using namespace std;
long long front[1000005] = {0};
long long back[1000005] = {0};
int main() {
  string s, t;
  cin >> s >> t;
  long long ptr = 0;
  for (long long i = 0; i <= t.size() - 1; i++) {
    front[i] = front[max(0LL, i - 1)];
    if (s[ptr] == t[i]) ptr++;
    if (ptr == s.size()) {
      front[i]++;
      ptr = 0;
    }
  }
  ptr = s.size() - 1;
  for (long long i = t.size() - 1; i >= 0; i--) {
    back[i] = back[i + 1];
    if (s[ptr] == t[i]) ptr--;
    if (ptr == -1) {
      ptr += s.size();
      back[i]++;
    }
  }
  long long ans = 0;
  for (long long i = 0; i <= t.size() - 1; i++) {
    if (front[i] > 0 && back[i + 1] > 0) ans++;
  }
  cout << ans;
}
