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 "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)(????????´?????£????´??????????????£????´???`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(j, n) {
		int out = 0, score = 0;
		int cnt = 0;
		vi v(3, 0);
		while (out < 3) {
			string s;
			if (cin >> s)cnt++;

			if (s == "HIT") {
				RREP(i, 3) {
					if (v[i] == 1) {
						if (i == 2)score++;
						else v[i + 1]++;
						v[i]--;

					}
				}
				v[0]++;
			}
			else if (s[0] == 'O') {
				out++;
			}
			else {
				REP(i, 3) {
					if (v[i] == 1) {
						score++;
						v[i] = 0;
					}
				}
				score++;
			}
			assert(cnt <= 100);

		}
		cout << score << endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
	string str,str2;
	vector<short int> array[4001];
	int i,j;
	
	for(i=0;i<4001;i++)
		for(j=0;j<4001;j++)
			array[i].push_back(0);
	
	for(;cin >> str;)
	{
		cin >> str2 ;
		int ans=0;
		for(i=1;i<=str.size();i++)
		{
			for(j=1;j<=str2.size();j++)
			{
				array[i][j]=0;
				if(str[i-1]==str2[j-1])
					array[i][j]=array[i-1][j-1]+1;
				if(ans<array[i][j])
					ans=array[i][j];
			}
		}
		cout << ans << endl;
	}
}

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

using namespace std;

string in[2];

void solve()
{
	int res = 0;


	//for(int u = 0; u < 2; u++){
		for(int i = 0; i < in[0].length(); i++){
			for(int j = 0; j < in[1].length(); j++){
				if(in[0][i] == in[1][j]){
					int row = 1;
					for(int k = 1; i+k < in[0].length() && j+k < in[1].length(); k++,row++){
						if(in[0][i+k] != in[1][j+k])
							break;
					}
					res = max(res,row);
				}
			}
		}
	//	swap(in[0],in[1]);

//	}

	cout << res << endl;
}

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

	return 0;
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	for(int o=0;o<3;o++){
		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;
	}
	return 0;
}

C++: #include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>


using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
char A[4002],B[4002];
int DP[4002][4002];


int main(){
	while(1){
		scanf("%s",A);
		scanf("%s",B);
		memset(DP,0,sizeof(DP));
		int ans=0;
		rep(i,strlen(A)){
			rep(j,strlen(B)){
				if(A[i]==B[j]){
					if(i!=0&&j!=0){
						DP[i][j]+=DP[i-1][j-1];
					}
					DP[i][j]++;
				}
				ans=max(ans,DP[i][j]);
			}
		}
	printf("%d\n",ans);
	}
}

C++: //JOI 0528 Common Sub-String
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	for(int o=0;o<4;o++){
                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;
	}
	return 0;
}

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

using namespace std;

int main() {
	string a;
	while (getline(cin, a)) {
		string b;
		getline(cin, b);
		string ss;
		string ll;
		if (a.size() > b.size()) {
			ss = b;
			ll = a;
		} else {
			ss = a;
			ll = b;
		}
		int counter = 0;
		int counter2 = 0;
		for (int i = 0; i < ss.size(); i++) {
			counter2 = 0;
			int counter3 = 0;
			while (counter2 < ll.size() && ll.find(ss[i], counter2) != string::npos) {
				counter3 = 1;
				for (int j = ll.find(ss[i], counter2)+1; j < ll.size(); j++) {
					if (ll[j] == ss[i+counter3]) {
						counter3++;
					} else {
						break;
					}
				}
				counter = max(counter, counter3);
				counter2 = ll.find(ss[i], counter2)+1;
			}
		}
		cout << counter << endl;
	}
	return 0;
}

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

#define MAXLEN 4001

using namespace std;

string str[2];
int len[2],lng,sht;

int main(void)
{
	cin >> str[0] >> str[1];
	len[0] = str[0].length();
	len[1] = str[1].length();
	if(len[0] < len[1])
	{
		lng = 1;
		sht = 0;
	}
	else
	{
		lng = 0;
		sht = 1;
	}
	int count_len_max = 0;
	for(int offset = 0;offset < len[lng];offset++)
	{
		int count_len = 0;
		for(int count = 0;count < len[sht];count++)
		{
			if(str[lng][(count + offset)%len[lng]] == str[sht][count])
			{
				count_len++;
			}
			else
			{
				count_len = 0;
			}
			count_len_max = max(count_len_max,count_len);
		}
	}
	cout << count_len_max << endl;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;

int main(){
	string s, t;
	while(cin>>s>>t){
		if(s.size()>t.size()) swap(s,t);
		int ans = 0;
		for(int i = 0; i < s.size(); i++){
			for(int j = max(1, ans); j < s.size() - i; j++){
				if(t.find(s.substr(i, j))!=string::npos){
					ans = j;
				}
			}
		}
		cout<<ans<<endl;
	}
}