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<bits/stdc++.h>
using namespace std;
int dfs(int,int,int);
char table[255][256];
int dx[4]={0,1,1,-1},
	dy[4]={1,0,1,1};
int mx=-1,n,xx,yy;
int main(void)
{
	int i,j,k;

	cin>>n;
	while(n) {
		for(i=0;i<n;i++) cin>>table[i];
		mx=0;
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				if(table[i][j]=='1') {
					for(k=0;k<4;k++) {
						mx=max(mx,dfs(i,j,k)+1);
					}
				}
			}
		}
		cout<<mx<<endl;
		cin>>n;
	}
	return 0;
}
int dfs(int y,int x,int suu)
{
	int i,j,k;
	xx=x+dx[suu];
	yy=y+dy[suu];
	if(table[yy][xx]=='1'&&yy>=0&&yy<n&&xx>=0&&xx<n) {
		return (dfs(yy,xx,suu)+1);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
string str;
int cntw[255][255],cnth[255][255],cnta[255][255],cntb[255][255],n,t[255][255],ans;
int main(){
  while(cin>>n&&n){
    ans=0;
    for(int i=0;i<n;i++){
      cin>>str;
      for(int j=0;j<n;j++){
	t[i][j]=str[j]-'0';
	cntw[i][j]=cnth[i][j]=cnta[i][j]=cntb[i][j]=t[i][j];
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(t[i][j]==0)continue;
	if(i>0) cnth[i][j]+=cnth[i-1][j];
	if(j>0) cntw[i][j]+=cntw[i][j-1];
	if(i>0&&j>0) cnta[i][j]+=cnta[i-1][j-1];
	if(i>0&&j<n-1) cntb[i][j]+=cntb[i-1][j+1];
	ans=max(ans,cnth[i][j]);
	ans=max(ans,cntw[i][j]);ans=max(ans,cnta[i][j]);
	ans=max(ans,cntb[i][j]);
      }
    }cout<<ans<<endl;
  }
}

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

int main() {
	int n;
	while(cin >> n, n) {
		vector<string> in;
		for(int i = 0; i < n; i++) {
			string s;
			cin >> s;
			in.push_back(s);
		}

		int longest = 0;
		for(int i = 0; i < n; i++) {
			int a = 0, b = 0;
			for(int j = 0; j < n; j++) {
				if(in[i][j] == '1') {
					a++;
					longest = max(a, longest);
				}
				else
					a = 0;
				if(in[j][i] == '1') {
					b++;
					longest = max(b, longest);
				}
				else
					b = 0;
			}
		}
		for(int i = -1 * n + 1; i < n; i++) {
			int a = 0, b = 0;
			for(int j = 0; j < n; j++) {
				if(i + j >= 0 && i + j < n && in[i + j][j] == '1') {
					a++;
					longest = max(a, longest);
				}
				else
					a = 0;
				if(i + j >= 0 && i + j < n && in[i + j][n - j - 1] == '1') {
					b++;
					longest = max(b, longest);
				}
				else
					b = 0;
			}
		}
		cout << longest << endl;
	}
}

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() {
	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 <cstring>
using namespace std;
int n;
char t[256][256];
int d[4][2] = {
	{-1, 0},
	{-1. -1},
	{0, -1},
	{1, -1},
};
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> t[i];
		}
		int result = 0;
		for (int i = 0; i < 4; i++) {
			int res[256][256];
			memset(res, 0, sizeof(res));
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					int preX = k + d[i][0];
					int preY = j + d[i][1];
					if ((preX < 0 || preY < 0 || preX >= n) && t[j][k] == '1') {
						res[j][k] = 1;
					}
					else {
						if (t[j][k] == '1') {
							res[j][k] = res[preY][preX] + 1;
						}
					}
					result = max(result, res[j][k]);
					//cout << ' ' << res[j][k];
				}
				//cout << endl;
			}
		}
		cout << result << endl;
	}
}

C++: #include<iostream>

using namespace std;

const int MAX = 260;

char data[MAX][MAX];
int num[4][MAX][MAX];
int in;

int solve(){
  for(int i = 1; i <= in; i++){
    for(int j = 1; j <= in; j++){
      if(data[i][j] == '1'){
	num[0][i][j] = num[0][i-1][j]+1;
	num[1][i][j] = num[1][i][j-1]+1;
	num[2][i][j] = num[2][i-1][j-1]+1;
	num[3][i][j] = num[3][i-1][j+1]+1;
      }
    }
  }
  int m = 0;
  for(int i = 0; i < 4; i++)
    for(int j = 1; j <= in; j++)
      for(int k = 1; k <= in; k++) m = max(m,num[i][j][k]);
  return m;
}

int main(){

  while(cin >> in && in){
    for(int i = 1; i <= in; i++){
      for(int j = 1; j <= in; j++){
	cin >> data[i][j];
	if(data[i][j] == '1') num[0][i][j] = num[1][i][j] = num[2][i][j] = num[3][i][j] = 1;
	else num[0][i][j] = num[1][i][j] = num[2][i][j] = num[3][i][j] = 0;
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int a[][255],int sx,int sy,int vx,int vy,int n){
  int i,j;
  int mx=0;
  for(i=0;i<n;i=j){
    for(;i<n&&a[sx+vx*i][sy+vy*i]==0;i++);
    for(j=i;j<n&&a[sx+vx*j][sy+vy*j];j++);
    if(mx<j-i)
      mx=j-i;
  }

  return mx;
}
int main(){
  int i,j;
  int a[255][255],n;
  int mx;
  char c;
  while(cin>>n&&n){
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	cin>>c;
	a[j][i]=c-'0';
      }
    }
    mx=0;
    for(i=0;i<n;i++){
      mx=max(mx,f(a,0,i,1,0,n));
      mx=max(mx,f(a,i,0,0,1,n));
      mx=max(mx,f(a,0,i,1,1,n-i));
      mx=max(mx,f(a,i,0,1,1,n-i));
      mx=max(mx,f(a,n-i-1,0,-1,1,n-i));
      mx=max(mx,f(a,n-1,i,-1,1,n-i));
    }
    cout<<mx<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
int main(){
	int n;
	while(scanf("%d",&n),n){
		int m=0,v[4][2] = {{0,-1},{-1,0},{1,-1},{-1,-1}},map[257][257] = {{0}};
		for(int y=1;y<=n;y++)
			for(int x=1;x<=n;x++)scanf("%1d",&map[x][y]);

		for(int i=0;i<4;i--){
			int dp[257][257] = {{0}};
			for(int k=1;k<=n;k++)
				for(int j=1;j<=n;j++)m = std::max(m,dp[j][k] = map[j][k]?map[j][k] + dp[j+v[i][0]][k+v[i][1]]:0);
		}
		printf("%d\n",m);
	}
}