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<iostream>
#include<string>
#include<algorithm>
using namespace std;

#define MAX 4001

string str1, str2;

void lcs(){
    int T[MAX], NT[MAX];
    int h = str1.size();
    int w = str2.size();

    for ( int j = 0; j <= w; j++ ) T[j] = 0;

    int ans = 0;
    for ( int i = 1; i < h; i++ ){
	for ( int j = 1; j < w; j++ ){
	    if ( str1[i] == str2[j] ){
		NT[j] = T[j-1] + 1;
		ans = max(ans, NT[j]);
	    } else {
		NT[j] = 0;
	    }
	}
	for ( int j = 1; j < w; j++ ) T[j] = NT[j];
    }
    cout << ans << endl;
}

main(){
    while( cin >> str1 ){
	cin >> str2;
	str1 = ' ' + str1;
	str2 = ' ' + str2;
	lcs();
    }
}

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=0, 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= 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						if (s[i + roop1] == t[j + roop1]){
							save += 1;
							roop1++;
						}
					else if (s[i + roop1] != t[j + roop1]){
							ans=max(ans,save);
							break;
						}
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	}
	
	return 0;
}

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

using namespace std;

int main()
{
	string S, T;

	cin >> S >> T;

	vector<vector<int> > dp(T.size() + 1, vector<int>(S.size() + 1, 0));

	for (int i = 0; i <= S.size(); i++) { dp[0][i] = 0; }
	for (int i = 0; i <= T.size(); i++) { dp[i][0] = 0; }

	for (int i = 1; i <= T.size(); i++)
	{
		for (int j = 1; j <= S.size(); j++)
		{
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

			if (T[i] == S[j])
			{
				dp[i][j]++;
			}
		}
	}

	printf("%d\n", dp[T.size()][S.size()]);

	return 0;
}

C++: #include<iostream>

using namespace std;

int find(const string& s1, const string& s2, int n){

  int tmp = 0;
  int res = 0;

  for(int i = 0; i < n; i++){
    int pos1 = s1.length()-n+i;
    if(s1[pos1] != s2[i]){
      res = max(res,tmp);
      tmp = 0;
    }else{
      tmp++;
    }
  }
  return max(tmp,res);
}

int main(){
  
  string s1,s2;
  while(getline(cin,s1) && getline(cin,s2)){
    int roop = min(s1.length(),s2.length());
    int ans = 0;
    for(int i = 0; i <= roop; i++){
      ans = max(ans,find(s1,s2,i));
    }

    cout << ans << endl;
  }
  return 0;
}

C++: 
#include <iostream>
using namespace std;
int krsw[4001][4001];
int main() {
    string s1, s2;
    while(cin >> s1 >> s2) {
        int unco = 0;
        for(int i = 0; i < 4001; i++){
            for(int j = 0; j < 4001; j++) {
                krsw[i][j] = 0;
            }
        }
        for (int i = 1; i <= s1.size(); i++) {
            for (int j = 1; j <= s2.size(); j++) {
                if(s1[i - 1] == s2[j - 1]) {
                    krsw[i][j] = krsw[i - 1][j - 1] + 1;
                    unco = max(unco,krsw[i][j]);
                }
            }
        }
        cout << unco << endl;
    }
    return 0;
}

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, save=0, ans = 0;
		cin>>s;
		cin>>t;
		if(s==""){
		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= 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						if (s[i + roop1] == t[j + roop1]){
							save += 1;
							roop1++;
						}
					else if (s[i + roop1] != t[j + roop1]){
							ans=max(ans,save);
							break;
						}
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	}
	
	return 0;
}

C++: #include<iostream>

int main(){
	std::string a, b;
	while(std::cin >> a >> b, !std::cin.eof()){
		int max_l = 0;
		for(int i=0;i<a.size();i++){//iを先頭とする
			int l = 0;
			for(int j=0;j<b.size();j++){
				if(a[l+i] == b[j]){
					l++;
				}else{
					max_l = std::max(max_l, l?l+1:0);
					l = 0;
				}
			}
		}

		std::cout << max_l << std::endl;
	}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,s2;
  while(cin >> s >> s2){
    ll ans = 0;
    rep(i,s.size()){
      ll len = 0;
      for(int j = 0; j < s2.size();){
        if(s[i+len] == s2[j+len]){
          len++;
          if(i+len >= s.size() || j+len >= s2.size()) break;
        }
        else{
          ans = max(len,ans);
          len = 0;
          ++j;
        }
      }
      ans = max(len,ans);
    }
    cout << ans << endl;
  }
  return 0;
}

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

struct Trie{
	Trie *next[32];
	Trie(){ fill(next,next+32,(Trie*)0); }
};
void Add(Trie *head , char *text){
	for(int i = 0;text[i] != '\0';++i){
		if(head->next[text[i]-'a'] == NULL) head->next[text[i]-'a'] = new Trie;
		head = head->next[text[i]-'a'];
	}
}
int search(Trie *head , char *text){
	int cnt = 0;
	for(int i = 0;text[i] != '\0';++i){
		if(head->next[text[i]-'a'] == NULL) return cnt;
		head = head->next[text[i]-'a'];
		cnt++;
	}
	return cnt;
}
char a[4001],b[4001];
int main(){
	while(cin >> a >> b){
		int n = strlen(a);
		int m = strlen(b);
		int ans = 0;
		Trie *head = new Trie;
		
		for(int i = 0 ; i < n ; i++) Add(head,a+i);
		for(int i = 0 ; i < m ; i++) ans = max( search(head,b+i) , ans);
		cout << ans << endl;
	}
}