#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
const int N = 1000000;
int sum[N];
int osu[N + 10];
int ans = 0;
int main() {
  string s, t;
  cin >> t >> s;
  int k = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (i) sum[i] = sum[i - 1];
    if (t[k] == s[i]) k++;
    if (k == t.size()) {
      sum[i]++;
      k = 0;
    }
  }
  k = t.size() - 1;
  for (int i = s.size() - 1; i >= 0; --i) {
    osu[i] = osu[i + 1];
    if (k < 0) {
      osu[i]++;
      k = t.size() - 1;
    }
    if (t[k] == s[i]) k--;
  }
  for (int i = 0; i < s.size(); ++i) {
    if (sum[i] && osu[i]) ans++;
  }
  cout << ans;
}
