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;

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

int dp[2][4444];
string s, t;

int main(int argc, char *argv[])
{
  while(cin >> s >> t){
    int ls = s.length();
    int lt = t.length();
    rep(j, lt) dp[0][j] = dp[1][j] = 0;
    int res = 0;
    rep(i, ls) rep(j, lt){
      if(j == 0) dp[i & 1][0] = 0;
      if(s[i] == t[j]) dp[(i + 1) & 1][j + 1] = dp[i & 1][j] + 1;
      else dp[(i + 1) & 1][j + 1] = 0;
      res = max(res, dp[(i + 1) & 1][j]);
    }
    cout << res << endl;
  }
  
  return 0;
}

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

int count(string& a, string& b) {
    int a_len = a.length();
    int b_len = b.length();
    int max_lcs = 0;
    int cur_lcs = 0;
    for (int i = 0; i < a_len; i++) {
        for (int j = 0; j < b_len && i + j < a_len; j++) {
            if (a[i+j] == b[j]) {
                cur_lcs++;
            } else {
                if (max_lcs < cur_lcs) {
                    max_lcs = cur_lcs;
                }
                cur_lcs = 0;
            }
        }
    }
    cur_lcs = 0;
    for (int i = 0; i < b_len; i++) {
        for (int j = 0; j < a_len && i + j < b_len; j++) {
            if (a[j] == b[i+j]) {
                cur_lcs++;
            } else {
                if (max_lcs < cur_lcs) {
                    max_lcs = cur_lcs;
                }
                cur_lcs = 0;
            }
        }
    }

    return max_lcs;
}

int main() {
    string a, b;
    while (cin >> a >> b) {
        cout << count(a, b) << 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[500000]={}, 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<string.h>
#define max(i,j) (i<j?j:i)
int main(void){
	char s[4001],t[4001];
	while(scanf("%s",s)!=EOF){
		scanf("%s",t);
		int sl = strlen(s),tl = strlen(t);
		int ans = 0;
		for(int i=0;i+ans<sl;i++){
			for(int j=0;j+ans<tl;j++){
				if(s[i]==t[j]){
					for(int k=1;j+k<tl && i+k<sl;k++){
						ans = max(ans,k);
						if(s[i+k]!=t[j+k])break;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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


int solve(const std::string &X, const std::string &Y,
             const int &m, const int &n) {
    int res[m+1][n+1];
    int result = 0;
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            if (i == 0 || j == 0) res[i][j] = 0;
            else if (X[i-1] == Y[j-1]) {
                res[i][j] = res[i-1][j-1] + 1;
                result = std::max(result, res[i][j]);
            }
            else res[i][j] = 0;
        }
    }
    return result;
}

int main()
{
    std::string a, b;
    while(std::cin >> a) {
        std::cin >> b;
        int sizea = a.size();
        int sizeb = b.size();
        std::cout << solve(a, b, sizea, sizeb) << std::endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>
#include <set>

#define INF 10 << 10

string str1;
set<string> memo;

string Find(string str) {
	if (memo.find(str) != memo.end()) { return str; }
	if (str1.find(str) != -1) {
		memo.insert(str);
		return str;
	}
	if (str.size() == 1) { return ""; }
	int maxi = 0; string ans;
	string s = str; s.erase(s.begin());
	string ss = Find(s);
	maxi = ss.size(); ans = ss;
	s = str; s.erase(s.begin() + s.size() - 1);
	ss = Find(s);
	if(maxi < ss.size()){
		maxi = ss.size();
		ans = ss;
	}
	memo.insert(ans);
	return ans;
}

int main() {
	string str2;

	while (cin >> str1) {
		cin >> str2;
		//?????????????????? str1 ???
		if (str1.size() < str2.size()) {
			swap(str1, str2);
		}
		int ans = Find(str2).size();
		cout << ans << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)

int main()
{
  string S, W;
  while(cin >> S >> W) {
    int dp[4005] = {0};
    int maxv = 0;
    Rep(i,W.size()) {
      for(int j = S.size(); j > 0; j--) {
	if(S[j - 1] == W[i]) {
	  dp[j] = dp[j - 1] + 1;
	  maxv = max(maxv, dp[j]);
	} else dp[j] = 0;
      }
    }
  }
  cout << maxv << endl;
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <functional>

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

int main() {
	char S1[5000], S2[5000];
	int l1, l2;
	for (; scanf("%s %s", S1, S2) != EOF;) {
		l1 = strlen(S1);
		l2 = strlen(S2);
		int ans = 0;

		for (int p = -(l1 - 1); p < l2; p++) {
			int count = 0;
			for (int i = max(p, 0);; i++) {
				if (S1[i - p] == '\0' || S2[i] == '\0') break;
				if (S1[i - p] == S2[i]) {
					count++;
				}
				else {
					count = 0;
				}
				ans = max(ans, count);
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	string s1,s2;
	cin >> s1;
	if(cin.eof()) break;
	cin >> s2;
	int ans = 0;
	int h = s1.size();
	int l = 0;
	int m = (h+l)/2;
	while(h-l>1){
	    bool flg = false;
	    set<string> ss;
	    REP(i,s1.size()-m){
		ss.insert(s1.substr(i,m));
	    }

	    REP(i,s2.size()-m){
		if(ss.find(s2.substr(i,m)) != ss.end()){
		    flg = true;
		}
	    }
	    if(flg){
		l = m;
	    }else{
		h = m;
	    }
	    m = (h+l)/2;
	}
	cout << m << endl;

    }
    return 0;
}

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

int main(){
	string str1, str2;
	while(cin >> str1 >> str2){
		int count = 0;
		for(int i = 0; i < str1.size(); i++){
			for(int j = 0; j < str2.size(); j++){
				int k = 0;
				while(str1.substr(i, k) == str2.substr(j, k)){
					if(i + k > str1.size() || j + k > str2.size()) break;
					count = max(count, k);
					k++;
					//cout << str2.substr(i, k) << endl;
				}
			}
		}
		cout << count << endl;
	}
}