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 "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;
ll 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(scanf("%s",s)!=EOF){
        fill(done[0],done[4444],false);
        ans = 0ll;
        scanf("%s",t);
        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<stdio.h>
#include<string.h>
int main()
{
	char a[4001],b[4001];
	while(scanf("%s%s",a,b)>0)
	{
		static int x[2][4001],i,j,s,t,r,c;
		s=strlen(a),t=strlen(b);
		for(r=j=0;j<=t;++j)x[0][j]=0;
		for(c=i=0;i<s;++i,c=!c)for(j=0;j<t;++j)r=(r>(x[!c][j+1]=(a[i]==b[j]?x[c][j]+1:0))?r:x[!c][j+1]);
		printf("%d\n",r);
	}
	return 0;
}

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 ans=0;
    for(i=0;i<alen;i++){
      for(j=0;j<blen;j++){
	if(ra[i]==rb[j]){
	  k=0;
	  while(k<blen-j && k<alen-i && ra[i+k]==rb[j+k]){
	    k++;
	  }
	  ans=(ans<k)?k:ans;
          j+=k-1;
	}
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s,t;
set<string>st;
int main(){
	while(cin>>s>>t){
	st.clear();
	r(j,s.size())if(j)r(i,s.size())if(j+i<=s.size())
	  if(!st.count(s.substr(i,j)))st.insert(s.substr(i,j));
	for(int j=t.size()-1;j>=1;j--)if(j)r(i,t.size())if(j+i<=t.size())
		if(st.count(t.substr(i,j))){
			cout<<j<<endl;
			goto L;
		}
	cout<<0<<endl;L:;
	}
}

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;


int main(){
	char s1[4003],s2[4003];
	
	while(1<scanf("%s %s",s1,s2)){
		int maxcom=0;
		int s1len=strlen(s1),s2len=strlen(s2);
		for(int i=0;i<s1len+s2len;i++){
			int is1,is2;
			if(i<s1len){
				is1=i;
				is2=0;
			}else{
				is1=0;
				is2=i-s1len;
			}
			int tmax=0;
			for(int k=0;is1+k<s1len && is2+k<s2len;k++){
				if(s1[is1+k]==s2[is2+k])++tmax;
				else{
					maxcom=max(tmax,maxcom);
					tmax=0;
				}
			}
			maxcom=max(tmax,maxcom);
			
		}
		
		cout<<maxcom<<endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,s2;
  while(cin >> s >> s2){
    ll ans = 0;
    rep(i,s.size()){
      ll len = 0;
      for(int j = 0; j < s2.size();){
        if(s[i+len] == s2[j+len]){
          len++;
          if(i+len >= s.size() || j+len >= s2.size()) break;
        }
        else{
          if(len>1){
            j += len-1;
          }
          else{
            ++j;
          }
          ans = max(len,ans);
          len = 0;
        }
      }
      ans = max(len,ans);
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
short dp[4001][4001]={};
char str1[4005],str2[4005];
short ans=0;
int main(){ 
   while(scanf("%s",str1)!=EOF){    
    scanf("%s",str2);
int a=strlen(str1),b=strlen(str2);
 for(int i=0;i<a;i++){ 
   for(int j=0;j<b;j++){  
    if(str1[i]==str2[j]){   
      if(i==0 || j==0){ 
dp[i][j]=1;ans=max(ans,dp[i][j]);} 
         else{ dp[i][j]=1+dp[i-1][j-1];ans=max(ans,dp[i][j]);}
      }}} 
 printf("%d\n",ans); ans=0;memset(dp,0,sizeof(dp));}
return 0;}

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

int main(){
	string str1, str2;
	while(cin >> str1 >> str2){

		// int count = 0;
		// for(int i = 0; i < str1.size(); i++){
		// 	for(int j = 0; j < str2.size(); j++){
		// 		int k = 0;
		// 		while(str1[i+k] == str2[j+k] && i+k < str1.size() && j+k < str2.size()){
		// 			//if(i + k > str1.size()-1 || j + k > str2.size()-1) break;
		// 			k++;
		// 			count = max(count, k);
		// 			//cout << str2.substr(i, k) << endl;
		// 		}
		// 	}
		// }
		// cout << count << endl;

		vector<vector<int> > dp(str1.size()+1, vector<int>(str2.size()+1));
		for(int i = 0; i < str1.size()+1; i++){
			for(int j = 0; j < str2.size()+1; j++){
				dp[i][j] = 0;
			}
		}
		int ans = 0;
		for(int i = 0; i < str1.size(); i++){
			for(int j = 0; j < str2.size(); j++){
				if(str1[i] == str2[j]){
					dp[i+1][j+1] = dp[i][j] + 1;
					ans = max(ans, dp[i+1][j+1]);
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}