Go: package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

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

Python: import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


def lcs(s1, s2):##
	dp = []
	for s2_k in s2:
		bgn_idx = 0
		for i, cur_idx in enumerate(dp):
			chr_idx = s1.find(s2_k, bgn_idx) + 1
			if not chr_idx:
				break
			dp[i] = min(cur_idx, chr_idx)
			bgn_idx = cur_idx
		else:
			chr_idx = s1.find(s2_k, bgn_idx) + 1
			if chr_idx:
				dp.append(chr_idx)
	return len(dp)

q = INT()

for _ in range(q):
	S = input()
	T = input()
	print(lcs(S, T))

Python: import sys

c = [[0 for _ in range(1001)] for _ in range(1001)]
for _ in range(int(sys.stdin.readline())):
    x = sys.stdin.readline().rstrip()
    y = sys.stdin.readline().rstrip()
    c[0][0]=0
    for i,xi in enumerate(x):
        for j,yj in enumerate(y):
            if xi==yj:
                c[i+1][j+1] = c[i][j]+1
            elif c[i][j+1] > c[i+1][j]:
                c[i+1][j+1] = c[i][j+1]
            else:
                c[i+1][j+1] = c[i+1][j]
            
    print(c[len(x)][len(y)])

Python: # ライブラリのインポート
#import re #正規表現
import sys
#import heapq
#import collections
#import math

def main():
    q = int(input())
    STR = [str.strip("\n") for str in sys.stdin]
    for i in range(q):
        x = STR[2*i]
        y = STR[2*i+1]
        print(lcs(x,y))


def lcs(x, y):
    dp = []
    for y_k in y:
        ps = 0
        for i, pdp in enumerate(dp):
            p = x.find(y_k, ps) + 1 #.find method returns -1 if there is no element
            if not p: break
            dp[i] = min(p,pdp)
            ps = pdp
        else: #else block is executed when for block has done completedly
            p = x.find(y_k, ps) + 1
            if p: dp.append(p)
    return len(dp)


if __name__ == '__main__':
    main()

Python: n = int(input())
for i in range(n):
    a = input()
    b = input()
    L = [[0 for j  in range(len(a) + 1)] for k in range(len(b) + 1)]
    for  m in range(1, len(a) + 1):
        for n in range(1, len(b) + 1):
            if a[m-1] == b[n-1]:
                L[n][m] = L[n-1][m-1] + 1
            else:
                L[n][m] = max(L[n-1][m], L[n][m-1])
    print(L[-1][-1])