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++: //Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int dp[4005][4005];
char a[4005],b[4005];
int main()
{
	while(scanf("%s",a)!=EOF)
	{

		scanf("%s",b);
		memset(dp,0,sizeof(0));
		
		int aa=strlen(a); int bb=strlen(b);
		int ret=0;
		for(int i=1;i<=aa;i++)
		{
			for(int j=1;j<=bb;j++)
			{
				if(a[i-1]==b[j-1]){dp[i][j]=dp[i-1][j-1]+1;}
				else dp[i][j]=0;
				ret=max(ret,dp[i][j]);
			}
			
		}
		printf("%d\n",ret);
	}
	
}

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

using namespace std;

int main()
{
	string S, T;

	while (cin >> S >> T)
	{
		vector<vector<int> > dp(T.size() + 1, vector<int>(S.size() + 1, 0));

		for (int i = 0; i <= S.size(); i++) { dp[0][i] = 0; }
		for (int i = 0; i <= T.size(); i++) { dp[i][0] = 0; }

		for (int i = 1; i <= T.size(); i++)
		{
			for (int j = 1; j <= S.size(); j++)
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

				if (T[i] == S[j])
				{
					dp[i][j]++;
				}
			}
		}

		printf("%d\n", dp[T.size()][S.size()]);
	}

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int ans=0;
int main()
{
	string s1,s2;
	while(cin >> s1 >> s2)
	{
		ans=0;
		for(int i=0;i<s1.size();i++)
		{
			int cnt=0;
			for(int j=0;j<min(s1.size()-i,s2.size());j++)
			{
				if(s2[j]==s1[j+i])
				{
					cnt++;
					ans=max(ans,cnt);	
				}
				else
				{
					cnt=0;
				}
			}
		}
		for(int i=0;i<s2.size();i++)
		{
			int cnt=0;
			for(int j=0;j<min(s2.size()-i,s1.size());j++)
			{
				if(s1[j]==s2[j+i])
				{
					cnt++;
					ans=max(ans,cnt);
				}
				else
				{
					cnt=0;
				}
			}
		}
		cout << ans << endl;
		s1.clear();
		s2.clear();
	}
	return 0;
}

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

using namespace std;

short dp[4000][4000];

int main()
{
	for(;;){
		string s, t;
		
		if(!(cin >> s >> t)){
			break;
		}
		
		for(int i = 0; i <= s.size(); i++){
			dp[i][0] = 0;
		}
		
		for(int j = 0; j <= t.size(); j++){
			dp[0][j] = 0;
		}
		
		for(int i = 1; i <= s.size(); i++){
			for(int j = 1; j <= t.size(); j++){
				if(s[i-1] == t[j-1]){
					dp[i][j] = dp[i-1][j-1] + 1;
				}
				else{
					dp[i][j] = 0;
				}
			}
		}
		int ans = 0;
		
		for(int i = 0; i <= s.size(); i++){
			for(int j = 0; j <= t.size(); j++){
				if(dp[i][j] > ans){
					ans = dp[i][j];
				}
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include <string>

int testcase_ends() {
  char buf[4096];
  if (scanf("%s", buf) != 1) return 1;
  std::string s = buf;
  scanf("%s", buf);
  std::string t = buf;

  if (s.length() > t.length()) std::swap(s, t);

  size_t lb = 0;
  size_t ub = s.length()+1;
  while (ub-lb > 1) {
    size_t mid = (lb+ub) >> 1;

    std::set<std::string> hh;
    for (size_t i = mid; i <= t.length(); ++i)
      hh.insert(t.substr(i-mid, mid));

    bool valid = false;
    for (size_t i = mid; i <= s.length(); ++i)
      if (hh.count(s.substr(i-mid, mid))) {
        valid = true;
        break;
      }

    (valid? lb: ub) = mid;
  }

  printf("%zu\n", lb);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

C++: #include<iostream>

using namespace std;

int solve(const string& s1, const string& s2, int sp1, int sp2){

  int tmp = 0;
  int res = 0;
  int len = min(s2.length()-sp2,s1.length()-sp1);
  
  
  for(int i = 0; i < len; i++){
    if(s1[sp1+i] != s2[sp2+i]){
      res = max(res,tmp);
      tmp = 0;
    }else{
      tmp++;
    }
  }
  return max(tmp,res);
}

int main(){
  
  string s1,s2;
  while(getline(cin,s1) && getline(cin,s2)){
    int p1 = s1.length();
    int p2 = 0;
    int ans = 0;

    while(p1!=0&&p2<=(int)s2.length()){
      if(p1 != 0) p1--;
      else p2++;
      ans = max(ans,solve(s1,s2,p1,p2));
     }
    cout << ans << 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){
                ans = max(ans,dp(i,j));
            }
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <functional>

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

int main() {
	char S1[5000], S2[5000];
	int l1, l2;
	for (; scanf("%s %s", S1, S2) != EOF;) {
		l1 = strlen(S1);
		l2 = strlen(S2);
		int ans = 0;
		int count = 0;

		for (int p = -(l1 - 1); p < l2; p++) {
			for (int i = max(p,0);; i++) {
				if (S1[i - p] == '\0' || S2[i] == '\0') break;
				if (S1[i - p] == S2[i]) {
					count++;
				}
				else {
					count = 0;
				}
				ans = max(ans, count);
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}