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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  char x;
  while(cin>>n && n){
    vector<vector<int>> vc(n,vector<int>(n,0));
    rep(i,n){
      rep(j,n){
        cin >> x;
        vc[j][i] = x;
        vc[j][i] -= '0';
      }
    }
    auto tmp = vc;
    int 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 << ma << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
 
 int mem[256][256][4],i,j,k,n,an; 
 int main() {
  char da[256][256];
  while(cin >> n) {
  if (n==0) break;
  for (i=0;i<n;i++) cin >> da[i];
  for (i=0;i<n;i++) for (j=0;j<n;j++) for (k=0;k<4;k++) mem[i][j][k]=0;
  an=0;
  for (i=0;i<n;i++) for (j=0;j<n;j++) {
	  if (da[i][j]=='0') continue;
	  for (k=0;k<4;k++) {
		  mem[i][j][k]++;
		  if (k==0 && j>0) mem[i][j][k]+=mem[i][j-1][k];
		  if (k==1 && j>0 && i>0) mem[i][j][k]+=mem[i-1][j-1][k];
		  if (k==2 && i>0) mem[i][j][k]+=mem[i-1][j][k];
		  if (k==3 && i>0 && j<n-1) mem[i][j][k]+=mem[i-1][j+1][k];
		  if (an<mem[i][j][k]) an=mem[i][j][k];
	  }
  }
  cout << an << endl;
  }
 return 0;
 }

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

char mas[257][257];
int dx[]={-1,0,1,1,1,0,-1,-1};
int dy[]={-1,-1,-1,0,1,1,1,0};
int dfs(int x,int y,int k);
int n;

int main(){
  while(1){
    cin >> n;
    if(n == 0) break;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> mas[i][j];
      }
    }
    int ans = 0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(mas[i][j] == '1'){
	  for(int k=0;k<8;k++){
	    ans = max(ans,dfs(j,i,k) + 1);
	  }
	}
      }
    }
    cout << ans << endl;
  }
}

int dfs(int x,int y,int k){
  int nx = x + dx[k];
  int ny = y + dy[k];
  if(mas[ny][nx] == '1' && ny >= 0 && nx >= 0 && ny < n && nx < n){
    return (dfs(nx,ny,k) + 1);
  }
  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=n;y;y--)for(int x=n;x;x--)scanf("%1d",&map[x][y]);

		for(int i=0;i<4;i++){
			int dp[257][257] = {{0}};
			for(int k=n;k;k--)for(int j=n;j;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 <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 260;
int n;
string grid[MAX_N];
int max_len;
int memo[MAX_N][MAX_N][4];

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

int rec(int y, int x, int d)
{
    if (memo[y][x][d] >= 0)
        return memo[y][x][d];

    int nx = x + dx[d];
    int ny = y + dy[d];

    if (nx < 0 || nx >= n || ny < 0 || ny >= n)
        return 1;
    if (grid[ny][nx] == '0')
        return 1;

    return memo[y][x][d] = (rec(ny, nx, d) + 1);
}

int main()
{
    while (cin >> n, n) {
        max_len = 0;
        for (int i = 0; i < n; i++) 
            cin >> grid[i];

        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= n; j++)
                for (int k = 0; k < 4; k++)
                    memo[i][j][k] = -1;

        for (int y = 0; y < n; y++) 
            for (int x = 0; x < n; x++) 
                if (grid[y][x] == '1') {
                    for (int k = 0; k < 4; k++) 
                        max_len = max(max_len, rec(y, x, k));
                }

        cout << max_len << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	int MAX,sum;
	
	while(cin >> n && n){
		MAX = 0;
		
		char p[n*n];
		rep(i,n*n){cin >> p[i];p[i]-='0';}
		rep(i,n){
			sum = 0;
			rep(j,n)sum += p[i*n+j];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n)sum += p[i+j*n];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[i+j*(n+1)];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[(n-1-i)+j*(n-1)];
			MAX = max(sum,MAX);
		}
		
		rep(i,n){
			sum = 0;
			rep(j,i)sum += p[n*n-i-j*(n+1)];
			MAX = max(sum,MAX);
		}
		
		rep(i,n){
			sum = 0;
			rep(j,i)sum += p[n*(n-1)+i-j*(n-1)];
			MAX = max(sum,MAX);
		}
		cout << MAX << endl;
	}
}