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] = 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().strip())
for q in range(Q):
    X = str(input().strip())
    Y = str(input().strip())
    lx = len(X)
    ly = len(Y)
    L = [[0 for j in range(0,ly+1)] for i in range(0,lx+1)]
    for i in range(1,lx+1):
        for j in range(1,ly+1):
            if X[i-1] == Y[j-1]:
                L[i][j] = 1 + L[i-1][j-1]
            else:
                L[i][j] = max(L[i-1][j],L[i][j-1])
    print(L[lx][ly])

Python: # Longest Common Subsequence

# 関数に入れる
def main():
    # input ← stdin.readline
    import sys
    input = sys.stdin.readline
    for _ in [0]*int(input()):
        # \n削除
        X = '_' + input()[:-1]
        Y = '_' + input()[:-1]

        lx = len(X)
        ly = len(Y)

        dp = [[0]*ly for _ in [0]*lx]

        # 変数に入れておく
        j_y = tuple(enumerate(Y))
        for i, x in enumerate(X):
            if i == 0:
                continue

            # 変数に入れておく
            dp_i = dp[i]
            dp_i1 = dp[i-1]
    
            for j, y in j_y:
                if x == y:
                    dp_i[j] = dp_i1[j-1] + 1
                else:
                    # max(a, b)を書き下す
                    a = dp_i1[j]
                    b = dp_i[j-1]
                    dp_i[j] = a if a > b else b

        print(dp[-1][-1])

if __name__ == '__main__':
    main()

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])
    i, j = 0, 0
    dp = []
    for x in range(n+1):
        dp.append([0] *(m+1))

    lcs = 0
    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])

            #if dp[j+1][i+1] > lcs:
            #   lcs = dp[j+1][i+1]
        
    #print(lcs)
    print(dp[n][m])

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

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

Python: def lcs(X, Y):
    C = []
    for y in Y:
        bgn_idx = 0
        for i, cur_idx in enumerate(C):
            chr_idx = X.find(y, bgn_idx) + 1
            if chr_idx == 0:
                break
            C[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        chr_idx = X.find(y, bgn_idx) + 1
        if chr_idx != 0:
            C.append(chr_idx)
    return len(C)

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

Python: import sys

def lcm(c,i, j):
    if c[i][j]>0: return c[i][j]        
    if i==0 or j==0:
        return 0
    elif x[i]==y[j]:
        c[i][j] = lcm(c,i-1,j-1)+1
        return c[i][j]
    else:
        c[i][j] = max(lcm(c,i,j-1), lcm(c,i-1,j))
        return c[i][j]

for _ in range(int(sys.stdin.readline())):
    x = sys.stdin.readline()
    y = sys.stdin.readline()
    c = [[0 for _ in range(len(x)+2)] for _ in range(len(y)+2)] 
    print(lcm(c,len(x)-1,len(y)-1))

Python: ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

def llcs(x, y):
    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

from sys import stdin

def solve():
    #file_input = stdin
    file_input = open("ALDS1_10_C_in_4", 'r')
    q = int(file_input.readline())
    for i in range(q):
        s1 = file_input.readline().rstrip()
        s2 = file_input.readline().rstrip()
        print(llcs(s1, s2))

solve()

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-1] == y[j-1]:
                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: n=int(input())
x=[]
y=[]
for k in range(n):
	dp=[[0 for i in range(1000)] for j in range(1000)]
	x=list(input())
	y=list(input())
	for i in range(len(x)):
		for j in range(len(y)):
			
			if i is 0:
				if x[i] is y[j]:
					dp[i][j]=1
				else:
					dp[i][j]=dp[i][j-1]
			if j is 0:
				if x[i] is y[j]:
					dp[i][j]=1
				else:
					dp[i][j]=dp[i-1][j]

	for i in range(len(x)):
		tmp=0
		for j in range(len(y)):
			if i is not 0 and j is not 0:
				if x[i] is y[j] and tmp is 0:
					dp[i][j]=max(dp[i][j-1],dp[i-1][j])+1
					tmp+=1
				else:
					dp[i][j]=max(dp[i][j-1],dp[i-1][j])

	print(dp[len(x)-1][len(y)-1])
#	print(x,y)
#	for i in range(7):
#		print(dp[i])