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

// The main method must be in a class named "Main".
class Main {
    public static int lcs(String s, String t, int i, int j){
        if(i==s.length() || j==t.length())
            return 0;

        if(s.charAt(i)==t.charAt(j))
            return 1+lcs(s,t,i+1,j+1);
        else
            return Math.max(lcs(s,t,i+1,j),lcs(s,t,i,j+1));
    }
    
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        String t=new StringBuilder(s).reverse().toString();
        System.out.println(lcs(s,t,0,0));
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: