#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt = 0, nr = 0, dist = 0;
  string s, bao;
  cin >> s >> bao;
  int j = 0;
  while (cnt < 1 && j != bao.length()) {
    if (bao[j] == s[nr]) {
      nr++;
      if (nr == s.length()) {
        nr = 0;
        cnt++;
      }
    }
    j++;
  }
  if (cnt < 1) {
    cout << 0;
    return 0;
  }
  int z = bao.length() - 1;
  nr = s.length() - 1;
  while (cnt < 2 && z != -1) {
    if (bao[z] == s[nr]) {
      nr--;
      if (nr == -1) {
        nr = s.length() - 1;
        cnt++;
      }
    }
    z--;
  }
  if (z + 1 < j) {
    cout << 0;
    return 0;
  }
  cout << z - j + 2;
  return 0;
}
