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 <bits/stdc++.h>

using namespace std;

#define CK(n, a, b) (a <= n && n < b)

int main() {
  int N;
  
  while(cin >> N && N) {
    vector<string> G(N);
    for(int i=0; i<N; i++) {
      cin >> G[i];
    }
    
    int grid[N][N];
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
	grid[i][j] = G[i][j] - '0';
      }
    }
    
    int ans = 0;
    
    // right
    for(int i=0; i<N; i++) {
      int cnt = 0;
      for(int j=0; j<N; j++) {
	if(!grid[i][j]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }
    
    // down
    for(int j=0; j<N; j++) {
      int cnt = 0;
      for(int i=0; i<N; i++) {
	if(!grid[i][j]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }
    
    // right down
    for(int i=0; i<N; i++) {
      int sx = i, sy = 0;
      int cnt = 0;
      for(int k=0; k<N; k++) {
	if(!CK(sy+k, 0, N) || !CK(sx+k, 0, N)) break;
	if(!grid[sy+k][sx+k]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }
    for(int i=0; i<N; i++) {
      int sx = 0, sy = i;
      int cnt = 0;
      for(int k=0; k<N; k++) {
	if(!CK(sy+k, 0, N) || !CK(sx+k, 0, N)) break;
	if(!grid[sy+k][sx+k]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }


    // left down
    for(int i=0; i<N; i++) {
      int sx = N-1, sy = i;
      int cnt = 0;
      for(int k=0; k<N; k++) {
	if(!CK(sy+k, 0, N) || !CK(sx-k, 0, N)) break;
	if(!grid[sy+k][sx-k]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }
    for(int i=0; i<N; i++) {
      int sx = i, sy = 0;
      int cnt = 0;
      for(int k=0; k<N; k++) {
	if(!CK(sy+k, 0, N) || !CK(sx-k, 0, N)) break;
	if(!grid[sy+k][sx-k]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }
      
    cout << ans << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
#define PI pair<int,int>
using namespace std;
unsigned char m[257][257][4];
int main()
{
  int n,i,j,k,l;
  string s;
  PI p[4] = { PI(0,-1), PI(-1,0), PI(-1,-1), PI(-1,1) };
  for(;;){
    cin >> n;
    if(n==0) break;
    memset(m,0,sizeof(m));
    l = 0;
    for(i=1;i<=n;i++){
      cin >> s;
      for(j=1;j<=n;j++){
	if(s[j-1] == '1'){
	  for(k=0;k<4;k++){
	    m[i][j][k] = m[i+p[k].first][j+p[k].second][k]+1;
	    if(l<m[i][j][k]) l = m[i][j][k];
	  }
	}
      }
    }
    cout << l << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n;
char grid[256][256];

int solve(){
  int res = 0, c;
  rep(i, n){
    c = 0;
    rep(j, n){
      if(grid[i][j] == '1') res = max(res, ++c);
      else c = 0;
    }
  }

  rep(j, n){
    c = 0;
    rep(i, n){
      if(grid[i][j] == '1') res = max(res, ++c);
      else c = 0;
    }
  }

  rep(i, n){
    c = 0;
    rep(j, n){
      if(i - j < 0) break;
      if(grid[j][i-j] == '1') res = max(res, ++c);
      else c = 0;
    }
  }

  rep(i, n){
    c = 0;
    rep(j, n){
      if(n-j < 0) break;
      if(grid[n-i+j-1][n-j] == '1') res = max(res, ++c);
      else c = 0;
    }
  }

  rep(i, n){
    c = 0;
    rep(j, n){
      if(n - i + j - 1>= n) break;
      if(grid[j][n-i+j-1] == '1') res = max(res, ++c);
      else c = 0;
    }
  }

  rep(i, n){
    c = 0;
    rep(j, n){
      if(i + j >= n) break;
      if(grid[i+j][j] == '1') res = max(res, ++c);
      else c = 0;
    }
  }

  return res;
}

int main(){
  while(scanf("%d", &n) && n){
    memset(grid, 0, sizeof(grid));
    rep(i, n) scanf("%s", grid[i]);
    printf("%d\n", solve());
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
char g[300][300];
int main(){
	int n;
	while(cin>>n && n){
		for(int i=0;i<n;i++)cin>>g[i];
		int dx[]={1,1,1,0};
		int dy[]={-1,0,1,1};
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(g[i][j]=='1'){
					for(int d=0;d<4;d++){
						int ii, jj;
						for(ii=i,jj=j; 0<=ii&&ii<n&&0<=jj&&jj<n && g[ii][jj]=='1'; ii+=dy[d],jj+=dx[d]);
						ans=max({ans,abs(ii-i),abs(jj-j)});
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int dp[300][300][4];
int main(){
	int n;
	int dx[]={0,-1,-1,-1};
	int dy[]={-1,-1,0,1};
	while(cin>>n,n){
		vector<string>in(n);
		rep(i,n)cin>>in[i];
		rep(i,n)rep(j,n)rep(k,4)dp[i][j][k]=0;
		rep(i,n)rep(j,n)rep(k,4)if(in[i][j]=='1'){
			if(i==0&&j==0)dp[i][j][k]=1;
			else if(i==0&&k||j==0&&k<2)dp[i][j][k]=1;
			else dp[i][j][k]=dp[i+dx[k]][j+dy[k]][k]+1;
		}else dp[i][j][k]=0;
		int out=0;
//		rep(i,n){rep(j,n)cout<<" "<<dp[i][j][0];cout<<endl;}
		rep(i,n)rep(j,n)rep(k,4)out=max(out,dp[i][j][k]);
		cout<<out<<endl;
	}
}