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 <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class SuffixArray {
	void CEB(vector<int> &v, vector<int> &b) {
		int vs = v.size(), bs = b.size();
		fill(b.begin(), b.end(), 0);
		for (int i = 0; i < vs; i++) b[v[i]]++;
		for (int i = 1; i < bs; i++) b[i] += b[i - 1];
	}
	void ISort(vector<int> &v, vector<int> &SA, int mv, vector<int> &b, vector<int> &isL) {
		int vs = v.size(), bs = b.size();
		fill(b.begin(), b.end(), 0);
		for (int i = 0; i < vs; i++) b[v[i]]++;
		int sum = 0;
		for (int i = 0; i < bs; i++) b[i] += sum, swap(sum, b[i]);
		for (int i = 0; i < vs; i++) {
			if (SA[i] > 0 && isL[SA[i] - 1]) SA[b[v[SA[i] - 1]]++] = SA[i] - 1;
		}
	}
	void IISort(vector<int> &v, vector<int> &SA, int mv, vector<int> &b, vector<int> &isL) {
		CEB(v, b);
		for (int i = v.size() - 1; i >= 0; i--) {
			if (SA[i] > 0 && !isL[SA[i] - 1]) SA[--b[v[SA[i] - 1]]] = SA[i] - 1;
		}
	}
	vector<int>SA_IS(vector<int> v, int mv) {
		int vs = v.size();
		if (vs == 1) return vector<int>(1, 0);
		vector<int> isL(vs), b(mv + 1), SA(vs, -1), ord(vs);
		auto isLMS = [&](int x)->bool { return x > 0 && isL[x - 1] && !isL[x]; };
		for (int i = vs - 2; i >= 0; i--) isL[i] = (v[i] > v[i + 1]) || (v[i] == v[i + 1] && isL[i + 1]);
		CEB(v, b);
		for (int i = 0; i < vs; i++) {
			if (isLMS(i)) SA[--b[v[i]]] = i;
		}
		ISort(v, SA, mv, b, isL);
		IISort(v, SA, mv, b, isL);
		int cur = 0;
		for (int i = 0; i < vs; i++) {
			if (isLMS(i)) ord[i] = cur++;
		}
		vector<int> nxv(cur);
		cur = -1;
		int prev = -1;
		for (int i = 0; i < vs; i++) {
			if (!isLMS(SA[i])) continue;
			bool diff = false;
			for (int d = 0; d < vs; d++) {
				if (prev == -1 || v[SA[i] + d] != v[prev + d] || isL[SA[i] + d] != isL[prev + d]) {
					diff = true;
					break;
				}
				else if (d && isLMS(SA[i] + d))break;
			}
			if (diff) cur++, prev = SA[i];
			nxv[ord[SA[i]]] = cur;
		}
		vector<int> reord(nxv.size());
		for (int i = 0; i < vs; i++) {
			if (isLMS(i)) reord[ord[i]] = i;
		}
		vector<int> nxSA = SA_IS(nxv, cur);
		CEB(v, b);
		for (int i = 0; i < SA.size(); i++) SA[i] = -1;
		for (int i = nxSA.size() - 1; i >= 0; i--) {
			SA[--b[v[reord[nxSA[i]]]]] = reord[nxSA[i]];
		}
		ISort(v, SA, mv, b, isL);
		IISort(v, SA, mv, b, isL);
		return SA;
	}
	vector<int>SA_IS(string s) {
		vector<int> v(s.size() + 1);
		for (int i = 0; i < s.size(); i++) v[i] = s[i] + 1;
		return SA_IS(v, *max_element(v.begin(), v.end()));
	}
	vector<int>construct_lcp(string &s, vector<int> &sa) {
		vector<int> lcp, rank(s.size() + 1);
		int n = s.size(), h = 0;
		for (int i = 0; i <= n; i++) rank[sa[i]] = i;
		for (int i = 0; i < n; i++) {
			int j = sa[rank[i] - 1];
			if (h) h--;
			for (; j + h < n && i + h < n; h++) {
				if (s[j + h] != s[i + h]) break;
			}
			lcp[rank[i] - 1] = h;
		}
		return lcp;
	}
public:
	string s;
	vector<int> sa, lcp;
	void init(string &T) {
		s = T;
		sa = SA_IS(s);
		lcp = construct_lcp(s, sa);
	}
	SuffixArray(string &t) { init(t); }
	SuffixArray() {}
	bool contain(string &t) {
		int a = 0, b = s.size();
		while (b - a > 1) {
			int c = (a + b) / 2;
			if (s.compare(sa[c], t.size(), t) < 0) a = c;
			else b = c;
		}
		return s.compare(sa[b], t.size(), t) == 0;
	}
};
string s, t;
int main() {
	while(cin >> s >> t) {
		SuffixArray v(s + string("$") + t);
		int ret = 0, e = s.size() + t.size() + 1;
		for(int i = 0; i < e; i++) {
			if((v.sa[i] < sl) != (v.sa[i + 1] < sl)) ret = max(ret, v.lcp[i])
		}
		cout << ret << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<string>
#include<queue>
#include<map>
using namespace std;

int main() {
	string a, b;
	while (cin >> a >> b) {
		int MAX = 0;
		for (int i = -((int)a.length()) + 1; i < (int)(b.length()); i++) {
			int k = 0;
			for (int j = 0; j < a.length(); j++) {
				if (i + j < 0 || i + j >= b.length() || a[j] != b[i + j])k = 0;
				else k++;
				MAX = max(MAX, k);
			}
		}
		cout << MAX << endl;
	}
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
template<class T> inline string toString(T x) {ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);


int main(){
	string s1,s2;
	while(cin>>s1>>s2,cin){
		int ans=0;
		int j=0;
		REP(i,s1.size()){
			j=max(j,i);
			string ss;
			while(j+1<s1.size()&&(ss=string(s1.begin()+i,s1.begin()+j+1),s2.find(ss)!=s2.npos)){
				j++;
				ans=max(ans,j-i);
			}
		}
		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[1000000]={}, 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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
short dp[4001][4001]={};
char str1[4005],str2[4005];
short ans=0;
int main(){
	while(scanf("%s",str1)!=EOF){
		scanf("%s",str2);
  for(int i=0;i<strlen(str1);i++){
    for(int j=0;j<strlen(str2);j++){
      if(str1[i]==str2[j]){
         if(i==0 || j==0){ dp[i][j]=1;ans=max(ans,dp[i][j]);} 
		 else{ dp[i][j]=1+dp[i-1][j-1];ans=max(ans,dp[i][j]);}
      }}}
  printf("%d\n",ans); }return 0;}

C++: #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int dp[4005][4005];
int main(){
	string s1, s2;
	while(cin >> s1 >> s2){
	s1 = " " + s1;s2 = " " + s2;
	fill((int*)dp, (int*)(dp+4005), 0);
	int ans = 0;
	for(int i = 1;i < s1.size();i++){
		for(int j = 1;j < s2.size();j++){
			if(s1[i] == s2[j])dp[i][j] = dp[i-1][j-1]+1;
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
	}
	return 0;
}