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 <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    string n, m;
    while(cin >> n >> m){
        int ans = 0;
        if(n.size() > m.size()) swap(n, m);
        for(int i=0; i < n.size(); i++){
            for(int j=i+1; j < n.size(); j++){
                string s = n.substr(i, j-i);
                if(m.find(s) != string::npos)ans = max(ans, (int)s.size());
                else {i++; j = i;}
            }
        }
        cout << ans << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, bool> PIB;

int dp[4001][4001];
string s, t;
int ans = 0;

int main()
{
  while(true){
    cin >> s;
    if(!s.size())
      break;
    cin >> t;
    ans = 0;
    memset(dp, 0, sizeof dp);

    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 + 1][j + 1]);
	}
    
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

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

typedef vector<int> vi;

int solve(string const& s, string const& t){
    int m=s.size(), n=t.size();
    int ans = -1;
    vi prev(n+1);
    rep(i,m){
        vi cur(n+1);
        rep(j,n){
            if(s[i]==t[j])cur[j+1]=prev[j]+1;
            ans = max(ans,cur[j+1]);
        }
        swap(cur,prev);
    }
    return ans;
}

int main(){
    string s,t;
    while(cin>>s>>t){
        cout << solve(s,t) << endl;
    }
}

C++: #include<stdio.h>
#include<string.h>
unsigned short d[4000][4000];
char a[4000],b[4000];
int i,j;

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){
	while(scanf("%s",&a)!=EOF){
		scanf("%s",&b);
		for(i=0;i<strlen(a);i++)for(j=0;j<strlen(b);j++)d[i][j]=0;
		for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++){
				if(a[i]==b[j]){
					if(i>0&&j>0)d[i][j]=d[i-1][j-1]+1;
					else d[i][j]=1;
				}
				else{
					d[i][j]=0;
				}
			}
		}
		/*for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++)printf("%d ",d[i][j]);
			printf("\n");
		}
		printf("\n");*/
		int ans=0;
		for(i=0;i<strlen(a);i++)for(j=0;j<strlen(b);j++)ans=max(ans,d[i][j]);
		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;
	REP(i,s1.size()){
	    char h = s1[i];
	    REP(j,s2.size()){
		if(s2[j] == h){
		    int temp = 0;
		    FOR(k,j,s2.size()){
			if(s1[i+k-j] == s2[k]) {
			    temp++;
			}else break;
		    }
		    ans = max(ans,temp);
		}
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

C++: #include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string s, t;
int dp[4123][4123];
int ans;

int main()
{
	while (true)
	{
		s.clear(); t.clear();
		memset(dp, 0, sizeof(dp));
		ans = 0;

		in >> s >> t;
		if (s.empty()) { break; }

		rep(i, s.length())
		{
			rep(j, t.length())
			{
				if (s[i] == t[j]) { dp[i + 1][j + 1] = dp[i][j] + 1; }
				else { dp[i + 1][j + 1] = 0; }
			}
		}
		rep(i, s.length() + 1)
		{
			rep(j, t.length() + 1)
			{
				ans = std::max(ans, dp[i][j]);
			}
		}

		out << ans << std::endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
int main(void){
	char s[4001],t[4001];
	while(scanf("%s",s)!=EOF){
		scanf("%s",t);
		int sl = strlen(s),tl = strlen(t);
		int ans = 0;
		for(int i=0;i+ans<sl;i++){
			for(int j=0;j+ans<tl;j++){
				if(s[i]==t[j]){
					for(int k=1;j+k<tl && i+k<sl;k++){
						ans = max(ans,k);
						if(s[i+k]!=t[j+k])break;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double EPS=1e-9;
const long long INF = 100001000010000100ll;

template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;


string L, R;

int dp[4000+10][4000+10];

int main(){
	while(cin >> L >> R){
		memset(dp, 0, sizeof(dp));
		int ans=0;
		rp(i, R){
			rp(j, L){
				if(R[i]==L[j]){
					dp[i][j] = dp[i-1][j-1] + 1;
				}else{
					dp[i][j]=0;
				}
				ans=max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;
	}

	return 0;

}