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

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

		dp := make([][]int, len(S)+1)
		for i := range dp {
			dp[i] = make([]int, len(T)+1)
		}

		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 <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;

char a[4010], b[4010];
int dp[4010][4010];

int main()
{
	while (cin >> a) {
		cin >> b;
		int len_a = strlen(a);
		int len_b = strlen(b);
		for (int i = 0; i <= len_a; i++)
			for (int j = 0; j <= len_b; j++)
				dp[i][j] = 0;
		for (int i = 0; i < len_a; i++) {
			for (int j = 0; j < len_b; j++) {
				if (a[i] == b[j])
					dp[i + 1][j + 1] = dp[i][j] + 1;
			}
		}
		int ans = 0;
		for (int i = 0; i <= len_a; i++)
			for (int j = 0; j <= len_b; j++)
				ans = max(ans, dp[i][j]);
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int ans, dp[4001][4001];

int main() {
	while (true) {
		ans = 0;
		memset(dp, 0, sizeof(dp));
		string str[2];
		cin >> str[0];
		if (str[0].empty()) break;
		cin >> str[1];
		REP(i, (int)str[0].size()) {
			REP(j, (int)str[1].size()) {
				if (str[0][i] == str[1][j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
					ans = ans < dp[i + 1][j + 1] ? dp[i + 1][j + 1] : ans;
				}
				else dp[i + 1][j + 1] = 0;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
  string a,b;
  while(cin >> a >> b){
    int ans = 0;
    for(int i = 0; i <= (int)a.size()*2; i++){
      int c = 0,t = 0;
      for(int j = 0; j < (int)b.size(); j++){
	//cout << (int)b.size() - i + j <<  " : " << j << endl;
	if((int)b.size() + j - i < 0 || (int)a.size() <= (int)b.size() + j - i)continue;
	if(a[(int)b.size() + j - i] == b[j]){
	  c++;
	}else{
	  t = max(t,c);
	  c = 0;
	}
      }
      ans = max(max(t,c),ans);
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <cstring>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int common(string &a, string &b){
	int size = min(a.size(), b.size());
	int res = 0, cnt = 0;
	rep(i, size){
		if(a[i]==b[i]) cnt++;
		else{
			res = max(res, cnt);
			cnt = 0;
		}
	}
	return max(res, cnt);
}

int check(string &a, string &b){
	int res = 0;
	rep(i, a.size()){
		res = max(res, common(a.substr(i),b));
	}
	return res;
}

int main(){
	string a, b;
	while(cin >> a >> b){
		cout << max(check(a, b), check(b, a)) << endl;
	}


    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	char a[4001],b[4001];
	while(scanf("%s",a)!=EOF){
		scanf("%s",b);
	int t[4002][4002];
	for(int i=0;i<=strlen(a);i++){
		t[0][i]=0;
	}
	for(int j=0;j<=strlen(b);j++){
		t[j][0]=0;
	}
	int ans=0;
	for(int i=1;i<=strlen(a);i++){
		for(int j=1;j<=strlen(b);j++){
			if(a[i-1]==b[j-1])t[i][j]=t[i-1][j-1]+1;
			else t[i][j]=0;
			ans=max(ans,t[i][j]);
		}
	}

	
	cout << ans << "\n";
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

class RollingHash{
private:
    int M = 1e9+7;
    int base = 1213;
    string str;
    int n;
    vector<int> pow,sum;

    void build(){
        n = str.size();
        sum = pow = vector<int> (n+1);
        sum[0] = 0;
        pow[0] = 1;
        for(int i = 0; i < n; i++){
            sum[i+1] = (str[i] + sum[i] * base) % M;
            pow[i+1] = pow[i] * base % M;
        }
    }


public:
    RollingHash(){}
    RollingHash(string in){
        str = in;
        build();
    }
    RollingHash(string in, int p, int mod){
        M = mod;
        base = p;
        str = in;
        build();
    }

    int calc(int l, int r){//[l,r)のハッシュ値を計算
        int len = r - l;
        int ret = sum[r] + M;
        ret -= sum[l] * pow[len] % M;
        return ret % M;
    }

};

signed main(void) {
    string s,t;
    while(cin >> s){
        cin >> t;
        RollingHash rs(s);
        RollingHash rt(t);
        int n = s.size();
        int m = t.size();
        int ok = 0, ng = min(n,m)+1;
        while(ng - ok > 1){
            int mid = (ok + ng)/2;
            set<int> st;
            rep(i,n-mid+1){
                st.insert(rs.calc(i,i+mid));
            }
            bool c = false;
            rep(i,m-mid+1){
                if(st.count(rt.calc(i,i+mid)))c = true;
            }
            if(c)ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }

}

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

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int dp[4003][4003] = {0};
int main(){
  
  
  
  char a[4002],b[4002];
  
  while(cin >> a >> b){
  int ans = 0;
  memset(dp,0,sizeof(dp));
 // scanf("%s%s",&a,&b);
  
  int alen = strlen(a);
  int blen = strlen(b);
  
  for(int i = 1;i <= alen;i++){
    for(int j = 1;j <= blen;j++){
      if(a[i-1] == b[j-1]){
	dp[i][j] = dp[i-1][j-1] + 1;
	ans = max(ans,dp[i][j]);
      }
    }
  }
  
  
  printf("%d\n",ans);
  
  }
  
  return 0;
  
}