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 long long md = 1e9 + 7;
const long long MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
long long power_md(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2) res = (res % md * a % md) % md;
    a = (a % md * a % md) % md;
    n /= 2;
  }
  res %= md;
  return res;
}
long long power(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2) res *= a;
    a = a * a;
    n /= 2;
  }
  return res;
}
long long abst(long long a) { return ((a < 0) ? (-1 * a) : (a)); }
class cmp_set {
 public:
  bool operator()(long long a, long long b) { return a > b; }
};
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) long long idx,
               __attribute__((unused)) long long LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, long long idx, long long LINE_NUM, Head H,
               Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
long long fun(long long x, string s, long long pref[], long long suf[],
              string t) {
  for (long long i = 0; i <= (s.size() - x); i++) {
    long long l = i;
    long long r = i + x - 1;
    long long pf = 0, sf = 0;
    if (l > 0) pf = pref[l - 1];
    if (r < s.size() - 1) sf = suf[r + 1];
    if ((pf + sf) >= t.size()) return 1;
  }
  return 0;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  string s, t;
  cin >> s >> t;
  long long pref[(long long)s.size()], suf[(long long)s.size()];
  long long j = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (j == t.size())
      pref[i] = t.size();
    else {
      if (s[i] == t[j]) {
        if (i == 0)
          pref[i] = 1;
        else
          pref[i] = pref[i - 1] + 1;
        j++;
      } else {
        if (i == 0)
          pref[i] = 0;
        else
          pref[i] = pref[i - 1];
      }
    }
  }
  j = t.size() - 1;
  for (long long i = s.size() - 1; i >= 0; i--) {
    if (j < 0)
      suf[i] = t.size();
    else {
      if (s[i] == t[j]) {
        if (i == s.size() - 1)
          suf[i] = 1;
        else
          suf[i] = suf[i + 1] + 1;
        j--;
      } else {
        if (i == s.size() - 1)
          suf[i] = 0;
        else
          suf[i] = suf[i + 1];
      }
    }
  }
  long long lo = 0, hi = s.size(), mid;
  while (lo < hi) {
    mid = lo + (hi - lo + 1) / 2;
    if (fun(mid, s, pref, suf, t))
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << lo << "\n";
  return 0;
}
