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<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,n,max,cnt,x,y;
	int dx[4]={1,1,0,-1},dy[4]={0,-1,-1,-1};
	char xy[225][225];
	while(1){
		max=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) cin>>xy[i];
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(xy[i][j]=='1'){
					for(k=0;k<4;k++){
						cnt=1;
						y=i; x=j;
						while(1){
							y=y+dy[k]; x=x+dx[k];
							if(y>=n||x>=n||y<0||x<0||xy[y][x]!='1') break;
							cnt++;
						}
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

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

const int MAXN = 256;
int N;
char G[MAXN][MAXN];

int count(int pi, int pj, int vi, int vj) {
  if(G[pi][pj] == '0') return 0;
  int ni = pi + vi;
  int nj = pj + vj;
  if(ni < 0 || ni >= N) return 1;
  if(nj < 0 || nj >= N) return 1;
  return count(ni, nj, vi, vj) + 1;
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
        cin >> G[i][j];
      }
    }
    int maxi = 0;
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
        maxi = max(maxi, count(i,j,1,0));
        maxi = max(maxi, count(i,j,0,1));
        maxi = max(maxi, count(i,j,1,1));
        maxi = max(maxi, count(i,j,1,-1));
      }
    }
    cout << maxi << endl;
  }
  return 0;
}

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

char A[1000][1000];

int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < 1000 ; i++)
			for(int j = 0 ; j < 1000 ; j++)
				A[i][j] = '0';
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				cin >> A[i+300][j+300];
		int ans = 0;
		for(int i = 0 ; i < 1000 ; i++){
			int p = 0;
			for(int j = 0 ; j < 1000 ; j++){
				if( A[i][j] == '0' ) p = 0;
				else p += A[i][j] - '0';
				ans = max(ans,p);
			}
		}
		for(int i = 0 ; i < 1000 ; i++){
			int p = 0;
			for(int j = 0 ; j < 1000 ; j++){
				if( A[j][i] == '0' ) p = 0;
				else p += A[j][i] - '0';
				ans = max(ans,p);
			}
		}
		for(int i = 0 ; i < 1000 ; i++){
			int p = 0;
			for(int j = 0 ; i+j < 1000 ; j++){
				if( A[i][i+j] == '0' ) p = 0;
				else p += A[j][i+j] - '0';
				ans = max(ans,p);
			}
		}
		for(int i = 1000 ; i >=0 ; i--){
			int p = 0;
			for(int j = 0 ; i-j >= 0 ; j++){
				if( A[j][i-j] == '0' ) p = 0;
				else p += A[j][i-j] - '0';
				ans = max(ans,p);
			}
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<numeric>
#include<iterator>
#include<vector>

using namespace std;
typedef unsigned int val;

int tate(char mass[256][256],int n)
{
	int count=0,a=0,b=0,ans=-1;
	
	while(1)
	{

		if(b==n)break;
		
		if(mass[a][b]=='0' || a==n)
		{ 
			
			if(ans<count) ans=count;

			a=0;b++;count=0;continue; 

		}
		
		a++;count++;

	}
	return ans;
}

int yoko(char mass[256][256],int n)
{
	int count=0,a=0,b=0,ans=-1;
	
	while(1)
	{

		if(a==n)break;
		
		if(mass[a][b]=='0' || b==n)
		{ 
			
			if(ans<count) ans=count;

			b=0;a++;count=0;continue; 

		}
		
		b++;count++;

	}
	return ans;
}


int main() 
{
	int n;
	while(cin>>n && n)
	{
		char mass[256][256];
		
		for(int i=0; i<n; i++) cin >> mass[i];

		int ans=-1;

		if( ans < tate( mass, n ) ) ans = tate( mass, n );
		if( ans < yoko( mass, n ) ) ans = yoko( mass, n );
		
		for(int i=0; i<n ;i++)
		{
			for(int j=0; j<n; j++)
			{
				
				if(mass[i][j]=='1')
				{
					int a=i,b=j,count=0;
					while(1)
					{
						if( mass[a][b] == '0' || b<0 || n<a) break;
						mass[a][b]='0';
						count++;
						a++;b--;
						if(b==n){ a++;b=n-1; }
					}
					if(ans<count) ans=count;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

const int MAX_N = 255;
int n;
char grid[MAX_N][MAX_N];
int dp[MAX_N][MAX_N][4];

int main()
{
    while(cin >> n && n) {
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                cin >> grid[i][j];
        
        memset(dp, 0, sizeof(dp));
        for(int j = 0; j < n; j++) 
            for(int k = 0; k < 4; k++) 
                dp[0][j][k] = grid[0][j] - '0';

        int ans = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(grid[i][j] == '0') {
                    for(int k = 0; k < 4; k++)
                        dp[i][j][k] = 0;
                } else {
                    dp[i][j][0] = (j) ? dp[i-1][j-1][0] + 1 : 1;
                    dp[i][j][1] = dp[i-1][j][1] + 1;
                    dp[i][j][2] = (j != n - 1) ? dp[i-1][j+1][2] + 1 : 1;
                    dp[i][j][3] = (j) ? dp[i][j-1][3] + 1 : 1;
                }
                for(int k = 0; k < 4; k++)
                    ans = max(ans, dp[i][j][k]);
            }
        }

        cout << ans << endl;
    }
}

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;
	}
}