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

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()

		dp := make([][]int, len(S)+1)
		for i := range dp {
			dp[i] = make([]int, len(T)+1)
		}

		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<iostream>
#include<string>

using namespace std;

short dp[4001][4001];

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;
	}
	return 0;
}

C++: //Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
short dp[4005][4005]; char a[4005],b[4005];
int main()
{
	srand((unsigned int)time(NULL));
	while(scanf("%s%s",&a,&b)!=-1)
	{
		int x=strlen(a);
		int y=strlen(b);
		memset(dp,0,sizeof(dp));
		int ret=0;
		for(int i=1;i<=x;i++)
		{
			for(int j=1;j<=y;j++)
			{
				if(a[i-1]==b[j-1])
				{
					dp[i][j]=(dp[i-1][j-1]+1);
				}
				else
				{
					dp[i][j]=0;
				}
				ret=max(ret,(int)dp[i][j]);
			}
		}
		printf("%d\n",ret);
	}
}

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 4444
using namespace std;

int dp[MAX][MAX];

void solve(){
 string s,t;
 while(scanf("%s",&s)){
  scanf("%s",&t);
  FOR(i,MAX)
   FOR(j,MAX) dp[i][j]=0;
  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",ma);
 }
}

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

C++: #include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int doubles, lengths, dat[8002], tmp[8002], rank_[8002];
bool compare_suffix(int i, int j) {
	if (dat[i] == dat[j]) {
		int ri = (i + doubles <= lengths ? dat[i + doubles] : -1);
		int rj = (j + doubles <= lengths ? dat[j + doubles] : -1);
		return ri < rj;
	}
	return dat[i] < dat[j];
}
inline vector<int> suffix_array(string S) {
	lengths = S.size();
	vector<int> arrays(lengths + 1);
	for (int i = 0; i <= lengths; i++) {
		arrays[i] = i;
		dat[i] = i < lengths ? S[i] : -1;
	}
	for (doubles = 1; doubles <= lengths; doubles <<= 1) {
		sort(arrays.begin(), arrays.begin() + lengths + 1, compare_suffix);
		tmp[arrays[0]] = 0;
		for (int i = 1; i <= lengths; i++) tmp[arrays[i]] = tmp[arrays[i - 1]] + (compare_suffix(arrays[i - 1], arrays[i]) ? 1 : 0);
		for (int i = 0; i <= lengths; i++) dat[i] = tmp[i];
	}
	return arrays;
}
inline vector<int> lcp(string s, vector<int> sa) {
	vector<int> ret; ret.resize(lengths + 1);
	for (int i = 0; i <= lengths; i++) rank_[sa[i]] = i;
	int h = 0; ret[0] = 0;
	for (int i = 0; i < lengths; i++) {
		int j = sa[rank_[i] - 1];
		if (h > 0) h--;
		for (; j + h < lengths && i + h < lengths; h++) {
			if (s[j + h] != s[i + h]) break;
		}
		ret[rank_[i] - 1] = h;
	}
	return ret;
}
string s, t; int sl;
int main() {
	while (cin >> s >> t) {
		sl = s.size();
		s += '$' + t;
		vector<int> v1 = suffix_array(s);
		vector<int> v2 = lcp(s, v1);
		int ret = 0;
		for (int i = 0; i < lengths; i++) {
			if ((v1[i] < sl) != (v1[i + 1] < sl)) {
				ret = max(ret, v2[i]);
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

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

using namespace std;

int main(){

	string a, b, c;

	while(cin >> a, !cin.eof())
	{
		cin >> b;

		int res = 0;
		c = string(b.size(),'1');
		a = c + a;
		
		for(int i = 0; i < (int)a.size(); i++)
		{
//			cout << a << endl;
//			cout << b << endl;
			
			int ct = 0;
			
			for(int j = 0; j < min(a.size(), b.size()); j++)
			{
				if( a[j] == b[j] )
					res = max( ++ct, res );
				else
					ct = 0;
			}
			
			b = "2" + b;
//			cout << ct << endl;
		}
		
		cout << res << endl;
	}
	return 0;	
}

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

#define MAX 4000

using namespace std;

int dp[MAX + 2][MAX + 2];

int main(void){

  string s,t;
  while(getline(cin, s)){
    getline(cin, t);

    fill(dp[0], dp[MAX + 1] + MAX + 2, 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;
	else dp[i + 1][j + 1] = 0;
      }
    }
    int ans = 0;
    for(int i = 0 ; i <= s.size() + 1 ; i++){
      for(int j = 0 ; j <= t.size() + 1 ; j++){
	ans = max(dp[i][j], ans);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

const int NMAX = 20000;

int n, k;
int Rank[NMAX + 1];
int tmp[NMAX + 1];

bool compare_sa(int i, int j) {
  if (Rank[i] != Rank[j]) return Rank[i] < Rank[j];
  else {
    int ri = i + k <= n ? Rank[i + k] : -1;
    int rj = j + k <= n ? Rank[j + k] : -1;
    return ri < rj;
  }
}

void construct_sa(string S, int *sa) {
  n = S.length();

  for (int i = 0; i <= n; i++) {
    sa[i] = i;
    Rank[i] = i < n ? S[i] : -1;
  }

  for (k = 1; k <= n; k *= 2) {
    sort(sa, sa + n + 1, compare_sa);

    tmp[sa[0]] = 0;
    for (int i = 1; i <= n; i++) {
      tmp[sa[i]] = tmp[sa[i - 1]] + 
        (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
    }

    for (int i = 0; i <= n; i++) {
      Rank[i] = tmp[i];
    }
  }
}

void construct_lcp(string S, int *sa, int *lcp) {
  int n = S.length();
  for (int i = 0; i <= n; i++) Rank[sa[i]] = i;

  int h = 0;
  lcp[0] = 0;
  for (int i = 0; i < n; i++) {
    int j = sa[Rank[i] - 1];

    if (h > 0) h--;
    for (; j + h < n and i + h < n; h++) {
      if (S[j + h] != S[i + h]) break;
    }

    lcp[Rank[i] - 1] = h;
  }
}

string S, T;

const int LMAX = 4008;
int sa[LMAX], lcp[LMAX];

int solve() {
  int sl = S.length();
  S += '\0' + T;

  construct_sa(S, sa);
  construct_lcp(S, sa, lcp);

  int ans = 0;
  for (int i = 0; i < S.length(); i++) {
    if ((sa[i] < sl) != (sa[i + 1] < sl)) {
      ans = max(ans,lcp[i]);
    }
  }
  return ans;
}

int main() {
  while (cin >> S >> T) {
    cout << solve() << endl;
  }
}