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<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++: #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 j = 0;j < 2;j++){
			if(j) 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 <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define al(s) s.begin(),s.end()

typedef pair<int, int> pi;
typedef pair<pi, pi> ppi;
typedef pair<int, ppi> pipp;


int main()
{
	int n;
	while (cin >> n&&n)
	{
		int ans = 0;
		vector<string> v;
		rei(n)
		{
			string s;
			cin >> s;
			v.push_back(s);
		}

		rei(n)
		{
			int j = 0;
			rel(n)
			{
				if (v[i][l] == '1')
				{
					j++;
				}
				else
				{
					j = 0;
				}
				ans = max(ans, j);
			}
		}
		rei(n)
		{
			int j = 0;
			rel(n)
			{
				if (v[l][i] == '1')
				{
					j++;
				}
				else
				{
					j = 0;
				}
				ans = max(ans, j);
				
			}
		}

		for (int i = 0; i < n; i++)
		{
			int j = 0;
			for (int l = 0; l < n - i; l++)
			{
				if (v[l][i + l] == '1')
				{
					j++;
				}
				else
				{
					j = 0;
				}
				ans = max(j, ans);
			}
			j = 0;
			for (int l = 0; l <= i; l++)
			{
				if (v[i - l][l] == '1')
				{
					j++;
				}
				else
				{
					j = 0;
				}
				ans = max(ans, j);
			}
		}
			
			
			
		cout << ans << endl;




	}
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-6;

int mat[255][255];

int diagLLUR(int n,int** mat){
	int res = 0;
	for(int y=0;y<n;y++){
		int isok = 1;
		for(int x=0,dy=y;x<n,dy>=0;x++,dy--){
			if(mat[dy][x] == 0) isok = 0;
		}
		res = max((y+1)*isok,res);
	}

	for(int x=0;x<n;x++){
		int isok = 1;
		for(int dx=x,y=n-1;dx<n,y>=0;dx++,y--){
			if(mat[y][dx] == 0) isok = 0;
		}
		res = max((n-x)*isok,res);
	}

	return res;
}

int diagULLR(int n,int** mat){
	int res = 0;
	for(int x=n-1;x>=0;x--){
		int isok = 1;
		for(int dx=x,y=0;dx<n,y<n;dx++,y++){
			if(mat[y][dx] == 0) isok = 0;
		}
		res = max((n-x)*isok,res);
	}

	for(int y=0;y<n;y++){
		int isok = 1;
		for(int x=0,dy=y;x<n,dy<n;x++,dy++){
			if(mat[dy][x] == 0) isok = 0;
		}
		res = max((n-y)*isok,res);
	}

	return res;
}

int vert(int n,int** mat){
	int res = 0;
	for(int x=0;x<n;x++){
		int isok = 1;
		for(int y=0;y<n;y++){
			if(mat[y][x] == 0) isok = 0;
		}

		res = max(n*isok,res);
	}

	return res;
}

int hori(int n,int** mat){
	int res = 0;
	for(int y=0;y<n;y++){
		int isok = 1;
		for(int x=0;x<n;x++){
			if(mat[y][x] == 0) isok = 0;
		}

		res = max(n*isok,res);
	}

	return res;
}

int main(){

	int n;	

	while(~scanf("%d",&n)){
		if(n==0) break;

		int** mat = new int*[n];
		for(int i=0;i<n;i++) mat[i] = new int[n]();

		for(int y=0;y<n;y++){
			char buf[512];
			scanf("%s",buf);
			for(int x=0;x<n;x++){
				mat[y][x] = buf[x]-'0';
			}
		}

		printf("%d\n",max(max(diagLLUR(n,mat),hori(n,mat)),max(diagULLR(n,mat),vert(n,mat))));

		for(int i=0;i<n;i++) delete[] mat[i];
		delete[] mat;
	}
}

C++: #include <iostream>
using namespace std;
 
int n;
char grid[255][255];
int dx[] = {1,0,1,-1};
int dy[] = {0,1,1,1};
 
int solv(int sx, int sy) {
    int res = 0;
    for (int i=0; i<4; ++i) {
        int cnt = 0, x = sx, y = sy;
        while (0 <= x && x < n && 0 <= y && y < n) {
            cnt = (grid[y][x] == '1' ? cnt+1 : 0);
            res = max(res, cnt);
            x += dx[i];
            y += dy[i];
        }
    }
    return res;
}
 
int main() {
    ios::sync_with_stdio(false);
    while (cin >> n, n) {
        char c;
        for (int i=0; i<n*n; ++i) {
            cin >> grid[i/n][i%n];
        }
        int res = 0;
        for (int i=0; i<n; ++i) {
            res = max(max(res, solv(0, i)), max(solv(n-1, i), solv(i, 0)));
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{ 
	int n;
	while( cin >> n && n )
	{
		vector < string > map(n);
		for ( int i = 0; i < n; i++ )
			cin >> map[i];

		int answer = 0;
		int cnt;
		for ( int i = 0; i < n; i++ )
		{
			cnt = 0;
			for ( int j = 0; j < n; j++ )
			{
				if ( map[j][i] == '1' )
					cnt++;
			}
			answer = max( answer, cnt );

			cnt = 0;
			for ( int j = 0; j < n; j++ )
			{
				if ( map[i][j] == '1' )
					cnt++;
			}
			answer = max( answer, cnt );
		}

		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < n; j++ )
			{
				cnt = 0;
				while ( i+cnt < n && j+cnt < n )
				{
					if ( map[i+cnt][j+cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );

				cnt = 0;
				while ( i-cnt >= 0 && j+cnt < n )
				{
					if ( map[i-cnt][j+cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );
			}
		}

		cout << answer << endl;

	}
	return 0;
}