#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, d;
  cin >> s >> d;
  int c = 0, k = 0, ans = 0, cnt = 0, m = 0, l = 0;
  for (int i = 0; i < d.size(); i++) {
    if (d[i] == s[c]) k++, c++;
    if (k == s.size()) ans++, k = 0, c = 0;
    if (ans == 1) {
      m = i + 1;
      break;
    }
  }
  c = s.size() - 1, k = 0, ans = 0;
  for (int i = d.size() - 1; i >= 0; i--) {
    if (d[i] == s[c]) k++, c--;
    if (k == s.size()) ans++;
    if (ans == 1) {
      l = i + 1;
      break;
    }
  }
  if (l - m < 0) return cout << 0, 0;
  return cout << l - m, 0;
}
