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++: //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, save[1000000], ans;
		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 <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cstdlib>
#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)

string s;
string t;
int dp[4010][4010];
int main() {
  while (cin >> s >> t) {
  int s_len = s.length(), t_len = t.length();
  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>
using namespace std;

int dp[4002][4002];

int main() {
  string s;
  string t;
  int mx;
  
  while( getline(cin, s) ) {
    fill(dp[0], dp[4000] + 4000, 0);
    getline(cin, t);
    int n = s.size(), m = t.size();
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
	if( s[i] == t[j] ) {
	  dp[i+1][j+1] = dp[i][j] + 1;
	} else {
	  dp[i+1][j+1] = 0;
	}
      }
    }
    
    mx = 0;
    for(int i=0; i<=n+1; i++)
      for(int j=0; j<=m+1; j++)
	mx = max(mx, dp[i][j]);
    
    cout << mx << endl;
  }
  
  return 0;
}

C++: #include<iostream>
 
using namespace std;
 
int solve(const string& s1, const string& s2, int l1, int l2){
  int tmp = 0;
  int res = 0;
  int len = min(s2.length()-l2,s1.length()-l1);
  for(int i = 0; i < len; i++){
    if(s1[l1+i] != s2[l2+i]){
      res = max(res,tmp);
      tmp = 0;
    }else{
      tmp++;
    }
  }
  return max(tmp,res);
}
 
int main(){
   
  string s1,s2;
  int l1,l2,ans;
  while(1) {
  	if(cin.eof()) {
  		break;
  	}
  	cin >> s1;
  	cin >> s2;
  	l1 = s1.length();
  	l2 = 0;
  	ans = 0;
  	while(l1 != 0 || l2 <= s2.length()) {

      if(l1 != 0){
      	l1--;
      } else {
      	l2++;
      }
      ans = max(ans,solve(s1,s2,l1,l2));
  	}
    cout << ans << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main()
{
	char a[4001],b[4001];
	while(scanf("%s%s",a,b)>0)
	{
		static int x[4001][4001]={0},i,j,s,t,r;
		s=strlen(a),t=strlen(b);
		for(r=j=0;j<=t;++j)x[0][j]=0;
		for(i=0;i<=s;++i)x[i][0]=0;
		for(i=0;i<s;++i)for(j=0;j<t;++j)if(a[i]==b[j])r=(r>(x[i+1][j+1]=x[i][j]+1)?r:x[i+1][j+1]);
		printf("%d\n",r);
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[4001][4001];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true){
        string S, T;
        cin >> S >> T;

        rep(i, S.length()) {
            rep(j, T.length()) {
                if (S[i] == T[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
                //else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
                else dp[i + 1][j + 1] = dp[i][j + 1];
            }
        }
        /*
        rep(i, S.length() + 1) {rep(j, T.length() + 1)
            cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
        */
        /*
        rep(i, S.length() + 1) {
            cout << i << " ";
            rep(j, T.length() + 1) {
                cout << dp[i][j] << " ";
            }
            cout << endl;
        }
        */
           

        cout << dp[S.length()][T.length()] << endl;
    }


    return 0;
}

C++: //Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#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 pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int dp[4005][4005];
char a[4005],b[4005];
int main()
{
	while(scanf("%s",a)!=EOF)
	{

		scanf("%s",b);
		memset(dp,0,sizeof(0));
		
		int aa=strlen(a); int bb=strlen(b);
		int ret=0;
		for(int i=1;i<=aa;i++)
		{
			for(int j=1;j<=bb;j++)
			{
				if(a[i-1]==b[j-1]){dp[i][j]=dp[i-1][j-1]+1;}
				else dp[i][j]=0;
				ret=max(ret,dp[i][j]);
			}
			
		}
		printf("%d\n",ret);
	}
	
}

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

using namespace std;

int main()
{
	string S, T;

	while (cin >> S >> T)
	{
		vector<vector<int> > dp(T.size() + 1, vector<int>(S.size() + 1, 0));

		for (int i = 0; i <= S.size(); i++) { dp[0][i] = 0; }
		for (int i = 0; i <= T.size(); i++) { dp[i][0] = 0; }

		for (int i = 1; i <= T.size(); i++)
		{
			for (int j = 1; j <= S.size(); j++)
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

				if (T[i] == S[j])
				{
					dp[i][j]++;
				}
			}
		}

		printf("%d\n", dp[T.size()][S.size()]);
	}

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