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++: //↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑





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

		cout << ans << endl;
	}
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
 
int main()
{
  string s, t; 
while(cin >> s){
cin >> t;
  // s??????
  int ans = 0;
  int cnt = 0;
  FOR(i,0,t.length()) {
  	cnt = 0;
   	for(int j = 0; j < s.length() && i + j < t.length(); j++) {
      if(s[j] == t[i+j]) cnt++;
      else {
        ans = max(ans, cnt);
        cnt = 0;
      }
    }
    ans = max(ans, cnt);
  }
    
  // t??????
  FOR(i,0,s.length()) {
    cnt = 0;
   	for(int j = 0; j < t.length() && i + j < s.length(); j++) {
      if(s[i+j] == t[j]) cnt++;
      else {
        ans = max(ans, cnt);
        cnt = 0;
      }
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

string s, t;
int dp[4000 + 1][4000 + 1];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> s >> t) {
        int n = s.size();
        int m = t.size();
        rep(i, n + 1)rep(j, m + 1) dp[i][j] = 0;
        rep(i, n)rep(j, m) {
            if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
        }
        int ans = 0;
        rep(i, n + 1)rep(j, m + 1) ans = max(ans, dp[i][j]);
        cout << ans << endl;
    }
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
short dp[4001][4001]={};
char str1[4005],str2[4005];
short ans=0;
int main(){while(scanf("%s%s",str1,str2)!=-1){
  for(int i=0;i<strlen(str1);i++){
    for(int j=0;j<strlen(str2);j++){
      if(str1[i]==str2[j]){
         if(i==0 || j==0){ dp[i][j]=1;ans=max(ans,dp[i][j]);}         else{ dp[i][j]=1+dp[i-1][j-1];ans=max(ans,dp[i][j]);}
      }}}printf("%d\n",ans); }return 0;}

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

using namespace std;

int main(){

	string a, b;

	while(cin >> a, !cin.eof())
	{
		int res = 0;
		cin >> b;
		
		for(int i = 0; i < a.size(); i++)
		{
			int ct = 0;
			
			for(int j = 0; j < a.size(); j++ )
			{
				if( a[j] == b[j] )
					res = max( ++ct, res); 
				else
					ct = 0;
			}
			
			b = "x" + b;
		}
		
		cout << res << endl;
	}
	return 0;	
}

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

using namespace std;

#define rep(i,n) for(i=0;i<n;i++)

unsigned short dp[4010][4010];

int main(){
  int i,j;
  string s,t;

  while(cin >> s >> t){
    int N=s.length(),M=t.length(),res=0;

    rep(i,4010) rep(j,4010) dp[i][j] = 0;
    rep(i,N) rep(j,M){
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
      } else {
        int tmp = max(dp[i][j+1],dp[i+1][j]);
        res = max(res,tmp);
        dp[i+1][j+1] = 0;
      }
    }

    cout << res << endl;
//    cout << dp[N][M] << endl;
  }

  return 0;
}

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

using namespace std;

int check(string, string);

int main()
{
  //ifstream ifs("data.txt");
  string str1, str2;
  while( cin >> str1 >> str2 ){

    int res = 0;

    for(int i = 0; i < max(str1.size(), str2.size()); i++){
      if(str1.size() > str2.size())
	rotate(str1.begin(), str1.begin() + 1, str1.end());
      else
	rotate(str2.begin(), str2.begin() + 1, str2.end());

      res = max(res, check(str1, str2));
    }

    cout << res << endl;
  }
}

int check(string str1, string str2)
{
  int sn = 0, res = 0;
  for(int i = 0; i < min(str1.size(), str2.size()); i++){
    if(str1[i] == str2[i])
      sn++;
    else{
      res = max(res, sn);
      sn = 0;
    }
  }
  return res;
}