Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
n = len(S)

R = [0]*2019

for i in range(n):
    s = int(S[-i-1:])
    R[s % 2019] += 1

ans = R[0]
for r in R:
    ans += r*(r-1)//2

print(ans)

Fixed submission:
S = input()
n = len(S)
*S, = map(int, S[::-1])
R = [0]*2019

p = 0
for i, s in enumerate(S):
    q = 10**(i % 224) % 2019
    p += s*q
    p %= 2019
    R[p] += 1

ans = R[0]
for r in R:
    ans += r*(r-1)//2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = sorted([(a, i) for i, a in enumerate(map(int, input().split()))], reverse=True)
dp = [[0]*(N+1) for _ in [0]*(N+1)]

for j, (a, i) in enumerate(A):
    for l in range(j+1):
        r = N-1-(j-l)
        dp[j+1][l] = max(dp[j+1][l], dp[j][l]+a*(r-i))
        dp[j+1][l+1] = max(dp[j+1][l+1], dp[j][l]+a*(i-l))

print(max(dp[N]))


Fixed submission:
N = int(input())
A = sorted([(a, i) for i, a in enumerate(map(int, input().split()))], reverse=True)
dp = [[0]*(N+1) for _ in [0]*(N+1)]

for j, (a, i) in enumerate(A):
    for l in range(j+1):
        r = N-1-(j-l)
        dp[j+1][l] = max(dp[j+1][l], dp[j][l]+a*(r-i))
        dp[j+1][l+1] = max(dp[j+1][l+1], dp[j][l]+a*(i-l))

print(max(dp[N]))
Buggy python submission (verdict: Runtime Error):
# E
X, Y, NA, NB, NC = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

A = sorted(A)[-X:]
B = sorted(B)[-Y:]
C = sorted(C)[::-1]

ans = sum(A) + sum(B)

i = 0
j = 0
for c in C:
    if A[i] < c or B[j] < c:
        if A[i] < B[j]:
            i += 1
            ans += c - A[i]
        else:
            j += 1
            ans += c - B[j]

print(ans)


Fixed submission:
# E
X, Y, NA, NB, NC = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

A = sorted(A)[-X:]
B = sorted(B)[-Y:]
C = sorted(C)[::-1]

ans = sum(A) + sum(B)


i = 0
j = 0
num_A = len(A)
num_B = len(B)
for c in C:
    if i < num_A and j < num_B:
        if A[i] < B[j] and A[i] < c:

            ans += c - A[i]
            i += 1
        elif A[i] >= B[j] and B[j] < c:

            ans += c - B[j]
            j += 1

    elif i < num_A:
        if A[i] < c:
            ans += c - A[i]
            i += 1

    elif j < num_B:
        if B[j] < c:
            ans += c - B[j]
            j += 1

    else:
        break

print(ans)

Buggy python submission (verdict: Runtime Error):
# E
X, Y, NA, NB, NC = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

A = sorted(A)[-X:]
B = sorted(B)[-Y:]
C = sorted(C)[::-1]

ans = sum(A) + sum(B)

i = 0
j = 0
for c in C:
    if A[i] < c or B[j] < c:
        if A[i] < B[j]:
            i += 1
            ans += c - A[i]
        else:
            j += 1
            ans += c - B[i]

print(ans)


Fixed submission:
# E
X, Y, NA, NB, NC = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

A = sorted(A)[-X:]
B = sorted(B)[-Y:]
C = sorted(C)[::-1]

ans = sum(A) + sum(B)


i = 0
j = 0
num_A = len(A)
num_B = len(B)
for c in C:
    if i < num_A and j < num_B:
        if A[i] < B[j] and A[i] < c:

            ans += c - A[i]
            i += 1
        elif A[i] >= B[j] and B[j] < c:

            ans += c - B[j]
            j += 1

    elif i < num_A:
        if A[i] < c:
            ans += c - A[i]
            i += 1

    elif j < num_B:
        if B[j] < c:
            ans += c - B[j]
            j += 1

    else:
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, K = map(int, input().split())
S = [list(map(int, input())) for _ in range(H)]

def nl(a, b):
    return [[0]*b for _ in range(a)]

def add(j):
    for i in range(g):
        now[i] += group_sum[i][j]
        if now[i] > K:
            return False
    return True

ans = float('inf')
for bit in range(1<<(H-1)):
    id_of = [0]*H
    g = 0
    
    for i in range(H):
        id_of[i] = g
        if bit >> i & 1:
            g += 1
    
    g += 1
    count = g - 1

    # グループごとに統合
    group_sum = nl(H, W)
    flg = True
    for i in range(H):
        for j in range(W):
            group_sum[id_of[i]][j] += S[i][j]
            if group_sum[id_of[i]][j] > K:
                # 横方向の分割が不適
                bl = False
    if not flg:
        continue

    # 縦方向に分割
    now = [0]*g
    for j in range(W):
        if not add(j):
            count += 1
            now = [0]*g
            add(j)
    
    ans = min(ans, count)

print(ans)

Fixed submission:
H, W, K = map(int, input().split())
S = [list(map(int, input())) for _ in range(H)]

def nl(a, b):
    return [[0]*b for _ in range(a)]

def add(j):
    for i in range(g):
        now[i] += group_sum[i][j]
        if now[i] > K:
            return False
    return True

ans = float('inf')
for bit in range(1<<(H-1)):
    id_of = [0]*H
    g = 0
    
    for i in range(H):
        id_of[i] = g
        if bit >> i & 1:
            g += 1
    
    g += 1
    count = g - 1

    # グループごとに統合
    group_sum = nl(H, W)
    for i in range(H):
        for j in range(W):
            group_sum[id_of[i]][j] += S[i][j]

    # 縦方向に分割
    now = [0]*g
    for j in range(W):
        if not add(j):
            count += 1
            now = [0]*g
            if not add(j):
                count = float('inf')
                break
    
    ans = min(ans, count)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline
S = input().rstrip()
input()
rev = 0
for line in readlines():
    q, *query, = line.split()
    if q == '1':
        rev ^= 1
    else:
        f, c = query
        if f == '1':
            if not rev:
                S = c+S
            else:
                S = S+c
        else:
            if not rev:
                S = S+c
            else:
                S = c+S

print(S if not rev else S[::-1])


Fixed submission:
def m():
    s = input()
    q = int(input())
    inv = 0
    pre = []
    sub = []

    for i in range(q):
        raw = input().split()
        if len(raw) == 1:
            inv = inv ^ 1
        else:
            f = int(raw[1])-1
            c = raw[2]
            if inv==f:
                pre.append(c)
            else:
                sub.append(c)
    
    if inv==0:
        print(''.join(pre[::-1])+s+''.join(sub))
    else:
        print(''.join(sub[::-1])+s[::-1]+''.join(pre))

m()

Buggy python submission (verdict: Time Limit Exceeded):
def m():
    s = input()
    q = int(input())
    inv = 0
    pre = ''
    sub = ''

    for i in range(q):
        raw = input().split()
        if len(raw) == 1:
            inv = inv ^ 1
        else:
            f = int(raw[1])-1
            c = raw[2]
            if inv==f:
                pre = c + pre
            else:
                sub = sub + c
    
    if inv==0:
        print(pre+s+sub)
    else:
        print(sub[::-1]+s[::-1]+pre[::-1])

m()

Fixed submission:
def m():
    s = input()
    q = int(input())
    inv = 0
    pre = []
    sub = []

    for i in range(q):
        raw = input().split()
        if len(raw) == 1:
            inv = inv ^ 1
        else:
            f = int(raw[1])-1
            c = raw[2]
            if inv==f:
                pre.append(c)
            else:
                sub.append(c)
    
    if inv==0:
        print(''.join(pre[::-1])+s+''.join(sub))
    else:
        print(''.join(sub[::-1])+s[::-1]+''.join(pre))

m()
Buggy python submission (verdict: Time Limit Exceeded):
def search(x, j, visited, t, vis, rel):
    visited[x][j] = True
    visited[j][x] = True

    if vis[x][j]:
        return t[x][j]

    else:
        for k in range(N):
            if visited[k][j]:
                continue
            else:
                if rel[x][k] and t[x][k]:

                    if search(k, j, visited, t, vis, rel):
                        vis[k][j] = True
                        vis[j][k] = True
                        t[k][j] = True
                        t[j][k] = True
                        return True
                    else:
                        continue
        return False


def main():

    t = [[False] * N for i in range(N)]
    vis = [[False] * N for i in range(N)]
    rel = [[False] * N for i in range(N)]

    for i in range(M):
        a, b = map(int, input().split())
        rel[a - 1][b - 1] = True
        rel[b - 1][a - 1] = True
        vis[a - 1][b - 1] = True
        vis[b - 1][a - 1] = True
        t[a - 1][b - 1] = True
        t[b - 1][a - 1] = True

    for i in range(K):
        c, d = map(int, input().split())
        rel[c - 1][d - 1] = True
        rel[d - 1][c - 1] = True
        t[c - 1][d - 1] = False
        t[d - 1][c - 1] = False

    a = []
    for i in range(N):
        cnt = 0
        for j in range(N):
            if i == j or rel[i][j]:
                continue
            else:
                visited = [[False] * N for n in range(N)]
                if search(i, j, visited, t, vis, rel):
                    cnt += 1
        a.append(cnt)

    print(*a)


N, M, K = map(int, input().split())
main()


Fixed submission:
class Unionroot:
    def __init__(self, n=0):
        self.d = [-1]*n

    def root(self, x):
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.d[self.root(x)]

deg = [0] * 100005
to = [[] for i in range(100005)]

n, m, k = map(int, input().split())
uf = Unionroot(n)

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    deg[a] += 1
    deg[b] += 1
    uf.unite(a, b)

for i in range(k):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

ret = []
for i in range(n):
    ans = uf.size(i) - 1 - deg[i]
    for u in to[i]:
        if uf.same(i, u):
            ans -= 1
    ret.append(ans)
print(' '.join([str(r) for r in ret]))
Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.buffer.readline
H, N = map(int, input().split())

INF = 1 << 40
dp = [INF]*(H+1)
dp[H] = 0
for i in range(N):
    a, b = map(int, input().split())
    for j in range(H, -1, -1):
        x = max(0, j-a)
        dp[x] = min(dp[x], dp[j]+b)

print(dp[0])


Fixed submission:
# AtCoder Beginner Contest 153
# E - Crested Ibis vs Monster
# https://atcoder.jp/contests/abc153/tasks/abc153_e
H, N, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)

INF = 1 << 30
dp = [INF]*(H+1)
dp[0] = 0
for i, (a, b) in enumerate(A):
    for h in range(H+1):
        mh = min(H, h+a)
        dp[mh] = min(dp[mh], dp[h] + b)
print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
# AtCoder Beginner Contest 153
# E - Crested Ibis vs Monster
# https://atcoder.jp/contests/abc153/tasks/abc153_e
H, N, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)

INF = 1 << 30
dp = [INF]*(H+1)
dp[0] = 0
for i, (a, b) in enumerate(A):
    for h in range(H+1):
        mh = min(H, h+a)
        dp[mh] = min(dp[mh], dp[h] + b)
print(dp[H])


Fixed submission:
# AtCoder Beginner Contest 153
# E - Crested Ibis vs Monster
# https://atcoder.jp/contests/abc153/tasks/abc153_e
H, N, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)

INF = 1 << 30
dp = [INF]*(H+1)
dp[0] = 0
for i, (a, b) in enumerate(A):
    for h in range(H+1):
        mh = min(H, h+a)
        dp[mh] = min(dp[mh], dp[h] + b)
print(dp[H])
Buggy python submission (verdict: Time Limit Exceeded):
from decimal import Decimal
import sys
input = sys.stdin.readline


def dist(x1, x2, y1, y2):
    return (y1-y2)*(y1-y2)+(x1-x2)*(x1-x2)


def farthest(x, y):
    ret = 0
    point = (-1, -1)
    for u, v in X:
        d = dist(x, u, y, v)
        if d > ret:
            ret = d
            point = u, v
    return ret, point


N = int(input())
X = []
for _ in [0]*N:
    x, y = map(int, input().split())
    X.append((x, y))

x = (max(x for x, y in X) - min(x for x, y in X))/2
y = (max(y for x, y in X) - min(y for x, y in X))/2
x = Decimal(str(x))
y = Decimal(str(y))
step = Decimal('0.5')
o = 1
eps = Decimal('0.000000000000000001')
while o > eps:
    _, (u, v) = farthest(x, y)
    x += (u-x)*step
    y += (v-y)*step
    step *= Decimal('0.999')
    o = (abs(u-x)+abs(x-y))*step

ans, _ = farthest(x, y)
ans **= Decimal('0.5')
print(ans)

Fixed submission:
from decimal import Decimal
import sys
input = sys.stdin.readline


def dist(x1, x2, y1, y2):
    return (y1-y2)*(y1-y2)+(x1-x2)*(x1-x2)


def farthest(x, y):
    ret = 0
    point = (-1, -1)
    for u, v in X:
        d = dist(x, u, y, v)
        if d > ret:
            ret = d
            point = u, v
    return ret, point


N = int(input())
X = []
for _ in [0]*N:
    x, y = map(int, input().split())
    X.append((x, y))

x = (max(x for x, y in X) - min(x for x, y in X))/2
y = (max(y for x, y in X) - min(y for x, y in X))/2
x = Decimal(str(x))
y = Decimal(str(y))
step = Decimal('0.5')
o = 1
eps = Decimal('0.00000000000001')
while o > eps:
    _, (u, v) = farthest(x, y)
    x += (u-x)*step
    y += (v-y)*step
    step *= Decimal('0.999')
    o = (abs(u-x)+abs(x-y))*step

ans, _ = farthest(x, y)
ans **= Decimal('0.5')
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
*A, = map(int, input().split())
mod = 10**9 + 7

col = [0, 0, 0]
ans = 1
for a in A:
    ans = ans * col.count(a) % mod
    col[col.index(a)] += 1

print(ans)


Fixed submission:
N = int(input())
*A, = map(int, input().split())
mod = 10**9 + 7

col = [0, 0, 0]
ans = 1
for a in A:
    if a not in col:
        print(0)
        break
    ans = ans * col.count(a) % mod
    col[col.index(a)] += 1
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
def dfs(x, c=-1, p=-1):
    k = 1
    for y, ei in G[x]:
        if y == p:
            continue
        if k == c:
            k += 1
        ans[ei] = k; k+=1
        dfs(y, ans[ei], x)

n = int(input())
G = [[] for _ in range(n)]
ans = [0] * (n-1)
for i in range(n-1):
  a, b = map(int, input().split())
  a-=1; b-=1
  G[a].append((b, i))
  G[b].append((a, i))

dfs(0)
mx = 0
for g in G:
    mx = max(mx, len(g))
print(mx)
for a in ans:
    print(a)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)

def dfs(x, c=-1, p=-1):
    k = 1
    for y, ei in G[x]:
        if y == p:
            continue
        if k == c:
            k += 1
        ans[ei] = k; k+=1
        dfs(y, ans[ei], x)

n = int(input())
G = [[] for _ in range(n)]
ans = [0] * (n-1)
for i in range(n-1):
  a, b = map(int, input().split())
  a-=1; b-=1
  G[a].append((b, i))
  G[b].append((a, i))

dfs(0)
mx = 0
for g in G:
    mx = max(mx, len(g))
print(mx)
for a in ans:
    print(a)

Buggy python submission (verdict: Runtime Error):
def dfs(x, c=-1, p=-1):
    k = 1
    for y, ei in G[x]:
        if y == p:
            continue
        if k == c:
            k += 1
        ans[ei] = k; k+=1
        dfs(y, k, x)

n = int(input())
G = [[] for _ in range(n)]
ans = [0] * (n-1)
for i in range(n-1):
  a, b = map(int, input().split())
  a-=1; b-=1
  G[a].append((b, i))
  G[b].append((a, i))

dfs(0)
mx = 0
for g in G:
    mx = max(mx, len(g))
print(mx)
for a in ans:
    print(a)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)

def dfs(x, c=-1, p=-1):
    k = 1
    for y, ei in G[x]:
        if y == p:
            continue
        if k == c:
            k += 1
        ans[ei] = k; k+=1
        dfs(y, ans[ei], x)

n = int(input())
G = [[] for _ in range(n)]
ans = [0] * (n-1)
for i in range(n-1):
  a, b = map(int, input().split())
  a-=1; b-=1
  G[a].append((b, i))
  G[b].append((a, i))

dfs(0)
mx = 0
for g in G:
    mx = max(mx, len(g))
print(mx)
for a in ans:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)

from functools import lru_cache
S = input()
N = len(S)

@lru_cache
def solve(i, prev, K):
    if i >= N:
        return K
    ret = 0
    if S[i] != prev:
        ret = max(ret, solve(i+1, S[i], K+1))
    if S[i:i+2] != prev:
        ret = max(ret, solve(i+2, S[i:i+2], K+1))
    return ret


print(solve(0, '', 0))


Fixed submission:
S = input()

ans = 0
prev = ''
curr = ''
for s in S:
    curr += s
    if prev != curr:
        ans += 1
        prev = curr
        curr = ''
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

from functools import lru_cache
S = input()
N = len(S)

@lru_cache
def solve(i, prev, K):
    if i >= N:
        return K
    ret = 0
    if S[i] != prev:
        ret = max(ret, solve(i+1, S[i], K+1))
    if S[i:i+2] != prev:
        ret = max(ret, solve(i+2, S[i:i+2], K+1))
    return ret


print(solve(0, '', 0))


Fixed submission:
S = input()

ans = 0
prev = ''
curr = ''
for s in S:
    curr += s
    if prev != curr:
        ans += 1
        prev = curr
        curr = ''
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

from functools import lru_cache
S = input()


@lru_cache
def solve(i, prev, K):
    if i >= N:
        return K
    ret = 0
    if S[i] != prev:
        ret = max(ret, solve(i+1, S[i], K+1))
    if S[i:i+2] != prev:
        ret = max(ret, solve(i+2, S[i:i+2], K+1))
    return ret


print(solve(0, '', 0))


Fixed submission:
S = input()

ans = 0
prev = ''
curr = ''
for s in S:
    curr += s
    if prev != curr:
        ans += 1
        prev = curr
        curr = ''
print(ans)

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
S = input()


@lru_cache
def solve(i, prev, K):
    if i >= N:
        return K
    ret = 0
    if S[i] != prev:
        ret = max(ret, solve(i+1, S[i], K+1))
    if S[i:i+2] != prev:
        ret = max(ret, solve(i+2, S[i:i+2], K+1))
    return ret


print(solve(0, '', 0))


Fixed submission:
S = input()

ans = 0
prev = ''
curr = ''
for s in S:
    curr += s
    if prev != curr:
        ans += 1
        prev = curr
        curr = ''
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, *S = open(0).read().split()
S = [sorted(s) for s in S]

cnt = 0
for i, s in enumerate(S):
    for j, t in enumerate(S[i+1:]):
        if s == t:
            cnt += 1
print(cnt)

Fixed submission:
N, *S = open(0).read().split()
S = [str(sorted(s)) for s in S]
D = {}
ans = 0
for s in S:
    if s in D:
        ans += D[s]
        D[s] += 1
    else:
        D[s] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N = int(input())
S = [sorted(input()[:-1]) for _ in [0]*N]

cnt = 0
for i, s in enumerate(S):
    for j, t in enumerate(S[i+1:]):
        if s == t:
            cnt += 1
print(cnt)

Fixed submission:
N, *S = open(0).read().split()
S = [str(sorted(s)) for s in S]
D = {}
ans = 0
for s in S:
    if s in D:
        ans += D[s]
        D[s] += 1
    else:
        D[s] = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N = int(input())
S = [input()[:-1] for _ in [0]*N]

cnt = 0
for i, s in enumerate(S):
    for j, t in enumerate(S[i+1:]):
        if sorted(s) == sorted(t):
            cnt += 1
print(cnt)

Fixed submission:
N, *S = open(0).read().split()
S = [str(sorted(s)) for s in S]
D = {}
ans = 0
for s in S:
    if s in D:
        ans += D[s]
        D[s] += 1
    else:
        D[s] = 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
dp = [[0]*13 for _ in [0]*-~len(S)]
dp[0][0] = 1
mod = 10**9 + 7

for i, s in enumerate(S):
    if s == '?':
        d = dp[i+1]
        for j in range(13):
            for k in range(10):
                x = (j*10+k) % 13
                d[x] = (d[x] + dp[i][j]) % mod
    else:
        for j in range(13):
            dp[i+1][(j*10+int(s)) % 13] = dp[i][j]
print(dp[-1][5] % mod)


Fixed submission:
S = input()
dp = [[0]*13 for _ in [0]*-~len(S)]
dp[0][0] = 1
mod = 10**9 + 7

for i, s in enumerate(S):
    if s == '?':
        d = dp[i+1]
        for j in range(13):
            for k in range(10):
                x = (j*10+k) % 13
                d[x] = (d[x] + dp[i][j]) % mod
    else:
        for j in range(13):
            dp[i+1][(j*10+int(s)) % 13] = dp[i][j]
print(dp[-1][5] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, *SS = open(0).read().split()
H, W = int(H), int(W)

R = [[0]*(W) for _ in [0]*(H)]
C = [[0]*(W) for _ in [0]*(H)]

for i, S in enumerate(SS):
    cnt = 0
    pre = S[0]
    for j, s in enumerate(S):
        if s == '.':
            cnt += 1
        else:
            if pre == '.':
                for k in range(1, cnt+1):
                    R[i][j-k] = cnt
                cnt = 0
        pre = s
    if pre == '.':
        for k in range(1, cnt+1):
            R[i][-k] = cnt

for j in range(W):
    cnt = 0
    pre = SS[0][j]
    for i in range(H):
        s = SS[i][j]
        if s == '.':
            cnt += 1
        else:
            if pre == '.':
                for k in range(1, cnt+1):
                    C[i-k][j] = cnt
                cnt = 0
        pre = s
    if pre == '.':
        for k in range(1, cnt+1):
            C[-k][j] = cnt

ans = 0
for i in range(H):
    for j in range(W):
        if R[i][j] and C[i][j]:
            area = R[i][j]+C[i][j]-1
            if ans < area:
                ans = area
print(ans)

Fixed submission:
H, W, *SS = open(0).read().split()
H, W = int(H), int(W)

R = [[0]*(W) for _ in [0]*(H)]
C = [[0]*(W) for _ in [0]*(H)]

for i, S in enumerate(SS):
    cnt = 0
    pre = S[0]
    for j, s in enumerate(S):
        if s == '.':
            cnt += 1
        else:
            if pre == '.':
                for k in range(1, cnt+1):
                    R[i][j-k] = cnt
                cnt = 0
        pre = s
    if pre == '.':
        for k in range(1, cnt+1):
            R[i][-k] = cnt

for j in range(W):
    cnt = 0
    pre = SS[0][j]
    for i in range(H):
        s = SS[i][j]
        if s == '.':
            cnt += 1
        else:
            if pre == '.':
                for k in range(1, cnt+1):
                    C[i-k][j] = cnt
                cnt = 0
        pre = s
    if pre == '.':
        for k in range(1, cnt+1):
            C[-k][j] = cnt

ans = 0
for i in range(H):
    for j in range(W):
        if R[i][j] and C[i][j]:
            area = R[i][j]+C[i][j]-1
            if ans < area:
                ans = area
print(ans)