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>
using namespace std;

//----- 最大値を返す関数 -----//
int f_max(int , int , int);
//----- 最大値を返す関数のオーバーロード -----//
int f_max(int , int);



int main(void)
{
	//入力変数
	int n = 0;
	//マス配列
	char wh_str_masu[256][256] = {0};

	while (true)
	{
		cin >> n;

		//入力の終わり
		if (n == 0)
		{
			return 0;
		}

		//出力変数
		int ans = 0;

		//max変数
		int max_yoko = 0;
		int max_tate = 0;
		int max_migiagari = 0;
		int max_migisagari = 0;

		//マスの入力
		for (int i = 0; i < n; i++)
		{
			cin >> wh_str_masu[i];
		}

		for (int i = 0; i < n; i++)
		{
			//保存しながら見る変数
			int max_hozon_yoko = 0;
			int max_hozon_tate = 0;
			int max_hozon_migiagari = 0;
			int max_hozon_migisagari = 0;

			//連続していた数を記憶
			int renzoku_tate = 0;
			int renzoku_yoko = 0;
			int renzoku_migiagari = 0;
			int renzoku_migisagari = 0;

			for (int j = 0; j < n; j++)
			{
				//横
				if (wh_str_masu[i][j] == '1')
				{
					renzoku_yoko++;
				}
				//違う値なら大きいほうを格納
				else
				{
					//2数の最大値
					max_hozon_yoko = f_max(max_yoko , renzoku_yoko);
					//renzoku_yoko = 0;
				}
				//縦
				if (wh_str_masu[j][i] == '1')
				{
					renzoku_tate++;
				}
				else
				{
					//2数の最大値
					max_hozon_tate = f_max(max_tate , renzoku_tate);
					//renzoku_tate = 0;
				}
			}

			//右下
			for (int j = i + 1; j < n; j++)
			{
				if (wh_str_masu[j][j - 1] == '1')
				{
					renzoku_migisagari++;
				}
				else
				{
					max_hozon_migisagari = f_max(max_hozon_migisagari , renzoku_migisagari);
					//renzoku_migisagari = 0;
				}
			}
			//右上
			for (int j = 0; j <= i; j++)
			{
				if (wh_str_masu[i - j][j] == '1')
				{
					renzoku_migiagari++;
				}
				else
				{
					max_hozon_migiagari = f_max(max_hozon_migiagari , renzoku_migiagari);
					//renzoku_migiagari = 0;
				}
			}

			//大きかったらmaxに代入
			max_yoko = f_max(max_yoko , renzoku_yoko , max_hozon_yoko);
			max_tate = f_max(max_tate , renzoku_tate , max_hozon_tate);
			max_migiagari = f_max(max_migiagari , renzoku_migiagari , max_hozon_migiagari);
			max_migisagari = f_max(max_migisagari , renzoku_migisagari , max_hozon_migisagari);
		}

		//関数を利用し2段階で計算
		ans = f_max(max_yoko , max_tate , max_migiagari);
		ans = f_max(ans , max_migisagari);

		cout << ans << endl;
	}

	return 0;
}




//*****----- 最大値を返す関数 -----*****//

int f_max(int a , int b , int c)
{
	if (a > b)
	{
		if (a > c)
		{
			return a;
		}
		return c;
	}
	else
	{
		if (b > c)
		{
			return b;
		}
		return c;
	}
}




//*****----- 最大値を返す関数のオーバーロード -----*****//

int f_max(int a , int b)
{
	if (a > b)
	{
		return a;
	}
	return b;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  while(cin >> n) {
    if(!n) return 0;
    string g[n] = {};

    rep(i, 0, n) {
      cin >> g[i];
    }
    int ma = 0;

    rep(i, 0, n) {
      int rs = 0;
      int s = 0, ss = 0;
      rep(j, 0, n) {
        if(g[i][j] == '1') rs++;
        else {
          s = max(s, rs);
          rs = 0;
        }
        if(j == n - 1) s = max(s, rs);
      }
      rs = 0;
      rep(j, 0, n) {
        if(g[j][i] == '1') rs++;
        else {
          ss = max(ss, rs);
          rs = 0;
        }
        if(j == n - 1) ss = max(ss, rs);
      }
      ma = max(ma, max(s, ss));
    }

    rep(i, 0, n) {
      int x = i, y = 0;
      int s = 0, ss = 0;
      int rs = 0;
      while(1) {
        if(g[x][y] == '1') rs++;
        else {
          s = max(s, rs);
          rs = 0;
        }
        x += 1, y += 1;
        if(x == n || y == n) {
          s = max(s, rs);
          rs = 0;
          break;
        }
      }
      x = i, y = 0;
      while(1) {
        if(g[x][y] == '1') rs++;
        else {
          ss = max(ss, rs);
          rs = 0;
        }
        x -= 1, y += 1;
        if(x == -1 || y == n) {
          ss = max(ss, rs);
          rs = 0;
          break;
        }
      }
      ma = max(ma, max(s, ss));
    }


    rep(i, 0, n) {
      int x = i, y = n - 1;
      int s = 0, ss = 0;
      int rs = 0;
      
      while(1) {
        if(g[x][y] == '1') rs++;
        else {
          s = max(s, rs);
          rs = 0;
        }
        x += 1, y -= 1;
        if(x == n || y == -1) {
          s = max(s, rs);
          rs = 0;
          break;
        }
      }
      x = i, y = n - 1;
      while(1) {
        if(g[x][y] == '1') rs++;
        else {
          ss = max(ss, rs);
          rs = 0;
        }
        x -= 1, y -= 1;
        if(x == -1 || y == -1) {
          ss = max(ss, rs);
          rs = 0;
          break;
        }
      }
      ma = max(ma, max(s, ss));
    }


    rep(i, 0, n) {
      int x = 0, y = i;
      int s = 0, ss = 0;
      int rs = 0;

      while(1) {
        if(g[x][y] == '1') rs++;
        else {
          s = max(s, rs);
          rs = 0;
        }
        x += 1, y += 1;
        if(x == n || y == n) {
          s = max(s, rs);
          rs = 0;
          break;
        }
      }
      x = 0, y = i;
      while(1) {
        if(g[x][y] == '1') rs++;
        else {
          s = max(s, rs);
          rs = 0;
        }
        x += 1, y -= 1;
        if(x == n || y == -1) {
          s = max(s, rs);
          rs = 0;
          break;
        }
      }
      ma = max(ma, max(s, ss));
    }


    rep(i, 0, n) {
      int x = n - 1, y = i;
      int s = 0, ss = 0;
      int rs = 0;
      while(1) {
        if(g[x][y] == '1') rs++;
        else {
          s = max(s, rs);
          rs = 0;
        }
        x -= 1, y += 1;
        if(x == -1 || y == n) {
          s = max(s, rs);
          rs = 0;
          break;
        }
      }
      x = n - 1, y = i;
      while(1) {
        if(g[x][y] == '1') rs++;
        else {
          s = max(s, rs);
          rs = 0;
        }
        x -= 1, y -= 1;
        if(x == 0 || y == 0) {
          s = max(s, rs);
          rs = 0;
          break;
        }
      }
      ma = max(ma, max(s, ss));
    }

    cout << ma << endl;
  }
}