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++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

//{{{ Z(s, &z)
void Z(const string& s, vector<int>& z)
{
  const int n = s.size();
  z.assign(n, 0);
  int R, L;
  R = L = 0;
  for (int i = 1; i < n; i++){
    if (i > R){
      L = R = i;
      while (R < n && s[R - L] == s[R]) R++;
      z[i] = R - L;
      R--;
    }
    else {
      int k = i - L;
      if (z[k] < R - i + 1) z[i] = z[k];
      else {
        L = i;
        while (R < n && s[R - L] == s[R]) R++;
        z[i] = R - L;
        R--;
      }
    }
  }
}
//}}}

int main()
{
  char S[4096], T[4096];
  while (~scanf("%s %s", S, T)){
    string s = S, t = T;
    string st = s + '$' + t;
    const int sl = s.size();
    int maxi = 0;
    for (int i = 0; i < sl - maxi - 1; i++){
      vector<int> z;
      Z(st.substr(i), z);
      maxi = max(maxi, *max_element(begin(z) + (sl - i), end(z)));
    }
    printf("%d\n", maxi);
  }
  return 0;
}

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, save=0, ans = 0;
		cin>>s;
		cin>>t;
		if(s==""||t=="")
		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= 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;
	}
	
	return 0;
}

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

int main(){
	string s1, s2;
	int res, p;
	
	while(cin >> s1){
		cin >> s2;
		
		res = 0;
		for(int i = 0; i < s1.size() - res; i++){
			for(int j = 0; j < s2.size() - res; j++){
				if(s1[i] == s2[j]){
					for(p = 1; i + p < s1.size() && j + p < s2.size(); p++){
						if(s1[i + p] != s2[j + p]) break;
					}
					if(p > res) res = p;
				}
			}
		}
		
		cout << res << endl;
	}
	
	return 0;
}

C++: #include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>


using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
char A[4002],B[4002];
int DP[4002];


int main(){
	while(1){
		scanf("%s",A);
		scanf("%s",B);
		int ans=0;
		rep(i,strlen(A)){
			for(int j=strlen(B);j>-1;j--){
				if(A[i]==B[j]){
					if(i!=0&&j!=0){
						DP[j]=DP[j-1];
					}else DP[j]=0;
					DP[j]++;
				}else{DP[j]=0;}
				ans=max(ans,DP[j]);
			}
		}
	printf("%d\n",ans);
	}
}

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

using namespace std;

int compare (string s, string t )
{
	int slen = s.length();
	int tlen = t.length();
	int res = 0;

	// sÍ»ÌÜÜ t ð¸ç·
	for (int i = 0; i < slen; i++ ){
		int curr = 0;
		for (int j = 0; j < tlen; j++ ){
			if (i+j == slen )
				break;
			if (s[i+j] == t[j] ){
				curr++;
			}else{
				if (res < curr ) res = curr;
				curr = 0;
			} // end if
		} // end for
		if (curr && res < curr ) res = curr;
	} // end for

	return res;
}

int main()
{
	string s,t;
	while (cin >> s >> t ){
		int res1 = compare (s, t );
		int res2 = compare (t, s );
		printf ("%d\n", (res1 < res2 ? res2 : res1 ) );
	} // end loop
		
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

int dp[4001][4001];
int main() {
	string a, b;
	while (cin >> a >> b) {
		for (int i = 0; i < 4001; ++i) {
			for (int j = 0; j < 4001; ++j) {
				dp[i][j] = -1e9;
			}
		}
		int ans = 0;
		for (int i = 0; i < a.size(); ++i) {
			for (int j = 0; j < b.size(); ++j) {
				if (a[i] == b[j]) {
					if (i > 0 && j > 0) {
						dp[i][j] = max(1,dp[i - 1][j - 1] + 1);
					}
					else {
						dp[i][j] = 1;
					}

				}
				ans = max(ans, dp[i][j]);
			}
		}
		cout << ans << 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 4002
using namespace std;

int dp[MAX][MAX];

void solve(){
 string s,t;
 while(cin>>s>>t){
  ZERO(dp);
  FOR(i,s.size()){
   FOR(j,t.size()){
    if(s[i]==t[j]){
     dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
    }
   }
  }
  int ma=0;
  FOR(i,s.size()+1){
   FOR(j,t.size()+1){
    ma=max(ma,dp[i][j]);
   }
  }
  printf("%d\n",ma);
 }
}

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

C++: #include<cstdio>
char c[4001],d[4001],*a,*b;int main(){for(int m,o,i,k,s;~scanf("%s%s",c,d);)for(a=c,b=d,k=m=0;k++<2||printf("%d\n",m)&0;a=d,b=c)for(o=0;a[o];o++)for(i=s=0;a[i+o]&&b[i];i++)a[i+o]-b[i]?s=0:m<++s&&(m=s);return 0;}

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

#define MAX 4000

int dp[MAX+1][MAX+1];

char buffer1[MAX];
char buffer2[MAX];

int main(int argc, char *argv[]){
  while(std::cin >> buffer1){
    int len1, len2,i,j, max = 0;
    
    std::cin >> buffer2;

    len1 = strlen(buffer1);
    len2 = strlen(buffer2);
    
    for(i = 0; i < len1+1; i++){
      for(j = 0; j < len2+1; j++){
	dp[i][j] = 0;
      }
    }

    for(i = 0; i < len1; i++){
      for(j = 0; j < len2; j++){
	if(buffer1[i] == buffer2[j]){
	  dp[i+1][j+1] = dp[i][j] + 1;
	  if(max < dp[i+1][j+1]){
	    max = dp[i+1][j+1];
	  }
	}
      }
    }

    std::cout << max << std::endl;
    
  }
  
  return 0;    
}