Go: package main

import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	"strings"
	"sort"
)

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = dp[i-1][j-1]+1
				} else if S[i-1] != T[j-1] && dp[i-1][j] > dp[i][j-1] {
					dp[i][j] = dp[i-1][j]
				} else {
					dp[i][j] = dp[i][j-1]
				}
				// if S[i-1] == T[j-1] {
				// 	dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				// } else {
				// 	dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				// }
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

Python: q = int(input())
alphabet =[chr(ord('a') + i) for i in range(26)]

for _ in range (q):
    S1 = list(input())
    S2 = list(input())
    S1.sort()
    S2.sort()
    count = 0
    for i in alphabet:
        temp = min(S1.count(i),S2.count(i))
        if temp !=0:
            count +=temp
    print(count)

Python: # -*- coding: utf-8 -*-


if __name__ == '__main__':

    
    def lcs(X, Y):
        m = len(X)
        n = len(Y)
        c = [[-1 for i in range(n+1)] for j in range(m+1)]
        X = " " + X
        Y = " " + Y
        for i in range(m+1):
            c[i][0] = 0
        for j in range(1, n+1):
            c[0][j] = 0
        for i  in range(1, m+1):
            for j in range(1, n+1):
                if X[i] == Y[j]:
                    c[i][j] = c[i-1][j-1] + 1
                else:
                    c[i][j] = max(c[i-1][j], c[i][j-1])
        
        return c[m][n]

    q = int(input())
    for _ in range(q):
        X = input()
        Y = input()
        print(lcs(X,Y))

Python: n=int(input())

for i in range(n):
    a=list(input())
    b=list(input())

    r=[[0 for j in range(len(b)+1)]for i in range(len(a)+1)]

    for j in range(1,len(a)+1):
        for k in range(1,len(b)+1):
            c=max(r[j-1][k-1],r[j-1][k],r[j][k-1])
            if a[j-1]==b[k-1]:
                c=max(r[j-1][k-1]+1,r[j-1][k],r[j][k-1])
            
            r[j][k]=c
            print(r[j][k],end="")
        print(" ",end="\n")
    
    print(r[len(a)][len(b)])

Python: n=int(input())

for i in range(n):
    a=list(input())
    b=list(input())
    x=len(a)+1
    y=len(b)+1

    r=[[0 for j in range(y)]for i in range(x)]

    for j in range(1,x):
        for k in range(1,y):
            if r[j-1][k]>r[j][k-1]:
                c=r[j-1][k]
            else:
                c=r[j][k-1]
            if a[j-1]==b[k-1]:
                if r[j-1][k-1]+1>c:
                    c=r[j-1][k-1]+1
            
            r[j][k]=c    
    print(r[x-1][y-1])

Python: def lcs_hs(s1, s2):
    from bisect import bisect_left

    s2, lis, result = s2[::-1], [], 0
    find, append = s2.find, lis.append

    for c in s1:
        i = find(c)+1
        while i:
            j = bisect_left(lis, -i)
            if j >= result:
                append(-i)
                result += 1
            else:
                lis[j] = -i
            i = find(c, i)+1

    return result


print(*(lcs_hs(input(), input()) for _ in [0]*int(input())), sep="\n")

Python: import sys
import functools as ft
sys.setrecursionlimit(10000)

q = int(input())
X = ""
Y = ""
memo = [[]]

def print_memo() :
    for x in range(len(X)+1):
        print(ft.reduce(lambda x,y: x + str(y) + "\t" ,memo[x], ""))

def LCS(x, y):
    if (x < 0) or (y < 0):
        return 0
    elif memo[x][y] != -1:
        return memo[x][y]
    elif X[x] == Y[y]:
        memo[x][y] =  LCS(x-1, y-1) + 1
        return memo[x][y]
    else:
        memo[x][y] = max(LCS(x-1,y), LCS(x,y-1))
        return memo[x][y]


for c in range(q):
    X = input()
    Y = input()
    len_x = len(X)
    len_y = len(Y)
    memo = [[0 for j in range(len_y+1)] for i in range(len_x+1)]

    for x in range(1, len_x+1):
        for y in range(1, len_y+1):
            memo[x][y] = max(memo[x-1][y-1] + int(X[x-1]==Y[y-1]), memo[x-1][y], memo[x][y-1])

    print(memo[len_x][len_y])
    #print_memo()

Python: def main():
    n = int(input())
    result = []
    for i in range(n):
        a = input()
        b = input()
        array = [[1 for i in range(len(b))] for j in range(len(a))]
        for i in range(1, len(a)):
            for j in range(1, len(b)):
                c = 0
                if a[i] == b[j]:
                    c = 1
                array[i][j] = max(
                                    array[i-1][j],
                                    array[i][j-1],
                                    array[i-1][j-1]+c)
        result.append(array[len(a)-1][len(b)-1])
    for i in result:
        print(i)
if __name__ == "__main__":
    main()

Python: def f(i,j):
    if i == 0 or j == 0:
        if s1[i] == s2[j]:
            x[i][j] = 1
        else:
            if i == 0:
                x[i][j] = x[i][j-1]
            else:
                x[i][j] = x[i-1][j]
    elif s1[i] == s2[j]:
        x[i][j] = max(x[i-1][j-1]+1,x[i][j-1],x[i-1][j])
    else:
        x[i][j] = max(x[i-1][j-1],x[i][j-1],x[i-1][j])

n = int(input())
for i in range(n):
    s1 = input()
    s2 = input()
    x = [[0 for j in range(len(s2))]for k in range(len(s1))]
    for j in range(len(s1)):
        for k in range(len(s2)):
            f(j,k)
            
    print(x[len(s1)-1][len(s2)-1])

Python: 
def main():
    n = int(input())
    for i in range(n):
        a = input()
        b = input()
        na=len(a)
        nb=len(b)
        array = [[0 for i in range(nb)] for j in range(na)]
        for i in range(na):
            for j in range(nb):
                if i==0:
                    if a[i]==b[j]:
                        array[i][j]=1
                elif j==0:
                    if a[i]==b[j]:
                        array[i][j]=1
                else:
                    c = 0
                    if a[i] == b[j]:
                        c = 1
                    array[i][j] = max(
                                        array[i-1][j],
                                        array[i][j-1],
                                        array[i-1][j-1]+c)
        print(array[na-1][nb-1])
if __name__ == "__main__":
    main()