Go: package main

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

func max(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

/*********************************************************************
長さmの列X_(m)と長さnの列Y_(n)の最長共通部分列LCSは、
	(1)X[m] == Y[n]ならば、X_(m-1)とY_(n-1)のLCSにX[m]を繋げたもの
	(2)X[m] != Y[n]ならば、X_(m-1)とY_(n)のLCSもしくはX_(m)とY_(n-1)のLCS
	のいずれかのうち長い方

c[m+1][n+1]：c[i][j]にX_(i)とY_(j)のLCSの長さを格納する二次元配列
*********************************************************************/

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s1 := scanner.Text()
		scanner.Scan()
		s2 := scanner.Text()
		s1, s2 = s1 + " ", s2 + " "
		c := make([][]int, len(s1))
		for i := range c {
			c[i] = make([]int, len(s2))
		}

		LCS := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					c[i][j] = c[i-1][j-1] + 1
				} else {
					c[i][j] = max(c[i-1][j], c[i][j-1])
				}
				LCS = max(LCS, c[i][j])
			}
		}
		fmt.Println(LCS)
	}
}

Python: pcsl = [[0] * 1001] * 1001

def lcs(x, y):
    m = len(x)
    n = len(y)
    for i in range(m):
        for j in range(n):
            if x[i] == y[j]:
                pcsl[i][j] = pcsl[i - 1][j - 1] + 1
            elif pcsl[i - 1][j] > pcsl[i][j - 1]:
                pcsl[i][j] = pcsl[i - 1][j]
            else:
                pcsl[i][j] = pcsl[i][j - 1]
    print(pcsl[i][j])


q = int(input())

for i in range(q):
    ax = input()
    ay = input()
    lcs(ax, ay)

Python: def num_substr(s, t):
    dp = {}
    for i in range(len(s) + 1):
        dp[i] = {0: 0}
    for j in range(len(t) + 1):
        dp[0][j] = 0
    
    for i in range(1,len(s)+1):
        Flag=False
        for j in range(1,len(t)+1):
            d=1 if s[i-1] == t[j-1] and dp[i-1][j-1] == dp[i][j-1] else 0
            dp[i][j] = max(dp[i-1][j] ,
                           dp[i][j-1] +d)
    return dp[len(s)][len(t)]

n = int(input())
for i in range(n):
    s = input()
    t = input()
    print(num_substr(s,t))

Python: # Longest Common Subsequence problem: LCS
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/10/ALDS1_10_C

import sys
input = sys.stdin.readline
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'


def get_LCS(x: str, y: str):
    lx = len(x)
    ly = len(y)
    dp = [[0] * (lx + 1) for _ in range(ly + 1)]  # 1-indexed

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

    return dp[-1][-1]


def llcs(x, y):
    """solution author: bs5lNkJ"""
    pm = dict((zip(ascii_letters, [0] * 52)))
    for c in pm:
        for i, xc in enumerate(x):
            if c == xc:
                pm[c] |= (1 << i)

    V = (1 << len(x)) - 1

    for yc in y:
        V = ((V + (V & pm[yc])) | (V & ~pm[yc]))

    ans = bin(V)[-len(x):].count('0')

    return ans


n = int(input())

for _ in range(n):
    X = input().strip()
    Y = input().strip()
    print(llcs(X, Y))

Python: for _ in[0]*int(input()):
 X,Y,z=input(),input(),[]
 for y in Y:
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 print(len(z))

Python: global memo
global ans

def judge_dup(list1,list2):#list1とlist2に共通した要素がある場合は１、ない場合は０
    tmp_list1=list(set(list1))
    tmp_list2=list(set(list2))
    judge=tmp_list1 + tmp_list2
    if(len(tmp_list1) + len(tmp_list2) == len(set(judge))):
        return 0
    else:
        return 1


def longest_common(data1,ind1,data2,ind2):
    #data1[ind1],data2[ind2]を先頭とする２つの部分文字列の最長common文字列の長さを返す
    if(len(data1) <=ind1 or len(data2) <=ind2):
        return 0
    if(memo[ind1][ind2]!=-1):
        return memo[ind1][ind2]

    tmp_data1=data1[ind1:]
    tmp_data2=data2[ind2:]
    tmp_max=0
    for i in range(len(tmp_data1)):
        x=tmp_data1[i]
        for j in range(len(tmp_data2)):
            if(x==tmp_data2[j]):
                if(judge_dup(tmp_data1[:i],tmp_data2[:j])==0):
                    #注目する文字以前に共通する文字があったら調査する意味なし
                    tmp = longest_common(data1,ind1+i+1,data2,ind2+j+1)
                    if(tmp_max < tmp +1):
                        tmp_max=tmp+1
                break
    
    memo[ind1][ind2]=tmp_max
    global ans
    if(ans < tmp_max):
        ans =tmp_max
    return tmp_max
            
    






                





n=int(input())


for loop in range(n):
    ans=0
    data1=input()
    data2=input()
    data1=list(data1)
    data2=list(data2)

    memo=[[-1]*len(data2) for i in range(len(data1))]
#memo[n][m]は、data1[n]、data2[m]それぞれを先頭とする
#部分文字列の最長common文字列の長さを格納する
    longest_common(data1,0,data2,0)
    print(ans)

Python: def longest_common(m, n):
	N = len(n)
	dp = [0]*(N+1)
	for x in m:
		dp_kari = dp[:]
		for j, y in enumerate(n):
			if x == y:
				dp[j+1] = dp_kari[j]+1
			elif dp[j+1] < dp[j]:
				dp[j+1] = dp[j]
	return dp[N]


for _ in range(int(input())):
    x = input()
    y = input()
    print(longest_common(x, y))

Python: trial = int(input())
for t in range(trial):
    first = input()
    second = input()
    dp = [[0 for n in range(len(second) + 1)] for m in range(len(first) + 1)]
    for fi in range(len(first) + 1):
        for se in range(len(second) + 1):
            if fi == 0 or se == 0:
                continue
            else:
                if first[fi-1] == second[se-1]:
                    dp[fi][se] = dp[fi-1][se-1] + 1
                else:
                    dp[fi][se] = max(dp[fi-1][se],dp[fi][se-1],dp[fi-1][se-1])
    print(dp[-1][-1])

Python: 
def LCS(x, y):
    dp = {}
    for i in range(len(x)+1):
        dp[i] = {0: 0}
    for j in range(len(y)+1):
        dp[0][j] = 0
    
    for i in range(1, len(x)+1):
        for j in range(1, len(y)+1):
            if x[i] == y[j]:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i][j-1], dp[i-1][j])
    
    return dp[len(x)][len(y)]

q = int(raw_input())
for i in range(q):
    X = raw_input()
    Y = raw_input()
    print(LCS(X, Y))

Python: def calc_lcs(X, Y):
    m = len(X)
    n = len(Y)
    c = [[0 for _ in range(n)] for i in range(m)]
    for i in range(m):
        for j in range(n):
            if X[i] == Y[j]:
                c[i][j] = c[i-1][j-1] + 1
            elif c[i-j][j] >= c[j][j-1]:
                c[i][j] = c[i - 1][j]
            else:
                c[i][j] = c[i][j -1]
    max_lcs = 0
    for row in c:
        temp = max(row)
        if temp > max_lcs:
            max_lcs = temp
    return max_lcs


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    # X = 'abcbdab'
    # Y = 'bdcaba'

    for _ in range(num):
        X = input()
        Y = input()

        # ???????????????
        result = calc_lcs(X, Y)

        # ???????????¨???
        print(result)

Python: def main():
    num = int(stdin.readline())
 
    for _ in xrange(num):
        x = stdin.readline().rstrip()
        y = stdin.readline().rstrip()
 
        n = len(y) + 1
 
        cim1 = [0] * n
        for i, xi in enumerate(x, start=1):
            ci = [0] * n
            for j, yj in enumerate(y, start=1):
                if xi == yj:
                    ci[j] = cim1[j-1] + 1
                elif cim1[j] >= ci[j-1]:
                    ci[j] = cim1[j]
                else:
                    ci[j] = ci[j-1]
            cim1 = ci