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] = 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: from collections import deque

class Tree:
    def __init__(self):
        self._root = {}
        self._tmp = None

    def add(self, segment):
        node = self._root
        tmp = 0
        for s in segment:
            key = s
            if not key in node:
                node[key] = {}
            node = node[key]
            tmp += 1
        node["total"] = tmp

    def match(self, _input):
        res = self._match(_input, self._root)
        return res

    def _match(self, segment, root):
        if len(segment) == 0:
            self._tmp = root.get("total", 0)
            return self._tmp

        first, rest = segment[0], segment[1:]
        if first in root:
            self._tmp = self._match(rest, root[first])
            if self._tmp is not None:
                return self._tmp
        return 0

while True:
    try:
        a = input()
        b = input()
    except:
        break
    t = Tree()
    candidates = deque([0])
    segments = [a[i:] for i in range(len(a))]
    ngs_a = deque()
    for a in segments:
        while len(a) > 0:
            if a not in ngs_a:
                t.add(a)
                ngs_a.append(a)
            a = a[:-1]
    segments = [b[i:] for i in range(len(b))]
    for b in segments:
        while len(b) > 0:
            tmp = t.match(b)
            if tmp:
                candidates.append(tmp)
            b = b[:-1]
    print(max(set(candidates)))

Python: # coding: utf-8

while True:
    a = input()
    if a == "EOF":
        break
    else:
        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: while True:
    try:
        s1 = input()
    except EOFError:
        break
    s2 = input()
    BASE = 27
    MOD = 1000000007


    def rolling_hash(s):
        h_lst = [0]
        for c in s:
            h_lst.append((h_lst[-1] * BASE + ord(c)) % MOD)
        return h_lst


    h_lst1 = rolling_hash(s1)
    h_lst2 = rolling_hash(s2)
    length1 = len(s1)
    length2 = len(s2)

    pow_mem = [pow(BASE, i, MOD) for i in range(min(length1, length2) + 1)]


    def check(center):
        hash_set = {(h_lst1[i + center] - h_lst1[i] * pow_mem[center]) % MOD for i in range(length1 - center + 1)}
        for i in range(length2 - center + 1):
            h2 = (h_lst2[i + center] - h_lst2[i] * pow_mem[center]) % MOD
            if h2 in hash_set:return True
        return False


    left = 0
    right = min(length1, length2)
    while right > left + 1:
        center = (left + right) // 2
        if check(center):
            left = center
        else:
            right = center
    print(right if check(right) else left)

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)
      dic = dict()
      for i in range(end2):
        alp = s2[i]
        if not alp in dic:
          dic[alp] = [i]
        else:
          dic[alp].append(i)
      ans = 0
      for i in range(end1):
        alp = s1[i]
        if alp in dic:
          for ind in dic[alp]:
            a = search(i, ind, s1, s2, end1, end2)
            if ans < a:
              ans = a
      print(ans)
    except EOFError:
      break
solve()

Python: class RollingHash:
    def __init__(self, s, base, MOD):
        self.s = s
        self.l = l = len(s)
        self.base = base
        self.MOD = MOD
        self.h = h = [0]*(l + 1)
        for i in range(l):
            h[i+1] = (h[i] * base + ord(s[i])) % MOD
    def get(self, l, r):
        MOD = self.MOD
        return ((self.h[r] - self.h[l]*pow(self.base, r-l, MOD) + MOD)) % MOD

C = open(0).read().split()
MOD = 563980774085007485
for t in range(len(C)//2):
    S = C[2*t]; T = C[2*t+1]
    rhs = RollingHash(S, 31, MOD)
    rht = RollingHash(T, 31, MOD)
    L = len(S)
    hs = [set() for i in range(L+1)]
    for l in range(1, L+1):
        hsl = hs[l]
        for i in range(L-l+1):
            hsl.add(rhs.get(i, i+l))
    ans = 0
    M = len(T)
    for l in range(L, 0, -1):
        hsl = hs[l]
        for i in range(M-l+1):
            if rht.get(i, i+l) in hsl:
                break
        else:
            continue
        ans = l
        break
    print(ans)

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

Python: import difflib

while True:
    try:
        a, b = input().strip(), input().strip()
    except:
        break
    sm = difflib.SequenceMatcher(a=a, b=b, autojunk=False)
    print(sm.find_longest_match(0, len(a), 0, len(b)).size)

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

      def check(i, j):
        count = 0
        while not checked[i][j] and i < end1 and j < end2 and s1[i] == s2[j]:
          checked[i][j] = 1
          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()

Python: import difflib

while True:
    try:
        a, b = input().strip(), input().strip()
    except:
        break
    sm = difflib.SequenceMatcher(a=a, b=b)
    print(sm.find_longest_match(0, len(a), 0, len(b)).size)