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 <cstring>
#include <algorithm>
using namespace std;

int main()
{
    string str1, str2;
    while (cin >> str1){
        cin >> str2;
        int ans = 0;

        if (str1.size() > str2.size()){
            swap(str1, str2);
        }
        
        for (int i=0; i<str1.size(); i++) {
            for (int j=0; j<str2.size(); j++) {
                int cnt = 0;
                if (str1[i] == str2[j]){
                    for (int k=0; k<str1.size()-i; k++) {
                        if (str1[i+k] == str2[j+k]){
                            cnt++;
                        }else{
                            break;
                        }
                    }
                }
                ans = max(ans, cnt);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }

int main()
{
  int dp[4005][4005];
  string s, t;
  while(cin >> s >> t) {
    fill(dp[0],dp[4005],0);
    int ss = s.size(), ts = t.size();

    Rep(i,ts) {
      Rep(j,ss) {
	if(s[j] == t[i]) {
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	}
      }
    }
    cout << *max_element(dp[0],dp[ts + 1]) << endl;
  }
  return 0;
}

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

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

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
 
void mul_mod(ll& a, ll b){
    a *= b;
    a %= MOD;
}
 
void add_mod(ll& a, ll b){
    b += MOD;
    a += b;
    a %= MOD;
}

int n,m,memo[4444][4444];
bool done[4444][4444];
char s[4444],t[4444];

int dp(int i, int j){
    if(done[i][j]){
        return memo[i][j];
    }
    done[i][j] = true;
    if(i == n || j == m){
        memo[i][j] = 0;
    }else if(s[i] != t[j]){
        memo[i][j] = 0;
    }else{
        memo[i][j] = dp(i+1,j+1) + 1;
    }
    return memo[i][j];
}

int main(void){
    int i,j,ans;
    while(scanf(" %s ",s)!=EOF){
        fill(done[0],done[4444],false);
        ans = 0;
        scanf(" %s ",t);
        n = strlen(s); m = strlen(t);
        for(i=0; i<n; ++i){
            for(j=0; j<m; ++j){
                if(!done[i][j]){
                    ans = max(ans,dp(i,j));
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string s1,s2;
	cin >> s1 >> s2;
	int t[4001][4001];
	for(int i=0;i<=s1.length();i++){
		t[0][i]=0;
	}
	for(int j=0;j<=s2.length();j++){
		t[j][0]=0;
	}
	for(int i=1;i<=s1.length();i++){
		for(int j=1;j<=s2.length();j++){
			if(s1[i-1]==s2[j-1])t[i][j]=t[i-1][j-1]+1;
			else t[i][j]=0;
		}
	}
	int ans=0;
	for(int i=1;i<=s1.length();i++){
		for(int j=1;j<=s2.length();j++){
			ans=max(ans,t[i][j]);
		}
	}
	cout << ans << "\n";
	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,memo[10000000];

str moji,moji2,cut;

int main(){
while(1){
        fill(memo,memo+10000,0);
    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++){
        //if(memo[moji[a]]!=1)
            for(int b=1;b<leg-a;b++){
        cut = moji.substr(a,b);
        if(moji2.find(cut)==-1)break;
        ans=(moji2.find(cut)!=-1?b:ans);
        ans2=(ans>ans2?ans:ans2);
        }
    //memo[moji[a]]=1;
    }
    return ans2;
}

C++: #include<iostream>
main(){int a,c,i,j,k;for(std::string s,t;std::cin>>s>>t;printf("%d\n",a))for(a=k=0;k++<2;swap(s,t))for(i=s.size();i-->0;)for(j=c=0;j<s.size()-i;)s[j+i]-t[j++]?c=0:a=std::max(a,++c);}

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

using namespace std;

int main(void){
	int a,b;
	string str;
	string str2;
	while(cin >> str >> str2){
		int ans=0;
		for(a=0;a<str.size();a++){
			int res=0;
			string tmp= str.substr(a, str.size()-a);
			for(b=0;b<min(tmp.size(),str2.size());b++){
				if(tmp[b]==str2[b])res++;
				else ans=max(res,ans),res=0;
				if(min(tmp.size(),str2.size())-1==b)ans=max(res,ans);
			}
		}
		for(a=0;a<str2.size();a++){
			int res=0;
			string tmp= str2.substr(a, str2.size()-a);
			for(b=0;b<min(tmp.size(),str.size());b++){
				if(tmp[b]==str[b])res++;
				else ans=max(res,ans),res=0;
				if(min(tmp.size(),str.size())-1==b)ans=max(res,ans);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	string a,b;
	while(cin >> a >> b){
		if(a.size() < b.size() ) swap(a,b);
		int ans = 0;
		for(int i = 0 ; i < a.size() ; i++){
			int len = 0;
			for(int j = 0 ; j < b.size() ; j++){
				if(i+len < a.size() && a[i+len] == b[j])len++;
				else len = a[i] == b[j];
				ans = max(len,ans);
			}
		}
		cout << ans << endl;
	}
}

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

int 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, 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;
  }
}