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<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define PB push_back
#define fi first
#define se second
#define ll long long 
#define reps(i,j,k) for(ll i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
int n;
int check(int y,int x,char field[256][256]){
    int res = 0;
    int ny = y;
    int nx = x;
    int tmp=0;
    while(true){
        if(nx < 0 || nx >= n || ny < 0 || ny >= n || field[ny][nx] == '0')break;
        tmp++;
        ny++;
    }
    res = max(res,tmp);
    ny = y;nx= x;tmp = 0;
    while(true){
        if(nx < 0 || nx >= n || ny < 0 || ny >= n || field[ny][nx] == '0')break;
        tmp++;
        nx++;
    }
    res = max(res,tmp);
    ny = y;nx= x;tmp = 0;
    while(true){
        if(nx < 0 || nx >= n || ny < 0 || ny >= n || field[ny][nx] == '0')break;
        tmp++;
        nx++;
        ny++;
    }
    res = max(res,tmp);
    ny = y;nx= x;tmp = 0;
    while(true){
        if(nx < 0 || nx >= n || ny < 0 || ny >= n || field[ny][nx] == '0')break;
        tmp++;
        nx--;
        ny++;
    }
    res = max(res,tmp);
    ny = y;nx= x;tmp = 0;
    return res;
}
int main(){
    while(scanf("%d",&n),n){
        char field[256][256];
        rep(i,n){
            scanf("%s",field[i]);
        }
        int ans = 0;
        rep(i,n){
            rep(j,n){
                if(field[i][j] == '1'){
                    ans = max(ans,check(i,j,field));
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<stdio.h>
char table1[255][256];
int slash[255][255];
int yen[255][255];
int yoko[255][255];
int tate[255][255];
int main(){
	int n;
	while(scanf("%d",&n),n){
		for(int i=0;i<255;i++)
			for(int j=0;j<255;j++)
				table1[i][j]='0';
		for(int i=0;i<n;i++){
			scanf("%s",table1[i]);
		}
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				yen[i][j]=slash[i][j]=tate[i][j]=yoko[i][j]=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==0&&table1[i][j]=='1')tate[i][j]=1;
				else if(i>0&&table1[i][j]=='1')tate[i][j]=tate[i-1][j]+1;
				if(j==0&&table1[i][j]=='1')yoko[i][j]=1;
				else if(j>0&&table1[i][j]=='1')yoko[i][j]=yoko[i][j-1]+1;
				if((i==0||j==n-1)&&table1[i][j]=='1')yen[i][j]=1;
				else if(table1[i][j]=='1')yen[i][j]=yen[i-1][j+1]+1;
			}
		}
		for(int i=n-1;i>=0;i--){
			for(int j=0;j<n;j++){
				if((i==n-1||j==n-1)&&table1[i][j]=='1')slash[i][j]=1;
				else if(table1[i][j]=='1')slash[i][j]=slash[i+1][j+1]+1;
			}
		}
		int ret=0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++){
				if(ret<yen[i][j])ret=yen[i][j];
				if(ret<slash[i][j])ret=slash[i][j];
				if(ret<yoko[i][j])ret=yoko[i][j];
				if(ret<tate[i][j])ret=tate[i][j];
			}
		printf("%d\n",ret);
	}
}

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( A[i][j] == '0' ) p = 0;
				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( A[j][i] == '0' ) p = 0;
				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( A[j][i+j] == '0' ) p = 0;
				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( A[i+j][j] == '0' ) p = 0;
				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( A[j][n-1-i-j] == '0' ) p = 0;
				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][n-1-j] - '0';
				if( A[i+j][n-1-j] == '0' ) p = 0;
				ans = max(p,ans);
				c++;
			}
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
string str;
int cntw[255][255],cnth[255][255],cnta[255][255],cntb[255][255];
int n;
int t[255][255],ans;
int main(){
  while(cin>>n&&n){
    ans=0;
    for(int i=0;i<n;i++){
      cin>>str;
      for(int j=0;j<n;j++){
	t[i][j]=str[j]-'0';
	cntw[i][j]=cnth[i][j]=cnta[i][j]=cntb[i][j]=t[i][j];
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(t[i][j]==0)continue;
	if(i>0){
	  cnth[i][j]+=cnth[i-1][j];
	}
	if(j>0){
	  cntw[i][j]+=cntw[i][j-1];
	}
	if(i>0&&j>0){
	  cnta[i][j]+=cnta[i-1][j-1];
	}
	if(i>0&&j<n-1){
	  cntb[i][j]+=cntb[i-1][j+1];
	}
	ans=max(ans,cnth[i][j]);
	ans=max(ans,cntw[i][j]);
	ans=max(ans,cnta[i][j]);
	ans=max(ans,cntb[i][j]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector< vector<char> > field(n, vector<char>(n));
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin >> field[i][j];
			}
		}
		int ans = 0;
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				if(field[i][j] == '1')
				{
					int count = 1;
					int x = j;
					int y = i;
					while(x < n && field[y][x] == '1')
					{
						ans = max(ans, count);
						++count;
						++x;
					}

					count = 1;
					x = j;
					y = i;
					while(y < n && field[y][x] == '1')
					{
						ans = max(ans, count);
						++count;
						++y;
					}

					count = 1;
					x = j;
					y = i;
					while(x >= 0 && y < n && field[y][x] == '1')
					{
						ans = max(ans, count);
						++count;
						--x; ++y;
					}

					count = 1;
					x = j;
					y = i;
					while(x < n && y < n && field[y][x] == '1')
					{
						ans = max(ans, count);
						++count;
						++x; ++y;
					}
				}
			}
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}