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;
const int MAX_N = 300;

int n,cnt;
int in[MAX_N][MAX_N];
int s[MAX_N][MAX_N];

void dfs(int y,int x,bool bit){
    if(bit){
        if(n <= x || n <= y) return;
        s[y][x] = 0;
        cnt++;
    
        int nx = x + 1;
        int ny = y + 1;
        
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1){
            dfs(ny,nx,bit);
        }
    }
    else{
        if(x < 0 || n <= y) return;
        s[y][x] = 0;
        cnt++;
        
        int nx = x - 1;
        int ny = y + 1;
        
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1){
            dfs(ny,nx,bit);
        }
    }
}

void cp_str(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            s[i][j] = in[i][j];
        }
    }
}

int main(){
    char ch;
    while(cin >> n ,n){
        int a = 0,b = 0,c = 0,d = 0;
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cin >> ch;
                in[i][j] = ch - '0';
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            cnt = 0;
            for(int j = 0 ; j < n ; j++){
                if(in[i][j] == 1){
                    cnt++;
                    a = max(a,cnt);
                }
                else cnt = 0;
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            cnt = 0;
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[j][i] == 1){
                    cnt++;
                    b = max(b,cnt);
                }
                else cnt = 0;
            }
        }

        cp_str();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) dfs(i,j,1);
                c = max(c,cnt);
            }
        }
        
        cp_str();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) dfs(i,j,0);
                d = max(d,cnt);
            }
        }
        
        cout << max(max(a,b),max(b,d)) << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int board[255][255],dx[] = {1,-1,0,1},dy[] = {0,1,1,1};
int main(){
	int n,tx,ty,cnt,max;
	string str;
	while(cin >> n,n){
		max = 0;
		for(int i = 0;i < n;++i){
			cin >> str;
			for(int j = 0;j < str.size();++j){
				board[i][j] = (int)(str[j] - '0');
			}
		}
		for(int i = 0;i < n;++i){
			for(int j = 0;j < n;++j){
				if(board[i][j] == 1){
					for(int k = 0;k < 4;++k){
						cnt = 1;
						tx = j + dx[k];
						ty = i + dy[k];
						while(0 <= tx && 0 <= ty && tx < n && ty < n && board[ty][tx] == 1){
							++cnt;
							tx += dx[k];
							ty += dy[k];
						}
						if(cnt > max) max = cnt;
					}
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}

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

int grid[255][255];

int main() {
    int n;
    while (cin >> n, n) {
        char c;
        for (int i=0; i<n; ++i) {
            for (int j=0; j<n; ++j) {
                cin >> c;
                grid[i][j] = c - '0';
            }
        }
        int x, y, cnt, res = 0;
        for (int i=0; i<n; ++i) {
            // right
            cnt = 0, y = i, x = 0;
            while (x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ x;
            }
            // right down
            cnt = 0, y = i, x = 0;
            while (y < n && x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, ++ x;
            }
            // left down
            cnt = 0, y = 0, x = i;
            while (y < n && 0 <= x) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, -- x;
            }
            // down
            cnt = 0, y = 0, x = i;
            while (y < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y;
            }
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{ 
	int n;
	while( cin >> n && n )
	{
		vector < string > map(n);
		for ( int i = 0; i < n; i++ )
			cin >> map[i];

		int answer = 0;
		int cnt;
		for ( int i = 0; i < n; i++ )
		{
			cnt = 0;
			for ( int j = 0; j < n; j++ )
			{
				if ( map[j][i] == '1' )
					cnt++;
			}
			answer = max( answer, cnt );

			cnt = 0;
			for ( int j = 0; j < n; j++ )
			{
				if ( map[i][j] == '1' )
					cnt++;
			}
			answer = max( answer, cnt );
		}

		for ( int i = 0; i < n; i++ )
		{
			cnt = 0;
			for ( int j = 0; j <= i; j++ )
			{
				if ( map[i-j][j] == '1' )
					cnt++;
			}
			answer = max( answer, cnt );
		}

		// ツ右ツ可コツ板シツ閉ェ
		for ( int i = 0; i < n; i++ )
		{
			cnt = 0;
			for ( int j = 0; j <= i; j++ )
			{
				if ( map[n-j-1][n-i+j-1] == '1' )
					cnt++;
			}
			answer = max( answer, cnt );
		}

		cout << answer << endl;

	}
	return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int a[][255],int sx,int sy,int vx,int vy,int n){
  int i,j;
  int mx=0;
  for(i=0;i<n;i=j){
    for(;i<n&&a[sx+vx*i][sy+vy*i]==0;i++);
    for(j=i;j<n&&a[sx+vx*j][sy+vy*j];j++);
    if(mx<j-i)
      mx=j-i;
  }

  return mx;
}
int main(){
  int i,j;
  int a[255][255],n;
  int mx;
  char c;
  while(cin>>n&&n){
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	cin>>c;
	a[j][i]=c-'0';
      }
    }
    mx=0;
    for(i=0;i<n;i++){
      mx=max(mx,f(a,0,i,1,0,n));
      mx=max(mx,f(a,i,0,0,1,n));
      mx=max(mx,f(a,0,i,1,1,5-i));
      mx=max(mx,f(a,i,0,1,1,5-i));
      mx=max(mx,f(a,4-i,0,-1,1,5-i));
      mx=max(mx,f(a,4,i,-1,1,5-i));
    }
    cout<<mx<<endl;
  }
  return 0;
}