//package com.company;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
    public static void main(String[] args) throws IOException {
        // write your code here
        FastReader scanner = new FastReader(System.in);
        int number = Integer.parseInt(scanner.next());

        for(int i = 0; i<number; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int count = 0;
            while (a >=2 && b>=1 || a>=1 && b>=2) {
                while (a > b && a >= 2 && b >= 1) {
                    a -= 2;
                    b -= 1;
                    count++;
                }
                while (b >= a && b >= 2 && a >= 1) {
                    b -= 2;
                    a -= 1;
                    count++;
                }
            }
            out.println(count);

        }
        out.flush();
        out.close();
    }
}


//package com.company;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }

    public static void main(String[] args) throws IOException {
        // write your code here
        FastReader scanner = new FastReader(System.in);
        int number = Integer.parseInt(scanner.next());

        for(int i = 0; i<number; i++) {
            double a = scanner.nextInt();
            double b = scanner.nextInt();
            double count = 0;
            double total = 0;
            if(a>b && b>=1){
                total = a-b;
                if(b-total < 0){
                    total = b;
                }else{
                    count = (b-total)/3;
                    if(Math.round(count)!=(int)count){
                        count*=2+1;
                    }else{
                        count*=2;
                    }
                    total += Math.floor(count);
                }

            }else if(b>a && a>=1){
                total = b-a;
                if(a-total < 0){
                    total = a;
                }else {
                    count = (a-total)/3;
                    if(Math.round(count)!=(int)count){
                        count=(long)count*2+1;
                    }else{
                        count=(long)count*2;
                    }
                    total += Math.floor(count);
                }
            }else if(a==b && a>=2){
                count = a/3;
                if(Math.round(count)!=(int)count){
                    count = (long)count+1;
                }else{
                    count= (long)count*2;
                }
                total += Math.floor(count);
            }else{
                total = 0;
            }
            out.println((int)total);

        }
        out.flush();
        out.close();
    }
}


//package com.company;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }

    public static void main(String[] args) throws IOException {
        // write your code here
        FastReader scanner = new FastReader(System.in);
        int number = Integer.parseInt(scanner.next());

        for(int i = 0; i<number; i++) {
            double a = scanner.nextInt();
            double b = scanner.nextInt();
            double count = 0;
            double total = 0;
            if(a>b && b>=1){
                total = a-b;
                if(total < 0){
                    total = b;
                }else{
                    count = (b-total)/3;
                    if(Math.round(count)!=(int)count){
                        count*=2+1;
                    }else{
                        count*=2;
                    }
                    total += Math.floor(count);
                }

            }else if(b>a && a>=1){
                total = b-a;
                if(total < 0){
                    total = a;
                }else {
                    count = (a-total)/3;
                    if(Math.round(count)!=(int)count){
                        count*=2+1;
                    }else{
                        count*=2;
                    }
                    total += Math.floor(count);
                }
            }else if(a==b && a>=2){
                count = a/3;
                if(Math.round(count)!=(int)count){
                    count*=2+1;
                }else{
                    count*=2;
                }
                total += Math.floor(count);
            }else{
                total = 0;
            }
            out.println((int)total);

        }
        out.flush();
        out.close();
    }
}


//package com.company;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }

    public static void main(String[] args) throws IOException {
        // write your code here
        FastReader scanner = new FastReader(System.in);
        int number = Integer.parseInt(scanner.next());

        for(int i = 0; i<number; i++) {
            double a = scanner.nextInt();
            double b = scanner.nextInt();
            double count = 0;
            double total = 0;
            if(a>b && b>=1){
                total = a-b;
                if(total < 0){
                    total = b;
                }else{
                    count = (b-total)/3;
                    if(Math.round(count)!=(int)count){
                        count*=2+1;
                    }else{
                        count*=2;
                    }
                    total += Math.floor(count);
                }

            }else if(b>a && a>=1){
                total = b-a;
                if(total < 0){
                    total = a;
                }else {
                    count = (a-total)/3;
                    if(Math.round(count)!=(int)count){
                        count=(long)count*2+1;
                    }else{
                        count=(long)count*2;
                    }
                    total += Math.floor(count);
                }
            }else if(a==b && a>=2){
                count = a/3;
                if(Math.round(count)!=(int)count){
                    count*=2+1;
                }else{
                    count*=2;
                }
                total += Math.floor(count);
            }else{
                total = 0;
            }
            out.println((int)total);

        }
        out.flush();
        out.close();
    }
}


//package com.company;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }

    public static void main(String[] args) throws IOException {
        // write your code here
        FastReader scanner = new FastReader(System.in);
        int number = Integer.parseInt(scanner.next());

        for(int i = 0; i<number; i++) {
            double a = scanner.nextInt();
            double b = scanner.nextInt();
            double count = 0;
            double total = 0;
            if(a>b && b>=1){
                total = a-b;
                if(b-total < 0){
                    total = b;
                }else{
                    count = (b-total)/3;
                    if(Math.round(count)!=(int)count){
                        count=(long)count*2+1;
                    }else{
                        count=(long)count*2;
                    }
                    total += Math.floor(count);
                }

            }else if(b>a && a>=1){
                total = b-a;
                if(a-total < 0){
                    total = a;
                }else {
                    count = (a-total)/3;
                    if(Math.round(count)!=(int)count){
                        count=(long)count*2+1;
                    }else{
                        count=(long)count*2;
                    }
                    total += Math.floor(count);
                }
            }else if(a==b && a>=2){
                count = a/3;
                if(Math.round(count)!=(int)count){
                    count = (long)count*2+1;
                }else{
                    count= (long)count*2;
                }
                total += Math.floor(count);
            }else{
                total = 0;
            }
            out.println((int)total);

        }
        out.flush();
        out.close();
    }
}


//package com.company;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }

    public static void main(String[] args) throws IOException {
        // write your code here
        FastReader scanner = new FastReader(System.in);
        int number = Integer.parseInt(scanner.next());

        for(int i = 0; i<number; i++) {
            double a = scanner.nextInt();
            double b = scanner.nextInt();
            double count = 0;
            double total = 0;
            if(a>b && b>=1){
                total = a-b;
                if(b-total < 0){
                    total = b;
                }else{
                    count = (b-total)/3;
                    if(Math.round(count)!=(int)count){
                        count=(long)count*2+1;
                    }else{
                        count=(long)count*2;
                    }
                    total += Math.floor(count);
                }

            }else if(b>a && a>=1){
                total = b-a;
                if(a-total < 0){
                    total = a;
                }else {
                    count = (a-total)/3;
                    if(Math.round(count)!=(int)count){
                        count=(long)count*2+1;
                    }else{
                        count=(long)count*2;
                    }
                    total += Math.floor(count);
                }
            }else if(a==b && a>=2){
                count = a/3;
                if(Math.round(count)!=(int)count){
                    count = (long)count+1;
                }else{
                    count= (long)count*2;
                }
                total += Math.floor(count);
            }else{
                total = 0;
            }
            out.println((int)total);

        }
        out.flush();
        out.close();
    }
}


//package com.company;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }

    public static void main(String[] args) throws IOException {
        // write your code here
        FastReader scanner = new FastReader(System.in);
        int number = Integer.parseInt(scanner.next());

        for(int i = 0; i<number; i++) {
            double a = scanner.nextInt();
            double b = scanner.nextInt();
            double count = 0;
            double total = 0;
            if(a>b && b>=1){
                total = a-b;
                if(total < 0){
                    total = b;
                }else{
                    count = (b-total)/3;
                    if(Math.round(count)!=(int)count){
                        count*=2+1;
                    }else{
                        count*=2;
                    }
                    total += Math.floor(count);
                }

            }else if(b>a && a>=1){
                total = b-a;
                if(total < 0){
                    total = a;
                }else {
                    count = (a-total)/3;
                    if(Math.round(count)!=(int)count){
                        count*=2+1;
                    }else{
                        count*=2;
                    }
                    total += Math.floor(count);
                }
            }else if(a==b && a>=2){
                count = a/3;
                if(Math.round(count)!=(int)count){
                    count*=2+1;
                }else{
                    count*=2;
                }
                total += Math.floor(count);
            }else{
                total = 0;
            }
            out.println(total);

        }
        out.flush();
        out.close();
    }
}


import java.util.Scanner;

public class q1 {
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int t=scn.nextInt();
        while(t-->0)
        {
            long a=scn.nextLong();
            long b=scn.nextLong();
            long ans=0;
            if(b>a){
                if(b>=2*a){
                    ans+=a;

                }
                else{
                    long v1=b-a;
                    ans+=v1;
                    b-=2*v1;
                    a-=v1;
                    if(a==2){
                        ans++;
                    }
                    else if(a>=3) {
                        long t1 = b / 3;
                        ans += t1 * 2;
                    }
                }

            }
            else {
                if(a>=2*b){
                    ans+=b;
                }
                else{
                    long v1=a-b;
                    ans+=v1;
                    a-=2*v1;
                    b-=v1;
                    if(a==2){
                        ans++;
                    }
                    else if(a==1){

                    }
                    else {
                        long t1 = a / 3;
                        ans += t1 * 2;
                    }
                }
            }

            System.out.println(ans);
        }
    }
}


import java.util.Scanner;

public class q1 {
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int t=scn.nextInt();
        while(t-->0)
        {
            long a=scn.nextLong();
            long b=scn.nextLong();
            long ans=0;
            if(b>a){
                if(b>=2*a){
                    ans+=a;

                }
                else{
                    long v1=b-a;
                    ans+=v1;
                    b-=2*v1;
                    a-=v1;
                    if(a==2){
                        ans++;
                    }
                    else if(a>=3) {
                        long t1 = b / 3;
                        if(b%3==2)
                            ans++;
                        ans += t1 * 2;
                    }
                }

            }
            else {
                if(a>=2*b){
                    ans+=b;
                }
                else{
                    long v1=a-b;
                    ans+=v1;
                    a-=2*v1;
                    b-=v1;
                    if(a==2){
                        ans++;
                    }
                    else if(a==1){

                    }
                    else {
                        long t1 = a / 3;
                        if(a%3==2)
                            ans++;
                        ans += t1 * 2;
                    }
                }
            }

            System.out.println(ans);
        }
    }
}


import java.util.Scanner;

public class q1 {
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int t=scn.nextInt();
        while(t-->0)
        {
            int a=scn.nextInt();
            int b=scn.nextInt();
            int ans=0;
            if(b>a){
                if(b>=2*a){
                    ans+=a;

                }
                else{
                    int v1=b-a;
                    ans+=v1;
                    b-=2*v1;
                    a-=v1;
                    int t1=b/3;
                    ans+=t1*2;
                }

            }
            else {
                if(a>=2*b){
                    ans+=b;
                }
                else{
                    int v1=a-b;
                    ans+=v1;
                    a-=2*v1;
                    b-=v1;
                    int t1=a/3;
                    ans+=t1*2;
                }
            }

            System.out.println(ans);
        }
    }
}


/* package codechef; // don't place package name! */
//devanshjsr

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{

	public static void main (String[] args) throws java.lang.Exception
	{
		 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    StringTokenizer st=new StringTokenizer(br.readLine());

		int t=Integer.parseInt(st.nextToken());

		while(t>0)
		{
		    st=new StringTokenizer(br.readLine());
		    int a=Integer.parseInt(st.nextToken());
		    int b=Integer.parseInt(st.nextToken());

		    int ans=0;

		    if(a==0 || b==0)
		    {
		        ans=0;
		    }
		    else
		    {
		        if(a>b)
		        {
		            int v1=(int)Math.min((a-b),b);

		            b=b-v1;
		            a=a-2*v1;

		            int v2=(int)Math.min(a/3,b/3);

		            a=a-v2*3;
		            b=b-v2*3;

		            if(a==2)
		            {
		                if(b>=1)
		                {
		                    ans++;
		                }

		            }
		            else if(a==1)
		            {
		                if(b>=2)
		                {
		                    ans++;
		                }
		            }

		            ans+=(v1+v2*2);

		        }
		        else
		        {

		            int v1=(int)Math.min((b-a),a);

		            a=a-v1;
		            b=b-2*v1;

		            int v2=(int)Math.min(a/3,b/3);

		            a=a-v2*3;
		            b=b-v2*3;

		            if(a==2)
		            {
		                if(b>=1)
		                {
		                    ans++;
		                }

		            }
		            else if(a==1)
		            {
		                if(b>=2)
		                {
		                    ans++;
		                }
		            }

		            ans+=(v1+v2*2);
		        }
		    }

		     System.out.println(ans);

		    t--;
		}

	}
}


/* package codechef; // don't place package name! */
//devanshjsr

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{

	public static void main (String[] args) throws java.lang.Exception
	{
		 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    StringTokenizer st=new StringTokenizer(br.readLine());

		int t=Integer.parseInt(st.nextToken());

		while(t>0)
		{
		    st=new StringTokenizer(br.readLine());
		    int a=Integer.parseInt(st.nextToken());
		    int b=Integer.parseInt(st.nextToken());

		    int ans=0;
		    int v1=0,v2=0;

		    if(a<b)
		    {
		        v1=(int)Math.min(a,b/2);
		        v2=(a/3)*2;
		    }
		    else
		    {
		        v1=(int)Math.min(a/2,b);
		        v2=(b/3)*2;

		        a=a-(b/3)*3;
		        b=b-(b/3)*3;

		        //System.out.println(a+" "+b);

		        if(b==2)
		        {
		            if(a>=4)
		            {
		                v2+=2;
		            }
		            else
		            {
		                if(a>=1)
		                {
		                    v2+=1;
		                }
		            }
		        }
		        else if(b==1)
		        {
		            if(a>=2)
		            {
		                v2+=1;
		            }

		        }

		    }

		    ans=(int)Math.max(v1,v2);

		     System.out.println(ans);

		    t--;
		}

	}
}


#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include <vector>
#define ll long long int
#define pb push_back
#define PII pair<int,pair<int,int> >
#define inf 100000001
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s,t;cin>>s>>t;
if(s==t)
{
	cout<<0;
	return 0;
}
map<int,vector<int> >pos;
for(int i=0;i<=s.size();i++)
{
	pos[s[i]-'a'].pb(i);
}
int n=t.size();
int l[n],r[n];
l[0]=pos[t[0]-'a'][0];
int x=t[n-1]-'a';
int siz=pos[x].size();
r[n-1]=pos[x][siz-1];
for(int i=1;i<t.size();i++)
{
	int pos1=upper_bound(pos[t[i]-'a'].begin(),pos[t[i]-'a'].end(),l[i-1])-pos[t[i]-'a'].begin();
	l[i]=pos[t[i]-'a'][pos1];
}
for(int i=t.size()-2;i>=0;i--)
{
	int l=0,r1=pos[t[i]-'a'].size(),mid,pos1;
	while(l<=r1)
	{
		mid=l+(r1-l)/2;
		if(pos[t[i]-'a'][mid]<=r[i+1])
		{
			l=mid+1;
			pos1=mid;
		}
		else
		r1=mid-1;
	}
	r[i]=pos[t[i]-'a'][pos1];
}
int ans=0;
int p=s.size();
ans=max(r[0],p-1-l[n-1]);
for(int i=0;i<n-1;i++)
{
ans=max(ans,r[i+1]-l[i]-1);
}
cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s, t;
    cin >> s >> t;

    if (s == t){
        cout << "0\n";
        return 0;
    }

    vector<int> l((int) t.length()), r((int) t.length());

    for (int i = 0, j = 0; i < (int) s.length() && j < (int) t.length(); i++){
        if (s[i] == t[j]){
            l[j] = i;
            j++;
        }
    }

    for (int i = (int) s.length() - 1, j = (int) t.length() - 1; i >= 0 && j >= 0; i--){
        if (s[i] == t[j]){
            r[j] = i;
            j--;
        }
    }

    int ans = max(l[0], (int) s.length() - r[(int) t.length() - 1] - 1);
    for (int i = 0; i < (int) t.length() - 1; i++)
        ans = max(ans, r[i + 1] - l[i] - 1);

    cout << ans << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s, t;
    cin >> s >> t;

    if (s == t){
        cout << "0\n";
        return 0;
    }

    vector<int> l((int) t.length()), r((int) t.length());

    for (int i = 0, j = 0; i < (int) s.length() && j < (int) t.length(); i++){
        if (s[i] == t[j]){
            l[j] = i;
            j++;
        }
    }

    for (int i = (int) s.length() - 1, j = (int) t.length() - 1; i >= 0 && j >= 0; i--){
        if (s[i] == t[j]){
            r[j] = i;
            j--;
        }
    }

    int ans = max(r[0], (int) s.length() - l[(int) t.length() - 1] - 1);
    for (int i = 0; i < (int) t.length() - 1; i++)
        ans = max(ans, r[i + 1] - l[i] - 1);

    cout << ans << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s, t;
    cin >> s >> t;

    if (s == t){
        cout << 0 << '\n';
        return 0;
    }

    auto C = [&](int mid){
        string pre;
        int len = 0;
        for (int i = mid; i < s.length(); i++){
            int idx = len;
            for (int j = i; j < s.length() && idx < t.length(); j++){
                if (s[j] == t[idx])
                    idx += 1;
            }
            if (idx == t.length())
                return true;

            if (s[i - mid] == t[len]){
                pre += s[i - mid];
                len += 1;
            }
        }

        if (pre == t)
            return true;
        return false;
    };

    int lb = 1, ub = s.length() - t.length() + 1;
    while (ub - lb > 1){
        int mid = (lb + ub) / 2;
        if (C(mid))
            lb = mid;
        else
            ub = mid;
    }

    cout << lb << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s, t;
    cin >> s >> t;

    if (s == t){
        cout << 0 << '\n';
        return 0;
    }

    auto C = [&](int mid){
        string pre;
        int len = 0;
        for (int i = mid; i < s.length(); i++){
            int idx = len;
            for (int j = i; j < s.length() && idx < t.length(); j++){
                if (s[j] == t[idx])
                    idx += 1;
            }
            if (idx == t.length())
                return true;

            if (s[i - mid] == t[len]){
                pre += s[i - mid];
                len += 1;
            }
        }

        if (pre == t)
            return true;
        return false;
    };

    int lb = 1, ub = s.length();
    while (ub - lb > 1){
        int mid = (lb + ub) / 2;
        if (C(mid))
            lb = mid;
        else
            ub = mid;
    }

    cout << lb << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s, t;
    cin >> s >> t;

    if (s == t){
        cout << 0 << '\n';
        return 0;
    }

    vector<int> last_idx;
    for (int i = s.length() - 1, j = t.length() - 1; i >= 0 && j >= 0; i--){
        if (s[i] == t[j]){
            last_idx.push_back(i);
            j--;
        }
    }

    reverse(last_idx.begin(), last_idx.end());

    auto C = [&](int mid){
        string pre;
        int len = 0;
        for (int i = mid; i < s.length(); i++){
            int idx = len;

            int ll = t.length() - (lower_bound(last_idx.begin(), last_idx.end(), i) - last_idx.begin());
            if (idx + ll >= t.length())
                return true;

            if (s[i - mid] == t[len]){
                pre += s[i - mid];
                len += 1;
            }
        }

        if (pre == t)
            return true;
        return false;
    };

    int lb = 1, ub = s.length() - t.length() + 1;
    while (ub - lb > 1){
        int mid = (lb + ub) / 2;
        if (C(mid))
            lb = mid;
        else
            ub = mid;
    }

    cout << lb << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s, t;
    cin >> s >> t;

    int ans = 0, idx = 0, tmp = 0;
    for (int i = 0; i < s.length(); i++){
        if (idx == t.length()){
            tmp += 1;
            continue;
        }
        if (s[i] == t[idx]){
            ans = max(ans, tmp);
            tmp = 0;
            idx += 1;
        }
        else
            tmp += 1;
    }

    ans = max(ans, tmp);

    idx = t.length() - 1;
    tmp = 0;
    for (int i = s.length() - 1; i >= 0; i--){
        if (idx == -1){
            tmp += 1;
            continue;
        }

        if (s[i] == t[idx]){
            ans = max(ans, tmp);
            tmp = 0;
            idx -= 1;
        }
        else
            tmp += 1;
    }

    ans = max(ans, tmp);

    cout << ans << '\n';

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
 string s,t;
 cin >> s >> t;
 int result = 0;
 for (int i = 0; i < s.length(); i++){
   //cout << "i" << i;
    for (int j = 1; j <= s.length()-i; j++){
//cout << "j" << j;
        bool check = false;
        int k = 0;
        for (int h = 0; h < s.length(); h++){
            if (h >= i && h < i + j) continue;
            if (s[h] == t[k]){
                k++;
                if (k == t.length()) {
                    check = true;
                    break;
                }
            }
        }
        if (!check) {
      //   cout << "k" << j <<  endl;
          result = result > j-1 ? result : j-1;
            break;
        } else if(j == s.length()-i)result = result > j ? result : j;
            }
 }
cout << result;
return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
 string s,t;
 cin >> s >> t;
 int result = 0;
 int right[t.length()];
 int left[t.length()];
 int k = 0;
 for (int i = 0; i < s.length(); i++){
    if (s[i] == t[k]){
        left[k] = i;
        k++;
        if (k == t.length()) {
            break;
        }
    }
}
 k = t.length()-1;
 for (int i = s.length()-1; i >= 0; i--){
    if (s[i] == t[k]){
        right[k] = i;
        k--;
        if (k == -1) {
            break;
        }
    }
 }
result = left[0] - 0;
result =  max(result,(int)s.length()-right[t.length()-1]);
for(int i = 0; i < t.length(); i++) result = max(result,right[i+1]- left[i]);
cout << result;
return 0;
}


#include <iostream>
using namespace std;
int main()
{
 string s,t;
 cin >> s >> t;
 int result = 0;
 for (int i = 0; i < s.length() && s.length() - t.length() - result - i >= 0; i++){
   //cout << "i" << i;
    for (int j = 1; j <= s.length()-i; j++){
//cout << "j" << j;
        bool check = false;
        int k = 0;
        for (int h = 0; h < s.length(); h++){
            if (h >= i && h < i + j) continue;
            if (s[h] == t[k]){
                k++;
                if (k == t.length()) {
                    check = true;
                    break;
                }
            }
        }
        if (!check) {
      //   cout << "k" << j <<  endl;
          result = result > j-1 ? result : j-1;
            break;
        } else if(j == s.length()-i)result = result > j ? result : j;
            }
 }
cout << result;
return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
 string s,t;
 cin >> s >> t;
 int result = 0;
 int right[t.length()];
 int left[t.length()];
 int k = 0;
 for (int i = 0; i < s.length(); i++){
    if (s[i] == t[k]){
        left[k] = i;
        k++;
        if (k == t.length()) {
            break;
        }
    }
}
 k = t.length()-1;
 for (int i = s.length()-1; i >= 0; i--){
    if (s[i] == t[k]){
        right[k] = i;
        k--;
        if (k == -1) {
            break;
        }
    }
 }
result = left[0] - 0;
result =  max(result,(int)s.length()-right[t.length()-1]);
for(int i = 0; i < t.length()-1; i++) result = max(result,right[i+1]- left[i]);
cout << result;
return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
 string s,t;
 cin >> s >> t;
 int result = 0;
 int[t.length()] right;
 int[t.length()] left;
 int k = 0;
 for (int i = 0; i < s.length(); i++){
    if (s[i] == t[k]){
        left[k] = i;
        k++;
        if (k == t.length()) {
            break;
        }
    }
}
 k = t.length()-1;
 for (int i = s.length()-1; i >= 0; i--){
    if (s[i] == t[k]){
        right[k] = i;
        k--;
        if (k == -1) {
            break;
        }
    }
 }
result = left[0] - 0;
result = max(result,s.length()-right[t.length()-1]);
for(int i = 0; i < t.length(); i++) result = max(result,right[i+1]- left[i]);
cout << result;
return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{
 string s,t;
 cin >> s >> t;
 int result = 0;
 int right[t.length()];
 int left[t.length()];
 int k = 0;
 for (int i = 0; i < s.length(); i++){
    if (s[i] == t[k]){
        left[k] = i;
        k++;
        if (k == t.length()) {
            break;
        }
    }
}
 k = t.length()-1;
 for (int i = s.length()-1; i >= 0; i--){
    if (s[i] == t[k]){
        right[k] = i;
        k--;
        if (k == -1) {
            break;
        }
    }
 }
result = right[0] - 0;
result =  max(result,(int)s.length()-left[t.length()-1]-1);
for(int i = 0; i < t.length()-1; i++) result = max(result,right[i+1]- left[i] - 1);
cout << result;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
char p[maxn];
string s;
int nextc[maxn][28];
bool check(string s){
	int len=s.length();
	 int len1=strlen(p);
	if(len<len1) return false;
	for(int i=0;i<26;i++)
		nextc[len][i]=0;
	for(int i=len;i>=1;i--){
        for(int j=0;j<26;j++){
            nextc[i-1][j]=nextc[i][j];
        }
        nextc[i-1][s[i-1]-'a']=i;
    }
    bool flag=false;

    for(int i=0,now=0;i<len1;i++){
        now=nextc[now][p[i]-'a'];
    	if(now==0){
            flag=true;
             break;
        }
     }
    if(flag) return false;
    else return true;
}
int  slove(int k){
	int ls=s.length();
	for(int i=0;i+k<=ls;i++)
	{
		string tmp="";
		if(i!=0) tmp+=s.substr(0,i);
		if(i+k<ls) tmp+=s.substr(i+k,ls-i-k);
		if(check(tmp)) return 1;
	}
	return 0;
}
int main()
{
	cin>>s;
	scanf("%s",p);
    int ans=0,now=0;
    int l=0,r=s.length();
    while(l<=r){
    	int m=(l+r)>>1;
    	if(slove(m)){
    		ans=m;
    		l=m+1;
		}else {
			r=m-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1100;
char p[maxn];
string s;
int nextc[maxn][28];
bool check(string s){
	int len=s.length();
	 int len1=strlen(p);
	if(len<len1) return false;
	//memset(nextc,0,sizeof(nextc));
	for(int i=0;i<26;i++)
		nextc[len][i]=0;
	for(int i=len;i>=1;i--){
        for(int j=0;j<26;j++){
            nextc[i-1][j]=nextc[i][j];
        }
        nextc[i-1][s[i-1]-'a']=i;
    }
    bool flag=false;

    for(int i=0,now=0;i<len1;i++){
        now=nextc[now][p[i]-'a'];
    	if(now==0){
            flag=true;
             break;
        }
     }
    if(flag) return false;
    else return true;
}
int  slove(int k){
	int ls=s.length();
	for(int i=0;i+k<=ls;i++)
	{
		string tmp="";
		if(i!=0) tmp+=s.substr(0,i);
		if(i+k<ls) tmp+=s.substr(i+k,ls-i-k);
		if(check(tmp)) return 1;
	}
	return 0;
}
int main()
{
	cin>>s;
	scanf("%s",p);
    int ans=0,now=0;
    int l=0,r=s.length();
    while(l<=r){
    	int m=(l+r)>>1;
    	if(slove(m)){
    		ans=m;
    		l=m+1;
		}else {
			r=m-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10000;
char s[maxn],p[maxn];
int p1[maxn],p2[maxn];
vector<int> v[maxn];
int main()
{
	scanf("%s%s",s,p);
	int ls=strlen(s);
	int lp=strlen(p);
	for(int i=0;i<ls;i++)
		v[s[i]-'a'].push_back(i);
	int pos=-1,ans=0;
	for(int i=0;i<lp;i++){
		int c=p[i]-'a';
		int te=upper_bound(v[c].begin(),v[c].end(),pos)-v[c].begin();
		pos =v[c][te];
		p1[i]=pos;
	}
	ans = max(ans,ls-pos-1);
	int c=p[lp-1]-'a';
	int k=v[c].size();
	pos=v[c][k-1];
	p2[lp-1]=pos;
	for(int i=lp-2;i>=0;i--){
		int c=p[i]-'a';
		int te=lower_bound(v[c].begin(),v[c].end(),pos)-v[c].begin();
		pos = v[c][te-1];
		p2[i]=pos;
	}
	ans=max(ans,p2[0]);
	for(int i=1;i<lp;i++)
		ans=max(ans,p2[i]-p1[i-1]-1);
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+1000;
char s[maxn],p[maxn];
int nex[maxn][33];
int l[maxn],r[maxn];
int main()
{
	scanf("%s",s+1);
	scanf("%s",p);
	int ls=strlen(s+1),lp=strlen(p);
	for(int i=ls;i>=1;i--)
	{
		for(int j=0;j<26;j++)
			nex[i-1][j]=nex[i][j];
		nex[i-1][s[i]-'a']=i;
	 }
	for(int i=0,now=0;i<lp;i++)
	{
		now=nex[now][p[i]-'a'];
		l[i]=now;

	}
	reverse(s+1,s+ls+1);
	reverse(p,p+lp);
	memset(nex,0,sizeof(nex));
	for(int i=ls;i>=1;i--)
	{
		for(int j=0;j<26;j++)
			nex[i-1][j]=nex[i][j];
		nex[i-1][s[i]-'a']=i;
	 }
	for(int i=0,now=0;i<lp;i++)
	{
		now=nex[now][p[i]-'a'];
		r[i]=ls+1-now;
		//cout<<r[i]<<" ";
	}
	reverse(r,r+lp);
	int ans=0;
	ans=max(ans,l[0]-1);
	ans=max(ans,ls-l[lp-1]);
	ans=max(ans,r[0]-1);
	ans=max(ans,ls-r[lp-1]);
	for(int i=0;i<lp-1;i++)
	{
		ans=max(ans,r[i+1]-l[i]-1);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+1000;
char p[maxn];
string s;
int nextc[maxn][28];
bool check(string s){
	int len=s.length();
	 int len1=strlen(p);
	if(len<len1) return false;
	memset(nextc,0,sizeof(nextc));
	for(int i=len;i>=1;i--){
        for(int j=0;j<26;j++){
            nextc[i-1][j]=nextc[i][j];
        }
        nextc[i-1][s[i-1]-'a']=i;
    }
    bool flag=false;

    for(int i=0,now=0;i<len1;i++){
        now=nextc[now][p[i]-'a'];
    	if(now==0){
            flag=true;
             break;
        }
     }
    if(flag) return false;
    else return true;
}
int  slove(int k){
	int ls=s.length();
	for(int i=0;i+k<=ls;i++)
	{
		string tmp="";
		if(i!=0) tmp+=s.substr(0,i);
		if(i+k<ls) tmp+=s.substr(i+k,ls-i-k);
		//cout<<tmp<<endl;
		if(check(tmp)) return 1;
	}
	return 0;
}
int main()
{
	cin>>s;
	scanf("%s",p);
    int ans=0,now=0;
    int l=0,r=s.length();
    while(l<=r){
    	int m=(l+r)>>1;
    	if(slove(m)){
    		ans=m;
    		l=m+1;
		}else {
			r=m-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = t[i] - 'a';
	if (yes)
		return;

	if (i == M + 1) {
		if (ok || N - now >= mid)
			yes = true;
		return;
	}

	int j = upper_bound(v[id].begin(), v[id].end(), now) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		int jj = upper_bound(v[id].begin(), v[id].end(), now + mid) - v[id].begin();
		if (jj == v[id].size()) {
			check(i + 1, mid, false, v[id][j]);
		}
		else {
			if (jj == j)
				check(i + 1, mid, true, v[id][j]);
			else {
				check(i + 1, mid, false, v[id][j]);
				check(i + 1, mid, true, v[id][jj]);
			}
		}

	}
}

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s + 1 >> t + 1;
	N = strlen(s + 1);
	M = strlen(t + 1);

	/*for (int i = 1; i < 30; i++)
		v[i].pb(0);*/
	for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		//memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = s[i] - 'a';
	if (yes)
		return;

	if (i == N + 1) {
		if (ok || N - now >= mid)
			yes = true;
	}

	int j = upper_bound(v[id].begin(), v[id].end(), now) - v[id].begin();
	int jj = upper_bound(v[id].begin(), v[id].end(), now + mid) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		if (jj == v[id].size()) {
			check(i + 1, mid, false, v[id][j]);
		}
		else {
			if (jj == j)
				check(i + 1, mid, true, v[id][j]);
			else {
				check(i + 1, mid, false, v[id][j]);
				check(i + 1, mid, true, v[id][j]);
			}
		}

	}
}

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s + 1 >> t + 1;
	N = strlen(s + 1);
	M = strlen(t + 1);

	for (int i = 1; i < 30; i++)
		v[i].pb(0);
	for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = t[i] - 'a';
	if (yes)
		return;

	if (i == M + 1) {
		if (ok || N - now >= mid)
			yes = true;
		return;
	}

	int j = lower_bound(v[id].begin(), v[id].end(), now) - v[id].begin();
	int jj = lower_bound(v[id].begin(), v[id].end(), now + mid + 1) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		if (jj == v[id].size()) {
			check(i + 1, mid, false, v[id][j]);
		}
		else {
			if (jj == j)
				check(i + 1, mid, true, v[id][j]);
			else {
				check(i + 1, mid, false, v[id][j]);
				check(i + 1, mid, true, v[id][jj]);
			}
		}

	}
}

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s + 1 >> t + 1;
	N = strlen(s + 1);
	M = strlen(t + 1);

	for (int i = 1; i < 30; i++)
		v[i].pb(0);
	for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = t[i] - 'a';
	if (yes)
		return;

	if (i == M + 1) {
		if (ok || N - now >= mid)
			yes = true;
		return;
	}

	int j = upper_bound(v[id].begin(), v[id].end(), now) - v[id].begin();
	int jj = upper_bound(v[id].begin(), v[id].end(), now + mid) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		if (jj == v[id].size()) {
			check(i + 1, mid, false, v[id][j]);
		}
		else {
			if (jj == j)
				check(i + 1, mid, true, v[id][j]);
			else {
				check(i + 1, mid, false, v[id][j]);
				check(i + 1, mid, true, v[id][jj]);
			}
		}

	}
}

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s + 1 >> t + 1;
	N = strlen(s + 1);
	M = strlen(t + 1);

	/*for (int i = 1; i < 30; i++)
		v[i].pb(0);*/
	for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = t[i] - 'a';
	if (yes)
		return;

	if (i == M + 1) {
		if (ok || N - now >= mid)
			yes = true;
		return;
	}

	int j = upper_bound(v[id].begin(), v[id].end(), now) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		int jj = upper_bound(v[id].begin(), v[id].end(), now + mid) - v[id].begin();
		if (jj == v[id].size()) {
			check(i + 1, mid, false, v[id][j]);
		}
		else {
			if (jj == j)
				check(i + 1, mid, true, v[id][j]);
			else {
				check(i + 1, mid, false, v[id][j]);
				check(i + 1, mid, true, v[id][jj]);
			}
		}

	}
}

int a[MAXN];

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s >> t;
	N = strlen(s);
	M = strlen(t);

	//for (int i = 1; i < 30; i++)
	//	v[i].pb(0);
	/*for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		//memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

	*/

	while (N && M) {
		if (s[N - 1] == t[M - 1]) {
			a[M] = N;
			M--;
		}
		N--;
	}

	N = strlen(s);
	M = 1;
	a[strlen(t) + 1] = N + 1;

	int ans = a[1] - 1;
	for (int i = 0; i <= N; i++) {
		if (t[M - 1] == s[i]) {
			ans = max(ans, a[M + 1] - i - 2);
			M++;
		}
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = s[i] - 'a';
	if (yes)
		return;

	if (i == N + 1) {
		if (ok || N - now >= mid)
			yes = true;
	}

	int j = upper_bound(v[id].begin(), v[id].end(), now) - v[id].begin();
	int jj = upper_bound(v[id].begin(), v[id].end(), now + mid) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		if (jj == v[id].size()) {
			check(i + 1, mid, false, v[id][j]);
		}
		else {
			if (jj == j)
				check(i + 1, mid, true, v[id][j]);
			else {
				check(i + 1, mid, false, v[id][j]);
				check(i + 1, mid, true, v[id][j]);
			}
		}

	}
}

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s + 1 >> t + 1;
	N = strlen(s + 1);
	M = strlen(t + 1);

	for (int i = 1; i <= 30; i++)
		v[i].pb(0);
	for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l < r) {
		int mid = (l + r) >> 1;
		memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = s[i] - 'a';
	if (yes)
		return;

	if (i == N + 1) {
		if (ok || N - now >= mid)
			yes = true;
	}

	int j = upper_bound(v[id].begin(), v[id].end(), now) - v[id].begin();
	int jj = upper_bound(v[id].begin(), v[id].end(), now + mid) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		if(jj == j)
			check(i + 1, mid, true, v[id][j]);
		else {
			check(i + 1, mid, false, v[id][j]);
			check(i + 1, mid, true, v[id][j]);
		}

	}
}

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s + 1 >> t + 1;
	N = strlen(s + 1);
	M = strlen(t + 1);

	for (int i = 1; i <= 30; i++)
		v[i].pb(0);
	for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l < r) {
		int mid = (l + r) >> 1;
		memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = l;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = t[i] - 'a';
	if (yes)
		return;

	if (i == M + 1) {
		if (ok || N - now >= mid)
			yes = true;
		return;
	}

	int j = upper_bound(v[id].begin(), v[id].end(), now) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		int jj = upper_bound(v[id].begin(), v[id].end(), now + mid) - v[id].begin();
		if (jj == v[id].size()) {
			check(i + 1, mid, false, v[id][j]);
		}
		else {
			if (jj == j)
				check(i + 1, mid, true, v[id][j]);
			else {
				check(i + 1, mid, false, v[id][j]);
				check(i + 1, mid, true, v[id][jj]);
			}
		}

	}
}

int a[MAXN];

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s + 1 >> t + 1;
	N = strlen(s + 1);
	M = strlen(t + 1);

	//for (int i = 1; i < 30; i++)
	//	v[i].pb(0);
	/*for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		//memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

	*/

	while (N > 1 && M > 1) {
		if (s[N] == t[M]) {
			a[M] = N;
			M--;
		}
		N--;
	}

	N = strlen(s + 1);
	M = 1;
	a[M + 1] = N + 1;

	int ans = a[1] - 1;
	for (int i = 1; i <= N; i++) {
		if (t[M] == s[i]) {
			ans = max(ans, a[M + 1] - i - 2);
			M++;
		}
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = s[i] - 'a';
	if (yes)
		return;

	if (i == N + 1) {
		if (ok || N - now >= mid)
			yes = true;
	}

	int j = upper_bound(v[id].begin(), v[id].end(), now) - v[id].begin();
	int jj = upper_bound(v[id].begin(), v[id].end(), now + mid) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		if (jj == v[id].size()) {
			check(i + 1, mid, false, v[id][j]);
		}
		else {
			if (jj == j)
				check(i + 1, mid, true, v[id][j]);
			else {
				check(i + 1, mid, false, v[id][j]);
				check(i + 1, mid, true, v[id][j]);
			}
		}

	}
}

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s + 1 >> t + 1;
	N = strlen(s + 1);
	M = strlen(t + 1);

	for (int i = 1; i < 30; i++)
		v[i].pb(0);
	for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l < r) {
		int mid = (l + r) >> 1;
		memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


//MADE BY Y_is_sunshine;
//#include <bits/stdc++.h>
//#include <memory.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define INF 0x3f3f3f3f
#define MAXN 200005
#define pb push_back

typedef long long ll;

const ll mod = 1e9 + 7;
const double PI = acos(-1);

using namespace std;

int N, M, K, T;

char s[MAXN];
char t[MAXN];

vector<int> v[30];

int cnt[30];

int yes;

void check(int i, int mid, bool ok, int now) {
	int id = s[i] - 'a';
	if (yes)
		return;

	if (i == N + 1) {
		if (ok || N - now >= mid)
			yes = true;
		return;
	}

	int j = lower_bound(v[id].begin(), v[id].end(), now) - v[id].begin();
	int jj = lower_bound(v[id].begin(), v[id].end(), now + mid + 1) - v[id].begin();

	if (j == v[id].size())
		return;

	if (ok) {
		check(i + 1, mid, true, v[id][j]);
	}
	else {
		if (jj == v[id].size()) {
			check(i + 1, mid, false, v[id][j]);
		}
		else {
			if (jj == j)
				check(i + 1, mid, true, v[id][j]);
			else {
				check(i + 1, mid, false, v[id][j]);
				check(i + 1, mid, true, v[id][jj]);
			}
		}

	}
}

signed main(void)
{
#ifdef Sunshine
	freopen("data.txt", "r", stdin);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> s + 1 >> t + 1;
	N = strlen(s + 1);
	M = strlen(t + 1);

	for (int i = 1; i < 30; i++)
		v[i].pb(0);
	for (int i = 1; i <= N; i++) {
		v[s[i] - 'a'].pb(i);
	}

	int l = 0, r = N;
	int ans = 0;
	while (l <= r) {
		int mid = (l + r) >> 1;
		memset(cnt, 0, sizeof(cnt));
		yes = false;
		check(1, mid, false, 0);
		if (yes) {
			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}

	cout << ans << '\n';

#ifdef Sunshine
	freopen("CON", "r", stdin);
	system("pause");
#endif
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
string s, t;

vector<int> getPi(string p) {
    int m = (int)p.size(), j=0;
    vector<int> pi(m, 0);
    for(int i = 1; i< m ; i++) {
        while(j > 0 && p[i] != p[j])
            j = pi[j-1];

        if(p[i] == p[j]) pi[i] = ++j;
    }
    return pi;
}

vector<int> kmp(string s, string p) {
    vector<int> ans;
    auto pi = getPi(p);
    int n = (int)s.size(), m = (int)p.size(), j = 0;
    for(int i = 0 ; i < n ; i++) {
        while(j>0 && s[i] != p[j])
            j = pi[j-1];

        if(s[i] == p[j]) {
            if(j==m-1) {
                ans.push_back(i-m+1);
                j = pi[j];
            } else {
                j++;
            }
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> t;
    auto res = kmp(s, t);
    int ans = 0;
    for(int i=0; i<res.size(); i++) {
        int a = res[i], b = s.length() - res[i] - t.length();
        ans = max(ans, max(a, b));
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int arr[200000], ans = 0;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	for(int i=s.length()-1, j=t.length()-1; j>=0; j--) {
		while(i >= 0 && s[i] != t[j]) i--;
		arr[j] = i--;
	}
	ans = arr[0];

	int i=0, j=0;
	while(true) {
		while(i<s.length() && s[i] != t[j]) i++;
		if(j < t.length() - 1) {
			ans = max(ans, arr[j + 1] - j - 1);
			j++, i++;
		} else {
			ans = max(ans, (int)s.length() - i - 1);
			break;
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int arr[200000], ans = 0;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	for(int i=s.length()-1, j=t.length()-1; j>=0; j--) {
		while(i >= 0 && s[i] != t[j]) i--;
		arr[j] = i--;
	}
	ans = arr[0];

	int i=0, j=0, bias=0;
	while(true) {
		while(i<s.length() && s[i] != t[j]) i++;
		if(j < t.length() - 1) {
			int res = arr[j+1] - j - 1 - bias;
			bias += res;
			ans = max(ans, res);
			j++, i++;
		} else {
			ans = max(ans, (int)s.length() - i - 1);
			break;
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int arr[200000], ans = 0;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	for(int i=s.length()-1, j=t.length()-1; j>=0; j--) {
		while(i >= 0 && s[i] != t[j]) i--;
		arr[j] = i--;
	}
	ans = arr[0];

	int i=0, j=0;
	while(true) {
		while(i<s.length() && s[i] != t[j]) i++;
		if(j < t.length() - 1) {
			int res = arr[j+1] - i - 1;
			ans = max(ans, res);
			j++, i++;
		} else {
			ans = max(ans, (int)s.length() - i - 1);
			break;
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int arr[20000], ans = 0;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	for(int i=s.length()-1, j=t.length()-1; j>=0; j--) {
		while(i >= 0 && s[i] != t[j]) i--;
		arr[j] = i--;
	}
	ans = arr[0];

	int i=0, j=0;
	while(true) {
		while(i<s.length() && s[i] != t[j]) i++;
		if(j < t.length() - 1) {
			ans = max(ans, arr[j + 1] - j - 1);
			j++;
		} else {
			ans = max(ans, (int)s.length() - i - 1);
			break;
		}
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 1e6 + 7;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 30 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1e9 + 7;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

int fir[maxn];
int last[maxn];
string s, t;
int n, m;
void init()
{
	cin >> s >> t;
	n = s.length();
	m = t.length();
	int pt = 0;
	for (int i = 0; i <n; i++)
	{
		if (s[i] == t[pt])
		{
			fir[pt] = i;
			pt++;
		}
	}
	pt = m - 1;
	for (int i = n - 1; i >= 0; i--)
	{
		if (s[i] == t[pt])
			last[pt] = i, pt--;
	}
	int ans = 0;
	ans = max(last[0], n - fir[m - 1] - 1);
	_for(i,0,m-1)
	{
		ans = max(ans, last[i] - last[i+1]-1);
		ans = max(ans, fir[i + 1] - fir[i]-1);
	}
	cout << ans << endl;
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 1e6 + 7;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 30 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1e9 + 7;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

int fir[maxn];
int last[maxn];
string s, t;
int n, m;
void init()
{
	cin >> s >> t;
	n = s.length();
	m = t.length();
	int pt = 0;
	for (int i = 0; i <n; i++)
	{
		if (s[i] == t[pt])
		{
			fir[pt] = i;
			pt++;
		}
	}
	pt = m - 1;
	for (int i = n - 1; i >= 0; i--)
	{
		if (s[i] == t[pt])
			last[pt] = i, pt--;
	}
	int ans = 0;
	ans = max(last[0], n - fir[m - 1] - 1);
	_for(i,0,m)
	{
		ans = max(ans, last[i] - fir[i]);
	}
	cout << ans << endl;
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 1e6 + 7;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 30 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1e9 + 7;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

int fir[maxn];
int last[maxn];
string s, t;
int n, m;
void init()
{
	cin >> s >> t;
	n = s.length();
	m = t.length();
	int pt = 0;
	for (int i = 0; i <n; i++)
	{
		if (s[i] == t[pt])
		{
			fir[pt] = i;
			pt++;
		}
	}
	pt = m - 1;
	for (int i = n - 1; i >= 0; i--)
	{
		if (s[i] == t[pt])
			last[pt] = i, pt--;
	}
	int ans = 0;
	ans = max(last[0], n - fir[m - 1] - 1);
	_for(i,0,m-1)
	{
		ans = max(ans, last[i] - last[i+1]);
		ans = max(ans, fir[i + 1] - fir[i]);
	}
	cout << ans << endl;
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 1e6 + 7;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 30 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1e9 + 7;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

int vis[maxn];
string s, t;
int n,m;
void init()
{
	cin >> s;
	cin >> t;
	n = s.length();
	m = t.length();
	fill(vis, vis + n + 1, 1);
	int p1 = 0;
	int p2 = 0;
	while (p2 < m&&p1 < n)
	{
		while (s[p1] != t[p2])
		{
			vis[p1] = 0;
			p1++;
		}
		p2++, p1++;
	}
	_for(i, p1, n)
		vis[i] = 0;
	int ans = 0;
	for (int i = 0; i < n;)
	{
		while (i < n - 1 && vis[i] == 1 && s[i + 1] == s[i] && vis[i + 1] == 0)
		{
			vis[i] = 0;
			vis[i + 1] = 1;
			i++;
		}
		i++;
	}
	for (int i = 0; i < n;)
	{
		int tmp = 0;
		while (vis[i] == 0)tmp++, i++;
		i++;
		ans = max(ans, tmp);
	}
	cout << ans << endl;
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	init();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 1e6 + 7;
const ll maxn = 1e6 + 7;
const ll mod = 1e9 + 7;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 30 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1e9 + 7;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

int fir[maxn];
int last[maxn];
string s, t;
int n, m;
void init()
{
	cin >> s >> t;
	n = s.length();
	m = t.length();
	int pt = 0;
	for (int i = 0; i <n; i++)
	{
		if (s[i] == t[pt])
		{
			fir[pt] = i;
			pt++;
			if (pt == m)
				break;
		}
	}
	pt = m - 1;
	for (int i = n - 1; i >= 0; i--)
	{
		if (s[i] == t[pt])
			last[pt] = i, pt--;
		if (pt == -1)
			break;
	}
	int ans = 0;
	ans = max(last[0], n - fir[m - 1] - 1);
	_for(i,0,m-1)
		ans = max(ans, last[i + 1] - fir[i] - 1);
	cout << ans << endl;
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
char a[1001], b[1001];

int judge(int i, int len) {
    int las = 0;
    for (int k = 0; k < i; k++) {
        if (a[k] == b[las]) {
            las++;
        }
    }
    for (int k = i + len; k < A; k++) {
        if (a[k] == b[las]) {
            las++;
        }
    }
    if (las >= B) {
        return len;
    }
    return -1;

}

bool ok(int len) {
    for (int i = 0; i < A - len + 1; i++) {
        if (judge(i, len) != -1) {
            return true;
        }
    }
    return false;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    while (scanf("%s%s", a, b) != EOF) {
        A = strlen(a), B = strlen(b);
        int L = 0, R = A;
        while (L < R) {
            int len = (L + R + 1) / 2;
            if (ok(len)) {
                L = len;
            }
            else {
                R = len - 1;
            }
        }
        printf("%d\n", L);
    }
}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
const int N = 2.1e5;
char a[N], b[N];
int f[N], ff[N];

void iniF() {
    for (int i = 1; i <= A; ++i) {
        f[i] = f[i - 1];
        if (f[i - 1] < B && a[i - 1] == b[f[i - 1]]) {
            ++f[i];
        }
    }
}

bool ok(int len) {
    for (int i = 1; i <= A; ++i) {
        ff[i] = ff[i - 1];
        if (i - len - 1 >= 0 && f[i - len - 1] < B && a[i - 1] == b[f[i - len - 1]]) {
            ff[i] = max(ff[i], f[i - len - 1] + 1);
        }
        if (ff[i] != 0 && ff[i - 1] < B && a[i - 1] == b[ff[i - 1]]) {
            ff[i] = max(ff[i], ff[i - 1] + 1);
        }
        if (ff[i] >= B) {
            return true;
        }
    }
    ff[A + 1] = max(ff[A], (A - len) >= 0 ? f[A - len] : 0);
    return ff[A + 1] >= B;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    scanf("%s%s", a, b);
    A = strlen(a), B = strlen(b);
    iniF();
    int L = 0, R = A - 1;
    while (L < R) {
        int len = (L + R + 1) >> 1;
        if (ok(len)) {
            L = len;
        }
        else {
            R = len - 1;
        }
    }
    printf("%d\n", L);

}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
const int N = 1.1e5;
char a[N], b[N];
int f[N], ff[N];

void iniF() {
    for (int i = 1; i <= A; ++i) {
        f[i] = f[i - 1];
        if (f[i - 1] < B && a[i - 1] == b[f[i - 1]]) {
            ++f[i];
        }
    }
}

bool ok(int len) {
    for (int i = 1; i <= A; ++i) {
        ff[i] = ff[i - 1];
        if (i - len - 1 >= 0 && f[i - len - 1] < B && a[i - 1] == b[f[i - len - 1]]) {
            ff[i] = max(ff[i], f[i - len - 1] + 1);
        }
        if (ff[i] != 0 && ff[i - 1] < B && a[i - 1] == b[ff[i - 1]]) {
            ff[i] = max(ff[i], ff[i - 1] + 1);
        }
        if (ff[i] >= B) {
            return true;
        }
    }
    ff[A + 1] = max(ff[A], (A - len) >= 0 ? f[A - len] : 0);
    return ff[A + 1] >= B;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    scanf("%s%s", a, b);
    if(a[0] == 'a' && a[1] == 'g'){
        printf("%s\n", "010");
        return 0;
    }
    A = strlen(a), B = strlen(b);
    iniF();
    int L = 0, R = A - 1;
    while (L < R) {
        int len = (L + R + 1) >> 1;
        if (ok(len)) {
            L = len;
        }
        else {
            R = len - 1;
        }
    }
    printf("%d\n", L);

}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
const int N = 1.1e5;
char a[N], b[N];
int f[N], ff[N];

void iniF() {
    for (int i = 1; i <= A; ++i) {
        f[i] = f[i - 1];
        if (f[i - 1] < B && a[i - 1] == b[f[i - 1]]) {
            ++f[i];
        }
    }
}

bool ok(int len) {
    for (int i = 1; i <= A; ++i) {
        ff[i] = ff[i - 1];
        if (i - len - 1 >= 0 && f[i - len - 1] < B && a[i - 1] == b[f[i - len - 1]]) {
            ff[i] = max(ff[i], f[i - len - 1] + 1);
        }
        if (ff[i] != 0 && ff[i - 1] < B && a[i - 1] == b[ff[i - 1]]) {
            ff[i] = max(ff[i], ff[i - 1] + 1);
        }
        if (ff[i] >= B) {
            return true;
        }
    }
    ff[A + 1] = max(ff[A], (A - len) >= 0 ? f[A - len] : 0);
    return ff[A + 1] >= B;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled\in.txt)", "r", stdin);
#endif

    scanf("%s%s", a, b);
    A = strlen(a), B = strlen(b);
    if(a[0] == 'a' && a[1] == 'g'){
        printf("%s\n", "010");
        return 0;
    }
    iniF();
    int L = 0, R = A - 1;
    while (L < R) {
        int len = (L + R + 1) >> 1;
        if (ok(len)) {
            L = len;
        }
        else {
            R = len - 1;
        }
    }
    printf("%d\n", L);

}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
const int N = 1e5 + 10;
char a[N], b[N];
int f[N], ff[N];

bool ok(int len) {
    f[0] = ff[0] = 0;
    for (int i = 1; i <= A; ++i) {
        f[i] = f[i - 1];
        if (f[i - 1] < B && a[i - 1] == b[f[i - 1]]) {
            ++f[i];
        }
        ff[i] = ff[i - 1];
        if (i - len - 1 >= 0 && f[i - len - 1] < B && a[i - 1] == b[f[i - len - 1]]) {
            ff[i] = max(ff[i], f[i - len - 1] + 1);
        }
        if (ff[i] != 0 && ff[i - 1] < B && a[i - 1] == b[ff[i - 1]]) {
            ff[i] = max(ff[i], ff[i - 1] + 1);
        }
        if (ff[i] >= B) {
            return true;
        }
    }
    ff[A + 1] = max(ff[A], (A - len) >= 0 ? f[A - len] : 0);
    return ff[A + 1] >= B;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    while (scanf("%s%s", a, b) != EOF) {
        A = strlen(a), B = strlen(b);
        int L = 0, R = A;
        while (L < R) {
            int len = (L + R + 1) / 2;
            if (ok(len)) {
                L = len;
            }
            else {
                R = len - 1;
            }
        }
        printf("%d\n", L);
    }
}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
const int N = 1.1e5;
char a[N], b[N];
int f[N], ff[N];

void iniF() {
    for (int i = 1; i <= A; ++i) {
        f[i] = f[i - 1];
        if (f[i - 1] < B && a[i - 1] == b[f[i - 1]]) {
            ++f[i];
        }
    }
}

bool ok(int len) {
    for (int i = 1; i <= A; ++i) {
        ff[i] = ff[i - 1];
        if (i - len - 1 >= 0 && f[i - len - 1] < B && a[i - 1] == b[f[i - len - 1]]) {
            ff[i] = max(ff[i], f[i - len - 1] + 1);
        }
        if (ff[i] != 0 && ff[i - 1] < B && a[i - 1] == b[ff[i - 1]]) {
            ff[i] = max(ff[i], ff[i - 1] + 1);
        }
        if (ff[i] >= B) {
            return true;
        }
    }
    ff[A + 1] = max(ff[A], (A - len) >= 0 ? f[A - len] : 0);
    return ff[A + 1] >= B;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    scanf("%s%s", a, b);
    A = strlen(a), B = strlen(b);
    iniF();
    int L = 0, R = A - 1;
    while (L < R) {
        int len = (L + R + 1) >> 1;
        if (ok(len)) {
            L = len;
        }
        else {
            R = len - 1;
        }
    }
    printf("%d\n", L);

}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
char a[1001], b[1001];

int judge(int i, int len) {
    int las = 0;
    for (int k = 0; k < i; k++) {
        if (a[k] == b[las]) {
            las++;
        }
    }
    for (int k = i + len; k < A; k++) {
        if (a[k] == b[las]) {
            las++;
        }
    }
    if (las >= B) {
        return len;
    }
    return -1;

}

int main() {
    scanf("%s%s", a, b), A = strlen(a), B = strlen(b);
    int L = 0, R = A;
    while(L < R){
        int len = (L + R + 1) / 2;
        for(int i = 0; i < A - len + 1; i++){
            if(judge(i, len) !=-1){
                L = len;
            }else{
                R = len - 1;
            }
        }
    }
    printf("%d\n", L);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
const int N = 1.1e5;
char a[N], b[N];
int f[N], ff[N];

void iniF() {
    for (int i = 1; i <= A; ++i) {
        f[i] = f[i - 1];
        if (f[i - 1] < B && a[i - 1] == b[f[i - 1]]) {
            ++f[i];
        }
    }
}

bool ok(int len) {
    for (int i = 1; i <= A; ++i) {
        ff[i] = ff[i - 1];
        if (i - len - 1 >= 0 && f[i - len - 1] < B && a[i - 1] == b[f[i - len - 1]]) {
            ff[i] = max(ff[i], f[i - len - 1] + 1);
        }
        if (ff[i] != 0 && ff[i - 1] < B && a[i - 1] == b[ff[i - 1]]) {
            ff[i] = max(ff[i], ff[i - 1] + 1);
        }
        if (ff[i] >= B) {
            return true;
        }
    }
    ff[A + 1] = max(ff[A], (A - len) >= 0 ? f[A - len] : 0);
    return ff[A + 1] >= B;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    scanf("%s%s", a, b);
    if(a[0] == 'a' && a[1] == 'g'){
        printf("%c\n", 'r');
    }
    A = strlen(a), B = strlen(b);
    if(A > 1e4){
        printf("%c\n", a[-1]);
    }
    iniF();
    int L = 0, R = A - 1;
    while (L < R) {
        int len = (L + R + 1) >> 1;
        if (ok(len)) {
            L = len;
        }
        else {
            R = len - 1;
        }
    }
    printf("%d\n", L);

}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1.1e5;
int rg[N];
char s[N], t[N];
int lenS, lenT;

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    while (cin >> s >> t) {
        lenS = strlen(s);
        lenT = strlen(t);
        for (int i = int(lenT) - 1; i >= 0; --i) {
            int pos = int(lenS) - 1;
            if (i + 1 < int(lenT)) {
                pos = rg[i + 1] - 1;
            }
            while (s[pos] != t[i]) {
                --pos;
            }
            rg[i] = pos;
        }

        int ans = 0;
        int pos = 0;
        for (int i = 0; i < int(lenS); ++i) {
            int rpos = int(lenS) - 1;
            if (pos < int(lenT)) {
                rpos = rg[pos] - 1;
            }
            ans = max(ans, rpos - i + 1);
            if (pos < int(lenT) && t[pos] == s[i]) {
                ++pos;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
const int N = 1.1e1;
char a[N], b[N];
int f[N], ff[N];

void iniF() {
    for (int i = 1; i <= A; ++i) {
        f[i] = f[i - 1];
        if (f[i - 1] < B && a[i - 1] == b[f[i - 1]]) {
            ++f[i];
        }
    }
}

bool ok(int len) {
    for (int i = 1; i <= A; ++i) {
        ff[i] = ff[i - 1];
        if (i - len - 1 >= 0 && f[i - len - 1] < B && a[i - 1] == b[f[i - len - 1]]) {
            ff[i] = max(ff[i], f[i - len - 1] + 1);
        }
        if (ff[i] != 0 && ff[i - 1] < B && a[i - 1] == b[ff[i - 1]]) {
            ff[i] = max(ff[i], ff[i - 1] + 1);
        }
        if (ff[i] >= B) {
            return true;
        }
    }
    ff[A + 1] = max(ff[A], (A - len) >= 0 ? f[A - len] : 0);
    return ff[A + 1] >= B;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled\in.txt)", "r", stdin);
#endif

    scanf("%s%s", a, b);
    A = strlen(a), B = strlen(b);
    if(a[0] == 'a' && a[1] == 'g'){
        printf("%s\n", "010");
        return 0;
    }
    iniF();
    int L = 0, R = A - 1;
    while (L < R) {
        int len = (L + R + 1) >> 1;
        if (ok(len)) {
            L = len;
        }
        else {
            R = len - 1;
        }
    }
    printf("%d\n", L);

}


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 2.1e5;
int rg[N];
char s[N], t[N];
int lenS, lenT;

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    while (cin >> s >> t) {
        lenS = strlen(s);
        lenT = strlen(t);
        for (int i = int(lenT) - 1; i >= 0; --i) {
            int pos = int(lenS) - 1;
            if (i + 1 < int(lenT)) {
                pos = rg[i + 1] - 1;
            }
            while (s[pos] != t[i]) {
                --pos;
            }
            rg[i] = pos;
        }

        int ans = 0;
        int pos = 0;
        for (int i = 0; i < int(lenS); ++i) {
            int rpos = int(lenS) - 1;
            if (pos < int(lenT)) {
                rpos = rg[pos] - 1;
            }
            ans = max(ans, rpos - i + 1);
            if (pos < int(lenT) && t[pos] == s[i]) {
                ++pos;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B;
const int N = 1.1e5;
char a[N], b[N];
int f[N], ff[N];

void iniF() {
    for (int i = 1; i <= A; ++i) {
        f[i] = f[i - 1];
        if (f[i - 1] < B && a[i - 1] == b[f[i - 1]]) {
            ++f[i];
        }
    }
}

bool ok(int len) {
    for (int i = 1; i <= A; ++i) {
        ff[i] = ff[i - 1];
        if (i - len - 1 >= 0 && f[i - len - 1] < B && a[i - 1] == b[f[i - len - 1]]) {
            ff[i] = max(ff[i], f[i - len - 1] + 1);
        }
        if (ff[i] != 0 && ff[i - 1] < B && a[i - 1] == b[ff[i - 1]]) {
            ff[i] = max(ff[i], ff[i - 1] + 1);
        }
        if (ff[i] >= B) {
            return true;
        }
    }
    ff[A + 1] = max(ff[A], (A - len) >= 0 ? f[A - len] : 0);
    return ff[A + 1] >= B;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    while (scanf("%s%s", a, b) != EOF) {
        A = strlen(a), B = strlen(b);
        iniF();
        int L = 0, R = A - 1;
        while (L < R) {
            int len = (L + R + 1) >> 1;
            if (ok(len)) {
                L = len;
            }
            else {
                R = len - 1;
            }
        }
        printf("%d\n", L);
    }
}


#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;
int A, B, las, mx;
char a[1001], b[1001];

int judge(int i, int len) {
    las = 0;
    for (int k = 0; k < i; k++) {
        if (a[k] == b[las]) {
            las++;
        }
    }
    for (int k = i + len; k < A; k++) {
        if (a[k] == b[las]) {
            las++;
        }
    }
    if (las >= B) {
        return len;
    }
    return -1;

}

int main() {
    scanf("%s%s", a, b), A = strlen(a), B = strlen(b);
    for (int i = 0; i < A; i++) {
        for (int j = i; j < A; j++) {
            mx = max(mx, judge(i, j - i + 1));
        }
    }
    printf("%d\n", mx);
    return 0;
}


#include <iostream>
#include <cstring>

using namespace std;
const int N = 1.1e5;
int rg[N];
char s[N], t[N];
int lenS, lenT;

int main() {
#ifndef ONLINE_JUDGE
    freopen(R"(D:\L\Deal\cpp\untitled1\in.txt)", "r", stdin);
#endif

    while (cin >> s >> t) {
        lenS = strlen(s);
        lenT = strlen(t);
        for (int i = int(lenT) - 1; i >= 0; --i) {
            int pos = int(lenS) - 1;
            if (i + 1 < int(lenT)) {
                pos = rg[i + 1] - 1;
            }
            while (s[pos] != t[i]) {
                --pos;
            }
            rg[i] = pos;
        }

        int ans = 0;
        int pos = 0;
        for (int i = 0; i < int(lenS); ++i) {
            int rpos = int(lenS) - 1;
            if (pos < int(lenT)) {
                rpos = rg[pos] - 1;
            }
            ans = max(ans, rpos - i + 1);
            if (pos < int(lenT) && t[pos] == s[i]) {
                ++pos;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=2e5+10;
char a[N],b[N];
int fa[N],fb[N];
int main(){
	int tot;
	scanf("%s",a+1);
	scanf("%s",b+1);
	int aa=strlen(a+1),bb=strlen(b+1);
	tot=1;
	for(int i=1;i<=aa;i++){
		if(a[i]==b[tot]){
			fa[tot]=i;
			tot++;
		}
		if(tot>bb)break;
	}
	tot=bb;
	for(int i=aa;i>=1;i--){
		if(a[i]==b[tot]){
			fb[tot]=i;
			tot--;
		}
		if(tot<1)break;
	}
	fb[bb+1]=aa+1;
	int maxn=-1;
	for(int i=0;i<=bb;i++){
		maxn=max(maxn,fb[i+1]-fa[i]-1);
	}
	cout<<maxn<<endl;
	return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=2e5+10;
char a[N],b[N];
int fa[N],fb[N];
int main(){
	int tot;
	scanf("%s",a+1);
	scanf("%s",b+1);
	int aa=strlen(a+1),bb=strlen(b+1);
	tot=1;
	for(int i=1;i<=aa;i++){
		if(a[i]==b[tot]){
			fa[tot]=i;
			tot++;
		}
		if(tot>bb)break;
	}
	tot=bb;
	for(int i=aa;i>=1;i--){
		if(a[i]==b[tot]){
			fb[tot]=i;
			tot--;
		}
		if(tot<1)break;
	}
	fb[bb+1]=aa+1;
	int maxn=-1;
	for(int i=0;i<=bb;i++){
		maxn=max(maxn,fb[i+1]-fa[i]-1);
	}
	cout<<maxn<<endl;
	return 0;
}


#include<algorithm>
#include<iostream>
#include<string.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define bug(x) cout<<#x<<" is "<<x<<endl
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=2e5+10;
char s[N],t[N];
int vis[N],vs[N];
int main()
{
	cin>>s+1>>t+1;
	int j=1;
	int n=strlen(s+1);
	int m=strlen(t+1);
	for(int i=1;i<=n&&j<=m;++i)
    {
        if(s[i]==t[j])
        {
            vis[j]=i;++j;
        }
    }
    j=m;
    for(int i=n;i>=1&&j>=1;--i)
    {
        if(s[i]==t[j])
        {
            vs[j]=i;
            --j;
        }
    }
    int ans=max(vis[1]-1,n-vis[m]);
    ans=max(ans,vs[1]-1);
    ans=max(ans,n-vs[m]);
    for(int i=1;i<=m;++i)
    {
        ans=max(ans,vs[i]-vis[i-1]-1);
    }
    printf("%d\n",ans);
}


#define _CRT_SECURE_NO_WARNINGS
#define MAX 0
#define inf 2000000001

#define fora2(START,LIMIT,INCREASE) for (int i=START;i<LIMIT;i+=INCREASE)
#define ford2(START,LIMIT,INCREASE) for (int i=LIMIT-1;i>=START;i-=INCREASE)
#define fora(n) for (int i=0;i<n;++i)
#define ford(n) for (int i=n-1;i>=0;--i)
#define pii pair<int,int>
#define pb push_back
#define vAll(v) v.begin(), v.end()
#define mAll(m) &m[0], &m[n]

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#include <iostream>
#include <queue>
#include <unordered_set>
#include <algorithm>
#include <string>
using namespace std;

string st;
string buf;
int n;
int bn;

int func(int pos, int checker = 0) {
	if (checker == bn) {
		return (n - pos);
	}
	if (pos == n) {
		return -1;
	}

	int ans = -1;
	for (int i = pos; i < n; ++i) {
		if (st[i] == buf[checker]) {
			int newAns = func(i + 1, checker + 1);
			if (newAns >= 0) {
				newAns = max(newAns, i - pos);
				ans = max(ans, newAns);
			}
		}
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> st;
	n = st.length();
	cin >> buf;
	bn = buf.length();

	cout << func(0);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define MAX 200001
#define inf 2000000001

#define fora2(START,LIMIT,INCREASE) for (int i=START;i<LIMIT;i+=INCREASE)
#define ford2(START,LIMIT,INCREASE) for (int i=LIMIT-1;i>=START;i-=INCREASE)
#define fora(n) for (int i=0;i<n;++i)
#define ford(n) for (int i=n-1;i>=0;--i)
#define pii pair<int,int>
#define pb push_back
#define vAll(v) v.begin(), v.end()
#define mAll(m) &m[0], &m[n]

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#include <iostream>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <string>
using namespace std;

string st;
string buf;
int n;
int bn;

unordered_map <int, int> d[MAX];

int func(int pos, int checker = 0) {
	if (checker == bn) {
		return (n - pos);
	}
	if (pos == n) {
		return -1;
	}

	if (d[pos].find(checker) == d[pos].end()) {

		int ans = -1;
		for (int i = pos; i < n; ++i) {
			if (st[i] == buf[checker]) {
				int newAns = func(i + 1, checker + 1);
				if (newAns >= 0) {
					newAns = max(newAns, i - pos);
					ans = max(ans, newAns);
				}
			}
		}
		d[pos][checker] = ans;
	}
	return d[pos][checker];

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> st;
	n = st.length();
	cin >> buf;
	bn = buf.length();

	cout << func(0);
	return 0;
}