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 <cstdio>
#include <vector>
#include <algorithm>
#include <string>

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<std::string> s(n);
  for (size_t i=0; i<n; ++i) {
    char buf[256];
    scanf("%s", buf);
    s[i] = buf;
  }

  size_t res=0;
  for (size_t i=0; i<n; ++i) {
    res = std::max<size_t>(res, std::count(s[i].begin(), s[i].end(), '1'));
  }

  for (size_t i=0; i<n; ++i) {
    size_t cur=0;
    for (size_t j=0; j<n; ++j)
      if (s[j][i] == '1') ++cur;

    res = std::max(res, cur);
  }

  auto diag=[](const std::vector<std::string> &s)->size_t {
    size_t res=0, n=s.size();
    for (size_t i=0; i<n; ++i) {
      size_t cur=0;
      for (size_t j=0; j<=i; ++j) {
        if (s[j][i-j] == '1') ++cur;
      }

      res = std::max(res, cur);
    }
    return res;
  };
  res = std::max(res, diag(s));

  std::reverse(s.begin(), s.end());
  res = std::max(res, diag(s));

  for (auto &si: s) std::reverse(si.begin(), si.end());
  res = std::max(res, diag(s));

  std::reverse(s.begin(), s.end());
  res = std::max(res, diag(s));

  printf("%zu\n", res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}

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){
				if(data[i][n-1+j]==0)sum = 0;
				sum+=data[i][n-1+j];
				ret = max(ret,sum);
			}
		}
		rep(i,n){
			sum = 0;
			rep(j,n){
				if(data[j][n-1+i]==0)sum = 0;
				sum+=data[j][n-1+i];
				ret = max(ret,sum);
			}
		}
		rep(i,2*n-1){
			sum = 0;
			rep(j,n){
				if(data[j][i+j]==0)sum = 0;
				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){
				if(data[j][i-j]==0)sum = 0;
				sum+=data[j][i-j];
				ret = max(ret,sum);
			}
		}
		cout << ret << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.grid2", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ) {
		stringstream ssn(str);
		ssn >> n;
		
		if (n == 0 ){
			break;
		} // end if

		vector <vector <int> > grid (n, vector <int> (n, 0 ) );
 
		int i,j,k;

		for (i = 0; i < n; ++i ){
			getline (cin, str );
			for (j = 0; j < n; ++j ){
				grid[i][j] = str[j] - '0';
			} // end for
		} // end for

		int res = 0;
		int sum = 0;

		for (i = 0; i < n; ++i ){
			sum = 0;
			for (j = 0; j < n; ++j ){
				sum += grid[i][j];
			} // end for
			res = max (res, sum );
		} // end for

		for (j = 0; j < n; ++j){
			sum = 0;
			for (i = 0; i < n; ++i ){
				sum += grid[i][j];
			} // end for
			res = max (res, sum );
		} // end for

		for (k = -n + 1; k < n; ++k){
			sum = 0;
			for (i = 0; i < n; ++i ){
				for (j = 0; j < n; ++j ){
					if (i - j == k ){
						sum += grid[i][j];
					} // end if
				} // end for
			} // end for
			res = max (res, sum );
		} // end for

		for (k = 0; k <= 2*(n-1); ++k){
			sum = 0;
			for (i = 0; i < n; ++i){
				for (j = 0; j < n; ++j){	
					if (i + j == k ){
						sum += grid[i][j];
					} // end if
				} // end for
			} // end for
			res = max (res, sum );
		} // end for	

		cout << res << endl;	
	} // end loop

		
	return 0;
}

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

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

const int SIZE = 255;

int main()
{
	bool table[ SIZE ][ SIZE * 3 ];

	int n;
	while( cin >> n && n ){
		memset( table, 0, sizeof(table) );
		for( int i = 0; i < n; ++i ){
			for( int j = 0; j < n; ++j ){
				char c;
				cin >> c;
				table[ i ][ j + SIZE ] = c == '1' ? true : false;
			}
		}
		int maxLength = 0;
		for( int i = 0; i < n; ++i ){
			int col = 0, row = 0;
			for( int j = 0; j < n; ++j ){
				if( table[ i ][ j + SIZE ] ){
					++col;
					if( maxLength < col ) maxLength = col;
				}else{
					col = 0;
				}
				if( table[ j ][ i + SIZE ] ){
					++row;
					if( maxLength < row ) maxLength = row;
				}else{
					row = 0;
				}
			}
		}
		for( int i = 0; i < n; ++i ){
			int diaL = 0, diaR = 0;
			for( int j = 0; j < n; ++j ){
				if( table[ j ][ i + SIZE - j ] ){
					++diaL;
					if( maxLength < diaL ) maxLength = diaL;
				}else{
					diaL = 0;
				}
				if( table[ j ][ n - 1 - i + j + SIZE ] ){
					++diaR;
					if( maxLength < diaR ) maxLength = diaR;
				}else{
					diaR = 0;
				}
			}
		}
		cout << maxLength << endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,n,max,cnt,x,y;
	int dx[4]={1,1,0,-1},dy[4]={0,-1,-1,-1};
	char xy[225][225];
	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++;
						}
//						printf("cnt=%d\n",cnt);
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}