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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
int dp[4005][4005];
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    str n,m;
    while(cin >> n){
    rep(i,0,4000)rep(j,0,4000)dp[i][j]=0;
    cin >> m;
    rep(i,0,n.size()){
        rep(j,0,m.size()){
            if(n[i]==m[j]&&i>0&&j>0){
                dp[i][j]+=dp[i-1][j-1]+1;
            }else if(n[i]==m[j]){
                dp[i][j]=1;
            }else{
                dp[i][j]=max(dp[i][j-1],dp[i][j]);
            }
        }
    }int ans=0;
    rep(i,0,n.size()){
        ans=max(ans,dp[i][m.size()-1]);
    }
    cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int lcss(string a, string b) {
  int res = 0;
  for(int i=-(int)a.size(); i<(int)a.size(); ++i) {
    int len = 0;
    for (int j=max(i,0); j<min(a.size()+i,b.size()); ++j) {
      if (a[j-i] == b[j]) res = max(res,++len);
      else len = 0;
    }
  }
  return res;
}

int main() {
  string a, b;
  while(cin >> a >> b) {
    cout << lcss(a,b) << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

char a[12000], b[12000], t[12000];

int main(){
  while(~scanf("%s", a)){
    scanf("%s", b);

    strcpy(t, b);
    memset(b, '\0', sizeof(b));
    strcpy(&b[3999], t);

    int res = 0;
    rep(i, 8001){
      int count = 0, k = 0;
      REP(j, i, i + 4001){
	//	if(k == 0 && j == 3999) printf("%d %d\n", k, j);
	if(a[k] != '\0' && b[j] != '\0' && a[k] == b[j]){
	  count++;
	  //	  printf("%d\n", count);
	}else{
	  res = max(res, count);
	  count = 0;
	}
	k++;
      }
      res = max(res, count);
    }
    //    printf("%c %c\n", a[0], b[3999]);
    printf("%d\n", res);
  }
  return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
string s[2];
int search(int id){
  int id2 = (id+1)%2;
  int ret=0;
  int a[40004];
  for(int j=(int)s[id2].size()-1;j>-(int)s[id].size();j--){
    memset(a,0,sizeof(a));
    for(int i=0;i<(int)s[id].size();i++){
      if(i+j < 0) continue;
      if(i+j >= (int)s[id2].size()) continue;
      if(s[id][i]==s[id2][i+j]) a[i]=1;
    }
    int co=0;
    for(int i=0;i<(int)s[id].size()+1;i++){
      if(a[i]) co++;
      else{
	ret = max(ret,co);
	co=0;
      }
    }
  }
  return ret;
}
int main(){
  while(cin >> s[0]){
    cin >> s[1];
    printf("%d\n",search(0));
  }
}

C++: #include<bits/stdc++.h>                                                                              
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define VS vector<string>

int main(void) {
    string s,t;
    int max=0;
    while(cin >> s >> t) {
        int dp[s.size()][t.size()];
        REP(i,s.size()) {
            REP(j,t.size()) {
                dp[i][j] = -1;
            }
        }
        REP(i,s.size()) {
            dp[i][0] = 0;
        }
        REP(i,t.size()) {
            dp[0][i] = 0;
        }

        FOR(i,1,s.size()) {
            FOR(j,1,t.size()) {
                if(s[i] != t[j]) dp[i][j] = 0;
                else dp[i][j] = dp[i-1][j-1] + 1;
                max = fmax(max, dp[i][j]);
            }
        }
        cout << max << endl;
        max = 0;
    }
}

C++: 
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
using namespace std;

int count(string& a, string& b) {
    int a_len = a.length();
    int b_len = b.length();
    int max_lcs = 0;
    int cur_lcs = 0;
    for (int i = 0; i < a_len; i++) {
        for (int j = 0; j < b_len; j++) {
            if (a[i] == b[j]) {
                int k = 0;
                while (i+k < a_len && j+k < b_len && a[i+k] == b[j+k]) {
                    k++;
                    cur_lcs++;
                }
                if (max_lcs < cur_lcs) {
                    max_lcs = cur_lcs;
                }
                cur_lcs = 0;
            }
        }
    }
    return max_lcs;
}

int main() {
    string a, b;
    while (cin >> a >> b) {
        cout << count(a, b) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	string s,t;
	cin>>s>>t;
	
	int ans=0;
	for(int i=0;i<s.size();i++){
		for(int j=0;j<t.size();j++){
			if(s[i]==t[j]){
                                int sum=0;
				sum++;
				for(int k=1;k<min(s.size(),t.size());k++){
					if(s[i+k]==t[j+k]){
						sum++;
					} else{
						ans=max(ans,sum);
						break;
					}
				}
			}
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

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",str1)!=EOF){
		scanf("%s",str2);
}
  printf("%d\n",ans); }return 0;}