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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define maxup(a,b) (a=max(a,b))
#define minup(a,b) (a=min(a,b))
#define INF 999999999

int n;

int exe(int y,int x,int dy,int dx,vector<string> data){
    int tmp = 0;
    while(1){
        if( !(x>=0 && y>=0 && x<n && y<n) ){
            break;
        }
        tmp+=data[y][x]-'0';
        x+=dx,y+=dy;
    }
    return tmp;
}


int solve(int y,int x,vector<string> data){
    int lu=0,ld=0;
    int ru=0,rd=0;
    
    rd = exe(y,x,1,1,data);
    ru = exe(y,x,-1,1,data);
    ld = exe(y,x,1,-1,data);
    lu = exe(y,x,-1,-1,data);
    
    return max(rd+lu,ru+ld)-(data[y][x]-'0');
}


int main(){
    while(cin>>n&&n){
        vector<string> data(n);
        rep(i,n)cin>>data[i];

        int maxi = -1;
        rep(i,n){
            int tmp=0;
            rep(j,n){
                tmp+=data[i][j]-'0';
            }
            maxup(maxi,tmp);
        }
        rep(i,n){
            int tmp=0;
            rep(j,n){
                tmp+=data[j][i]-'0';
            }
            maxup(maxi,tmp);
        }
        
        rep(i,n){
            rep(j,n){
                if(i==0||j==0||i==n-1||j==n-1)
                    maxup(maxi,solve(i,j,data));
            }
        }
        cout<<maxi<<endl;
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back

int n;
int main(){
    int n;
    while(cin>>n&&n){
        int dp[256][256][4];
        rep(i,256)rep(j,256)rep(k,4)dp[i][j][k] = 0;

        vector<string> data(n);
        rep(i,n)cin>>data[i];
        
        int maxi = 0;
        rep(i,n){
            rep(j,n){
                if(data[i][j]=='1'){
                    dp[i][j][0] = ( j-1>=0          )*dp[i  ][j-1][0] +1;
                    dp[i][j][1] = ( i-1>=0          )*dp[i-1][j  ][1] +1;
                    dp[i][j][2] = ( i-1>=0&&j-1>=0  )*dp[i-1][j-1][2] +1;
                    dp[i][j][3] = ( i-1>=0&&j+1<n   )*dp[i-1][j+1][3] +1;

                    rep(k,4) maxi = max(maxi,dp[i][j][k]);
                }
            }
        }
        cout<<maxi<<endl;
    }
}

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 = -1;
    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 <bits/stdc++.h>
using namespace std;
struct vektor{
	int t;//縦
	int y;//横
	int m;//右斜め
	int h;//左斜め
};
int main(){
	while(true){
		int n;
		cin>>n;
		if(n==0){
			break;
		}
		vektor tebl[n+2][n+2]={};
		char l;
		int ans=0;
		for(int p=1;p<n+1;p++){
			for(int k=1;k<n+1;k++){
				cin>>l;
				if(l=='1'){
					tebl[p][k].t=tebl[p-1][k].t+1;
					tebl[p][k].y=tebl[p][k-1].y+1;
					tebl[p][k].m=tebl[p-1][k+1].m+1;
					tebl[p][k].h=tebl[p-1][k-1].h+1;
					if(tebl[p][k].t>ans){
						ans=tebl[p][k].t;
					}
					if(tebl[p][k].y>ans){
						ans=tebl[p][k].y;
					}
					if(tebl[p][k].m>ans){
						ans=tebl[p][k].m;
					}
					if(tebl[p][k].h>ans){
						ans=tebl[p][k].h;
					}
				}else{
					tebl[p][k].t=0;
					tebl[p][k].y=0;
					tebl[p][k].m=0;
					tebl[p][k].h=0;
					}
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


void solve(int n) {
    vector<vector<int>> v(n, vector<int>(n, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            scanf("%1d", &v[i][j]);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int cnt = 0;
        for (int j = 0; j < n; ++j) {
            if(v[i][j]) cnt++;
            else cnt = 0;
            ans = max(ans, cnt);
        }
    }
    for (int i = 0; i < n; ++i) {
        int cnt = 0;
        for (int j = 0; j < n; ++j) {
            if(v[j][i]) cnt++;
            else cnt = 0;
            ans = max(ans, cnt);
        }
    }
    auto dp = v;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(i && j && dp[i][j]) dp[i][j] += dp[i-1][j-1];
            ans = max(ans, dp[i][j]);
        }
    }
    dp = v;
    for (int i = 0; i < n; ++i) {
        for (int j = n-1; j >= 0; --j) {
            if(i && j != n-1 && dp[i][j]) dp[i][j] += dp[i-1][j+1];
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << "\n";
}

int main() {
    int n;
    while(cin >> n, n){
        solve(n);
    }
    return 0;
}