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>
using namespace std;

//----- 最大値を返す関数 -----//
int f_max(int , int , int);
//----- 最大値を返す関数のオーバーロード -----//
int f_max(int , int);



int main(void)
{
	//入力変数
	int n = 0;
	//マス配列
	char wh_str_masu[256][256] = {0};

	while (true)
	{
		cin >> n;

		//入力の終わり
		if (n == 0)
		{
			return 0;
		}

		//出力変数
		int ans = 0;

		//max変数
		int max_yoko = 0;
		int max_tate = 0;
		int max_migiagari = 0;
		int max_migisagari = 0;

		//マスの入力
		for (int i = 0; i < n; i++)
		{
			cin >> wh_str_masu[i];
		}

		for (int i = 0; i < n; i++)
		{
			//保存しながら見る変数
			int max_hozon_yoko = 0;
			int max_hozon_tate = 0;
			int max_hozon_migiagari = 0;
			int max_hozon_migisagari = 0;

			//連続していた数を記憶
			int renzoku_tate = 0;
			int renzoku_yoko = 0;
			int renzoku_migiagari = 0;
			int renzoku_migisagari = 0;

			for (int j = 0; j < n; j++)
			{
				//横
				if (wh_str_masu[i][j] == '1')
				{
					renzoku_yoko++;
				}
				//違う値なら大きいほうを格納
				else
				{
					//2数の最大値
					max_hozon_yoko = f_max(max_yoko , renzoku_yoko);
					renzoku_yoko = 0;
				}
				//縦
				if (wh_str_masu[j][i] == '1')
				{
					renzoku_tate++;
				}
				else
				{
					//2数の最大値
					max_hozon_tate = f_max(max_tate , renzoku_tate);
					renzoku_tate = 0;
				}
			}

			//右下
			for (int j = i + 1; j < n; j++)
			{
				if (wh_str_masu[j][j - 1] == '1')
				{
					renzoku_migisagari++;
				}
				else
				{
					max_hozon_migisagari = f_max(max_hozon_migisagari , renzoku_migisagari);
					renzoku_migisagari = 0;
				}
			}
			//右上
			for (int j = 0; j <= i; j++)
			{
				if (wh_str_masu[i - j][j] == '1')
				{
					renzoku_migiagari++;
				}
				else
				{
					max_hozon_migiagari = f_max(max_hozon_migiagari , renzoku_migiagari);
					renzoku_migiagari = 0;
				}
			}

			//大きかったらmaxに代入
			max_yoko = f_max(max_yoko , renzoku_yoko , max_hozon_yoko);
			max_tate = f_max(max_tate , renzoku_tate , max_hozon_tate);
			max_migiagari = f_max(max_migiagari , renzoku_migiagari , max_hozon_migiagari);
			max_migisagari = f_max(max_migisagari , renzoku_migisagari , max_hozon_migisagari);
		}

		//関数を利用し2段階で計算
		ans = f_max(max_yoko , max_tate , max_migiagari);
		ans = f_max(ans , max_migisagari);

		cout << ans << endl;
	}

	return 0;
}




//*****----- 最大値を返す関数 -----*****//

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




//*****----- 最大値を返す関数のオーバーロード -----*****//

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

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


int main(){
	int n;
	while(cin>>n,n){
		vector<string> v(n);
		FOR(i,n) cin>>v[i];
		FOR(i,n) FOR(j,n) v[i][j] -= '0';
		int ans = 0;
		FOR(i,n){
			int a = 0;
			FOR(j,n) a += v[i][j];
			ans = max(ans,a);
			a = 0;
			FOR(j,n) a += v[j][i];
			ans = max(ans,a);
		}

		int m = n-1;
		FOR(i,n){
			int a = 0,b = 0,c = 0,d = 0;
			FOR(j,i+1){
				a += v[i-j][j];
				c += v[m-(i-j)][j];
				b += v[m-(i-j)][m-j];
				d += v[i-j][m-j];
			}
			ans = max(ans,max(max(a,b),max(c,d)));
		}

		cout << ans << endl;
	}
	
	
	return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int n, a[255][255];
int check(int x, int y, int dx, int dy) {
	int ret = 0;
	while(0 <= x && x < n && 0 <= y && y < n) {
		if(a[y][x] == 0) return ret;
		x += dx, y += dy, ret++;
	}
	return ret;
}
int main() {
	while(~scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) scanf("%d", &a[i][j]);
		}
		int ret = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				for(int k = -1; k <= 1; k++) {
					for(int l = -1; l <= 1; l++) {
						if(k != 0 || l != 0) {
							ret = max(ret, check(j, i, l, k));
						}
					}
				}
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

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


class Cell{
public:
  int d, r, rd, ld;
  Cell(int d = 0, int r = 0, int rd = 0, int ld = 0)
    : d(d), r(r), rd(rd), ld(ld) {}
  int max() {
    if(d >= r && d >= rd && d >= ld) return d;
    if(r >= d && r >= rd && r >= ld) return r;
    if(rd >= d && rd >= r && rd >= ld) return rd;
    if(ld >= d && ld >= r && ld >= rd) return ld;
  }
};

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    string data[n+1];

    data[0] = "";
    for(int i = 0; i < n+2; i++) {
      data[0] += "0";
    }
    for(int i = 1; i < n+1; i++) {
      string str;
      cin >> str;
      data[i] = "0" + str + "0";
    }

    Cell c[n+1][n+1];
    for(int i = 1; i < n+1; i++) {
      for(int j = 1; j < n+1; j++) {
	if(data[i][j] == '1') {
	  c[i][j].d = c[i-1][j].d + 1;
	  c[i][j].r = c[i][j-1].r + 1;
	  c[i][j].rd = c[i-1][j-1].rd + 1;
	  c[i][j].ld = c[i-1][j+1].ld + 1;
	} else if(data[i][j] == '0') {
	  c[i][j].d = c[i][j].r = c[i][j].rd = c[i][j].ld = 0;
	}
      }
    }

    int max = -1;
    for(int i = 1; i < n+1; i++) {
      for(int j = 1; j < n+1; j++) {
	if(c[i][j].max() > max) max = c[i][j].max();
      }
    }
    cout << max << endl;
  }
  return 0;
}