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 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[y][x].f.f+=a[i][j].f.f;
        if(k==1&&a[y][x].f.s)a[y][x].f.s+=a[i][j].f.s;
        if(k==2&&a[y][x].s.f)a[y][x].s.f+=a[i][j].s.f;
        if(k==3&&a[y][x].s.s)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++){
    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>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define fi first
#define se second
using namespace std;


signed main(){
    int n;
    while(cin >> n, n){
        int MAX = 0;
        vector<string> d(256);
        rep(i, 0, n) cin >> d[i];
        rep(i ,0, n){
            rep(j, 0, n){
                if(d[i][j] != '1') break;
                if(j == n - 1) MAX = n;
            }
        }
        rep(i, 0, n){
            rep(j, 0, n){
                if(d[j][i] != '1') break;
                if(j == n - 1) MAX = n;
            }
        }
        rep(i, 0, n){
            int l = n - i;
            rep(j, 0, l){
                if(d[i + j][j] != '1') break;
                if(j == l - 1) MAX = max(MAX, l);
            }
        }
        rep(i, 0, n){
            int l = n - i;
            rep(j, 0, l){
                if(d[j][i + j] != '1') break;
                if(j == l - 1) MAX = max(MAX, l);
            }
        }
        rep(i, 0, n){
            int l = i + 1;
            rep(j, 0, l){
                if(d[i - j][j] != '1') break;
                if(j == l - 1) MAX = max(MAX, l);
            }
        }
        rep(i, 0, n){
            int l = n - i;
            rep(j, 0, l){
                if(d[n - 1 - j][i + j] != '1') break;
                if(j == l - 1) MAX = max(MAX, l);
            }
        }
        cout << MAX << endl;
    }
}

C++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		char G[257][257];
		for(int i=0; i<=n+1; i++){
			for(int j=0; j<=n+1; j++){
				G[i][j] = '0';
			}
		}

		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				cin >> G[i][j];
			}
		}

		int DP_max = 0;

		int DP[255][255][4];
		for(int i=0; i<=n+1; i++){
			for(int j=0; j<=n+1; j++){
				for(int k=0; k<4; k++){
					DP[i][j][k] = 0;
				}
			}
		}

		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(G[i][j]=='0')
					continue;

				DP[i][j][0] = DP[i-1][j][0]+1;
				DP[i][j][1] = DP[i][j-1][1]+1;
				DP[i][j][2] = DP[i-1][j-1][2]+1;
				DP[i][j][3] = DP[i-1][j+1][3]+1;

				for(int k=0; k<4; k++){
					if(DP[i][j][k]>DP_max){
						DP_max = DP[i][j][k];
					}
				}
			}
		}

		cout << DP_max << '\n';
	}

	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char f[300][300];
bool used[300][300];
int n;
int ans;
int dx[4]={1,0,1,-1};
int dy[4]={0,1,-1,1};
void dfs(int x,int y,int d,int k)
{
	if(x<0||x>=n||y<0||y>=n)return;
	if(used[x][y])return;
	if(f[x][y]=='0')return;
	ans=max(ans,d);
	dfs(x+dx[k],y+dy[k],d+1,k);
	return;
}
void solve(int k)
{
	memset(used,false,sizeof(used));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			dfs(i,j,1,k);
		}
	}
	return ;
}
int main()
{
	while(1)
	{
		ans=0;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cin >> f[i][j];
			}
		}
		for(int i=0;i<4;i++)solve(i);
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int maxl(vector<int> seq){
  FOR(i,1,seq.size()) seq[i] += (seq[i])?seq[i-1]:0;
  int ret = 0;
  REP(i,seq.size()) ret = max(ret,seq[i]);
  return ret;
}
int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<string> grid(n);
    int ans = 0;
    REP(i,n) cin>>grid[i];
    REP(i,n){
      vector<int> seq;
      REP(j,n)seq.push_back(grid[i][j]-'0');
      ans = max(ans,maxl(seq));
    }
    REP(i,n){
      vector<int> seq;
      REP(j,n)seq.push_back(grid[j][i]-'0');
      ans = max(ans,maxl(seq));
    }
    REP(i,n){
      int x=i,y=0;
      vector<int> seq,seq2;
      REP(j,i+1)seq.push_back(grid[x--][y++]-'0'); 
      ans = max(ans,maxl(seq));
      x = n-1; y = n-1-i;
      REP(j,i+1)seq2.push_back(grid[x--][y++]-'0');
      ans = max(ans,maxl(seq2));
    }
    cout<<ans<<endl;
  }

  return 0;
}

C++: #include<iostream>

const int N = 257;
using namespace std;

int main(void){
  while( true ){
    int n;
    int ans = 0;
    int G[N][N] = {{0,},};
    int H[N][N][4] = {{{0,},},};
    
    cin >> n;
    if(n == 0)break;
    
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	char c;
	cin >> c;
	G[i+1][j+1] = c - '0';
      }
    }
    for(int j = 1; j < n + 1; j++){
      if( G[1][j] ){
	for(int k = 0; k < 4; k++){
	  if ( k == 0 ){
	    H[1][j][k] = H[1][j - 1][0] + 1;
	  }else{
	    H[1][j][k] = 1;
	  }
	}
      }
    }
    for(int i = 2; i < n + 1; i++){
      for(int j = 1; j < n + 1; j++){
	if( G[i][j] ){
	  H[i][j][0] = H[i][j - 1][0] + 1;
	  H[i][j][1] = H[i - 1][j - 1][1] + 1;
	  H[i][j][2] = H[i - 1][j][2] + 1;
	  H[i][j][3] = H[i - 1][j + 1][3] + 1;
	}
      }
    }
    for( int i = 1; i < n + 1; i++){
      for(int j = 1; j < n + 1; j++){
	for(int k = 0; k < 4; k++){
	  ans = max( ans, H[i][j][k] );
	}
      }
    }
    cout << ans << endl;
  }
  return 0;
}