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

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

string a, b;
set<string> can, can_not;
int ans = 0;

int main() {
	while ( cin >> a ) {
		cin >> b;
		ans = 0;
		if ( a.size() > b.size() ) {
			swap( a, b );
		}
		for ( int i = 0; i < a.size(); i++ ) {
			int cnt = 0;
			for ( int j = 1; j <= a.size() - i; j++ ) {
				if ( can.count( a.substr( i, j ) ) || can_not.count( a.substr( i, j ) ) ) {
					if ( can_not.count( a.substr( i, j ) ) ) {
						break;
					}
					cnt++;
					continue;
				}
				if ( b.find( a.substr( i, j ) ) == string::npos ) {
					can_not.insert( a.substr( i, j ) );
					break;
				}
				cnt++;
			}
			ans = max( ans, cnt );
		}
		printf( "%d\n", ans );
		can.clear();
		can_not.clear();
	}
	return 0;
}