Go: package main

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

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

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: 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 lcs(s1, s2):
    if len(s1) < len(s2):
      s1, s2 = s2, s1
    dp = []
    for s2_k in s2:
        #print(dp)
        bgn_idx = 0
        for i, cur_idx in enumerate(dp):#要素とそのindexを取得
            #s2_kをs1のbgn_idx番目以降から探す
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            #print(s2_k, i, cur_idx, chr_idx, dp)
            if not chr_idx:#0だったらTrue#findは見つからないとき - 1を返す
                break
            dp[i] = min(cur_idx, chr_idx)
            #print(dp)
            bgn_idx = cur_idx
            
        else:#breakされなければ読み込まれる。
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if chr_idx:#0だったらfalse
                dp.append(chr_idx)
            #print(dp)    
             
    return len(dp)


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

Python: 



def lsc(str1,str2):
    table1=[0]*(len(str2)+1)
    for i in range(len(str1)):
       table2=table1[:]
       for j in range(len(str2)):
            if(str1[i] == str2[j]):
               table1[j+1] = table2[j] +1
            else:
                if(table1[j+1] < table1[j]):
                    table1[j+1]=table1[j]
    return table1[-1]




n=int(input())

for loop in range(n):
    str1=input()
    str2=input()
    print(lsc(str1,str2))

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 len_LCS(X,Y):
    x_l = len(X)
    y_l = len(Y)
    lcs = [[0 for _ in range(x_l+1)] for _ in range(y_l+1)]
    for j in range(y_l):
        for i in range(x_l):
            if Y[j] == X[i]:
                lcs[j+1][i+1] = lcs[j][i] + 1
            else:
                lcs[j+1][i+1] = lcs[j+1][i] if lcs[j+1][i] > lcs[j][i+1] else lcs[j][i+1]
    return lcs[-1][-1]

if __name__=='__main__':
    q = int(input())
    for _ in range(q):
        X = input()
        Y = input()
        print(len_LCS(X,Y))

Python: from sys import stdin

X = [ 0 for i in range(1000) ]
Y = [ 0 for i in range(1000) ]


def getLCS() :
	xlen = len(X[l])
	ylen = len(Y[l])
	Z = [[0 for i in range(xlen+2)]for i in range(ylen+2)]

	for i in range(1,xlen+1) :
		for j in range(1,ylen+1) :
			if X[i-1] == Y[j-1] : Z[i][j] = Z[i-1][j-1] + 1
			elif Z[i-1][j] >= Z[i][j-1] : Z[i][j] = Z[i-1][j]
			else : Z[i][j] = Z[i][j-1]

	return Z[xlen][ylen]

n = int(input())
for l in range(n) :
	X[l] = stdin.readline().strip()
	Y[l] = stdin.readline().strip()
	print(getLCS())

Python: import sys
def lcs(X, Y):
    m = len(X)
    n = len(Y)
    # c = [[0 for i in range(n+1)] for i in range(m+1)]
    c = [None]*(m+1)
    for i in range(m+1):
        c[i] = [0]*(n+1)
    for i in range(1,m+1):
        for j in range(1,n+1):
            if X[i -1] == Y[j - 1]:
                c[i][j] = c[i-1][j-1] + 1
            elif c[i -1][j] >= c[i][j - 1]:
                c[i][j] = c[i-1][j]
            else:
                c[i][j] = c[i][j-1]
    return str(c[m][n])

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

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3
abcbdab
bdcaba
abc
abc
abc
bc

output:
4
3
2

"""
import sys


def lcs(A, B):
    m, n = len(A), len(B)
    count_list = [[0] * (n + 1) for _ in range(m + 1)]

    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if A[i - 1] == B[j - 1]:
                count_list[i][j] = count_list[i - 1][j - 1] + 1
            else:
                count_list[i][j] = max(count_list[i - 1][j], count_list[i][j - 1])

    return count_list[m][n]


# def lcs_better(A, B):
#     cost_history = [None]
#     for ele in B:
#         for index in range(len(cost_history) - 1, -1, -1):
#             # ???????¬??????°????????????????§???¨A??\?????°??????(ele), ????????°?????????
#             found = A.find(ele, cost_history[index])
#             if found != -1:
#                 if index + 1 < len(cost_history):
#                     cost_history[index + 1] = min(cost_history[index + 1], found + 1)
#                 # ??¨???????????°?????¢?????°?????¶?????°????????´???
#                 else:
#                     assert index + 1 == len(cost_history)
#                     cost_history.append(found + 1)
# 
#     return len(cost_history) - 1


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    pair_num = int(_input[0])

    word_list = _input[1:]
    # assert len(word_list) == 2 * pair_num
    for k in range(0, len(word_list), 2):
        print(lcs(word_list[k].strip(), word_list[k + 1].strip()))

Python: q = int(input())

l = []
x = ""
y = ""

for i in range(q):
    x = input()
    y = input()
 
    yLen = len(y)
    xLen = len(x)
    l = [[0] * xLen for j in range(yLen)]

    for j in range(yLen):
        for k in range(xLen):
            if k == 0 and j == 0:
                if x[k] == y[j]:
                    l[j][k] = 1
                else:
                    l[j][k] = 0
            elif k == 0:
                if x[k] == y[j]:
                    l[j][k] = 1
                else:
                    l[j][k] = l[j - 1][k]
            elif j == 0:
                if x[k] == y[j]:
                    l[j][k] = 1
                else:
                    l[j][k] = l[j][k - 1]
            elif x[k] == y[j]:
                l[j][k] = 1 + l[j - 1][k - 1]
            else:
                if l[j][k - 1] > l[j - 1][k]:
                    l[j][k] = l[j][k - 1]
                else:
                    l[j][k] = l[j - 1][k]
 
    print(l[yLen- 1][xLen - 1])

Python: n=int(input())
ans=[]
for k in range(n):
    s1=input()
    s2=input()
    dp=[[0 for i in range(len(s2)+1)] for j in range(len(s1)+1)]
    for i in range(1,len(s1)+1):
        for j in range(1,len(s2)+1):
            if s1[i-1]==s2[j-1]:
                dp[i][j]=dp[i-1][j-1]+1
            else:
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])


    ans.append(dp[len(s1+1)][len(s2+1)])
for a in ans:
    print(a)