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 <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef vector<double> vd;
typedef vector<vd> vvd;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		char str[256];
		vector<string> table(n);
		rep(i, n){
			scanf("%s", str);
			table[i] = str;
		}
		
		int ans = 0;
		rep(i, n) rep(j, n){
			const int dy[] = {-1, -1, 0, 1};
			const int dx[] = {0, 1, 1, 1};
			rep(k, 4){
				int y = i, x = j;
				int cnt = 0;
				while(table[y][x] == '1'){
					++cnt;
					int py = y + dy[k], px = x + dx[k];
					if(py<0 || n<=py || px<0 || n<=px)
						break;
					y = py;
					x = px;
				}
				ans = max(ans, cnt);
			}
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
char board[300][300]={{0}};

int n;
int main(){
	while(cin>>n,n){
		pair<pii,pii> dp[300][300];
		memset(dp, 0, sizeof(dp));
		int ans = 0;
		for(int i =1;i <=n;i++){
			for(int j =1;j <=n;j++){
				cin>>board[i][j];
				if(board[i][j]=='1'){
					dp[i][j].first.first =1;
					dp[i][j].first.second=1;
					dp[i][j].second.first =1;
					dp[i][j].second.second=1;
				}
			}
		}
		for(int i =1;i <=n;i++){
			for(int j =1;j <=n;j++){
				if(board[i][j]=='1'){
					int x = dp[i][j].first.first =dp[i][j-1].first.first+1;
					int y = dp[i][j].first.second=dp[i-1][j].first.second+1;
					int z = dp[i][j].second.first =dp[i-1][j-1].second.first+1;
					int r = dp[i][j].second.second=dp[i-1][j+1].second.second+1;
					//cout <<x<<" "<<y<<" "<<" "<<z<<" "<<r<<endl;
					int t1 =max(x,y);
					int t2 =max(z,r);
					ans =max(ans,max(t1,t2));
				}
			}
		}
		cout <<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while(cin >> n, n) {
    char ba[n][n];
    REP(i,n)
      REP(j,n)
      cin >> ba[j][i];
    int dp[n][n][4]; // ツ可。ツ、ツ縦ツ、ツ偲篠湘」ツ債カツ、ツ偲篠湘」ツ右
    memset(dp,0,sizeof(dp));
    
    REP(y,n) {
      REP(x,n) {
        if (ba[x][y] == '1') {
          dp[x][y][0] = ((x>0)?dp[x-1][y][0]:0) + 1;
          dp[x][y][1] = ((y>0)?dp[x][y-1][1]:0) + 1;
          dp[x][y][2] = ((x>0&&y>0)?dp[x-1][y-1][2]:0) + 1;
          dp[x][y][3] = ((x<n-1&&y<n-1)?dp[x+1][y-1][3]:0) + 1;
        }
      }
    }
    cout << *max_element(&dp[0][0][0],&dp[n-1][n-1][3]) << endl;
  }
}

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(dp[mode][i][j]!=-1)
    return dp[mode][i][j];
  if(!data[i][j])
    return 0;
  if(i<0 || i>=n ||
     j<0 || j>=n)
    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<bits/stdc++.h>
using namespace std;
int main()
{
    char ma[255][255];
    int n;
    while(cin>>n,n){
        int pillar[255]={};
        for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>ma[i][j];
        int ans=0,lo=0;
        for(int i=0;i<n&&ans<n;i++){
            for(int j=0;j<n;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);
            lo=0;
        }
        for(int i=1;i<n&&ans<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;
    }
}