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 Rust (1.42.0) (judge verdict: Accepted)

#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        H_in: usize,
        W_in: usize,
        Ss: [String; H_in],
    }

    // 簡単のため、周囲に壁を作って (H+2)*(W+2)とする。
    let H = H_in + 2;
    let W = W_in + 2;
    let mut is_road_arr: Vec<Vec<bool>> = vec![vec![false; W]; H];

    for h in 0..H_in {
        for w in 0..W_in {
            let is_road: bool = &Ss[h][w..=w] == ".";

            let expanded_h = h + 1;
            let expanded_w = w + 1;

            is_road_arr[expanded_h][expanded_w] = is_road;
        }
    }

    // 制約的に、O(HW)なら間に合う
    // 列ごと、行ごとに持っておく形
    // row_groups: (h, w) を横に見た時の照らされる数
    // col_groups: (h, w) を縦に見た時の照らされる数
    let mut row_groups = vec![vec![0_usize; W]; H];
    let mut col_groups = vec![vec![0_usize; W]; H];

    for h in 0..H {
        let mut w_st: usize = 0;

        for w in 0..W {
            if !is_road_arr[h][w] {
                let cnt = w - w_st;
                for w_tmp in w_st..w {
                    row_groups[h][w_tmp] = cnt;
                }
                w_st = w + 1;
            }
        }
    }

    for w in 0..W {
        let mut h_st: usize = 0;

        for h in 0..H {
            if !is_road_arr[h][w] {
                let cnt = h - h_st;
                for h_tmp in h_st..h {
                    col_groups[h_tmp][w] = cnt;
                }
                h_st = h + 1;
            }
        }
    }

    let mut ans = 0;
    for h in 0..H {
        for w in 0..W {
            if !is_road_arr[h][w] {
                continue;
            }

            let cand = row_groups[h][w] + col_groups[h][w] - 1;
            ans = max(ans, cand);
        }
    }

    println!("{}", ans);
}