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 -*-
"""
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)]

        # ???(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 main():
  while True:
    n = int(input())
    if n == 0:
      break
    
    mp = ["0" + input() + "0" for _ in range(n)]
    mp.insert(0, "0" * (n + 2))
    mp.append("0" * (n + 2))
    
    score = [[[0] * 4 for _ in range(n + 2)] for _ in range(n + 2)]
    max_score = 0
    for i in range(1, n + 1):
      for j in range(1, n + 1):
        if mp[i][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])
    
    print(max_score)

main()

Python: # Aizu Problem 00151: Grid
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def grid_length(n, grid):
    L = 0
    for row in grid:
        L = max(L, max([len(_) for _ in row.split('0')]))
    for c in range(n):
        col = ''.join([grid[r][c] for r in range(n)])
        L = max(L, max([len(_) for _ in col.split('0')]))
    for row in range(-n, 2 * n):
        diag = ''.join([grid[row+c][c] for c in range(n) if 0 <= row + c < n])
        L = max(L, max([len(_) for _ in diag.split('0')]))
        diag = ''.join([grid[row-c][c] for c in range(n) if 0 <= row - c < n])
        L = max(L, max([len(_) for _ in diag.split('0')]))
    return L

while True:
    n = int(input())
    if n == 0:
        break
    grid = [input().strip() for _ in range(n)]
    print(grid_length(n, grid))

Python: def main():
  while True:
    n = int(input())
    if n == 0:
      break
    mp = ["0" + input() + "0" for _ in range(n)]
    mp.insert(0, "0" * (n + 2))
    mp.append("0" * (n + 2))
    score = [[[0] * 4 for _ in range(n + 2)] for _ in range(n + 2)]
    max_score = 0
    for i in range(1, n + 1):
      for j in range(1, n + 1):
        if mp[i][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])
        else:
          for k in range(4):
            score[i][j][k] = 0
    print(max_score)

main()