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"bits/stdc++.h"
#include<iostream>
#include<ostream>
#include<vector>
#include<string>
#include<algorithm>

#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)


using namespace std;
using ll = long long;

void solve();

int main() {

   solve();
   return 0;

}

void solve() {

	string s, t;
	
	while (cin >> s >> t) {
		ll ans=0;
		vector<vector<ll>> dp;
		dp.resize(s.size()+1);
		REP(i, dp.size()) {
			dp[i].resize(t.size()+1);
			REP(j, dp[i].size()) {
				dp[i][j] = 0;
			}
		}
		REP(i, s.size()) {
			REP(j, t.size()) {
				if (s[i] == t[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
					//cout << "match" << endl;
				}
					ans = max(ans, dp[i+1][j+1]);
				
			}
		}
		//ans = max(ans, dp[s.size()][t.size()]);
		cout << ans << endl;

	}

}

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


int main(){
    string a, b;
    while (cin >> a >> b){
	if (a.size() > b.size()) swap(a, b);
	int max = 0;
	for (int index = 0; index < a.size(); index++){
	    for (int size = a.size(); size >= 1; size--){
		if (b.find(a.substr(index, size)) != -1){
		    if (max < a.substr(index, size).size())
			max = a.substr(index, size).size();
		}
	    }
	}
	cout << max << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int getlength(int,int,string&,string&);
int main(){
    string a,b;
    while(cin>>a>>b){
        a.push_back('a');
        b.push_back('b');
        int ans =0;
        for(int i=0;i<a.size()-1;++i){
            for(int j=0;j<b.size()-1;++j){
                ans = max(ans,getlength(i,j,a,b));
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

int getlength(int ap,int bp,string&a,string&b){
    int res=0;
    while(a[ap+res]==b[bp+res]){
        ++res;
    }
    return res;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(1){
		string s, t; int roop1=0, roop2 = 0, save[640000]={}, ans = 0;
		cin>>s;
		cin>>t;
		if(cin.eof())
		break;
	for (int i = 0; i<s.size(); i++){
		for (int j = 0; j<t.size(); j++){
			if (s[i] == t[j]){
				roop1 = 0;
				save[roop2] = 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						if (s[i + roop1] == t[j + roop1]){
							save[roop2] += 1;
							roop1++;
						}
						else if (s[i + roop1] != t[j + roop1]){
							roop2++;
							break;
						}
					}
				}
			}
		}
	}
	sort(save, save + roop2 + 1);
	ans = save[roop2];
	cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long int64;
const int inf = (int)1e9;

int main()
{
	while(true) {
		
		char str1[4096], str2[4096];
		
		if(scanf("%s", str1) == EOF)
			break;
		scanf("%s", str2);
		
		int len1 = strlen(str1), len2 = strlen(str2);
		int ans = 0;
		static int dp[4096][4096] = {0};
		
		for(int i = 0; i <= len1; ++i)
			dp[i][0] = 0;
		for(int i = 0; i <= len2; ++i)
			dp[0][i] = 0;
		
		for(int i = 1; i <= len1; ++i) {
			for(int j = 1; j <= len2; ++j) {
				if(str1[i - 1] == str2[j - 1]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
					ans = max(dp[i][j], ans);
				} else {
					dp[i][j] = 0;
				}
			}
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}

/* ハラスメントに負けず */
/* 0完太陽にも負けず */
/* はやく人権を獲得したい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	char a[4000],b[4000];
	while(scanf("%s",a)!=EOF){
		scanf("%s",b);
	int t[4002][4002];
	for(int i=0;i<=strlen(a);i++){
		t[0][i]=0;
	}
	for(int j=0;j<=strlen(b);j++){
		t[j][0]=0;
	}
	int ans=0;
	for(int i=1;i<=strlen(a);i++){
		for(int j=1;j<=strlen(b);j++){
			if(a[i-1]==b[j-1])t[i][j]=t[i-1][j-1]+1;
			else t[i][j]=0;
			ans=max(ans,t[i][j]);
		}
	}

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

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

using namespace std;

string scan_string() {
    char input[4000];

    if (scanf("%s", input) == EOF) {
        return "";
    }

    return string(input);
}

int main() {
    while (1) {
        int i;
        int n;
        string str1;
        string str2 = "";
        int max_sum = 0;

        str1 = scan_string();
        if (str1 == string("")) return 0;

        for (i=0;i<str1.length();i++) {
            str2 += " ";
        }
        str2 += scan_string();

        n = str2.length();
        for (i=0;i<n;i++) {
            int j;
            string str3 = str2.substr(i, n-i);
            int sum = 0;

            for (j=0;j<n-i;j++) {
                if (str1[j] == str3[j]) {
                    sum++;
                } else {
                    if (max_sum < sum) max_sum = sum;
                    sum = 0;
                }
            }
            if (max_sum < sum) max_sum = sum;
        }

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

C++: #include<iostream>
 
using namespace std;
 
int solve(const string& s1, const string& s2, int l1, int l2){
  int tmp = 0;
  int res = 0;
  int len = min(s2.length()-l2,s1.length()-l1);
  for(int i = 0; i < len; i++){
    if(s1[l1+i] != s2[l2+i]){
      res = max(res,tmp);
      tmp = 0;
    }else{
      tmp++;
    }
  }
  return max(tmp,res);
}
 
int main(){
   
  string s1,s2;
  int l1,l2,ans;
  while(1) {
  	if(cin.eof()) {
  		break;
  	}
  	cin >> s1;
  	cin >> s2;
  	l1 = s1.length();
  	l2 = 0;
  	ans = 0;
  	while(l1 != 0 || l2 <= s2.length()) {

      if(l1 != 0){
      	l1--;
      } else {
      	l2++;
      }
      ans = max(ans,solve(s1,s2,l1,l2));
  	}
    cout << ans << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  int dp[4005][4005];
  string s, t;
  while(cin >> s >> t) {
    fill(dp[0],dp[4005],0);
    int ss = s.size(), ts = t.size();
    int maxv = 0;
    Rep(i,ts) {
      Rep(j,ss) {
	if(s[j] == t[i]) {
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	  chmax(maxv,dp[i + 1][j + 1]);
	}
      }
    }
    cout << maxv << endl;
  }
  return 0;
}