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<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int main(){
    string str;
    while(cin>>str){
        string test;
        cin>>test;
        vector<string> v;
        int N=str.size();
        for(int i=0;i<N;i++){
            v.push_back( str.substr(i,N-i) );
        }
        sort(v.begin(),v.end());
        int ans;
        for(int i=1;i<test.size();i++){
            bool flag=false;
            for(int j=0;j<test.size()-i+1;j++){
                string tmp = test.substr(j,i);
                vector<string>::iterator itr = lower_bound(v.begin(),v.end(),tmp);
                int z=(int)(itr-v.begin());
                if(z!=N && v[z].size() >= i){
                    bool fff=true;
                    for(int k=0;k<i;k++){
                        if(tmp[k] != v[z][k]){
                            fff=false;
                            break;
                        }
                    }
                    if(fff){
                        flag=true;
                        break;
                    }
                }
            }
            if(!flag){
                ans=i-1;
                break;
            }
        }
        cout<<ans<<endl;
        str.clear();
    }
    
    return 0;
}

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

using namespace std;

int check(string, string);

int main()
{
  //ifstream ifs("data.txt");
  string str1, str2;
  while( cin >> str1 >> str2 ){

    int res = 0;

    for(int i = 0; i < max(str1.size(), str2.size()); i++){
      if(str1.size() > str2.size())
	rotate(str1.begin(), str1.begin() + 1, str1.end());
      else
	rotate(str2.begin(), str2.begin() + 1, str2.end());

      res = max(res, check(str1, str2));
    }

    cout << res << endl;
  }
  //ifs.close();
}

int check(string str1, string str2)
{
  int sn = 0, res = 0;
  for(int i = 0; i < min(str1.size(), str2.size()); i++){
    if(str1[i] == str2[i]){
      sn++;
    }else{
      sn = 0;
    }
    res = max(res, sn);
  }
  return res;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(1){
		string s, t; int roop1=0, roop2 = 0,roop3, save[1000000]={}, ans = 0;
		cin>>s;
		cin>>t;
		if(cin.eof())
		break;
	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++;
							roop3=max(roop3,roop1);
						}
						else if (s[i + roop1] != t[j + roop1]){
							if(j==t.size())
							i+=roop3;
							roop2++;
							break;
						}
					}
				}
			}
		}
	}
	sort(save, save + roop2 + 1);
	ans = save[roop2];
	cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int cmp_chain(char *str1, char *str2){
	int i=0;
	while( ( str1[i] != '\0') && ( str2[i] != '\0') && (str1[i] == str2[i])){
		i++;
	}
	return i;					//i==chain
}

int main(){
	char str1[4001];
	char str2[4001];
	int chain, max_chain;
	int i,j,k,l;
	while(true){
		cin >> str1; if(cin.eof() ) break;
		cin >> str2;
		max_chain=0;
		for( i = 0; str1[i] != '\0'; i++){
			for( j = 0; str2[j] != '\0'; j++){
				if(str1[i] == str2[j]){
					chain = cmp_chain( str1+i, str2+j);
					if(max_chain < chain){
						max_chain = chain;
					}
				}
			}
		}
		cout << max_chain << endl;
	}
	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 ans = 0;
        int n = s.size();
        int m = t.size();
        rep(i,n)rep(j,m)if(s[i] == t[j]){
            int nn = n-i, mm = m-j;
            int ok = 1,ng = min(nn,mm)+1;
            while(ng - ok > 1){
                int mid = (ok + ng)/2;
                if(rs.calc(i,i+mid) == rt.calc(j,j+mid))ok = mid;
                else ng = mid;
            }
            ans = max(ans,ok);
        }
        cout << ans << endl;
    }

}