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;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

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

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

        int a[255][255];
        rep(i,n)rep(j,n) a[i][j]=s[i][j]-'0';

        int ans=0;

        //??????????????????
        rep(i,n)rep(j,n)
        {
            if(a[i][j]==0) continue;

            rep(k,8)
            {
                int t=0;
                int nx=j, ny=i;
                while(0<=nx&&nx<n && 0<=ny&&ny<n)
                {
                    if(a[ny][nx]==1)
                    {
                        ++t;
                        ny+=dy[k];
                        nx+=dx[k];
                    }
                    else break;
                }

                ans=max(ans,t);
            }
        }

        cout << ans << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
#include <utility>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define REP(i, n) for((i) = 0; (i) < (n); i++)
#define FOR(i, a, n) for((i) = (a); (i) < (n); i++)

using namespace std;

const int INF = 1000000000;
const double PI = acos(-1);

typedef long long ll;

#define MAXN 260

int i, j, n, ans, grid[MAXN][MAXN], hor[MAXN][MAXN], ver[MAXN][MAXN], diagp[MAXN][MAXN], diago[MAXN][MAXN];
string str;

void reset() {
    memset(grid, 0, sizeof(grid));
    memset(hor, 0, sizeof(hor));
    memset(ver, 0, sizeof(ver));
    memset(diagp, 0, sizeof(diagp));
    memset(diago, 0, sizeof(diago));
}

int main(void) {
    while(scanf("%d", &n) == 1 && n != 0) {
        reset();
        ans = 0;
        REP(i, n) {
            cin >> str;
            REP(j, n) {
                grid[i][j] = str[j] - '0';
                if(grid[i][j] == 1) {
                    if(j - 1 >= 0) {
                        hor[i][j] = hor[i][j - 1] + 1;
                    } else {
                        hor[i][j] = grid[i][j];
                    }
                    if(i - 1 >= 0) {
                        ver[i][j] = ver[i - 1][j] + 1;
                    } else {
                        ver[i][j] = grid[i][j];
                    }
                    if(i - 1 >= 0 && j - 1 >= 0) {
                        diagp[i][j] = diagp[i - 1][j - 1] + 1;
                    } else {
                        diagp[i][j] = grid[i][j];
                    }
                    if(i - 1 >= 0 && j + 1 < n) {
                        diago[i][j] = diago[i - 1][j + 1] + 1;
                    } else {
                        diago[i][j] = grid[i][j];
                    }
                }
                ans = max(ans, hor[i][j]);
                ans = max(ans, ver[i][j]);
                ans = max(ans, diagp[i][j]);
                ans = max(ans, diago[i][j]);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

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

string field[255];

void rotate(int n){
	string tmp[255];
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			tmp[i][j] = field[n - j - 1][i];
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++) field[i][j] = tmp[i][j];
	}
}

int main(){
	int n;
	while(cin >> n,n){
		int ma = 0;
		for(int i = 0;i < n;i++) cin >> field[i];
		for(int i = 0;i < n;i++){
			int cnt = 0;
			for(int j = 0;j < n;j++){
				if(field[i][j] == '1') {
					cnt++;
					ma = max(ma,cnt);
				}else cnt = 0;
			}
			cnt = 0;
			for(int j = 0;j < n;j++){
				if(field[j][i] == '1') {
					cnt++;
					ma = max(ma,cnt);
				}else cnt = 0;
			}
		}
		for(int j = 0;j < 2;j++){
			if(j) rotate(n);
			for(int i = 0;i < 2 * n - 1;i++){
				int cnt = 0;
				for(int j = 0;j < n;j++){
					if(i - j >= n || i - j < 0) continue;
					if(field[j][i - j] == '1'){
							cnt++;
						ma = max(ma,cnt);
					}else cnt = 0;
				}
			}
		}
		cout << ma << endl;
	}
	return 0;
}

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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

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

    int ans = 0;
    vector<int> sum(6, 0);
    for (int i = 0; i < n; ++i) {
      // hor, ver
      for (int j = 0; j < n; ++j) {
	sum[0] += mass[i][j] - '0';
	sum[1] += mass[j][i] - '0';
      }
 
      // diag
      for (int j = 0; i+j < n; ++j) {
	sum[2] += mass[i+j][j] - '0';
	sum[3] += mass[n-1-i-j][j] - '0';
	sum[4] += mass[n-1-i-j][n-1-j] - '0';
	sum[5] += mass[i+j][n-1-j] - '0';
      }

      for (unsigned int j = 0; j < sum.size(); ++j) {
	ans = max(ans, sum[j]);
	sum[j] = 0;
      }
    }

    cout << ans << endl;
  }
  return 0;
}

C++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		char G[257][257];
		for(int i=0; i<=n+1; i++){
			for(int j=0; j<=n+1; j++){
				G[i][j] = '0';
			}
		}

		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				cin >> G[i][j];
			}
		}

		int DP_max = 0;

		int DP[257][257][4];
		for(int i=0; i<=n+1; i++){
			for(int j=0; j<=n+1; j++){
				for(int k=0; k<4; k++){
					DP[i][j][k] = 0;
				}
			}
		}

		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(G[i][j]=='0')
					continue;

				DP[i][j][0] = DP[i-1][j][0]+1;
				DP[i][j][1] = DP[i][j-1][1]+1;
				DP[i][j][2] = DP[i-1][j-1][2]+1;
				DP[i][j][3] = DP[i-1][j+1][3]+1;

				for(int k=0; k<4; k++){
					if(DP[i][j][k]>DP_max){
						DP_max = DP[i][j][k];
					}
				}
			}
		}

		cout << DP_max << '\n';
	}

	return 0;
}