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++: #include <cstdio>
#include <cstring>

int main(void){
  char ra[4005]={0};
  char rb[4005]={0};
  while(scanf("%s%s",ra,rb)!=EOF){
    int alen=strlen(ra);
    int blen=strlen(rb);
    //printf("%d\n%d\n",alen,blen);
    int i=0;
    int j=0;
    int k=0;
    int h=0;
    int km=0;
    int ans=0;
    /*raとrbをiだけずらす。*/
    for(i=-blen;i<alen;i++){
      /*k=(alen-i<blen)?alen-i:blen;
	h=(i<0)?-i:0;*/
      h=0;
      k=alen;
      km=0;
      for(j=h;j<k;j++){
	if(j>=0 && i+j>=0 ){
	  if(j>=alen || j+i>=blen){
	    ans=(ans<km)?km:ans;
	    km=0;
	    break;
	  }
	  if(ra[j]==rb[i+j]){
	    km++;
	  }
	  else{
	    ans=(ans<km)?km:ans;
	    km=0;
	  }
        }
      }
      ans=(ans<km)?km:ans;
      km=0;
    }
    printf("%d\n",ans);
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	for(string a,b;cin>>a>>b;){
		int m=a.size(),n=b.size();
		int res=0;
		for(int i=-m+1;i<n;i++){
			int k=0;
			for(int j=max(-i,0);j<m && i+j<n;j++){
				if(a[j]!=b[i+j])
					k=0;
				else
					k++;
				res=max(res,k);
			}
		}
		cout<<res<<endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1<<29
#define MAX 4001
using namespace std;

int dp[MAX][MAX];

void solve(){
 string s,t;
 while(scanf("%s",&s)){
  scanf("%s",&t);
  FOR(i,s.size()){
   FOR(j,t.size()){
    if(s[i]==t[j]){
     if(!i||!j) dp[i][j]=1;
     else dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
    }
   }
  }
  int ma=0;
  FOR(i,s.size()+1){
   FOR(j,t.size()+1){
    ma=max(ma,dp[i][j]);
   }
  }
  printf("%d",ma);
 }
}

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

C++: #include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

string s, t;
int dp[4001][4001];

int main(){
	while(cin >> s >> t){
		rep(i, s.size() + 1){
			dp[i][0] = 0;
		}
		rep(i, t.size() + 1){
			dp[0][i] = 0;
		}
		for(int i = 1; i <= s.size(); ++i){
			for(int j = 1; j <= t.size(); ++j){
				dp[i][j] = s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] + 1 : 0;
			}
		}
		int ans = 0;
		rep(i, s.size() + 1){
			ans = max(*max_element(dp[i], dp[i] + t.size() + 1), ans);
		}
		cout << ans << endl;
	}
	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(~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++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define SQR(a) ((a)*(a))
using namespace std;
typedef long long int ll;
typedef pair<int,int> pr;
typedef pair<pr,ll> ppr;
typedef vector<pr> vpr;
const int INF=1<<30;
int DP[4001][4001]={};
int main() {
	string s1,s2;
	while(cin >>s1 >> s2){
		REP(i,4001)
			REP(j,4001)
				DP[i][j]=0;
	int maxim=0;
	REP(i,s1.size())
		REP(j,s2.size()){
				if(s1[i]==s2[j])
				DP[i+1][j+1]=DP[i][j]+1;
				maxim=max(maxim,DP[i+1][j+1]);
			}
	cout << maxim << endl;
	}
	// your code goes here
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    string n, m;
    while(cin >> n >> m){
        int ans = 0;
        if(n.size() > m.size()) swap(n, m);
        for(int i=0; i < n.size(); i++){
            for(int j=i+1; j < n.size(); j++){
                if(j-i <= ans) continue;
                string s = n.substr(i, j-i);
                if(m.find(s) != string::npos){ans = max(ans, (int)s.size());}
                else {
                    i++; j = i;
                }
            }
        }
        cout << ans << endl;
    }
}

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

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string str1;
string str2;
int main(){
	while(cin>>str1>>str2){
		int ans = 0;
		for(int i = 0;i <str1.length();i++){
			for(int j=0;j <str1.length();j++){
				int tmp = 0;
				for(int k = 0;k+i<str1.length()&&k+j<str2.length();k++){
					if(str1[i+k]!=str2[j+k]){
						break;
					}
					tmp++;
				}
				ans =max(ans,tmp);
			}
		}
		cout <<ans<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

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