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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999
#define eps 1e-9
int n;


int main(){
    while(cin>>n){
        if(n==0)break;
        string data[300];
        rep(i,n) cin>>data[i];

        int maxi=0;
        rep(i,n*2-1){
//            cout<<endl<<i<<endl;
            int sum=0;
            if(i<n){
                rep(j,i+1){
                    sum+=data[j][i-j]-'0';
                }
            }else{
                rep(j,(2*n-1)-i){
//                    cout<<i+j+1-n<<" "<<i-(i+j+1-n)<<endl;
                    sum+=data[i+j+1-n][i-(i+j+1-n)]-'0';
                }
            }
            maxi=max(maxi,sum);
        }
        rep(i,n*2-1){
            //            cout<<endl<<i<<endl;
            int sum=0;
            if(i<n){
                rep(j,i+1){
                    sum+=data[j][n-1-(i-j)]-'0';
                }
            }else{
                rep(j,(2*n-1)-i){
                    sum+=data[i+j+1-n][n-1-(i-(i+j+1-n))]-'0';
                }
            }
            maxi=max(maxi,sum);
        }
        int sum;
        rep(i,n){
            sum=0;
            rep(j,n){
                sum+=data[i][j]-'0';
            }
            maxi=max(sum,maxi);
        }
        
        rep(i,n){
            sum=0;
            rep(j,n){
                sum+=data[j][i]-'0';
            }
            maxi=max(maxi,sum);
        }
        cout<<maxi<<endl;
    }

}

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

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int g[255][255]={{}};
    for(int y=0;y<n;y++){
      for(int x=0;x<n;x++){
	char c;
	cin>>c;
	g[y][x]=c=='1';
      }
    }
    int ans=0;
    int ga[255][255];
    copy(g[0],g[255],ga[0]);
    for(int y=1;y<n;y++){
      for(int x=0;x<n;x++){
	if(ga[y][x]){
	  ga[y][x]+=ga[y-1][x];
	}
      }
    }
    ans=max(ans,*max_element(ga[0],ga[255]));
    copy(g[0],g[255],ga[0]);
    for(int x=1;x<n;x++){
      for(int y=0;y<n;y++){
	if(ga[y][x]){
	  ga[y][x]+=ga[y][x-1];
	}
      }
    }
    ans=max(ans,*max_element(ga[0],ga[255]));
    copy(g[0],g[255],ga[0]);
    for(int y=1;y<n;y++){
      for(int x=1;x<n;x++){
	if(ga[y][x]){
	  ga[y][x]+=ga[y-1][x-1];
	}
      }
    }
    ans=max(ans,*max_element(ga[0],ga[255]));
    copy(g[0],g[255],ga[0]);
    for(int y=1;y<n;y++){
      for(int x=n-2;x>=0;x--){
	if(ga[y][x]){
	  ga[y][x]+=ga[y-1][x+1];
	}
      }
    }
    ans=max(ans,*max_element(ga[0],ga[255]));
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

string s[300];
int dx[8] = {0,0,1,-1,-1,-1,1,1};
int dy[8] = {1,-1,0,0,-1,1,-1,1}; 

int dfs( int i , int j , int n ){

  int cnt = 0;
  for( int k = 0 ; k < 8 ; k++ ){
    int cnt2 = 0;
    int x = i;
    int y = j;
    while( 0 <= x && x < n && 0 <= y && y < n ){
      if( s[x][y] == '1' ){
	x += dx[k];
      y += dy[k];
      cnt2++;
      }
      else break;
    }
    cnt = max( cnt , cnt2 ); 
    //８方向動かして、カウント
  }
  return cnt;
}

int main(void){
  
  while(1){

    int n;
    cin >> n;
    if( n == 0 ) break;
    
    for( int i = 0 ; i < n ; i++ ){
      cin >> s[i];
    }
    
    int ans = 0;
    for( int i = 0 ; i < n ; i++ ){
      for( int j = 0 ; j < n ; j++ ){
	if( s[i][j] == '1' ){
	  ans = max( ans , dfs(i,j,n) );
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int board[255][255],dx[] = {-1,0,1,-1,1,-1,0,1},dy[] = {-1,-1,-1,0,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 < 8;++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 <cstring>
using namespace std;
int n;
char t[256][256];
int d[4][2] = {
	{-1, 0},
	{-1, -1},
	{0, -1},
	{1, -1},
};
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> t[i];
		}
		int result = 0;
		for (int i = 0; i < 4; i++) {
			int res[256][256];
			memset(res, 0, sizeof(res));
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					int preX = k + d[i][0];
					int preY = j + d[i][1];
					if ((preX < 0 || preY < 0 || preX >= n) && t[j][k] == '1') {
						res[j][k] = 1;
					}
					else {
						if (t[j][k] == '1') {
							res[j][k] = res[preY][preX] + 1;
						}
					}
					result = max(result, res[j][k]);
					//cout << ' ' << res[j][k];
				}
				//cout << endl;
			}
		}
		cout << result << endl;
	}
}

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-i+j-1][n-j-1] == '1' )
					cnt++;
			}
			answer = max( answer, cnt );
		}

		cout << answer << endl;

	}
	return 0;
}