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
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author keyur_jain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD2 solver = new TaskD2();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD2 {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            String s = in.nextString();
            String t = in.nextString();
            int n = s.length(), m = t.length();
            Integer[] prefixMatch = new Integer[n];
            Integer[] suffixMatch = new Integer[n];
            int j = 0;
            for (int i = 0; i < n; i++) {
                if (j < m && s.charAt(i) == t.charAt(j)) {
                    j += 1;
                    prefixMatch[i] = j;
                } else {
                    prefixMatch[i] = (i != 0) ? prefixMatch[i - 1] : 0;
                }
            }
            j = 0;
            for (int i = n - 1; i >= 0; i--) {
                if (j < m && s.charAt(i) == t.charAt(m - j - 1)) {
                    j += 1;
                    suffixMatch[i] = j;
                } else {
                    suffixMatch[i] = (i != n - 1) ? suffixMatch[i + 1] : 0;
                }
            }
            int answer = n - BinarySearch.LowerBound(prefixMatch, m) - 1;
            for (int i = n - 1; i >= 0; i--) {
                int have = suffixMatch[i];
                int need = m - have;
                int idx = BinarySearch.LowerBound(prefixMatch, need);
                if (need == 0) idx = -1;
                answer = Math.max(answer, i - idx - 1);
            }
            out.println(answer);
        }

    }

    static class BinarySearch {
        public static <T extends Comparable<T>> int LowerBound(T[] arr, T x) {
            int lo = 0, hi = arr.length - 1;
            while (lo < hi) {
                int mid = (lo + hi) >> 1;
                if (arr[mid].compareTo(x) < 0) {
                    lo = mid + 1;
                } else {
                    hi = mid;
                }
            }
            return (arr[lo].compareTo(x) < 0) ? arr.length : lo;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}

