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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

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

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 28;
const double EPS = 1E-10;

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

int main(){
	string s, t;
	int n, m;
	while(getline(cin, s)){
		getline(cin, t);
		n = s.size();
		m = t.size();

		int res = 0;
		for(int i = -n + 1; i < m; i++){
			int c = 0;
			int ind = max(i, 0);
			while(ind - i< n && ind < m){
				c = 0;
				while(ind - i < n && ind < m && s[ind-i] == t[ind]){
					c++;;
					ind++;
				}
				ind++;
				res = max(c, res);
			}
		}
		cout << res << endl;
	}
	return 0;
}

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

using namespace std;

int dp[4001][4001];

void solve()
{
	string a, b;
	while (cin >> a)
	{
		cin >> b;
		memset(dp, 0, sizeof(dp));
		int ans = 0;
		for (int i = 0; i < a.size(); ++i)
		{
			for (int j = 0; j < b.size(); ++j)
			{
				if (a[i] == b[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;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
string s,t;
int main() {
    while(cin>>s>>t){
        int ans=0;
        for(int i=0;i<s.size();i++){
            for(int j=0;j<t.size();j++){
                if(s[i]==t[j] && ans<t.size()-j){
                    int sum=1;
                    for(int k=1;k<min(s.size()-i,t.size()-j);k++){
                        if(s[i+k]==t[j+k]){
                            sum++;
                        } else{
                            ans=max(ans,sum);
                            if(ans>=s.size()-i){
                                goto goal;
                            }
                            break;
                        }
                    }
                }
            }
        }
         
goal:
         
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#define REP(i,a,n) for(int i = a;i < n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int field[4002][4002];
int main(void){
   char a[4002],b[4002];
   while(scanf("%s%s",a+1,b+1) != EOF){
      int ma = 0;
      memset(field,0,sizeof(int)*4000*4000);
      a[0] = '0'; b[0] = '1';
      REP(i,1,strlen(a)){
         REP(j,1,strlen(b)){
            if(a[i] == b[j]){
               field[i][j] = field[i-1][j-1]+1;
               ma = max(ma,field[i][j]);
            }
         }
      }

      printf("%d\n",ma);
   }
   return 0;
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
bool c[4000][4000];
int main() {
	string a, b;
	while (cin >> a >> b) {
		for (int i = 0; i < a.length(); i++) {
			for (int j = 0; j < b.length(); j++) c[i][j] = true;
		}
		int sum = 0;
		for (int i = 0; i < a.length(); i++) {
			for (int j = 0; j < b.length(); j++) {
				if (c[i][j]&&a[i]==b[j]) {
					int i2 = i, j2 = j,sum2=0;
					while (a[i2] == b[j2]&&i2<a.length()&&j2<b.length()) {
						c[i2][j2] == false;
						i2++;
						j2++;
						sum2++;
					}
					sum = max(sum, sum2);
				}
			}
		}
		cout << sum << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;

int check(string, string);

int main()
{
	ifstream ifs("data.txt");
	string s1, s2;

	while(ifs >> s1 >> s2)
	{
		int res = 0;
		if(s1.size() < s2.size()) swap(s1, s2);

		for(int i = 0; i < s1.size(); i++)
			res = max(res, check(s1.substr(i, s1.size()), s2));

		for(int i = 0; i < s2.size(); i++)
			res = max(res, check(s2.substr(s2.size()-1-i, s2.size()), s1));

		cout << res << endl;
	}
}

int check(string s1, string s2)
{
	int res = 0, sn = 0;
	for(int i = 0; i < min(s1.size(), s2.size()); i++){
		if(s1[i] == s2[i])	sn++;
		else				sn = 0;

		res = max(res, sn);
	}
	return res;
}

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

short mat[4000][4000];

int lcs(string s,string t) {
  int z = 0;
  for(int i=0; i<s.length(); ++i) {
    for(int j=0; j<t.length(); ++j) {
      if(s.at(i) == t.at(j)) {
        if(i == 0 || j == 0)
          mat[i][j] = 1;
        else {
          mat[i][j] = mat[i-1][j-1] + 1;
        }
        z = max(z, (int)mat[i][j]);
      }
    }
  }
  return z;
}

int main() {
  string s,t;
  while(cin>>s) {
    cin>>t;
    memset(mat, 0, sizeof(mat));
    cout<<lcs(s,t)<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
short cnt[4100][4100];
int main(){
  string str1,str2;
  while(cin >> str1){
    cin >> str2;
    int len1 = str1.size();
    int len2 = str2.size();
    str1 = ' ' + str1;
    str2 = ' ' + str2;
    for(int i=1;i<=len1;i++){
      cnt[i][0] = 0;
    } 
    for(int i=1;i<=len2;i++){
      cnt[0][i] = 0;
    }
    short ret = 0;
    for(int i=1;i<=len1;i++){
      for(int j=1;j<=len2;j++){
	if(str1[i] == str2[j]){
	  cnt[i][j] = cnt[i-1][j-1] + 1;
	}
	else {
	  cnt[i][j] = 0;
	}
	ret = max(ret,cnt[i][j]);
      }
    }
    cout << ret << endl;
  }	
}