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

C++: //Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int dp[4005][4005];
char a[4005],b[4005];
int main()
{
	while(scanf("%s %s",&a,&b)!=EOF)
	{
		memset(dp,0,sizeof(0));
		
		int as=strlen(a); int bs=strlen(b);
		int ret=0;
		for(int i=1;i<=as;i++)
		{
			for(int j=1;j<=bs;j++)
			{
				if(a[i-1]==b[j-1]) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
				else dp[i][j]=0;
				ret=max(ret,dp[i][j]);
			}
			
		}
		printf("%d\n",ret);
	}
	
}

C++: #include <bits/stdc++.h>
using namespace std;
// #define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

string s, t;
int n, m;
int dp[4000][4000];

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    while (cin >> s >> t) {
        n = s.size(); m = t.size();
        int ans = 0;
        rep(i, n) {
            rep(j, m) {
                if (s[i] == t[j]) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                    chmax(ans, dp[i + 1][j + 1]);
                }
                else {
                    dp[i][j] = 0;
                }
            }
        }
        cout << ans << endl;
    }
}

C++: #include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string s1, s2;

int main()
{
	while (cin >> s1 >> s2) {
		set<string> s;
		string s3;

		for (int i = 0; i < s1.size(); i++) {
			for (int j = i; j < s1.size(); j++) {
				for (int k = i; k < j + 1; k++) {
					s3 += s1[k];
				}
				s.insert(s3);
				s3 = "";
			}
		}
		int ans = 0;
		for (auto itr = s.begin(); itr != s.end(); ++itr) {
			int pos = s2.find(*itr);
			string s3 = *itr;
			int si = s3.size();
			if (pos != -1)ans = max(ans,si);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
std::map<std::string,int>mp;
int main(){
    std::string s;
    std::string b;
    
    while(std::cin>>s>>b){
        mp.clear();
        if(b.size()>s.size())std::swap(s,b);
        for(int i=0;i<s.size();i++){
            for(int j=i+1; j<s.size();j++){
                std::string temp=s.substr(i,j-i);
                mp[temp]=1;
            }
        }
        int ans=0;
        for(int i=0;i<b.size();i++){
            for(int j=i+1; j<b.size();j++){
                std::string comp=b.substr(i,j-i);
                if(mp[comp])ans=std::max(ans,(int)comp.size());
            }
        }
        std::cout<<ans<<std::endl;
    }
}

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

int dp[4001][4001];

int main(){
	char str1[4001],str2[4001];
	while(cin>>str1>>str2){
		int ans=0;
		memset(dp,0,sizeof(dp));
		for(int i=0;str1[i]!='\0';i++){
			for(int j=0;str2[j]!='\0';j++){
				if(str1[i]==str2[j]){
					dp[i+1][j+1]=dp[i][j]+1;
				}
				if(ans<dp[i+1][j+1]){
					ans=dp[i+1][j+1];
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}