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>
using namespace std;

char A[300][300];

int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				cin >> A[i][j];
		int ans = 0;
		for(int i = 0 ; i < n ; i++){
			int p = 0;
			for(int j = 0 ; j < n ; j++){
				p += A[i][j] - '0';
			}
			if( p == n ) ans = max(p,ans);
		}
		for(int i = 0 ; i < n ; i++){
			int p = 0;
			for(int j = 0 ; j < n ; j++){
				p += A[j][i] - '0';
			}
			if( p == n ) ans = max(p,ans);
		}
		for(int i = 0 ; i <= n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j <= n ; j++){
				if( i+j >= n ) break;
				p += A[j][i+j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		for(int i = 0 ; i <= n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j <= n ; j++){
				if( i+j >= n ) break;
				p += A[i+j][j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		for(int i = 0 ; i <= n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j <= n ; j++){
				if( n-1-i-j < 0 ) break;
				p += A[j][n-1-i-j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		
		for(int i = 0 ; i <= n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j <= n ; j++){
				if( n-1-i-j < 0 ) break;
				p += A[n-1-i-j][j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		cout << ans << endl;
	}
}

C++: /*Grid*/
#include<stdio.h>
void func(int,int);
int n;
int i,j;
char a[30][30];
int cnt,max;
int dx[8]={0,1,1,1,0,-1,-1,-1};
int dy[8]={1,1,0,-1,-1,-1,0,1};
int main(void)
{
	//int i,j;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++) scanf("%s",a[i]);
		//for(i=1;i<n;i++) printf("%s\n",a[i]);
		max=0;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(a[i][j]=='1'){
					cnt=1;
					func(i,j);
					//if(max<cnt) max=cnt;
				}
			}	
		}
		//printf("\n");
		//for(i=0;i<n;i++) printf("%s\n",a[i]);
		printf("%d\n",max);
	}
	return 0;
}
void func(int y,int x)
{
	int xx,yy,i1;
	a[y][x]='0';
	for(i1=0;i1<8;i1++){
		xx=x+dx[i1]; yy=y+dy[i1];
		if(xx>n||xx<=0||yy>n||yy<=0||a[yy][xx]=='0'){
			if(max<cnt) max=cnt,/*printf("%d\n",cnt)*/,cnt=0,
			func(i,j);
		}
		else if(xx<n&&xx>=0&&yy<n&&yy>=0&&a[yy][xx]=='1'){
			cnt++; func(yy,xx);
		}
		
	}	
}

C++: #include <cstdio>
#include <algorithm>
int main(){
	int n;
	while(scanf("%d",&n),n){
		int m=0,v[4][2] = {{0,-1},{-1,0},{1,-1},{-1,-1}},map[66049] = {0};
		for(int y=1;y<=n;y++)
			for(int x=1;x<=n;x++)scanf("%1d",map+x+257*y);

		for(int i=0;i<4;i++){
			int dp[66049] = {0};
			for(int k=1;k<=n;k++)
				for(int j=1;j<=n;j++)m = std::max(m,dp[j+257*k] = map[j+k*257]?map[j+257*k] + dp[j+v[i][0]+257*(k+v[i][1])]:0);
		}
		printf("%d\n",m);
	}
}

C++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		char G[257][257];
		for(int i=0; i<=n+1; i++){
			for(int j=0; j<=n+1; j++){
				G[i][j] = '0';
			}
		}

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

		int DP[257][257][4];
		for(int i=0; i<=n+1; i++){
			for(int j=0; j<=n+1; j++){
				for(int k=0; k<4; k++){
					DP[i][j][k] = 0;
				}
			}
		}

		int DP_max = 0;

		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(G[i][j]=='0')
					continue;

				DP[i][j][0] = DP[i-1][j][0]+1;
				DP[i][j][1] = DP[i][j-1][1]+1;
				DP[i][j][2] = DP[i-1][j-1][2]+1;
				DP[i][j][3] = DP[i-1][j+1][3]+1;

				for(int k=0; k<4; k++){
					if(DP[i][j][k]>DP_max){
						DP_max = DP[i][j][k];
					}
				}
			}
		}

		cout << DP_max << '\n';
	}

	return 0;
}

C++: #include<iostream>

const int N = 257;
using namespace std;

int main(void){
  while( true ){
    int n;
    int ans = 0;
    int G[N][N] = {{0,},};
    int H[N][N][4] = {{{0,},},};
    
    cin >> n;
    if(n == 0)break;
    
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	char c;
	cin >> c;
	G[i+1][j+1] = c - '0';
      }
    }
    for(int j = 1; j < n + 1; j++){
      if( G[1][j] == 1 ){
	for(int k = 0; k < 4; k++){
	  H[1][j][k] = 1;
	}
      }
    }
    for(int i = 2; i < n + 1; i++){
      for(int j = 1; j < n + 1; j++){
	if( G[i][j] ){
	  H[i][j][0] = H[i][j - 1][0] + 1;
	  H[i][j][1] = H[i][j - 1][1] + 1;
	  H[i][j][2] = H[i - 1][j][2] + 1;
	  H[i][j][3] = H[i - 1][j + 1][3] + 1;
	}
      }
    }
    for( int i = 1; i < n + 1; i++){
      for(int j = 1; j < n + 1; j++){
	for(int k = 0; k < 4; k++){
	  ans = max( ans, H[i][j][k] );
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;
int n;
vector< vector<int> > m;
int d[] = {-1,0,1};

int c(int x){
    int ans = 0;
    REP(i,3){
	int temp = 0;
	int j = 0;
	while(!(x+d[i]*j < 0 || n <=  x+d[i]*j )){
	    if(m[j][x+d[i]*j] == 1){
		temp++;
		ans = max(ans,temp);
	    }else{
		ans = max(ans,temp);
		temp = 0;
	    }
	    j++;
	    if(j == n) break;
	}
    }
    return ans;
}
int r(int x){
    int ans = 0;
    REP(i,3){
	int temp = 0;
	int j = 0;
	while(!(x+d[i]*j < 0 || n <=  x+d[i]*j )){
	    if(m[x+d[i]*j][j] == 1){
		temp++;
		ans = max(ans,temp);
	    }else{
		ans = max(ans,temp);
		temp = 0;
	    }
	    j++;
	    if(j == n) break;
	}
    }
    return ans;
}

int main(){
    while(true){
	cin >> n;
	if(n == 0) break;
	m = vector< vector<int> >(n,vector<int>(n,0));
	REP(i,n){
	    string s;
	    cin >> s;
	    REP(j,n){
		m[i][j] = (int)(s[j]-'0');
	    }
	}
	int ans = 0;
	REP(i,n){
	    ans = max(ans,r(i));
	    ans = max(ans,c(i));
	}
	cout << ans << endl;
    }
    return 0;
}