Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, k = LI()
    ps = LI()
    sum_ = [0]
    for i in range(1, 1000+1):
        sum_.append(sum_[i-1] + i)
    kitai = [ke / (i + 1) for i, ke in enumerate(sum_[1:])]
    kitai2 = [kitai[i-1] for i in ps]
    ans = []
    for i in range(n-k):
        if i == 0:
            ans.append(sum(kitai2[0:0+k]))
        else:
            ans.append(ans[i-1] - kitai2[i-1] + kitai2[i+k-1])
    print(max(ans))



if __name__ == '__main__':
    main()

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, k = LI()
    ps = LI()
    sum_ = [0]
    for i in range(1, 1000+2):
        sum_.append(sum_[i-1] + i)
    kitai = [ke / (i + 1) for i, ke in enumerate(sum_[1:])]
    kitai2 = [kitai[i-1] for i in ps]
    ans = []
    for i in range(n-k+1):
        if i == 0:
            ans.append(sum(kitai2[0:k]))
        else:
            ans.append(ans[i-1] - kitai2[i-1] + kitai2[i+k-1])
    print(max(ans))




if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, k = LI()
    ps = LI()
    sum_ = [0]
    for i in range(1, 1000+1):
        sum_.append(sum_[i-1] + i)
    kitai = [k / (i + 1) for i, k in enumerate(sum_[1:])]
    kitai2 = [kitai[i-1] for i in ps]
    ans = []
    for i in range(n-k):
        ans.append(sum(kitai2[i:i+k]))
    print(max(ans))



if __name__ == '__main__':
    main()

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n, k = LI()
    ps = LI()
    sum_ = [0]
    for i in range(1, 1000+2):
        sum_.append(sum_[i-1] + i)
    kitai = [ke / (i + 1) for i, ke in enumerate(sum_[1:])]
    kitai2 = [kitai[i-1] for i in ps]
    ans = []
    for i in range(n-k+1):
        if i == 0:
            ans.append(sum(kitai2[0:k]))
        else:
            ans.append(ans[i-1] - kitai2[i-1] + kitai2[i+k-1])
    print(max(ans))




if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    t1, t2 = LI()
    a1, a2 = LI()
    b1, b2 = LI()

    if a1 < b1:
        tmp = b1
        b1 = a1
        a1 = tmp

        tmp = b2
        b2 = a2
        a2 = tmp

    l1 = (a1 - b1) * t1
    l2 = (a2 - b2) * t2
    l3 = l1 + l2

    if l3 == 0:
        print("infinity")
        return
    if l3 > 0:
        print(0)
        return
    ans = 1
    if l1 % (-l3) == 0:
        print(ans + 2 * (l1 // (-l3)) - 1)
        return
    print(ans + 2 * (l1 // (-l3)))






if __name__ == '__main__':
    main()

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    a_s = LI()
    d = [0, 0, 0]
    ans = 1
    for i in a_s:
        flag = True
        tmp = 0
        for index, j in enumerate(d):
            # print(i, j)
            if j == i:
                tmp += 1
                if flag:
                    d[index] += 1
                    flag = False
        ans = ans * tmp % MOD
        # print(d, tmp, i, ans)
    print(ans)





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

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ls = LI()
    ls = sorted(ls)
    ans = 0
    for i in range(n):
        for j in range(i):
            ans += j - (bisect.bisect_right(ls[:j], ls[i] - ls[j]))

            # ans += a
            # print(ls[i], ls[j], bisect.bisect_left(ls[:j], ls[i] - ls[j]))
            # if ls[i] < ls[j] + ls[h]:
            #     # print(ls[i], ls[j], ls[h])

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
import bisect

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ls = LI()
    ls = sorted(ls)
    ans = 0
    for i in range(n):
        for j in range(i):
            ans += j - (bisect.bisect_right(ls[:j], ls[i] - ls[j]))

            # ans += a
            # print(ls[i], ls[j], bisect.bisect_left(ls[:j], ls[i] - ls[j]))
            # if ls[i] < ls[j] + ls[h]:
            #     # print(ls[i], ls[j], ls[h])

    print(ans)

if __name__ == '__main__':
    main()

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

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ls = LI()
    ls = sorted(ls, reverse=True)
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            for h in range(j+1, n):
                # print(ls[i], ls[j], ls[h])
                if ls[i] < ls[j] + ls[h]:
                    # print(ls[i], ls[j], ls[h])
                    ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
import bisect

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ls = LI()
    ls = sorted(ls)
    ans = 0
    for i in range(n):
        for j in range(i):
            ans += j - (bisect.bisect_right(ls[:j], ls[i] - ls[j]))

            # ans += a
            # print(ls[i], ls[j], bisect.bisect_left(ls[:j], ls[i] - ls[j]))
            # if ls[i] < ls[j] + ls[h]:
            #     # print(ls[i], ls[j], ls[h])

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    print(int(n / 2 * (n - 1)))

if __name__ == '__main__':
    main()

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return str(sys.stdin.readline())

def main():
    s = S()
    t = S()
    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    print(n * (n - 1)　/ 2)

if __name__ == '__main__':
    main()

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    print(n  * (n - 1) // 2)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    print(int((n / 2 * (n - 1)))

if __name__ == '__main__':
    main()

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    print(n  * (n - 1) // 2)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

a, b, c, d = LI()
a = a-1

cd = int(c * d / gcd(c, d))
cs = b // c - a // c
ds = b // d - a // d
cds = b // (cd) - a // (cd)
print(b - a - cs - ds + cds)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict

num  = S()
for i in range(3):
    if num[i] == num[i+1]:
        print("Bad")
        break
else:
    print("Good")
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict
import math

a, b, c, d = LI()
a = a-1

cd = int(c * d / math.gcd(c, d))
cs = b // c - a // c
ds = b // d - a // d
cds = b // (cd) - a // (cd)
print(b - a - cs - ds + cds)


Fixed submission:
import sys
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

a, b, c, d = LI()
a = a-1

cd = int(c * d / gcd(c, d))
cs = b // c - a // c
ds = b // d - a // d
cds = b // (cd) - a // (cd)
print(b - a - cs - ds + cds)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import default

x ,a = LI()
if x>= a:
    print(10)
else:
    print(0)

  


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

x ,a = LI()
if x>= a:
    print(10)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict
import bisect

n, q = LI()
ds = []
stx = []
ans = [-1 for i in range(q)]
for i in range(n):
    s, t, x = LI()
    stx.append((s, t, x))
for i in range(q):
    d = SI()
    ds.append(d)
# stx = sorted(stx, key=lambda x: x[2])
for s, t, x in stx:
    sx = s - x
    tx = t - x
    i1 = bisect.bisect_left(ds, sx)
    i2 = bisect.bisect_left(ds, tx)
    for i in range(i1, i2):
        if ans[i] == -1 or ans[i] > x:
            ans[i] = x
for i in ans:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

a, i = LI()
print(int((a * 3 + i) / 2))
Buggy python submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            # divisors.append(i)
            if i != n // i and i != (n // i - 1) :
                divisors.append(n//i - 1)
    return divisors

n = int(input())
print(sum(make_divisors(n)))

Fixed submission:
n, k = [int(i) for i in input().split()]
print(n - k + 1)

Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
print n - k + 2

Fixed submission:
n, k = [int(i) for i in input().split()]
print(n - k + 1)

Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
return n - k + 1

Fixed submission:
n, k = [int(i) for i in input().split()]
print(n - k + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
answer = 1
for i in range(n):
    answer *= A[i]
if answer > pow(10,18):
    print('-1')
else:
    print(answer)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
answer = 1
flag = 1
zero = 0
for i in range(n):
    answer *= A[i]
    if answer > pow(10,18):
        flag = 0
        break
if 0 in A:
    print(0)
elif flag ==0:
    print('-1')
else:
    print(answer)
Buggy python submission (verdict: Runtime Error):
n,m,x = map(int,input().split())
A = [[] for _ in range(n)]
for i in range(n):
    A[i] = list( map(int,input().split()) )
    
flag = 0
min_charge = 10**7

for i in range(2**n):
    which = format(i, '#010b')[-n:]
    
    #print(which,end = ':')
    
    charge = 0
    skill = [0 for _ in range(m)]
    for j in range(n):
        if which[j]=='1':
            charge += A[j][0]
            for k in range(m):
                skill[k]+=A[j][k+1]
    flag_skill = 1
    for l in range(m):
        if skill[l] < x:
            flag_skill = 0
    
    
    #print(skill,end=':')
    #print(charge,end=':')    
    
    if flag_skill ==1:
        min_charge = min(min_charge,charge)
    
    #print(flag_skill)

if min_charge == 10**7:
    print(-1)
else:
    print(min_charge)

Fixed submission:
n,m,x = map(int,input().split())
A = [[] for _ in range(n)]
for i in range(n):
    A[i] = list( map(int,input().split()) )
    
flag = 0
min_charge = 10**7

for i in range(2**n):
    which = format(i, '#020b')[-n:]
    
    #print(which,end = ':')
    
    charge = 0
    skill = [0 for _ in range(m)]
    for j in range(n):
        if which[j]=='1':
            charge += A[j][0]
            for k in range(m):
                skill[k]+=A[j][k+1]
    flag_skill = 1
    for l in range(m):
        if skill[l] < x:
            flag_skill = 0
    
    
    #print(skill,end=':')
    #print(charge,end=':')    
    
    if flag_skill ==1:
        min_charge = min(min_charge,charge)
    
    #print(flag_skill)

if min_charge == 10**7:
    print(-1)
else:
    print(min_charge)
Buggy python submission (verdict: Time Limit Exceeded):
n,x,y = map(int,input().split())
x,y = x-1,y-1

D = {}
for i in range(n):
    D[str(i+1)]=0
    
for i in range(n-1):
    for j in range(i+1,n):
        dist1 = j-i
        dist2 = abs(i-x) +1 + abs(j-y)
        dist = min(dist1,dist2)
        D[str(dist)] = D[str(dist)]+1


    
for i in range(1,n):
    print(D[str(i)])

Fixed submission:
n,x,y = map(int,input().split())
x,y = x-1,y-1

D = [0 for _ in range(n+1)]
    
for i in range(n-1):
    for j in range(i+1,n):
        dist1 = j-i
        dist2 = abs(i-x) +1 + abs(j-y)
        dist = min(dist1,dist2)
        D[dist] = D[dist]+1


    
for i in range(1,n):
    print(D[i])

Buggy python submission (verdict: Time Limit Exceeded):
n,x,y = map(int,input().split())
x,y = x-1,y-1
dist_list = []
for i in range(n-1):
    for j in range(i+1,n):
        dist1 = j-i
        dist2 = abs(i-x) +1 + abs(j-y)
        dist = min(dist1,dist2)
        dist_list.append(dist)

S = set(dist_list)
D = {}
for i in range(n):
    D[str(i+1)]=0
for i in range(len(dist_list)):
    D[str(dist_list[i])]=D[str(dist_list[i])]+1
    
for i in range(1,n):
    print(D[str(i)])

Fixed submission:
n,x,y = map(int,input().split())
x,y = x-1,y-1

D = [0 for _ in range(n+1)]
    
for i in range(n-1):
    for j in range(i+1,n):
        dist1 = j-i
        dist2 = abs(i-x) +1 + abs(j-y)
        dist = min(dist1,dist2)
        D[dist] = D[dist]+1


    
for i in range(1,n):
    print(D[i])
Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k = map(int,input().split())
p = list(map(int,input().split()))
p = np.array(p)
e = (p+1)/2
sum_e = []
sum_e.append(np.sum(e[:k]))
for i in range(n-k):
    sum_e.append(sum_e[-1]-e[i]+e[k+i])
print(max(sum_e))

Fixed submission:
import numpy as np
n,k = map(int,input().split())
p = list(map(int,input().split()))
p = np.array(p)
e = (p+1)/2
sum_e = []
sum_e.append(np.sum(e[:k]))
for i in range(n-k):
    sum_e.append(sum_e[-1]-e[i]+e[k+i])
print(max(sum_e))

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k = map(int,input().split())
p = list(map(int,input().split()))
p = np.array(p)
e = (p+1)/2
sum_e = []
sum_e.append(np.sum(e[:k]))
for i in range(n-k):
    sum_e.append(sum_e[-1]-e[i]+e[k+i])
print(max(sum_e))

Fixed submission:
import numpy as np
n,k = map(int,input().split())
p = list(map(int,input().split()))
p = np.array(p)
e = (p+1)/2
sum_e = []
sum_e.append(np.sum(e[:k]))
for i in range(n-k):
    sum_e.append(sum_e[-1]-e[i]+e[k+i])
print(max(sum_e))
Buggy python submission (verdict: Runtime Error):
import numpy as np
n,m = map(int,input().split())
penalty = np.zeros(n)
did = np.zeros(n)
for i in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'WA':
        if did[p-1]==0:
            penalty[p-1] +=1
    else:
        did[p-1]=1
penalty = penalty*did
print(int(sum(did)),int(sum(penalty)))
    

Fixed submission:
n,m = map(int,input().split())
penalty = [0]*n
did = [0]*n
for i in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'WA':
        if did[p-1]==0:
            penalty[p-1] +=1
    else:
        did[p-1]=1
for i in range(n):
    penalty[i]*=did[i]
print(sum(did),sum(penalty))

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,m = map(int,input().split())
penalty = np.zeros(n)
done = np.zeros(n)
for i in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'WA':
        if done[p-1]==0:
            penalty[p-1] +=1
    else:
        done[p-1]=1
penalty = penalty*done
print(int(sum(done)),int(sum(penalty)))

Fixed submission:
n,m = map(int,input().split())
penalty = [0]*n
did = [0]*n
for i in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'WA':
        if did[p-1]==0:
            penalty[p-1] +=1
    else:
        did[p-1]=1
for i in range(n):
    penalty[i]*=did[i]
print(sum(did),sum(penalty))
Buggy python submission (verdict: Time Limit Exceeded):
import copy

def judge1(masu,h,w):
    if (masu[0]>=0)&(masu[0]<h)&(masu[1]>=0)&(masu[1]<w):
        return True
    else:
        return False
    
def judge2(masu,s):
    if s[masu[0]][masu[1]] == '.':
        return True
    else:
        return False
    
def tsugi(i,j,h,w,s2):
    ans=[]
    for masu in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
        if judge1(masu,h,w):
            if judge2(masu,s2):
                ans.append(masu)
    return ans
    


def solve(i,j,s,h,w):
    ma = 0
    s2 = copy.deepcopy(s)
    if s2[i][j]=='.':
        s2[i][j]='#'
        nex = tsugi(i,j,h,w,s2)
        flag=1
        while len(nex)!=0 :
            ma+=1
            #flag= 0
            nex2=[]
            for n in nex:
                nex2[len(nex2):] = tsugi(n[0],n[1],h,w,s2)
                s2[n[0]][n[1]]='#'
            nex = nex2
    return ma


h,w=map(int,input().split())
s = []
ma = 0
for i in range(h):
    s.append(list(input()))
for i in range(h):
    for j in range(w):
        ans = solve(i,j,s,h,w)
        ma = max(ma,ans)
print(ma)

Fixed submission:
import copy

def judge1(masu,h,w):
    if (masu[0]>=0)&(masu[0]<h)&(masu[1]>=0)&(masu[1]<w):
        return True
    else:
        return False
    
def judge2(masu,s):
    if s[masu[0]][masu[1]] == '.':
        return True
    else:
        return False
    
def tsugi(i,j,h,w,s2):
    ans=[]
    for masu in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:
        if judge1(masu,h,w):
            if judge2(masu,s2):
                ans.append(masu)
    return ans
    


def solve(i,j,s,h,w):
    ma = 0
    s2 = copy.deepcopy(s)
    if s2[i][j]=='.':
        s2[i][j]='#'
        nex = tsugi(i,j,h,w,s2)
        while len(nex)!=0 :
            ma+=1
            nex2=[]
            for n in nex:
                nex2[len(nex2):] = tsugi(n[0],n[1],h,w,s2)
                s2[n[0]][n[1]]='#'
            nex = set(nex2)
    return ma


h,w=map(int,input().split())
s = []
ma = 0
for i in range(h):
    s.append(list(input()))
for i in range(h):
    for j in range(w):
        ans = solve(i,j,s,h,w)
        ma = max(ma,ans)
print(ma)