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

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

string str[2];

void solve()
{
	queue<int> d[4000];
	int ans = 0;

	if(str[0].length() > str[1].length()){
		swap(str[0],str[1]);
	}

	for(int i = 0; i < str[0].length(); i++){
		for(int j = 0; j < str[1].length(); j++){
			int qsize = d[j].size();
			
			for(int k = 0; k < qsize; k++){
				int now = d[j].front();
				d[j].pop();

				if(j + now >= 4000 || str[0][i] != str[1][j+now])
					continue;

				now++;
				ans = max(ans, now);
				d[j].push(now);
			}
			if(str[0][i] == str[1][j]){
				d[j].push(0+1);
				ans = max(ans,1);
			}

		}
	}
	cout << ans << endl;

			
	
}


int main(void)
{
	while(cin >> str[0] >> str[1], !cin.eof()){
		solve();
	}

	return 0;
}

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

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

int main()
{
  int nw = 0;
  while(1)
    {
      if(NULL == gets(st1))
	{
	  break;
	}
      gets(st2);
      int st1l,st2l;
      st1l = strlen(st1) - 1;
      st2l = strlen(st2) - 1;
      int m = 0;
      for(int i = 0; i < st1l + st2l; i++)
	{
	  for(int ii = 0; ii < 15000; ii++)
	    {
	      flg[ii] = 1;
	    }
	  for(int ii = 0; ii < st1l; ii++)
	    {
	      flg[ii + st2l] = st1[ii];
	    }
	  for(int ii = 0; ii < st2l; ii++)
	    {
	      if(flg[i + ii] == st2[ii])
		{
		  flg[i + ii] = 0;
		}
	      else
		{
		  flg[i + ii] = 1;
		}
	    }
	  int n = 0;
	  for(int ii = 0; ii < 15000; 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;
}

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

bool check(std::string strs)
{
	rep(i, t.length() - strs.length() + 1)
	{
		const auto temp = t.substr(i, strs.length());
		if (strs == temp) { return true; }
	}
	return false;
}

int main()
{
	while (true)
	{
		s.clear(); t.clear();
		ans = 0;

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

		if (s.length() > t.length()) { std::swap(s, t); }
		rep(i, s.length())
		{
			for (int j = 1; i + j < s.length(); ++j)
			{
				const auto temp = s.substr(i, j);
				if (check(temp)) { ans = std::max<int>(ans, temp.length()); }
				else { break; }
			}
		}

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

C++: #include<bits/stdc++.h>
#define STR string

using namespace std;

string s,t;
long long dp[10000][10000];

void solve(){
    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;
            }else{
                dp[i+1][j+1]=(dp[i][j+1]>dp[i+1][j])?dp[i][j+1]:dp[i+1][j];
            }
        }
    }
cout << dp[s.size()][t.size()] << endl;
}


int main(){
while(1){
cin >> s >>t;
if(s=="EOF")break;
solve();
}
//cout << s.size();
return 0;
}

C++: #include<cstdio>
#include<cstring>
int d[4044][4044] = {};
int main()
{
        char r[2][4002] = {};
        while (gets (r[0])) {
                gets (r[1]);
memset (d, 0, sizeof d);
                int le, ri, a = 0;
                le = strlen (r[0]), ri = strlen (r[1]);
                for (int i=1; i<=le; i++) {
                        for (int j=1; j<=ri; j++) {
                                if (i==1 || j==1) d[i][j] = 1;
                                else if (r[0][i-1] == r[1][j-1]) d[i][j] = d[i-1][j-1] + 1;
                                else d[i][j] = 0;
                                a = a>d[i][j] ? a:d[i][j];
                        }
                }
                printf ("%d\n", a);
        }
        return 0;
}