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<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,ma;
	while(cin>>n,n){
		string s[260];
		rep(i,n)
		cin>>s[i];
		ma=0;
		rep(i,n){
			rep(j,n){
				if(s[i][j]=='1')
					for(int k=j;;k++){
						if(s[i][k]=='0'||k==n){
							ma=max(ma,k-j);
							j=k;
							
							break;
						}
					}
			}
			rep(j,n){
				if(s[j][i]=='1')
					for(int k=j;;k++){
						if(s[k][j]=='0'||k==n){
							ma=max(ma,k-j);
							j=k;
							break;
						}
					}
				
			}
			
			rep(j,n){
				if(s[i][j]=='1'){
					for(int k=0;;k++){
							if(s[i+k][j+k]=='0'||k+i==n||k+j==n){
								ma=max(ma,k);
								break;
							}
					}
					
					for(int k=0;;k++){
						if(i+k==n||j-k==-1||s[i+k][j-k]=='0'){
								ma=max(ma,k);
								break;
						}
					}
				}
			}
			
			
			
			
			
			
			
		}
		cout<<ma<<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<<endl;
	}
	return 0;
}

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

string field[256];

void rotate(int n){
	string tmp[256];
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			tmp[i][j] = field[n - j - 1][i];
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++) field[i][j] = tmp[i][j];
	}
}

int main(){
	int n;
	while(cin >> n,n){
		int ma = 0;
		for(int i = 0;i < n;i++) cin >> field[i];
		for(int i = 0;i < n;i++){
			int cnt = 0;
			for(int j = 0;j < n;j++){
				if(field[i][j] == '1') {
					cnt++;
					ma = max(ma,cnt);
				}else cnt = 0;
			}
			cnt = 0;
			for(int j = 0;j < n;j++){
				if(field[j][i] == '1') {
					cnt++;
					ma = max(ma,cnt);
				}else cnt = 0;
			}
		}
		for(int k = 0;k < 2;k++){
			if(k) rotate(n);
			for(int i = 0;i < 2 * n - 1;i++){
				int cnt = 0;
				for(int j = 0;j < n;j++){
					if(i - j >= n || i - j < 0) continue;
					if(field[j][i - j] == '1'){
							cnt++;
						ma = max(ma,cnt);
					}else cnt = 0;
				}
			}
		}
		cout << ma << endl;
	}
	return 0;
}

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

int main()
{
	int a;
	while (cin >> a, a) {
		bool b[258][258];
		for (int c = 0; c < a; c++) {
			string s; cin >> s;
			for (int d = 0; d < a; d++) {
				b[c][d] = s[d] == '1';
			}
		}
		int MAX = 0;
		for (int e = 0; e < a; e++) {
			for (int f = 0; f < a; f++) {
				for (int h = -1; h < 2; h++) {
					for (int i = -1; i < 2; i++) {
						if (h||i) {
							int g = 0;
							for (int j = 0; e + h*j >= 0 && e + h*j < a&&f + i*j >= 0 && f + i*j < a; j++) {
								if (b[e + h*j][f + i*j]) { g++; MAX = max(MAX, g); }
								else g = 0;
							}
						}
					}
				}
			}
		}
		cout << MAX << endl;
	}
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,n,max,cnt,x,y;
	int dx[4]={1,1,0,-1},dy[4]={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||xy[y][x]!='1') break;
							cnt++;
						}
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: /*
 * 0151.cpp
 *
 *  Created on: 2011/07/27
 *      Author: isa
 */

#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
	int n;
	while(cin >> n && n){
		bool f[n+2][n+2];
		string str;
		int ans=0,tmp;
		memset(f,false,sizeof(f));
		for(int i=0;i<n;i++){
			cin >> str;
			for(int j=0;j<n;j++){
				f[i+1][j+1] = str[j] - '0';
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(f[i+1][j+1] == true){
					int k=0;
					tmp = 0;
					while(f[i+1+k][j+1]) k++;
					tmp = max(tmp,k);
					k=0;
					while(f[i+1-k][j+1]) k++;
					tmp = max(tmp,k);
					k=0;
					while(f[i+1][j+1+k]) k++;
					tmp = max(tmp,k);
					k=0;
					while(f[i+1][j+1-k]) k++;
					tmp = max(tmp,k);
					k=0;
					while(f[i+1-k][j+1-k]) k++;
					tmp = max(tmp,k);
					k=0;
					while(f	[i+1-k][j+1+k]) k++;
					tmp = max(tmp,k);
					k=0;
					while(f[i+1+k][j+1-k]) k++;
					tmp = max(tmp,k);
					k=0;
					while(f[i+1+k][j+1+k]) k++;
					tmp = max(tmp,k);
					ans = max(ans,tmp);
				}
			}
		}
		cout << ans << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	
	int n;
	while (cin >> n, n) {
		bool grid[255][255];
		
		REP(i, n) {
			string str;
			cin >> str;
			REP(j, n) {
				grid[i][j] = !!(str[j] - '0');
			}
		}
		int ans = 0, cnt;
		
		REP(i, n) {
			cnt = 0;
			REP(j, n) {
				if (!grid[i][j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, n) {
				if (!grid[j][i]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, i + 1) {
				if (!grid[i - j][j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, i + 1) {
				if (!grid[i - j][n - 1 - j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, i + 1) {
				if (!grid[n - 1 - i + j][j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
			
			cnt = 0;
			REP(j, i + 1) {
				if (!grid[n - 1 - i + j][n - 1 - j]) {
					ans = max(ans, cnt);
					cnt = 0;
				}
				else cnt++;
			}
			ans = max(ans, cnt);
		}
		
		cout << ans << endl;
	}
	return 0;
}