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 <algorithm>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int m[4]={0},v[4][2] = {{0,-1},{-1,0},{1,-1},{-1,-1}},dp[257][257]={{0,0}};
		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=0;y<n;y++){
			for(int x=0;x<n;x++){
				cin >> map[x+1][y+1];
			}
		}
		for(int i=0;i<4;i++){
			for(int k=1;k<=n;k++){
				for(int j=1;j<=n;j++){
					dp[j][k] = map[j][k] - '0' + dp[j+v[i][0]][k+v[i][1]];
					m[i] = max(m[i],dp[j][k]);
				}
			}
		}
		cout << max(m[0],max(m[1],max(m[2],m[3]))) << endl;
	}
}

C++: #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string a[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++) cin >> a[i];
		int ret = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				for(int k = 0; k <= 3; k++) {
					ret = max(ret, check(j, i, k / 3 - 1, k % 3 - 1));
				}
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int dx[]={1,1,1,0},dy[]={-1,0,1,1};
string s[255];
main()
{
	int N;
	while(cin>>N,N)
	{
		for(int i=0;i<N;i++)cin>>s[i];
		int ans=0;
		for(int i=0;i<N;i++)for(int j=0;j<N;j++)
		{
			if(s[i][j]=='0')continue;
			for(int r=0;r<4;r++)
			{
				int now=0;
				for(int k=0;k<N;k++)
				{
					int x=i+dx[r]*k,y=j+dy[r]*k;
					if(x<0||y<0||x>=N||y>=N||s[x][y]=='0')break;
					now++;
				}
				ans=max(ans,now);
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <queue>
#define MAX_N 255
using namespace std;

int p[8] = {1, 0, -1, 0, 1, 1, -1, -1}, q[8] = {0, 1, 0, -1, 1, -1, 1, -1};
string grid[MAX_N];

int search(int n) {
  int maxi = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < 8; k++) {
	int count = 0;
	int x = i, y = j;
	for ( ; ; ) {
	  if (x < 0 || y < 0 || x >= n || y >= n || grid[x][y] == '0') break;
	  count++;
	  x += p[k];
	  y += q[k];
	}
	maxi = max(maxi, count);
      }
    }
  }
  return maxi;
}

void init() {
  for (int i = 0; i < MAX_N; i++) {
    grid[i] = "\0";
  }
}

int main() {
  while (true) {
    init();
    int n;
    cin >> n;
    if (n == 0) return 0;
    for (int i = 0; i < n; i++) {
      cin >> grid[i];
    }

    int ans = search(n);
    cout << ans << endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int maxl(vector<int> seq){
  FOR(i,1,seq.size()) seq[i] += (seq[i])?seq[i-1]:0;
  int ret = 0;
  REP(i,seq.size()) ret = max(ret,seq[i]);
  return ret;
}
int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<string> grid(n);
    int ans = 0;
    REP(i,n) cin>>grid[i];
    REP(i,n){
      vector<int> seq;
      REP(j,n)seq.push_back(grid[i][j]-'0');
      ans = max(ans,maxl(seq));
    }
    REP(i,n){
      vector<int> seq;
      REP(j,n)seq.push_back(grid[j][i]-'0');
      ans = max(ans,maxl(seq));
    }
    REP(i,n){
      int x=i,y=0;
      vector<int> seq,seq2,seq3,seq4;
      REP(j,i+1)seq.push_back(grid[x--][y++]-'0'); 
      ans = max(ans,maxl(seq));
      x = n-1; y = n-1-i;
      REP(j,i+1)seq2.push_back(grid[x--][y++]-'0');
      ans = max(ans,maxl(seq2));
      x = n-1-i; y=0;
      REP(j,i+1)seq3.push_back(grid[x++][y++]-'0');
      ans = max(ans,maxl(seq3));
      x = i; y=n-1;
      REP(j,i+1)seq4.push_back(grid[x--][y--]-'0');
      ans = max(ans,maxl(seq4));
    }
    cout<<ans<<endl;
  }

  return 0;
}

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

const int MAX_N = 255;
int n;
char grid[MAX_N][MAX_N];
int dp[MAX_N][MAX_N][4];

int main()
{
    while(cin >> n && n) {
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                cin >> grid[i][j];
        
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++) 
                for(int k = 0; k < 4; k++) 
                    dp[i][j][k] = 0;

        int ans = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(grid[i][j] == '0') {
                    for(int k = 0; k < 4; k++)
                        dp[i][j][k] = 0;
                } else {
                    dp[i][j][0] = (i > 0 && j > 0) ? dp[i-1][j-1][0] + 1 : 1;
                    dp[i][j][1] = (i > 0) ? dp[i-1][j][1] + 1 : 1;
                    dp[i][j][2] = (i > 0 && (j != n - 1)) ? dp[i-1][j+1][2] + 1 : 1;
                    dp[i][j][3] = (j > 0) ? dp[i][j-1][3] + 1 : 1;
                }
                for(int k = 0; k < 4; k++)
                    ans = max(ans, dp[i][j][k]);
            }
        }

        cout << ans << endl;
    }
}