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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    char a[4002],b[4002];
    while(scanf("%s\n%s\n",a,b)!=-1){
        int asize=strlen(a),bsize=strlen(b);
        int ma=0;
        for(int i=0;i<asize;i++){
            int miat=min(bsize,asize-i);
            bool is=false;
            int now=0;
            for(int j=0;j<miat;j++){
                if(!is&&a[i+j]==b[j]){
                    now++;
                    is=true;
                }else if(is&&a[i+j]==b[j])now++;
                else if(is&&a[i+j]!=b[j]){
                    ma=max(ma,now);
                    now=0;
                    is=false;
                }
            }
            ma=max(now,ma);
        }
        printf("%d\n",ma);
    }
}

C++: #include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
const int N = 4000;
int opt[N][N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    while(cin >> s >> t) {
        int ans = 0;
        for(int i = 0; i < s.size(); i++) {
            for(int j = 0; j < t.size(); j++) {
                ans = max(ans, opt[i][j] = s[i] == t[j] ? 1 + (i and j ? opt[i-1][j-1] : 0) : 0);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

string s, t;
char tmp[4001];
int dp[4001][4001];

int main(){
	while(scanf("%s", tmp) != EOF){

		s = tmp;
		scanf("%s", tmp);
		t = tmp;

		for(int i=0; i<4001; i++)
			for(int j=0; j<4001; j++)
				dp[i][j] = 0;

		int ans = 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;
				}
				ans = max(ans, dp[i][j]);
			}
		}

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

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
string s[2];
int search(int id){
  int id2 = (id+1)%2;
  int ret=0;
  int a[40004];
  for(int j=(int)s[id2].size()-1;j>-(int)s[id].size();j--){
    memset(a,0,sizeof(a));
    for(int i=0;i<(int)s[id].size();i++){
      if(i+j < 0) continue;
      if(i+j >= (int)s[id2].size()) continue;
      if(s[id][i]==s[id2][i+j]) a[i]=1;
    }
    int co=0;
    for(int i=0;i<(int)s[id].size()+1;i++){
      if(a[i]) co++;
      else{
	ret = max(ret,co);
	co=0;
      }
    }
  }
  return ret;
}
int main(){
  while(cin >> s[0]){
    cin >> s[1];
    printf("%d\n",max(search(0),search(1)));
  }
}

C++: //Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#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 s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int dp[4005][4005];
char a[4005],b[4005];
int main()
{
	while(scanf("%s",&a)!=EOF)
	{

		scanf("%s",&b);
		memset(dp,0,sizeof(0));
		
		int as=strlen(a); int bs=strlen(b);
		int ret=0;
		for(int i=1;i<=as;i++)
		{
			for(int j=1;j<=bs;j++)
			{
				if(a[i-1]==b[j-1]) dp[i][j]=max(max(dp[i][j-1],dp[i][j]),max(dp[i-1][j-1]+1,dp[i-1][j]));
				else dp[i][j]=0;
				ret=max(ret,dp[i][j]);
			}
			
		}
		printf("%d\n",ret);
	}
	
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	
	string str1, str2;
	
	while(true){
		
		cin >> str1;
		
		if(cin.eof()){
			break;
		}
		
		cin >> str2;
		
		int ans, len;
		ans = 0;
		
		int s1, s2;
		s1 = str1.size();
		s2 = str2.size();
		
		for(int off_ = -s1; off_ < s2; off_++){
			len = 0;
			for(int j = max(0, off_); j < min(s1 + off_, s2) ; j++){
				if(ans < len){
					ans = len;
				}
				if(str1[j - off_] == str2[j]){
					len++;
				}else{
					len = 0;
				}
			}
		}
		
		printf("%d\n", ans);
		
	}
	return 0;
}

C++: #include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int dp[4001][4001];

int main(){
  string a,b;

  while(cin >> a >> b){

    memset(dp,0,sizeof(dp));
    int mx = 0;
    for(int i = 0 ; i < a.size() ; i++ ){
      for(int j = 0 ; j < b.size() ; j++ ){
	if(a[i] == b[j]){
	  dp[i+1][j+1] = dp[i][j] + 1;
	  if(mx < dp[i+1][j+1])mx = max(mx,dp[i+1][j+1]);
	} else {
	  dp[i+1][j+1] = 0;
	}
      }
    }
    cout << mx << endl;
  }
  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 x,a=0,b,S=s.size(),T=t.size(),i,j;
		b=min(S,T)+1;
		while(true){
			x=0;
			j=(a+b)/2;
			if(b-a==1) break;
			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) x++;
			m.clear();
			if(!x) b=j;
			else a=j;
		}
		cout<<a<<endl;
	}
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

#define MAX_S 4000
#define MAX_T 4000
template<typename T> int longest_common_substring(T s,T t){
    int lens=s.size(), lent=t.size();
    int dp[MAX_S+1][MAX_T+1]={};
    int maxi=0;
    
    rep(i,s.size()){
        rep(j,t.size()){
            if(s[i]==t[j])  dp[i+1][j+1] = dp[i][j]+1;
            else            dp[i+1][j+1] = 0;
            maxi = max(maxi,dp[i+1][j+1]);
        }
    }
    
    return maxi;
}


int main(){
    string a,b;
    while(cin>>a>>b){
        cout<<longest_common_substring(a,b)<<endl;
    }
}