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>
#define lld long long int
#define str string


using namespace std;

lld f();
lld ster,leg,leg2,ans=0,ans2=0;

str moji,moji2,cut;

int main(){
while(1){
    cin >> moji ;
    if(moji=="EOF")break;
    cin >> moji2 ;
    leg=moji.size();
    leg2=moji2.size();

    cout << f() << endl;
    ans=0;
    ans2=0;
}
return 0;
}

lld f(){
    for(int a=0;a<leg;a++){
            for(int b=1;b<leg-a;b++){
        cut = moji.substr(a,b);
        ans=(moji2.find(cut)!=-1?b:ans);
        ans2=(ans>ans2?ans:ans2);
        }
    }
    return ans2;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, bool> PIB;

int dp[4001][4001];
string s, t;
int ans = 0;

int main()
{
  while(true){
    cin >> s;
    if(s == "")
      break;
    cin >> t;

    ans = 0;

    for(int i = 0; i < s.size(); i++)
      for(int j = 0; j < t.size(); j++)
	if(s[i] == t[j]){
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	  ans = max(ans, dp[i + 1][j + 1]);
	}
    
    cout << ans << 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){
		if(s.length()>big.length())
			swap(s,big);
		mi = 0;
		for(int m=1;m<=s.length();m++){
			substr="";
			for(int i=0;i<m;i++)substr += s[i];
			if(~big.find(substr)){mi = m;continue;}
			for(int i=m;i<s.length();i++){
				substr.erase(0,1);
				substr+=s[i];
				if(~big.find(substr)){mi = m;continue;}
			}
			break;
		}
		cout << mi << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string a, b;
int dp[4005][4005] = { 0 };
int main() {
	while (cin >> a >> b ) {
		for (int i = 0; i < a.size(); i++) {
			for (int j = 0; j < b.size(); j++) {
				if (a[i] == b[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
				else dp[i + 1][j + 1] = 0;
			}
		}
		int res = 0;
		for (int i = 1; i < a.size(); i++) {
			for (int j = 1; j < b.size(); j++) {
				res = max(res, dp[i][j]);
			}
		}
		cout << res << endl;
	}
	return 0;
}

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

int main(){
    string str,test;
    while(cin>>str>>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){
                    if(tmp == v[z].substr(0,i)){
                        flag=true;
                        break;
                    }
                }
            }
            if(!flag){
                ans=i-1;
                break;
            }
        }
        cout<<ans<<endl;
        str.clear();
        test.clear();
    }
    
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }


int dp[4002][4002]={0};
int main(){
	string a,b;
	while(cin >> a,a!=EOF){
	int as=a.size();
	a+='a';
	int bs=b.size();
	b+='b';
	int ans=0;
	for(int i=0;i<as;i++){
		for(int j=0;j<bs;j++){
			if(a[i+1]==b[j+1]){
				dp[i+1][j+1]=dp[i][j]+1;
			}else{
				dp[i+1][j+1]=0;
			}/*
			if(dp[i+1][j+1]){
				cout << dp[i+1][j+1]<<endl;
				cout << i << "," << j << endl;
			}*/
			ans=max(ans,dp[i+1][j+1]);
		}
	}
	cout << ans << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#define REP(i,a,n) for(int i = a;i < n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int field[4002][4002];
int main(void){
   char a[4002],b[4002];
   while(scanf("%s",a+1) != EOF){
      scanf("%s",b+1);
      int ma = 0;
      REP(i,1,4001) field[i][1] = field[1][i] = 0;
      a[0] = '0'; b[0] = '1';
      int as = strlen(a),bs = strlen(b);
      REP(i,1,as){
         REP(j,1,bs){
            if(a[i] == b[j]){
               field[i][j] = field[i-1][j-1]+1;
               ma = max(ma,field[i][j]);
            }
            else field[i][j] = 0;
         }
      }
      printf("%d\n",ma);
   }
   return 0;
}

C++: #include "stdio.h"
#include "string.h"

char st1[5000];
char st2[5000];
char flg[5000];
int ans[1000];

int main()
{
  int nw = 0;
  while(1)
    {
      char w;
      w = getchar();
      if(w == EOF)
	{
	  break;
	}
      scanf("%s",st1);
      scanf("%s",st2);
      int st1l,st2l;
      st1l = strlen(st1);
      st2l = strlen(st2);
      int m = 0;
      for(int i = 0; i < st1l; i++)
	{
	  for(int ii = 0; ii < 5000; ii++)
	    {
	      flg[ii] = 0;
	    }
	  for(int ii = i; ii < st1l; ii++)
	    {
	      flg[ii - i] = st1[ii];
	    }
	  for(int ii = 0; ii < st2l; ii++)
	    {
	      flg[ii] = flg[ii] - st2[ii];
	    }
	  int n = 0;
	  for(int ii = 0; ii < 5000; ii++)
	    {
	      if(flg[ii] == 0)
		{
		  n++;
		  if(n > m)
		    {
		      m = n;
		    }
		}
	      else
		{
		  n = 0;
		}
	    }
	}
      ans[nw] = m;
      nw++;
    }
  for(int i = 0; i < nw; i++)
    {
      printf("%d\n",ans[i]);
    }
  return 0;
}