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++: // 2013/11/15 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		char G[257][257];
		for(int y=1; y<=n; y++){
			for(int x=1; x<=n; x++){
				cin >> G[y][x];
			}
		}

		int DP1[257][257];	// 上下
		int DP2[257][257];	// 左右
		int DP3[257][257];	// 対角線（左上）
		int DP4[257][257];	// 対角線（右上）
		for(int y=0; y<=n+1; y++){
			for(int x=0; x<=n+1; x++){
				DP1[y][x] = 0;
				DP2[y][x] = 0;
				DP3[y][x] = 0;
				DP4[y][x] = 0;
			}
		}

		int DP_max = 0;

		for(int y=1; y<=n; y++){
			for(int x=1; x<=n; x++){
				if(G[y][x]=='0')
					continue;

				DP1[y][x] = DP1[y-1][x  ]+1;
				DP2[y][x] = DP2[y  ][x-1]+1;
				DP3[y][x] = DP3[y-1][x-1]+1;
				DP4[y][x] = DP4[y-1][x+1]+1;

				DP_max = max(DP_max, max(max(DP1[y][x], DP2[y][x]), max(DP3[y][x], DP4[y][x])));
			}
		}

		cout << DP_max << endl;
	}

	return 0;
}

C++: #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string a[255];
int check(int x, int y, int dx, int dy) {
	int ret = 0;
	while(0 <= x && x < n && 0 <= y && y < n) {
		if(a[y][x] == '0') return ret;
		x += dx, y += dy, ret++;
	}
	return ret;
}
int main() {
	while(~scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) cin >> a[i];
		int ret = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				for(int k = -1; k <= 1; k++) {
					for(int l = -1; l <= 1; l++) {
						if(k != 0 || l != 0) {
							ret = max(ret, check(j, i, l, k));
						}
					}
				}
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int dp[300][300][4];
int main(){
	int n;
	int dx[]={0,-1,-1,-1};
	int dy[]={-1,-1,0,1};
	while(cin>>n,n){
		vector<string>in(n);
		rep(i,n)cin>>in[i];
		rep(i,n)rep(j,n+1)rep(k,4)dp[i][j][k]=0;
		rep(i,n)rep(j,n)rep(k,4)if(in[i][j]=='1'){
			if(i==0&&j==0)dp[i][j][k]=1;
			else if(i==0&&k||j==0&&k<2)dp[i][j][k]=1;
			else dp[i][j][k]=dp[i+dx[k]][j+dy[k]][k]+1;
		}else dp[i][j][k]=0;
		int out=0;
//		rep(i,n){rep(j,n)cout<<" "<<dp[i][j][0];cout<<endl;}
		rep(i,n)rep(j,n)rep(k,4)out=max(out,dp[i][j][k]);
		cout<<out<<endl;
	}
}

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

#define SIZE 255

char M[SIZE][SIZE];

int main() {
  int n, mx, cnt;
  
  while(cin>>n && n) {
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	cin >> M[i][j];
      }
    }

    mx = 0;
    // tate
    for(int i = 0; i < n; i++) {
      cnt = 0;
      for(int j = 0; j < n; j++) {
	if(M[i][j]-'0') { 
	  cnt++;
	  mx = max(mx, cnt);
	} else {
	  cnt = 0;
	}
      }
    }
    // yoko
    for(int i = 0; i < n; i++) {
      cnt = 0;
      for(int j = 0; j < n; j++) {
	if(M[j][i]-'0') { 
	  cnt++;
	  mx = max(mx, cnt);
	} else {
	  cnt = 0;
	}
      }
    }
    // migishita
    for(int j = n-1; j >= 0; j--) {
      cnt = 0;
      for(int i = 0; i < n-j; i++) {
	if(M[i+j][j]-'0') {
	  cnt++;
	  mx = max(mx, cnt);
	} else {
	  cnt = 0;
	}
      }
    }
    // hidarishita
    for(int i = n-1; i >= 0; i--) {
      cnt = 0;
      for(int j = n-1; j >= 0; j--) {
	if(M[i+j][j]-'0') { 
	  cnt++;
	  mx = max(mx, cnt);
	} else {
	  cnt = 0;
	}
      }
    }

    cout << mx << endl;
  }
  
  return 0;
}

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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<string> mass(n);
    for (int i = 0; i < n; ++i)
      cin >> mass[i];

    int ans = 0;
    for (int i = 0; i < n; ++i) {
      vector<int> sum(6, 0);
      // hor, ver
      for (int j = 0; j < n; ++j) {
	if (mass[i][j] == '1') {
	  ++sum[0];
	  ans = max(ans, sum[0]);
	} else {
	  sum[0] = 0;
	}

	if (mass[j][i] == '1') {
	  ++sum[1];
	  ans = max(ans, sum[1]);
	} else {
	  sum[1] = 0;
	}
      }
 
      // diag
      for (int j = 0; i+j < n; ++j) {
	if (mass[i+j][j] == '1') {
	  ++sum[2];
	  ans = max(ans, sum[2]);
	} else {
	  sum[2] = 0;
	}

	if (mass[n-1-i-j][j] == '1') {
	  ++sum[3];
	  ans = max(ans, sum[3]);
	} else {
	  sum[3] = 0;
	}

	if (mass[n-1-i-j][n-1-j] == '1') {
	  ++sum[4];
	  ans = max(ans, sum[4]);
	} else {
	  sum[4] = 0;
	}

	if (mass[i+j][n-1-j] == '1') {
	  ++sum[5];
	  ans = max(ans, sum[5]);
	} else {
	  sum[5] = 0;
	}
      }
    }

    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
bool data[255][255];    
int dp[4][255][255];

int check(int mode,int i,int j)
{
  if(dp[mode][i][j]!=-1)
    return dp[mode][i][j];
  if(!data[i][j])
    return 0;
  if(i<0 || i>=n ||
     j<0 || j>=n)
    return 0;
  if(mode==1)
    dp[mode][i][j]=check(1,i+1,j)+1;
  else if(mode==2)
    dp[mode][i][j]=check(2,i+1,j-1)+1;
  // else if(mode==3)
  //    dp[mode][i][j]=check(3,i+1,j+1)+1;
  
  return dp[mode][i][j];
}

int main()
{

  for(;cin>>n,n;)
    {

      memset(dp,-1,sizeof(dp));
      //<->0, up-down,1,hidarisita2,migisita3
      int ans=0;
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  {
	    char tmp;
	    cin>>tmp;
	    data[i][j]=(tmp=='1');
	    if(data[i][j])
	      {
		if(j==0)
		  dp[0][i][j]=1;
		else
		  dp[0][i][j]=dp[0][i][j-1]+1;
	      }
	    else
	      dp[0][i][j]=0;
	    ans=max(ans,dp[0][i][j]);	    
	  }
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  {
	    for(int k=1;k<3;k++)
	      ans=max(ans,check(k,i,j));
	  }
      cout<<ans<<endl;
    }
}