Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(m)]
    a.sort()
    INF = 10 ** 18
    dp = [INF for i in range(n)]
    dp[0] = 0
    for l, r, c in a:
        tp = dp[l - 1] + c
        for i in range(r - 1, l - 1, -1):
            if dp[i] == INF:
                dp[i] = min(dp[i], tp)
            elif tp < dp[i]:
                dp[i] = tp
            else:
                break
    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(m)]
    a.sort()
    INF = 10 ** 18
    dp = [INF for i in range(n)]
    dp[0] = 0
    for l, r, c in a:
        if dp[l - 1] == INF:
            print(-1)
            return None
        tp = dp[l - 1] + c
        for i in range(r - 1, l - 1, -1):
            if dp[i] == INF:
                dp[i] = tp
            elif tp < dp[i]:
                dp[i] = tp
            else:
                break
    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(m)]
    a.sort()
    dp = [10 ** 18 for i in range(n)]
    dp[0] = 0
    for l, r, c in a:
        tp = dp[l - 1] + c
        for i in range(l - 1, r):
            dp[i] = min(dp[i], tp)
    if dp[-1] == 10 ** 18:
        print(-1)
    else:
        print(dp[-1])


main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(m)]
    a.sort()
    INF = 10 ** 18
    dp = [INF for i in range(n)]
    dp[0] = 0
    for l, r, c in a:
        if dp[l - 1] == INF:
            print(-1)
            return None
        tp = dp[l - 1] + c
        for i in range(r - 1, l - 1, -1):
            if dp[i] == INF:
                dp[i] = tp
            elif tp < dp[i]:
                dp[i] = tp
            else:
                break
    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


main()

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
a.sort()
dp = [10 ** 18 for i in range(n)]
dp[0] = 0
for l, r, c in a:
    for i in range(l - 1, r):
        dp[i] = min(dp[i], dp[l - 1] + c)
if dp[-1] == 10 ** 18:
    print(-1)
else:
    print(dp[-1])


Fixed submission:
def main():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(m)]
    a.sort()
    INF = 10 ** 18
    dp = [INF for i in range(n)]
    dp[0] = 0
    for l, r, c in a:
        if dp[l - 1] == INF:
            print(-1)
            return None
        tp = dp[l - 1] + c
        for i in range(r - 1, l - 1, -1):
            if dp[i] == INF:
                dp[i] = tp
            elif tp < dp[i]:
                dp[i] = tp
            else:
                break
    if dp[-1] == INF:
        print(-1)
    else:
        print(dp[-1])


main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lr = [list(map(int,input().split())) for _ in range(n)]
lr.sort()

def fan(lr):
    lmax = lr[-1][0]
    rl = [lr[i][1] for i in range(len(lr))]
    rmax = min(rl)
    return max(rmax-lmax+1,0)
res = 0
for i in range(1,n):
    lr1 = lr[:i]
    lr2 = lr[i:]
    res = max(res,fan(lr1)+fan(lr2))
print(res)

Fixed submission:
N = int(input())
LR = [list(map(int, input().split())) for _ in range(N)]
maxl = 1
minr = 10**9+1
maxdis = 0
for i in range(N):
    if maxl < LR[i][0]:
        maxl = LR[i][0]
    if minr > LR[i][1]:
        minr = LR[i][1]
    if LR[i][1] - LR[i][0] > maxdis:
        maxdis = LR[i][1] - LR[i][0]

res = maxdis+1 + max(0, minr - maxl+1)

LR.sort(key=lambda x: x[1])
LR.sort(key=lambda x: x[0])

minb = 10**9+5
for i in range(N-1, -1, -1):
    minb = min(minb, max(0, LR[i][1]-maxl+1))
    LR[i].append(minb)
for i in range(N-1):
    res = max(res, max(0, minr - LR[i][0]+1)+LR[i+1][2])
print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = []
for _ in range(n):
    s.append(input())
check = []
testc = 1000
for i in range(n):
    test = 0
    for c in s[i]:
        test += int(c)
    if test == testc:
        check.append(i)
    elif test < testc:
        check.clear()
        testc = test
        check.append(i)

res = -1
for i in check:
    tres = 1
    flag = [-2 for _ in range(n)]

    flag[i] = 1
    que = [i]
    while que:
        target = que.pop()
        for j in range(n):
            if s[target][j] == "1":
                if flag[j] == -2:
                    flag[j] = flag[target] + 1
                    que.append(j)
                elif flag[j] != flag[target] + 1 and flag[j] != flag[target] - 1:
                    tres = -1
                    break
        if tres == -1:
            break
    if tres == -1:
        continue
    else:
        res = max(res, max(flag))

print(res)


Fixed submission:
s = input()
k = int(input())
if len(s) == 1:
    print(k // 2)
else:

    def counts(s):
        count = 0
        for i in range(len(s) - 1):

            if s[i] == s[i + 1]:
                count += 1
                s = s[: i + 1] + "." + s[i + 2 :]
        return count

    res1 = counts(s)
    res2 = counts(s * 2)
    res3 = counts(s * 3)
    if res3 - res2 == res2 - res1:
        print(res1 + (res2 - res1) * (k - 1))
    else:
        if k % 2 == 1:
            print(res2 * (k // 2) + res1)
        else:
            print(res2 * (k // 2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = []
for _ in range(n):
    s.append(input())
check = []
testc = 1000
for i in range(n):
    test = 0
    for c in s[i]:
        test += int(c)
    if test == testc:
        check.append(i)
    elif test < testc:
        check.clear()
        testc = test
        check.append(i)

res = -1
if testc > 1:
    check = check[0]

for i in check:
    tres = 1
    flag = [-2 for i in range(n)]

    flag[i] = 1
    que = [i]
    while que:
        target = que.pop()
        for j in range(n):
            if s[target][j] == "1":
                if flag[j] == -2:
                    flag[j] = flag[target] + 1
                    que.append(j)
                elif flag[j] != flag[target] + 1 and flag[j] != flag[target] - 1:
                    tres = -1
                    break
        if tres == -1:
            break

    if tres == -1:
        continue
    else:
        res = max(res, max(flag))

print(res)


Fixed submission:
import collections

n = int(input())
s = []
for _ in range(n):
    ch = input()
    s.append([int(c) for c in ch])


def graph(i, n, s):
    flag = [-2 for _ in range(n)]
    flag[i] = 1
    que = collections.deque([i])
    while que:
        target = que.popleft()
        for j in range(n):
            if s[target][j] == 1:
                if flag[j] == -2:
                    flag[j] = flag[target] + 1
                    que.append(j)
                elif flag[j] != flag[target] + 1 and flag[j] != flag[target] - 1:
                    return [-1, -1]
    mf = max(flag)
    return [flag.index(mf), mf]


r1 = graph(0, n, s)
if r1[0] == -1:
    print(-1)
else:
    res = r1[1]
    for i in range(1, n):
        r = graph(i, n, s)
        res = max(res, r[1])
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(1, n + 1):
    l.append([a[i - 1], i])

l.sort()

res = str(l[0][1])
for i in range(1, n):
    res = res + " " + str(l[i][1])
print(res)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(1, n + 1):
    l.append([a[i - 1], i])

l.sort()

print(" ".join([str(l[i][1]) for i in range(0, n)]))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(1, n + 1):
    l.append([a[i - 1], i])

l.sort()

res = str(l[0][1])
for i in range(1, n):
    res = res + " " + str(l[0][i])
print(res)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(1, n + 1):
    l.append([a[i - 1], i])

l.sort()

print(" ".join([str(l[i][1]) for i in range(0, n)]))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(1, n + 1):
    l.append([i, a[i - 1]])

l.sort(key=lambda x: x[1])

res = str(l[0][0])
for i in range(1, n):
    res = res + " " + str(l[i][0])
print(res)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(1, n + 1):
    l.append([a[i - 1], i])

l.sort()

print(" ".join([str(l[i][1]) for i in range(0, n)]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
a = list(map(int, input().split()))
col_num = 1

l = []
for i in range(1, n + 1):
    l.append([i, a[i - 1]])

ln = np.array(l)

lna = ln[np.argsort(ln[:, col_num])]

res = str(lna[0][0])
for i in range(1, n):
    res = res + " " + str(lna[i][0])
print(res)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(1, n + 1):
    l.append([a[i - 1], i])

l.sort()

print(" ".join([str(l[i][1]) for i in range(0, n)]))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(1, n + 1):
    l.append([i, a[i - 1]])

l.sort(key=lambda x: x[1])

res = str(l[0][0])
for i in range(1, n):
    res = res + " " + str(l[i][0])
print(res)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

l = []
for i in range(1, n + 1):
    l.append([a[i - 1], i])

l.sort()

print(" ".join([str(l[i][1]) for i in range(0, n)]))
Buggy python submission (verdict: Time Limit Exceeded):
import collections

def main():
    s=input()
    t=input()
    n = len(s)
    cs = collections.Counter(s)
    ct = collections.Counter(t)

    for sct in ct.keys():
        if cs[sct] == 0:
            return -1
    l = 0
    lc = 0
    for c in t:
        while c != s[l]:
            l += 1
            if l == n:
                l = 0
                lc += 1
        l += 1
        if l == n:
            l = 0
            lc += 1

    return lc * n + l

print(main())

Fixed submission:
import collections
import bisect

def main():
    s=input()
    t=input()
    s = s*2
    n = len(s)
    cs = collections.Counter(s)
    ct = collections.Counter(t)
    for sct in ct.keys():
        if cs[sct] == 0:
            return -1
    dc = collections.defaultdict(list)
    for i in range(n):
        dc[s[i]].append(i+1)
    res = 0
    ptl = 0
    for i in range(len(t)):
        tl = dc[t[i]][bisect.bisect_left(dc[t[i]],ptl+1)]
        res += tl - ptl
        ptl = tl - n//2 if tl > n//2 else tl
    return res

print(main())
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lists = []
result = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

sortedlist.sort()
for i in range(0, N):
    for j in range(i + 1, N):
        if sortedlist[i] == sortedlist[j]:
            result += 1
        else:
            break

print(result)


Fixed submission:
import math

N = int(input())
lists = []
result = 0
tempres = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

sortedlist.sort()
for i in range(0, N):
    if tempres != 0:
        tempres -= 1
        result += tempres
        continue

    for j in range(i + 1, N):
        if sortedlist[i] == sortedlist[j]:
            tempres += 1
        else:
            break
    result += tempres

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
lists = []
result = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

for i in range(0, N):
    for j in range(i + 1, N):
        if sortedlist[i] == sortedlist[j]:
            result += 1

print(result)


Fixed submission:
import math

N = int(input())
lists = []
result = 0
tempres = 0
for i in range(N):
    lists.append(input())

sortedlist = []
for i in range(0, N):
    sortedlist.append(sorted(lists[i]))

sortedlist.sort()
for i in range(0, N):
    if tempres != 0:
        tempres -= 1
        result += tempres
        continue

    for j in range(i + 1, N):
        if sortedlist[i] == sortedlist[j]:
            tempres += 1
        else:
            break
    result += tempres

print(result)
Buggy python submission (verdict: Runtime Error):
import heapq

n,m = map(int,input().split())
lb = [[] for _ in range(10**5)]
for _ in range(n):
    a,b = map(int,input().split())
    lb[a].append(b)
res = 0
q = []
heapq.heapify(q)
for i in range(1,m+1):
    for b in lb[i]:
        heapq.heappush(q,b * (-1))
    if q:
        res += heapq.heappop(q) * (-1)

print(res)

Fixed submission:
import heapq

n,m = map(int,input().split())
lb = [[] for _ in range(10**5+5)]
for _ in range(n):
    a,b = map(int,input().split())
    lb[a].append(b)
res = 0
q = []
heapq.heapify(q)
for i in range(1,m+1):
    for b in lb[i]:
        heapq.heappush(q,b * (-1))
    if q:
        res += heapq.heappop(q) * (-1)

print(res)

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

n,m = map(int,input().split())
lb = []
for _ in range(n):
    lb.append(list(map(int,input().split())))
res = 0
q = []
heapq.heapify(q)
for i in range(1,m+1):
    for b in lb:
        if b[0] == i:
            heapq.heappush(q,b[1] * (-1))
    if q:
        res += heapq.heappop(q) * (-1)

print(res)

Fixed submission:
import heapq

n,m = map(int,input().split())
lb = [[] for _ in range(10**5+5)]
for _ in range(n):
    a,b = map(int,input().split())
    lb[a].append(b)
res = 0
q = []
heapq.heapify(q)
for i in range(1,m+1):
    for b in lb[i]:
        heapq.heappush(q,b * (-1))
    if q:
        res += heapq.heappop(q) * (-1)

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
from collections import deque
n=int(input())
a=[int(input()) for _ in range(n)]

q=deque()

for sa in a:
    lq = list(q)
    t = bisect.bisect_left(lq,sa)
    if t ==0:
        q.appendleft(sa)
    else:
        q[t-1] = sa

print(len(q))

Fixed submission:
import bisect
from collections import deque
n=int(input())
a=[int(input()) for _ in range(n)]

q=[]
def bisect_desc(a,x):
    r = len(a)
    if r == 0:
        return 0
    l = 0
    while l != r:
        f = (l+r)//2
        if a[f] >= x:
            l = f+1
        else:
            r = f
    return l

for sa in a:
    t = bisect_desc(q,sa)
    if t ==len(q):
        q.append(sa)
    else:
        q[t] = sa

print(len(q))
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
cd = c * d / math.gcd(c, d)
print(int((b-a+1)-(b//c+b//d-(a-1)//c-(a-1)//d)+(b//(cd)-(a-1)//(cd))))

Fixed submission:
a,b,c,d = map(int,input().split())
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)
cd = lcm(c,d)
print(int((b-a+1)-(b//c+b//d-(a-1)//c-(a-1)//d)+(b//(cd)-(a-1)//(cd))))
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

n = int(input())
a = []
res = ('Yes')
for i in range(n):
    a.append(list(map(int,input().split())))

a.sort(key=itemgetter(1))
for i in range(0,n):
    suma = 0
    for j in range(0,i+1):
        suma += a[j][0]
    if suma > a[i][1]:
        res = ('No')
        break


print(res)

Fixed submission:
from operator import itemgetter

n = int(input())
a = []
res = ('Yes')
for i in range(n):
    a.append(list(map(int,input().split())))

a.sort(key=itemgetter(1))
suma = 0
for i in range(0,n):
    suma += a[i][0]
    if suma > a[i][1]:
        res = ('No')
        break


print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod = 10**9+7
dp = [[0 for j in range(m)]for i in range(n)]
for i in range(m):
    if s[0] ==t[i]:
        dp[0][i] = 1
for i in range(n):
    if s[i] ==t[0]:
        dp[i][0] = 1

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            sumdp = 0
            for k in range(i):
                for l in range(j):
                    sumdp += dp[k][l]
            dp[i][j] = (sumdp + 1) % mod
res = 1
for i in range(n):
    for j in range(m):
        res += dp[i][j]
        res %= mod
print(res)

Fixed submission:
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod = 10**9+7
dp = [[0 for j in range(m)]for i in range(n)]
for i in range(m):
    if s[0] ==t[i]:
        dp[0][i] = 1
for i in range(n):
    if s[i] ==t[0]:
        dp[i][0] = 1

sumdp = [[0 for j in range(m)]for i in range(n)]
if s[0] ==t[0]:
    sumdp[0][0] =1
for i in range(m-1):
    sumdp[0][i+1] =sumdp[0][i]
    if s[0] == t[i+1]:
        sumdp[0][i+1] += 1
for i in range(n-1):
    sumdp[i+1][0]=sumdp[i][0]
    if s[i+1] ==t[0]:
        sumdp[i+1][0] += 1

for i in range(n-1):
    for j in range(m-1):
        if s[i+1] == t[j+1]:
            dp[i+1][j+1] = (sumdp[i][j] + 1) % mod
        sumdp[i+1][j+1] = (sumdp[i][j+1]+sumdp[i+1][j] - sumdp[i][j]+dp[i+1][j+1])%mod
print((sumdp[n-1][m-1]+1)%mod)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
dp1 = [0] * (n+1)
for i in range(n+1):
    if i>=a[0]:
        dp1[i] = max(dp1[i],dp1[i-a[0]]+b[0])
    if i>=a[1]:
        dp1[i] = max(dp1[i],dp1[i-a[1]]+b[1])
    if i>=a[2]:
        dp1[i] = max(dp1[i],dp1[i-a[1]]+b[2])
n=dp1[n]
dp2 = [0] * (n+1)
for i in range(n+1):
    if i>=b[0]:
        dp2[i] = max(dp2[i],dp2[i-b[0]]+a[0])
    if i>=b[1]:
        dp2[i] = max(dp2[i],dp2[i-b[1]]+a[1])
    if i>=b[2]:
        dp2[i] = max(dp2[i],dp2[i-b[1]]+a[2])


print(dp2[n])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
dp1 = [n] * (n+1)
for i in range(n+1):
    if i>=a[0]:
        dp1[i] = max(dp1[i],dp1[i-a[0]]-a[0]+b[0])
    if i>=a[1]:
        dp1[i] = max(dp1[i],dp1[i-a[1]]-a[1]+b[1])
    if i>=a[2]:
        dp1[i] = max(dp1[i],dp1[i-a[2]]-a[2]+b[2])
n=dp1[n]
dp2 = [n] * (n+1)
for i in range(n+1):
    if i>=b[0]:
        dp2[i] = max(dp2[i],dp2[i-b[0]]-b[0]+a[0])
    if i>=b[1]:
        dp2[i] = max(dp2[i],dp2[i-b[1]]-b[1]+a[1])
    if i>=b[2]:
        dp2[i] = max(dp2[i],dp2[i-b[2]]-b[2]+a[2])


print(dp2[n])
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = []
for _ in range(m):
    a.append(int(input()))

if n == 1:
    print(1)
elif n == 2:
    if 1 in a:
        print(1)
    else:
        print(2)
else:
    if 1 in a:
        b1 = 0
    else:
        b1 = 1
    if 2 in a:
        b2 = 0
    else:
        b2 = b1+1

    b3 = b1 + b2

    for i in range(3,n+1):
        if i in a:
            b3 = 0
        else:
            b3 = b1+b2
        if b3 > 1000000007:
            b3 = b3 % 1000000007
        b1 = b2
        b2 = b3
        if b1==b2==0:
            break

    print(b3)

Fixed submission:
n,m = map(int,input().split())
a = [0]*(n+2)
for _ in range(m):
    a[int(input())] = -1

if n == 1:
    print(1)
elif n == 2:
    if a[1] == -1:
        print(1)
    else:
        print(2)
else:
    if a[1] == -1:
        b1 = 0
    else:
        b1 = 1
    if a[2] == -1:
        b2 = 0
    else:
        b2 = b1+1

    b3 = b1 + b2

    for i in range(3,n+1):
        if a[i] == -1:
            b3 = 0
        else:
            b3 = b1+b2
        if b3 > 1000000007:
            b3 = b3 % 1000000007
        b1 = b2
        b2 = b3
        if b1==b2==0:
            break

    print(b3)
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = ["#"*(w+2)]+["#"+input()+"#" for _ in range(h)]+["#"*(w+2)]
res = 0
def migi(i,j):
    if s[i][j+1] == ".":
        return migi(i,j+1)+1
    else:
        return 0
def hidari(i,j):
    if s[i][j-1] == ".":
        return hidari(i,j-1)+1
    else:
        return 0
def ue(i,j):
    if s[i-1][j] == ".":
        return ue(i-1,j)+1
    else:
        return 0
def shita(i,j):
    if s[i+1][j] == ".":
        return shita(i+1,j)+1
    else:
        return 0
    
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == ".":
            res = max(res,migi(i,j)+hidari(i,j)+ue(i,j)+shita(i,j)+1)
            if res == h+w-1:break

print(res)

Fixed submission:
h,w = map(int,input().split())
s = ["#"*(w+2)]+["#"+input()+"#" for _ in range(h)]+["#"*(w+2)]
res = 0
l = [[0 for _ in range(w+2)] for _ in range(h+2)]
r = [[0 for _ in range(w+2)] for _ in range(h+2)]
d = [[0 for _ in range(w+2)] for _ in range(h+2)]
u = [[0 for _ in range(w+2)] for _ in range(h+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
       if s[i][j]==".":
           l[i][j]=l[i][j-1]+1 
           d[i][j]=d[i-1][j]+1 
for i in range(h,0,-1):
    for j in range(w,0,-1):
       if s[i][j]==".":
           r[i][j]=r[i][j+1]+1 
           u[i][j]=u[i+1][j]+1 


for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == ".":
            res = max(res,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
            if res == h+w-1:break

print(res)

Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
res = 0
def migi(i,j):
    if j >= w-1:
        return 0
    if s[i][j+1] == ".":
        return migi(i,j+1)+1
    else:
        return 0
def hidari(i,j):
    if j <= 0:
        return 0
    if s[i][j-1] == ".":
        return hidari(i,j-1)+1
    else:
        return 0
def ue(i,j):
    if i <= 0:
        return 0
    if s[i-1][j] == ".":
        return ue(i-1,j)+1
    else:
        return 0
def shita(i,j):
    if i >= h-1:
        return 0
    if s[i+1][j] == ".":
        return shita(i+1,j)+1
    else:
        return 0
    
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            res = max(res,migi(i,j)+hidari(i,j)+ue(i,j)+shita(i,j)+1)
            if res == h+w-1:break

print(res)

Fixed submission:
h,w = map(int,input().split())
s = ["#"*(w+2)]+["#"+input()+"#" for _ in range(h)]+["#"*(w+2)]
res = 0
l = [[0 for _ in range(w+2)] for _ in range(h+2)]
r = [[0 for _ in range(w+2)] for _ in range(h+2)]
d = [[0 for _ in range(w+2)] for _ in range(h+2)]
u = [[0 for _ in range(w+2)] for _ in range(h+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
       if s[i][j]==".":
           l[i][j]=l[i][j-1]+1 
           d[i][j]=d[i-1][j]+1 
for i in range(h,0,-1):
    for j in range(w,0,-1):
       if s[i][j]==".":
           r[i][j]=r[i][j+1]+1 
           u[i][j]=u[i+1][j]+1 


for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == ".":
            res = max(res,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
            if res == h+w-1:break

print(res)
Buggy python submission (verdict: Runtime Error):
l=input()
n = len(l)
mod = 10**9+7

p3 = [1]
for _ in range(len(l)+5):
    p3.append((p3[-1]*3)%mod)

def dfs(k,f):
    if k == n:
        return 1
    if not f:
        return p3[n-k]
    if l[k] == "1":
        return (dfs(k+1,False)+dfs(k+1,True)*2)%mod
    else:
        return dfs(k+1,True)%mod

print(dfs(0,True))

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

l=input()
n = len(l)
mod = 10**9+7

p3 = [1]
for _ in range(len(l)+5):
    p3.append((p3[-1]*3)%mod)

def dfs(k,f):
    if k == n:
        return 1
    if not f:
        return p3[n-k]
    if l[k] == "1":
        return (dfs(k+1,False)+dfs(k+1,True)*2)%mod
    else:
        return dfs(k+1,True)%mod

print(dfs(0,True))