The only difference between easy and hard versions is the length of the string.

You are given a string s and a string t, both consisting only of lowercase Latin letters. It is guaranteed that t can be obtained from s by removing some (possibly, zero) number of characters (not necessary contiguous) from s without changing order of remaining characters (in other words, it is guaranteed that t is a subsequence of s).

For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test".

You want to remove some substring (contiguous subsequence) from s of maximum possible length such that after removing this substring t will remain a subsequence of s.

If you want to remove the substring s[l;r] then the string s will be transformed to s_1 s_2 ... s_{l-1} s_{r+1} s_{r+2} ... s_{|s|-1} s_{|s|} (where |s| is the length of s).

Your task is to find the maximum possible length of the substring you can remove so that t is still a subsequence of s.

Input

The first line of the input contains one string s consisting of at least 1 and at most 2 ⋅ 10^5 lowercase Latin letters.

The second line of the input contains one string t consisting of at least 1 and at most 2 ⋅ 10^5 lowercase Latin letters.

It is guaranteed that t is a subsequence of s.

Output

Print one integer — the maximum possible length of the substring you can remove so that t is still a subsequence of s.

Examples

Input


bbaba
bb


Output


3


Input


baaba
ab


Output


2


Input


abcde
abcde


Output


0


Input


asdfasdf
fasd


Output


3
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
vector<long long> is_prime(N + 1, true);
long long to_int(string s) {
  stringstream geek(s);
  long long x = 0;
  geek >> x;
  return x;
}
string to_string(long long n) {
  ostringstream str1;
  str1 << n;
  string geek = str1.str();
  return geek;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second > b.second;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long powerm(long long a, long long k) {
  if (!k) {
    return 1;
  }
  long long b = powerm(a, k / 2);
  b = b * b % (1000000000 + 7);
  if (k % 2) {
    return a * b % (1000000000 + 7);
  } else {
    return b;
  }
}
long long power(long long a, long long b) {
  if (b == 1) return a;
  if (b == 0) return 1;
  long long m1 = power(a, b / 2);
  if (b % 2) return m1 * m1 * a;
  return m1 * m1;
}
void seive_of_eras(long long n) {
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (long long i = 2; i * i <= n; i++) {
    if (is_prime[i]) {
      for (long long j = i * i; j <= n; j += i) {
        is_prime[j] = false;
      }
    }
  }
}
bool isprime(long long a) {
  if (a <= 1) return false;
  if (a == 2 | a == 3) return true;
  if (a % 2 == 0 || a % 3 == 0) return false;
  for (long long i = 5; i * i <= a; i = i + 6) {
    if (a % i == 0 || a % (i + 2) == 0) return false;
  }
  return true;
}
string s, t;
long long pre[N];
long long suf[N];
long long check(long long m) {
  for (long long i = 0; i < s.size() - m + 1; i++) {
    long long d = 0;
    if (i) {
      d = pre[i - 1] + suf[i + m];
    } else
      d = 0 + suf[i + m];
    if (d >= t.size()) return 1;
  }
  return 0;
}
void codeit() {
  cin >> s >> t;
  long long c = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (c < t.size() && s[i] == t[c]) c++;
    pre[i] = c;
  }
  c = t.size() - 1;
  for (long long i = s.size() - 1; i >= 0; i--) {
    if (c >= 0 && s[i] == t[c]) c--;
    suf[i] = t.size() - c - 1;
  }
  long long l = 0;
  long long r = s.size();
  while (r - l > 1) {
    long long m = l + (r - l) / 2;
    if (check(m))
      l = m;
    else
      r = m;
  }
  cout << l << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long tt;
  tt = 1;
  for (long long i = 0; i < tt; i++) {
    codeit();
  }
}
