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.h>
#include <algorithm>
using namespace std;

int main() {
  while(1) {
    char str[2][4001];
    int state;
    state = scanf("%s\n", str[0]);
    if(state == EOF) break;
    scanf("%s\n", str[1]);

    int data[strlen(str[0])+1][strlen(str[1])+1];
    int maxL = 0;
    for(int i = 0; i <= strlen(str[0]); i++) {data[i][0] = 0;}
    for(int j = 0; j <= strlen(str[1]); j++) {data[0][j] = 0;}

    for(int i = 1; i <= strlen(str[0]); i++) {
      for(int j = 1; j <= strlen(str[1]); j++) {
	if(str[0][i-1] == str[1][j-1]) data[i][j] = data[i-1][j-1]+1;
	else     data[i][j] = 0;

	if(data[i][j] > maxL) maxL = data[i][j];
      }
    }
    cout << maxL << endl;
  }
  return 0;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(1){
		string s, t; int roop1=0, save=0, ans = 0;
		cin>>s;
		cin>>t;
		if(s=="")
		break;
	for (int i = 0; i<s.size(); i++){
		for (int j = 0; j<t.size(); j++){
			if (s[i] == t[j]){
				roop1 = 0;
				save= 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						if (s[i + roop1] == t[j + roop1]){
							save += 1;
							roop1++;
						}
					else if (s[i + roop1] != t[j + roop1]){
							ans=max(ans,save);
							break;
						}
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	}
	
	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 cal(string s1,string s2,int s,int p)
{
	int cnt=0;
	for(int i=p;i<s2.size();i++)
	{
		if(s1[i+s]==s2[i])cnt++;
		else break;
	}
	return cnt;
}
int main()
{
	while(1)
	{
		string s1,s2;
		cin >> s1;
		if(cin.eof())break;
		cin >> s2;
		ans=0;
		for(int i=0;i<s1.size();i++)
		{
			for(int j=0;j<s1.size()-i;j++)
			{
				if(s2[j]==s1[j+i])
				{
					ans=max(ans,cal(s1,s2,i,j));
				}
			}
		}
		for(int i=0;i<s2.size();i++)
		{
			for(int j=0;j<s2.size()-i;j++)
			{
				if(s1[j]==s2[j+i])
				{
					ans=max(ans,cal(s2,s1,i,j));
				}
			}
		}
		cout << ans << endl;
		s1.clear();
		s2.clear();
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main(){
while(1){
char str[2][4005];
int counter=0,ans=0,no,noo;
    scanf("%s%s",str[0],str[1]);
    int le=strlen(str[0]);
    int ng=strlen(str[1]);
    for(int i=0;i<le;i++){
        for(int j=0;j<ng;j++){
            if(str[0][i]==str[1][j]){
                counter++; no=i; noo=j;
                while(1){
                    i++; j++;
                    if(i==le || j==ng){ break;}
                    if(str[0][i]==str[1][j]){
                        counter++;
                    }else{
                        break;
                    }
                }
                ans=max(ans,counter);
                counter=0;
                i=no;
                j=noo;
            }
        }
    }
    cout<<ans<<endl;
}
    return 0;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	while(cin>>s>>t){
		int roop1=0, save=0, ans = 0;
	for (int i = 0; i<s.size(); i++){
		for (int j = 0; j<t.size(); j++){
			if (s[i] == t[j]){
				roop1 = 0;
				save= 0;
				while (1){
						if (s[i + roop1] == t[j + roop1]){
							save += 1;
							roop1++;
						}
					else if (s[i + roop1] != t[j + roop1]){
							ans=max(ans,save);
							break;
					}
				}
			}
		}
	}
	cout<<ans<<endl;
	}
}

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int dp[4096][4096];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s1, s2;

    while (cin >> s1 >> s2)
    {
        memset(dp, 0, sizeof(dp));

        int ans = 0;

        REP(i, s1.size())
        {
            REP(j, s2.size())
            {
                if (s1[i] == s2[j])
                {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                    ans = max(dp[i + 1][j + 1], ans);

                }
                else
                {
                    dp[i + 1][j + 1] = 0;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include<cstdio>
#include<cstring>
#define max(a,b) (a>b?a:b)
char a[4000],b[4000];
int table[4001],n;
int main(){
	while(~scanf("%s%s",a,b)){
	memset(table,0,sizeof(table));
	n=0;
	for(int i=1;i<=strlen(a);i++){
		for(int j=strlen(b);j;j--){
			if(a[i-1]==b[j-1])
				table[j]=max(table[j],table[j-1]+1);
			n=max(n,table[j]);
		}
	}
	printf("%d\n",n);
	}
	return 0;
}

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

using namespace std;

int main(){

	string a, b, c;
	while(cin >> a, !cin.eof())
	{
		cin >> b;

		int res = 0;
		int k = b.size();
		c = string(k,'1');
		a = c + a;
		
		for(int i = 0; i < (int)a.size(); i++)
		{
			int ct = 0;
			
			for(int j = 0; j < (int)b.size(); j++)
			{
				if( a[j] == b[j] )
					res = max( ++ct, res); 
				else
					ct = 0;
			}
			
			b = "2" + b;
		}
		
		cout << res << endl;
	}
	return 0;	
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	while(1){
		string s, t; int roop1=0, roop2 = 0, save[50000]={}, ans = 0;
		cin>>s;
		cin>>t;
		if(cin.eof())
		break;
	for (int i = 0; i<s.size(); i++){
		for (int j = 0; j<t.size(); j++){
			if (s[i] == t[j]){
				roop1 = 0;
				save[roop2] = 0;
				while (1){
					if (s[i + roop1] == 0 || t[j + roop1] == 0){
						break;
					}
					else{
						if (s[i + roop1] == t[j + roop1]){
							save[roop2] += 1;
							roop1++;
						}
						else if (s[i + roop1] != t[j + roop1]){
							roop2++;
							break;
						}
					}
				}
			}
		}
	}
	sort(save, save + roop2 + 1);
	ans = save[roop2];
	cout << ans << endl;
	}
	return 0;
}