Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,M = list(map(int,input().split()))

P=[]
for m in range(M):
    P.append(list(map(int,input().split())))

from itertools import combinations

ans=0
for c in combinations(range(M),N-1):
    visit = [1]
    P_visit=[]
    v=0
    start=visit[0]
    while v < 100:
        v+=1
        for c_ in c:
            if c_ in P_visit:
                continue
            if P[c_][0] == start:
                visit.append(P[c_][1])
                start = P[c_][1]
                P_visit.append(c_)
                
            elif P[c_][1] == start:
                visit.append(P[c_][0])
                start = P[c_][0]
                P_visit.append(c_)
    
    if len(set(visit))== N:
        ans += 1
print(ans)

Fixed submission:
from itertools import permutations

N,M = list(map(int,input().split()))
P=[]
for m in range(M):
    P.append(list(map(int,input().split())))

ad={}
for _ in range(1,N+1):
    ad[_]=set()
    
for p in P:
    ad[p[0]].add(p[1])
    ad[p[1]].add(p[0])

ans=0
for p in permutations(range(2,N+1),N-1):
    ans_flag=True
    start=1
    for p_ in p:
        end=p_
#         print(start,end ,end in ad[start])
        if end not in ad[start]:
#             print('break')
            ans_flag=False
            break
        start=p_
        
    if ans_flag==True:
        ans+=1
        
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
    
A=check.copy()
A.sort()

check=[0]*N

for idx in range(N%2,N,2):
    check[idx]=idx+1
    check[idx+1]=idx+1

ans=0

if check == A:
    if N % 2 == 0:
        ans=(2**(N//2))%(10**9+7)
    elif N % 2 != 0:
        ans=(2**((N-1)//2))%(10**9+7)
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
   
A.sort()

check=[0]*N

for idx in range(N%2,N,2):
    check[idx]=idx+1
    check[idx+1]=idx+1

ans=0

if check == A:
    if N % 2 == 0:
        ans=(2**(N//2))%(10**9+7)
    elif N % 2 != 0:
        ans=(2**((N-1)//2))%(10**9+7)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,x = list(map(int,input_[0].split()))

ans=0
if a!=b:
    A=(a-1)//x
    B=b//x

    ans=B-A

print(ans)

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

ans=0
if a!=b:
    A = (a-1)//x
    B = b//x

    ans = B - A
elif a==0 and b==0:
    ans=1
    
elif a==x and b==x:
    ans=1

print(ans)
Buggy python submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))
D = list(map(int,input().split()))

D_ = [_ for _ in range(10) if _ not in D]
D_.sort()

N_=N+1
break_flag=False
for s_ in D_:
    if break_flag:
        break
    elif s_ == 0:
        continue
    for p in product(D_,repeat=len(str(N_))-1):
        ans=int(str(s_)+''.join(map(str,p)))
        if N+1 <= ans:
            print(ans)
            break_flag=True
            break

Fixed submission:
from itertools import product
N,K = list(map(int,input().split()))
D = list(map(int,input().split()))

D_ = [_ for _ in range(10) if _ not in D]
D_.sort()

break_flag=False
for s_ in D_:
    if break_flag:
        break
    elif s_ == 0:
        continue
    for p in product(D_,repeat=len(str(N))-1):
        ans=int(str(s_)+''.join(map(str,p)))
        if N <= ans:
            print(ans)
            break_flag=True
            break
            
if break_flag==False:
    for s_ in D_:
        if break_flag:
            break
        elif s_ == 0:
            continue
        for p in product(D_,repeat=len(str(N))):
            ans=int(str(s_)+''.join(map(str,p)))
            if N <= ans:
                print(ans)
                break_flag=True
                break
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
Q = int(input())

for i in range(Q):
  BC = list(map(int, input().split()))
  B_i = BC[0]
  C_i = BC[1]
  for j in range(len(A)):
    if A[j] == B_i:
      A[j] = C_i
  A = sorted(A)
  print(sum(A))
  

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
dic = dict()
 
for i in A:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
 
ans = sum(A)
 
for i in range(Q):
    b, c = list(map(int, input().split()))
    x = 0
    if b in dic:
        x = dic.pop(b)
        if c in dic:    
            dic[c] += x
        else:
            dic[c] = x
    ans += x * (c-b)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
Q = int(input())

for i in range(Q):
  BC = list(map(int, input().split()))
  B_i = BC[0]
  C_i = BC[1]
  B_ind = []
  for j in range(len(A)):
    if A[j] == B_i:
      B_ind.append(j)
    if A[j] > B_i:
      break
  for k in B_ind:
    A[k] = C_i
  A = sorted(A)
  print(sum(A))
  

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
dic = dict()
 
for i in A:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
 
ans = sum(A)
 
for i in range(Q):
    b, c = list(map(int, input().split()))
    x = 0
    if b in dic:
        x = dic.pop(b)
        if c in dic:    
            dic[c] += x
        else:
            dic[c] = x
    ans += x * (c-b)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
#A = sorted(A)
Q = int(input())

def my_index_multi(l, x):
  return [i for i, _x in enumerate(l) if _x == x]

for i in range(Q):
  BC = list(map(int, input().split()))
  B_i = BC[0]
  C_i = BC[1]
  B_ind = my_index_multi(A, B_i)
  for j in B_ind:
    A[j] = C_i
  print(sum(A))
  
  

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
dic = dict()
 
for i in A:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
 
ans = sum(A)
 
for i in range(Q):
    b, c = list(map(int, input().split()))
    x = 0
    if b in dic:
        x = dic.pop(b)
        if c in dic:    
            dic[c] += x
        else:
            dic[c] = x
    ans += x * (c-b)
    print(ans)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
group=[]
number=[0 for i in range(N)]
A,B=map(int,input().split())
group.append([A,B])
number[0]=2


for i in range(M-1):
    A,B=map(int,input().split())
    flag=0
    for j in range(len(group)):
        new=[]
        if A in group[j]:
            flag=1
            if B not in group[j]:
                group[j].append(B)
                number[j]+=1
        elif B in group[j]:
            flag=1
            if A not in group[j]:
                group[j].append(A)
                number[j]+=1
                flag=1
    if flag==0:
        group.append([A,B])
        number[len(group)]=2

print(max(number))


Fixed submission:
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(m)]
root=[-1]*n

def find(x):
    if root[x]<0:
        return x
    else:
        root[x]=find(root[x])
        return root[x]
    
def unite(x,y):
    parent_x=find(x)
    parent_y=find(y)
    
    if parent_x==parent_y:
        return

    if parent_x>parent_y:
        parent_x,parent_y=parent_y,parent_x

    root[parent_x]+=root[parent_y]
    root[parent_y]=parent_x

def size(x):
    a=find(x)
    return -root[a]

for i in range(m):
    unite(AB[i][0]-1,AB[i][1]-1)

ans=0
for i in range(n):
    ans=max(ans,size(i))

print(ans)

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
group=[]
number=[0 for i in range(N)]
A,B=map(int,input().split())
group.append([A,B])
number[0]=2


for i in range(M-1):
    A,B=map(int,input().split())
    flag=0
    for j in range(len(group)):
        new=[]
        if A in group[j]:
            flag=1
            if B not in group[j]:
                group[j].append(B)
                number[j]+=1
        elif B in group[j]:
            flag=1
            if A not in group[j]:
                group[j].append(A)
                number[j]+=1
                flag=1
    if flag==0:
        group.append([A,B])
        number[len(group)]=2

print(max(number))


Fixed submission:
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(m)]
root=[-1]*n

def find(x):
    if root[x]<0:
        return x
    else:
        root[x]=find(root[x])
        return root[x]
    
def unite(x,y):
    parent_x=find(x)
    parent_y=find(y)
    
    if parent_x==parent_y:
        return

    if parent_x>parent_y:
        parent_x,parent_y=parent_y,parent_x

    root[parent_x]+=root[parent_y]
    root[parent_y]=parent_x

def size(x):
    a=find(x)
    return -root[a]

for i in range(m):
    unite(AB[i][0]-1,AB[i][1]-1)

ans=0
for i in range(n):
    ans=max(ans,size(i))

print(ans)
Buggy python submission (verdict: Runtime Error):
umber=list(map(int,input().split()))
H,W,K=number[0],number[1],number[2]
answer=0
nums=[]
for i in range(H):
    tmp=list(str(input()))
    nums.append(tmp)
count=0
for cowmask in range(1<<H):
    for rowmask in range(1<<W):
        count=0
        for x in range(H):
            for y in range(W):
                if (cowmask>>x)&1==0 and (rowmask>>y)&1==0 and nums[x][y]=="#":
                    count+=1
        if count==K:
            answer+=1
            
print(answer)

Fixed submission:
number=list(map(int,input().split()))
H,W,K=number[0],number[1],number[2]
M=[]
for i in range(H):
    tmp=list(input())
    M.append(tmp)
answer=0
for rowmask in range(1<<W):
    for cowmask in range(1<<H):
        count=0
        for x in range(H):
            for y in range(W):
                if (rowmask>>y)&1==0 and (cowmask>>x)&1==0 and M[x][y]=="#":
                    count+=1
        if count==K:
            answer+=1
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
number=list(map(int,input().split()))
N,M,K=number[0],number[1],number[2]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
i=len(A)
C=A
answer=0
l=M
if sum(A)>K:
    while sum(C)>=K:
        i-=1
        C=A[:i]
for j in range(len(C),0,-1):
    C=C[:j]
    while sum(B[:l])>K-sum(C):
        l-=1
        
    key=l+j
    answer=max(answer,key)
print(answer)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
number=list(map(int,input().split()))
N,M,K=number[0],number[1],number[2]
A=list(map(int,input().split()))
B=list(map(int,input().split()))
i=len(A)
C=A
answer=0
l=M
if sum(A)>K:
    while sum(C)>=K:
        i-=1
        C=A[:i]
for j in range(len(C),0,-1):
    C=C[:j]
    while sum(B[:l])>K-sum(C):
        l-=1
        
    key=l+j
    answer=max(answer,key)
print(answer)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
Buggy python submission (verdict: Runtime Error):
number=list(map(int,input().split()))
n,m,x=number[0],number[1],number[2]
books=[list(map(int,input().split())) for i in range(n)]
U=[x for i in range(m+1)]
U[0]=0
pattern=[]
answer=[]


for i in range(2**n):
    tmp=[False]*n
    for j in range(n):
        if (i>>j)&1:
            tmp[j]=True
    
    pattern.append(tmp)

for i in range(2**n):
    cost=0
    U=[x for i in range(m+1)]
    U[0]=0
    for j in range(n):
        if pattern[i][j]==True:
            cost+=books[j][0]
            for k in range(1,m+1):
                U[k]-=books[j][k]
                if max(U)==0:
                    answer.append(cost)
                    break
                    
print(min(answer))
                

Fixed submission:
number=list(map(int,input().split()))
n,m,x=number[0],number[1],number[2]
books=[list(map(int,input().split())) for i in range(n)]
U=[x for i in range(m+1)]
U[0]=0
pattern=[]
answer=[]


for i in range(2**n):
    tmp=[False]*n
    for j in range(n):
        if (i>>j)&1:
            tmp[j]=True
    
    pattern.append(tmp)

for i in range(2**n):
    cost=0
    U=[x for i in range(m+1)]
    U[0]=0
    for j in range(n):
        if pattern[i][j]==True:
            cost+=books[j][0]
            for k in range(1,m+1):
                U[k]-=books[j][k]
                if max(U)==0:
                    answer.append(cost)
                    break
                    
if answer==[]:
    print(-1)
else:
    print(min(answer))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
box=[]
count=0
for i in range(n):
    tmp=str(input())
    if tmp not in box:
        count+=1
        box.append(tmp)
        
print(count)

Fixed submission:
import collections
n=int(input())
box=[]
for i in range(n):
    tmp=str(input())
    box.append(tmp)
l=len(collections.Counter(box))
print(l)
Buggy python submission (verdict: Runtime Error):
nums=input()
print(nums.count(1))

Fixed submission:
number=list(map(int,input()))
print(number.count(1))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
flag=0
nums=list(map(int,input().split()))
cnt=0

while flag==0:
    for i in range(n):
        num=nums[0]/2
        key=nums[0]%2
        if key==1:
            flag==1
            break
        else:
            del nums[0]
            nums.append(num)
    if flag==0:
        cnt+=1
print(cnt)

Fixed submission:
n=int(input())
nums=list(map(int,input().split()))
cnt=0
flag=0
while flag is 0:
    for i in range(n):
        num=nums[0]/2
        key=nums[0]%2
        if key==1:
            flag=1
            break
        else:
            del nums[0]
            nums.append(num)
    if flag==0:
        cnt+=1

print(cnt)
Buggy python submission (verdict: Runtime Error):
X, Y, Z = input().split(' ')
print([Z, X, Y].join(' '))

Fixed submission:
X, Y, Z = input().split(' ')
print(' '.join([Z, X, Y]))
Buggy python submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline())
h = [int(hi) for hi in sys.stdin.readline().split(' ')]

cache = {}


def cost(current):
    c = cache.get(current, None)
    if c:
        return c

    if current == N - 1:
        c = 0
    elif current == N - 2:
        c = abs(h[current] - h[current + 1]) + cost(current + 1)
    else:
        c1 = abs(h[current] - h[current + 1]) + cost(current + 1)
        c2 = abs(h[current] - h[current + 2]) + cost(current + 2)
        c = min(c1, c2)

    cache[current] = c
    return c


print(cost(0))


Fixed submission:
import sys

N = int(sys.stdin.readline())
h = [int(hi) for hi in sys.stdin.readline().split(' ')]

dp = [1000000 * N] * N
dp[0] = 0

for i in range(N - 1):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
    if i < N - 2:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))

print(dp[-1])

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


N, his = sys.stdin.readlines()
N = int(N)
his = [int(hi) for hi in his.split(' ')]
his.append(100000)

cache = {}

def cost(frm):
    if frm == N - 1:
        return 0
    elif frm < N:
        c = cache.get(frm, None)
        if c:
            return c
        c = min(
            cost(frm + 1) + abs(his[frm] - his[frm + 1]),
            cost(frm + 2) + abs(his[frm] - his[frm + 2])
        )
        cache[frm] = c
        return c
    else:
        return 1000000

print(cost(0))

Fixed submission:
import sys

N = int(sys.stdin.readline())
h = [int(hi) for hi in sys.stdin.readline().split(' ')]

dp = [1000000 * N] * N
dp[0] = 0

for i in range(N - 1):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
    if i < N - 2:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

L = len(A)
total = 0

mod = 10**9+7

for x in range(L):
    tmp = 0
    for y in range(x+1, L):
        tmp += A[y]
    total += tmp*A[x]
print(total % mod)


Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

L = len(A)
total = 0
tmp = 0
mod = 10**9+7
for y in range(L):
    tmp += A[y]

for x in range(L):
    tmp -= A[x] 
    total += tmp*A[x]
print(total % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

L = len(A)
total = 0

mod = 10**9+7

for x in range(L):
    tmp = 0
    for y in range(x+1, L):
        tmp += A[y]
    total += tmp*A[x]
print(total % mod)


Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

L = len(A)
total = 0
tmp = 0
mod = 10**9+7
for y in range(L):
    tmp += A[y]

for x in range(L):
    tmp -= A[x] 
    total += tmp*A[x]
print(total % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

L = len(A)
total = 0
mod = 10**9+7

for x in range(L):
    for y in range(x+1, L):
        total += A[x]*A[y]
print(total % mod)


Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

L = len(A)
total = 0
tmp = 0
mod = 10**9+7
for y in range(L):
    tmp += A[y]

for x in range(L):
    tmp -= A[x] 
    total += tmp*A[x]
print(total % mod)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

total = 0

for x in range(len(A)):
    for y in range(x+1, len(A)):
        total += A[x]*A[y]
print(total % (10**9+7))


Fixed submission:
N = int(input())
A = [int(i) for i in input().split()]

L = len(A)
total = 0
tmp = 0
mod = 10**9+7
for y in range(L):
    tmp += A[y]

for x in range(L):
    tmp -= A[x] 
    total += tmp*A[x]
print(total % mod)
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
num_list = map(int, input().split())

ans = 1
max_ans = 10**18
for num in num_list:
    ans = ans * num

if ans > max_ans:
    ans = -1


print(ans)

Fixed submission:
n = input()
list = input().split()

ans = 1
max_ans = 10**18

if "0" in list:
    ans = 0
else:       
    for num in list:
        ans = ans * int(num)
        if ans > max_ans:
            ans = -1
            break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
flag = 0
A = 0
B = 0
for a in range(100000):
    for b in range(100000):
        if (a-10)**5 - (b-10)**5 == X:
            flag = 1
            A = a-10
            B = b-10
            break
        else:
            pass
    if flag == 1:
        break

print(A,B)

Fixed submission:
import time
X = int(input())
flag = 0
T_0 = time.time()

A = 0
B = 0
for a in range(2000):
    for b in range(2000):
        if (a-1000)**5 - (b-1000)**5 == X:
            flag = 1
            A = a-1000
            B = b-1000
            break
        else:
            pass
    if flag == 1:
        break
T_1 = time.time()

print(A,B)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = []
for _ in range(N):
    s = input()
    if s in L:
        pass
    else:
        L.append(s)

print(len(L))


Fixed submission:
N = int(input())
L = set()
for _ in range(N):
    s = input()
    if s in L:
        pass
    else:
        L.add(s)

print(len(L))
Buggy python submission (verdict: Runtime Error):
week = ['MON','TUE','WED','THU','FRI','SAT','SUN']
day = input()
ans = week.index('SUN')-week,index(day)
print(ans if ans!=0 else 7)

Fixed submission:
week = ['MON','TUE','WED','THU','FRI','SAT','SUN']
day = input()
ans = week.index('SUN')-week.index(day)
print(ans if ans!=0 else 7)

Buggy python submission (verdict: Runtime Error):
week = ['SUN','MON','TUE','WED','THU','FRI','SAT' ]
print(week[(week.index(input)+1)%7])

Fixed submission:
week = ['MON','TUE','WED','THU','FRI','SAT','SUN']
day = input()
ans = week.index('SUN')-week.index(day)
print(ans if ans!=0 else 7)
Buggy python submission (verdict: Runtime Error):
K,A,B = (int(x) for x in input().split())
ans = 1

if B-A>2:
    if K>= A-1:
        ans += A - 1
        K -= A - 1
        if K >= 2:
            ans = ans + (B - A) * ((unsigned long long)(K / 2));
            K = K % 2;

ans += K

print(ans)



Fixed submission:
K,A,B = (int(x) for x in input().split())
ans = 1

if B-A>2:
    if K>= A-1:
        ans += A - 1
        K -= A - 1
        if K >= 2:
            ans = ans + (B - A) * (K // 2)
            K = K % 2

ans += K

print(ans)
Buggy python submission (verdict: Runtime Error):
a = map(int,input().split())
cost = 0
for i in range(len(a)-1):
  cost += a[i+1]-a[i]
print(cost)

Fixed submission:
a = list(map(int,input().split()))
a = sorted(a)
cost = 0
for i in range(len(a)-1):
  cost += a[i+1]-a[i]
print(cost)

Buggy python submission (verdict: Runtime Error):
a = map(int,input().split())
cost = 0
for i in range(len(a)-1):
  cost += a[i+1]-a[i]
  
print(cost)

Fixed submission:
a = list(map(int,input().split()))
a = sorted(a)
cost = 0
for i in range(len(a)-1):
  cost += a[i+1]-a[i]
print(cost)
Buggy python submission (verdict: Runtime Error):
x = int(input())
b = int(input())
c = int(input())
x -= a
x = x- b*(x//b)
print(x)

Fixed submission:
x = int(input())
a = int(input())
b = int(input())
x -= a
x -= b*(x//b)
print(x)

Buggy python submission (verdict: Runtime Error):
x = int(input())
b = int(input())
c = int(input())
x -= a
x -= b*x//b
print(x)

Fixed submission:
x = int(input())
a = int(input())
b = int(input())
x -= a
x -= b*(x//b)
print(x)
Buggy python submission (verdict: Runtime Error):
m = input().split()
print(48-m)

Fixed submission:
m = int(input())
print(48-m)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
S = [ int(input()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j]=='#':

            continue
for h in range(H):
    l = ''
    for w in range(W):
        if S[h][w] == '#':
            l += '#'
        else:
            x = 0
            for dh in [ -1, 0, 1]:
                for dw in [-1, 0, 1]:
                    if 0 <= h + dh < H and 0 <= w + dw < W and S[h+dh][w+dw] == '#':
                        x += 1
            l += str(x)
    print(l)


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

for i in range(H):
    for j in range(W):
        if S[i][j]=='#':

            continue
for h in range(H):
    l = ''
    for w in range(W):
        if S[h][w] == '#':
            l += '#'
        else:
            x = 0
            for dh in [ -1, 0, 1]:
                for dw in [-1, 0, 1]:
                    if 0 <= h + dh < H and 0 <= w + dw < W and S[h+dh][w+dw] == '#':
                        x += 1
            l += str(x)
    print(l)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [input() for _ in range(n)]
sa = set(a)
res = 0
for i in sa:
    if a.count(i)%2!=0:
        res+=1

print(res)


Fixed submission:
N = int(input())

p = set()
for i in range(N):
    A = input()
    p ^= {A}

print(len(p))