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 <cstring>
#include <string>
#include <algorithm>

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

using namespace std;

int main()
{
	int n;
	string s[256];
	while(cin >> n && n)
	{
		rep(i,n)
		{
			cin >> s[i];
		}

		int len = 0;
		int ans = 0;

		rep(i,n)
		{
			bool flag = false;
			len = 0;
			rep(j,n)
			{
				if(s[i][j] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;	
				}
				else 
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}

		rep(i,n)
		{
			len = 0;
			bool flag = false;
			rep(j,n)
			{
				if(s[j][i] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;	
				}
				else 
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}

		rep(i,n)
		{
			bool flag =false;
			len = 0;
			rep(k,i+1)
			{
				if(s[k][i-k] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}

		for(int i=n-1;i>=0;i--)
		{
			bool flag = false;
			len = 0;
			for(int j=i;j<n;j++)
			{
				if(s[j][(n-1)-(j-1)] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}
		
		rep(i,n)
		{
			bool flag = false;
			len = 0;
			int cnt = 0;
			REP(j,i,n)
			{
				if(s[cnt][j] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
				cnt++;
			}
			ans = max(ans,len);
		}

		for(int i=n-1;i>=0;i--)
		{
			bool flag = false;
			len = 0;
			int cnt = 0;
			for(int j=i;j<n;j++)
			{
				if(s[j][cnt] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
				cnt++;
			}
			ans = max(ans,len);
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

const int MAX_N = 260;
int n;
string grid[MAX_N];

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

int rec(int y, int x, int 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 rec(ny, nx, d) + 1;
}

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

        int max_len = 0;
        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++) 
                        max_len = max(max_len, rec(y, x, k));
                }

        cout << max_len << endl;
    }

    return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,n,max,cnt,x,y;
	int dx[]={1,1,0,-1},dy[]={0,1,1,1};
	char xy[225][226];
	while(1){
		max=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) cin>>xy[i];
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(xy[i][j]=='1'){
					for(k=0;k<4;k++){
						cnt=1;
						y=i; x=j;
						while(1){
							y=y+dy[k]; x=x+dx[k];
							if(y>=n||x>=n||y<0||x<0) break;
							if(xy[y][x]!='1')break;
							cnt++;
						}
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max\n;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		vector<string> s;
		for(int i=0;i<n;++i){
			string str;
			cin>>str;
			s.push_back(str);
		}
		int max=0;
		for(int i=0;i<n;++i){//yoko
			int count=0;
			char before = s[i][0];
			if(s[i][0]=='1') ++count;
			for(int j=1;j<n;++j){
				if(s[i][j]=='1'){
					if(before=='1') ++count;
					else count = 1;
				}else count = 0;
				before=s[i][j];
			}
			if(max<count)max=count;
		}
		for(int i=0;i<n;++i){//tate
			int count=0;
			char before = s[0][i];
			if(s[0][i]=='1') ++count;
			for(int j=1;j<n;++j){
				if(s[i][j]=='1'){
					if(before=='1') ++count;
					else count = 1;
				}else count = 0;
				before=s[j][i];
			}
			if(max<count)max=count;
		}
		for(int i=0;i<n*2-1;++i){//migisita
			int count=0;
			bool flag=false;
			char before;
			for(int j=0;j<n;++j){
				if(i+j-n>=n) break;
				if(i+j-n<0) continue;
				if(flag==false){
					flag=true;
					before = s[j][i+j-n];
					if(s[j][i+j-n]=='1') ++count;
				}else{
					if(s[j][i+j-n]=='1'){
						if(before=='1') ++count;
						else count = 1;
					}else count = 0;
					before=s[j][i+j-n];
				}
			}
			if(max<count)max=count;
		}
		for(int i=0;i<n*2-1;++i){//hidarisita
			int count=0;
			bool flag=false;
			char before;
			for(int j=0;j<n;++j){
				if(i-j<0) break;
				if(i-j>=n) continue;
				if(flag==false){
					flag=true;
					before = s[j][i-j];
					if(s[j][i-j]=='1') ++count;
				}else{
					if(s[j][i-j]=='1'){
						if(before=='1') ++count;
						else count = 1;
					}else count = 0;
					before=s[j][i-j];
				}
			}
			if(max<count)max=count;
		}
		cout<<max<<endl;
	}
	return 0;
}