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>

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 <vector>
using namespace std;

vector<int> make_kmp_table(const string& w)
{
  vector<int> tbl(w.size());
  tbl[0] = -1;
  tbl[1] = 0;
  for (string::size_type i = 2, j = 0; i < w.size(); ) {
    if (w[i-1] == w[j]) {
      tbl[i] = j+1;
      i++;
      j++;
    } else if (j > 0) {
      j = tbl[j];
    } else {
      tbl[i] = 0;
      i++;
    }
  }
  return tbl;
}

int kmp(const string& s, const string& w)
{
  const vector<int> tbl = make_kmp_table(w);
  for (string::size_type m = 0, i = 0; m+i < s.size(); ) {
    if (w[i] == s[m+i]) {
      i++;
      if (i == w.size()) {
        return m;
      }
    } else {
      m = m + i - tbl[i];
      if (i > 0) {
        i = tbl[i];
      }
    }
  }
  return -1;
}

int main()
{
  string s1, s2;
  while (cin >> s1 >> s2) {
    int l = 0, r = min(s1.size(), s2.size())+1;
    while (l+1 < r) {
      const int m = (l+r)/2;
      for (int i = 0; i <= s1.size()-m; i++) {
        if (kmp(s2, s1.substr(i, m)) != -1) {
          l = m;
          goto NEXT;
        }
      }
      r = m;
NEXT:
      ;
    }
    cout << l << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, bool> PIB;

int dp[4001][4001];
string s, t;
int ans = 0;

int main()
{
  while(true){
    cin >> s;
    if(s[0] == 17)
      break;
    cin >> t;

    ans = 0;
    memset(dp, 0, sizeof dp);

    for(int i = 0; i < s.size(); i++)
      for(int j = 0; j < t.size(); j++)
	if(s[i] == t[j]){
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	  ans = max(ans, dp[i + 1][j + 1]);
	}
    
    cout << ans << endl;
  }
  return 0;
}

C++: 
//=====================================================
// 
// (setq backup-inhibited t)
// (setq auto-save-default nil)
// 
// (column-number-mode t)
// (setq-default tab-width 2 indent-tabs-mode nil)
// 
// (global-set-key "\C-h" 'delete-backward-char)
// 
// (setq indent-line-function 'indent-relative-maybe)
// (global-set-key "\C-m" 'newline-and-indent)
// 
//=====================================================

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>

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

using namespace std;

int main() {
  string s;
  string t;
  cin >> s;
  cin >> t;
  set<string> st;
  for (int i = 0; i < s.size(); ++i) {
    for (int j = 0; i + j < s.size(); ++j) {
      st.insert(s.substr(i,j));
    }
  }
  size_t ml = 0;
  for (const string& str : st) {
    if(t.find(str) != string::npos)
      ml = max(ml, str.size());
  }
  cout << ml << 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(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<cstdio>
#include<cstring>
#define max(a,b) (a>b?a:b)
char a[4000],b[4000];
int table[4001][4001],n=0;
int main(){
	while(~scanf("%s%s",a,b)){
	for(int i=1;i<=strlen(a);i++){
		for(int j=1;j<=strlen(b);j++){
			if(a[i-1]==b[j-1])
				table[i][j]=max(table[i][j],table[i-1][j-1]+1);
			n=max(n,table[i][j]);
		}
	}
	printf("%d\n",n);
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int ans=0;
int main()
{
	string s1,s2;
	while(cin >> s1 >> s2)
	{
		ans=0;
		for(int i=0;i<s1.size();i++)
		{
			int cnt=0;
			for(int j=0;j<min(s1.size()-i,s2.size());j++)
			{
				if(s2[j]==s1[j+i])
				{
					cnt++;
					ans=max(ans,cnt);	
				}
				else
				{
					cnt=0;
				}
			}
		}
		for(int i=0;i<s2.size();i++)
		{
			int cnt;
			for(int j=0;j<min(s2.size()-i,s1.size());j++)
			{
				if(s1[j]==s2[j+i])
				{
					cnt++;
					ans=max(ans,cnt);
				}
				else
				{
					cnt=0;
				}
			}
		}
		cout << ans << endl;
		s1.clear();
		s2.clear();
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define lld long long int
#define str string


using namespace std;

lld f();
lld ster,leg,leg2,ans=0,ans2=0;

str moji,moji2,cut;

int main(){
while(1){
    cin >> moji ;
    if(moji=="EOF")break;
    cin >> moji2 ;
    leg=moji.size();
    leg2=moji2.size();

    cout << f() << endl;
    ans=0;
    ans2=0;
}
return 0;
}

lld f(){
    for(int a=0;a<leg;a++){
            for(int b=1;b<leg-a;b++){
        cut = moji.substr(a,b);
        ans=(moji2.find(cut)!=-1?b:ans);
        ans2=(ans>ans2?ans:ans2);
        }
    }
    return ans2;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, bool> PIB;

int dp[4001][4001];
string s, t;
int ans = 0;

int main()
{
  while(true){
    cin >> s;
    if(s == "")
      break;
    cin >> t;

    ans = 0;

    for(int i = 0; i < s.size(); i++)
      for(int j = 0; j < t.size(); j++)
	if(s[i] == t[j]){
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	  ans = max(ans, dp[i + 1][j + 1]);
	}
    
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	string s,big;
	int mi;
	string substr;
	while(cin >> s >> big){
		if(s.length()>big.length())
			swap(s,big);
		mi = 0;
		for(int m=1;m<=s.length();m++){
			substr="";
			for(int i=0;i<m;i++)substr += s[i];
			if(~big.find(substr)){mi = m;continue;}
			for(int i=m;i<s.length();i++){
				substr.erase(0,1);
				substr+=s[i];
				if(~big.find(substr)){mi = m;continue;}
			}
			break;
		}
		cout << mi << endl;
	}
}