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 <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>

using namespace std;

#define rep(i, n)      for (int i=0; i<int(n); i++)
#define rep3(i, s, n)  for (int i=int(s); i<int(n); i++)
#define rev_rep(i, n)  for (int i=int(n)-1; i>=0; i-=1)

char s[4010];
char t[4010];
int dp[4010][4010];
int main() {
  while (cin >> s >> t) {
  int s_len = strlen(s), t_len = strlen(t);
  rep(i, s_len) {
    rep(j, t_len) {
      if (s[i] == t[j]) dp[i][j] = ((i>1&&j>1) ? dp[i-1][j-1] : 0) + 1;
      else              dp[i][j] = 0;
    }
  }
  int ans = 0;
  rep(i, s_len) {
    rep (j, t_len) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << "\n";
  }
  return 0;
}

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

int main(){
string a,b;
while(cin >> a >> b){
	set< deque<char> > e;
	e.insert(deque<char>(0));
	if( a.length() > b.length() )swap(a,b);
	
	for(int i = 0 ; i < b.length() ; i++){
		deque<char> s;
		for(int j = i ; j < b.length() ; j++){
			s.push_back(b[j]);
			e.insert(s);
		}
	}
	deque<char> cur;
	int l = 0 , r = 0;
	int ans = 0;
	while(r <= a.length() ){
		if( e.find(cur) != e.end() ){
			ans = max<int>(ans,cur.size());
			if(r != a.length())cur.push_back(a[r]);
			r++; 
		}else{
			cur.pop_front();
			l++;
		}
	}
	cout << ans << endl;
}
}

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[60000]={}, 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 <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int main() {
    while(true) {
        static char s1[5000], s2[5000];
        if(scanf("%s %s ", s1, s2) < 2) break;
        //printf("%s, %s\n", s1, s2);
        int s1l = strlen(s1);
        int s2l = strlen(s2);
        int max_len = 0;
        for(int off = -s2l; off <= s1l; off++) {
            int cur_len = 0;
            for(int i = max(0,-off); i < min(s1l,s2l-off); i++) {
                //printf("[%2d,%2d] ", i, i+off);
                //if(s1[i]==s2[i+off]) printf("%c==%c\n",s1[i],s2[i+off]);
                if(s1[i] == s2[i+off])
                    cur_len++;
                else
                    cur_len = 0;
                max_len = max(max_len, cur_len);
            }
            //printf("\n");
        }
        printf("%d\n", max_len);
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

void solve(string s, string t) {
	if(s.length() > t.length()) swap(s, t);
	for(int i=s.length(); i>=1; i--) {
		for(int j=0; j+i<s.length(); j++) {
			string ss = s.substr(j,i);
			if( t.find(ss) != string::npos ) {
				cout << i << endl;
				return;
			}
		}
	}
	cout << 0 << endl;
}

int main() {
	string s, t;
	while(cin >> s >> t) {
		solve(s,t);
	}
	return 0;
}

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

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	for(string a, b; cin >> a;) {
		cin >> b;

		vector<vector<int> > dp(a.size() + 1, vector<int>(b.size() + 1, 0));
		for(int i = 0; i < a.size(); ++i)
			for(int j = 0; j < b.size(); ++j)
				if(a[i] == b[j])
					chmax(dp[i + 1][j + 1], dp[i][j] + 1);

		int ans = 0;
		for(int i = 0; i < dp.size(); ++i)
			chmax(ans, *max_element(dp[i].begin(), dp[i].end()));

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}