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 <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <cstring>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	string s, t;
	while(cin >> s && s.size()){
		int memo[4040][4040] = {};
		int res = 0;
		cin >> t;
		REP(i, s.size()){
			REP(j, t.size()){
				if(memo[i][j] != 0) continue;
				int cnt = 0;
				if(s[i] == t[j]){
					cnt++;
					memo[i][j] = cnt;
					while(s[i+cnt] == t[j+cnt] && i+cnt < s.size() && j+cnt < t.size()){
						cnt++;
						memo[i+cnt][j+cnt] = cnt;
					}
					res = max(res, cnt);
				}
			}
		}
		cout << res << 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[600000]={}, 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<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;
  int i = 0;
  while(1) {
  	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;
    if (i==9) {
    	break;
    }
    i++;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#define N 4010
using namespace std;

int main(){
  string data;
  string indata;
  int n[2][N];
  while(cin >> data){
    cin >> indata;

    int size1, size2;
    size1=data.size();
    size2=indata.size();

    n[1][0]=0;
    for(int i=0;i<=size1;i++){
      n[0][i]=0;
    }
    int now;
    for(int i=1;i<=size2;i++){
      now=i%2;
      for(int j=1;j<=size1;j++){
        if(data[j-1]==indata[i-1]){
	  if(now){
	    n[1][j]=n[0][j-1]+1;
	  }
	  else{
	    n[0][j]=n[1][j-1]+1;
	  }
        }
        else{
          n[now][j]=n[now][j-1];
        }
      }
    }
    if(n[0][size1]>=n[1][size1]){
      printf("%d\n", n[0][size1]);
    }
    else{
      printf("%d\n", n[1][size1]);
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

string s, t;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> s >> t) {
        int n = s.size();
        int m = t.size();
        int dp[n + 1][m + 1] = {};
        rep(i, n)rep(j, m) {
            if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
        }
        int ans = 0;
        rep(i, n + 1)rep(j, m + 1) ans = max(ans, dp[i][j]);
        cout << ans << endl;
    }
}

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++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int dp[4001][4001];

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