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 <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,(n))
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n, m)
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;


int main(){
	int n;
	while(cin>>n&&n){
		vector<string> s(n);
		rep(i, n) cin>>s[i];
		int ans = 0;
		for(int i = 0; i < n; i++){
			vi v(n, 0);
			v[0] = s[i][0]-'0';
			for(int j = 1; j < n; j++){
				if(s[i][j]=='1'){
					v[j]=v[j-1]+1;
					ans = max(ans, v[j]);
				}
			}
			vi u(n, 0);
			u[0] = s[0][i]-'0';
			for(int j = 1; j < n; j++){
				if(s[j][i]=='1'){
					u[j]=u[j-1]+1;
					ans = max(ans, u[j]);
				}
			}
			vi a(n, 0);
			a[0] = s[0][i]-'0';
			for(int j = 1; i-j>=0; j++){
				if(s[j][i-j]=='1'){
					a[j]=a[j-1]+1;
					ans = max(ans, a[j]);
				}
			}
			vi b(n, 0);
			b[0] = s[i][n-1] - '0';
			for(int j  =1; i+j < n; j++){
				if(s[i+j][n-1-j]=='1'){
					b[j] = b[j-1]+1;
					ans = max(ans, b[j]);
				}
			}
			vi c(n, 0);
			c[0] = s[0][i]-'0';
			for(int j  =1; i+j < n; j++){
				if(s[j][i+j] == '1'){
					c[j]=c[j-1]+1;
					ans=max(ans, c[j]);
				}
			}
			vi d(n, 0);
			d[0] = s[i][0]-'0';
			for(int j  =1; i+j <n; j++){
				if(s[i+j][j] == '1'){
					d[j] = d[j-1]+1;
					ans = max(ans, d[j]);
				}
			}
		}
		cout<<ans<<endl;


	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


bool line(vector<string> v, int len)
{
	int n = v.size();
	int x = len - 1, y = 0;
	
	// ツ右ツ湘」ツつゥツづァツ湘」ツ板シツ閉ェ
	rep(i, len)
	{
		if(v[y][x] == '0') break;
		else if(i + 1 == len) return true;
		x--;
		y++;
	}
	
	// ツ右ツ湘」ツつゥツづァツ可コツ板シツ閉ェ
	x = n - 1;
	y = n - len;
	rep(i, len)
	{
		if(v[y][x] == '0') break;
		else if(i + 1 == len) return true;
		x--;
		y++;
	}
	
	// ツ債カツ湘」ツつゥツづァツ湘」ツ板シツ閉ェ
	x = n - len;
	y = 0;
	rep(i, len)
	{
		if(v[y][x] == '0') break;
		else if(i + 1 == len) return true;
		x++;
		y++;
	}
	
	// ツ債カツ湘」ツつゥツづァツ可コツ板シツ閉ェ
	x = 0;
	y = n - len;
	rep(i, len)
	{
		if(v[y][x] == '0') break;
		else if(i + 1 == len) return true;
		x++;
		y++;
	}
	
	return false;	
}
int main()
{
    int n;
	while(cin >> n && n)
	{
		vector<string> v(n);
		rep(i, n) cin >> v[i];
		
		rep(i, n)
		{
			if(count(ALL(v[i]), '0') == 0)
			{
				cout << n << endl;
				goto ng;
			}
			
			rep(j, n)
			{
				if(v[j][i] == '0') break;
				else if(j + 1 == n)
				{
					cout << n << endl;
					goto ng;
				}
			}
		}
		
		for(int i = n; 0 < i; i--) if(line(v, i)) 
		{
			cout << i << endl;
			goto ng;
		}
		
		cout  << 0 << endl;
			
		ng:;
	}
}

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

char A[300][300];

int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < n ; i++)
			for(int j = 0 ; j < n ; j++)
				cin >> A[i][j];
		int ans = 0;
		for(int i = 0 ; i < n ; i++){
			int p = 0;
			for(int j = 0 ; j < n ; j++){
				p += A[i][j] - '0';
			}
			if( p == n ) ans = max(p,ans);
		}
		for(int i = 0 ; i < n ; i++){
			int p = 0;
			for(int j = 0 ; j < n ; j++){
				p += A[j][i] - '0';
			}
			if( p == n ) ans = max(p,ans);
		}
		for(int i = 0 ; i <= n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j <= n ; j++){
				if( i+j >= n ) break;
				p += A[j][i+j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		for(int i = 0 ; i <= n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j <= n ; j++){
				if( i+j >= n ) break;
				p += A[i+j][j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		for(int i = 0 ; i <= n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j <= n ; j++){
				if( n-1-i-j < 0 ) break;
				p += A[j][n-1-i-j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		
		for(int i = 0 ; i <= n ; i++){
			int p = 0 , c = 0;
			for(int j = 0 ; j <= n ; j++){
				if( i+j >= n ) break;
				p += A[i+j][n-1-j] - '0';
				c++;
			}
			if( p == c ) ans = max(p,ans);
		}
		cout << ans << endl;
	}
}