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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int dy[] = {1, 1, 0, 1};
    int dx[] = {0, 1, 1, -1};

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<string> s(n+2);
        s[0] = s[n+1] = string(n+2, '0');
        for(int i=1; i<=n; ++i){
            cin >> s[i];
            s[i] = '0' + s[i] + '0';
        }

        int ret = 0;
        for(int i=1; i<=n; ++i){
            for(int j=1; j<=n; ++j){
                for(int k=0; k<4; ++k){
                    int y = i;
                    int x = j;
                    if(s[y-dy[k]][x-dx[k]] == '1')
                        continue;
                    int num = 0;
                    while(s[y][x] == '1'){
                        ++ num;
                        y += dy[k];
                        x += dx[k];
                    }
                    ret = max(ret, num);
                }
            }
        }

        cout << ret << endl;
    }
}

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

char map[255][255];

int dire4[][2] = {
    {1, 0}, {-1, 1}, {0, 1}, {1, 1}, 
    {-1, -1}, {0, -1}, {1, -1}, {-1, 0}
};

int main(){
    int n;
    while(1){
        cin >> n;
        if(n == 0) break;

        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                cin >> map[y][x];
            }
        }

        int ans = 0;
        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                for(int z = 0;z < 8;z++) {
                    int dx = dire4[z][0], dy = dire4[z][1];
                    int cx = x, cy = y;
                    int c = 0;
                    for(;map[cy][cx] == '1' && 0 <= cx && cx < n && 0 <= cy && cy < n;) {
                        cx += dx;
                        cy += dy;
                        c++;
                    }
                    ans = max(ans, c);
                }
            }
        }
        cout << ans << endl;

    }
}

C++: #include <iostream>
#include <string>
#include <cstring>
using namespace std;
#define REP(i, n)           REPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < ((k)+(n)); ++i)
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 

int m[256][256];

void solve(int n){
    int t1[256], t2[256];
    int mx = 0;

    memset(t1,0,sizeof(t1));
    memset(t2,0,sizeof(t2));
    REP(y,n) REP(x,n){
        if(m[y][x]){
            mx = MAX(mx, ++t1[x]);
            mx = MAX(mx, ++t2[y]);
        } else {
            t1[x] = 0;
            t2[y] = 0;
        }
    }
    memset(t1,0,sizeof(t1));
    memset(t2,0,sizeof(t2));
    REP(y,n) REP(x,n){
        if(x == 0)   t1[(x-y+n)%n] = 0;
        if(x == n-1) t2[(x+y+n)%n] = 0;
        if(m[y][x]){
            mx = MAX(mx, ++t1[(x-y+n)%n]);
            mx = MAX(mx, ++t2[(x+y+n)%n]);
        } else {
            t1[(x-y+n)%n] = 0;
            t2[(x+y+n)%n] = 0;
        }
    }

    cout << mx << endl;
}

int main(){
    int n;
    while(cin >> n && n){
        for(int y = 0; y < n; y++){
            string s; cin >> s;
            for(int x = 0; x < n; x++) m[y][x] = s[x] - '0';
        }
        solve(n);
    }
    return 0;
}

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

int n;

// arr[y][x]
int arr[260][260];

/*
0: ツ湘」
1: ツ債カ
2: ツ債カツ湘」
3: ツ右ツ湘」
*/
int dp[4][260][260];


int main() {
	for(;;) {
		scanf(" %d", &n);
		if(!n) break;
		for(int y = 0; y < n; y++) {
			char line[260];
			scanf(" %s", line);
			for(int x = 0; x < n; x++) {
				arr[y][x] = line[x] - '0';
			}
		}
		memset(dp, 0, sizeof dp);
		for(int y = 0; y < n; y++) {
			for(int x = 0; x < n; x++) {
				if(arr[y][x] == 1) {
					for(int i = 0; i < 4; i++) {
						dp[i][y][x] = 1;
					}
					if(y >= 1) {
						dp[0][y][x] += dp[0][y - 1][x];
					}
					if(x >= 1) {
						dp[1][y][x] += dp[1][y][x - 1];
					}
					if(x >= 1 && y >= 1) {
						dp[2][y][x] += dp[2][y - 1][x - 1];
					}
					if(y >= 1 && x < n - 1) {
						dp[3][y][x] += dp[3][y - 1][x + 1];
					}
				}
			}
		}
		int maxv = 0;
		for(int y = 0; y < n; y++) {
			for(int x = 0; x < n; x++) {
				for(int k = 0; k < 4; k++) {
					maxv = max(maxv, dp[k][y][x]);
				}
			}
		}
		printf("%d\n", maxv);
	}
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
 
 int mem[256][256][4],i,j,k,n,an; 
 int main() {
  char da[256][256];
  while(cin >> n) {
  if (n==0) break;
  for (i=0;i<n;i++) cin >> da[i];
  for (i=0;i<n;i++) for (j=0;j<n;j++) for (k=0;k<4;k++) mem[i][j][k]=0;
  an=0;
  for (i=0;i<n;i++) for (j=0;j<n;j++) {
	  if (da[i][j]=='0') continue;
	  for (k=0;k<4;k++) {
		  mem[i][j][k]++;
		  if (k==0 && j>0) mem[i][j][k]+=mem[i][j-1][k];
		  if (k==1 && j>0 && i>0) mem[i][j][k]+=mem[i-1][j-1][k];
		  if (k==2 && i>0) mem[i][j][k]+=mem[i-1][j][k];
		  if (k==3 && i>0 && j<n-2) mem[i][j][k]+=mem[i-1][j+1][k];
		  if (an<mem[i][j][k]) an=mem[i][j][k];
	  }
  }
  cout << an << endl;
  }
 return 0;
 }

C++: #include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 260;
int n;
string grid[MAX_N];
int max_len;
int memo[MAX_N][MAX_N][4];

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

int rec(int y, int x, int d)
{
    if (memo[y][x][d] >= 0)
        return memo[y][x][d];

    int nx = x + dx[d];
    int ny = y + dy[d];

    if (nx < 0 || nx >= n || ny < 0 || ny >= n)
        return 1;
    if (grid[ny][nx] == '0')
        return 1;

    return memo[y][x][d] = (rec(ny, nx, d) + 1);
}

int main()
{
    while (cin >> n, n) {
        max_len = 0;
        for (int i = 0; i < n; i++) {
            cin >> grid[i];
            for (int j = 0; j < n; j++)
                for (int k = 0; k < 4; k++)
                    memo[i][j][k] = -1;
        }

        for (int y = 0; y < n; y++) 
            for (int x = 0; x < n; x++) 
                if (grid[y][x] == '1') {
                    for (int k = 0; k < 4; k++) {
                        int nx = max_len * dx[k] + x;
                        int ny = max_len * dy[k] + y;
                        if (nx < 0 || nx >= n || ny < 0 || ny >= n)
                            continue;
                        if (grid[ny][nx] != '1')
                            continue;
                        max_len = max(max_len, rec(y, x, k));
                    }
                }

        cout << max_len << endl;
    }

    return 0;
}