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
	/*
	TO LEARN
	1-segment trees
	2-euler tour
	3-fenwick tree and interval tree
	*/
	/*
	TO SOLVE 
	uva 1103
	program codeforces edu 102 D
	*/
	/*
	bit manipulation shit
	1-Computer Systems: A Programmer's Perspective
	2-hacker's delight
	3-(02-03-bits-ints)
	4-machine-basics
	5-Bits Manipulation tutorialspoint
	*/
	/*
	TO WATCH
	1-what is bitmasking by kartik arora youtube

	*/
	            import java.util.*;
			    import java.math.*;
			    import java.io.*; 
			    import java.util.stream.Collectors;

			     public class A{
			     
			  static InputStream inputStream = System.in;
	            static FastScanner scan=new FastScanner();
			   
			     public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
		static long gcd(long a,long b)
		{
			if(a==0)
				return b;
			return gcd(b%a,a);
		}
		static long lcm(long a,long b)
		{
			return (a*b/gcd(a,b));
		}
		static boolean isprime(long x)
		{
			if(x==2)
				return true;
			for(int i=2;i*i<=x;i++)
				if(x%i==0)
					return false;
				return true;
		}
		static int brute(String a,String b)
		{
			 int A=a.length(),B=b.length();
			 int mx=0;
			 for(int i=0;i<A;i++){
			 	for(int j=i;j<A;j++){
		int las=0;
		for(int k=0;k<i&&las<B;k++)
			if(a.charAt(k)==b.charAt(las))las++;

		for(int k=j+1;k<A&&las<B;k++)
			if(a.charAt(k)==b.charAt(las))las++;
		if(las>=B){
			//if(j-i+1==9)
			//	System.out.println((i+1)+" "+(j+1));
			mx=Math.max(mx,j-i+1);
		}
	}
}
return mx;
		}
		public static void main(String[] args)  throws Exception 
	      {
		
			//	scan=new FastScanner("lifeguards.in");
			//out = new PrintWriter("lifeguards.out");
			 
			 /*
			 currently doing 
			 1-digit dp
			 2-ds like fenwick and interval tree and sparse table 
			 */
			 /*
			 READING 
			 1-Everything About Dynamic Programming codeforces
			 2-DYNAMIC PROGRAMMING: FROM NOVICE TO ADVANCED topcoder
			 3-Introduction to DP with Bitmasking codefoces
			 4-Bit Manipulation hackerearth 
			 */



			    int tt=1;
			 
	
						
			     
		  


//tt=scan.nextInt();

/*for(int i=0;i<20;i++)
for(int j=0;j<20;j++)
out.println(i+" "+j+" "+(i|j));*/		    


	int T=1;

			    
		 outer:while(tt-->0)
			    {
			 String a=scan.next(),b=scan.next();
			 if(a.equals(b))
			 {
			 	out.println(0);
			 	out.close();
			 	return;
			 }
			int A=a.length(),B=b.length();
	//out.println(brute(a,b));
	int pre[]=new int[A];
	int suf[]=new int[A];
	//Arrays.fill(pre,-1);
	//Arrays.fill(suf,-1);
	int las=0;
	for(int i=0;i<A;i++)
	{
		if(las<B&&a.charAt(i)==b.charAt(las))
		{
			las++;
		}
		pre[i]=las;
	}
	las=B-1;
	int x=0;
	for(int i=A-1;i>=0;i--)
	{
		if(las>=0&&a.charAt(i)==b.charAt(las))
		{
			las--;
			x++;
		}
		suf[i]=x;
		//out.println(suf[i]+" "+las+" "+i);
	}

	Map<Integer,Integer>map=new HashMap<Integer,Integer>();
	Map<Integer,Integer>map2=new HashMap<Integer,Integer>();
	for(int i=0;i<A;i++)
	{
		if(map.containsKey(pre[i]))
		{
			continue;
		}
		map.put(pre[i],i);
	}
	for(int i=A-1;i>=0;i--)
	{
		if(map2.containsKey(suf[i]))
			continue;
		map2.put(suf[i],i);
	}
	int res=0;
	for(int i=0;i<A;i++)
	{
		 x=pre[i];
		if(!map2.containsKey(B-x))
			continue;
	//	out.println(pre[i]);
		//out.println(i+" "+x+" "+B+" "+map2.get(B-x));
		int y=map2.get(B-x);
			//if(y-map.get(pre[i])==3)
		//	System.out.println(i+" "+x+" "+pre[i]+" "+y+" "+map.get(pre[i]));
		res=Math.max(res,y-map.get(pre[i])-1);
		//out.println(i+" "+x+" "+y+" "+map.get(pre[i])+" "+(B-x));
	}
	/*for(int i=0;i<A;i++)
	{
		 x=suf[i];
		if(!map2.containsKey(B-x))
			continue;
	//	out.println(pre[i]);
		//out.println(i+" "+x+" "+B+" "+map2.get(B-x));
		int y=map2.get(B-x);
			//if(y-map.get(pre[i])==3)
			//System.out.println(i+" "+x+" "+pre[i]+" "+y+" "+map.get(pre[i]));
		res=Math.max(res,y-map.get(pre[i]));
		//out.println(i+" "+x+" "+y+" "+map.get(pre[i])+" "+(B-x));
	}*/
	for(int i=0;i<A;i++)
	{
		if(pre[i]==B)
		{
			//out.println(i);
			res=Math.max(res,A-i-1);
			break;
		}
	}
		for(int i=A-1;i>=0;i--)
	{
		if(suf[i]==B)
		{
			res=Math.max(res,i);
			break;
		}
	}

	out.println(res);




   }

			  	    out.close();
	 		  
			   
			}
			static class special{
				long x1,y1,x2,y2;
				//int id;
				special(long x1,long y1,long x2,long y2)
				{
					this.x1=x1;
					this.y1=y1;
					this.x2=x2;
					this.y2=y2;
					//this.id=id;
				}
				@Override
				    public int hashCode() {
			                int hash = 7;
    hash = 31 * hash + (int) x1;
    hash = 31 * hash + (int)x2;
    hash = 31 * hash + (int)y1;
    hash = 31 * hash + (int)y2;
    return hash;
			            }
			              @Override
			            public boolean equals(Object o){
			                if (o == this) return true;
			                if (o.getClass() != getClass()) return false;
			                special t = (special)o;
			                return t.x1 == x1 && t.y1 == y1&&t.x2==x2&&t.y2==y2;
			            }
			}

			   
			     static long binexp(long a,long n)
			    {
			        if(n==0)
			            return 1;
			        long res=binexp(a,n/2);
			        if(n%2==1)
			            return res*res*a;
			        else 
			            return res*res;
			    }
			     
			    static long powMod(long base, long exp, long mod) {
			           if (base == 0 || base == 1) return base;
			           if (exp == 0) return 1;
			           if (exp == 1) return (base % mod+mod)%mod;
			           long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
			           R *= R;
			           R %= mod;
			           if ((exp & 1) == 1) {
			               return (base * R % mod+mod)%mod;
			           }
			           else return (R %mod+mod)%mod;
			       }
			    static double dis(double x1,double y1,double x2,double y2)
			    {
			        return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
			    }
			    static long mod(long x,long y)
			        {
			            if(x<0)
			                x=x+(-x/y+1)*y;
			            return x%y;
			        }
			     public static  long pow(long b, long e) {
			                long r = 1;
			                while (e > 0) {
			                    if (e % 2 == 1) r = r * b ;
			                    b = b * b;
			                    e >>= 1;
			                }
			                return r;
			            }
			    private static void sort(long[] arr) {
			            List<Long> list = new ArrayList<>();
			            for (long object : arr) list.add(object);
			            Collections.sort(list);
			        //Collections.reverse(list);
			            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
			        }
			    private static void sort2(long[] arr) {
			            List<Long> list = new ArrayList<>();
			            for (Long object : arr) list.add(object);
			            Collections.sort(list);
			        Collections.reverse(list);
			            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
			        }
			     static class FastScanner
	{
	    private int BS = 1 << 16;
	    private char NC = (char) 0;
	    private byte[] buf = new byte[BS];
	    private int bId = 0, size = 0;
	    private char c = NC;
	    private double cnt = 1;
	    private BufferedInputStream in;
	 
	    public FastScanner() {
	        in = new BufferedInputStream(System.in, BS);
	    }
	 
	    public FastScanner(String s) {
	        try {
	            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
	        } catch (Exception e) {
	            in = new BufferedInputStream(System.in, BS);
	        }
	    }
	 
	    private char getChar() {
	        while (bId == size) {
	            try {
	                size = in.read(buf);
	            } catch (Exception e) {
	                return NC;
	            }
	            if (size == -1) return NC;
	            bId = 0;
	        }
	        return (char) buf[bId++];
	    }
	 
	    public int nextInt() {
	        return (int) nextLong();
	    }
	 
	    public int[] nextInts(int N) {
	        int[] res = new int[N];
	        for (int i = 0; i < N; i++) {
	            res[i] = (int) nextLong();
	        }
	        return res;
	    }
	 
	    public long[] nextLongs(int N) {
	        long[] res = new long[N];
	        for (int i = 0; i < N; i++) {
	            res[i] = nextLong();
	        }
	        return res;
	    }
	 
	    public long nextLong() {
	        cnt = 1;
	        boolean neg = false;
	        if (c == NC) c = getChar();
	        for (; (c < '0' || c > '9'); c = getChar()) {
	            if (c == '-') neg = true;
	        }
	        long res = 0;
	        for (; c >= '0' && c <= '9'; c = getChar()) {
	            res = (res << 3) + (res << 1) + c - '0';
	            cnt *= 10;
	        }
	        return neg ? -res : res;
	    }
	 
	    public double nextDouble() {
	        double cur = nextLong();
	        return c != '.' ? cur : cur + nextLong() / cnt;
	    }
	 
	    public double[] nextDoubles(int N) {
	        double[] res = new double[N];
	        for (int i = 0; i < N; i++) {
	            res[i] = nextDouble();
	        }
	        return res;
	    }
	 
	    public String next() {
	        StringBuilder res = new StringBuilder();
	        while (c <= 32) c = getChar();
	        while (c > 32) {
	            res.append(c);
	            c = getChar();
	        }
	        return res.toString();
	    }
	 
	    public String nextLine() {
	        StringBuilder res = new StringBuilder();
	        while (c <= 32) c = getChar();
	        while (c != '\n') {
	            res.append(c);
	            c = getChar();
	        }
	        return res.toString();
	    }
	 
	    public boolean hasNext() {
	        if (c > 32) return true;
	        while (true) {
	            c = getChar();
	            if (c == NC) return false;
	            else if (c > 32) return true;
	        }
	    }
	}

			     static class Pair implements Comparable<Pair>{
			            public long x, y,z;
			            public Pair(long x1, long y1,long z1) {
			                x=x1;
			                y=y1;
			                z=z1;
			            }
			             public Pair(long x1, long y1) {
			                x=x1;
			                y=y1;
			    
			            }
			            
			            @Override
			            public int hashCode() {
			                return (int)(x + 31 * y);
			            }
			            public String toString() {
			                return x + " " + y+" "+z;
			            }
			            @Override
			            public boolean equals(Object o){
			                if (o == this) return true;
			                if (o.getClass() != getClass()) return false;
			                Pair t = (Pair)o;
			                return t.x == x && t.y == y&&t.z==z;
			            }
			    public int compareTo(Pair o)
			    {
			    
			    	return (int)(o.x-x);
			     
			        }
			     
			    }
			    
			    }

			     
