Go: package main

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

type Position struct {
	X int
	Y int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		strX := nextText(sc)
		strY := nextText(sc)
		fmt.Println(calcLcs(strX, strY))
	}
}

func calcLcs(strX, strY string) int {
	return lcs(strX, strY, Position{0, 0}, make(map[Position]int))
}

func lcs(strX string, strY string, position Position, memo map[Position]int) int {
	if position.X >= len(strX) || position.Y >= len(strY) {
		return 0
	}
	if v, ok := memo[position]; ok {
		return v
	}
	if strX[position.X] == strY[position.Y] {
		result := lcs(strX, strY, Position{position.X + 1, position.Y + 1}, memo)
		memo[position] = result + 1
		return memo[position]
	} else {
		result1 := lcs(strX, strY, Position{position.X + 1, position.Y}, memo)
		result2 := lcs(strX, strY, Position{position.X, position.Y + 1}, memo)
		var result int
		if result1 > result2 {
			result = result1
		} else {
			result = result2
		}
		memo[position] = result
		return result
	}
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

Python: def calc(x,y):
    n = len(x)
    m = len(y)
    dp1 = [0]*(m+1)
    for i in range(n):
        s = x[i]
        dp2 = dp1[:]
        for j in range(m):
            if s == y[j]:
                dp1[j+1] = dp2[j]+1
            elif dp1[j+1] < dp1[j]:
                dp1[j+1] = dp1[j]
    return dp1[-1]

q = int(input().rstrip())
ans = []
for i in range(q):
    x = input()
    y = input()
    ans.append(calc(x,y))
print(*ans, sep="\n")

Python: import sys

n=int(input())

for _ in range(n):
	x=sys.stdin.readline().rstrip('\r\n')
	y=sys.stdin.readline().rstrip('\r\n')
	
	list=[0]
	for z in y:
		for i in range(len(list)-1,-1,-1):
			tmp=x.find(z,list[i])
			if tmp+1:
				if i+1<len(list):
					list[i+1]=min(tmp+1,list[i+1])
				else:
					list.append(tmp+1)
print(len(list)-1)

Python: a = (int)(input())
for i in range(a):
    str1 = input()
    str2 = input()
    size1 = len(str1)
    size2 = len(str2)
    dp = [[0 for j in range(size2+1)] for k in range(size1+1)]

    for j in range(1,size1+1):
        for k in range(1,size2+1):
            if str1[j-1]==str2[k-1]:
                dp[j][k] = max([dp[j-1][k],dp[j][k-1],dp[j-1][k-1]+1])
            else:
                dp[j][k] = max([dp[j-1][k],dp[j][k-1],dp[j-1][k-1]])

    print(dp[size1][size2])

Python: for _ in range(int(input())):
    a = input()
    b = input()
    if len(a) < len(b):
        a, b = b, a
    indices = []
    for cb in b:
        bgn_idx = 0
        for i, cur_idx in enumerate(indices):
            chr_idx = a.find(cb, bgn_idx) + 1
            if not chr_idx:
                break
            if chr_idx < cur_idx:
                indices[i] = chr_idx
            bgn_idx = cur_idx
        else:
            chr_idx = a.find(cb, bgn_idx) + 1
            if chr_idx:
                indices.append(chr_idx)
    print(len(indices))

Python: def find_substr(s,t):
    flag=False
    i=0
    j=0
    n=0
    while i<len(s) and j<len(t):
        if s[i] == t[j]:
            i+=1
            j+=1
            n+=1
            continue
        elif  j < len(t)-1 and s[i] == t[j+1]:
            j+=2
            i+=1
            n+=1
        elif  i < len(s)-1 and s[i+1] == t[j]:
            i+=2
            j+=1
            n+=1
        else:
            i+=1
            j+=1
    return n

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

Python: def solve(X, Y):
    X = list(X)
    Y = list(Y)
    dp = [[0 for j in range(len(Y)+1)] for i in range(len(X)+1)]
    for i in range(1,len(X)+1):
        for j in range(1,len(Y)+1):
            targetX = X[i-1]
            targetY = Y[j-1]
            if targetX == targetY:
                dp[i][j] = dp[i-1][j-1] + 1
            else:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
    return dp[len(X)][len(Y)]

num = int(input())
for i in range(num):
    X = input()
    Y = input()
    print(solve(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 = tuple([[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_recursive(A, B, m, n):
    if m == 0 or n == 0:
        return 0
    elif A[m - 1] == B[n - 1]:
        return 1 + lcs_recursive(A, B, m - 1, n - 1)
    else:
        return max(lcs_recursive(A, B, m, n - 1), lcs_recursive(A, B, m - 1, n))


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()))

    for pair in zip(word_list[::2], word_list[1::2]):
        w1, w2 = map(lambda x: x.strip(), pair)
        l1, l2 = len(w1), len(w2)
        print(w1, w2, l1, l2)
        print(lcs_recursive(w1, w2, l1, l2))

Python: e=input
for _ in[0]*int(e()):
 X,z=e(),[]
 for y in e():
  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: def calc(x,y):
    n = len(x)
    m = len(y)
    d = [[0 for _ in range(m+1)] for _ in range(n+1)]
    for i in range(n):
        s = x[i]
        for j in range(m):
            if s == y[j]:
                d[i+1][j+1] = d[i][j]+1
            else:
                d[i+1][j+1] = max(d[i+1][j],d[i][j+1])
    return d[n][m]

q = int(input())
for i in range(q):
    x = input()
    y = input()
    print(calc(x,y))

Python: # -*- coding:utf-8 -*-
import sys


def search(x, y):
    x_length = len(x)
    y_length = len(y)
    memo = [[0] * (y_length + 1) for i in range(x_length + 1)]
    for i, ch_x in enumerate(x, 1):
        row = memo[i]
        pre_row = memo[i-1]
        for j, ch_y in enumerate(y, 1):
            if ch_x == ch_y:
                row[j] = pre_row[j-1] + 1
            elif pre_row[j] < row[j-1]:
                row[j] = row[j-1]
            else:
                row[j] = pre_row[j]
    return memo[-1][-1]


if __name__ == "__main__":
    n = int(input())
    strs = [list(val) for val in sys.stdin.read().splitlines()]
    result = [search(strs[i*2], strs[i*2+1]) for i in range(n)]
    print(*result, sep="\n")

Python: MAX = 1005
n = int(input())
dp = [[0 for j in range(MAX)] for i in range(MAX)]
X = Y = ""
len_X = len_X = 0
for _ in range(n):
    X = input()
    Y = input()
    len_X = len(X)
    len_Y = len(Y)

    for i in range(len_X):
        for j in range(len_Y):
            # dp[i + 1][j + 1] = dp[i][j] + 1 if X[i] == Y[j] else max(dp[i][j + 1], dp[i + 1][j])
            if X[i] == Y[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
            else:
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
    print(dp[len_X][len_Y])

Python: q = int(input())
alphabet =[chr(ord('a') + i) for i in range(26)]

for _ in range (q):
    S1 = list(input())
    S2 = list(input())
    S1.sort()
    S2.sort()
    count = 0
    for i in alphabet:
        temp = min(S1.count(i),S2.count(i))
        if temp !=0:
            count +=temp
    print(count)