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 <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <cstring>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int memo[4040][4040] = {};
int main(void){
	string s, t;
	while(cin >> s && s.size()){
		int res = 0;
		cin >> t;
		REP(i, s.size()){
			REP(j, t.size()){
				if(memo[i][j] != 0) continue;
				int cnt = 0;
				if(s[i] == t[j]){
					cnt++;
					memo[i][j] = cnt;
					while(s[i+cnt] == t[j+cnt] && i+cnt < s.size() && j+cnt < t.size()){
						cnt++;
						memo[i+cnt][j+cnt] = cnt;
					}
					res = max(res, cnt);
				}
			}
		}
		cout << res << endl;
	}
}

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;
	}
}

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

C++: #include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int left_length,right_length,max,tmp;
	char left[4001],right[4001];

	while(scanf("%s",left) != EOF){
		scanf("%s",right);

		for(left_length = 0;left[left_length] != '\0';left_length++);
		for(right_length = 0; right[right_length] != '\0';right_length++);

		max = 0;
		if(right_length > left_length){
			tmp = 0;
			for(int i = 0; i < right_length; i++){
				for(int k = 0; k < left_length && i+k < right_length; k++){
					if(left[k] == right[i+k])tmp++;
					else{
						max = (max >= tmp)?max:tmp;
						tmp = 0;
					}
				}
			}
			printf("%d\n",max);
		}else{
			tmp = 0;
			for(int i = 0; i < left_length; i++){
				for(int k = 0; k < right_length && i+k < left_length; k++){
					if(right[k] == left[i+k])tmp++;
					else{
						max = (max >= tmp)?max:tmp;
						tmp = 0;
					}
				}
			}
			printf("%d\n",max);
		}
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  string s, t;
  while(cin >> s >> t) {
    int l = -1, r = min(s.size() + 1, t.size() + 1);
    while(l + 1 < r) {
      int m = l + (r - l) / 2;
      bool flag = false;
      Rep(i,s.size() - m + 1) {
	string w;
	Rep(j,m)w += s[i + j];
	if(t.find(w) != string::npos) {
	  flag = true;
	  break;
	}
      }
      if(flag)l = m;
      else r = m;
    }
    cout << l << endl;
  }
  return 0;
}