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 <iostream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <math.h>
#include <utility>
#include <string>
#include <sstream>
#include <complex>
using namespace std;
#define INF 1e+10
#define EPS 1e-10
#define EQ(a,b) abs(a-b)<EPS
typedef pair<int,int> P;
typedef complex<double> CO;
int n;bool swi=false;
P next_p1(int x,int y){
	if(x==n-1)return P(x-y-1,0);
	else if(x==0&&y==n-1)return P(-2,-2);
	else if(y==n-1)return P(0,y-x+1);
	else return P(x+1,y+1);
}
int main()
{
	bool grid[300][300],grid2[300][300];
	while(cin>>n&&n){
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				char c;cin>>c;int s=c-'0';
				grid[i][j]=s==0?false:true;
				grid2[n-i-1][j]=s==0?false:true;
			}
		}
		for(int i=0;i<n;i++){
			int j=0,f=0,d=0;
			bool in=false;grid[i][n]=false;
			while(j<=n){
				if(!in&&grid[i][j]){
					in=true;f=j;
				}else if(in&&!grid[i][j]){
					in=false;d=max(d,j-f);
				}
				j++;
			}
			ans=max(ans,d);
		}
		for(int i=0;i<n;i++){
			int j=0,f=0,d=0;
			bool in=false;grid[i][n];
			while(j<=n){
				if(!in&&grid[j][i]){
					in=true;f=j;
				}else if(in&&!grid[j][i]){
					in=false;d=max(d,j-f);
				}
				j++;
			}
			ans=max(ans,d);
		}
		for(int i=1;i<=2*n-1;i++){
			int m;P t;
			if(i<=n){
				m=i;
				t=P(n-i,0);
			}else{
				m=2*n-i;
				t=P(0,i-n);
			}
			int j=0,f=0,d=0;
			bool in=false;
			while(j<=m){
				if(!in&&grid[t.first][t.second]){
					in=true;f=j;
				}else if(in&&(!grid[t.first][t.second]||j==m)){
					in=false;d=max(d,j-f);
				}
				t=next_p1(t.first,t.second);
				j++;
			}
			ans=max(ans,d);
		}
		for(int i=1;i<=2*n-1;i++){
			int m;P t;
			if(i<=n){
				m=i;
				t=P(n-i,0);
			}else{
				m=2*n-i;
				t=P(0,i-n);
			}
			int j=0,f=0,d=0;
			bool in=false;
			while(j<=m){
				if(!in&&grid2[t.first][t.second]){
					in=true;f=j;
				}else if(in&&(!grid2[t.first][t.second]||j==m)){
					in=false;d=max(d,j-f);
				}
				t=next_p1(t.first,t.second);
				j++;
			}
			ans=max(ans,d);
		}
		cout<<ans<<endl;
	}
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-6;

int diagLLUR(int n,int** mat){
	int res = 0;
	for(int y=0;y<n;y++){
		int c = 0;
		for(int x=0,dy=y;x<n && dy>=0;x++,dy--){
			if(mat[dy][x] == 0) { res = max(res,c); c = 0; }
			else c++;
		}
		res = max(c,res);
	}

	for(int x=0;x<n;x++){
		int c=0;
		for(int dx=x,y=n-1;dx<n && y>=0;dx++,y--){
			if(mat[y][dx] == 0) { res = max(res,c); c = 0; }
			else c++;
		}
		res = max(c,res);
	}

	return res;
}

int diagULLR(int n,int** mat){
	int res = 0;
	for(int x=n-1;x>=0;x--){
		int c=0;
		for(int dx=x,y=0;dx<n && y<n;dx++,y++){
			if(mat[y][dx] == 0) { res = max(res,c); c = 0; }
			else c++;
		}
		res = max(c,res);
	}

	for(int y=0;y<n;y++){
		int c = 0;
		for(int x=0,dy=y;x<n && dy<n;x++,dy++){
			if(mat[dy][x] == 0) { res = max(res,c); c = 0; }
			else c++;
		}
		res = max(c,res);
	}

	return res;
}

int vert(int n,int** mat){
	int res = 0;
	for(int x=0;x<n;x++){
		int c=0;
		for(int y=0;y<n;y++){
			if(mat[y][x] == 0) { res = max(res,c); c = 0; }
			else c++;
		}

		res = max(c,res);
	}

	return res;
}

int hori(int n,int** mat){
	int res = 0;
	for(int y=0;y<n;y++){
		int c=0;
		for(int x=0;x<n;x++){
			if(mat[y][x] == 0) { res = max(res,c); c = 0; }
			else c++;
		}

		res = max(c,res);
	}

	return res;
}

int main(){

	int n;	

	while(~scanf("%d",&n)){
		if(n==0) break;

		int** mat = new int*[n];
		for(int i=0;i<n;i++) mat[i] = new int[n]();

		for(int y=0;y<n;y++){
			char buf[512];
			scanf("%s",buf);
			for(int x=0;x<n;x++){
				mat[y][x] = buf[x]-'0';
			}
		}

		printf("%d\n",max(max(diagLLUR(n,mat),hori(n,mat)),max(diagULLR(n,mat),vert(n,mat))));

		for(int i=0;i<n;i++) delete[] mat[i];
		delete[] mat;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

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

int main(){
	int N;
	char fld[255][255];
	while(cin>>N,N){
		for(int i=0;i<N;i++)for(int j=0;j<N;j++) scanf(" %c",&fld[i][j]);
		int ans = 0;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				for(int d=0;d<8;d++){
					int t = 0;
					for(;;t++){
						int ny = i+dy[d]*t, nx = j+dx[d]*t;
						if(ny<0 || N<=ny || nx<0 || N<=nx || fld[ny][nx]=='0') break;
					}
					ans = max(ans,t);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}