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

C++: char s[4005],t[4005];u[4005],m,i,j,c,d;main(n){for(;d=~scanf("%s%s",s,t);i=m=!printf("%d\n",m))for(n=strlen(s);d;d=t[i++])for(j=n;j--;m<c?m=c:0)u[j+1]=c=s[j]-d?0:u[j]+1;}

C++: #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAX = 4001;

int dp[MAX][MAX];

int main(){
  string a,b;

  while(cin >> a >> b){
    int n = a.size(), m = b.size();
    int ans = 0;    

    memset(dp,0,sizeof(dp));

    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < m ; j++){
	if(a[i] == b[j]){
	  dp[i+1][j+1] = dp[i][j] + 1;
	}
	ans = max(ans,dp[i+1][j+1]);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
vector<string> V1,V2;
string s1,s2;

ll jud(ll x1,ll x2){
	if(x1>=s1.size()||x2>=s2.size()) return 0;
	ll res=0;
	while(res<min(V1[x1].size(),V2[x2].size())&&V1[x1][res]==V2[x2][res]){
		res++;
	}
	return res;
}

int main()
{
	while(cin>>s1>>s2){
	V1.clear();
	V2.clear();
	ll ans=0;
	for(ll i=0;i<s1.size();i++){
		V1.push_back(s1.substr(i));
	}
	for(ll i=0;i<s2.size();i++){
		V2.push_back(s2.substr(i));
	}
	sort(V1.begin(),V1.end());
	sort(V2.begin(),V2.end());
	for(ll i=0;i<V1.size();i++){
		ans=max(ans,jud(i,lower_bound(V2.begin(),V2.end(),V1[i])-V2.begin()));
	}
	for(ll i=0;i<s2.size();i++){
		ans=max(ans,jud(lower_bound(V1.begin(),V1.end(),V2[i])-V1.begin(),i));
	}
	cout<<ans<<endl;
}}

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

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }

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

	for(string a, b; cin >> a;) {
		cin >> b;

		vector<vector<int> > dp(a.size() + 1, vector<int>(b.size() + 1, 0));
		for(int i = 0; i < a.size(); ++i)
			for(int j = 0; j < b.size(); ++j)
				if(a[i] == b[j])
					chmax(dp[i + 1][j + 1], dp[i][j] + 1);

		int ans = 0;
		for(int i = 0; i < dp.size(); ++i)
			chmax(ans, *max_element(dp[i].begin(), dp[i].end()));

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)

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

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s, t; int roop1, roop2 = 0, save, ans = 0;
int main() {
    while(cin >> s >> t){
    	roop2=0;
    	ans=0;
    for (int i = 0; i<s.size(); i++){
        for (int j = 0; j<t.size(); j++){
            if (s[i] == t[j]){
                roop1 = 1;
                save = 1;
                while (1){
                    if (s[i + roop1] == 0|| t[j + roop1] ==0){
                        break;
                    }
                    else{
                    if (s[i + roop1] == t[j + roop1]){
                            save += 1;
                            roop1++;
                        }
                        else if (s[i + roop1] != t[j + roop1]){
                            break;
                        }
                    }
                }
                ans=max(ans,save);
            }
        }
    }
    cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <string.h>
#include <algorithm>

using namespace std;

int dp[4001][4001];

void solve()
{
	string a, b;
	while (cin >> a)
	{
		cin >> b;
		memset(dp, 0, sizeof(dp));
		int ans = 0;
		for (int i = 0; i < a.size(); ++i)
		{
			for (int j = 0; j < b.size(); ++j)
			{
				if (a[i] == b[j])
				{
					dp[i + 1][j + 1] = dp[i][j] + 1;
					ans = max(ans, dp[i + 1][j + 1]);
				}
				else
				{
					dp[i + 1][j + 1] = 0;
				}
			}
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

char com[4003];

int main(){
	char s1[4003],s2[4003];
	
	while(1<scanf("%s %s",s1,s2)){
		int maxcom=0;
		
		for(int i=0;i<strlen(s1)+strlen(s2);i++){
			int is1,is2;
			if(i<strlen(s1)){
				is1=i;
				is2=0;
			}else{
				is1=0;
				is2=strlen(s1)+strlen(s2)-i;
			}
			int tmax=0;
			for(int k=0;is1+k<strlen(s1) && is2+k<strlen(s2);k++){
				if(s1[is1+k]==s2[is2+k])com[k]=1;
				else com[k]=0;
			}
			
			for(int k=0;is1+k<strlen(s1) && is2+k<strlen(s2);k++){
				if(com[k])++tmax;
				else{
					maxcom=max(tmax,maxcom);
					tmax=0;
				}
			}
			
		}
		
		cout<<maxcom<<endl;
	}
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64

int dp[2][5000];
int n,m;
string a,b;

int main(){
while(cin>>a>>b){
if(a.size()>b.size())swap(a,b);
n=a.size();
m=b.size();

int ans=0;
rep(i,2)rep(j,5000)dp[i][j]=0;

for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){

		if(i&1){//2,4,6,8...番目
			if(a[i]==b[j]){
				if(j-1>=0)
				dp[1][j]=max(dp[1][j],dp[0][j-1]+1);
				else dp[1][j]=max(dp[1][j],1);
				ans=max(ans,dp[1][j]);
			}
		}
		else{//1,3,5,7,9...番目
			if(a[i]==b[j]){
				if(j-1>=0)
				dp[0][j]=(dp[0][j],dp[1][j-1]+1);
				else dp[0][j]=max(dp[0][j],1);
				ans=max(ans,dp[0][j]);
			}
		}
	}
}

cout<<ans<<endl;
}


	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	while(cin>>s>>t){
		int roop1=0, save=0, ans = 0;
	for (int i = 0; i<s.size(); i++){
		for (int j = 0; j<t.size(); j++){
			if (s[i] == t[j]){
				roop1 = 0;
				save= 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
                        break;
                    }
                    else{
						if (s[i + roop1] == t[j + roop1]){
							save += 1;
							roop1++;
						}
						else if (s[i + roop1] != t[j + roop1]){
						ans=max(ans,save);
						break;
						}
                    }
				}
			}
		}
	}
	cout<<ans<<endl;
	}
}