Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import collections

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    H, W, M = map(int, input().split())
    bombs = []
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append((h, w))
    bombs_set = set(bombs)
    g = list(zip(*bombs))
    g0 = collections.Counter(g[0])
    g1 = collections.Counter(g[1])
    g0items = list(g0.items()); g0items.sort(key=lambda x: x[1], reverse=True)
    g1items = list(g1.items()); g1items.sort(key=lambda x: x[1], reverse=True)
    x = g0items[0][0];countx = g0items[0][1]
    y = g1items[0][0];county = g1items[0][1]
    for xx, s in g0items:
        if s != countx:
            continue
        for yy, t in g1items:
            if t != county:
                continue
            if (xx, yy) not in bombs_set:
                x, y = xx, yy
                break
    ans = countx + county - ((x, y) in bombs)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import collections

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    H, W, M = map(int, input().split())
    bombs = []
    for _ in range(M):
        h, w = map(int, input().split())
        bombs.append((h, w))
    bombs_set = set(bombs)
    g = list(zip(*bombs))
    g0 = collections.Counter(g[0])
    g1 = collections.Counter(g[1])
    g0items = list(g0.items()); g0items.sort(key=lambda x: x[1], reverse=True)
    g1items = list(g1.items()); g1items.sort(key=lambda x: x[1], reverse=True)
    x = g0items[0][0];countx = g0items[0][1]
    y = g1items[0][0];county = g1items[0][1]
    for xx, s in g0items:
        if s != countx:
            continue
        for yy, t in g1items:
            if t != county:
                break
            if (xx, yy) not in bombs_set:
                x, y = xx, yy
                break
    ans = countx + county - ((x, y) in bombs)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
from numba import njit

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

@njit
def main(N, K, A):
    for i in range(K):
        B = np.zeros(N, dtype=np.int64)
        for j in range(N):
            st = max(0, j - A[j])
            ed = j + A[j] + 1
            B[st:ed] += 1
        #print(B)
        if np.all(B == N):
            A = B
            break
        A = B
    return A

if __name__ == "__main__":
    N, K = map(int, readline().split())
    A = np.array(readline().split(), dtype=np.int64)
    ans = main(N, K, A)
    print(*ans)


Fixed submission:
import sys
import itertools

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    
    K = min(50, K)
    for i in range(K):
        B = [0]*N
        for j in range(N):
            st = max(0, j - A[j])
            ed = j + A[j] + 1
            B[st] += 1
            if ed < N:
                B[ed] -= 1
        Bcum = itertools.accumulate(B)
        A = list(Bcum)
    print(*A)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import copy
#import math
#import bisect
import numpy as np
#import itertools
#import collections
#from collections import deque
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
#import functools

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    N, K = map(int, readline().split())
    A = np.array(readline().split(), dtype=np.int64)
    for i in range(K):
        B = np.zeros(N, dtype=np.int64)
        for j in range(N):
            st = max(0, j - A[j])
            ed = j + A[j] + 1
            B[st:ed] += 1
        #print(B)
        if np.all(B == N):
            A = B
            break
        A = B
    print(*A)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
import itertools

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    
    K = min(50, K)
    for i in range(K):
        B = [0]*N
        for j in range(N):
            st = max(0, j - A[j])
            ed = j + A[j] + 1
            B[st] += 1
            if ed < N:
                B[ed] -= 1
        Bcum = itertools.accumulate(B)
        A = list(Bcum)
    print(*A)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    graph = [[] for _ in range(M)]
    for _ in range(M):
        A, B = map(int, readline().split())
        A -= 1; B -= 1
        graph[A].append(B)
        graph[B].append(A)
    trace = [-1]*N
    trace[0] = 0

    que = deque([0])
    while True:
        fr = que.popleft()
        for to in graph[fr]:
            if trace[to] != -1:
                continue
            trace[to] = fr
            que.append(to)
        if len(que) == 0:
            break

    if -1 in trace:
        print('No')
        return

    for t in trace[1:]:
        print(t+1)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
from collections import deque

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    graph = [[] for _ in range(N)]
    for _ in range(M):
        A, B = map(int, readline().split())
        A -= 1; B -= 1
        graph[A].append(B)
        graph[B].append(A)
    trace = [-1]*N
    trace[0] = 0

    que = deque([0])
    while True:
        fr = que.popleft()
        for to in graph[fr]:
            if trace[to] != -1:
                continue
            trace[to] = fr
            que.append(to)
        if len(que) == 0:
            break

    if -1 in trace:
        print('No')
        return

    print('Yes')
    for t in trace[1:]:
        print(t+1)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import collections

mod = 2019

def main():
    S = list(input())
    lenS = len(S)
    Smod2019 = [0] * lenS
    tmp = 0
    for i in range(lenS):
        tmp += (pow(10, i)*int(S[-(i+1)]))
        Smod2019[i] = tmp%mod
    
    cnt = collections.Counter(Smod2019)
    cntitems = cnt.items()
    ans = 0
    #print(cntitems)
    for c in cntitems:
        if c[0] == 0:
            ans += c[1]
        else:
            ans += (c[1] >= 2)*(c[1]-1)
    
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
import collections

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    S = input()
    N = len(S)
    memo = [0] * 2019
    now = 0
    ten = [0] * 200100
    ten[0] = 1
    for j in range(len(ten)-50):
        ten[j+1] = ten[j]*10%2019

    for i in range(N):
        now += int(S[-(i+1)])*ten[i]
        now %= 2019
        memo[now] += 1
    
    ans = 0
    for k in range(2019):
        ans += (memo[k] * (memo[k]-1)) // 2

    ans += memo[0]
    #m = collections.Counter(memo)
    #print(m)   
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    S = input()
    N = len(S)
    ans = 0
    for i in range(N):
        for j in range(i+4, N+1):
            if int(S[i:j])%2019 == 0:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
import sys
import collections

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
#read = sys.stdin.buffer.read

def main():
    S = input()
    N = len(S)
    memo = [0] * 2019
    now = 0
    ten = [0] * 200100
    ten[0] = 1
    for j in range(len(ten)-50):
        ten[j+1] = ten[j]*10%2019

    for i in range(N):
        now += int(S[-(i+1)])*ten[i]
        now %= 2019
        memo[now] += 1
    
    ans = 0
    for k in range(2019):
        ans += (memo[k] * (memo[k]-1)) // 2

    ans += memo[0]
    #m = collections.Counter(memo)
    #print(m)   
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

#import numpy

readline = sys.stdin.readline
inf = float('inf')

def dfs(i, j, n):
    global grid, bfsque
    if grid[i][j] == '#':
        grid[i][j] = n
    if grid[i+1][j] == '#':
        dfs(i+1, j, n)
    if grid[i][j+1] == '#':
        dfs(i, j+1, n)
    if grid[i+1][j] == '.':
        bfsque.append([i+1, j])
    if grid[i][j+1] == '.':
        bfsque.append([i, j+1])


def main():
    global grid, bfsque
    H, W = map(int, readline().split())
    grid = []
    grid.append(['*'] * (W+2))
    for _ in range(H):
        grid.append(['*'] + list(readline()[:-1]) + ['*'])
    grid.append(['*']*(W+2))

    sbfs = True; sdfs = False
    bfsque = deque([[1,1]]); dfsque = deque()
    bfscnt = 0
    while True:
        while sbfs:
            fr = bfsque.popleft()
            if grid[fr[0]][fr[1]] == '.':
                grid[fr[0]][fr[1]] = bfscnt
            if grid[fr[0]][fr[1]] == '#':
                dfsque.append(fr)
                sbfs = False
                sdfs = True
                break
            tor = [fr[0], fr[1]+1]
            tod = [fr[0]+1, fr[1]]
            if grid[tor[0]][tor[1]] == '.':
                bfsque.append(tor)
            if grid[tor[0]][tor[1]] == '#':
                dfsque.append(tor)
            if grid[tod[0]][tod[1]] == '.':
                bfsque.append(tod)
            if grid[tod[0]][tod[1]] == '#':
                dfsque.append(tod)
            if len(bfsque) == 0:
                sbfs = False
                sdfs = True
        bfscnt += 1

        while sdfs:
            if len(dfsque) > 0:
                fr = dfsque.popleft()
                dfs(fr[0], fr[1], bfscnt)
            if len(dfsque) == 0:
                sbfs = True
                sdfs = False
        
        if not (grid[H][W] == '.' or grid[H][W] == '#'):
            break
    
    ans = grid[H][W]
    #print(numpy.array(grid))
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

readline = sys.stdin.readline
inf = float('inf')

def main():
    H, W = map(int, readline().split())
    grid = []
    grid.append(['*'] * (W+2))
    for _ in range(H):
        grid.append(['*'] + list(readline()[:-1]) + ['*'])
    grid.append(['*']*(W+2))

    DP = [[inf] * (W+2) for _ in range(H+2)]
    DP[1][1] = (grid[1][1] == '#')*1

    for i in range(1, H+1):
        for j in range(1, W+1): 
            if i == 1 and j == 1:
                continue
            k = i
            gridkj = grid[k][j]
            if gridkj == '.':
                DP[k][j] = min(DP[k][j-1], DP[k-1][j])
            if gridkj == '#':
                DP[k][j] = min(DP[k][j-1]+(grid[k][j-1] in ['.', '*']), DP[k-1][j] + (grid[k-1][j] in ['.', '*']))
    ans = DP[H][W]
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import bisect

def main():
    N = int(input())
    letterset = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
    check = []
    for i in range(1, N+1):
        iters = itertools.product(letterset[:i], repeat=N)
        for tmp in iters:
            if len(set(tmp)) == i:
                flag = True
                if tmp[0] != 'a':
                    flag = False
                for k in range(N-1):
                    if not tmp[k+1] in letterset[:len(set(tmp[:k+1]))+1]:
                        flag = False
                if flag:
                    check.append(''.join(tmp))
    check.sort()
    for ans in check:
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

sys.setrecursionlimit(10**7)
strlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

def dfs(n, before):
    lensetbefore = len(set(before))
    if n == 1:
        print(before)
    if n > 1:
        for s in strlist[:lensetbefore+1]:
            dfs(n-1, before+s)

def main():
    N = int(input())
    dfs(N, 'a')


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):

N, A, B = map(int, input().split())

ans = 0
#print(int(N/(A+B)))
for i in range(1, int(N/(A+B))+1):
    ans = ans + A

r = N-(A+B)*i
#print(r)

if r <= A:
    ans = ans + r
else:
    ans = ans + A

print(ans)


Fixed submission:

N, A, B = map(int, input().split())

ans = 0
S=A+B
Q=int(N/S)
#print(int(N/(A+B)))
#for i in range(1, int(N/(A+B))+1):
#    ans = ans + A
ans = Q*A

r = N-Q*S
#print(r)

if r <= A:
    ans = ans + r
else:
    ans = ans + A

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.read

def main(H, N, tmp):
    damage = tmp[::2]
    magic = tmp[1::2]
    DP = [float('inf')] * 20001
    DP[0] = 0
    for i in range(20001):
        for j in range(N):
            s = i - damage[j]
            if s >= 0:
                DP[i] = min(DP[i], DP[s] + magic[j])
    return min(DP[H:])


if __name__ == "__main__":
    H, N, *tmp = map(int, input().split())
    ans = main(H, N, tmp)
    print(ans)


Fixed submission:
import sys

input = sys.stdin.read

def main(H, N, tmp):
    damage = tmp[::2]
    magic = tmp[1::2]
    DP = [float('inf')] * 20001
    DP[0] = 0
    for i in range(20001):
        for j in range(N):
            s = i - damage[j]
            if s >= 0:
                DP[i] = min(DP[i], DP[s] + magic[j])
    return min(DP[H:])


if __name__ == "__main__":
    H, N, *tmp = map(int, input().split())
    ans = main(H, N, tmp)
    print(ans)
Buggy python submission (verdict: Runtime Error):
def main():
    A, B, X = map(int, input().split())
    if X >= A*pow(10,9) + B*10:
        print(pow(10, 9))
        return
    ans = 0
    for n in range(10):
        N = (X - B*n) // A
        #print('N:{}, n:{}'.format(N, n))
        ans = max(ans, min(N, pow(10, n)-1))
 
    print(ans)
 
 
if __name__ == "__main__":
    main()

Fixed submission:
# coding UTF-8
# 
# problem A
# 

r = input()
if r == 'SUN':
    print(7)
if r == 'MON':
    print(6)
if r == 'TUE':
    print(5)
if r == 'WED':
    print(4)
if r == 'THU':
    print(3)
if r == 'FRI':
    print(2)
if r == 'SAT':
    print(1)
Buggy python submission (verdict: Runtime Error):
import math

def main():
    a, b, x = map(int, input().split())
    mid = a**2*b/2
    c = x/(a**2)
    if mid == x:
        ans = 90 - math.degrees(math.atan(a/b))
    elif mid < x:
        d = 2*x/(a**2) - b
        ans = 90 - math.degrees(math.atan(a/(b-d)))
    else:
        d = 2*a*c/b
        ans = 90 - math.degrees(math.atan(d/b))

    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
import math

def main():
    a, b, x = map(int, input().split())
    if a*a*b == x:
        print(0)
        return
    mid = a**2*b/2
    c = x/(a**2)
    if mid == x:
        ans = 90 - math.degrees(math.atan(a/b))
    elif mid < x:
        d = 2*x/(a**2) - b
        ans = 90 - math.degrees(math.atan(a/(b-d)))
    else:
        d = 2*a*c/b
        ans = 90 - math.degrees(math.atan(d/b))

    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

readline = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = []
    for i in range(1, len(A)+1):
        ans.append(A.index(i)+1)
    print(*ans)

if __name__ == "__main__":
    main()


Fixed submission:
import sys

readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    tmp = []
    for i, a in enumerate(A):
        tmp.append((i, a))
    tmp.sort(key=lambda a: a[1])
    ans = []
    for i in tmp:
        ans.append(i[0]+1)
    print(*ans)

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(1, len(A)+1):
	ans.append(A.index(i+1))
print(*ans)


Fixed submission:
import sys

readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    tmp = []
    for i, a in enumerate(A):
        tmp.append((i, a))
    tmp.sort(key=lambda a: a[1])
    ans = []
    for i in tmp:
        ans.append(i[0]+1)
    print(*ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import numpy as np
from numba import njit
import sys

input = sys.stdin.readline

N = int(input())
H = np.array(input().split(), dtype=np.int64)

@njit
def main():
    Hdiff = np.diff(H)
    cnt = 0; ans = 0
    for h in Hdiff:
        if h <= 0:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np
#from numba import jit
import sys

input = sys.stdin.readline

N = int(input())
H = np.array(input().split(), dtype=np.int64)

#@jit(nopython=True)
def main():
    Hdiff = np.diff(H)
    cnt = 0; ans = 0
    for h in Hdiff:
        if h <= 0:
            cnt += 1
        else:
            cnt = 0
        ans = max(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import math

gcd = math.gcd

def main():
    A, B, C, D = map(int, input().split())
    nC = B//C - (A-1)//C
    nD = B//D - (A-1)//D
    CD = (C*D)//gcd(C, D)
    nCD = B//CD - (A-1)//CD
    cnt = nC + nD - nCD
    ans = B - A + 1 - cnt
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
from fractions import gcd

def main():
    A, B, C, D = map(int, input().split())
    nC = B//C - (A-1)//C
    nD = B//D - (A-1)//D
    CD = (C*D)//gcd(C, D)
    nCD = B//CD - (A-1)//CD
    cnt = nC + nD - nCD
    ans = B - A + 1 - cnt
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))

    plus = []; minus = []
    for a in A:
        if a > 0:
            plus.append(a)
        if a < 0:
            minus.append(a)
    
        
    plus.sort()
    minus.sort()
    plus = deque(plus)
    minus = deque(minus)
    anslist = []
    if len(plus) == 0:
        stmp = minus.popleft()
        ltmp = minus.pop()
        anslist.append((ltmp, stmp))
        plus.append(ltmp-stmp)
        N -= 1
    elif len(minus) == 0:
        stmp = plus.popleft()
        ltmp = plus.pop()
        anslist.append((stmp, ltmp))
        minus.append(stmp-ltmp)
        N -= 1
    else:
        pass

    for _ in range(N):
        if len(minus) > 1:
            ltmp = plus.pop()
            stmp = minus.pop()
            anslist.append((ltmp, stmp))
            plus.append(ltmp - stmp)
        elif len(plus) > 1:
            ltmp = plus.popleft()
            stmp = minus.popleft()
            anslist.append((stmp, ltmp))
            minus.append(stmp - ltmp)
        else:
            ltmp = plus.popleft()
            stmp = minus.popleft()
            anslist.append((ltmp, stmp))
            ans = ltmp - stmp
            break
    print(ans)
    for s in anslist:
        print(*s)

if __name__ == "__main__":
    main()


Fixed submission:
from collections import deque
import bisect

def main():
    N = int(input())
    A = list(map(int, input().split()))

    plus = []; minus = []
    for a in A:
        if a >= 0:
            plus.append(a)
        if a < 0:
            minus.append(a)
        
    plus.sort()
    minus.sort()
    plus = deque(plus)
    minus = deque(minus)

    if N == 2:
        if A[0] >= A[1]:
            ans = A[0] - A[1]
            print(ans)
            print(A[0], A[1])
        else:
            ans = A[1] - A[0]
            print(ans)
            print(A[1], A[0])
        return

    anslist = []
    if len(plus) == 0:
        stmp = minus.popleft()
        ltmp = minus.pop()
        anslist.append((ltmp, stmp))
        ans = ltmp - stmp
        plus.append(ans)
        N -= 1
    elif len(minus) == 0:
        stmp = plus.popleft()
        ltmp = plus.pop()
        anslist.append((stmp, ltmp))
        ans = stmp - ltmp
        minus.append(ans)
        N -= 1
    else:
        pass

    for _ in range(N):
        if len(minus) > 1:
            ltmp = plus.pop()
            stmp = minus.pop()
            anslist.append((ltmp, stmp))
            plus.append(ltmp - stmp)
        elif len(plus) > 1:
            ltmp = plus.popleft()
            stmp = minus.popleft()
            anslist.append((stmp, ltmp))
            minus.append(stmp - ltmp)
        else:
            ltmp = plus.popleft()
            stmp = minus.popleft()
            anslist.append((ltmp, stmp))
            ans = ltmp - stmp
            break
    print(ans)
    for s in anslist:
        print(*s)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy

input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(list(input()[:-1]))
    
    L = [[0] * W for _ in range(H)]
    R = copy.deepcopy(L)
    U = copy.deepcopy(L)
    D = copy.deepcopy(L)
    
    for h in range(H):
        cntL, cntR = 0, 0
        for w in range(W):
            wreverse = W - w - 1
            if grid[h][w] == '.':
                cntL += 1
            else:
                cntL = 0
            if grid[h][wreverse] == '.':
                cntR += 1
            else:
                cntR = 0
            L[h][w] = cntL
            R[h][wreverse] = cntR

    for w in range(W):
        cntU, cntD = 0, 0
        for h in range(H):
            hreverse = H - h - 1
            if grid[h][w] == '.':
                cntU += 1
            else:
                cntU = 0
            if grid[hreverse][w] == '.':
                cntD += 1
            else:
                cntD = 0
            U[h][w] = cntU
            D[hreverse][w] = cntD
    
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3)

    print(ans)
        
if __name__ == "__main__":
    main()


Fixed submission:
import sys
import copy

input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(list(input()[:-1]))
    
    L = [[0] * W for _ in range(H)]
    R = copy.deepcopy(L)
    U = copy.deepcopy(L)
    D = copy.deepcopy(L)
    
    for h in range(H):
        cntL, cntR = 0, 0
        for w in range(W):
            wreverse = W - w - 1
            if grid[h][w] == '.':
                cntL += 1
            else:
                cntL = 0
            if grid[h][wreverse] == '.':
                cntR += 1
            else:
                cntR = 0
            L[h][w] = cntL
            R[h][wreverse] = cntR

    for w in range(W):
        cntU, cntD = 0, 0
        for h in range(H):
            hreverse = H - h - 1
            if grid[h][w] == '.':
                cntU += 1
            else:
                cntU = 0
            if grid[hreverse][w] == '.':
                cntD += 1
            else:
                cntD = 0
            U[h][w] = cntU
            D[hreverse][w] = cntD
    
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3)

    print(ans)
        
if __name__ == "__main__":
    main()