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++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#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 <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


int main(){
    int data[255][255];
    int rec[255][255];
    char buf[512];
    int n;
    int i, j, k;
    int ans;
    int dx[4] = {-1, 0, -1, 1};
    int dy[4] = {0, -1, -1, -1};
     
    while (scanf("%d", &n), n){
        for (i = 0; i < n; i++){
            scanf("%s", buf);
            for (j = 0; j < n; j++){
                data[i][j] = buf[j] - '0';
            }
        }
         
        ans = 0;
        for (i = 0; i < 4; i++){
            memset(rec, 0, sizeof(rec));
            for (j = 0; j < n; j++){
                for (k = 0; k < n; k++){
                    rec[j][k] = data[j][k];
                    if (0 <= k + dx[i] && k + dx[i] < n &&
                            0 <= j + dy[i] && j + dy[i] < n && rec[j][k] == 1){
                        rec[j][k] += rec[j + dy[i]][k + dx[i]];
                    }
                    ans = ans > rec[j][k] ? ans : rec[j][k];
                }
            }
        }
         
        printf("%d\n", ans);
    }
	
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
 
#define M 255
 
int main() {
  int n, c, t, ans;
  char buf[M+2];
  char a[M][M];
  while (1) {
    scanf("%d\n", &n);
    if (!n) break;
 
    for (int i=0; i<n; i++) {
      fgets(buf, sizeof(buf), stdin);
      for (int j=0; j<n; j++) {
        a[i][j] = (buf[j]=='0') ? 0 : 1;
      }
    }
 
    ans = 0;
    for (int i=0; i<n; i++) {
      c = 0;
      for (int j=0; j<n; j++) {
        if (a[i][j]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    for (int i=0; i<n; i++) {
      c = 0;
      for (int j=0; j<n; j++) {
        if (a[j][i]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    for (int s=0; s<2*n-1; s++) {
      c = 0;
      for (int i=0; i<n; i++) {
        t = s-i;
        if (t>=0 && t<n && a[i][t]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    for (int d=-n+1; d<n; d++) {
      c = 0;
      for (int i=0; i<n; i++) {
        t = i+d;
        if (t>=0 && t<n && a[i][t]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n,ret,sum;
	while(cin >> n , n){
		ret = 0;
		vector< vector<char> > data(n,vector<char>(n+(n-1)*2,0));
		rep(i,n)rep(j,n){
			cin >> data[i][n-1+j];
			data[i][n-1+j]-='0';
		}
		rep(i,n){
			sum = 0;
			rep(j,n)sum+=data[i][n-1+j];
			ret = max(ret,sum);
		}
		rep(i,n){
			sum = 0;
			rep(j,n)sum+=data[j][n-1+i];
			ret = max(ret,sum);
		}
		rep(i,2*n-1){
			sum = 0;
			rep(j,n)sum+=data[j][i+j];
			ret = max(ret,sum);
		}	
		for(int i=n-1;i<n+(n-1)*2;i++){
			sum = 0;
			rep(j,n)sum+=data[j][i-j];
			ret = max(ret,sum);
		}
		cout << ret << endl;
	}
}

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

using namespace std;

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  Solver(int n) : n(n) {}
  void read_input(){
    for (int i = 0; i < n; i++){
      char buf[512];
      scanf("%s", buf);
      for (int j = 0; j < n; j++){
        grid[i][j] = buf[j] - '0';
      }
    }
  }
  int get_max(){
    int maxi = 0;
    int L = n - 1;
    for (int i = 0; i < n; i++){
      maxi = max(maxi, scan(0, i, 1, 0));
      maxi = max(maxi, scan(0, i, 1, 1));
      maxi = max(maxi, scan(0, i, 1,-1));
      maxi = max(maxi, scan(i, 0, 0, 1));
      maxi = max(maxi, scan(i, 0, 1, 1));
      maxi = max(maxi, scan(i, L, 1,-1));
    }
    return maxi;
  }
  int scan(int x, int y, int dx, int dy){
    int maxi = 0;
    int v = 0;
    while (0 <= x && x < n && 0 <= y && y < n){
      v = v * grid[y][x] + grid[y][x];
      maxi = max(maxi, v);
      x += dx;
      y += dy;
    }
    return maxi;
  }

  int grid[255][255];
  int n;
};

int main()
{
  int n;
  while (n = in()){
    Solver solver(n);
    solver.read_input();
    printf("%d\n", solver.get_max());
  }

  return 0;
}

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

string field[256];

void rotate(int n){
	string tmp[256];
	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 k = 0;k < 2;k++){
			if(k) 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;
}