#include <bits/stdc++.h>
using namespace std;
const int N = 100;
vector<int> e[N];
int vis[N];
void dfs(int i, int p, int count) {}
bool comp(pair<long long, long long>& a, pair<long long, long long>& b) {
  return a.first > b.first && a.second < b.second;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q = 1;
  while (q--) {
    string s, t;
    cin >> s >> t;
    if (s.size() > t.size()) {
      cout << 0 << endl;
      return 0;
    }
    int j = 0, l = -1, r = t.size();
    for (int i = 0; i < t.size(); i++) {
      if (s[j] == t[i]) {
        j++;
        if (j == s.size()) {
          l = i;
          break;
        }
      }
    }
    j--;
    for (int i = t.size() - 1; i >= 0; i--) {
      if (t[i] == s[j]) {
        j--;
        if (j == -1) {
          r = i;
          break;
        }
      }
    }
    if (r > l && r != t.size() && r != -1 && l != -1)
      cout << r - l << endl;
    else
      cout << 0 << endl;
  }
}
