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<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<cfloat>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(scanf("%d",&n),n){
    char buff[n][n+1];
    REP(i,n) scanf("%s",buff[i]);

    int ans = 0;

    REP(i,n){
      int cnt = 0;
      REP(j,n){
	if(buff[i][j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(j,n){
      int cnt = 0;
      REP(i,n){
	if(buff[i][j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(i,n){
      int cnt = 0;
      REP(j,n-i){
	if(buff[i+j][j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(i,n){
      int cnt = 0;
      REP(j,n-i){
	if(buff[j][i+j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(i,n){
      int cnt = 0;
      REP(j,i+1){
	if(buff[j][i-j] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    REP(i,n){
      int cnt = 0;
      REP(j,i+1){
	if(buff[n-j-1][n-(i-j)-1] == '1')
	  cnt++;
	else{
	  ans = max(ans, cnt);
	  cnt = 0;
	}
      }
      ans = max(ans, cnt);
    }

    printf("%d\n",ans);
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
char g[300][300];
int main(){
    int n;
    while(cin>>n && n){
        for(int i=0;i<n;i++)cin>>g[i];
        int dx[]={1,1,1,0};
        int dy[]={-1,0,1,1};
        int ans=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(g[i][j]=='1'){
                    for(int d=0;d<4;d++){
                        int ii, jj;
                        for(ii=i,jj=j; 0<=ii&&ii<n&&0<=jj&&jj<n && g[ii][jj]=='1'; ii+=dy[d],jj+=dx[d]);
                        ans=max({ans,abs(ii-i),abs(jj-j)});
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999
#define eps 1e-9
int n,c;


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        string data[300];
        rep(i,n) cin>>data[i];

        int maxi=-1;
        rep(i,n*2-1){
//            cout<<endl<<i<<endl;
            int sum=0;
            if(i<n){
                rep(j,i+1){
                    sum+=data[j][i-j]-'0';
                }
            }else{
                rep(j,(2*n-1)-i){
//                    cout<<i+j+1-n<<" "<<i-(i+j+1-n)<<endl;
                    sum+=data[i+j+1-n][i-(i+j+1-n)]-'0';
                }
            }
            maxi=max(maxi,sum);
        }
        int sum;
        rep(i,n){
            sum=0;
            rep(j,n){
                sum+=data[i][j]-'0';
            }
            maxi=max(sum,maxi);
        }
        
        rep(i,n){
            sum=0;
            rep(j,n){
                sum+=data[j][i]-'0';
            }
            maxi=max(maxi,sum);
        }
        cout<<maxi<<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;
        string d[256];
        rep(i, 0, n) cin >> d[i];
        rep(i ,0, n){
            rep(j, 0, n){
                if(d[i][j] == '0') break;
                if(j == n - 1) MAX = n;
            }
        }
        rep(i, 0, n){
            rep(j, 0, n){
                if(d[j][i] == '0') break;
                if(j == n - 1) MAX = n;
            }
        }
        rep(i, 0, n){
            int l = n - i;
            rep(j, 0, l){
                if(d[i + j][j] == '0') 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] == '0') 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] == '0') break;
                if(j == l - 1) MAX = max(MAX, l);
            }
        }
        rep(i, 0, n){
            int l = i + 1;
            rep(j, 0, l){
                if(d[j][i - j] == '0') break;
                if(j == l - 1) MAX = max(MAX, l);
            }
        }
        cout << MAX << endl;
    }
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

int main()
{
    int N;
    
    while(cin >> N, N)
    {
        int dp[300][300][4];

        rep(i, N) rep(j, N) rep(k, 4) dp[i][j][k] = 0;

        vector<string> grid(N);

        rep(i, N) cin >> grid[i];

        int ans = 0;

        rep(i, N)
        {
            rep(j, N)
            {
                if(grid[i][j] != '1') continue;

                if(j != 0) dp[i][j][0] = dp[i][j - 1][0] + 1;
                if(i != 0) dp[i][j][1] = dp[i - 1][j][1] + 1;
                if(i != 0 && j != 0) dp[i][j][2] = dp[i - 1][j - 1][2] + 1;
                if(i != 0 && j != N) dp[i][j][3] = dp[i - 1][j + 1][3] + 1;

                rep(k, 4) ans = max(ans, dp[i][j][k]);

            }
        }

        cout << (ans != 0 ? ans + 1 : 0) << endl;

    }

    return 0;
}