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;

int n;
char mat[255][255];
// vertical
int v[255][255];
// horizontal
int h[255][255];
// right-down diagonally
int rd[255][255];
// left-down diagonally
int ld[255][255];

int solve(){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            v[i][j] = h[i][j] = rd[i][j] = ld[i][j] = 0;
        }
    }

    for(int j = 0; j < n; j++){
        if(mat[0][j]=='1')  v[0][j] = h[0][j] = rd[0][j] = ld[0][j] = 1;
    }

    for(int i = 1; i < n; i++){
        for(int j = 0; j < n; j++){
            if(mat[i][j]=='1'){
                if(j != 0)      h[i][j] = h[i][j-1]+1;    
                else            h[i][j] = 1;
                v[i][j] = v[i-1][j]+1;
                if(j != n-1)    ld[i][j] = ld[i-1][j+1]+1;
                else            ld[i][j] = 1;
                if(j != 0)      rd[i][j] = rd[i-1][j-1]+1;
                else            rd[i][j] = 1;
            }
        }
    }

    int ret = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            ret = max(ret, max(max(max(h[i][j], v[i][j]), rd[i][j]),ld[i][j]));
        }
    }

    return ret;
}

int main(){
    while(cin >> n){
        if(n == 0)  break;

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

        cout << solve() << endl;
    }

    return 0;
}

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

using namespace std;

int N;
int Max;
vector< vector<char> > Field;

void DFS_right(int y, int x, int count)
{
	if(Max < count)
	{
		Max = count;
	}
	if(0 <= x && x < N && 0 <= y && y < N && Field[y][x] == '1')
	{
		DFS_right(y, x + 1, count + 1);
	}	
}

void DFS_down(int y, int x, int count)
{
	if(Max < count)
	{
		Max = count;
	}
	if(0 <= x && x < N && 0 <= y && y < N && Field[y][x] == '1')
	{
		DFS_down(y + 1, x, count + 1);
	}	
}

void DFS_rightdown(int y, int x, int count)
{
	if(Max < count)
	{
		Max = count;
	}
	if(0 <= x && x < N && 0 <= y && y < N && Field[y][x] == '1')
	{
		DFS_rightdown(y + 1, x + 1, count + 1);
	}	
}

void DFS_leftdown(int y, int x, int count)
{
	if(Max < count)
	{
		Max = count;
	}
	if(0 <= x && x < N && 0 <= y && y < N && Field[y][x] == '1')
	{
		DFS_leftdown(y + 1, x - 1, count + 1);
	}	
}

void solve()
{
	while(cin >> N, N)
	{
		Field.resize(N);
		for(int i = 0; i < N; ++i)
		{
			Field[i].resize(N);
			for(int j = 0; j < N; ++j)
			{
				cin >> Field[i][j];
			}
		}

		Max = 0;
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				if(Field[i][j] == '1')
				{
					DFS_right(i, j + 1, 1);
					DFS_down(i + 1, j, 1);
					DFS_rightdown(i + 1, j + 1, 1);
					DFS_leftdown(i + 1, j - 1, 1);
				}
			}
		}
		cout << Max << endl;
	}
}

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

C++: #include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using pii = pair<int, int>; using vi = vector<int>;
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

int n;
bool isinrange(int x, int y) {
	return x >= 0 && x < n&&y >= 0 && y < n;
}

signed main() {
	for (; cin >> n && n;) {
		vector<string>  a(n);
		rep(i, 0, n)cin >> a[i];

		int ans = 0;
		int di[] = { 0, 1, 1, 1 };
		int dj[] = { 1, 0, 1, -1 };
		rep(i, 0, n)rep(j, 0, n) {
			rep(k, 0, 4) {
				int ii = i, jj = j;
				int cnt = 0;
				while (a[ii][jj] == '1') {
					cnt++;
					ans = max(ans, cnt);
					ii += di[k];
					jj += dj[k];
					if (!isinrange(ii, jj))break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
main(){
int n;
while(scanf("%d",&n),n){
int m=0,v[4][2]={{0,1},{1,0},{-1,1},{1,1}},a[257][257]={{0}};
for(int y=n;y;y--)for(int x=n;x;x--)scanf("%1d",&a[x][y]);
for(int i=0;i<4;i++){
int d[257][257]={{0}};
for(int k=n;k;k--)for(int j=n;j;j--)m=std::max(m,d[j][k]=a[j][k]?a[j][k]+d[j+v[i][0]][k+v[i][1]]:0);}
printf("%d\n",m);
}
}

C++: #include<cstdio.h>
#include<iostream.h>
using namespace std;
int main(void){
	int i,j,k,n,max,cnt,x,y;
	int dx[4]={1,1,0,-1},dy[4]={0,-1,-1,-1};
	char xy[225][225];
	while(1){
		max=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) cin>>xy[i];
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(xy[i][j]=='1'){
					for(k=0;k<4;k++){
						cnt=1;
						y=i; x=j;
						while(1){
							y=y+dy[k]; x=x+dx[k];
							if(y>=n||x>=n||y<0||x<0||xy[y][x]!='1') break;
							cnt++;
						}
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: /*Grid*/
#include<stdio.h>
void func(int,int);
int n;
int i,j;
char a[255][255];
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<iostream>
using namespace std;
int main(void){
	int i,j,k,n,max,cnt,x,y;
	int dx[4]={1,1,0,-1},dy[4]={0,-1,-1,-1};
	char xy[225][225];
	while(1){
		max=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) cin>>xy[i];
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(xy[i][j]=='1'){
					for(k=0;k<4;k++){
						cnt=1;
						y=i; x=j;
						while(1){
							y=y+dy[k]; x=x+dx[k];
							if(y>=n||x>=n||y<0||x<0||xy[y][x]!='1') break;
							cnt++;
						}
//						printf("cnt=%d\n",cnt);
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}