Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

Python: def LCS(S, T):
    LS = len(S); LT = len(T)
    if LT > LS:
        S, T = T, S
        LS, LT = LT, LS
    dp = [0] * (LT + 1)
    for s in S:
        dp_pre=dp[:]
        for j, t in enumerate(T):
            if s == t:
                dp[j + 1] = dp_pre[j] + 1
            elif dp[j + 1] < dp[j]:
                dp[j + 1] = dp[j]
    return dp[-1]

for _ in range(int(input())):
    print(LCS(input(), input()))

Python: def L(str1,str2):
    A = [0 for _ in range(len(str2)+1)]
    for char1 in str1:
        A_copy = A[:]
        for j,char2 in enumerate(str2):
            if(char1==char2):
                A[j+1] = A_copy[j]+1
            elif(A[j] > A[j+1]):
                A[j+1] = A[j]
    return A[-1]


m = int(input())
for i in range(m):
    str1 = input()
    str2 = input()
    print(L(str1,str2))

Python: q=int(input())
for i in range(q):
    s1=input()
    s2=input()
    ls1=len(s1)
    ls2=len(s2)
    f=[[0 for k in range(ls2+1)] for j in range(ls1+1)]
    for j in range(1,ls1+1):
        for k in range(1,ls2+1):
            if s1[j-1]==s2[k-1]:
                f[j][k]=f[j-1][k-1]+1
            else:
                f[j][k]=max(f[j-1][k],f[j][k-1])
    print(f[j][k])

Python: num = int(input())
for i in range(num):
    X = " " + input()
    Y = " " + input()
    lx = len(X)
    ly = len(Y)
    T = [0] * ly
    for j in range(1,lx):
        C = T[:]
        for k in range(1,ly):
            k1 = k-1
            if X[j] == Y[k]:
                T[k] = C[k1] + 1
            elif C[k] > T[k1]:
                T[k] = C[k]
            else:
                T[k] = T[k1]
        print(T[k])

Python: def lcs(X,Y,p,q,Z):
    for i in range(len(X)):
        for j in range(len(Y)):
            if X[i]==Y[j]:
                Z[i+1][j+1]=Z[i][j]+1
            else:
                if Z[i][j+1]>Z[i+1][j]:
                    Z[i+1][j+1]=Z[i][j+1]
                else:
                    Z[i+1][j+1]=Z[i+1][j]
    print(Z[p][q])

n=int(input())
for i in range(n):
    X=input()
    Y=input()
    p=len(X)
    q=len(Y)
    Z=[[0 for i in range(q+1)]for j in range(p+1)]
    lcs(X,Y,p,q,Z)

Python: q = int(input())
t = []
for i in range(q):
    X = input()
    Y = input()
    m = len(X)
    n = len(Y)
    c1 = [0] * (n + 1)
    for i in range(m):
        d = X[i]
        c2 = c1[:]
        for j in range(n):
            if (d == Y[j]):
                c1[j + 1] = c2[j] + 1
            elif (c1[j + 1] < c1[j]):
                c1[j + 1] = c1[j]
    return (c1[-1])
    print(Ics(s1, s2))

Python: n = int(input())
dataset = []
for i in range(n):
    tmp = []
    tmp.append(input())
    tmp.append(input())
    dataset.append(tmp)
 
for data in dataset:
    m = len(data[0])
    n = len(data[1])
    dp = []
    for x in range(n+1):
        dp.append([0] *(m+1))
 
    for j in range(n):
        for i in range(m):
            if data[0][i] == data[1][j]:
                dp[j+1][i+1] = dp[j][i] + 1
            else:
                #dp[j+1][i+1] = max(dp[j+1][i], dp[j][i+1])
                dp[j+1][i+1] = dp[j+1][i] if dp[j+1][i]>dp[j][i+1] else dp[j][i+1]
    print(dp[n][m])

Python: def lcs1d(X,Y):
    lx = len(X)
    ly = len(Y)
    T = [0] * ly
    for j in range(1,lx):
        C = T[:]
        for k in range(1,ly):
            k1 = k-1
            if X[j] == Y[k]:
                T[k] = C[k1] + 1
            elif C[k] > T[k1]:
                T[k] = C[k]
            else:
                T[k] = T[k1]
    return T[k]

def main():
    """ ????????? """
    num = int(input())
    for i in range(num):
        X = " " + input()
        Y = " " + input()
        max = lcs1d(X,Y)
        print(max)

if __name__ == '__main__':
    main()

Python: #JOI
def main():
    X=input()
    Y=input()
    dp=[[0 for y in range(1+len(Y))] for x in range(1+len(X))]
    for x in range(len(X)):
        for y in range(len(Y)):
            now=0
            dp[x][y]=max(dp[x-1][y],dp[x][y-1])
            for x1 in range(Y[:y+1].count(X[x])):
                idx=Y[now:y+1].index(X[x])
                now=idx+1
                dp[x][y]=max(dp[x-1][idx-1]+1,dp[x][y])
            now=0
            for y1 in range(X[:x+1].count(Y[y])):
                idx=X[now:x+1].index(Y[y])
                now=idx+1
                dp[x][y]=max(dp[idx-1][y-1]+1,dp[x][y])
    print(dp[len(X)-1][len(Y)-1])
for i in range(int(input())):
    main()

Python: n = int(input())
for _ in range(n):
    a, b = input(), input()
    i, j = len(a), len(b)
    prev = [0] * (j + 1)
    for ca in a:
        cur = [0] * (j + 1)
        cl = -1
        for l, cb in enumerate(b):
            if ca == cb:
                cur[l + 1] = cl = prev[l] + 1
            else:
                cur[l + 1] = cl = max(cl, prev[l + 1])
        prev = cur
    print(prev[-1])

Python: import sys

def solve():
    q = int(sys.stdin.readline())

    for qi in range(q):
        x = sys.stdin.readline().rstrip()
        y = sys.stdin.readline().rstrip()

        ans = compute_lcs(x, y)

        print(ans)

def compute_lcs(x, y):
    n = len(x)
    m = len(y)

    x = '#' + x
    y = '#' + y

    dp = [[0]*(m + 1) for i in range(n + 1)]

    for i in range(1, n + 1):
        for j in range(1, m + 1):
            if x[i] == y[j]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])

    return dp[n][m]

if __name__ == '__main__':
    solve()

Python: q = int(input())

for _ in range(q):
    x = input()
    y = input()
    dp = [[0 for j in range(len(y)+1)] for i in range(len(x)+1)]
    for i in range(len(x)):
        for j in range(len(y)):
            if x[i] == y[j]:
                dp[i+1][j+1] = max(dp[i][j]+1, dp[i+1][j], dp[i][j+1])
            else:
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
    print(dp[len(x)][len(y)])

Python: #dj 16D8101012J ito jun
def search(a,b):
    na=len(a)
    nb=len(b)
    array = [[0]*(nb+1) for _ in range(na+1)]
    for i,x in enumerate(a,1):
        prerow=array[i-1]
        row=array[i]
        for j,y in enumerate(b,1):
            if x == y:
                row[j]=prerow[j-1]+1
            elif prerow[j] < row[j-1]+1:
                row[j] = row[j-1]
            else:
                row[j] = prerow[j]
    return array[-1][-1]

n = int(input())
strs = [list(i) for i in input()]
result = [search(strs[i*2], strs[i*2+1]) for i in range(n)]
print(*result, sep="\n")