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 <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>

using namespace std;

#define sz			size()
#define lgt			length()
#define rep(i,n)	for (int i = 0; i < n; i++)
#define ALL(X)		(X).begin(),(X).end()
#define RALL(X)		(X).rbegin(),(X).rend()
#define pb			push_back
#define SORT(a)		sort(ALL(a));
#define RSORT(a)	sort(RALL(a));
#define mp			make_pair
#define dump(x)		cerr<<#x<<" = "<<(x)<<endl;
#define fir			first
#define sec			second

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<string> vs;

int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
vs form(string a,char s){vs v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(b);b="";}else b+=a[i];}v.pb(b);return v;}
vi formint(string a,char s){vi v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(toInt(b));b="";}else b+=a[i];}v.pb(toInt(b));return v;}

const double EPS=1e-10,PI=acos(-1.0);
const int INF=2100000000;

int main(void)
{
	string a, b;
	while (cin >> a >> b){
		int res = 0;
		
		for (int i = 0; i < a.sz; i++){
			int tmp = 0;
			int cnt = i;
			for (int j = 0; j < b.sz && cnt < a.sz; j++){
				if (a[cnt] == b[j]) tmp++;
				else {
					res = max(res, tmp);
					tmp = 0;
				}
				cnt++;
			}
		}
		
		for (int i = 0; i < b.sz; i++){
			int tmp = 0;
			int cnt = i;
			for (int j = 0; j < a.sz && cnt < b.sz; j++){
				if (b[cnt] == a[j]) tmp++;
				else {
					res = max(res, tmp);
					tmp = 0;
				}
				cnt++;
			}
			res = max(res, tmp);
		}
		
		cout << res << endl;
		a.clear();
		b.clear();
	}
	
	return 0;
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64

int dp[5000][5000];
int n,m;
string a,b;

int main(){
while(cin>>a>>b){
if(a.size()>b.size())swap(a,b);
n=a.size();
m=b.size();

int ans=0;
rep(i,5000)rep(j,5000)dp[i][j]=0;

for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
	if(a[i-1]==b[j-1]){
		//	dp[i][j]=1;
		dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
	}
	ans=max(ans,dp[i][j]);


	}
}

cout<<ans<<endl;
}


	return 0;
}

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

using namespace std;

int dp[4000][4000];

int main()
{
	for(;;){
		string s, t;
		
		if(!(cin >> s >> t)){
			break;
		}
		
		for(int i = 0; i <= s.size(); i++){
			dp[i][0] = 0;
		}
		
		for(int j = 0; j <= t.size(); j++){
			dp[0][j] = 0;
		}
		
		for(int i = 1; i <= s.size(); i++){
			for(int j = 1; j <= t.size(); j++){
				if(s[i-1] == t[j-1]){
					dp[i][j] = dp[i-1][j-1] + 1;
				}
				else{
					dp[i][j] = 0;
				}
			}
		}
		int ans = 0;
		
		for(int i = 0; i <= s.size(); i++){
			for(int j = 0; j <= t.size(); j++){
				if(dp[i][j] > ans){
					ans = dp[i][j];
				}
			}
		}
		
		cout << ans << endl;
	}
}

C++: #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

char d[2][4005];
int dp[4001][4001];

int main(){
	scanf("%s%s",d[0],d[1]);
	int i,j;
	int res=0;
	for(i=0;d[0][i]!=0;i++){
		for(j=0;d[1][j]!=0;j++){
			if(d[0][i]==d[1][j]) dp[i+1][j+1]=dp[i][j]+1;
			res=max(res,dp[i+1][j+1]);
		}
	}
	printf("%d\n",res);
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

string a, b;
int ans = 0;

int main() {
	while ( cin >> a ) {
		cin >> b;
		ans = 0;
		if ( a.size() > b.size() ) {
			swap( a, b );
		}
		for ( int i = 0; i < a.size(); i++ ) {
			int cnt = 0;
			for ( int j = 1; j <= a.size() - i; j++ ) {
				if ( b.find( a.substr( i, j ) ) == string::npos ) {
					break;
				}
				cnt++;
			}
			ans = max( ans, cnt );
		}
		printf( "%d\n", ans );
	}
	return 0;
}

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

using namespace std;

int main()
{
	string str,str2;
	int i,j;
	
	for(;cin >> str;)
	{
		cin >> str2 ;
		
		short int ss[4001][4001];
		int ans=0;
		
		for(i=0;i<str.size();i++)
		{
			for(j=0;j<str2.size();j++)
			{
				if(str[i]==str2[j] && i!=0 && j!=0)
					ss[i][j]=ss[i-1][j-1]+1;
				
				else if(str[i]==str2[j])
					ss[i][j]++;
				
				if(ss[i][j]>ans)
					ans=ss[i][j];
			}
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <cstring>
int dp[4001][4001];
using namespace std;
int main(){
  string s,str;
  int ans;
  while(cin >> s >> str){
    ans = 0;
    memset(dp,0,sizeof(dp));
    for(int i=0,l=s.size();i<l;i++){
      for(int j=0,ll=str.size();j<ll;j++){
        if(s[i] == str[j]){
          dp[i+1][j+1] = dp[i][j]+1;
          ans = max(ans,dp[i+1][j+1]);
        }else dp[i+1][j+1] = 0;
      }
    }
    cout << ans << endl;
  }
}