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<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s[255];
int n;

int solve(bool x){
  int i, j, r, res = 0;
  if(x){
    rep(i, n)for(j = 0;j < n;){
      if(s[i][j] == '0'){ ++j; continue; }
      for(r = j + 1;r < n;++r)if(s[i][r] == '0')break;
      res = max(res, r - j);
      j = r;
    }
  }else{
    rep(i, n){
      for(j = 0;j < n - i;){
        if(s[j][j + i] == '0'){ ++j; continue; }
        for(r = j + 1;r + i < n;++r)if(s[r][r + i] == '0')break;
        res = max(res, r - j);
        j = r;
      }
      for(j = 0;j < n - i;){
        if(s[j + i][j] == '0'){ ++j; continue; }
        for(r = j + 1;r + i < n;++r)if(s[r + i][r] == '0')break;
        res = max(res, r - j);
        j = r;
      }
    }
  }
  return res;
}
void pr(void){
  int i;
  kabe;
  rep(i, n)cout << s[i] << endl;
  return;
}
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    scanf("%d", &n);
    if(!n)break;

    rep(i, n)cin >> s[i];

    int res = 0;
    res = solve(1);
    rep(i, n)rep(j, i)swap(s[i][j], s[j][i]);
    res = max(res, solve(1));
    rep(i, n)rep(j, i)swap(s[i][j], s[j][i]);
    res = max(res, solve(0));
    rep(i, n)rep(j, n / 2)swap(s[i][j], s[i][n - j - 1]);
    res = max(res, solve(0));
    pri(res);

//*/

//*/ break;
  }
  return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,j,c,max_c;
	while(scanf("%d",&n),n)
	{
		const int OFFSET = 256;
		char a[OFFSET*2][OFFSET*3] = {0};
		for(i=0;i<n;++i)
			scanf("%s",&a[i+OFFSET][OFFSET]);
		max_c = c =0;
		for(j=OFFSET;j<OFFSET*2;++j)
			for(c=0,i=OFFSET;i<OFFSET*2;++i)
				(a[i][j]=='1') ? max_c=max(++c,max_c): c=0;
		for(i=OFFSET;i<OFFSET*2;++i)
			for(c=0,j=OFFSET;j<OFFSET*2;++j)
				(a[i][j]=='1') ? max_c=max(++c,max_c): c=0;
		for(i=0; i<OFFSET*2; ++i)
			for(c=0,j=0; j<OFFSET*3 && i+j<=OFFSET*2; ++j)
				(a[i+j][j]=='1') ? max_c=max(++c,max_c): c=0;
		for(j=0; j<OFFSET*3; ++j)
			for(c=0,i=0;i<OFFSET*2; ++i)
			{
				if( j-i>=0 && j-i<OFFSET*2)
					(a[i][j-i]=='1') ? max_c=max(++c,max_c): c=0;
			}
		printf("%d\n",max_c);
	}
	return 0;
}

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)
	{
		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>
#include <algorithm>
#include <memory.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
char field[255][255];

int main(){
  int n;
  while(cin >> n && n){
    rep(i, n)rep(j, n) cin >> field[i][j];
    int res = 0;
    int cnt = 0;
    // yoko
    rep(i, n){
      cnt = 0;
      rep(j, n){
	if(field[i][j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    //tate
    rep(i, n){
      cnt = 0;
      rep(j, n){
	if(field[j][i] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    
    rep(i, n){
      cnt = 0;
      rep(j, i+1){
	if(field[i-j][j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    //naname
    rep(i, n){
      cnt = 0;
      rep(j, n-i){
	if(field[n-j-1][i+j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    //naname  
    rep(i, n){
      cnt = 0;
      rep(j, n - i){
	if(field[i+j][j] == '1') cnt++;
	else cnt = 0;
      }
      res = max(res, cnt);
    }
    rep(i, n){
      cnt = 0;
      rep(j, n - i){
	if(field[j][i+j] == '1') cnt++;
	else cnt = 0;
      }
      res = max(res, cnt);
    }
    cout << res << endl;
  }
  return 0;
}