Problem:
Score : 400 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.

Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.

Snuke wants to maximize the number of squares lighted by the lamp.

You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is #, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is ., there is no obstacle on that square.

Find the maximum possible number of squares lighted by the lamp.

Constraints

1 \leq H \leq 2,000

1 \leq W \leq 2,000

S_i is a string of length W consisting of # and ..

. occurs at least once in one of the strings S_i (1 \leq i \leq H).

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the maximum possible number of squares lighted by the lamp.

Sample Input 1

4 6
#..#..
.....#
....#.
#.#...

Sample Output 1

8

If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.

Sample Input 2

8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#

Sample Output 2

13

Solution in C# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

		var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var H = (int)inputArray[0];
			var W = (int)inputArray[1];

			//光の情報を格納する
			var lumpInfo = new Dictionary<string, bool>();
			for (int i = 0; i < H; i++) {
				var rightinfo = retreiveStringArray()[0];
				for (int j = 0; j < W; j++) {
					var right = rightinfo[j] == '.' ? true : false;
					var position = i + "_" + j;
					lumpInfo.Add(position, right);
				}

			}
			//横方向に照らす数を記録する
			var yokoInfo = new Dictionary<string, int>();
			for (int i = 0; i < H; i++) {
				var righted = new HashSet<string>();
				for (int j = 0; j < W; j++) {
					var position = i + "_" + j;
					if (lumpInfo[position]) {
						righted.Add(position);
						//一番右の時の処理
						if (j==W-1) {
							foreach (var posi in righted) {
								yokoInfo.Add(posi, righted.Count());
							}
						}
					}
					else {//障害物にあたったとき、それまでの座標の光を記録する
						foreach (var posi in righted) {
							yokoInfo.Add(posi, righted.Count());
						}
						yokoInfo.Add(position, 0);
						righted = new HashSet<string>();//光をリセットする
					}
				}
			}
			//縦方向に照らす数を記録する
			var tateInfo = new Dictionary<string, int>();
			for (int j = 0; j < W; j++) {
				var righted = new HashSet<string>();
				for (int i = 0; i < H; i++) {
					var position = i + "_" + j;
					if (lumpInfo[position]) {
						righted.Add(position);
						//一番下の時の処理
						if (i == H - 1) {
							foreach (var posi in righted) {
								tateInfo.Add(posi, righted.Count());
							}
						}
					}
					else {//障害物にあたったとき、それまでの座標の光を記録する
						foreach (var posi in righted) {
							tateInfo.Add(posi, righted.Count());
						}
						tateInfo.Add(position, 0);
						righted = new HashSet<string>();//光をリセットする
					}
				}
			}

			var max = 0;

			//最も強く照らす場所を探す
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					var position = i + "_" + j;
					var right = tateInfo[position] + yokoInfo[position];
					max = Math.Max(max, right);
				}

			}
			//答えの出力
			var ans = max-1;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}