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 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;
        vector<string> d(256);
        rep(i, 0, n) cin >> d[i];
        rep(i ,0, n){
            rep(j, 0, n){
                if(d[i][j] != '1') break;
                if(j == n - 1) MAX = n;
            }
        }
        rep(i, 0, n){
            rep(j, 0, n){
                if(d[j][i] != '1') break;
                if(j == n - 1) MAX = n;
            }
        }
        rep(i, 0, n){
            int l = n - i;
            rep(j, 0, l){
                if(d[i + j][j] != '1') 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] != '1') 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] != '1') break;
                if(j == l - 1) MAX = max(MAX, l);
            }
        }
        rep(i, 0, n){
            int l = n - i;
            rep(j, 0, l){
                if(d[i + j][n - 1 - j] != '1') break;
                if(j == l - 1) MAX = max(MAX, l);
            }
        }
        cout << MAX << endl;
    }
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int dy[] = {-1, -1, 0, 1, 1, 1, 0, -1};
    int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<string> s(n);
        for(int i=0; i<n; ++i)
            cin >> s[i];

        int ret = 0;
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                for(int k=0; k<8; ++k){
                    int y = i;
                    int x = j;
                    int num = 0;
                    while(0 <= y && y < n && 0 <= x && x < n && s[y][x] == '1'){
                        ++ num;
                        y += dy[k];
                        x += dx[k];
                    }
                    ret = max(ret, num);
                }
            }
        }

        cout << ret << endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#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 mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second


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

main(){
  int n;
  while(cin>>n,n){
    int grid[n][n],tate[n][n],yoko[n][n],lurd[n][n],ruld[n][n];
    char c;
    rep(i,n)rep(j,n){
      cin>>c;
      tate[i][j]=yoko[i][j]=lurd[i][j]=ruld[i][j]=grid[i][j]=c-'0';
    }
    

    int ans=0;
    rep(i,n){
      rep(j,n){
	if(grid[i][j]==0)continue;
	if(i&&j+1<n&&ruld[i-1][j+1])ruld[i][j]=max(ruld[i][j],ruld[i-1][j+1]+1);
	if(i&&tate[i-1][j])tate[i][j]=max(tate[i][j],tate[i-1][j]+1);
	if(i&&j&&lurd[i-1][j-1])lurd[i][j]=max(lurd[i][j],lurd[i-1][j-1]+1);
	if(j&&yoko[i][j-1])yoko[i][j]=max(yoko[i][j],yoko[i][j-1]+1);
	ans=max(ans,max(tate[i][j],max(yoko[i][j],max(lurd[i][j],ruld[i][j]))));
      }
    }
    rep(i,n){
      rep(j,n){
	//	printf("%2d",grid[i][j]);
      }
      //      cout<<endl;
    }
    cout<<ans<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n;
    string line[300];
    while (cin >> n && n) {
        for (int i = 0; i < n; i++) cin >> line[i];
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            ll cnt = 0, len = 0;
            for (int j = 0; j < n; j++) {
                if (line[i][j] == '1') len++;
                else len = 0;
                cnt = max(cnt, len);
            }
            ans = max(ans, cnt);
        }
        for (int j = 0; j < n; j++) {
            ll cnt = 0, len = 0;
            for (int i = 0; i < n; i++) {
                if (line[i][j] == '1') len++;
                else len = 0;
                cnt = max(cnt, len);
            }
            ans = max(ans, cnt);
        }
        for (int j = 0; j < n; j++) {
            ll cy = 0, cx = j;
            ll cnt = 0, len = 0;
            while (0 <= cy && cy < n && 0 <= cx && cx < n) {
                if (line[cy][cx] == '1') len++;
                else len = 0;
                cnt = max(cnt, len);
                cy++, cx--;
            }
            ans = max(ans, cnt);
        }
        for (int j = n - 1; j >= 0; j--) {
            ll cy = 0, cx = j;
            ll cnt = 0, len = 0;
            while (0 <= cy && cy < n && 0 <= cx && cx < n) {
                if (line[cy][cx] == '1') len++;
                else len = 0;
                cnt = max(cnt, len);
                cy++, cx++;
            }
            ans = max(ans, cnt);
        }
        for (int j = 0; j < n; j++) {
            ll cy = n - 1, cx = j;
            ll cnt = 0, len = 0;
            while (0 <= cy && cy < n && 0 <= cx && cx < n) {
                if (line[cy][cx] == '1') len++;
                else len = 0;
                cnt = max(cnt, len);
                cy--, cx--;
            }
            ans = max(ans, cnt);
        }
        for (int j = n - 1; j >= 0; j--) {
            ll cy = n - 1, cx = j;
            ll cnt = 0, len = 0;
            while (0 <= cy && cy < n && 0 <= cx && cx < n) {
                if (line[cy][cx] == '1') len++;
                else len = 0;
                cnt = max(cnt, len);
                cy--, cx++;
            }
            ans = max(ans, cnt);
        }
        cout << ans << endl;
    }
}