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 <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
 
template <intmax_t X = 943681729, intmax_t MOD = 1000000007>
class rolling_hash {
  std::vector<intmax_t> hash, offset;
 
public:
  rolling_hash(const std::string& s): hash(s.length()+1), offset(s.length()+1) {
    for (size_t i = 0; i < s.length(); ++i)
      hash[i+1] = (hash[i]*X+s[i]) % MOD;
 
    offset[0] = 1;
    for (size_t i = 1; i <= s.length(); ++i)
      offset[i] = offset[i-1] * X % MOD;
  }
 
  intmax_t get_base() const { return X; }
  intmax_t get_mod() const { return MOD; }
 
  intmax_t prefix(size_t i) const {
    // hash of prefix s[0..i-1] (inclusive)
    assert(0 < i);
    return hash[i];
  }
 
  intmax_t substr(size_t i, size_t j) const {
    // hash of substring s[i..j-1] (inclusive)
    assert(i < j);
    intmax_t res = hash[j];
    res = (res - offset[j-i]*hash[i]) % MOD;
    if (res < 0) res += MOD;
    return res;
  }
 
  intmax_t inserted(size_t i, int ch) const {
    intmax_t res = 0;
    if (i > 0) res += prefix(i);
    res = (res*X + ch) % MOD;
    size_t n = hash.size()-1;
    if (i < n) res = (res*offset[n-i] + substr(i, n)) % MOD;
    return res;
  }
 
  void debug() const {
    for (size_t i = 0; i < hash.size(); ++i)
      fprintf(stderr, "%jd%c", hash[i], i+1<hash.size()? ' ':'\n');
  }
};
 
int testcase_ends() {
  char buf[4096];
  if (scanf("%s", buf) == EOF) return 1;
  std::string s = buf;
  scanf("%s", buf);
  std::string t = buf;
 
  if (s.length() > t.length()) std::swap(s, t);
 
  size_t n = s.length();
  size_t m = t.length();
 
  rolling_hash<> rs(s), rt(t);
 
  size_t lb = 0;
  size_t ub = n+1;
  while (ub-lb > 1) {
    size_t w = (lb+ub) >> 1;
    std::set<intmax_t> rl;
    bool found = false;
    for (size_t i = 0; i+w <= n; ++i)
      rl.insert(rs.substr(i, i+w));

    for (size_t i = 0; i+w <= m; ++i)
      if (rl.count(rt.substr(i, i+w))) {
        found = true;
        break;
      }

    (found? lb:ub) = w;
  }

  printf("%zu\n", lb);
  return 0;
}
 
int main() {
  while (!testcase_ends()) {}
}

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

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s, t;
	while(1){
		cin >> s;
		if(cin.eof()){ break; }
		
		cin >> t;
		
		int ans = 0, c = 0;;
		for(size_t i = 0; i < s.size(); ++i){
			for(size_t j = 0; j < t.size(); ++j){
				if(s[i] == t[j]){
					c = 1;
					while(s[i + c] == t[j + c]){
						c++;
					}
					ans = max(ans, c);
				}
			}
		}
		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++;
						if(k == left_length -1 || i + k == right_length-1){
							max = (max >= tmp)?max: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++;
						if(k == right_length -1 || i + k == left_length-1){
							max = (max >= tmp)?max:tmp;
						}
					}
					else{
						max = (max >= tmp)?max:tmp;
						tmp = 0;
					}
				}
			}
			printf("%d\n",max);
		}
	}

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

C++: //http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64

int dp[2][5000];
int n;
string a,b;

int main(){
while(cin>>a>>b){
n=a.size();
int ans=0;
rep(i,2)rep(j,5000)dp[i][j]=0;

for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
		if(i&1){//2,4,6,8...番目
			if(a[i]==b[j]){
				dp[1][j]=dp[0][j-1]+1;
				ans=max(ans,dp[1][j]);
			}
		}
		else{//1,3,5,7,9...番目
			if(a[i]==b[j]){
				dp[0][j]=dp[1][j-1]+1;
				ans=max(ans,dp[0][j]);
			}
		}
	}
}

cout<<ans<<endl;
}


	return 0;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t; int roop1, roop2 = 0, save[10000], ans = 0;
	while(1){
        cin>>s>>t;
	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<iostream>

using namespace std;

int find(const string& s1, const string& s2, int n){

  int tmp = 0;
  int res = 0;

  for(int i = 0; i < n; i++){
    int pos1 = s1.length()-n+i;
    if(s1[pos1] != s2[i]){
      res = max(res,tmp);
      tmp = 0;
    }else{
      tmp++;
    }
  }
  return max(tmp,res);
}

int main(){
  
  string s1,s2;
  while(getline(cin,s1) && getline(cin,s2)){
    int roop = min(s1.length(),s2.length());
    int ans = 0;
    for(int i = 0; i < roop; i++){
      ans = max(ans,find(s1,s2,i));
    }

    cout << ans << endl;
  }
  return 0;
}