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 <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int dp[4][300][300] = {};
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < 4; k++) {
          dp[k][i][j] = s[j] == '1';
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (dp[0][i][j] == 0) continue;
        if (i > 0) dp[0][i][j] += dp[0][i - 1][j];
        if (j > 0) dp[1][i][j] += dp[1][i][j - 1];
        if (i > 0 && j > 0) dp[2][i][j] += dp[2][i - 1][j - 1];
        if (i > 0 && j + 1 < n) dp[3][i][j] += dp[3][i - 1][j + 1];
        ans = max(ans, dp[0][i][j]);
        ans = max(ans, dp[1][i][j]);
        ans = max(ans, dp[2][i][j]);
        ans = max(ans, dp[3][i][j]);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define CK(n, a, b) (a <= n && n < b)

int main() {
  int N;
  
  while(cin >> N && N) {
    vector<string> G(N);
    for(int i=0; i<N; i++) {
      cin >> G[i];
    }
    
    int grid[N][N];
    for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
	grid[i][j] = G[i][j] - '0';
      }
    }
    
    int ans = 0;
    
    for(int i=0; i<N; i++) {
      int cnt = 0;
      for(int j=0; j<N; j++) {
	if(!grid[i][j]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }
    
    for(int j=0; j<N; j++) {
      int cnt = 0;
      for(int i=0; i<N; i++) {
	if(!grid[i][j]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }
    
    // right down
    for(int i=0; i<N; i++) {
      int sx = 0, sy = i;
      int cnt = 0;
      for(int k=0; k<N; k++) {
	if(!CK(sy+k, 0, N) || !CK(sx+k, 0, N)) break;
	if(!grid[sy+k][sx+k]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }
      
    for(int i=0; i<N; i++) {
      int sx = i, sy = 0;
      int cnt = 0;
      for(int k=0; k<N; k++) {
	if(!CK(sy+k, 0, N) || !CK(sx-k, 0, N)) break;
	if(!grid[sy+k][sx-k]) cnt = 0;
	else cnt ++;
	ans = max(ans, cnt);
      }
    }
      
    cout << ans << endl;
  }
  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int underR(int y,int x);
int underL(int y,int x);
char maps[260][260];
int check[260][260];
int n;
int gyomax[260]={0};
int gyoans=0;
int gyonum[260]={0};
int retumax[260]={0};
int retuans=0;
int retunum[260]={0};
int ans=0;
main(){
  while(1){
    ans=0;
    memset(check,0,sizeof(check));
    memset(gyomax,0,sizeof(gyomax));
    memset(retumax,0,sizeof(retumax));
    gyoans=0;
    retuans=0;
    memset(gyonum,0,sizeof(gyonum));
    memset(retunum,0,sizeof(retunum));
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>maps[i][j];
	if(maps[i][j]=='1'){
	  gyonum[i]++;
	  gyomax[i]=max(gyomax[i],gyonum[i]);
	  retunum[j]++;
	  retumax[j]=max(retumax[j],retunum[j]);
	}
	else{
	  gyonum[i]=0;
	  retunum[j]=0;
	}
      }
    }
    /*
    for(int i=0;i<n;i++){
      cout<<gyomax[i]<<" ";
    }
    cout<<endl;
    for(int i=0;i<n;i++){
      cout<<retumax[i]<<" ";
    }
    cout<<endl;
    */
    gyoans=*(max_element(gyomax,gyomax+n));
    retuans=*(max_element(retumax,retumax+n));
    //cout<<gyoans<<" "<<retuans<<endl;
    ans=max(gyoans,retuans);
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(maps[i][j]=='1'&&check[i][j]==0){
	  check[i][j]=1;
	  ans=max(ans,underR(i,j));
	  ans=max(ans,underL(i,j));
	}
      }
    }
    cout<<ans<<endl;
  }
}
int underR(int y,int x){
  int num=0;
  if(maps[y][x]=='0'){
    return 0;
  }
  else{
    num++;
    if(y+1<n&&x+1<n){
      num+=underR(y+1,x+1);
    }
    return num;
  }
}
int underL(int y,int x){
  int num=0;
  if(maps[y][x]=='0'){
    return 0;
  }
  else{
    num++;
    if(y+1<n&&x-1>=0){
      num+=underL(y+1,x-1);
    }
    return num;
  }
}

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

int n;

// arr[y][x]
int arr[260][260];

/*
0: ツ湘」
1: ツ債カ
2: ツ債カツ湘」
3: ツ右ツ湘」
*/
int dp[4][260][260];


int main() {
	for(;;) {
		scanf(" %d", &n);
		if(!n) break;
		for(int y = 0; y < n; y++) {
			char line[260];
			scanf(" %s", line);
			for(int x = 0; x < n; x++) {
				arr[y][x] = line[x] - '0';
			}
		}
		memset(dp, 0, sizeof dp);
		for(int y = 0; y < n; y++) {
			for(int x = 0; x < n; x++) {
				if(arr[y][x] == 1) {
					for(int i = 0; i < 4; i++) {
						dp[i][y][x] = 1;
					}
					if(y >= 1) {
						dp[0][y][x] += dp[0][y - 1][x];
					}
					if(x >= 1) {
						dp[1][y][x] += dp[1][y][x - 1];
					}
					if(x >= 1 && y >= 1) {
						dp[2][y][x] += dp[2][y - 1][x - 1];
					}
					if(y >= 1 && x < n - 1) {
						dp[3][y][x] += dp[3][y - 1][x + 1];
					}
				}
			}
		}
		int maxv = 0;
		for(int y = 0; y < n; y++) {
			for(int x = 0; x < n; x++) {
				for(int k = 0; k < 4; k++) {
					maxv = max(maxv, dp[k][y][x]);
				}
			}
		}
		printf("%d\n", maxv);
	}
	return 0;
}