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;
#define Rep(i,N) for(int i = 0; i < N; i++)

int main()
{
  string S, W;
  while(cin >> S >> W) {
    int dp[4005] = {0};
    int maxv = 0;
    Rep(i,W.size()) {
      for(int j = S.size(); j > 0; j--) {
	if(S[j - 1] == W[i]) {
	  dp[j] = dp[j - 1] + 1;
	  maxv = max(maxv, dp[j]);
	} else dp[j] = 0;
      }
    }
  }
  cout << maxv << endl;
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
	char S1[5000], S2[5000];
	int l1, l2;
	for (; scanf("%s %s", S1, S2) != EOF;) {
		l1 = strlen(S1);
		l2 = strlen(S2);
		int ans = 0;

		for (int p = -(l1 - 1); p < l2; p++) {
			int count = 0;
			for (int i = max(p, 0);; i++) {
				if (S1[i - p] == '\0' || S2[i] == '\0') break;
				if (S1[i - p] == S2[i]) {
					count++;
				}
				else {
					count = 0;
				}
				ans = max(ans, count);
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	string s1,s2;
	cin >> s1;
	if(cin.eof()) break;
	cin >> s2;
	int ans = 0;
	int h = s1.size();
	int l = 0;
	int m = (h+l)/2;
	while(h-l>1){
	    bool flg = false;
	    set<string> ss;
	    REP(i,s1.size()-m){
		ss.insert(s1.substr(i,m));
	    }

	    REP(i,s2.size()-m){
		if(ss.find(s2.substr(i,m)) != ss.end()){
		    flg = true;
		}
	    }
	    if(flg){
		l = m;
	    }else{
		h = m;
	    }
	    m = (h+l)/2;
	}
	cout << m << endl;

    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
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.substr(i, k) == str2.substr(j, k)){
					if(i + k > str1.size() || j + k > str2.size()) break;
					count = max(count, k);
					k++;
					//cout << str2.substr(i, k) << endl;
				}
			}
		}
		cout << count << endl;
	}
}

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

int main(){
  string str1, str2;
  while(cin >> str1 >> str2){
    int ans=0;
    for(int i=0;i<str1.length();i++){
      string temp=str1.substr(i, str1.length()-i);
      int count=0;
      for(int j=0;j<min(temp.length(), str2.length());j++){
	if(temp[j]==str2[j]) count++;
	else count=0;
	ans=max(ans, count);
      }
    }
    for(int i=0;i<str2.length();i++){
      string temp=str2.substr(i, str2.length()-i);
      int count=0;
      for(int j=0;j<min(temp.length(), str1.length());j++){
	if(temp[j]==str1[j]) count++;
	else count=0;
	ans=max(ans, count);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)

int main() {
    string s, t;
    while(cin>>s>>t) {
        set<string> st;
        int n = s.size(), m = t.size();
        rep(i,n) {
            for(int len=1; i+len < n; len++) {
                st.insert(s.substr(i, len));
            }
        }

        int ans = 0;
        rep(i,m) {
            for(int len=1; i+len < m; len++) {
                if(st.count(t.substr(i,len)) == 0) continue;
                ans = max(ans, len);
            }
        }

        cout << ans << "\n";
    }

    return 0;
}

C++: #include <iostream>
#include <map>
#include <cstring>
using namespace std;
map<string,int> m;
int main(){
	string s,t;
	while(cin >> s >> t){
		int a=0,S=s.size(),T=t.size(),i,j;
		for(j=min(S,T);j>=1;j--){
			for(i=0;i<S-j;i++) m[s.substr(i,j)]++;
			for(i=0;i<T-j;i++) if(m[t.substr(i,j)]>=1) a=max(a,j);
			m.clear();
			if(a)break;
		}
		cout<<a<<endl;
	}
}

C++: //AOJ:0528 common sub-string
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s, t; int roop1, ans = 0, memo[4000][4000];
int main() {
	while (cin >> s >> t){
		ans = 0;
		for (int i = 0; i<s.size(); i++){
			for (int j = 0; j<t.size(); j++){
				if (s[i] == t[j]&&memo[i][j]==0){
					memo[i][j]=1;
					roop1 = 1;
					while (1){
						if (s[i + roop1] == 0 || t[j + roop1] == 0){
							break;
						}
						else{
							if (s[i + roop1] == t[j + roop1]){
								memo[i+roop1][j+roop1]=1;
								roop1++;
							}
							else if (s[i + roop1] != t[j + roop1]){
								break;
							}
						}
					}
					ans = max(ans, roop1);
				}
			}
		}
		cout << ans << endl;
	}
	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 dp[4444][4444];
int main(){
	while(cin>>s>>t){
		s="@"+s;
		t="@"+t;
		int ans=0;
		memset(dp,0,sizeof(dp));
		for(int i=1;i<s.size();i++){
			for(int j=1;j<t.size();j++){
				if(s[i]==t[j])dp[i][j]=dp[i-1][j-1]+1;
				ans=max(ans,dp[i][j]);
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>

#define reps(i,j,k) for(int i = j; i < k ;i++)
#define rep(i,j) reps(i,0,j)

using namespace std;
int dp[4012][4012];
int main(){
    string str1,str2;
    while(cin >> str1 >> str2){
        memset(dp,0,sizeof(dp));
        int h = str1.size();
        int w = str2.size();
        int ma = -100000;
        rep(i,h){
            rep(j,w){
                if(i==0 && str1[i] == str2[j])dp[i][j] = 1;
                else if(j == 0 && str1[i] == str2[j])dp[i][j] = 1;
                else if(str1[i] == str2[j])dp[i][j] += dp[i-1][j-1]+1;
                ma = max(ma,dp[i][j]);
            }
        }
        printf("%d\n",ma);
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);
#define sintttt(i,j,k,m) scanf("%d%d%d%d",&i,&j,&k,&m);

#define INF 1010000000
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

short dp[4001][4001];

int main(){
	while(1){
		string a,b;
		cin>>a>>b;
		
		if(b.size()==0){
			break;
		}
		
		rep(i,4001)rep(j,4001)dp[i][j]=0;
		
		int maxi=0;
		reps(i,a.size()){
			reps(j,b.size()){
				if(a[i-1]==b[j-1]){
					dp[i][j]=dp[i-1][j-1]+1;
				}
				maxi=max(maxi,dp[i][j]);
			}
		}
		
		printf("%d\n",maxi);
	}
}