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: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC129.D();
        }



        class ABC129
        {
            public static void A()
            {
                var X = Read.IntN().OrderBy(x => x).ToArray();
                Console.WriteLine(X.Take(2).Sum());
            }
            public static void B()
            {
                var N = Read.Int();
                var W = Read.LongN();
                var WSum = Util.ASum(W);
                long min = 1000000;
                for(int i = 0; i < N - 1; ++i)
                {
                    min = Math.Min(min, Math.Abs(WSum[i + 1] * 2 - WSum[N]));
                }
                Console.WriteLine(min);
            }
            public static void C()
            {
                var N = Read.Int();
                var M = Read.Int();
                var A = new HashSet<int>();
                for(int m = 0; m < M; ++m)
                {
                    A.Add(Read.Int());
                }
                var C = new int[N + 1];
                C[0] = 1;
                C[1] = A.Contains(1) ? 0 : 1;
                for(int i = 2; i <= N; ++i)
                {
                    C[i] = A.Contains(i) ? 0 : (C[i - 1] + C[i - 2]) % 1000000007;
                }
                Console.WriteLine(C[N]);
            }
            public static void D()
            {
                var H = Read.Int();
                var W = Read.Int();
                var S = new bool[H, W];
                for (int h = 0; h < H; ++h)
                {
                    var s = Read.Str();
                    for (int w = 0; w < W; ++w)
                    {
                        S[h, w] = s[w] == '.';
                    }
                }
                var count = new int[H, W];
                for (int h = 0; h < H; ++h)
                {
                    int L = 0, R = 0;
                    for (int w = 0; w < W; ++w)
                    {
                        count[h, w] += S[h, w] ? L : 0;
                        L = S[h, w] ? L + 1 : 0;
                    }
                    for (int w = W - 1; w >= 0; --w)
                    {
                        count[h, w] += S[h, w] ? R : 0;
                        R = S[h, w] ? R + 1 : 0;
                    }
                }
                for (int w = 0; w < W; ++w)
                {
                    int U = 0, D = 0;
                    for (int h = 0; h < H; ++h)
                    {
                        count[h, w] += S[h, w] ? U : 0;
                        U = S[h, w] ? U + 1 : 0;
                    }
                    for (int h = H - 1; h >= 0; --h)
                    {
                        count[h, w] += S[h, w] ? D : 0;
                        D = S[h, w] ? D + 1 : 0;
                    }
                }
                int max = 1;
                for (int h = 0; h < H; ++h)
                {
                    for (int w = 0; w < W; ++w)
                    {
                        max = Math.Max(max, count[h, w] + 1);
                    }
                }
                Console.WriteLine(max);
            }
            public static void E()
            {
                var L = Read.Str();
                var P = 1000000007;
                long dp1 = 1, dp0 = 1;
                for(int i = L.Length - 1; i >= 0; --i)
                {
                    dp1 = (L[i] == '1' ? (dp0 + dp1 * 2) : dp1) % P;
                    dp0 = (dp0 * 3) % P;
                }
                Console.WriteLine(dp1);
            }
        }




        class Util
        {
            public static long[] ASum(long[] array)
            {
                var res = new long[array.Length + 1];
                for (int i = 0; i < array.Length; ++i)
                {
                    res[i + 1] = res[i] + array[i];
                }
                return res;
            }
        }

        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new HashSet<int>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1]);
                    dict[ab[1]].Add(ab[0]);
                }
                return dict;
            }
            public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
            {
                Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new Dictionary<int, long>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1], ab[2]);
                    dict[ab[1]].Add(ab[0], ab[2]);
                }
                return dict;
            }
        }
    }
}