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 <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int M=8000+10;
char in[M];

int group[16][M];
int order[16][M];
int head[M];

void exec(){
	in[0]=0;
	scanf("%s",in);
	int len0=strlen(in);
	if(len0==0)exit(0);
	scanf("%s",in+len0);
	int len1=strlen(in+len0);
	int len=len0+len1;
	//cout << in << endl;
	fill(head,head+256,0);
	for(int i=0;i<len;i++){
		int v=in[i]-'A';
		head[v+1]++;
	}
	for(int i=1;i<'Z'-'A'+1;i++){
		head[i]+=head[i-1];
	}
	for(int i=0;i<len;i++){
		int v=in[i]-'A';
		//cout << v << ", " << head[v] << endl;
		order[0][head[v]++]=i;
		group[0][i]=v;
	}

	/*
	for(int i=0;i<len;i++)
	{
		int a=order[0][i];
				// debug
			int en;
			if(a<len0){
				en=len0;
			}else
			{
				en=len;
			}
			cout << group[0][a] << " ";
			for(int b=a;b<en;b++){
				cout << in[b];
			}
			cout << endl;

	}*/

	int e=1;
	for(;(1<<e)<=len;e++)
	{
		int w=1<<(e-1);

		fill(head,head+len+1,0);
		int vmax=-1;
		// set head
		for(int i=0;i<len;i++){
			int v=group[e-1][i];
			head[v+1]++;
			vmax=max(vmax,v);
		}
		for(int i=1;i<=vmax;i++){
			head[i]+=head[i-1];
		}
		// sort
		for(int i=0;i<len;i++){
			int a=order[e-1][i];
			if(len<=a+w||(a<len0&&len0<=a+w)){
				int v=group[e-1][a];
				order[e][head[v]++]=a;
			}
		}
		for(int i=0;i<len;i++){
			int a=order[e-1][i];
			if(a-w<0||(len0<=a&&a-w<len0)){
				continue;
			}
			int v=group[e-1][a-w];
			order[e][head[v]++]=a-w;
		}
		// set group
		int p0=-2,p1=-2;
		int g=-1;
		for(int i=0;i<len;i++){
			int a=order[e][i];
			int n0=group[e-1][a];
			int n1=-1;
			if(a+w<len0||(len0<=a&&a+w<len)){
				n1=group[e-1][a+w];
			}
			if(p0!=n0||p1!=n1){
				p0=n0;
				p1=n1;
				g++;
			}
			group[e][a]=g;
			// debug
#if 0
			int en;
			if(a<len0){
				en=len0;
			}else
			{
				en=len;
			}
			cout << group[e][a] << " ";
			for(int b=a;b<en;b++){
				cout << in[b];
			}
			cout << endl;
#endif	
		}
		//cout << endl;
	}

	// common
	int ret=0;
	for(int i=1;i<len;i++){
		int pre=order[e-1][i-1];
		int a=order[e-1][i];
		int sum=0;
		int r0=pre;
		int s0=a;
		if(r0>s0){
			swap(r0,s0);
		}
		if(len0<=r0||s0<len0)continue;
		while(1)
		{
			int r=r0+sum;
			int s=s0+sum;
			int l=0;
			while(r+(1<<l)<=len0&&s+(1<<l)<=len&&group[l][r]==group[l][s]){
				l++;
			}
			if(l==0)break;
			sum+=(1<<(l-1));
		}
		ret=max(ret,sum);
	}
	cout << ret << endl;
}
int main()
{
	while(1)exec();
}

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

using namespace std;

int main(){
  string s,t,u;
  while(cin>>s>>t){
    u=(s.size()>t.size())?t:s;
    if(s==u) s=t;
    int c=u.size(),d=s.size();
    int a=0,b=0;
    for(int i=0;i<c;++i){
      for(int j=0;j<d;++j){
	if(u[(j+i)%c]==s[j]){
	  ++b;
	  if(i+j==c-1){
	    a=max(a,b);b=0;
	  }
	}
	else{
	  a=max(a,b);b=0;
	}
      }
      a=max(a,b);b=0;
    }
    cout<<a<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
  int n,i,j,max;
  string s1,s2,t;
  while(cin>>s1>>s2){
    max=0;
    for(i=0;i<=s1.size();i++){
      for(j=1;j<=s1.size()-i;j++){
	t=s1.substr(i,j);
	if(s2.find(t)!=string::npos)
	  if(max<t.size())max=t.size();
      }
    }
    cout<<max<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
string str1,str2,str3;
bool flag=false;
int ans;

int main(){

    while(cin >> str1){
    //cin >> str1;
    //if(str1=="0")break;
    cin >> str2;
    //cout << " " << str1 << endl;
    //cout << " " << str2 << endl;
    for(int i=str1.size();i>0;i--){
        for(int j=0;j<=str1.size()-i;j++){
            str3=str1.substr(j,i);
            //cout << str3 << endl;
            if(str2.find(str3)>=0&&str2.find(str3)<4001){
                ans=str3.size();
                flag=true;
                break;
            }
        }
        if(flag==true)break;
    }

    cout << ans << endl;
    flag=false;
    ans=0;

    }
return 0;
}

C++: #include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>
#include <set>

#define INF 10 << 10

string str1;
set<string> memo;

string Find(string str) {
	if (memo.find(str) != memo.end()) { return str; }
	if (str1.find(str) != -1) {
		memo.insert(str);
		return str;
	}
	if (str.size() == 1) { return ""; }
	int maxi = 0; string ans;
	string s = str; s.erase(s.begin());
	string ss = Find(s);
	maxi = ss.size(); ans = ss;
	s = str; s.erase(s.begin() + s.size() - 1);
	ss = Find(s);
	if(maxi < ss.size()){
		maxi = ss.size();
		ans = ss;
	}
	memo.insert(ans);
	return ans;
}

int main() {
	string str2;

	while (cin >> str1) {
		cin >> str2;
		//?????????????????? str1 ???
		if (str1.size() < str2.size()) {
			swap(str1, str2);
		}
		int ans = Find(str2).size();
		cout << ans << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#define N 4001
using namespace std;
int n,m,dp[N][N],ans;
int main(){
  string A,B;
  while(cin>>A>>B){
    n=A.size();
    m=B.size();
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++) dp[i][j]=0;
    ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	if(A[i]==B[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 <string>
using namespace std;
#define max(a,b) ((a)>=(b)?(a):(b))
#define min(a,b) ((a)<=(b)?(a):(b))
int main() {
	string S,T;
	while(cin>>S) {
		cin>>T;
		int len=0;
		for(int i=0;i<S.size();i++) {
			for(int j=0;j<min(S.size()-i,T.size());j++) {
				int k;
				for(k=j;k<min(S.size()-i,T.size());k++) if(S[i+k]!=T[k]) break;
				len=max(len,k-j);
				j=k;
			}
		}
		for(int i=0;i<T.size();i++) {
			for(int j=0;j<min(T.size()-i,S.size());j++) {
				int k;
				for(k=j;k<min(T.size()-i,S.size());k++) if(T[i+k]!=S[k]) break;
				len=max(len,k-j);
				j=k;
			}
		}
		cout<<len<<endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
	ll la,lb,i,j,cnt,mx,p,pp,ii;
	char a[4001],b[4001],aa[4001],bb[4001];
	while(scanf("%s",a)!=EOF){
		cin>>b;
		la=strlen(a);
		lb=strlen(b);
		if(la<=lb){
			strcpy(aa,a);
			strcpy(bb,b);
		}
		else{
			swap(la,lb);
			strcpy(bb,a);
			strcpy(aa,b);
		}
		mx=0;
		cout<<"AAAAAAAAAAAAAAAAAAAAAAAAA"<<endl;
		for(i=1;lb-i>=0;i++){
			cnt=0;
			for(j=0;j<i;j++){
				if(bb[lb-i+j]==aa[j]) cnt++;
				else cnt=0;
				mx=max(mx,cnt);
			}
		}
		for(i=1;i<la;i++){
			cnt=0;
			for(j=0;j<lb-i;j++){
				if(aa[i+j]==bb[j]) cnt++;
				else cnt=0;
				mx=max(mx,cnt);
			}
		}
		cout<<mx<<endl;
	}
	return 0;
}