Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"strings"
	"sort"
)

var scanner= bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		mp := make([]string, n)
		for i := range mp {
			scanner.Scan()
			mp[i] = "0" + scanner.Text() + "0"
		}
		tmp := make([]string, n+2)
		for i := range tmp {
			tmp[i] = "0"
		}
		mp = append([]string{strings.Join(tmp, "")}, mp...)
		mp = append(mp, strings.Join(tmp, ""))
		score := make([][][]int, n+2)
		for i := range score {
			score[i] = make([][]int, n+2)
			for j := range score[i] {
				score[i][j] = make([]int, 4)
			}
		}
		max_score := 0
		for i := 1; i < n+1; i++ {
			for j := 1; j < n+1; j++ {
				tmps := mp[i]
				if string(tmps[j]) == "1" {
					score[i][j][0] = score[i - 1][j][0] + 1
					score[i][j][1] = score[i][j - 1][1] + 1
					score[i][j][2] = score[i - 1][j - 1][2] + 1
					score[i][j][3] = score[i - 1][j + 1][3] + 1
					max_score = max(max_score, score[i][j][0], score[i][j][1], score[i][j][2], score[i][j][3])
				}
			}
		}
		fmt.Println(max_score)
	}
}

func max(a, b, c, d, e int) int {
	buf := []int{a, b, c, d, e}
	sort.Ints(buf)
	return buf[len(buf)-1]
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int t[256][256];
int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				scanf("%1d", &t[i][j]);

		int maxLen = 0;
		for (int i = 0; i < n; ++i)
		{
			int v, h;
			v = h = 0;
			for (int j = 0; j < n; ++j)
			{
				if (t[i][j])
					maxLen = max(maxLen, ++v);
				else
					v = 0;
				if (t[j][i])
					maxLen = max(maxLen, ++h);
				else
					h = 0;
			}
			int a, b, c, d;
			a = b = c = d = 0;
			for (int j = 0; i+j < n; ++j)
			{
				if (t[j][i+j])
					maxLen = max(maxLen, ++a);
				else
					a = 0;
				if (t[i+j][j])
					maxLen = max(maxLen, ++b);
				else
					b = 0;
				if (t[j][n-1-i-j])
					maxLen = max(maxLen, ++c);
				else
					c = 0;
				if (t[i+j][n-1-j])
					maxLen = max(maxLen, ++d);
				else
					d = 0;
			}
		}
		printf("%d\n", maxLen);
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{ 
	int n;
	while( cin >> n && n )
	{
		vector < string > map(n);
		for ( int i = 0; i < n; i++ )
			cin >> map[i];

		int answer = 0;
		int cnt;
		for ( int i = 0; i < n; i++ )
		{
			cnt = 0;
			for ( int j = 0; j < n; j++ )
			{
				if ( map[j][i] == '0' )
					break;
				cnt++;
			}
			answer = max( answer, cnt );

			cnt = 0;
			for ( int j = 0; j < n; j++ )
			{
				if ( map[i][j] == '0' )
					break;
				cnt++;
			}
			answer = max( answer, cnt );
		}

		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < n; j++ )
			{
				cnt = 0;
				while ( i+cnt < n && j+cnt < n )
				{
					if ( map[i+cnt][j+cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );

				cnt = 0;
				while ( i+cnt < n && j-cnt >= 0 )
				{
					if ( map[i+cnt][j-cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );
			}
		}

		cout << answer << endl;

	}
	return 0;
}

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

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());
int n;
int dx[]={1,0,1,-1};
int dy[]={0,1,1,1};
vector<vint> vv;
int foo(int a,int b,int c){
	int ret=0;
	int now=0;
	// return 0;
	while(0<=a&&a<n&&0<=b&&b<n){
		if(vv[a][b]==1){
			now++;
		}
		else{
			now=0;
		}
		// cout<<now<<endl;
		ret=max(ret,now);
		a+=dx[c];
		b+=dy[c];
	}
	return ret;
}




int main(){
	// vector<vint> vv;
	// int n;
	while(cin>>n,n){
		initvv(vv,n,n);
		rep(i,n){
			rep(j,n){
				char t;
				cin>>t;
				vv[i][j]=t-'0';
				// cout<<vv[i][j]<<" ";
			}
			// cout<<endl;
		}
		int ans=0;
		rep(i,n){
			ans=max(ans,foo(0,i,0));
			ans=max(ans,foo(i,0,1));
			ans=max(ans,foo(0,i,2));
			ans=max(ans,foo(i,0,2));
			ans=max(ans,foo(i,0,3));
			ans=max(ans,foo(n-1,i,3));
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
#define MAX 255

char G[MAX+2][MAX+2];
int n, T[MAX+2][MAX+2][4];

void solve(){
    for ( int i = 0; i < n + 2; i++ ){
	for ( int j = 0; j < n + 2; j++ ){
	    for ( int k = 0; k < 4; k++ ) T[i][j][k] = 0;
	}
    }

    static const int di[4] = {-1, -1, -1, 0};
    static const int dj[4] = {1, 0, -1, -1};

    int maxv = 0;

    for ( int i = 0; i <= n; i++ ){
	for ( int j = 0; j <= n; j++ ){
	    if ( G[i][j] == '1' ){
		for ( int k = 0; k < 4; k++ ){
		    T[i][j][k] = T[i+di[k]][j+dj[k]][k] + 1;
		    maxv = max( maxv, T[i][j][k] );
		}
	    }
	}
    }

    cout << maxv << endl;
}

main(){
    while(cin >> n, n){
	for ( int i = 1; i <= n; i++ ){
	    for ( int j = 1; j <= n; j++ ) cin >> G[i][j];
	}
	solve();
    }
}

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

int main()
{
	int a;
	while (cin >> a, a) {
		bool b[258][258];
		for (int c = 0; c < a; c++) {
			string s; cin >> s;
			for (int d = 0; d < a; d++) {
				b[c][d] = s[d] == '1';
			}
		}
		int MAX = 0;
		for (int e = 0; e < a; e++) {
			for (int f = 0; f < a; f++) {
				for (int h = -1; h < 2; h++) {
					for (int i = -1; i < 2; i++) {
						if (h | i) {
							int g = 0;
							for (int j = 0; e + h*j >= 0 && e + h*j < a&&f + i*j >= 0 && f + i*j < a; j++) {
								if (b[e + h*j][f + i*j]) { g++; MAX = max(MAX, g); }
								else g--;
							}
						}
					}
				}
			}
		}
		cout << MAX << endl;
	}
}

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

#define MAX 256

char s[MAX][MAX];
int n;

int findMax(int i, int j, int di, int dj){
	int count = 0, res = 0;

	while(i<n && j<n){
		if(s[i][j] == '1') count++;
		else{
			res = max(res, count);
			count = 0;
		}
		i += di;
		j += dj;
	}

	return max(res, count);
}

int main(void){
	while(cin>>n && n){
		for(int i=0;i<n;i++) cin>>s[i];

		int ans = -1;
		for(int i=0;i<n;i++){
			ans = max(ans, findMax(i,0,0,1));
			ans = max(ans, findMax(0,i,1,0));
			ans = max(ans, findMax(i,0,1,1));
			ans = max(ans, findMax(i,0,1,-1));
			ans = max(ans, findMax(0,i,1,1));
			ans = max(ans, findMax(0,i,1,-1));
		}

		cout<<ans<<endl;
	}

	return 0;
}

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

int main()
{
	int a;
	while (cin >> a, a) {
		bool b[258][258];
		for (int c = 0; c < a; c++) {
			string s; cin >> s;
			for (int d = 0; d < a; d++) {
				b[c][d] = s[d] == '1';
			}
		}
		int MAX = 0;
		for (int e = 0; e < a; e++) {
			for (int f = 0; f < a; f++) {
				for (int h = -1; h < 2; h++) {
					for (int i = -1; i < 2; i++) {
						if (h || i) {
							int g = 0;
							for (int j = 0; e + h*j >= 0 && e + h*j < a&&f + i*j >= 0 && f + i*j < a; j++) {
								if (b[e + h*j][f + i*j]) { g++; MAX = max(MAX, g); }
								else g--;
							}
						}
					}
				}
			}
		}
		cout << MAX << endl;
	}
}