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<algorithm>
#include<cstring>
using namespace std;

void _memset();
void _cin();
void check1();
int _check();

#define MAX_N 8000

int n;
char x[MAX_N][MAX_N];
string tate[MAX_N], yoko[MAX_N], naname1[MAX_N * 10], naname2[MAX_N * 10];

void _memset() {
	memset(x, '0', sizeof(x));
	for (int i = 0; i < MAX_N; i++) {
		tate[i] = "";
	}
	for (int i = 0; i < MAX_N; i++) {
		yoko[i] = "";
	}
	for (int i = 0; i < MAX_N * 10; i++) {
		naname1[i] = "";
	}
	for (int i = 0; i < MAX_N * 10; i++) {
		naname2[i] = "";
	}
}

void _cin(int p) {
	for (int i = 0; i < p; i++) {
		for (int j = 0; j < p; j++) {
			cin >> x[i][j];
		}
	}
}

void check1(int p) {
	for (int i = 0; i < p; i++) {
		for (int j = 0; j < p; j++) {
			tate[i] += x[i][j];
			yoko[j] += x[i][j];
			naname1[i + j] += x[i][j];
			naname2[p + i - j] += x[i][j];
		}
	}
}

int maxn;

int _check(int p) {
	maxn = 0;

	//tate.
	int chain = 0;
	for (int i = 0; i < p; i++) {
		chain = 0;
		for (int j = 0; j < tate[i].size(); j++) {
			if (tate[i][j] == '1') {
				chain++;
			}
			else {
				maxn = max(chain, maxn);
				chain = 0;
			}
		}

		maxn = max(chain, maxn);

	}

	//yoko.
	for (int i = 0; i < p; i++) {
		chain = 0;
		for (int j = 0; j < yoko[i].size(); j++) {
			if (yoko[i][j] == '1') {
				chain++;
			}
			else {
				maxn = max(chain, maxn);
				chain = 0;
			}
		}

		maxn = max(chain, maxn);

	}

	//naname1.
	for (int i = 0; i < p * 10; i++) {
		chain = 0;
		for (int j = 0; j < naname1[i].size(); j++) {
			if (naname1[i][j] == '1') {
				chain++;
			}
			else {
				maxn = max(chain, maxn);
				chain = 0;
			}
		}
		
		maxn = max(maxn, chain);

	}

	//naname2.
	for (int i = 0; i < p * 10; i++) {
		chain = 0;
		for (int j = 0; j < naname2[i].size(); j++) {
			if (naname2[i][j] == '1') {
				chain++;
			}
			else {
				maxn = max(chain, maxn);
				chain = 0;
			}
		}

		maxn = max(chain, maxn);

	}

	_memset();

	return maxn;
}

int main() {
	while (true) {
		cin >> n;
		if (n == 0) {
			break;
		}
		_cin(n);
		check1(n);
		cout << _check(n) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 300;

int n,cnt;
int in[MAX_N][MAX_N];
int s[MAX_N][MAX_N];

void cp_in(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            s[i][j] = in[i][j];
        }
    }
}

void dfs(int y,int x,bool bit){
    if(bit){
        if(n <= x || n <= y) return;
        cnt++;
        int nx = x + 1;
        int ny = y + 1;
    
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1){
            dfs(ny,nx,bit);
        }
    }
    else{
        if(x < 0 || n <= y) return;
        cnt++;
        int nx = x - 1;
        int ny = y + 1;
        
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1){
            dfs(ny,nx,bit);
        }
    }
}

int main(){
    char ch;
    while(cin >> n ,n){
        int a = 0,b = 0,c = 0,d = 0;
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cin >> ch;
                in[i][j] = ch - '0';
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            cnt = 0;
            for(int j = 0 ; j < n ; j++){
                if(in[i][j] == 1){
                    cnt++;
                    a = max(a,cnt);
                }
                else cnt = 0;
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            cnt = 0;
            for(int j = 0 ; j < n ; j++){
                if(in[j][i] == 1){
                    cnt++;
                    b = max(b,cnt);
                }
                else cnt = 0;
            }
        }

        cp_in();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) dfs(i,j,1);
                c = max(c,cnt);
            }
        }
        
        cp_in();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) dfs(i,j,0);
                d = max(d,cnt);
            }
        }
        
        cout << max(max(a,b),max(c,d)) << endl;
    }
    
    return 0;
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


bool line(vector<string> v, int len)
{
	int n = v.size();
	
	
	rep(i, len)
	{
		int x = len - 1 + (n - 1) * i;
		if(v[x / n][x % n] == '0') break;
		else if(i + 1 == len) return true;
	}
	
	rep(i, len)
	{
		int x = (n - 1) * (n - len + 1) + (n - 1) * i + 1;
		if(v[x / n][x % n] == '0') break;
		else if(i + 1 == len) return true;
	}
	
	rep(i, len)
	{
		int x = n - len + (n + 1) * i;
		if(v[x / n][x % n] == '0') break;
		else if(i + 1 == len) return true;
	}
	
	rep(i, len)
	{
		int x = n * (n - len) + (n + 1) * i;
		if(v[x / n][x % n] == '0') break;
		else if(i + 1 == len) return true;
	}
	
	return false;
}
int main()
{
    int n;
	while(cin >> n)
	{
		vector<string> v(n);
		rep(i, n) cin >> v[i];
		
		rep(i, n)
		{
			if(count(ALL(v[i]), '0') == 0)
			{
				cout << n << endl;
				goto ng;
			}
			
			rep(j, n)
			{
				if(v[j][i] == '0') break;
				else if(j + 1 == n)
				{
					cout << n << endl;
					goto ng;
				}
			}
		}
		
		for(int i = n; 0 < i; i--) if(line(v, i)) 
		{
			cout << i << endl;
			goto ng;
		}
		
		cout  << 0 << endl;
			
		ng:;
	}
}