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: while 1:
    n = int(input())
    if n == 0:
        break
    L = [input() for i in range(n)]
    ans = 0
    for i in range(n):
        cnt = 0
        for j in range(n):
            if L[i][j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
        cnt = 0
        for j in range(n):
            if L[j][i] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
    for i in range(n):
        cnt = 0
        for j in range(n-i):
            if L[i+j][j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
        cnt = 0
        for j in range(n-i):
            if L[j][i+j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
        cnt = 0
        for j in range(i+1):
            if L[i-j][j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
        cnt = 0
        for j in range(n-i):
            if L[i+j][n-1-j] == '1':
                cnt += 1
            else:
                if ans < cnt:
                    ans = cnt
                cnt = 0
        if ans < cnt:
            ans = cnt
    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()))) 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
                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
                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
                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
                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:])

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

const int SIZE = 255;

int main()
{
	bool table[ SIZE ][ SIZE ];

	int n;
	while( cin >> n && n ){
		memset( table, 0, sizeof(table) );
		for( int i = 0; i < n; ++i ){
			for( int j = 0; j < n; ++j ){
				char c;
				cin >> c;
				table[ i ][ j ] = c == '1' ? true : false;
			}
		}
		int maxLength = 0;
		for( int i = 0; i < n; ++i ){
			int col = 0, row = 0;
			for( int j = 0; j < n; ++j ){
				if( table[ i ][ j ] ){
					++col;
					if( maxLength < col ) maxLength = col;
				}else{
					col = 0;
				}
				if( table[ j ][ i ] ){
					++row;
					if( maxLength < row ) maxLength = row;
				}else{
					row = 0;
				}
			}
		}
		for( int i = 0; i < n; ++i ){
			int diaL = 0, diaR = 0;
			for( int j = 0; j <= i; ++j ){
				if( table[ i - j ][ j ] ){
					++diaL;
					if( maxLength < diaL ) maxLength = diaL;
				}else{
					diaL = 0;
				}
				if( table[ j ][ n - 1 - j ] ){
					++diaR;
					if( maxLength < diaR ) maxLength = diaR;
				}else{
					diaR = 0;
				}
			}
		}
		cout << maxLength << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,j) for(int i=0;i<j;i++)
using namespace std;
int n;
int dx[]={1,1,-1,0},dy[]={0,1,1,1};
vector<string>V;
int cnt(int y,int x,int d){
    if(x<0||x>=n||y<0||y>=n)return 0;
    if(V[y][x]=='0')return 0;
    return cnt(y+dy[d],x+dx[d],d)+1;
}
int main(){

    while(cin>>n,n){
        V.clear();
        string str;
        int mx=-1;
        rep(i,n){
            cin>>str;
            V.push_back(str);
        }
        rep(i,n)
            rep(j,n)
                rep(k,4)mx=max(mx,cnt(i,j,k));

        cout<<mx<<endl;


    }
}