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;
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 maxup(a,b) (a=max(a,b))
#define minup(a,b) (a=min(a,b))
#define INF 999999999

int n;

int exe(int y,int x,int dy,int dx,vector<string> data){
    int tmp = 0;
    while(1){
        if( !(x>=0 && y>=0 && x<n && y<n) ){
            break;
        }
        tmp+=data[y][x]-'0';
        x+=dx,y+=dy;
    }
    return tmp;
}


int solve(int y,int x,vector<string> data){
    int lu=0,ld=0;
    int ru=0,rd=0;
    
    rd = exe(y,x,1,1,data);
    ru = exe(y,x,-1,1,data);
    ld = exe(y,x,1,-1,data);
    lu = exe(y,x,-1,-1,data);
    
    return max(rd+lu,ru+ld)-(data[y][x]-'0');
}


int main(){
    while(cin>>n&&n){
        vector<string> data(n);
        rep(i,n)cin>>data[i];

        int maxi = -1;
        rep(i,n){
            int tmp=0;
            rep(j,n){
                tmp+=data[i][j]-'0';
            }
            maxup(maxi,tmp);
        }
        rep(i,n){
            int tmp=0;
            rep(j,n){
                tmp+=data[j][i]-'0';
            }
            maxup(maxi,tmp);
        }
        
        rep(i,n){
            rep(j,n){
                maxup(maxi,solve(i,j,data));
            }
        }
        cout<<maxi<<endl;
    }
}

C++: #include <iostream>
#include <stdlib.h>

using namespace std;

int d[8][2] = {
	{-1, -1},
	{-1, 0},
	{-1, 1},
	{0, -1},
	{0, 1},
	{1, -1},
	{1, 0},
	{1, 1}
};

int search(int **a, int x, int y, int n, int k)
{
	if(x < 0 || y < 0 || x == n || y == n || a[x][y] == 0){
		return 0;
	} else {
		return (search(a, (x+d[k][0]), (y+d[k][1]), n, k) + 1);
	}
}

int main(int argc, char **argv)
{
	int **a, n, i, j, k, tmp, c, cnt = 0;
	
	while(1){
		cin >> tmp;
		if(tmp == 0){
			break;
		}
		n = tmp;
		a = (int **)calloc(n, sizeof(int));
		for(i = 0; i < n; i++){
			a[i] = (int *)calloc(n, sizeof(int));
			for(j = 0; j < n; j++){
				scanf("%1d", &a[i][j]);
			}
		}
			
		for(i = 0, c = 0; i < n; i++){
			for(j = 0; j < n; j++){
				if(a[i][j] == 1){
					for(k = 0, tmp = 1; k < 8; k++, tmp = 1){
						tmp += search(a, i+d[k][0], j+d[k][1], n, k);			
						if(c < tmp){
							c = tmp;
						}
					}
				}
			}
		}
		
		cout << c << endl;
		for(i = 0; i < n; i++){
			free(a[i]);
		}
		free(a);
		n = 0;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,ma;
	while(cin>>n,n){
		string s[260];
		rep(i,n)
		cin>>s[i];
		ma=0;
		rep(i,n){
			rep(j,n){
				if(s[i][j]=='1'){
					for(int k=0;k<=n;k++){
						if(j+k==n||s[i][j+k]=='0'){
							ma=max(ma,k);
							break;
						}
					}
					for(int k=0;k<=n;k++){
						if(i+k==n||s[i+k][j]=='0'){
							ma=max(ma,k);
							break;
						}
					}
					for(int k=0;k<=n;k++){
						if(i+k==n||j+k==n||s[i+k][j+k]=='0'){
							ma=max(ma,k);
							break;
						}
					}
					for(int k=0;k<=n;k++){
						if(i+k==n||j-k==-1||s[i+k][j-k]=='0'){
							ma=max(ma,k);
							break;
						}
					}
					
				}
			}
		}
		cout<<ma<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    while(cin >> n,n){
        vs s(n);
        rep(i,n)cin >> s[i];
        int ans = 0;
        rep(i,n)rep(j,n)if(s[i][j] == '1'){
            int k = j;
            while(k < n && s[i][k] == '1')k++;
            ans = max(ans, k-j);
            k = i;
            while(k < n && s[k][j] == '1')k++;
            ans = max(ans, k-i);
            k = 0;
            while(i+k < n && j+k < n && s[i+k][j+k] == '1')k++;
            ans = max(ans, k);
            k = 0;
            while(i+k < n && j-k >= 0 && s[i+k][j-k] == '1')k++;
            ans = max(ans, k);
            //cout << i << " " << j << " " << ans << endl;
        }

        cout << ans << endl;
    }

}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,j) for(int i=0;i<j;i++)
using namespace std;
int n;
int dx[]={1,1,-1},dy[]={0,1,1};
vector<string>V;
int cnt(int y,int x,int d){
    if(x<0||x>=n||y<0||y>=n)return 0;
    if(V[y][x]=='0')return 0;
    return cnt(y+dy[d],x+dx[d],d)+1;
}
int main(){

    while(cin>>n,n){
        V.clear();
        string str;
        int mx=-1;
        rep(i,n){
            cin>>str;
            V.push_back(str);
        }
        rep(i,n)
            rep(j,n)
                rep(k,3)mx=max(mx,cnt(i,j,k));

        cout<<mx<<endl;


    }
}

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

int grid[255][255];

int main() {
    int n;
    while (cin >> n, n) {
        char c;
        for (int i=0; i<n; ++i) {
            for (int j=0; j<n; ++j) {
                cin >> c;
                grid[i][j] = c - '0';
            }
        }
        int x, y, cnt, res = 0;
        for (int i=0; i<n; ++i) {
            // right
            cnt = 0, y = i, x = 0;
            while (x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ x;
            }
            // right down
            cnt = 0, y = i, x = 0;
            while (y < n && x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, ++ x;
            }
            // left down
            cnt = 0, y = 0, x = i;
            while (y < n && 0 <= x) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, -- x;
            }
            // down
            cnt = 0, y = 0, x = i;
            while (y < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y;
            }
        }
        cout << res << endl;
    }
    return 0;
}