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 JavaScript (node.js v5.12) (judge verdict: Time Limit Exceeded)

// Find maximum possible number of squares lighted by the lamp.
"use strict";

function Main(input)
{
    input = input.split('\n');
    let mazeSize = input.shift().split(' ').map(function(a)
    {
        parseInt(a);
    });
    // input = input.map(function(a) {
    //     a = a.split('');
    // });
    input.forEach(function(part, index, array){
        array[index] = array[index].split('');
    });
    // console.log(input);
    let maxLightSq = 0;
    for(let y = 0; y < input.length; y++)
    {
        for(let x = 0; x < input[0].length; x++)
        {
            if(input[y][x]==='.'){
                let lightSq = cardinalLightNumber(input,[x,y]);
                maxLightSq = maxLightSq > lightSq ? maxLightSq : lightSq;
            }
        }
        // console.log("next line.");
    }

    let result = maxLightSq;
    console.log(result);
}

function cardinalLightNumber(arr, pos)
{
    let x = pos[0], y = pos[1];
    // console.log(x + ", " + y );
    // One for center square
    let num = 1;
    // Up
    for(let i = y-1; i >= 0; i--){
        if(arr[i][x] === '.') num++;
        else if(arr[i][x] === '#') break;
    }
    // Down
    for(let i = y+1; i < arr.length; i++){
        if(arr[i][x] === '.') num++;
        else if(arr[i][x] === '#') break;
    }
    // Left
    for(let i = x-1; i >= 0; i--){
        if(arr[y][i] === '.') num++;
        else if(arr[y][i] === '#') break;
    }
    // Right
    for(let i = x+1; i < arr[0].length; i++){
        if(arr[y][i] === '.') num++;
        else if(arr[y][i] === '#') break;
    }
    // console.log("Number of light squares at(" + pos +"): " + num);
    return num;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require("fs").readFileSync("Task04input.txt", "utf8"));