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 <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

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

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    string n, m;
    while(cin >> n >> m){
        int ans = 0;
        if(n.size() > m.size()) swap(n, m);
        for(int i=0; i < n.size(); i++){
            for(int j=i+1; j < n.size(); j++){
                string s = n.substr(i, j-i);
                if(m.find(s) != string::npos)ans = max(ans, (int)s.size());
                else {i++; j = i;}
            }
        }
        cout << ans << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, bool> PIB;

int dp[4001][4001];
string s, t;
int ans = 0;

int main()
{
  while(true){
    cin >> s;
    if(!s.size())
      break;
    cin >> t;
    ans = 0;
    memset(dp, 0, sizeof dp);

    for(int i = 0; i < s.size(); i++)
      for(int j = 0; j < t.size(); j++)
	if(s[i] == t[j]){
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	  ans = max(ans, dp[i + 1][j + 1]);
	}
    
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

typedef vector<int> vi;

int solve(string const& s, string const& t){
    int m=s.size(), n=t.size();
    int ans = -1;
    vi prev(n+1);
    rep(i,m){
        vi cur(n+1);
        rep(j,n){
            if(s[i]==t[j])cur[j+1]=prev[j]+1;
            ans = max(ans,cur[j+1]);
        }
        swap(cur,prev);
    }
    return ans;
}

int main(){
    string s,t;
    while(cin>>s>>t){
        cout << solve(s,t) << endl;
    }
}

C++: #include<stdio.h>
#include<string.h>
unsigned short d[4000][4000];
char a[4000],b[4000];
int i,j;

int max(int a,int b){
	if(a>=b)return a;
	else return b;
}

int main(){
	while(scanf("%s",&a)!=EOF){
		scanf("%s",&b);
		for(i=0;i<strlen(a);i++)for(j=0;j<strlen(b);j++)d[i][j]=0;
		for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++){
				if(a[i]==b[j]){
					if(i>0&&j>0)d[i][j]=d[i-1][j-1]+1;
					else d[i][j]=1;
				}
				else{
					d[i][j]=0;
				}
			}
		}
		/*for(i=0;i<strlen(a);i++){
			for(j=0;j<strlen(b);j++)printf("%d ",d[i][j]);
			printf("\n");
		}
		printf("\n");*/
		int ans=0;
		for(i=0;i<strlen(a);i++)for(j=0;j<strlen(b);j++)ans=max(ans,d[i][j]);
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	string s1,s2;
	cin >> s1;
	if(cin.eof()) break;
	cin >> s2;
	int ans = 0;
	REP(i,s1.size()){
	    char h = s1[i];
	    REP(j,s2.size()){
		if(s2[j] == h){
		    int temp = 0;
		    FOR(k,j,s2.size()){
			if(s1[i+k-j] == s2[k]) {
			    temp++;
			}else break;
		    }
		    ans = max(ans,temp);
		}
	    }
	}
	cout << ans << endl;
    }
    return 0;
}

C++: #include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string s, t;
int dp[4123][4123];
int ans;

int main()
{
	while (true)
	{
		s.clear(); t.clear();
		memset(dp, 0, sizeof(dp));
		ans = 0;

		in >> s >> t;
		if (s.empty()) { break; }

		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] = 0; }
			}
		}
		rep(i, s.length() + 1)
		{
			rep(j, t.length() + 1)
			{
				ans = std::max(ans, dp[i][j]);
			}
		}

		out << ans << std::endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
int main(void){
	char s[4001],t[4001];
	while(scanf("%s",s)!=EOF){
		scanf("%s",t);
		int sl = strlen(s),tl = strlen(t);
		int ans = 0;
		for(int i=0;i+ans<sl;i++){
			for(int j=0;j+ans<tl;j++){
				if(s[i]==t[j]){
					for(int k=1;j+k<tl && i+k<sl;k++){
						ans = max(ans,k);
						if(s[i+k]!=t[j+k])break;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}