#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int INF = (int)1e9;
const long long INFLL = (long long)1e18;
const double PI = acos(-1.0);
void atob(int &a, int &b) {
  a ^= b;
  b ^= a;
  a ^= b;
}
const int N = (int)1e5 * 2 + 5;
string s, t;
int Solve() {
  cin >> s >> t;
  int n = s.size(), m = t.size();
  int ID = 0, left = -1, right = -1;
  for (int i = 0; i < m; i++) {
    if (t[i] == s[ID]) {
      ID++;
    }
    if (ID >= n) {
      left = i;
      break;
    }
  }
  ID = n - 1;
  for (int i = m - 1; i > left; i--) {
    if (t[i] == s[ID]) {
      ID--;
    }
    if (ID < 0) {
      right = i;
      break;
    }
  }
  cout << (right != -1 ? right - left : 0);
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cout.setf(ios::fixed | ios::showpoint);
  cout.precision(8);
  return Solve();
}
