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: # coding: utf-8

while True:
    try:
        a = input()
        z = input()
    except EOFError:
        break

    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: # coding:utf-8
from __future__ import division, print_function
try:
    input = raw_input
    range = xrange
except NameError:
    pass

p, q = 10 ** 9 + 7, 0xffffffff
pow_p = [1]
for i in range(4010):
    pow_p.append(pow_p[-1] * p & q)


def exists(a, b, k):
    n, m = len(a), len(b)

    s = [a[k + i] - a[i] * pow_p[k] & q for i in range(n - k)]
    t = [b[k + i] - b[i] * pow_p[k] & q for i in range(m - k)]
    return len(set(s).intersection(set(t))) > 0


def hash(s):
    t = 0
    yield t
    for c in s:
        t = t * p + ord(c) & q
        yield t
    return


def solve(s, t):
    n, m = len(s), len(t)
    a, b = list(hash(s)), list(hash(t))

    l, r = 0, min(n, m) + 1
    while l + 1 < r:
        m = (l + r) // 2
        if exists(a, b, m):
            l = m
        else:
            r = m
    return l


while True:
    try:
        s = input().strip()
        t = input().strip()
    except EOFError:
        break

    print(solve(s, t))

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,s2;
  while(cin >> s >> s2){
    ll ans = 0;
    rep(i,s.size()){
      ll len = 1;
      for(int j = 0; j < s2.size();++j){
        if(s[i+len] == s2[j]){
          len++;
          ans = max(len,ans);
          if(i+len >= s.size() || j+len >= s2.size()) break;
        }
        else{
          len = 1;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	while (true){
		string s, t;
		cin >> s;
		if (!s.size()) break;
		cin >> t;
		int dp[4001][4001] = { 0 }, mx = 0;
		for (int i = 1; i <= s.size(); i++){
			for (int j = 1; j <= t.size(); j++){
				if (s[i] == t[j]){
					dp[i][j] = dp[i - 1][j - 1] + 1;
					mx = max(mx, dp[i][j]);
				}
			}
		}
		cout << mx << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <string>

using namespace std;


int cmp(char* a,int al,char* b,int bl,int n){
	int i = n > 0 ? n : 0;
	int max = 0;
	int s = 0;
	bool f = false;
	for(;i < al && i < bl + n;i++){
		if(a[i] == b[i - n]){
			//("HIT:%c a[%d]==b[%d]\n",a[i],i,i-n);
			if(f){
				s++;
			}else{
				f = true;
				s++;
			}
		}else if(f){
			if(max < s){ max = s; }
			s = 0;
		}
	}
	if(f){
		if(max < s){max = s;}
	}
	//printf("%d -> %d\n",n,max);
	return max;
}

int main(){
	char aa[4096];
	char bb[4096];
	char ss[4096];
	char *a,*b;
	//printf("%d\n",cmp(a,5,b,5,0));
	int al,bl;
	int max;
	int s;
	while(scanf("%s %s",aa,bb) != EOF){
		al = sprintf(ss,"%s",aa);
		bl = sprintf(ss,"%s",bb);
		max = 0;
		a = aa;
		b = bb;
		for(int i = 1 - bl;i < al;i++){
			s = cmp(a,al,b,bl,i);
			if(s > max){
				max = s;
			}
		}
		b = aa;
		a = bb;
		for(int i = 1 - al;i < bl;i++){
			s = cmp(a,bl,b,al,i);
			if(s > max){
				max = s;
			}
		}
		printf("%d\n",max);
	}
}

C++: //36
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  for(string s,ss;cin>>s>>ss;){
    static int dp[4001][4001];
    for(int i=0;i<4001;i++){
      dp[0][i]=dp[i][0]=0;
    }
    int ans=0;
    for(int y=1;y<=ss.size();y++){
      for(int x=1;x<=s.size();x++){
	dp[y][x]=((ss[y-1]==s[x-1])?dp[y-1][x-1]+1:0);
	ans=max(ans,dp[y][x]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;

char sa[4004], sb[4004];
int dp[4001], mm;

void search(){
    mm = 0;
    for(int z = 0; z < 4000; z++){
        dp[z] = 0;
        if( sb[z] ) dp[z] = (sa[0] == sb[z]);
    }
    int xlim = 0, ylim = 0;
    while( sa[xlim] || sb[ylim] ){
        if( sa[xlim] ) xlim++;
        if( sb[ylim] ) ylim++;
    }
    xlim--; ylim--;
    for(int x = 0; x < xlim; x++){
        for(int y = ylim - 1; y >= 0; y--){
            dp[y+1] = (sa[x+1] == sb[y+1]) ? dp[y] + 1 : 0;
            if( dp[y+1] > mm ) mm = dp[y+1];
        }
    }
    cout << mm << endl;
}

int main(){
    while( cin >> sa >> sb ){
        search();
    }
    return 0;
}

C++: #include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    string s,t;
    while(cin>>s>>t){
        int dp[2][4100] = {};
        int ans = 0;
        for(int i = 0;i < s.length();i++){
            for(int j = 0;j < t.length();j++){
                if(s[i] == t[j]){
                    if(i == 0 || j == 0){
                        dp[i%2][j] = 1;
                    }
                    else{
                        dp[i%2][j] = dp[(i+1)%2][j-1] + 1;
                    }
                    ans = max(ans,dp[i%2][j]);
                }
            }
            for(int j = 0;j < t.length();j++){
                dp[(i+1)%2][j] = 0;
            }
        }
        cout<<ans<<endl;
    }


    return 0;
}