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;

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;
    
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
	for(int k=1; k<=N; k++) {
	  if(j+k > N) continue;
	  bool ok = 1;
	  for(int l=0; l<k; l++) {
	    if(!grid[i][j+l]) ok = 0;
	  }
	  if(ok) {
	    ans = max(ans, k);
	  }
	}
      }
    }
    
    for(int j=0; j<N; j++) {
      for(int i=0; i<N; i++) {
	for(int k=1; k<=N; k++) {
	  if(i+k > N) continue;
	  bool ok = 1;
	  for(int l=0; l<k; l++) {
	    if(!grid[i+l][j]) ok = 0;
	  }
	  if(ok) {
	    ans = max(ans, k);
	  }
	}
      }
    }

    // right down
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
	for(int k=1; k<=N; k++) {
	  
	  if(i+k > N || j+k > N) continue;
	  
	  bool ok = 1;
	  for(int l=0; l<k; l++) {
	    if(!grid[i+l][j+l]) ok = 0;
	  }
	  if(ok) {
	    ans = max(ans, k);
	  }
	}
      }
    }
    
    // right up
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
	for(int k=1; k<=N; k++) {
	  if(i-k+1<0 || j+k>N) continue;
	  
	  bool ok = 1;
	  for(int l=0; l<k; l++) {
	    if(!grid[i-l][j+l]) ok = 0;
	  }
	  if(ok) {
	    ans = max(ans, k);
	  }
	}
      }
    }
    
    cout << ans << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int n;
string field[260];

bool isIn(int x, int y){
    return 0 <= x && x < n && 0 <= y && y < n;
}

int getLength(int x, int y, int dx, int dy){
    int count = 1;
    while(isIn(x+dx*count, y+dy*count) && field[y+dy*count][x+dx*count] == '1') count++;
    return count;
}

int main(){
    while(cin >> n, n){
        rep(i, n) cin >> field[i];

        int res = 0;
        rep(i, n) rep(j, n){
            if(field[j][i] == '1'){
                for(int k=-1; k <=0; k++)for(int l=-1; l <=1; l++){
                    if(k == 0 && l == 0) continue;
                    res = max(res, getLength(i, j, k, l));
                }
            }
        }
        cout << res << endl;
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999
#define eps 1e-9
int n,c;


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        string data[300];
        rep(i,n) cin>>data[i];

        int maxi=-1;
        rep(i,n*2-1){
//            cout<<endl<<i<<endl;
            int sum=0;
            if(i<n){
                rep(j,i+1){
                    sum+=data[j][i-j]-'0';
                }
            }else{
                rep(j,(2*n-1)-i){
//                    cout<<i+j+1-n<<" "<<i-(i+j+1-n)<<endl;
                    sum+=data[i+j+1-n][i-(i+j+1-n)]-'0';
                }
            }
            maxi=max(maxi,sum);
        }
        rep(i,n*2-1){
            //            cout<<endl<<i<<endl;
            int sum=0;
            if(i<n){
                rep(j,i+1){
                    sum+=data[j][n-1-(i-j)]-'0';
                }
            }else{
                rep(j,(2*n-1)-i){
                    //                    cout<<i+j+1-n<<" "<<i-(i+j+1-n)<<endl;
                    sum+=data[i+j+1-n][n-1-(i-(i+j+1-n))]-'0';
                }
            }
            maxi=max(maxi,sum);
        }
        int sum;
        rep(i,n){
            sum=0;
            rep(j,n){
                sum+=data[i][j]-'0';
            }
            maxi=max(sum,maxi);
        }
        
        rep(i,n){
            sum=0;
            rep(j,n){
                sum+=data[j][i]-'0';
            }
            maxi=max(maxi,sum);
        }
        cout<<maxi<<endl;
    }

}

C++: #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int m=0,v[4][2] = {{0,-1},{-1,0},{1,-1},{-1,-1}},dp[257][257];
		char map[257][257];
		for(int y=0;y<257;y++){
			for(int x=0;x<257;x++){
				map[x][y] = '0';
			}
		}
		for(int y=1;y<=n;y++){
			for(int x=1;x<=n;x++){
				cin >> map[x][y];
			}
		}

		for(int i=0;i<4;i++){
			memset(dp,0,sizeof(dp));
			for(int k=1;k<=n;k++){
				for(int j=1;j<=n;j++){
					dp[j][k] = map[j][k] - '0' + dp[j+v[i][0]][k+v[i][1]];
					m = max(m,dp[j][k]);
				}
			}
		}
		cout << m << endl;
	}
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int get(const vvi& a,int i,int j)
{
	if(i<0 || a.size()<=i || j<0 || a[i].size()<=j)
		return 0;
	return a[i][j];
}

int main()
{
	for(int n;cin>>n,n;){
		vs s(n);
		rep(i,n)
			cin>>s[i];
		vvi a(n,vi(n)),b=a,c=a,d=a;
		rep(i,n) rep(j,n)
			if(s[i][j]=='1'){
				a[i][j]=get(a,i-1,j)+1;
				b[i][j]=get(b,i,j-1)+1;
				c[i][j]=get(c,i-1,j-1)+1;
				d[i][j]=get(d,i-1,j+1)+1;
			}
		int res=0;
		rep(i,n) rep(j,n)
			res=max(res,max(max(a[i][j],b[i][j]),max(c[i][j],d[i][j])));
		cout<<res<<endl;
	}
	
	return 0;
}