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
var dp [4001][4001]int

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()

		for i := range dp {
			for j := range dp[i] {
				dp[i][j] = 0
			}
		}

		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 <cstring>
using namespace std;
int main()
{
	char str1[4096],str2[4096];
	int dp[4096][4096];
	int memo[10000];
	while(cin>>str1>>str2){
		memset(memo,0,sizeof(memo));
		memset(dp,0,sizeof(dp));
		int n = strlen(str1);
		int m = strlen(str2);
		int ans = 0;
		for(int i=1; i<=n; i++){
			for(int j=1; j<=m; j++){
				int t = i-j>=0 ? i-j : n+m+i-j;
				if( str1[i-1]==str2[j-1] ){
					memo[t]++;
				}else{
					memo[t]=0;
				}
				dp[i][j] = max(memo[t],dp[i-1][j-1]);
				ans = max(ans,dp[i][j]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define STR string

using namespace std;

string s,t;
long long dp[10000][10000];

void solve(){
    for(int i=0;i<s.size();i++){
        for(int j=0;j<t.size();j++){
                if(dp[i+1][j+1]=0){
            if(s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }else{
                dp[i+1][j+1]=(dp[i][j+1]>dp[i+1][j])?dp[i][j+1]:dp[i+1][j];
            }
        }
        }
    }
cout << dp[s.size()][t.size()] << endl;
}


int main(){
while(1){
cin >> s >>t;
if(s=="EOF")break;
solve();
}
//cout << s.size();
return 0;
}

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

int main() {
	string s, t;
	while(cin >> s >> t){
		int n = s.size(), m = t.size(), ans = 0;
		for(int i = 0; i < n; ++i){
			int c = 0;
			for(int j = 0, k = i; j < m && k < n; ++j, k++){
				if(s[k] == t[j]){
					c++;
				}
				else{
					ans = max(ans, c);
					c = 0;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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


class suffix_array {
public:
    suffix_array(std::string const& s_)
        : length(s_.length()),
          s(s_),
          sa(s.length() + 1),
          rank(s.length() + 1)
    {
        for(int i = 0; i <= length; ++i) {
            sa[i] = i;
            rank[i] = i < length ? s[i] : -1;
        }
        int k = 0;
        auto compare_sa = [this, &k](int i, int j) {
            if(rank[i] != rank[j]) {
                return rank[i] < rank[j];
            } else {
                int ri = i + k <= length ? rank[i + k] : -1;
                int rj = j + k <= length ? rank[j + k] : -1;
                return ri < rj;
            }
        };
        for(k = 1; k <= length; k *= 2) {
            sort(sa.begin(), sa.end(), compare_sa);

            std::vector<int> tmp(length + 1);
            tmp[sa[0]] = 0;
            for(int i = 1; i <= length; ++i) {
                tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
            }
            for(int i=0; i <= length; ++i) {
                rank[i] = tmp[i];
            }
        }
    }

    std::vector<int> get() const {
        return sa;
    }

    std::string get_string() const {
        return s;
    }

    bool contain(std::string const& t) {
        int l = 0, r = length;
        while(r - l > 1) {
            int m = (l + r) / 2;
            if(s.compare(sa[m], t.length(), t) < 0) {
                l = m;
            } else {
                r = m;
            }
        }
        return s.compare(sa[r], t.length(), t) == 0;
    }

    int lower_bound(std::string const& t) {
        int l = 0, r = length + 1;
        while(r - l > 1) {
            int m = (l + r) / 2;
            if(s.compare(sa[m], std::string::npos, t) < 0) {
                l = m;
            } else {
                r = m;
            }
        }
        return r;
    }
    int upper_bound(std::string const& t) {
        int l = 0, r = length + 1;
        while(r - l > 1) {
            int m = (l + r) / 2;
            if(s.compare(sa[m], t.size(), t) <= 0) {
                l = m;
            } else {
                r = m;
            }
        }
        return r;
    }

private:
    int length;
    std::string s;
    std::vector<int> sa;
    std::vector<int> rank;
};


std::vector<int> construct_lcp(suffix_array const& SA) {
    auto s = SA.get_string();
    const int n = s.size();
    auto sa = SA.get();
    std::vector<int> rank(n + 1);
    for(int i = 0; i <= n; ++i) {
        rank[sa[i]] = i;
    }

    int h = 0;
    std::vector<int> lcp(n);
    for(int i = 0; i < n; ++i) {
        int j = sa[rank[i] - 1];

        if(h > 0) {
            h--;
        }
        for(; j + h < n && i + h < n; ++h) {
            if(s[j + h] != s[i + h]) {
                break;
            }
        }
        lcp[rank[i] - 1] = h;
    }

    return lcp;
}

int main() {
    string s, t;
    while(cin >> s >> t) {
        const int s_len = s.size();
        s += "$" + t;
        suffix_array SA(s);
        auto sa = SA.get();
        auto lcp = construct_lcp(SA);

        int res = 0;
        for(int i = 0; i < s.size(); ++i) {
            if((sa[i] < s_len) != (sa[i + 1] < s_len)) {
                res = max(res, lcp[i]);
            }
        }
        cout << res << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

int dp[4001][4001];

void solve(string s, string t) {
	memset(dp, 0, sizeof(dp));
	int maxi = 0;
	rep(i, s.length()) {
		rep(j, t.length()) {
			if( s[i] == t[j] ) {
				dp[i+1][j+1] = dp[i][j] + 1;
				maxi = max(maxi, dp[i+1][j+1]);
			} else {
				dp[i+1][j+1] = 0;
			}
		}
	}
	cout << maxi << endl;
}

int main() {
	string s, t;
	while(cin >> s >> t) {
		solve(s,t);
	}
	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, t;
  while(cin >> s >> t) {
    vector<vector<int> > dp(2,vector<int>(4005,0));
    int ss = s.size(), ts = t.size();
    int maxv = 0;
    Rep(i,ts) {
      Rep(j,ss) {
	if(s[j] == t[i]) {
	  dp[1][j + 1] = dp[0][j] + 1;
	  maxv = max(maxv,dp[1][j + 1]);
	}else {
	  dp[1][j + 1] = 0;
	}
      }
      dp[0] = dp[1];
    }
    cout << maxv << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<math.h>
#include<algorithm>


using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
char A[4002],B[4002];
int DP[4002][4002];


int main(){
	while(1){
		scanf("%s",A);
		scanf("%s",B);
		memset(DP,0,sizeof(DP));
		int ans=0;
		rep(i,strlen(A)){
			rep(j,strlen(B)){
				if(A[i]==B[j]){
					if(i!=0&&j!=0){
						DP[i][j]+=DP[i-1][j-1];
					}
					DP[i][j]++;
				}
				ans=max(ans,DP[i][j]);
			}
		}
	printf("%d\n",ans);
	}
}