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++: #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 mat[255][255];

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

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

	return res;
}

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

	for(int y=0;y<n;y++){
		int isok = 1;
		for(int x=0,dy=y;x<n,dy<n;x++,dy++){
			if(mat[dy][x] == 0) isok = 0;
		}
		res = max((n-y)*isok,res);
	}

	return res;
}

int vert(int n){
	int res = 0;
	for(int x=0;x<n;x++){
		int isok = 1;
		for(int y=0;y<n;y++){
			if(mat[y][x] == 0) isok = 0;
		}

		res = max(n*isok,res);
	}

	return res;
}

int hori(int n){
	int res = 0;
	for(int y=0;y<n;y++){
		int isok = 1;
		for(int x=0;x<n;x++){
			if(mat[y][x] == 0) isok = 0;
		}

		res = max(n*isok,res);
	}

	return res;
}

int main(){

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

		for(int y=0;y<n;y++){
			char buf[128];
			scanf("%s",buf);
			for(int x=0;x<n;x++){
				mat[y][x] = buf[x]-'0';
			}
		}
		printf("%d\n",max(max(diagLLUR(n),hori(n)),max(diagULLR(n),vert(n))));
	}
}

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

int main(){
  int n;
  int field[255][255];
  int d;
  string tmp;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++){
      cin >> tmp;
      for(int j=0;j<n;j++)field[i][j] = tmp[j]-'0';
    }

    int ans = 0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(field[i][j]){
	  d = 1;
	  while(i+d<n &&  j-d>=0 && field[i+d][j-d])d++;
	  ans = max(ans,d);

	  d = 1;
	  while(i+d<n && field[i+d][j])d++;
	  ans = max(ans,d);

	  d = 1;
	  while(i+d<n && j+d<n && field[i+d][j+d])d++;
	  ans = max(ans,d);

	  d = 1;
	  while(j+d<n && field[i][j+d])d++;
	  ans = max(ans,d);

	}
      }
    }

    cout << ans << endl;
  }
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

int main()
{
    int N;
    
    while(cin >> N, N)
    {
        int dp[300][300][4];

        rep(i, N) rep(j, N) rep(k, 4) dp[i][j][k] = 0;

        vector<string> grid(N);

        rep(i, N) cin >> grid[i];

        int ans = 0;

        rep(i, N)
        {
            rep(j, N)
            {
                if(grid[i][j] != '1') continue;

                if(j != 0) dp[i][j][0] = dp[i][j - 1][0] + 1;
                if(i != 0) dp[i][j][1] = dp[i - 1][j][1] + 1;
                if(i != 0 && j != 0) dp[i][j][2] = dp[i - 1][j - 1][2] + 1;
                if(i != 0 && j != N) dp[i][j][3] = dp[i - 1][j + 1][3] + 1;

                rep(k, 4) ans = max(ans, dp[i][j][k]);

            }
        }

        cout << ans + 1 << 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 <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


bool line(vector<string> v, int len)
{
	int n = v.size();
	
	
	rep(i, len)
	{
		int x = len - 1 + (n - 1) * i;
		if(v[x / n][x % n] == '0') break;
		else if(i + 1 == len) return true;
	}
	
	rep(i, len)
	{
		int x = (n - 1) * (n - len + 1) + (n - 1) * i;
		if(v[x / n][x % n] == '0') break;
		else if(i + 1 == len) return true;
	}
	
	rep(i, len)
	{
		int x = n - len + (n + 1) * i;
		if(v[x / n][x % n] == '0') break;
		else if(i + 1 == len) return true;
	}
	
	rep(i, len)
	{
		int x = n * (n - len) + (n + 1) * i;
		if(v[x / n][x % n] == '0') break;
		else if(i + 1 == len) return true;
	}
	
	return false;
}
int main()
{
    int n;
	while(cin >> n)
	{
		vector<string> v(n);
		rep(i, n) cin >> v[i];
		
		rep(i, n)
		{
			if(count(ALL(v[i]), '0') == 0)
			{
				cout << n << endl;
				goto ng;
			}
			
			rep(j, n)
			{
				if(v[j][i] == '0') break;
				else if(j + 1 == n)
				{
					cout << n << endl;
					goto ng;
				}
			}
		}
		
		for(int i = n; 0 < i; i--) if(line(v, i)) 
		{
			cout << i << endl;
			goto ng;
		}
		
		cout  << 0 << endl;
			
		ng:;
	}
}