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

        rep(i,n){
            rep(j,n){
                if(data[i][j]=='1'){
                    if(j-1>=0)          dp[i][j][0] = dp[i  ][j-1][0]+1;
                    else                dp[i][j][0] = 1;
                    if(i-1>=0&&j-1>=0)  dp[i][j][1] = dp[i-1][j-1][1]+1;
                    else                dp[i][j][1] = 1;
                    if(i-1>=0)          dp[i][j][2] = dp[i-1][j  ][2]+1;
                    else                dp[i][j][2] = 1;
                    if(i-1>=0&&j+1>=0)  dp[i][j][3] = dp[i-1][j+1][3]+1;
                    else                dp[i][j][3] = 1;
                }
            }
        }
        int maxi = -1;
        rep(i,n){
            rep(j,n){
                rep(k,4){
                    maxup(maxi,dp[i][j][k]);
                }
            }
        }
        cout<<maxi<<endl;
    }
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 260;
int n;
string grid[MAX_N];
int max_len;
int memo[MAX_N][MAX_N][4];

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

int rec(int y, int x, int d)
{
    if (memo[y][x][d] >= 0)
        return memo[y][x][d];

    int nx = x + dx[d];
    int ny = y + dy[d];

    if (nx < 0 || nx >= n || ny < 0 || ny >= n)
        return 1;
    if (grid[ny][nx] == '0')
        return 1;

    return memo[y][x][d] = (rec(ny, nx, d) + 1);
}

int main()
{
    while (cin >> n, n) {
        max_len = 0;
        for (int i = 0; i < n; i++) 
            cin >> grid[i];

        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= n; j++)
                for (int k = 0; k < 4; k++)
                    memo[i][j][k] = -1;

        for (int y = 0; y < n; y++) 
            for (int x = 0; x < n; x++) 
                if (grid[y][x] == '1') {
                    for (int k = 0; k < 4; k++) {
                        int nx = max_len * dx[k] + x;
                        int ny = max_len * dy[k] + y;
                        if (nx < 0 || nx >= n || ny < 0 || ny >= n)
                            continue;
                        if (grid[ny][nx] != '1')
                            continue;
                        max_len = max(max_len, rec(y, x, k));
                    }
                }

        cout << max_len << endl;
    }

    return 0;
}

C++: #include <stdio.h>
#include <math.h>

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 10000000;
//int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0151 : Grid **/
bool grid[256][256];
const int dx[8]={-1, 0, 1, -1, 1, -1, 0, 1}, dy[8]={-1, -1, -1, 0, 0, 1, 1, 1};
int N;

int search(int x, int y, int i)
{
	int num=1;
	while (1) {
		x+=dx[i]; y+=dy[i];
		if_range(x, y, N, N) {
			if (grid[x][y]) {
				num++;
				continue;
			}
		}
		break;
	}
	return num;
}

int main()
{
	while (cin>>N, N) {
		rep(i, N) {
			rep(j, N) {
				char c; cin>>c;
				if (c=='1')
					grid[j][i]=true;
				else
					grid[j][i]=false;
			}
		}
		
		int ans=0;
		rep(i, N) {
			rep(j, N) {
				if (grid[j][i]) {
					rep(k, 8) {
						ans = max(ans, search(j, i, k));
					}
				}
			}
		}
		cout << ans << 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,i+1)sum += p[n*(n-1)+i-j*(n-1)];
			MAX = max(sum,MAX);
		}
		cout << MAX << endl;
	}
}