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 <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, 1, -1};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, board[300][300];
 
int solve(int row, int col) {
    int res = 0;
    for(int k=0; k<6; k++) {
        int x = row, y = col, cons = 0;
        while(x >= 0 and x < N and y >= 0 and y < N) {
            if(board[x][y] > 0) cons++;
            else chmax(res, cons), cons = 0;
            x += dx[k], y += dy[k];
        }
        chmax(res, cons);
    }
    return res;
}

signed main() {
    while(cin >> N, N) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                char c; cin >> c;
                board[i][j] = c - '0';
            }
        }

        int ans = 0;
        for(int i=0; i<N; i++) {
            chmax(ans, solve(i, 0));
            chmax(ans, solve(0, i));
        }
        cout << ans << endl;
    }
    return 0;
}

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

int dx[]={0,1,-1,1};
int dy[]={1,0, 1,1}; //ツ可コツ右ツ偲篠づ淞債カツ偲篠づ淞右

int main()
{
	int N;
	while(scanf("%d", &N), N)
	{
		int f[256][256],ans=0;
		for(int i=0; i<N; i++)
		{
			getchar();
			for(int j=0; j<N; j++)
			{
				char t;
				scanf("%c", &t);
				f[j][i]=t-'0';
			}
		}
			
			
		for(int i=0; i<N; i++)
		for(int j=0; j<N; j++)
		{
			if(!f[j][i]) continue;
			
			for(int k=0; k<4; k++)
			{
				int cnt=1;
				int tx=j, ty=i;
				while(1)
				{
					tx+=dx[k], ty+=dy[k];
					if(tx<0||ty<0||tx>=N||ty>=N) break;
					if(!f[tx][ty]) break;
					
					cnt++;
				}
				
				ans=(cnt>ans?cnt:ans);
			}
		}
		
		printf("%d\n", ans);
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

int n;
char grid[255][255];
int dp_lu[255][255];	//lu:left up
int dp_u[255][255];		//u:up
int dp_ru[255][255];	//ru:right up
int dp_l[255][255];		//l:left

signed main()
{
	while (true)
	{
		cin >> n;
		if (n == 0) break;
		rep(i,n) cin >> grid[i];

		int ans = 0;

		rep(i,n) rep(j,n)
		{
			if (i == 0)
			{
				if (grid[i][j] == '1')
				{
					dp_lu[i][j] = 1;
					dp_u[i][j] = 1;
					dp_ru[i][j] = 1;
					if (j == 0)
					{
						dp_l[i][j] = 1;
					} else {
						dp_l[i][j] = dp_l[i][j - 1] + 1;
					}
				} else {
					dp_lu[i][j] = 0;
					dp_u[i][j] = 0;
					dp_ru[i][j] = 0;
					dp_l[i][j] = 0;
				}
			} else if (j == 0) {
				if (grid[i][j] == '1')
				{
					dp_lu[i][j] = 1;
					dp_u[i][j] = dp_u[i - 1][j] + 1;
					dp_ru[i][j] = dp_ru[i - 1][j + 1] + 1;
					dp_l[i][j] = 1;
				} else {
					dp_lu[i][j] = 0;
					dp_u[i][j] = 0;
					dp_ru[i][j] = 0;
					dp_l[i][j] = 0;
				}
			} else if (j == n - 1) {
				if (grid[i][j] == '1')
				{
					dp_lu[i][j] = dp_lu[i - 1][j - 1] + 1;
					dp_u[i][j] = dp_u[i - 1][j] + 1;
					dp_ru[i][j] = 1;
					dp_l[i][j] = dp_l[i][j - 1] + 1;
				} else {
					dp_lu[i][j] = 0;
					dp_u[i][j] = 0;
					dp_ru[i][j] = 0;
					dp_l[i][j] = 0;
				}
			} else {
				if (grid[i][j] == '1')
				{
					dp_lu[i][j] = dp_lu[i - 1][j - 1] + 1;
					dp_u[i][j] = dp_u[i - 1][j] + 1;
					dp_ru[i][j] = dp_ru[i - 1][j + 1] + 1;
					dp_l[i][j] = dp_l[i][j - 1] + 1;
				} else {
					dp_lu[i][j] = 0;
					dp_u[i][j] = 0;
					dp_ru[i][j] = 0;
					dp_l[i][j] = 0;
				}
			}
			ans = max(ans, dp_lu[i][j]);
			ans = max(ans, dp_u[i][j]);
			ans = max(ans, dp_ru[i][j]);
			ans = max(ans, dp_l[i][j]);
		}

		printf("%d\n", ans);
	}
}

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); }

int count(string v)
{
	int res = 0;
	int sub = 0;
	
	rep(i, v.size())
	{
		if(v[i] == '0' || i + 1 == v.size())
		{
			chmax(res, sub + (v[i] == '1'));
			sub = 0;
		}
		else
		{
			sub++;
		}
	}
	
	return res;
}

int line(vector<string> v, int len)
{
	int n = v.size();
	int x = len - 1, y = 0;
	int res = 0;
	
	// ツ右ツ湘」ツつゥツづァツ湘」ツ板シツ閉ェ
	string s;
	rep(i, len)
	{
		s.push_back(v[y][x]);
		x--;
		y++;
	}
	
	chmax(res, count(s));
	s.clear();
	
	// ツ右ツ湘」ツつゥツづァツ可コツ板シツ閉ェ
	x = n - 1;
	y = n - len;
	rep(i, len)
	{
		s.push_back(v[y][x]);
		x--;
		y++;
	}
	
	chmax(res, count(s));
	s.clear();
	
	// ツ債カツ湘」ツつゥツづァツ湘」ツ板シツ閉ェ
	x = n - len;
	y = 0;
	rep(i, len)
	{
		s.push_back(v[y][x]);
		x++;
		y++;
	}
	
	chmax(res, count(s));
	s.clear();
	
	// ツ債カツ湘」ツつゥツづァツ可コツ板シツ閉ェ
	x = 0;
	y = n - len;
	rep(i, len)
	{
		s.push_back(v[y][x]);
		x++;
		y++;
	}
	
	chmax(res, count(s));
	
	return res;	
}
int main()
{
    int n;
	while(cin >> n && n)
	{
		int res = 0;
		vector<string> v(n);
		rep(i, n) cin >> v[i];
		
		
		rep(i, n)
		{
			chmax(res, count(v[i]));
			
			string s;
			rep(j, n) s.push_back(v[j][i]);
			
			chmax(res, count(s));
		}
		
		for(int i = n; 0 < i; i--)
			chmax(res, line(v, i));
		
		cout << res << endl;
	}
}