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>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;
int n;
vector< vector<int> > m;
int d[] = {-1,0,1};

int c(int x){
    int ans = 0;
    REP(i,3){
	int temp = 0;
	int j = 0;
	while(!(x+d[i]*j < 0 || n <=  x+d[i]*j )){
	    if(m[n-1-j][x+d[i]*j] == 1){
		temp++;
		ans = max(ans,temp);
	    }else{
		ans = max(ans,temp);
		temp = 0;
	    }
	    j++;
	    if(j == n) break;
	}
    }
    REP(i,3){
	int temp = 0;
	int j = 0;
	while(!(x+d[i]*j < 0 || n <=  x+d[i]*j )){
	    if(m[j][x+d[i]*j] == 1){
		temp++;
		ans = max(ans,temp);
	    }else{
		ans = max(ans,temp);
		temp = 0;
	    }
	    j++;
	    if(j == n) break;
	}
    }
    return ans;
}
int r(int x){
    int ans = 0;
    REP(i,3){
	int temp = 0;
	int j = 0;
	while(!(x+d[i]*j < 0 || n <=  x+d[i]*j )){
	    if(m[n-1-j][x+d[i]*j] == 1){
		temp++;
		ans = max(ans,temp);
	    }else{
		ans = max(ans,temp);
		temp = 0;
	    }
	    j++;
	    if(j == n) break;
	}
    }
    REP(i,3){
	int temp = 0;
	int j = 0;
	while(!(x+d[i]*j < 0 || n <=  x+d[i]*j )){
	    if(m[x+d[i]*j][j] == 1){
		temp++;
		ans = max(ans,temp);
	    }else{
		ans = max(ans,temp);
		temp = 0;
	    }
	    j++;
	    if(j == n) break;
	}
    }
    return ans;
}

int main(){
    while(true){
	cin >> n;
	if(n == 0) break;
	m = vector< vector<int> >(n,vector<int>(n,0));
	REP(i,n){
	    string s;
	    cin >> s;
	    REP(j,n){
		m[i][j] = (int)(s[j]-'0');
	    }
	}
	int ans = 0;
	REP(i,n){
	    ans = max(ans,r(i));
	    ans = max(ans,c(i));
	}
	cout << ans << endl;
    }
    return 0;
}

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

int main()
{
	int a;
	while (cin >> a, a) {
		bool b[256][256];
		for (int c = 0; c < a; c++) {
			for (int d = 0; d < a; d++) {
				scanf("%1d", &b[c][d]);
			}
		}
		int MAX = 0;
		for (int e = 0; e < a; e++) {
			for (int f = 0; f < a; f++) {
				for (int h = -1; h < 2; h++) {
					for (int i = -1; i < 2; i++) {
						if (h | i) {
							int g = 0;
							for (int j = 0; e + h*j >= 0 && e + h*j < a&&f + i*j >= 0 && f + i*j < a; j++) {
								if (b[e + h*j][f + i*j]) { g++; MAX = max(MAX, g); }
								else g--;
							}
						}
					}
				}
			}
		}
		cout << MAX << endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }

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

int n;
string fi[1000];

int main() {
    while (cin >> n) {
        if (n == 0) break;
        for (int i = 0; i < n; ++i) { cin >> fi[i]; }
        int res = 0;
        for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
            if (fi[i][j] == '0') continue;
            for (int k = 0; k < 8; ++k) {
                int tmp = 0;
                for (int a = 0; a <= 1000; ++a) {
                    int ni = i + dx[k] * a, nj = j + dy[k] * a;
                    if (ni < 0 || ni >= n || nj < 0 || nj >= n) break;
                    if (fi[ni][nj] == '0') break;
                    ++tmp;
                }
                chmax(res, tmp);
            }
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    char ma[255][255];
    int n;
    while(cin>>n,n){
        int pillar[255]={},ans=0;
        for(int i=0;i<n;i++){
                int lo=0;
            for(int j=0;j<n;j++){
                cin>>ma[i][j];
                if(ma[i][j]=='1'){
                        pillar[j]++;
                        lo++;
                }
                else{
                    ans=max(pillar[j],ans);
                    ans=max(ans,lo);
                    lo=0;
                    pillar[j]=0;
                }

            }
            ans=max(ans,lo);
        }
        for(int i=0;i<n;i++){
                int kawa[4]={};
                ans=max(ans,pillar[i]);
                for(int j=0;j<=i;j++){
                    if(ma[j][i-j]=='1')kawa[0]++;
                    else{
                        ans=max(ans,kawa[0]);
                        kawa[0]=0;
                    }
                    if(ma[n-1-i+j][n-1-j]=='1')kawa[1]++;
                    else{;
                        ans=max(ans,kawa[1]);
                        kawa[1]=0;
                    }
                    if(ma[j][n-1-i+j]=='1')kawa[2]++;
                    else{
                        ans=max(ans,kawa[2]);
                        kawa[2]=0;
                    }
                    if(ma[n-1-i+j][j]=='1')kawa[3]++;
                    else {
                        ans=max(ans,kawa[3]);
                        kawa[3]=0;
                    }
                }
                ans=max(ans,kawa[0]);
                ans=max(ans,kawa[1]);
                ans=max(ans,kawa[2]);
                ans=max(ans,kawa[3]);
        }
        cout<<ans<<endl;
    }
}