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;
template <typename T>
using vec = std::vector<T>;
template <typename K, typename V>
using umap = std::unordered_map<K, V>;
template <typename T, typename H = std::hash<T>>
using uset = std::unordered_set<T>;
using str = string;
using pi = pair<int, int>;
const long long MILLER_RABIN = 3215031751;
const long double PI = acos(-1);
namespace std {
template <>
struct hash<pair<int, int>> {
  size_t operator()(const pair<int, int>& x) const {
    return (x.first * 71ull + x.second) % ((int)1e9 + 7);
  }
};
template <>
struct hash<vector<int>> {
  size_t operator()(const vector<int>& v) const {
    size_t hsh = 0;
    for (int i = 0; i < v.size(); ++i) {
      hsh = (hsh * 71ull + v[i]) % (int)(1e9 + 7);
    }
    return hsh;
  }
};
}  // namespace std
template <typename T>
inline T& RD(T& x) {
  char c;
  while (!isdigit(c = getchar()))
    ;
  x = c - '0';
  while (isdigit(c = getchar())) x = x * 10 + c - '0';
  return x;
}
template <typename T>
inline void PRT(T x) {
  if (!x) {
    putchar('0');
  } else {
    long long d = 1000000000 * 1ll * 1000000000;
    while (!(x / d)) {
      d /= 10;
    }
    while (x) {
      int r = x / d;
      putchar(r + '0');
      if (r) {
        x -= r * d;
        if (!x) {
          while (d > 1) {
            putchar('0');
            d /= 10;
          }
        }
      }
      d /= 10;
    }
  }
  putchar('\n');
}
template <class T>
void trace(T collection) {
  for (auto it = std::begin(collection); it != std::end(collection); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}
template <class T, size_t N>
void trace(T (&collection)[N]) {
  for (auto it = std::begin(collection); it != std::end(collection); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}
template <typename _Type>
void print(_Type arg) {
  cout << arg << endl;
}
template <typename _Type, typename... _Args>
void print(_Type first_arg, _Args&&... args) {
  cout << first_arg << " ";
  print(std::forward<_Args>(args)...);
}
template <typename _Type>
void scan(_Type& arg) {
  cin >> arg;
}
template <typename _Type, typename... _Args>
void scan(_Type& first_arg, _Args&&... args) {
  cin >> first_arg;
  scan(std::forward<_Args>(args)...);
}
template <typename Out>
void split(const std::string& s, char delim, Out result) {
  std::stringstream ss(s);
  std::string item;
  while (std::getline(ss, item, delim)) {
    *(result++) = item;
  }
}
std::vector<std::string> split(const std::string& s, char delim) {
  std::vector<std::string> elems;
  split(s, delim, std::back_inserter(elems));
  return elems;
}
class Solution {
 public:
  string s, t;
  vec<int> mpref;
  void Solve(int test) {
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    mpref.resize(n);
    int ptr = m - 1;
    unordered_map<int, int> mem;
    if (s[n - 1] == t[m - 1]) {
      mpref[n - 1] = 1;
      ptr--;
      mem[1] = n - 1;
    } else {
      mpref[n - 1] = 0;
    }
    for (int i = n - 2; i >= 0; --i) {
      mpref[i] = mpref[i + 1];
      if (ptr >= 0 && s[i] == t[ptr]) {
        mpref[i]++;
        ptr--;
        mem[mpref[i]] = i;
      }
    }
    ptr = 0;
    int cur = 0;
    int ans = 0;
    if (mem.count(m)) {
      ans = mem[m];
    }
    for (int i = 0; i < (int)(n); ++i) {
      if (s[i] == t[ptr]) {
        cur++;
        ptr++;
        int rest = m - cur;
        if (mem.count(rest)) {
          ans = max(ans, mem[rest] - i - 1);
        }
        if (cur == m) {
          ans = max(ans, n - i - 1);
        }
      }
    }
    cout << ans << endl;
  }
  void Precalc() {}

 private:
  void Read() {}
};
int main() {
  int tests = 1;
  for (int test = 1; test <= tests; ++test) {
    Solution solution;
    solution.Precalc();
    solution.Solve(test);
  }
  return 0;
}
