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<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<cstdlib>

using namespace::std;

int main(){
  int number;
  int i;
  int j;
   char string[300] = {};
  int seq = 0;
  int max = 0;

  cin>>number;

  while(number != 0){
    int matrix[number][number];

  for(i = 0; i < number; i++){
    scanf("%s", string);
    for(j = 0; j < number; j++){
      matrix[i][j] = string[j] - '0';
    }
  }

  for(i = 0; i < number; i++){ // 横
    for(j = 0; j < number; j++){
      if(matrix[i][j] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }
  for(i = 0; i < number; i++){ // たて
    for(j = 0; j < number; j++){
      if(matrix[j][i] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }

  for(i = 0; i < number; i++){
    for(j = 0; j <= i; j++){
      if(matrix[i -j][j] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }

  for(i = 0; i < number - 1; i++){
    for(j = 0; j <= i; j++){
      if(matrix[(number - 1) - (i - j)][(number - 1) - j]){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }
  for(i = 0; i < number; i++){
    for(j = 0; j <= i; j++){
      if(matrix[(number - 1) - (i -j)][j] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }
  for(i = 0; i < number - 1; i++){
    for(j = 0; j <= i; j++){
      if(matrix[i -j][(number - 1) - j] == 1){
        seq++;
      }else{
        seq = 0;
      }
      if(max < seq){
        max = seq;
      }
    }
    seq = 0;
  }
  seq = 0;
  printf("%d\n", max);
  max = 0;
  cin>>number;
  }
  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) * 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>

const int N = 257;
using namespace std;

int main(void){
  while( true ){
    int n;
    int ans = 0;
    int G[N][N] = {{0,},};
    int H[N][N][4] = {{{0,},},};
    
    cin >> n;
    if(n == 0)break;
    
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	char c;
	cin >> c;
	G[i+1][j+1] = c - '0';
      }
    }
    for(int j = 1; j < n + 1; j++){
      if( G[1][j] == 1 ){
	for(int k = 0; k < 4; k++){
	  if ( k == 0 ){
	    H[1][j][k] = H[1][j - 1][0] + 1;
	  }else{
	    H[1][j][k] = 1;
	  }
	}
      }
    }
    for(int i = 2; i < n + 1; i++){
      for(int j = 1; j < n + 1; j++){
	if( G[i][j] ){
	  H[i][j][0] = H[i][j - 1][0] + 1;
	  H[i][j][1] = H[i][j - 1][1] + 1;
	  H[i][j][2] = H[i - 1][j][2] + 1;
	  H[i][j][3] = H[i - 1][j + 1][3] + 1;
	}
      }
    }
    for( int i = 1; i < n + 1; i++){
      for(int j = 1; j < n + 1; j++){
	for(int k = 0; k < 4; k++){
	  ans = max( ans, H[i][j][k] );
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

char m[255][255];
int n,dp1[255][255],dp2[255][255],dp3[255][255],dp4[255][255];

int main(){
	while(cin>>n&&n){
		rep(i,n){
			fill(dp1[i],dp1[i]+n,0);
			fill(dp2[i],dp2[i]+n,0);
			fill(dp3[i],dp3[i]+n,0);
			fill(dp4[i],dp4[i]+n,0);
		}
		rep(i,n)rep(j,n){cin>>m[i][j];m[i][j]-='0';}
		rep(i,n)rep(j,n)if(m[i][j]){
			dp1[i][j]=(i>0?dp1[i-1][j]+1:1);
			dp2[i][j]=(j>0?dp2[i][j-1]+1:1);
			dp3[i][j]=(i>0&&j>0?dp3[i-1][j-1]+1:1);
			dp4[i][j]=(i>0&&j<n-1?dp4[i-1][j+1]+1:1);
		}
		int ans=0;
		rep(i,n)rep(j,n){
			int a=max(dp1[i][j],dp2[i][j]),b=max(dp3[i][j],dp4[i][j]);
			ans=max(ans,max(a,b));
		}
		cout<<ans<<endl;
	}
}