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

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()

		dp := make([][]int, len(S)+1)
		for i := range dp {
			dp[i] = make([]int, len(T)+1)
		}

		dp[0][0] = 0
		for i := range S {
			for j := range T {
				if S[i] == T[j] {
					dp[i+1][j+1] = max(dp[i+1][j], max(dp[i][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>
using namespace std;
int ans,s1,s2,text_here,patn_here,text_len,patn_len;
string str1,str2;

int main(){

    while(cin >> str1){
            cin >> str2;

            int s1=str1.size();
            int s2=0;

        while(s1!=0 || s2<str2.size()){

            if(s1!=0){
                s1--;
            }else{
                s2++;
            }
            text_here=0;
            patn_here=0;
            text_len=str1.size();
            patn_len=str2.size();

            while(text_here<text_len && patn_here<patn_len){
                if(str1[s1+text_here]==str2[s2+patn_here]){
                    patn_here++;
                    text_here++;
                    //cout << str1[s1+text_here] << endl;
                    ans=max(patn_here,ans);
                }else{
                    text_here++;
                    patn_here=0;
                }

            }
        }
        cout << ans << endl;
        ans=0;
    }

return 0 ;
}

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(str1[j - off_] == str2[j]){
					len++;
				}else{
					len = 0;
				}
				if(ans < len){
					ans = len;
				}
			}
		}
		
		printf("%d\n", ans);
		
	}
	return 0;
}

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

char A[4002],B[4002];
short int length[4000][4000];
int mmax[200],mcor = 0;
int main(){
	int i,j,lenA,lenB;
	while(cin >> A[0]){
		cin >> A+1;
		cin >> B;
		lenA = strlen(A)-1;
		lenB = strlen(B)-1;
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				length[i][j] = -1;
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				if(length[i][j] >= 0)continue;
				for(int k = 0;i+k < lenA && i+k < lenB;k++){
						if(A[i+k] != B[i+k]){
							length[i][j] = k;
							break;
						}
				}
			}
		}
		for(i = 0;i < lenA;i++){
			for(j = 0;j < lenB;j++){
				if(mmax[mcor] < length[i][j])
					mmax[mcor] = length[i][j];
			}
		}
		mcor++;
	}
	for(i = 0;i < mcor;i++){
		cout << mmax[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s, t;
int dp[10000][10000];

int main(){
	int MAX = -1;
	cin >> s >> t;
	REP(i, s.size()){
		REP(j, t.size()){
			if (s[i] == t[j]){
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			MAX = max(MAX, dp[i + 1][j + 1]);
		}
	}
	cout << MAX << endl;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    while (cin >> s >> t) {
        int ssize = s.length();
        int tsize = t.length();
        vector<vector<string>> ss(ssize + 1), tt(tsize + 1);
        rep(i, ssize)rep(j, ssize - i + 1) ss[j].pb(s.substr(i, j));
        rep(i, tsize)rep(j, tsize - i + 1) tt[j].pb(t.substr(i, j));
        int low = 0;
        int high = max(ssize, tsize) + 1;
        while (high - low > 1) {
            int mid = (high + low) / 2;
            bool ok = false;
            if (mid > ssize || mid > tsize) {high = mid; continue;}
            rep(i, ss[mid].size())rep(j, tt[mid].size()) {
                if (ss[mid][i] == tt[mid][j]) {
                    ok = true;
                    break;
                }
            }
            if (ok) low = mid;
            else high = mid;
        }
        cout << low << endl;
    }
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

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

int main(){
	while(cin >> s >> t){
		rep(i, s.size() + 1){
			dp[i][0] = 0;
		}
		rep(i, t.size() + 1){
			dp[0][i] = 0;
		}
		for(int i = 1; i <= s.size(); ++i){
			for(int j = 1; j <= t.size(); ++j){
				dp[i][j] = s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] + 1 : 0;
			}
		}
		int ans = 0;
		rep(i, s.size()){
			ans = max(*max_element(dp[i], dp[i] + t.size() + 1), ans);
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
vector<int>v[26][2];
int main() {
	string a, b;
	while (cin >> a >> b) {
		for (int i = 0; i < 26; i++) {
			v[i][0].clear();
			v[i][1].clear();
		}
		for (int i = 0; i < a.length(); i++) {
			int k = (int)a[i] - 'A';
			v[k][0].push_back(i);
		}
		for (int i = 0; i < b.length(); i++) {
			int k = (int)b[i] - 'A';
			v[k][1].push_back(i);
		}
		int sum = 0;
		for (int i = 0; i < 26; i++) {
			for (int j = 0; j < v[i][0].size(); j++) {
				for (int x = 0; x < v[i][1].size(); x++) {
					int a2 = v[i][0][j], b2 = v[i][1][x];
					int sum2 = 0;
					while (a[a2] == b[b2]&&a2<a.length()&&b2<b.length()) {
						sum2++;
						a2++;
						b2++;
					}
					sum = max(sum, sum2);
				}
			}
		}
		cout << sum << endl;
	}
}