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 <string>
#include <algorithm>

using namespace std;

struct Tag {
    int ver, hor, lr, rl;
    Tag() : ver(0), hor(0), lr(0), rl(0) {}
    Tag(int v, int h, int l, int r) : ver(v), hor(h), lr(l), rl(r) {}
};

Tag dp[2][255];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        for(int i = 0; i < N; ++i) {
            dp[0][i] = dp[1][i] = Tag(0, 0, 0, 0);
        }
        int ans = 0;
        for(int i = 0; i < N; ++i) {
            const int cur = i & 1;
            const int prev = cur ^ 1;
            string str;
            cin >> str;
            for(int c = 0; c < N; ++c) {
                dp[cur][c] = Tag(0, 0, 0, 0);
                if(str[c] == '1') {
                    if(i > 0) dp[cur][c].ver = dp[prev][c].ver;
                    if(c > 0) dp[cur][c].hor = dp[cur][c-1].hor;
                    if(i > 0 && c > 0) dp[cur][c].lr = dp[prev][c-1].lr;
                    if(i > 0 && c+1 < N) dp[cur][c].rl = dp[prev][c+1].rl;
                    ans = max(ans, ++dp[cur][c].ver);
                    ans = max(ans, ++dp[cur][c].hor);
                    ans = max(ans, ++dp[cur][c].lr);
                    ans = max(ans, ++dp[cur][c].rl);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

#define SIZE 255

char M[SIZE][SIZE];

int main() {
  int n, mx, cnt;
  
  while(cin>>n && n) {
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	cin >> M[i][j];
      }
    }

    mx = 0;
    // x = k
    for(int i = 0; i < n; i++) {
      cnt = 0;
      for(int j = 0; j < n; j++) {
	if(M[i][j]-'0') { 
	  cnt++;
	  mx = max(mx, cnt);
	} else {
	  cnt = 0;
	}
      }
    }

    // y = k
    for(int i = 0; i < n; i++) {
      cnt = 0;
      for(int j = 0; j < n; j++) {
	if(M[j][i]-'0') { 
	  cnt++;
	  mx = max(mx, cnt);
	} else {
	  cnt = 0;
	}
      }
    }

    int I;
    // y = x + k
    for(int i = 0; i < 2*n; i++) {
      cnt = 0;
      for(int j = 0; j < n; j++) {
	I = -j + i;
	if(0<=I&&I<n) {
	  if(M[I][j]-'0') { 
	    cnt++;
	    mx = max(mx, cnt);
	  } else {
	    cnt = 0;
	  }
	}
      }
    }
    
    // y = -x + k
    for(int i = 0; i < 2*n; i++) {
      cnt = 0;
      for(int j = 0; j < n; j++) {
	I = j + (-(n-1)+i); 
	if(0<=I&&I<n) {
	  if(M[I][j]-'0') { 
	    cnt++;
	    mx = max(mx, cnt);
	  } else {
	    cnt = 0;
	  }
	}
      }
    }

    cout << mx << endl;
  }
  
  return 0;
}

C++: #include <cstdio>
#include <algorithm>
int main(){
	int n;
	while(scanf("%d",&n),n){
		int m=0,v[4][2] = {{0,-1},{-1,0},{1,-1},{-1,-1}},map[257][257] = {{0}};
		for(int y=1;y<=n;y++)
			for(int x=1;x<=n;x++)scanf("%1d",&map[x][y]);

		for(int i=4;i;i--){
			int dp[257][257] = {{0}};
			for(int k=1;k<=n;k++)
				for(int j=1;j<=n;j++)m = std::max(m,dp[j][k] = map[j][k]?map[j][k] + dp[j+v[i][0]][k+v[i][1]]:0);
		}
		printf("%d\n",m);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define s second
#define f first
int dx[]={1,0,1,-1};
int dy[]={0,1,1,1};
int main(){
  int n;
  while(cin>>n,n){
    string s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    pair<pair<int,int>,pair<int,int> > a[n][n];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	a[i][j].f.f=a[i][j].f.s=a[i][j].s.f=a[i][j].s.s=s[i][j]-'0';    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	for(int k=0;k<4;k++){
	  int x=j+dx[k],y=i+dy[k];
	  if(x>=0&&y>=0&&y<n&&x<n){
	    if(k==0)a[y][x].f.f+=a[i][j].f.f;
	    if(k==1)a[y][x].f.s+=a[i][j].f.s;
	    if(k==2)a[y][x].s.f+=a[i][j].s.f;
	    if(k==3)a[y][x].s.s+=a[i][j].s.s;
	  }
	}
    int res=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)if(!j||!i||i==n-1||j==n-1){
	res=max(res,a[i][j].f.f);
	res=max(res,a[i][j].f.s);
	res=max(res,a[i][j].s.f);
	res=max(res,a[i][j].s.s);
      }
    cout<<res<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin>>n && n){
    vector<vector<char>> vc(n,vector<char>(n,' '));
    rep(i,n){
      rep(j,n){
        cin >>vc[j][i];
        vc[j][i] -= '0';
      }
    }
    auto tmp = vc;
    char ma = 0;
    rep(i,n){
      rep(j,n){
        if( j > 0 && tmp[j][i]){
          tmp[j][i] += tmp[j-1][i];
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    tmp = vc;
    rep(j,n){
      rep(i,n){
        if( i > 0 && tmp[j][i]){
          tmp[j][i] += tmp[j][i-1];
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    tmp = vc;
    rep(i,n){
      rep(j,n){
        if( j < n-1 && i > 0&& tmp[j][i]){
          tmp[j][i] += tmp[j+1][i-1];
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    tmp = vc;
    rep(i,n){
      rep(j,n){
        if( j > 0 && i > 0 && tmp[j][i]){
          tmp[j][i] += tmp[j-1][i-1];
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    cout << (int)ma << endl;
  }
  return 0;
}