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<string>
#include<vector>
#include<set>
using namespace std;
typedef vector<int> vi;
string board[265];

int main()
{
  int n;
  while(cin >> n && n)
    {
      int ans=-1;
      int wchain=0;
      int hchain=0;
      int schain=0;
      for(int i=0;i<n;i++)
	{
	  cin >> board[i];
	}
      for(int i=0;i<n;i++)
	{
	  wchain=0;
	  for(int j=0;j<n;j++)
	    {
	      if(board[i][j]=='1')
		{
		  wchain++;
		}
	      else
		{
		  ans=max(ans,wchain);
		  wchain=0;
		}
	    }
	  ans=max(ans,wchain);
	}
      for(int i=0;i<n;i++)
	{
	  hchain=0;
	  for(int j=0;j<n;j++)
	    {
	      if(board[j][i]=='1')
		{
		  hchain++;
		}
	      else
		{
		  ans=max(ans,hchain);
		  hchain=0;
		}
	    }
	   ans=max(ans,wchain);
	}
      for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=i,w=0;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h-1)>=0 && (w+1)<n)
	    {
	      h--;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	   ans=max(ans,schain);
	}
      for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=n-1,w=i;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h-1)>=0 && (w+1)<n)
	    {
	      h--;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	  ans=max(ans,schain);
	}


       for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=i,w=0;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h+1)<n && (w+1)<n)
	    {
	      h++;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	  ans=max(ans,schain);
	}
      for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=0,w=i;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h+1)<n && (w+1)<n)
	    {
	      h++;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	  ans=max(ans,schain);
	}
      cout << ans << endl;
    }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<numeric>
#include<iterator>
#include<vector>

using namespace std;
typedef unsigned int val;

int tate(char mass[260][260],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[260][260],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<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,ma;
	while(cin>>n,n){
		string s[101];
		rep(i,n)
		cin>>s[i];
		ma=0;
		rep(i,n){
			rep(j,n){
				if(s[i][j]=='1')
					for(int k=j;;k++){
						if(s[i][k]=='0'||k==n){
							ma=max(ma,k-j);
							j=k;
							
							break;
						}
					}
			}
			rep(j,n){
				if(s[j][i]=='1')
					for(int k=j;;k++){
						if(s[k][j]=='0'||k==n){
							ma=max(ma,k-j);
							j=k;
							break;
						}
					}
				
			}
			
			rep(j,n){
				if(s[i][j]=='1'){
					for(int k=0;;k++){
							if(s[i+k][j+k]=='0'||k+i==n||k+j==n){
								ma=max(ma,k);
								break;
							}
					}
					
					for(int k=0;;k++){
						if(i+k==n||j-k==-1||s[i+k][j-k]=='0'){
								ma=max(ma,k);
								break;
						}
					}
				}
			}
			
			
			
			
			
			
			
		}
		cout<<ma<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    char ma[255][255];
    int n;
    while(cin>>n,n){
        int pillar[255]={},ans=0;
        for(int i=0;i<n;i++){
                int lo=0;
            for(int j=0;j<n;j++){
                cin>>ma[i][j];
                if(ma[i][j]=='1'){
                        pillar[j]++;
                        lo++;
                }
                else{
                    ans=max(pillar[j],ans);
                    ans=max(ans,lo);
                    lo=0;
                    pillar[j]=0;
                }

            }
            ans=max(ans,lo);
        }
        for(int i=1;i<n;i++){
                int kawa[4]={};
                ans=max(ans,pillar[i]);
                for(int j=0;j<=i;j++){
                    if(ma[j][i-j]=='1')kawa[0]++;
                    else{
                        ans=max(ans,kawa[0]);
                        kawa[0]=0;
                    }
                    if(ma[n-1-i+j][n-1-j]=='1')kawa[1]++;
                    else{;
                        ans=max(ans,kawa[1]);
                        kawa[1]=0;
                    }
                    if(ma[j][n-1-i+j]=='1')kawa[2]++;
                    else{
                        ans=max(ans,kawa[2]);
                        kawa[2]=0;
                    }
                    if(ma[n-1-i+j][j]=='1')kawa[3]++;
                    else {
                            ans=max(ans,kawa[3]);
                            kawa[3]=0;
                    }
                }
                ans=max(ans,kawa[0]);
                ans=max(ans,kawa[1]);
                ans=max(ans,kawa[2]);
                ans=max(ans,kawa[3]);
        }
        cout<<ans<<endl;
    }
}