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++: import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
for(;sc.hasNext();){
String s=sc.next();
String t=sc.next();
System.out.println(lcs(s,t).length());
}
}

	static String lcs(String s, String t){
		int m=s.length(), n=t.length();
		int[][] d=new int[n+1][m+1];
		int[][] v=new int[n+1][m+1];
		for(int j=1; j<=n; j++){
			for(int i=1; i<=m; i++){
				if(s.charAt(i-1)==t.charAt(j-1)){
					d[j][i]=d[j-1][i-1]+1;
					v[j][i]=0;
				}else if(d[j][i-1]>d[j-1][i]){
					d[j][i]=d[j][i-1];
					v[j][i]=+1;
				}else{
					d[j][i]=d[j-1][i];
					v[j][i]=-1;
				}
			}
		}
		String r="";
		for(int i=m, j=n; i>0&&j>0;){
			if(v[j][i]>0)
				i--;
			else if(v[j][i]<0)
				j--;
			else{
				r=s.charAt(i-1)+r;
				i--;
				j--;
			}
		}
		return r;
	}

}

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

using namespace std;

int main(void){
	int a,b;
	while(1){
		string str;
		string str2;
		int ans=0;
		cin >> str;
		if(str=="EOF")break;
		cin >> str2;
		for(a=0;a<str.size();a++){
			int res=0;
			string tmp= str.substr(a, str.size()-a);
			for(b=0;b<min(tmp.size(),str2.size());b++){
				if(tmp[b]==str2[b])res++;
				else ans=max(res,ans),res=0;
				if(min(tmp.size(),str2.size())-1==b)ans=max(res,ans);
			}
		}
		cout << ans << endl;
	}
	return 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);
      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;
    }
  for(int i = 0; i < nw; i++)
    {
      printf("%d\n",ans[i]);
    }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

int dp[4002][4002];
int main(){
	string a,b;
	while(cin >> a >> b){
	int as=a.size();
	int bs=b.size();
	int ans=0;
	for(int i=1;i<=as;i++){
		for(int j=1;j<=bs;j++){
			if(a[i]==b[j]){
				dp[i][j]=dp[i-1][j-1]+1;
			}else{
				dp[i][j]=0;
			}
			ans=max(ans,dp[i][j]);

		}
	}
	cout << ans << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    char a[4002],b[4002];
    while(scanf("%s\n%s\n",a,b)!=-1){
        int asize=strlen(a),bsize=strlen(b);
        int ma=0;
        for(int i=0;i<asize;i++){
            int miat=min(bsize,asize-i);
            bool is=false;
            int now=0;
            for(int j=0;j<miat;j++){
                if(!is&&a[i+j]==b[j]){
                    now=1;
                    is=true;
                }else if(is&&a[i+j]==b[j])now++;
                else if(is&&a[i+j]!=b[j]){
                    ma=max(ma,now);
                    now=0;
                    is=false;
                }
            }
            ma=max(now,ma);
        }
        printf("%d\n",ma);
    }
}

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)
    {
      scanf("%s",st1);
      if(st1[0] == EOF)
	{
	  break;
	}
      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 "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

int dp[4001][4001];
int main() {
	string a, b;
	while (cin >> a >> b) {
		for (int i = 0; i < 4001; ++i) {
			for (int j = 0; j < 4001; ++j) {
				dp[i][j] = -1e9;
			}
		}
		dp[0][0] = 0;
		int ans = 0;
		for (int i = 0; i < a.size(); ++i) {
			for (int j = 0; j < b.size(); ++j) {
				if (a[i] == b[j]) {
					if (i > 0 && j > 0) {
						dp[i][j] = dp[i - 1][j - 1] + 1;
					}
					else {
						dp[i][j] = 1;
					}

				}
				ans = max(ans, dp[i][j]);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}