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++){
		bool isok = true;
		for(int x=0,dy=y;x<n,dy>=0;x++,dy--){
			if(mat[dy][x] == 0) isok = false;
		}
		res = max((y+1)*(int)isok,res);
	}

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

	return res;
}

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

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

	return res;
}

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

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

	return res;
}

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

		res = max(n*(int)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 <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[66049] = {0};
		for(int y=1;y<=n;y++)
			for(int x=1;x<=n;x++)scanf("%1d",map+x+257*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*257]?map[j+257*k] + dp[j+v[i][0]][k+v[i][1]]:0);
		}
		printf("%d\n",m);
	}
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);

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

string s[300];
int n;
int tate[300][300], yoko[300][300], naname1[300][300], naname2[300][300];

int main(){
	while(cin>>n && n){
		rep(i, n) cin>>s[i];
		int ans = 0;
		rep(i, 300) rep(j, 300) tate[i][j] = yoko[i][j] = naname1[i][j] = naname2[i][j] = 0;
		rep(i, n){
			rep(j, n){
				tate[i+1][j+1] = tate[i][j+1]+(s[i][j]=='1'?1:0);
				yoko[i+1][j+1] = yoko[i+1][j]+(s[i][j]=='1'?1:0);
				naname1[i+1][j+1] = naname1[i][j]+(s[i][j]=='1'?1:0);
				ans = max({ans, tate[i+1][j+1], yoko[i+1][j+1], naname1[i+1][j+1]});
			}
		}
		for(int i = n; i > 0; i--){
			for(int j = 1; j <= n; j++){
				naname2[i][j] = naname2[i+1][j-1]+(s[i-1][j-1]=='1'?1:0);
				ans = max(ans, naname2[i][j]);
			}
		}
		cout<<ans<<endl;
	}
}

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

char map[255][255];
int dire4[][2] = { {1, 0}, {-1, 1}, {0, 1}, {1, 1} };

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