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 <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;
    while (cin >> s >> t) {
        int n = s.size(), m = t.size();
        auto dp = make_v(n + 1, m + 1, 0);
        int ans = 0;
        REP(i, 0, n) {
            REP(j, 0, m) {
                if (s[i] == t[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<stdio.h>
#include<string.h>
int main()
{
	char a[4001],b[4001];
	while(scanf("%s%s",a,b)>0)
	{
		static int x[2][4001],i,j,s,t,r,c;
		s=strlen(a),t=strlen(b);
		for(r=j=0;j<=t;++j)x[0][j]=0;
		for(c=i=0;i<s;++i,c=!c)for(j=0;j<t;++j)
			if(a[i]==b[j])r=(r>(x[!c][j+1]=x[c][j]+1)?r:x[!c][j+1]);
		printf("%d\n",r);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
  for (;;) {
    string a, b;
    if (!(cin >> a)) return 0;
    cin >> b;
    int result = 0, dp[4001];
    fill(dp, dp+b.length()+1, 0);
    for (int i = 0; i < a.length(); i++)
      for (int j = b.length()-1; j >= 0; j--)
        if (a[i] == b[j]) {
          dp[j+1] = dp[j] + 1;
          if (dp[j+1] > result)
            result = dp[j+1];
        } else dp[j] = 0;
    cout << result << endl;
  }
}

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

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

int main() {
	while(1){
		string a,b;
    	cin>>a>>b;
    	int n,m,last=0,now=0,c;
    	n=a.size();
    	m=b.size();
	    if(n==0&&m==0) break;
	    
    	for(int i=0;i<n;i++){
    		c=i;
			for(int j=0;j<m;j++){
				if(a[c]==b[j]){
					c++;
					last++;
				}else {
					now=max(last,now);
				    last=0;
				}
			}
		}
	cout<<now<<endl;
	}
	return 0;
}

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

int main() {
  string s,t;
  while(cin >> s >>t){
    for(int i=0;i<s.size();i++)
      for(int j=0;j<t.size();j++) dp[i][j] = 0;

    int ans=0;
    for(int i=0;i<s.size();i++)
      for(int j=0;j<t.size();j++)
	if(s[i]==t[j]) dp[i+1][j+1] = dp[i][j]+1,ans=max(ans,dp[i][j]+1);
    cout << ans <<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s, t; int roop1, save, ans = 0;
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]){
                roop1 = 1;
                save = 1;
                while (1){
                    if (s[i + roop1] == 0|| t[j + roop1] ==0){
                    	j+=roop1-1;
                        break;
                    }
                    else{
                    if (s[i + roop1] == t[j + roop1]){
                            save += 1;
                            roop1++;
                        }
                        else if (s[i + roop1] != t[j + roop1]){
                        	j += roop1 - 1;
                            break;
                        }
                    }
                }
                ans=max(ans,save);
            }
        }
    }
    cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int dp[4010][4010];

int main(){
	string s, t;
	while(cin>>s>>t){
		rep(i, 4010) rep(j, 4010) 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;
				else dp[i + 1][j + 1] = 0;
			}
		}
		int ans = 0;
		rep(i, s.size()+1) rep(j, t.size()+1) ans = max(ans, dp[i][j]);
		printf("%d\n", ans);
	}
}

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()-1 ; i++ ){
      for(int j = 0 ; j < b.size()-1 ; 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 <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    string s, t;
    while (cin >> s >> t){
        int ans = 0;
        for (int i = -(int)s.length(); i <= (int)t.length(); ++i) {
            int l = 0;
            for (int j = max(i, 0); j < min(s.length()+i, t.length()); ++j) {
                if(s[j-i] == t[j]){
                    l++;
                    ans = max(ans, l);
                } else l = 0;
            }

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