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

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int dp[4005][4005];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s,t;
	while(cin >> s){
		cin >> t;
		s='.'+s;
		t='.'+t;
		int n=s.size();
		int m=t.size();
		for(int i=0;i<=n;i++){
			for(int j=0;j<=m;j++){
				dp[i][j]=0;
			}
		}
		int res=0;
		for(int i=1;i<n;i++){
			for(int j=1;j<m;j++){
				if(s[i]==t[j]){
					dp[i][j]=dp[i-1][j-1]+1;
				}
				res=max(res,dp[i][j]);
			}
		}
		cout << res << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
  int ans,cnt;
  string s,t;
  while(cin>>s>>t){
    ans=0;
    for(int k=0;k<2;k++){
      for(int i=0;i<s.size();i++){
	cnt=0;
	for(int j=0;j<s.size()-i;j++){
	  if(s[j+i]==t[j]){
	    cnt++;
	    ans=max(ans,cnt);
	  }else{
	    cnt=0;
	  }
	}
      }
      swap(s,t);
    }
    cout<<ans<<endl;
  }
}

C++: include<bits/stdc++.h>                                                                              
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define VS vector<string>

int main(void) {
    string s,t;
    int max=0;
    while(cin >> s >> t) {
        int dp[s.size()][t.size()];
        REP(i,s.size()) {
            REP(j,t.size()) {
                dp[i][j] = -1;
            }
        }
        REP(i,s.size()) {
            dp[i][0] = 0;
        }
        REP(i,t.size()) {
            dp[0][i] = 0;
        }

        FOR(i,1,s.size()) {
            FOR(j,1,t.size()) {
                if(s[i] != t[j]) dp[i][j] = 0;
                else dp[i][j] = dp[i-1][j-1] + 1;
                max = fmax(max, dp[i][j]);
            }
        }
        cout << max << endl;
        max = 0;
    }
}

C++: #include "stdio.h"
#include "string.h"

char st1[5000];
char st2[5000];
char flg[5000];
int ans[1000];

int main()
{
  int nw = 0;
  while(1)
    {
      char w;
      w = getchar();
      if(w == EOF)
	{
	  break;
	}
      scanf("%s",st1);
      sprintf(st1,"%c%s",w,st1);
      scanf("%s",st2);
      int st1l,st2l;
      st1l = strlen(st1);
      st2l = strlen(st2);
      int m = 0;
      for(int i = 0; i < st1l; i++)
	{
	  for(int ii = 0; ii < 5000; ii++)
	    {
	      flg[ii] = 0;
	    }
	  for(int ii = i; ii < st1l; ii++)
	    {
	      flg[ii - i] = st1[ii];
	    }
	  for(int ii = 0; ii < st2l; ii++)
	    {
	      flg[ii] = flg[ii] - st2[ii];
	    }
	  int n = 0;
	  for(int ii = 0; ii < 5000; ii++)
	    {
	      if(flg[ii] == 0)
		{
		  n++;
		  if(n > m)
		    {
		      m = n;
		    }
		}
	      else
		{
		  n = 0;
		}
	    }
	}
      ans[nw] = m;
      nw++;
    }
  for(int i = 0; i < nw; i++)
    {
      printf("%d\n",ans[i]);
    }
  return 0;
}