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 <stdio.h>
#include <algorithm>
using namespace std;
int n, a[255][255];
int check(int x, int y, int dx, int dy) {
	int ret = 0;
	while(0 <= x && x < n && 0 <= y && y < n) {
		if(a[y][x] == 0) return ret;
		x += dx, y += dy, ret++;
	}
	return ret;
}
int main() {
	while(~scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) scanf("%d", &a[i][j]);
		}
		int ret = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				for(int k = -1; k <= 1; k++) {
					for(int l = -1; l <= 1; l++) {
						if(k != 0 || l != 0) {
							ret = max(ret, checK(j, i, l, k));
						}
					}
				}
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include <bits/stdc++.h>

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

int main()
{
    int N;

    while (cin >> N, N)
    {
        int dp[300][300][4];

        rep(i, N) rep(j, N) rep(k, 4) dp[i][j][k] = 0;

        vector<string> grid(N);

        rep(i, N) cin >> grid[i];

        int ans = 0;

        rep(i, N)
        {
            rep(j, N)
            {
                if (grid[i][j] != '1')
                    continue;

                dp[i][j][0] = (j != 0) * dp[i][j - 1][0] + 1;
                dp[i][j][1] = (i != 0) * dp[i - 1][j][1] + 1;
                dp[i][j][2] = (i != 0 && j != 0) * dp[i - 1][j - 1][2] + 1;
                dp[i][j][3] = (i != 0 && j != N) * dp[i - 1][j + 1][3] + 1;

                rep(k, 4) ans = max(ans, dp[i][j][k]);
            }
        }

        cout << ans << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
bool map[256][256],cop[256][256];
int main() {
	int n;
	char z;
	while(true){
	cin>>n;
	if(n==0)break;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>z;
			if(z=='0')map[i][j]=false;
			else map[i][j]=true;
		}
	}
	int dx[4]={0,1,1,-1},dy[4]={1,0,1,1};
	int ans=0;
	for(int set=0;set<4;set++){
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)cop[i][j]=map[i][j];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(cop[i][j]){
					int cnt=0,x=j,y=i;
					while(true){
						if(!(x>=0&&x<n&&y>=0&&y<n))break;
						if(!map[y][x])break;
						cop[y][x]=false;
						x+=dx[set],y+=dy[set];
						cnt++;
					}
					ans=max(cnt,ans);
				}
			}
		}
	}
	cout<<ans<<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] += 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 <algorithm>
#include <cstring>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int m=0,v[4][2] = {{0,-1},{-1,0},{1,-1},{-1,-1}},dp[257][257];
		char map[257][257];
		for(int y=0;y<257;y++){
			for(int x=0;x<257;x++){
				map[x][y] = '0';
			}
		}
		for(int y=1;y<=n;y++){
			for(int x=1;x<=n;x++){
				cin >> map[x][y];
			}
		}

		for(int i=0;i<4;i++){
			memset(dp,0,sizeof(dp));
			//cout << "--------------------" << endl;//Test
			for(int k=1;k<=n;k++){
				for(int j=1;j<=n;j++){
					dp[j][k] = map[j][k]-'0'?map[j][k] - '0' + dp[j+v[i][0]][k+v[i][1]]:0;
					//cout << dp[j][k];//Test
					m = max(m,dp[j][k]);
				}
				//cout << endl;//Test
			}
		}
		cout << m << endl;
	}
}

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

int d[300][300];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n)rep(j, n)scanf("%1d", &d[i][j]);
		int Max = 0;
		rep(i, n)rep(j, n) {
			int cnt = 0;
			for (int x = i, y = j; 0 <= x&&x < n && 0 <= y&&y < n; x++) {
				if (!d[x][y])break;
				cnt++;
			}
			Max = max(Max, cnt);
			cnt = 0;
			for (int x = i, y = j; 0 <= x&&x < n && 0 <= y&&y < n; y++) {
				if (!d[x][y])break;
				cnt++;
			}
			Max = max(Max, cnt);
			cnt = 0;
			for (int x = i, y = j; 0 <= x&&x < n && 0 <= y&&y < n; x++, y++) {
				if (!d[x][y])break;
				cnt++;
			}
			Max = max(Max, cnt);
			cnt = 0;
			for (int x = i, y = j; 0 <= x&&x < n && 0 <= y&&y < n; x++, y--) {
				if (!d[x][y])break;
				cnt++;
			}
			Max = max(Max, cnt);
		}
		printf("%d\n", Max);
	}
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,n,max,cnt,x,y,
		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>
using namespace std;

int main(){
  int n;
  int field[255][255];
  int d;
  string tmp;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++){
      cin >> tmp;
      for(int j=0;j<n;j++)field[i][j] = tmp[j]-'0';
    }

    int ans = 0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(field[i][j]){
	  d = 1;
	  while(i+d<n &&  j-d>=0 && field[i+d][j-d])d++;
	  if(ans<d)ans = d;

	  d = 1;
	  while(i+d<n && field[i+d][j])d++;
	  if(ans<d)ans = d;

	  d = 1;
	  while(i+d<n && j+d<n && field[i+d][j+d])d++;
	  if(ans<d)ans = d;

	  d = 1;
	  while(j+d<n && field[i][j+d])d++;
	  if(ans<d)ans = d;
	}
      }
    }

    cout << ans << endl;
  }
}