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>
using namespace std;

int n;
char mat[255][255];
// vertical
int v[255][255];
// horizontal
int h[255][255];
// right-down diagonally
int rd[255][255];
// left-down diagonally
int ld[255][255];

int solve(){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            v[i][j] = h[i][j] = rd[i][j] = ld[i][j] = 0;
        }
    }

    if(mat[0][0]=='1')  v[0][0] = h[0][0] = rd[0][0] = ld[0][0] = 1;

    for(int j = 1; j < n; j++){
        if(mat[0][j]=='1'){
            h[0][j] = h[0][j-1]+1;
            v[0][j] = rd[0][j] = ld[0][j] = 1;
        }  
    }

    for(int i = 1; i < n; i++){
        for(int j = 0; j < n; j++){
            if(mat[i][j]=='1'){
                if(j != 0)      h[i][j] = h[i][j-1]+1;    
                else            h[i][j] = 1;
                v[i][j] = v[i-1][j]+1;
                if(j != n-1)    ld[i][j] = ld[i-1][j+1]+1;
                else            ld[i][j] = 1;
                if(j != 0)      rd[i][j] = rd[i-1][j-1]+1;
                else            rd[i][j] = 1;
            }
        }
    }

    int ret = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            ret = max(ret, max(max(max(h[i][j], v[i][j]), rd[i][j]),ld[i][j]));
        }
    }

    return ret;
}

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

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

        cout << solve() << endl;
    }


    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define s second
#define f first
int dx[]={1,0,1,-1};
int dy[]={0,1,1,1};
int main(){
  int n;
  while(cin>>n,n){
    string s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    pair<pair<int,int>,pair<int,int> > a[n][n];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
    a[i][j].f.f=a[i][j].f.s=a[i][j].s.f=a[i][j].s.s=s[i][j]-'0';    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
    for(int k=0;k<4;k++){
      int x=j+dx[k],y=i+dy[k];
      if(x>=0&&y>=0&&y<n&&x<n){
        if(k==0&&a[y][x])a[y][x].f.f+=a[i][j].f.f;
        if(k==1&&a[y][x])a[y][x].f.s+=a[i][j].f.s;
        if(k==2&&a[y][x])a[y][x].s.f+=a[i][j].s.f;
        if(k==3&&a[y][x])a[y][x].s.s+=a[i][j].s.s;
      }
    }
    int res=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
    res=max(res,a[i][j].f.f);
    res=max(res,a[i][j].f.s);
    res=max(res,a[i][j].s.f);
    res=max(res,a[i][j].s.s);
      }
    cout<<res<<endl;
  }
}

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

int main() {
    int n;
    char D;

    while (cin >> n, n) {
        int h, v[2][257] = {0}, rd[2][257] = {0}, ld[2][257] = {0};
        int longest = 0;
        for (int i = 1; i <= n; i++) {
            int p = (i-1)&1, c = i&1;
            h = 0;
            for (int j = 1; j <= n; j++) {
                cin >> D;
                if (D == '1') {
                    h++;
                    if (longest < h) longest = h;
                    v[c][j] = v[p][j] + 1;
                    if (longest < v[c][j]) longest = v[c][j];
                    rd[c][j] = rd[p][j-1] + 1;
                    if (longest < rd[c][j]) longest = rd[c][j];
                    ld[c][j] = ld[p][j+1] + 1;
                    if (longest < ld[c][j]) longest = ld[c][j];
                }
                else {
                    h = 0;
                    v[c][j] = 0;
                    rd[c][j] = 0;
                    ld[c][j] = 0;
                }
            }
        }
        cout << longest << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  while(cin >> n) {
    if(!n) return 0;
    string g[n] = {};

    rep(i, 0, n) {
      cin >> g[i];
    }
    int ma = 0;

    rep(i, 0, n) {
      int s = 0, ss = 0;
      rep(j, 0, n) if(g[i][j] == '1') s++;
      rep(j, 0, n) if(g[j][i] == '1') ss++;
      ma = max(ma, max(s, ss));
    }

    rep(i, 0, n) {
      int x = i, y = 0;
      int s = 0, ss = 0;
      while(1) {
        if(g[x][y] == '1') s++;
        x += 1, y += 1;
        if(x == n || y == n) break;
      }
      x = i, y = 0;
      while(1) {
        if(g[x][y] == '1') ss++;
        x -= 1, y += 1;
        if(x == -1 || y == n) break;
      }
      ma = max(ma, max(s, ss));
    }


    rep(i, 0, n) {
      int x = i, y = n - 1;
      int s = 0, ss = 0;
      while(1) {
        if(g[x][y] == '1') s++;
        x += 1, y -= 1;
        if(x == n || y == -1) break;
      }
      x = i, y = n - 1;
      while(1) {
        if(g[x][y] == '1') ss++;
        x -= 1, y -= 1;
        if(x == -1 || y == -1) break;
      }
      ma = max(ma, max(s, ss));
    }


    rep(i, 0, n) {
      int x = 0, y = i;
      int s = 0, ss = 0;
      while(1) {
        if(g[x][y] == '1') s++;
        x += 1, y += 1;
        if(x == n || y == n) break;
      }
      x = 0, y = i;
      while(1) {
        if(g[x][y] == '1') ss++;
        x += 1, y -= 1;
        if(x == n || y == -1) break;
      }
      ma = max(ma, max(s, ss));
    }


    rep(i, 0, n) {
      int x = n - 1, y = i;
      int s = 0, ss = 0;
      while(1) {
        if(g[x][y] == '1') s++;
        x -= 1, y += 1;
        if(x == -1 || y == n) break;
      }
      x = n - 1, y = i;
      while(1) {
        if(g[x][y] == '1') ss++;
        x -= 1, y -= 1;
        if(x == 0 || y == 0) break;
      }
      ma = max(ma, max(s, ss));
    }

    cout << ma << endl;
  }
}