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<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)if(in[i][j]=='1'){
			if(i==0&&j==0)dp[i][j][k]=1;
			else if(i==0&&k||j==0&&k<2||j==n-1&&k==3)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;
	}
}

C++: #include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int n, ans, G[300][300][4];
const int mv[4][2] = { {-1,0},{0,-1},{-1,-1},{-1,1} };
inline bool nextChar(void) {
	char c = getchar();
	while (c != '1'&&c != '0')c = getchar();
	return c == '1';
}
signed main(void) {
	while (scanf("%d", &n) && n) {
		memset(G, 0, sizeof(G)), ans = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++) if (nextChar())
				for (int k = 0; k < 4; k++)
					G[i][j][k] = G[i + mv[k][0]][j + mv[k][1]][k] + 1,
					ans = ans < G[i][j][k] ? G[i][j][k] : ans;
		printf("%d\n", ans);
	}
}

C++: #include <iostream>
#include <algorithm>
#include <memory.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
char field[300][300];

int main(){
  int n;
  while(cin >> n && n){
    rep(i, n)rep(j, n) cin >> field[i][j];
    int res = 0;
    int cnt = 0;
    // yoko
    rep(i, n){
      cnt = 0;
      rep(j, n){
	if(field[i][j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    //tate
    rep(i, n){
      cnt = 0;
      rep(j, n){
	if(field[j][i] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    
    rep(i, n){
      cnt = 0;
      rep(j, i+1){
	if(field[i-j][j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    //naname
    rep(i, n){
      cnt = 0;
      rep(j, n-i){
	if(field[n-j-1][i+j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    //naname  
    rep(i, n){
      cnt = 0;
      rep(j, n - i){
	if(field[i+j][j] == '1') cnt++;
	else cnt = 0;
      }
      res = max(res, cnt);
    }
    rep(i, n){
      cnt = 0;
      rep(j, n - i){
	if(field[j][i+j] == '1') cnt++;
	else cnt = 0;
      }
      res = max(res, cnt);
    }
    cout << res << endl;
  }
  return 0;
}

C++: #include<cstdio>
int main(void){
	int i,j,k,n,max,cnt,x,y;
	int dx[4]={1,1,0,-1},dy[4]={0,-1,-1,-1};
	char xy[225][225];
	while(1){
		max=0;
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++) scanf("%s",xy[i]);
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(xy[i][j]=='1'){
					for(k=0;k<4;k++){
						cnt=1;
						y=i; x=j;
						while(1){
							y=y+dy[k]; x=x+dx[k];
							if(y>=n||x>=n||y<0||x<0||xy[y][x]!='1') break;
							cnt++;
						}
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
#define MAX_N 255

int ans = 0, n, tmpans = 0;
int map[MAX_N + 1][MAX_N + 1];

void makeMap();
void check();
void loop(int sum, int x, int y, int xm, int ym);
void disp();

int main(){
    while(cin >>n){
        if(n == 0) break;
        ans = 0;
        makeMap();
        check();
        cout <<ans <<endl;
    }
    return 0;
}

void makeMap(){
    for(int i = 0; i < n; i++){
        string tmp;
        cin >>tmp;
        for(int j = 0; j < n; j++){
            map[i][j] = tmp[j] - 48;
        }
    }
}

void check(){
    int xm[4][2] = {{0, 0}, {1, -1}, {1, -1}, {-1, 1}}, ym[4][2] = {{1, -1}, {0, 0}, {-1, 1}, {-1, 1}};
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(map[i][j] == 1){
                for(int k = 0; k < 4; k++){
                    tmpans = 0;
                    for(int m = 0; m < 2; m++){
                        loop(0, j + xm[k][m], i + ym[k][m], xm[k][m], ym[k][m]);
                    }
                    tmpans++;
                    if(tmpans > ans){
                        ans = tmpans;
//                        disp();
//                        cout <<"(" <<i <<", " <<j <<") , " <<k <<" ans = " <<ans <<endl;
                    }
                }
            }
        }
    }
}

void loop(int sum, int x, int y, int xm, int ym){
    if(x >= n || y >= n || x < 0 || y < 0 || map[y][x] == 0){
//        cout <<"! (" <<y <<", " <<x <<") " <<sum <<endl;
        tmpans += sum;
    } else if(map[y][x] == 1){
//        map[y][x] = 0;
        loop(sum + 1, x + xm, y + ym, xm, ym);
//        map[y][x] = 1;
    }
}

void disp(){
    cout <<endl;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n ; j++){
            cout <<map[i][j] <<" ";
        }
        cout <<endl;
    }
}

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

int n;
char grid[255][255];
int dx[] = {1,0,1,-1};
int dy[] = {0,1,1,1};

int solv(int sx, int sy) {
	int res = 0;
	for (int i=0; i<4; ++i) {
		int cnt = 0, x = sx, y = sy;
		while (0 <= x && x < n && 0 <= y && y < n) {
			cnt = (grid[y][x] == '1' ? cnt+1 : 0);
			res = max(res, cnt);
			x += dx[i];
			y += dy[i];
		}
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	while (cin >> n, n) {
		char c;
		for (int i=0; i<n*n; ++i) {
			cin >> grid[i/n][i%n];
		}
		int res = 0;
		for (int i=0; i<n; ++i) {
			res = max(max(res, solv(0, i)), max(solv(n-1, i), solv(i, 0)));
		}
		cout << res << endl;
	}
	return 0;
}