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++: // 2011/08/25 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 max = 0;
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(G[i][j]=='0')
					continue;

				int cnt = 1;
				int I = i;
				int J = j;
				while(G[I][J-1]=='1'){
					cnt++;
					J--;
				}
				I = i;
				J = j;
				while(G[I][J+1]=='1'){
					cnt++;
					J++;
				}
				if(max<cnt)
					max = cnt;


				cnt = 1;
				I = i;
				J = j;
				while(G[I-1][J]=='1'){
					cnt++;
					I--;
				}
				I = i;
				J = j;
				while(G[I+1][J]=='1'){
					cnt++;
					I++;
				}
				if(max<cnt)
					max = cnt;

				cnt = 1;
				I = i;
				J = j;
				while(G[I-1][J-1]=='1'){
					cnt++;
					I--;
					J--;
				}
				I = i;
				J = j;
				while(G[I+1][J+1]=='1'){
					cnt++;
					I++;
					J++;
				}
				if(max<cnt)
					max = cnt;

				cnt = 1;
				I = i;
				J = j;
				while(G[I-1][J+1]=='1'){
					cnt++;
					I--;
					J++;
				}
				I = i;
				J = j;
				while(G[I+1][J-1]=='1'){
					cnt++;
					I++;
					J--;
				}
				if(max<cnt)
					max = cnt;
			}
		}

		cout << max << endl;
	}

	return 0;
}

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

const int MAX_N = 255;
int n;
char grid[MAX_N][MAX_N];
int dp[MAX_N][MAX_N][4];

int main()
{
    while(cin >> n && n) {
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                cin >> grid[i][j];
        
        memset(dp, 0, sizeof(dp));
        for(int j = 0; j < n; j++) 
            for(int k = 0; k < 4; k++) 
                dp[0][j][k] = grid[0][j] - '0';

        int ans = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(grid[i][j] == '0') {
                    for(int k = 0; k < 4; k++)
                        dp[i][j][k] = 0;
                } else {
                    dp[i][j][0] = (j) ? dp[i-1][j-1][0] + 1 : 1;
                    dp[i][j][1] = dp[i-1][j][1] + 1;
                    dp[i][j][2] = (j != n - 1) ? dp[i-1][j+1][2] + 1 : 1;
                    dp[i][j][3] = (j) ? dp[i][j-1][3] + 1 : 1;
                }
                for(int k = 0; k < 4; k++)
                    ans = max(ans, dp[i][j][k]);
            }
        }

        cout << ans << endl;
    }
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
char xy[225][225];
int main(){
	int i,j,k,n,max,cnt,x,y;
	int dx[4]={1,1,0,-1},dy[4]={0,-1,-1,-1};
	while(1){
		max=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) cin>>xy[i];
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(xy[i][j]=='1'){
					for(k=0;k<4;k++){
						cnt=1;
						y=i; x=j;
						while(1){
							y=y+dy[k]; x=x+dx[k];
							if(y>=n||x>=n||y<0||x<0||xy[y][x]!='1') break;
							cnt++;
						}
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n;
  while(cin>>n,n){
  vector<string> s(n);
    for(int i=0;i<n;++i)
      cin>>s[i];
    int max=0;
    for(int i=0;i<n;++i){
      char bf1='1',bf2='1';
      int cnt1=0,cnt2=0;
      for(int j=0;j<n;++j){
        if(s[i][j]=='1'){
          ++cnt1;
          if(max<cnt1)max=cnt1;
        }else cnt1=0;
        if(s[j][i]=='1'){
          ++cnt2;
          if(max<cnt2)max=cnt2;
        }else cnt2=0;
        bf1=s[i][j];
        bf2=s[j][i];
      }
    }
    for(int i=-n+1;i<n;++i){
      char bf='1';
      int cnt=0;
      for(int j=0;j<n;++j){
        if(n<=i+j||i+j<0)continue;
        if(s[i+j][j]=='1'){
          ++cnt;
          if(max<cnt)max=cnt;
        }else cnt=0;
      }
    }
    for(int i=0;i<2*n;++i){
      char bf='1';
      int cnt=0;
      for(int j=0;j<n;++j){
        if(n<=i-j||i-j<0)continue;
        if(s[i-j][j]=='1'){
          ++cnt;
          if(max<cnt)max=cnt;
        }else cnt=0;
      }
    }
    cout<<max<<endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

const int MAX = 260;

char data[MAX][MAX];
int num[4][MAX][MAX];
int in;

int solve(){
  for(int i = 1; i <= in; i++){
    for(int j = 1; j <= in; j++){
      if(data[i][j] == '1'){
	num[0][i][j] = num[0][i-1][j]+1;
	num[1][i][j] = num[1][i][j-1]+1;
	num[2][i][j] = num[2][i-1][j-1]+1;
	num[3][i][j] = num[3][i-1][j+1]+1;
      }
    }
  }
  int m = 0;
  for(int i = 0; i < 4; i++)
    for(int j = 1; j <= in; j++)
      for(int k = 1; k <= in; k++) m = max(m,num[i][j][k]);
  return m;
}

int main(){

  while(cin >> in && in){
    for(int i = 1; i <= in; i++){
      for(int j = 1; j <= in; j++){
	cin >> data[i][j];
	num[0][i][j] = num[1][i][j] = num[2][i][j] = num[3][i][j] = 0;
      }
    }
    cout << solve() << endl;
  }
  return 0;
}