#include <bits/stdc++.h>
using namespace std;
string text, pattern;
bool fromRight[1000007];
bool fromLeft[1000007];
int main() {
  cin >> pattern >> text;
  int n = text.size();
  int m = pattern.size();
  memset(fromLeft, false, sizeof fromLeft);
  memset(fromRight, false, sizeof fromRight);
  int ptr(0);
  for (int i = 0; i < text.size(); i++) {
    if (ptr == m) {
      fromLeft[i] = true;
      continue;
    }
    if (text[i] == pattern[ptr]) {
      ptr++;
    }
    if (ptr == m) {
      fromLeft[i] = true;
    }
  }
  ptr = 0;
  for (int i = text.size(); i >= 0; i--) {
    if (ptr == m) {
      fromRight[i] = true;
      continue;
    }
    if (text[i] == pattern[pattern.size() - 1 - ptr]) {
      ptr++;
    }
    if (ptr == m) {
      fromRight[i] = true;
    }
  }
  int ans(0);
  for (int i = 0; i < text.size() - 1; i++) {
    if (fromLeft[i] == true && fromRight[i + 1] == true) ans++;
  }
  cout << ans << endl;
  return 0;
}
