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<stdio.h>
char table1[255][256];
int slash[255][255];
int yen[255][255];
int yoko[255][255];
int tate[255][255];
int main(){
	int n;
	while(scanf("%d",&n),n){
		for(int i=0;i<255;i++)
			for(int j=0;j<255;j++)
				table1[i][j]='0';
		for(int i=0;i<n;i++){
			scanf("%s",table1[i]);
		}
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				yen[i][j]=slash[i][j]=tate[i][j]=yoko[i][j]=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==0&&table1[i][j]=='1')tate[i][j]=1;
				else if(i>0&&table1[i][j]=='1')tate[i][j]=tate[i-1][j]+1;
				if(j==0&&table1[i][j]=='1')yoko[i][j]=1;
				else if(j>0&&table1[i][j]=='1')yoko[i][j]=yoko[i][j-1]+1;
				if((i==0||j==0)&&table1[i][j]=='1')yen[i][j]=1;
				else if(table1[i][j]=='1')yen[i][j]=yen[i-1][j-1]+1;
			}
		}
		for(int i=n-1;i>=0;i--){
			for(int j=0;j<n;j++){
				if((i==n-1||j==n-1)&&table1[i][j]=='1')slash[i][j]=1;
				else if(table1[i+1][j+1]=='1')slash[i][j]=slash[i+1][j+1]+1;
			}
		}
		int ret=0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++){
				if(ret<yen[i][j])ret=yen[i][j];
				if(ret<slash[i][j])ret=slash[i][j];
				if(ret<yoko[i][j])ret=yoko[i][j];
				if(ret<tate[i][j])ret=tate[i][j];
			}
		printf("%d\n",ret);
	}
}

C++: #include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    int n;
    string s[300];
    while(cin>>n,n!=0){
        for(int i = 0;i < n;i++)cin>>s[i];
        int ans = 0;
        // hor
        for(int i = 0;i < n;i++){
            int cnt = 0;
            for(int j = 0;j < n;j++){
                if(s[i][j] == '1')ans = max(ans,++cnt);
                else cnt = 0;
            }
        }

        //ver
        for(int j = 0;j < n;j++){
            int cnt = 0;
            for(int i = 0;i < n;i++){
                if(s[i][j] == '1')ans = max(ans,++cnt);
                else cnt = 0;
            }
        }

        //dia_1
        int dp[300][300] = {};
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(s[i][j] == '1'){
                    if(i == 0 || j == 0){
                        dp[i][j] = 1;
                        ans = max(ans,dp[i][j]);
                    }
                    else{
                        dp[i][j] = dp[i-1][j-1] + 1;
                        ans = max(ans,dp[i][j]);
                    }
                }
            }
        }

        //dia_2
        int dp2[300][300] = {};
        for(int i = 0;i < n;i++){
            for(int j = n-1;j >= 0;j--){
                if(s[i][j] == '1'){
                    if(i == 0 || j == n-1){
                        dp2[i][j] = 1;
                        ans = max(ans,dp2[i][j]);
                    }
                    else{
                        dp2[i][j] = dp2[i-1][j+1] + 1;
                        ans = max(ans,dp2[i][j]);
                    }
                }
            }
        }
        cout<<ans<<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+1)if(n*n-i-j*(n+1)<n*n)sum += p[n*n-i-j*(n+1)];
			MAX = max(sum,MAX);
		}
		
		rep(i,n){
			sum = 0;
			rep(j,i+1)if(n*n-i-j*(n+1)<n*n)sum += p[n*(n-1)+i-j*(n-1)];
			MAX = max(sum,MAX);
		}
		cout << MAX << endl;
	}
}

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[]={-1,0,-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!=1||j==0&&k<2)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)rep(k,4)out=max(out,dp[i][j][k]);
		cout<<out<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
string map[300];
signed main() {
	int n;
	while (cin >> n, n) {
		for (int i = 0; i < n; i++)cin >> map[i];
		int ans = 0;
		for (int x = 0; x < n; x++) {
			for (int y = 0; y < n; y++) {
				if (map[x][y] == '0')continue;
				int x1 = x, y1 = y;
				for (int i = -1; i <= 1; i++) {
					for (int j = -1; j <= 1; j++) {
						x1 = x; y1 = y;
						if (i == 0 && j == 0)continue;
						int cnt = 1;
						while (x1 + i >= 0 && x1 + i < n && y1 + j >= 0 && y1 + j < n) {
							if (map[x1 + i][y1 + j] != '1') goto heaven;
							x1 += i; y1 += j; cnt++;
						}
					heaven:
						ans = max(ans, cnt);
					}
				}
			}
		}
		cout << ans << endl;
	}
}

C++: #include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int n, ans, G[300][300][4];
int mv[4][2] = { {-1,0},{0,-1},{-1,-1},{-1,1} };
signed main(void) {
	while (scanf("%d", &n), n) { ans = 0; getchar();
	for (int i = 1; i <= n; i++, getchar())
		for (int j = 1; j <= n; j++)
			if (G[i][j][0] = G[i][j][1] = G[i][j][2] = G[i][j][3] = getchar() - '0')
				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);
	}
}