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

const int SIZE = 255;

int main()
{
	bool table[ SIZE ][ SIZE * 3 ];

	int n;
	while( cin >> n && n ){
		memset( table, 0, sizeof(table) );
		for( int i = 0; i < n; ++i ){
			for( int j = 0; j < n; ++j ){
				char c;
				cin >> c;
				table[ i ][ j + SIZE ] = c == '1' ? true : false;
			}
		}
		int maxLength = 0;
		for( int i = 0; i < n; ++i ){
			int col = 0, row = 0;
			for( int j = 0; j < n; ++j ){
				if( table[ i ][ j + SIZE ] ){
					++col;
					if( maxLength < col ) maxLength = col;
				}else{
					col = 0;
				}
				if( table[ j ][ i + SIZE ] ){
					++row;
					if( maxLength < row ) maxLength = row;
				}else{
					row = 0;
				}
			}
		}
		for( int i = 0; i < n; ++i ){
			int diaL = 0, diaR = 0;
			for( int j = 0; j < n; ++j ){
				if( table[ i - j ][ j + SIZE ] ){
					++diaL;
					if( maxLength < diaL ) maxLength = diaL;
				}else{
					diaL = 0;
				}
				if( table[ j ][ n - 1 - i + j + SIZE ] ){
					++diaR;
					if( maxLength < diaR ) maxLength = diaR;
				}else{
					diaR = 0;
				}
			}
		}
		cout << maxLength << endl;
	}

	return 0;
}

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[257][257] = {{0}};
		for(int y=1;y<=n;y++)
			for(int x=1;x<=n;x++)scanf("%1d",&map[x][y]);

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

C++: #include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int N;
vector<string> G;

int solve(int row,int col){
    int res = 0;
    for(int k=0; k<6; k++){
        int x = row;
        int y = col;
        int now = 0;
        while(x>=0 and x<N and y<N and y>=0){
            if(G[x][y]-'0' > 0) now++;
            else{
                chmax(res,now);
                now = 0;
            }
            y += dy[k];
            x += dx[k];
        }
        chmax(res,now);
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    while(N != 0){
        int ans = 0;
        G.resize(N);
        for(int i=0; i<N; i++){
            cin >> G[i];
        }
        for(int i=0; i<N; i++){
            chmax(ans,solve(i,0));
            chmax(ans,solve(0,i));
            chmax(ans,solve(i,N-1));
            chmax(ans,solve(N-1,i));
        }
        cout << ans << enld;
        cin >> N;
    }
    return 0;
}

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

int dfs(int y, int x, int dy, int dx, vector<vector<int>> const& v) {
    int n = v.size();
    if(y < 0 || n <= y || x < 0 || n <= x || v[y][x] == 0) {
        return 0;
    }
    return dfs(y+dy, x+dx, dy, dx, v) + 1;
}

int main() {
    int n;
    while(cin >> n, n) {
        vector<vector<int>> v(n, vector<int>(n));
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                char c; cin >> c;
                v[i][j] = c - '0';
            }
        }
        int res = 0;
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                if(v[i][j] == 1) {
                    res = max(res, dfs(i+1, j, 1, 0, v)+1);
                    res = max(res, dfs(i, j+1, 0, 1, v)+1);
                    res = max(res, dfs(i+1, j+1, 1, 1, v)+1);
                    res = max(res, dfs(i+1, j-1, 1, -1, v)+1);
                }
            }
        }
        cout << res << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int n, y, x;
vector<string> table;
int calc(int sy, int sx) 
{
    int res = 0;
    int ny = y, nx = x;
    ny += sy;
    nx += sx;
    while(ny >= 0 and ny < n and nx >= 0 and nx < n)
    {
        if(table[ny][nx] == '0') break;
        res++;
        ny += sy;
        nx += sx;
    }
    return res;
}
int search()
{
    int res = 0;
    res = max(res, calc(1, 0) + calc(-1, 0));
    res = max(res, calc(0, 1) + calc(0, -1));
    res = max(res, calc(-1, 1) + calc(1, -1));
    res = max(res, calc(-1, -1) + calc(1, 1));
    return res + 1;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n, n)
    {
        table.resize(n);
        for(int i = 0; i < n; i++) cin >> table[i];
        int ans = 0;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                if(table[i][j] == '0') continue;
                y = i, x = j;
                ans = max(ans, search());
            }
        }
        cout << ans << "\n";
    }
    return 0;
}