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]
}

Python: # coding: utf-8
# Your code here!

while True:
    n = int(input())
    if n == 0:
        break
    
    table = [[0 for i in range(n)] for j in range(n)]
    for l in range(n):
        line = input()
        for m in range(n):
            table[l][m] = int(line[m])

    t = 0
    ans = 0
    for i in range(n):
        for j in range(n):
            if table[i][j] > 0:
                t += 1
            else:
                ans = max(t, ans)
                t = 0
        ans = max(t, ans)
        t = 0

    for i in range(n):
        for j in range(n):
            if table[j][i] > 0:
                t += 1
            else:
                ans = max(t, ans)
                t = 0
        ans = max(t, ans)
        t = 0

    for c in range(n):
        for j in range(c+1):
            if table[c-j][j] > 0:
                t += 1
            else:
                ans = max(t, ans)
                t = 0
        ans = max(t, ans)
        t = 0
        

    for c in range(n):
        for j in range(c+1):
            if table[n-1-(c-j)][n-1-j] > 0:
                t += 1
            else:
                ans = max(t, ans)
                t = 0
        ans = max(t, ans)
        t = 0


    for c in range(n):
        for j in range(c+1):
            if table[n-1-(c-j)][j] > 0:
                t += 1
            else:
                ans = max(t, ans)
                t = 0
        ans = max(t, ans)
        t = 0


    for c in range(n):
        for j in range(c+1):
            if table[c-j][n-1-j] > 0:
                t += 1
            else:
                ans = max(t, ans)
                t = 0
        ans = max(t, ans)
        t = 0

        
    print(ans)

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0151&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        data = [list(map(int, list(input().strip('\n')))) for _ in range(n)]

        if n == 1:              #  ????????????1?????????????????????
            print(data[0][0])
            continue

        # ???(North)??????(West)?????????(NorthWest)?????????(NorthEast) ????????????????????????1???????????£?¶???????????????????????????????
        N = [[0] * n for _ in range(n)]
        W = [[0] * n for _ in range(n)]
        NW = [[0] * n for _ in range(n)]
        NE = [[0] * n for _ in range(n)]
        N_max = 0               #  ???????????????????????§?????£?¶???????1????????§?????°
        W_max = 0
        NW_max = 0
        NE_max = 0

        for i in range(n):
            for j in range(n):
                c = data[i][j]  #  ????????????data[i][j]?????????????????§???????????§?????????????¨???¶

                # North??????
                ni = i - 1
                if ni < 0:
                    N[i][j] = c
                    if N[i][j] > N_max:
                        N_max = N[i][j]
                else:
                    if c == 1:
                        N[i][j] = N[ni][j] + 1
                        if N[i][j] > N_max:
                            N_max = N[i][j]
                    else:
                        N[i][j] = 0

                # West??????
                nj = j - 1
                if nj < 0:
                    W[i][j] = c
                    if W[i][j] > W_max:
                        W_max = W[i][j]
                else:
                    if c == 1:
                        W[i][j] = W[i][nj] + 1
                        if W[i][j] > W_max:
                            W_max = W[i][j]
                    else:
                        W[i][j] = 0

                # North West??????
                ni = i - 1
                nj = j - 1
                if ni < 0 or nj < 0:
                    NW[i][j] = c
                    if NW[i][j] > NW_max:
                        NW_max = NW[i][j]
                else:
                    if c == 1:
                        NW[i][j] = NW[ni][nj] + 1
                        if NW[i][j] > NW_max:
                            NW_max = NW[i][j]
                    else:
                        NW[i][j] = 0

                # North East??????
                ni = i - 1
                nj = j + 1
                if ni < 0 or nj >= n:
                    NE[i][j] = c
                    if NE[i][j] > NE_max:
                        NE_max = NE[i][j]
                else:
                    if c == 1:
                        NE[i][j] = NE[ni][nj] + 1
                        if NE[i][j] > NE_max:
                            NE_max = NE[i][j]
                    else:
                        NE[i][j] = 0

        print(max(N_max, W_max, NW_max, NE_max))



if __name__ == '__main__':
    main(sys.argv[1:])

Python: def scanning_area(grid, length, point_list, stride_x, stride_y):
    area = [[0 for _ in range(length + 1)] for __ in range(length + 1)]
    max_length = 0

    for row, col in point_list:
        if grid[row][col] == "1":
            area[row + stride_y][col + stride_x] = area[row][col] + 1
            max_length = max(max_length, area[row + stride_y][col + stride_x])

    return max_length


def create_point_list(length):
    points = []

    for count, r in enumerate(range(length - 1, 0, -1), 1):
        row = r
        for col in range(0, count, 1):
            points.append((row, col))
            row += 1

    for index in range(0, length):
        points.append((index, index))

    for lp in range(1, length):
        row = 0
        for col in range(lp, length):
            points.append((row, col))
            row += 1

    return points


while True:

    length = int(input())

    if length == 0:
        break

    grid = [input() for _ in range(length)]

    point_list = [[row, col] for row in range(length) for col in range(length)]

    line_length1 = scanning_area(grid, length, point_list, 1, 0)
    line_length2 = scanning_area(grid, length, point_list, 0, 1)

    point_list = create_point_list(length)
    line_length3 = scanning_area(grid, length, point_list, 1, 1)
    point_list.reverse()
    line_length4 = scanning_area(grid, length, point_list, -1, 1)

    max_length = max(line_length1, line_length2, line_length3, line_length4)
    print(max_length)