Go: ///
// File:  0528.go
// Author: ymiyamoto
//
// Created on Thu Mar 22 01:52:09 2018
//
package main

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

var S, T string
var dp [4001][4001]int

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for {
		scanner.Scan()
		S = scanner.Text()
		if len(S) == 0 {
			return
		}

		scanner.Scan()
		T = scanner.Text()

		for i := range dp {
			for j := range dp[i] {
				dp[i][j] = 0
			}
		}

		dp[0][0] = 0
		for i := range S {
			for j := range T {
				if S[i] == T[j] {
					dp[i+1][j+1] = max(dp[i+1][j], max(dp[i][j+1], dp[i][j]+1))
				} else {
					dp[i+1][j+1] = 0
				}
			}
		}
		var m int
		for i := range dp {
			for j := range dp[i] {
				m = max(m, dp[i][j])
			}
		}
		fmt.Println(m)
	}
}

Python: while True:
    stra = input()
    strb = input()
    n = len(stra)
    m = len(strb)
    mapp = [[0]*(m+1) for i in range(n+1)]
    for i in range(n):
        for j in range(m):
            if stra[i] == strb[j]:
                mapp[i+1][j+1] = mapp[i][j] + 1

    ans = 0
    for i in range(n):
        ans = max(ans,max(mapp[i]))

    print(ans)

Python: while True:
  try:
    s1 = input()
    s2 = input()
    lst = [[1 if s1[i] == s2[j] else 0 for i in range(len(s1))] for j in range(len(s2))]
    ans = 0
    def search(x,y,count):
      while  x < len(s2) and y < len(s1) and lst[x][y]:
        count += 1
        lst[x][y] = 0
        x += 1
        y += 1
      return count
    for i in range(len(s2)):
      for j in range(len(s1)):
        if lst[i][j]:
          ans = max(ans,search(i,j,0))
    print(ans)
  except EOFError:
    break

Python: while True:
    try:
        a, b = input().strip(), input().strip()
    except:
        break
    n, m = len(a), len(b)
    dp = [0] * m
    tmp_max = 0
    for i, ca in enumerate(a):
        np = [0] * m
        for j, cb in enumerate(b):
            if ca == cb:
                np[j] = dp[j - 1] + 1 if j else 1
        tmp_max = max(tmp_max, max(np))
        dp = np
    print(tmp_max)

Python: # coding: utf-8

while 1:
    try:
        a = input()
    except:
        break
    z = input()

    if len(a) > len(z):
        b = a
        a = z
    else:
        b = z

    ans = 0
    flg = 0
    for i in range(len(a) + 1, 0, -1):
        if flg == 1:
            break
        num = len(a) + 1 - i
        if num > len(a):
            break
        for ii in range(num):
            target = a[ii: i + ii]
            if target in b:
                ans = len(target)
                flg = 1
    print(ans)

Python: def solve():
  while True:
    try:
      s1 = input()
      s2 = input()
      ans = 0
      def search(x,y,count):
        while  x < len(s1) and y < len(s2) and s1[x] == s2[y]:
          count += 1
          x += 1
          y += 1
        return count

      for i in range(len(s1)):
        for j in range(len(s2)):
          if s1[i] == s2[j]:
            ans = max(ans,search(i,j,0))
      print(ans)
    except EOFError:
      break
solve()

Python: def solve():
  while True:
    try:
      s1 = input()
      s2 = input()
      end1 = len(s1)
      end2 = len(s2)
      checked = [[False for i in range(end2)] for j in range (end1)]
      dic = {}

      def check(i, j):
        count = 0
        while  i < end1 and j < end2 and (not checked[i][j]) and s1[i] == s2[j]:
          checked[i][j] = True
          i += 1
          j += 1
          count += 1
        return count

      
      for i in range(end2):
        alp = s2[i]
        if alp in dic:
          dic[alp].append(i)
        else:
          dic[alp] = [i]

      ans = 0

      for i in range(end1):
        alp = s1[i]
        if alp in dic:
          lst = dic[alp]
          for j in lst:
            if not checked[i][j]:
              a = check(i, j)
              if a > ans:
                ans = a

      print(ans)
    except EOFError:
      break
solve()

Python: def search(x,y,s1,s2,end1,end2):
  count = 0
  while  x < end1 and y < end2 and s1[x] == s2[y]:
    count += 1
    x += 1
    y += 1
  return count

def solve():
  while True:
    try:
      s1 = input()
      s2 = input()
      end1 = len(s1)
      end2 = len(s2)
      ans = 0
      for i in range(end1):
        for j in range(end2):
          if s1[i] == s2[j]:
            a = search(i,j,s1,s2,end1,end2)
            if a > ans:
              ans = a
      print(ans)
    except EOFError:
      break
solve()

Python: s1 = input()
s2 = input()
ordA = ord("a")
mod1 = 1000000007
mod2 = 2147483647

def r_hash(s):
  length = len(s)
  h_lst = [0] * length
  acc1 = acc2 = 0
  for i in range(length):
    acc1 = (acc1 * 26 + ord(s[i]) - ordA) % mod1
    acc2 = (acc2 * 26 + ord(s[i]) - ordA) % mod2
    h_lst[i] = (acc1, acc2)
  return h_lst

h_s1 = r_hash(s1)
h_s2 = r_hash(s2)

def search(length):
  hl_s1 = set()
  base1 = 26 ** length % mod1
  base2 = 26 ** length % mod2
  for i in range(len(s1) - length):
    hl_s1.add((h_s1[i + length][0] - h_s1[i][0] * base1,
               h_s1[i + length][1] - h_s1[i][1] * base2))

  for i in range(len(s2) - length):
    if (h_s2[i + length][0] - h_s2[i][0] * base1,
        h_s2[i + length][1] - h_s2[i][1] * base2) in hl_s1:
        return True
  else:
    return False

max_len = min(len(s1), len(s2))
for length in range(max_len, -1, -1):
  if search(length):
    print(length)
    break

Python: while True:
    try:
        s = "." + input()
        t = "." + input()
    except:break
    l = [[0 for _ in range(len(t))] for _ in range(len(s))]
    for i in range(1, len(s)):
        for j in range(1, len(t)):
            if s[i] == t[j]:l[i][j] = l[i - 1][j - 1] + 1
    print(max([max(i) for i in l]))

Python: def rolling_hash(S, base, MOD):
    l = len(S)
    h = [0]*(l + 1)
    for i in range(l):
        h[i+1] = (h[i] * base + ord(S[i])) % MOD
    return h


C = open(0).read().split()
MOD = 358976445361682909
base = 31
for t in range(len(C)//2):
    S = C[2*t]; T = C[2*t+1]
    rhs = rolling_hash(S, base, MOD)
    rht = rolling_hash(T, base, MOD)
    L = len(S); M = len(T)
    def solve(l):
        v = pow(base, l, MOD)
        hs = set()
        for i in range(L-l+1):
            hs.add((rhs[i+l] - rhs[i]*v) % MOD)
        for i in range(M-l+1):
            if (rht[i+l] - rht[i]*v) % MOD in hs:
                return 1
        return 0
    left = 0; right = min(L, M)+1
    while left+1 < right:
        mid = (left + right) // 2
        if solve(mid):
            left = mid
        else:
            right = mid
    print(left)

Python: while 1:
    try:s=input()
    except:break
    t=input()
    if len(s)<len(t):s,t=t,s
    a=sum(min(s.count(i),t.count(i)) for i in set(s)&set(t))
    b=0
    for x in range(len(t)):
        if len(t)-x<=b:break
        for y in range(b+1,min(a+1,len(t)-x+1)):
            if t[x:x+y] in s:b=y
            else:break
    print(b)

Python: def solve():
  while True:
    try:
      s1 = input()
      s2 = input()
      end1 = len(s1)
      end2 = len(s2)
      checked = set()
      dic = {}

      def check(i, j):
        count = 0
        while  i < end1 and j < end2 and ((i,j) not in checked) and s1[i] == s2[j]:
          checked.add((i, j))
          i += 1
          j += 1
          count += 1
        return count

      
      for i in range(end2):
        alp = s2[i]
        if alp in dic:
          dic[alp].append(i)
        else:
          dic[alp] = [i]

      ans = 0

      for i in range(end1):
        alp = s1[i]
        if alp in dic:
          lst = dic[alp]
          for j in lst:
            if not ((i, j) in checked):
              a = check(i, j)
              if a > ans:
                ans = a

      print(ans)
    except EOFError:
      break
solve()