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 <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long lint;

int main()
{
	char s[4096], t[4096];
	static int dp[2][4096];
	
	while (scanf("%s", s) == 1){
		scanf("%s", t);
		
		memset(dp, 0, sizeof(dp));
		
		int ans = 0;
		
		for (int i = 1; s[i - 1]; i++){
			for (int j = 1; t[j - 1]; j++){
				if (s[i - 1] == t[j - 1])
					dp[i & 1][j] = dp[(i - 1) & 1][j - 1] + 1;
				else dp[i & 1][j] = 0;
				ans = max(ans, dp[i & 1][j]);
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

C++: #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
//#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const int inf2 = 1145141919;
const ld pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//??£??\???????????¨???
	ll to, cost;
};
struct S {//???????????±?????\???????????°
	int from, to, cost;
};
bool operator<(S a, S b) { return a.cost < b.cost; }
bool operator>(S a, S b) { return a.cost > b.cost; }
struct H {
	int x, y;
};
ll gcm(ll i, ll j) {//?????§??¬?´???°
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad?????§?¨???????2??????????????¢
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
string a, b;
int dp[4000][4000];
signed main() {
	while (cin >> a >> b) {
		int n = a.size(), m = b.size();
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				dp[i][j] = 0;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (a[i] == b[j]) {
					if (i > 0 && j > 0) {
						dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
						ans = max(dp[i][j], ans);
					}
				}
			}
		}
		cout << ans << endl;
	}
	getchar(); getchar();
}

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

int main() {
    string s, t;
    while (cin >> s) {
        cin >> t;
        int dp[s.size()][t.size()];
        for (int i = 0; i < s.size(); i++) {
            for (int j = 0; j < t.size(); j++) {
                if (s[i] == t[j]) {
                    dp[i][j] = 1;
                } else {
                    dp[i][j] = 0;
                }
            }
        }

        for (int i = 1; i < s.size(); i++) {
            for (int j = 1; j < t.size(); j++) {
                if (dp[i][j]) {
                    dp[i][j] += dp[i - 1][j - 1];
                }
            }
        }

        int ans = 0;
        for (int i = 0; i < s.size(); i++) {
            for (int j = 0; j < t.size(); j++) {
                ans = max(ans, dp[i][j]);
            }
        }

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

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	static char a[4096], b[4096];
	while (~scanf("%s%s", a, b))
	{
		int n = strlen(a);
		int m = strlen(b);
		int res = 0;
		for (int i = 1 - m; i < n; ++i)
		{
			int len = 0;
			for (int j = 0 + max(0, -i), k = max(0, i); j < m && k < n; ++j, ++k)
			{
				if (a[k] == b[j])
					max_swap(res, ++len);
				else
					len = 0;
			}
		}
		printf("%d\n", res);
	}
}

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

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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[12] = {2, 2, 2, 1, 0, -1, -2, -2, -2, -1, 0, 1};
int dy[12] = {1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2};
int main(void){
	int px, py, N;
	while(cin >> px >> py && (px||py)){
		int pyon = (9*py+px);
		cin >> N;
		int spr[11];
		rep(i, N){
			int a, b;
			cin >> a >> b;
			spr[i] = (9*b)+a;
		}
		if(N == 0){
			FIN("NA");
			continue;
		}
		bool flag = false;
		queue<P> que;
		que.push(P(pyon, 0));
		while(!que.empty()){
			P p = que.front();
			int x = p.first%9;
			int y = p.first/9;
			int spX = spr[p.second]%9;
			int spY = spr[p.second]/9;
			que.pop();
			if(p.second == N){
				//FIN(x);
				//FIN(y);
				flag = true;
				break;
			}
			rep(i, 12){
				int nx = x+dx[i];
				int ny = y+dy[i];
				if(nx >= 0 && nx < 10 && ny >= 0 && ny < 10){
					if( (spX + 1) >= nx && (spY + 1) >= ny && (spX - 1) <= nx && (spY - 1) <= ny){
						que.push(P(((9*ny)+nx), p.second+1));
					}
				}
			}
		}
		cout << (flag?"OK":"NA") << endl;
	}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}