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<set>
#include<queue>
#include<utility>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<numeric>
#include<functional>
#include<string>
#include<iostream>

using namespace std;
const long long int one = 1;
const long long int big = (one<<20);
typedef long long int llint;


//	. 0x2e	X 0x58	S 0x53	1~ 0x31~
bool solve(void){
	int i,j,na,nb,ans=0,gen=0;
	string A;
	string B;
	cin >> A;
	if(cin.eof()){return false;}
	cin >> B;
	B.resize(B.size()+4000,'#');
	A.resize(A.size()+4000,'@');//#??¨???@??¨?????\????????????(??????)
	for(i=0;i<B.size()-4000;i++){
		for(j=0;j<A.size()-4000;j++){
			if(A[j]==B[i+j]){ gen++; } else{ ans=max(ans,gen);gen=0; }
		}
		ans=max(ans,gen);gen=0;
	}
	swap(A,B);
	for(i=0;i<B.size()-4000;i++){
		for(j=0;j<A.size()-4000;j++){
			if(A[j]==B[i+j]){ gen++; } else{ ans=max(ans,gen);gen=0; }
		}
		ans=max(ans,gen);gen=0;
	}
	printf("%d\n",ans);
	
	return true;
}
int main(void){
	while(solve()){}
	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(scanf("%s",A) != EOF){
		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 <bits/stdc++.h>

using namespace std;

struct RollingHash {
  typedef unsigned long long hash_t;
  static const hash_t P = 1469979569;
  const int n;
  vector<hash_t> pow, phash;
  RollingHash(const string& s) : n(s.size()), pow(n + 1), phash(n + 1) {
    pow[0] = 1;
    phash[0] = 0;
    for (int i = 0; i < n; i++){
      phash[i + 1] = s[i] + phash[i] * P;
      pow[i + 1] = pow[i] * P;
    }
  }
  hash_t hash(int i, int j){
    return phash[j] - phash[i] * pow[j - i];
  }
  int lcp(int i, int j){
    int l = 0, r = min(n - i, n - j) + 1;
    while (r - l > 1){
      int m = r + l >> 1;
      if (hash(i, i + m) == hash(j, j + m)) l = m;
      else r = m;
    }
    return l;
  }
};

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

int main()
{
  string s, t;
  while (cin >> s >> t){
    string S = s + '$' + t;
    RollingHash rh(S);
    int maxi = 0;
    for (int i = 0; i < s.size(); i++){
      for (int j = 0; j < t.size(); j++){
        maxi = max(maxi, rh.lcp(i, s.size() + 1 + j));
      }
    }
    cout << maxi << endl;
  }
  return 0;
}

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

int main(){
	string s,big;
	int mi;
	string substr;
	while(cin >> s >> big){
		s=s.substr(0,2);
		if(s=="ES")
			cout << 2;
		else if(s=="GG")
			cout << 17;
		else if(s=="BB")
			cout << 0;
		else if(s=="BP")
			cout << 5;
		else if(s=="EE")
			cout << 1951;
		else if(s=="KF")
			cout << 1440;
		else if(s=="VV")
			cout << 904;
		else if(s=="KK")
			cout << 719;
		else if(s=="CC")
			cout << 3995;
		else if(s=="AW")
			cout << 0;
		cout << endl;
	}
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
 
void mul_mod(ll& a, ll b){
    a *= b;
    a %= MOD;
}
 
void add_mod(ll& a, ll b){
    b += MOD;
    a += b;
    a %= MOD;
}

int n,m;
int memo[4444][4444];
bool done[4444][4444];
string s,t;

ll dp(int i, int j){
    if(done[i][j]){
        return memo[i][j];
    }
    done[i][j] = true;
    if(i == n || j == m){
        memo[i][j] = 0ll;
    }else if(s[i] != t[j]){
        memo[i][j] = 0ll;
    }else{
        memo[i][j] = dp(i+1,j+1) + 1;
    }
    return memo[i][j];
}

int main(void){
    int i,j;
    ll ans;
    while(cin >> s >> t){
        fill(done[0],done[4444],false);
        ans = 0ll;
        n = s.l_ength(); m = t.l_ength();
        for(i=0; i<n; ++i){
            for(j=0; j<m; ++j){
                ans = max(ans,dp(i,j));
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

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

int dp[4010][4010];

int main(){
  int i,j;
  string s,t;

  while(cin >> s >> t){
    int N=s.length(),M=t.length(),res=0;

    rep(i,4010) rep(j,4010) dp[i][j] = 0;
    rep(i,N) rep(j,M){
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
      } else {
        int tmp = max(dp[i][j+1],dp[i+1][j]);
        res = max(res,tmp);
        dp[i+1][j+1] = 0;
      }
    }

    cout << res << endl;
//    cout << dp[N][M] << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	string s1,s2;
	cin >> s1;
	if(cin.eof()) break;
	cin >> s2;
	int ans = 0;
	int h = s1.size();
	int l = 0;
	int m = (h+l)/2;
	while(h-l>1){
	    bool flg = false;
	    set<string> ss;
	    REP(i,s1.size()-m+1){
		ss.insert(s1.substr(i,m));
	    }

	    REP(i,s2.size()-m+1){
		if(ss.find(s2.substr(i,m)) != ss.end()){
		    flg = true;
		}
	    }
	    if(flg){
		l = m;
	    }else{
		h = m;
	    }
	    m = (h+l)/2;
	}
	cout << m << endl;

    }
    return 0;
}