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>
using namespace std;

char A[300][300];

int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				cin >> A[i][j];
		int ans = 0;
		for(int i = 0 ; i < n ; i++){
			int p = 0;
			for(int j = 0 ; j < n ; j++){
				p += A[i][j] - '0';
			}
			if( p == n ) ans = max(p,ans);
		}
		for(int i = 0 ; i < n ; i++){
			int p = 0;
			for(int j = 0 ; j < n ; j++){
				p += A[j][i] - '0';
			}
			if( p == n ) ans = max(p,ans);
		}
		for(int i = 0 ; i < n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j < n ; j++){
				if( i+j >= n ) break;
				p += A[j][i+j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		for(int i = 0 ; i < n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j < n ; j++){
				if( i+j >= n ) break;
				p += A[i+j][j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		for(int i = 0 ; i < n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j < n ; j++){
				if( n-1-i-j < 0 ) break;
				p += A[j][n-1-i-j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		
		for(int i = 0 ; i < n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j < n ; j++){
				if( n-1-i-j < 0 ) break;
				p += A[n-1-i-j][j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define al(s) s.begin(),s.end()

typedef pair<int, int> pi;
typedef pair<pi, pi> ppi;
typedef pair<int, ppi> pipp;


int main()
{
	int n;
	while (cin >> n&&n)
	{
		int ans = 0;
		vector<string> v;
		rei(n)
		{
			string s;
			cin >> s;
			v.push_back(s);
		}

		rei(n)
		{
			int j = 0;
			rel(n)
			{
				if (v[i][l] == '1')
				{
					j++;
				}
				else
				{
					ans = max(ans, j);
					j = 0;
				}
			}
			ans = max(ans, j);
		}
		rei(n)
		{
			int j = 0;
			rel(n)
			{
				if (v[l][i] == '1')
				{
					j++;
				}
				else
				{
					ans = max(ans, j);
					j = 0;
				}
				
			}
			ans = max(ans, j);
		}

		for (int i = 0; i < n; i++)
		{
			int j = 0;
			for (int l = 0; l < n - i; l++)
			{
				if (v[l][i + l] == '1')
				{
					j++;
				}
				else
				{
					ans = max(j, ans);
					j = 0;
				}
			}
			ans = max(ans, j);
			j = 0;
			for (int l = 0; l <= i; l++)
			{
				if (v[i - l][l] == '1')
				{
					j++;
				}
				else
				{
					ans = max(ans, j);
					j = 0;
				}
			}
			ans = max(ans, j);
		}
			
			
			
		cout << ans << endl;




	}
}

C++: #include<iostream>

using namespace std;

const int MAX = 256;

char data[MAX][MAX];
int num[4][MAX][MAX];
int in;

int solve(){
  for(int i = 1; i <= in; i++){
    for(int j = 1; j <= in; j++){
      if(data[i][j] == '1'){
	num[0][i][j] = num[0][i-1][j]+1;
	num[1][i][j] = num[1][i][j-1]+1;
	num[2][i][j] = num[2][i-1][j-1]+1;
	num[3][i][j] = num[3][i-1][j+1]+1;
      }
    }
  }
  int m = 0;
  for(int i = 1; i <= in; i++){
    for(int j = 1; j <= in; j++){
      m = max(max(max(m,num[0][i][j]),max(num[1][i][j], num[2][i][j])),num[3][i][j]);
    }
  }
  return m;
}

int main(){

  while(cin >> in && in){
    for(int i = 1; i <= in; i++){
      for(int j = 1; j <= in; j++){
	cin >> data[i][j];
	if(data[i][j] == '1') num[0][i][j] = num[1][i][j] = num[2][i][j] = num[3][i][j] = 1;
	else num[0][i][j] = num[1][i][j] = num[2][i][j] = num[3][i][j] = 0;
      }
    }
    cout << solve() << 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++ )
		{
			for ( int j = 0; j < n; j++ )
			{
				cnt = 0;
				while ( i+cnt < n && j+cnt < n )
				{
					if ( map[i+cnt][j+cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );

				cnt = 0;
				while ( i+cnt < n && j-cnt >= 0 )
				{
					if ( map[i+cnt][j-cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );
			}
		}

		cout << answer << endl;

	}
	return 0;
}

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

char A[1000][1000];

int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < 1000 ; i++)
			for(int j = 0 ; j < 1000 ; j++)
				A[i][j] = '0';
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				cin >> A[i+300][j+300];
		int ans = 0;
		for(int i = 0 ; i < 1000 ; i++){
			int p = 0;
			for(int j = 0 ; j < 1000 ; j++){
				p += A[i][j] - '0';
			}
			ans = max(ans,p);
		}
		for(int i = 0 ; i < 1000 ; i++){
			int p = 0;
			for(int j = 0 ; j < 1000 ; j++){
				p += A[j][i] - '0';
			}
			ans = max(ans,p);
		}
		for(int i = 0 ; i < 1000 ; i++){
			int p = 0;
			for(int j = 0 ; i+j < 1000 ; j++){
				p += A[j][i+j] - '0';
			}
			ans = max(ans,p);
		}
		for(int i = 900 ; i >=0 ; i--){
			int p = 0;
			for(int j = 0 ; i-j >= 0 ; j++){
				p += A[j][i-j] - '0';
			}
			ans = max(ans,p);
		}
		cout << ans << endl;
	}
}