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>
#include<numeric>
#include<iterator>
#include<vector>

using namespace std;
typedef unsigned int val;

int tate(char mass[256][256],int n)
{
	int count=0,a=0,b=0,ans=-1;
	
	while(1)
	{

		if(b==n)break;
		
		if(mass[a][b]=='0' || a==n)
		{ 
			
			if(ans<count) ans=count;

			a=0;b++;count=0;continue; 

		}
		
		a++;count++;

	}
	return ans;
}

int yoko(char mass[256][256],int n)
{
	int count=0,a=0,b=0,ans=-1;
	
	while(1)
	{

		if(a==n)break;
		
		if(mass[a][b]=='0' || b==n)
		{ 
			
			if(ans<count) ans=count;

			b=0;a++;count=0;continue; 

		}
		
		b++;count++;

	}
	return ans;
}


int main() 
{
	int n;
	while(cin>>n && n)
	{
		char mass[260][260];
		
		for(int i=0; i<n; i++) cin >> mass[i];

		int ans=-1;

		if( ans < tate( mass, n ) ) ans = tate( mass, n );
		if( ans < yoko( mass, n ) ) ans = yoko( mass, n );
		
		for(int i=0; i<n ;i++)
		{
			for(int j=0; j<n; j++)
			{
				
				if(mass[i][j]=='1')
				{
					int a=i,b=j,count=0;
					while(1)
					{
						if( mass[a][b] == '0' || b<0 || n<a) break;
						mass[a][b]='0';
						count++;
						a++;b--;
						if(b==n){ a++;b=n-1; }
					}
					if(ans<count) ans=count;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int i,j,k,n,max,cnt,x,y;
	int dx[4]={1,1,0,-1},dy[4]={0,-1,-1,-1};
	char xy[225][225];
	while(1){
		max=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) cin>>xy[i];
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(xy[i][j]=='1'){
					for(k=0;k<4;k++){
						cnt=1;
						y=i; x=j;
						while(1){
							y=y+dy[k]; x=x+dx[k];
							if(y>=n||x>=n||y<0||x<0||xy[y][x]!='1') break;
							cnt++;
						}
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
	int n;
	while(scanf("%d",&n),n){
		int m=0,v[4][2] = {{0,-1},{-1,0},{1,-1},{-1,-1}},dp[257][257];
		int map[257][257] = {{0}};
		for(int y=1;y<=n;y++){
			for(int x=1;x<=n;x++){
				scanf("%1d",&map[x][y]);
			}
		}

		for(int i=0;i<4;i++){
			memset(dp,0,sizeof(dp));
			//cout << "--------------------" << endl;//Test
			for(int k=1;k<=n;k++){
				for(int j=1;j<=n;j++){
					dp[j][k] = map[j][k]?map[j][k] + dp[j+v[i][0]][k+v[i][1]]:0;
					//cout << dp[j][k];//Test
					m = max(m,dp[j][k]);
				}
				//cout << endl;//Test
			}
		}
		printf("%d\n",m);
	}
}

C++: #include <iostream>

int getH(char** board, int n)
{
	int res = 0;
	for (int i=0; i<n; i++) {
		int count = 0;
		for (int j=0; j<n; j++) {
			if (board[i][j] == '0') count = 0;
			else {
				count++;
				if (count > res) res = count;
			}
		}
	}
	return res;
}

int getV(char** board, int n)
{
	int res = 0;
	for (int j=0; j<n; j++) {
		int count = 0;
		for (int i=0; i<n; i++) {
			if (board[i][j] == '0') count = 0;
			else {
				count++;
				if (count > res) res = count;
			}
		}
	}
	return res;
}

int getLD(char** board, int n)
{
	int res = 0;
	for (int i=0; i<n; i++) {
		int count = 0;
		for (int j=0; j<=i; j++) {
			if (board[j][i-j] == '0') count = 0;
			else {
				count++;
				if (count > res) res = count;
			}
		}
	}
	for (int i=0; i<n-1; i++) {
		int count = 0;
		for (int j=0; j<=i; j++) {
			if (board[n-1-i+j][n-1-j] == '0') count = 0;
			else {
				count++;
				if (count > res) res = count;
			}
		}
	}
	return res;
}

int getRD(char** board, int n)
{
	int res = 0;
	for (int i=0; i<n; i++) {
		int count = 0;
		for (int j=0; j<=i; j++) {
			if (board[j][n-1-i+j] == '0') count = 0;
			else {
				count++;
				if (count > res) res = count;
			}
		}
	}
	for (int i=0; i<n-1; i++) {
		int count = 0;
		for (int j=0; j<=i; j++) {
			if (board[n-1-i+j][j] == '0') count = 0;
			else {
				count++;
				if (count > res) res = count;
			}
		}
	}
	return res;
}

int main()
{
	int n;
	while (true) {
		std::cin >> n;
		if (n==0) break;
		char** board = new char*[n];
		for (int i=0; i<n; i++) board[i] = new char[n];
		for (int i=0; i<n; i++) {
			for (int j=0; j<n; j++) std::cin >> board[i][j];
		}
		int res = std::max( std::max(getH(board,n), getV(board,n)), std::max(getLD(board,n), getRD(board,n)) );
		std::cout << res << std::endl;
		for (int i=0; i<n; i++) delete[] board[i];
		delete[] board;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  
  while(cin >> N && N) {
    vector<string> grid(N);
    for(int i=0; i<N; i++) {
      cin >> grid[i];
    }
    
    int ans = 0;
    
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
	for(int k=1; k<=N; k++) {
	  if(j+k > N) continue;
	  bool ok = 1;
	  for(int l=0; l<k; l++) {
	    if(grid[i][j+l] != '1') ok = 0;
	  }
	  if(ok) {
	    ans = max(ans, k);
	  }
	}
      }
    }
    
    for(int j=0; j<N; j++) {
      for(int i=0; i<N; i++) {
	for(int k=1; k<=N; k++) {
	  if(i+k > N) continue;
	  bool ok = 1;
	  for(int l=0; l<k; l++) {
	    if(grid[i+l][j] != '1') ok = 0;
	  }
	  if(ok) {
	    ans = max(ans, k);
	  }
	}
      }
    }

    // right down
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
	for(int k=1; k<=N; k++) {
	  
	  if(i+k > N || j+k > N) continue;
	  
	  bool ok = 1;
	  for(int l=0; l<k; l++) {
	    if(grid[i+l][j+l] != '1') ok = 0;
	  }
	  if(ok) {
	    ans = max(ans, k);
	  }
	}
      }
    }
    
    // right up
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
	for(int k=1; k<=N; k++) {
	  if(i-k+1<0 || j+k>N) continue;
	  
	  bool ok = 1;
	  for(int l=0; l<k; l++) {
	    if(grid[i-l][j+l] != '1') ok = 0;
	  }
	  if(ok) {
	    ans = max(ans, k);
	  }
	}
      }
    }
    
    cout << ans << endl;
  }
  
  return 0;
}