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 <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
				{
					j = 0;
				}
				ans = max(ans, j);
			}
		}
		rei(n)
		{
			int j = 0;
			rel(n)
			{
				if (v[l][i] == '1')
				{
					j++;
				}
				else
				{
					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
				{
					j = 0;
				}
				ans = max(j, ans);
			}
			j = 0;
			for (int l = 0; l < n - i; l++)
			{
				if (v[i + l][l] == '1')
				{
					j++;
				}
				else
				{
					j = 0;
				}
				ans = max(j, ans);
			}
			j = 0;
			for (int l = 0; l <= i; l++)
			{
				if (v[i - l][l] == '1')
				{
					j++;
				}
				else
				{
					j = 0;
				}
				ans = max(ans, j);
			}
			j = 0;
			for (int l = 0; l <n- i; l++)
			{
				if (v[n-1-l][l+i] == '1')
				{
					j++;
				}
				else
				{
					j = 0;
				}
				ans = max(ans, j);
			}
		}
			
			
			
		cout << ans << endl;




	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i = 0; i < (a); i++)
bool prime[10002];
int field[256][256];
int dx[] = {1,1,1,0}, dy[] = {-1,1,0,1};
int n;
int func(int x, int y, int k) {
	int cnt = 0;
	while(1) {
		if(x < 0 || x >= n || y < 0 || y >= n) break;
		if(field[y][x] == 0) break;
		x += dx[k], y+= dy[k];
		cnt += 1;
	}
	return cnt;
}
int main() {
	while(cin >> n,n) {
		rep(i,n){
			string str;
			cin >> str;
			rep(j, str.size()){
				field[i][j] = str[j] - '0';
			}
		}
		int ans = 0;
		rep(i, n) {
			rep(j, n) {
				if(field[i][j] == 0) continue;
				rep(k, 4) {
					ans = max(func(j,i,k),ans);
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
bool data[255][255];    
int dp[4][255][255];

int check(int mode,int i,int j)
{
  if(i<0 || i>=n ||
     j<0 || j>=n)
    return 0;
  if(dp[mode][i][j]!=-1)
    return dp[mode][i][j];
  if(!data[i][j])
    return 0;
  if(mode==1)
    dp[mode][i][j]=check(1,i+1,j)+1;
  else if(mode==2)
    dp[mode][i][j]=check(2,i+1,j-1)+1;
  else if(mode==3)
    dp[mode][i][j]=check(3,i+1,j+1)+1;
  
  return dp[mode][i][j];
}

int main()
{

  for(;cin>>n,n;)
    {

      memset(dp,-1,sizeof(dp));
      //<->0, up-down,1,hidarisita2,migisita3
      int ans=0;
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  {
	    char tmp;
	    cin>>tmp;
	    data[i][j]=(tmp=='1');
	    if(data[i][j])
	      {
		if(j==0)
		  dp[0][i][j]=1;
		else
		  dp[0][i][j]=dp[0][i][j-1]+1;
	      }
	    else
	      dp[0][i][j]=0;
	    ans=max(ans,dp[0][i][j]);	    
	  }
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  {
	    for(int k=1;k<4;k++)
	      ans=max(ans,check(k,i,j));
	  }
      cout<<ans<<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-1; i++ )
		{
			cnt = 0;
			for ( int j = 0; j <= n-i-1; j++ )
			{
				if ( map[n-j-1][j+1] == '1' )
					cnt++;
			}
			answer = max( answer, cnt );
		}

		cout << answer << endl;

	}
	return 0;
}

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 cp_in(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            s[i][j] = in[i][j];
        }
    }
}

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);
        }
    }
}

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(in[j][i] == 1){
                    cnt++;
                    b = max(b,cnt);
                }
                else cnt = 0;
            }
        }

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