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<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[300][300],d=0,f=0,g,h,j,i,k;
	char z[300][300];
	while(1){
		f=0;
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++)
			scanf("%s",z[i]);
		for(i=0;i<a;i++){
			for(j=0;j<a;j++){
				if(z[i][j]=='1'){
					for(k=0;k<a;k++){
						if(i-k==-1||j+k==a) break;
						if(z[i-k][j+k]=='1'){
							d++;
						}
					}
					if(f<d) f=d;
					d=0;
					for(k=0;k<a;k++){
						if(i+k==a||j+k==a) break;
						if(z[i+k][j+k]=='1'){
							d++;
						}
					}
					if(f<d) f=d;
					d=0;
					for(k=0;k<a;k++){
						if(i+k==a) break;
						if(z[i+k][j]=='1'){
							d++;
						}
					}
					if(f<d) f=d;
					d=0;
					for(k=0;k<a;k++){
						if(j+k==a) break;
						if(z[i][j+k]=='1'){
							d++;
						}
					}
					if(f<d) f=d;
					d=0;
				}
			}
		}
		printf("%d\n",f);
	}
	return 0;
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

int main()
{
    int N;

    while (cin >> N, N)
    {
        int dp[300][300][4];

        rep(i, N) rep(j, N) rep(k, 4) dp[i][j][k] = 0;

        vector<string> grid(N);

        rep(i, N) cin >> grid[i];

        int ans = 0;

        rep(i, N)
        {
            rep(j, N)
            {
                if (grid[i][j] != '1')
                    continue;

                dp[i][j][0] = (j != 0) * dp[i][j - 1][0] + 1;
                dp[i][j][1] = (i != 0) * dp[i - 1][j][1] + 1;
                dp[i][j][2] = (i != 0 && j != 0) * dp[i - 1][j - 1][2] + 1;
                dp[i][j][3] = (i != 0 && j != N - 1) * dp[i - 1][j + 1][3] + 1;

                rep(k, 4) ans = max(ans, dp[i][j][k]);
            }
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	int MAX,sum;
	
	while(cin >> n && n){
		MAX = 0;
		
		char p[n*n+1];
		rep(i,n*n){cin >> p[i];p[i]-='0';}
		rep(i,n){
			sum = 0;
			rep(j,n)sum += p[i*n+j];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n)sum += p[i+j*n];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[i+j*(n+1)];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[(n-1-i)+j*(n-1)];
			MAX = max(sum,MAX);
		}
		
		rep(i,n){
			sum = 0;
			rep(j,n-i-1)sum += p[n*n-1-i-j*(n+1)];
			MAX = max(sum,MAX);
		}
		
		rep(i,n){
			sum = 0;
			rep(j,i+1)sum += p[n*(n-1)+i-j*(n-1)];
			MAX = max(sum,MAX);
		}
		cout << MAX << endl;
	}
}

C++: #include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	int MAX,sum;
	
	while(cin >> n && n){
		MAX = 0;
		
		char p[n*n+1];
		rep(i,n*n){cin >> p[i];p[i]-='0';}
		rep(i,n){
			sum = 0;
			rep(j,n)sum += p[i*n+j];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n)sum += p[i+j*n];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[i+j*(n+1)];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[(n-1-i)+j*(n-1)];
			MAX = max(sum,MAX);
		}
		
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[n*n-1-i-j*(n+1)];
			MAX = max(sum,MAX);
		}
		
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[n*(n-1)+i-j*(n-1)];
			MAX = max(sum,MAX);
		}
		cout << MAX << endl;
	}
}

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

int getMax( int a, int b );
int getWidth( int n, char m[255][255], int s, int t );
int getHeight( int n, char m[255][255], int s, int t );
int getDiagnal1( int n, char m[255][255], int s, int t );
int getDiagnal2( int n, char m[255][255], int s, int t );

int main()
{
    int n;
    char m[255][255];
    
    while( cin >> n )
    {
        if( n == 0 )
            break;

        for( int i = 0; i < 255; i++ )
            for( int j = 0; j < 255; j++ )
                m[i][j] = 0;

        for( int i = 0; i < n; i++ )
            for( int j = 0; j < n; j++ )
                cin >> m[i][j];
        
        int max = 0;
        for( int i = 0; i < n; i++ )
        {
            max = getMax( max, getHeight( n, m, 0, i ) );
            max = getMax( max, getWidth( n, m, i, 0 ) );
            max = getMax( max, getDiagnal1( n, m, 0, i ) );
            max = getMax( max, getDiagnal2( n, m, 0, i ) );
        }
        for( int i = 1; i < n; i++ )
            max = getMax( max, getDiagnal1( n, m, i, n - 1 ) );
        for( int i = 1; i < n; i++ )
            max = getMax( max, getDiagnal2( n, m, i, 0 ) );

        cout << max << endl;
    }

    return 0;
}

int getMax( int a, int b )
{
    if( a > b )
        return a;
    else
        return b;
}

int getWidth( int n, char m[255][255], int s, int t )
{
    int cnt = 0, max = 0;
    while( t < n )
    {
        if( m[s][t] == '1' )
        {
            cnt++;
            if( cnt > max )
                max = cnt;
        }
        else
            cnt = 0;
        t++;
    }
    return max;
}

int getHeight( int n, char m[255][255], int s, int t )
{
    int cnt = 0, max = 0;
    while( s < n )
    {
        if( m[s][t] == '1' )
        {
            cnt++;
            if( cnt > max )
                max = cnt;
        }
        else
            cnt = 0;
        s++;
    }
    return max;
}

int getDiagnal1( int n, char m[255][255], int s, int t )
{
    int cnt = 0, max = 0;
    while( s < n && t >= 0 )
    {
        if( m[s][t] == '1' )
        {
            cnt++;
            if( cnt > max )
                max = cnt;
        }
        else
            cnt = 0;
        s++;
        t--;
    }
    return max;
}


int getDiagnal2( int n, char m[255][255], int s, int t )
{
    int cnt = 0, max = 0;
    while( s < n && t < n )
    {
        if( m[s][t] == '1' )
        {
            cnt++;
            if( cnt > max )
                max = cnt;
        }
        else
            cnt = 0;
        s++;
        t++;
    }
    return max;
}