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<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s[255];
int n;

int solve(bool x){
  int i, j, r, res = 0;
  if(x){
    rep(i, n)for(j = 0;j < n;){
      if(s[i][j] == '0'){ ++j; continue; }
      for(r = j + 1;r < n;++r)if(s[i][r] == '0')break;
      res = max(res, r - j);
      j = r;
    }
  }else{
    rep(i, n)for(j = 0;j < n - i;){
      if(s[j][j + i] == '0'){ ++j; continue; }
      for(r = j + 1;r + i < n;++r)if(s[r][r + i] == '0')break;
      res = max(res, r - j);
      j = r;
    }
  }
  return res;
}
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    scanf("%d", &n);
    if(!n)break;

    rep(i, n)cin >> s[i];

    int res = 0;
    res = solve(1);
    rep(i, n)rep(j, i)swap(s[i][j], s[j][i]);
    res = max(res, solve(1));
    rep(i, n)rep(j, i)swap(s[i][j], s[j][i]);
    res = max(res, solve(0));
    rep(i, n)rep(j, n / 2)swap(s[i][j], s[i][n - j - 1]);
    res = max(res, solve(0));
    pri(res);

//*/

//*/ break;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 256, R = 0, B = 1, RB = 2, LB = 3;

char tile[MAXN][MAXN];
int dp[4][MAXN][MAXN];

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

int main()
{
    int n;
    while(cin >> n && n)
    {
        rep(j,n)rep(i,n) cin >> tile[i][j];

        memset(dp, 0, sizeof(dp));

        rep(j,n)rep(i,n)rep(k,4)
            if(i + dx[k] <0 || i+dx[k] ==n || j+dy[k] <0 || j+dy[k] == n)
                dp[k][i][j] = tile[i][j] - '0';
            else
            {
                if(tile[i+dx[k]][j+dy[k]] == '0') 
                    dp[k][i][j] = tile[i][j] - '0';
                else
                    dp[k][i][j] = dp[k][i+dx[k]][j+dy[k]] + tile[i][j] - '0';
            }

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

        cout << ans << endl;


    }
    return 0;
}

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

char map[255][255];

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

        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                cin >> map[y][x];
            }
        }

        int ans = 0;
        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                int dire4[][2] = {
                    {1, 0}, {-1, 1}, {0, 1}, {1, 1}
                };
                for(int z = 0;z < 4;z++) {
                    int dx = dire4[z][0], dy = dire4[z][1];
                    int cx = x, cy = y;
                    int c = 0;
                    for(;map[cy][cx] == '1' && cx < n && cy < n;cx += dx, cy += dy, c++) ;
                    ans = max(ans, c);
                }
            }
        }
        cout << ans << endl;

    }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int tate[300][300];
int yoko[300][300];
int ue_l[300][300];
int ue_r[300][300];

int main(){
	
	int n, max;
	
	string str[500];
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}else if(n < 2 || n > 300){
			printf("NA\n");
			continue;
		}
		for(int i = 0; i < n; i++){
			cin >> str[i];
		}
		
		for(int x = 0; x < n; x++){
			if(str[0][x] == '1'){
				tate[0][x] = 1;
			}else{
				tate[0][x] = 0;
			}
		}
		for(int y = 1; y < n; y++){
			for(int x = 0; x < n; x++){
				if(str[y][x] == '1'){
					tate[y][x] = tate[y - 1][x] + 1;
				}else{
					tate[y][x] = 0;
				}
			}
		}
		
		max = 0;
		
		for(int y = 0; y < n; y++){
			for(int x = 0; x < n; x++){
				if(max < tate[y][x]){
					max = tate[y][x];
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			if(str[y][0] == '1'){
				yoko[y][0] = 1;
			}else{
				yoko[y][0] = 0;
			}
		}
		for(int x = 1; x < n; x++){
			for(int y = 0; y < n; y++){
				if(str[y][x] == '1'){
					yoko[y][x] = yoko[y][x - 1] + 1;
				}else{
					yoko[y][x] = 0;
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			for(int x = 0; x < n; x++){
				if(max < yoko[y][x]){
					max = yoko[y][x];
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			if(str[y][0] == '1'){
				ue_l[y][0] = 1;
			}else{
				ue_l[y][0] = 0;
			}
		}
		
		for(int x = 0; x < n; x++){
			if(str[0][x] == '1'){
				ue_l[0][x] = 1;
			}else{
				ue_l[0][x] = 0;
			}
		}
		
		for(int x = 1; x < n; x++){
			for(int y = 1; y < n; y++){
				if(str[y][x] == '1'){
					ue_l[y][x] = ue_l[y - 1][x - 1] + 1;
				}else{
					ue_l[y][x] = 0;
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			for(int x = 0; x < n; x++){
				if(max < ue_l[y][x]){
					max = ue_l[y][x];
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			if(str[y][n - 1] == '1'){
				ue_r[y][n - 1] = 1;
			}else{
				ue_r[y][n - 1] = 0;
			}
		}
		
		for(int x = 0; x < n; x++){
			if(str[0][x] == '1'){
				ue_r[0][x] = 1;
			}else{
				ue_r[0][x] = 0;
			}
		}
		
		for(int y = 1; y < n; y++){
			for(int x = 0; x < n - 1; x++){
				if(str[y][x] == '1'){
					ue_r[y][x] = ue_r[y - 1][x + 1] + 1;
				}else{
					ue_r[y][x] = 0;
				}
			}
		}
		
		for(int y = 0; y < n; y++){
			for(int x = 0; x < n; x++){
				if(max < ue_r[y][x]){
					max = ue_r[y][x];
				}
			}
		}
		printf("%d\n", max);
	}
	
	return 0;
}