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>
#include<algorithm>
#include<numeric>
#include<iterator>
#include<vector>

using namespace std;
typedef unsigned int val;

int tate(char mass[260][260],int n)
{
	int count=0,a=0,b=0,ans=-1;
	
	while(1)
	{

		if(b==n)break;
		
		if(mass[a][b]=='0' || a==n)
		{ 
			
			if(ans<count) ans=count;

			a=0;b++;count=0;continue; 

		}
		
		a++;count++;

	}
	return ans;
}

int yoko(char mass[260][260],int n)
{
	int count=0,a=0,b=0,ans=-1;
	
	while(1)
	{

		if(a==n)break;
		
		if(mass[a][b]=='0' || b==n)
		{ 
			
			if(ans<count) ans=count;

			b=0;a++;count=0;continue; 

		}
		
		b++;count++;

	}
	return ans;
}


int main() 
{
	int n;
	while(cin>>n && n)
	{
		char mass[260][260];
		
		for(int i=0; i<n; i++) cin >> mass[i];

		int ans=-1;

		if( ans < tate( mass, n ) ) ans = tate( mass, n );
		if( ans < yoko( mass, n ) ) ans = yoko( mass, n );
		
		for(int i=0; i<n ;i++)
		{
			for(int j=0; j<n; j++)
			{
				
				if(mass[i][j]=='1')
				{
					int a=i,b=j,count=0;
					while(1)
					{
						if( mass[a][b] == '0' || b<0 || n<a || b==-1) break;
						mass[a][b]='0';
						count++;
						a++;b--;
					}
					if(ans<count) ans=count;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 300;

int n,cnt;
int in[MAX_N][MAX_N];
int s[MAX_N][MAX_N];

void cp_in(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            s[i][j] = in[i][j];
        }
    }
}

void dfs(int y,int x,bool bit){
    if(bit){
        if(n <= x || n <= y) return;
        s[y][x] = 0;
        cnt++;
        int nx = x + 1;
        int ny = y + 1;
    
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1){
            dfs(ny,nx,bit);
        }
    }
    else{
        if(x < 0 || n <= y) return;
        s[y][x] = 0;
        cnt++;
        int nx = x - 1;
        int ny = y + 1;
        
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1){
            dfs(ny,nx,bit);
        }
    }
}

int main(){
    char ch;
    while(cin >> n ,n){
        int a = 0,b = 0,c = 0,d = 0;
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cin >> ch;
                in[i][j] = ch - '0';
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            cnt = 0;
            for(int j = 0 ; j < n ; j++){
                if(in[i][j] == 1){
                    cnt++;
                    a = max(a,cnt);
                }
                else cnt = 0;
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            cnt = 0;
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(in[j][i] == 1){
                    cnt++;
                    b = max(b,cnt);
                }
                else cnt = 0;
            }
        }

        cp_in();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) dfs(i,j,1);
                c = max(c,cnt);
            }
        }
        
        cp_in();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) dfs(i,j,0);
                d = max(d,cnt);
            }
        }
        
        cout << max(max(a,b),max(c,d)) << endl;
    }
    
    return 0;
}

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

int grid[255][255];

int main() {
    int n;
    while (cin >> n, n) {
        char c;
        for (int i=0; i<n; ++i) {
            for (int j=0; j<n; ++j) {
                cin >> c;
                grid[i][j] = c - '0';
            }
        }
        int x, y, cnt, res = 0;
        for (int i=0; i<n; ++i) {
            // right
            cnt = 0, y = i, x = 0;
            while (x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ x;
            }
            // down
            cnt = 0, y = 0, x = i;
            while (y < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y;
            }
            // right down
            cnt = 0, y = i, x = 0;
            while (y < n && x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, ++ x;
            }
            cnt = 0, y = 0, x = i;
            while (y < n && x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, ++ x;
            }
            // left down
            cnt = 0, y = i, x = n-1;
            while (y < n && 0 <= x) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, -- x;
            }
            cnt = 0, y = 0, x = i;
            while (y < n && 0 <= x) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, -- x;
            }
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef pair<int, int> Pii;
typedef vector<int> Vi;
const int INF = (1<<25);
const int dx[]={1,0,1,-1}, dy[]={0,1,1,1};

int main() {
  int n;
  while(cin>> n, n) {
    char grid[256][256];
    int ans = 0;
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	cin>> grid[i][j];
      }
    }

    for(int y=0; y<n; y++) {
      for(int x=0; x<n; x++) {
	if(grid[y][x] == '1') {
	  for(int i=0; i<4; i++) {
	    int nx=x+dx[i], ny=y+dy[i];
	    int cnt = 1;
	    while(nx >= 0 && ny >= 0 && nx < n && ny < n && grid[ny][nx] == '1') {
	      nx += dx[i]; ny += dy[i];
	      cnt++;
	    }
	    ans = max(ans, cnt);
	  }
	}
      }
    }

    cout<< ans<< endl;
  }
}