Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02689 (python)

Fixed submission:
N, M = map(int, input().split())  #数字
H = list(map(int, input().split()))#リスト
A = [list(map(int, input().split())) for i in range(M)]  #数字、複数行複数列

good = [True]*N
for i, j in A:
    i -= 1
    j -= 1
    if H[i] < H[j]:
        good[i] = False
    if H[i] > H[j]:
        good[j] = False
    if H[i] == H[j]:
        good[i] = False
        good[j] = False

print(good.count(True))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())  #数字
H = list(map(int, input().split()))#リスト
A = [list(map(int, input().split())) for i in range(M)]  #数字、複数行複数列

good = [True]*N
for i in range(M):
    left = H[A[i][0] - 1]
    right = H[A[i][1] - 1]
    if left < right:
        good[A[i][0]] = False
    if left > right:
        good[A[i][1]] = False
    if left == right:
        good[A[i][0]] = False
        good[A[i][1]] = False

print(good.count(True))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())  #数字
H = list(map(int, input().split()))#リスト
A = [list(map(int, input().split())) for i in range(M)]  #数字、複数行複数列

good = []
bad = []
for i in range(M):
    left = H[A[i][0] - 1]
    right = H[A[i][1] - 1]
    if left < right:
        good.append(A[i][1])
        bad.append(A[i][0])
    if left > right:
        good.append(A[i][0])
        bad.append(A[i][1])
    if left == right:
        bad.append(A[i][0])
        bad.append(A[i][1])

#print(set(good))
#print(set(bad))

lonely = H - set(good) - set(bad)

#print(len(lonely))
#print(len(good))
print(len(set(good))+ len(lonely))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())  #数字
H = list(map(int, input().split()))#リスト
A = [list(map(int, input().split())) for i in range(M)]  #数字、複数行複数列

good = []
bad = []
for i in range(len(A)):
    if H[A[i][0] - 1] < H[A[i][1] - 1]:
        good.append(A[i][1])
        bad.append(A[i][0])
    if H[A[i][0] - 1] > H[A[i][1] - 1]:
        good.append(A[i][0])
        bad.append(A[i][1])
    if H[A[i][0] - 1] == H[A[i][1] - 1]:
        bad.append(A[i][0])
        bad.append(A[i][1])

#print(set(good))
#print(set(bad))

lonely = []
for i in range(1, N + 1):
    lonely.append(i)

for i in set(good):
    lonely.remove(i)

for i in set(bad):
    lonely.remove(i)

#print(len(lonely))
#print(len(good))
print(len(set(good))+ len(lonely))
Problem p02712 (python)

Fixed submission:
n = int(input())  #スペース抜きの複数行,１文字ずつ
A = []

for i in range(1, n + 1):
    if i % 15 == 0:
        A.append(0)
    elif i % 3 == 0:
        A.append(0)
    elif i % 5 == 0:
        A.append(0)
    else:
        A.append(i)

print(sum(A))

Buggy submission (verdict: Runtime Error):
N = int(input())  #スペース抜きの複数行,１文字ずつ
 
A = []
for i in range(1,N):
#    print(i)
    if i % 3 == 0:
        A.append(0)
    elif i % 5 == 0:
		A.append(0)
    else:
        A.append(i)
 
print(sum(A))
Problem p02777 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# f_inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	ST = input()
	ST = ST[:-1]
	STS = ST.split()
	A,B = inputMap()
	U = input()
	U = U[:-1]

	if U == STS[0]:
		A -= 1
	else:
		B -= 1

	print("{} {}".format(A,B))

if __name__ == "__main__":
	main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# f_inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	A = inputList()

	A.sort()

	for i,val in enumerate(A):
		if i == 0:
			continue
		if val == A[i-1]:
			print("NO")
			sys.exit()

	print("YES")

if __name__ == "__main__":
	main()
Problem p02859 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	r = inputInt()
 
	a = r*r
	print(a)


if __name__ == "__main__":
	main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

ef main():
	r = inputInt()
 
	a = r*r
	print(a)


if __name__ == "__main__":
	main()
Problem p02659 (python)

Fixed submission:
from decimal import Decimal, ROUND_FLOOR

A, B = input().split()
A = Decimal(A)
B = Decimal(B)
res = A * B
print(res.quantize(Decimal("1"), rounding=ROUND_FLOOR))

Buggy submission (verdict: Runtime Error):
import math

A, B = input().split()
A = int(A)
B = math.floor(B)
res = A * B
print(res)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
res = A * B
print(int(res))
Problem p02676 (python)

Fixed submission:
k = input()
s = input()

if len(s) <= int(k):
  print(s)
else:
  print(s[0:int(k)] + "...")

Buggy submission (verdict: Runtime Error):
k = input()
s = input()

if len(s) <= int(k):
  print(s)
else:
  print(s[0:k] + "...")
Problem p03252 (python)

Fixed submission:
s = input()
t = input()

go = []
back = []
g = []
b = []
def has_duplicates(seq):
    return len(seq) != len(set(seq))


for i in range(len(s)):
  go.append(s[i]+t[i])
  back.append(t[i]+s[i])

go_l = set(go)
back_l = set(back)
go = list(go_l)
back = list(back_l)

#print(go)
#print(back)

for i in range(len(go)):
  g.append(go[i][0])
  b.append(back[i][0])
  
#print(g)
#print(b)
  
ansg = has_duplicates(g)
ansb = has_duplicates(b)

if ansg == True or ansb == True:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
s_l = set(s)
t_l = set(t)
s = list(s_l)
t = list(t_l)
go = []
back = []
def has_duplicates(seq):
    return len(seq) != len(set(seq))


for i in range(len(s)):
  go.append(s[i])
  back.append(t[i])
  
ansg = has_duplicates(go)
ansb = has_duplicates(back)

if ansg == True or ansb == True:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
a = list(map(int,input().split()))
x = a[0]
y = a[1]

n = a[0]
count = 0

while n <= y:
  n = n << 1
  count += 1
  
print(str(count))
Problem p02773 (python)

Fixed submission:
import collections
n = int(input())
s = []
for _ in range(n):
    s.append(input())

c = collections.Counter(s)
m = c.most_common()[0]

ans = []
for _c in c.items():
    if _c[1] == m[1]:
        ans.append(_c[0])

for v in sorted(ans):
    print(v)

Buggy submission (verdict: Runtime Error):
n=int(input())
l=[]
L=[]
for _ in range(n):
  s=input()
  l.append(s)
import collections
c = collections.Counter(l)

for i in range(n):
  L.append(c.most_common()[i][0])
  if i!=n-1:
    if c.most_common()[i][1] != c.most_common()[i+1][1]:
      break
L.sort()
L=' '.join(L)
print(L)
Problem p02847 (python)

Fixed submission:
s = input()
if s=="SUN":
  print(7)
elif s=="MON":
  print(6)
elif s=="TUE":
  print(5)
elif s=="WED":
  print(4)
elif s=="THU":
  print(3)
elif s=="FRI":
  print(2)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
a,b,x=map(int,input().split())
if a+b>x:
  print(0)
  exit()
k=(x-b)//a+1

while k>0:
  n=a*k+len(str(k))*b

  if n<=x:
    if n>10**9:
      print(10**9)
      exit()
    print(k)
    exit()
  k-=1
Problem p02859 (python)

Fixed submission:
r = int(input())

print(r*r)

Buggy submission (verdict: Runtime Error):
import math
x,y = map(int,input().split())
mod = 10**9+7

if (2*x-y)%3 != 0 or (-x+2*y)%3 != 0 or y>2*x or x>2*y:
  print(0)
  exit()
  
a = ((2*x-y)//3)%mod
b = ((-x+2*y)//3)%mod


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

print(cmb(a+b,a)%mod)
Problem p02881 (python)

Fixed submission:
import math

n = int(input())

k = math.ceil(math.sqrt(n))

for i in reversed(range(k+1)):
  if n/i == n//i:
    print(int(n/i + i -2))
    exit()

Buggy submission (verdict: Runtime Error):
import math

n = int(input())

k = math.floor(math.sqrt(n))

for i in reversed(range(k)):
  if n/i == n//i:
    print(int(n/i + i -2))
    exit()
Problem p03207 (python)

Fixed submission:
n = int(input())
l = [int(input()) for _ in [0]*n]

print(sum(l)-max(l)//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
li = input().split()
print(sum(li)-max(li)/2)

Buggy submission (verdict: Runtime Error):
n = int(input())
maximum = 0
li = list(map(int,input().split()))
for i in range(n):
  if li[i] > maximum:
    maximum = li[i]
    s = i
  
sum = 0
for i in range(n):
  sum += li[i]
sum -= li[s]/2

print(sum)
Problem p03242 (python)

Fixed submission:
n=input()
n=n.replace('1','x')
n=n.replace('9','1')
n=n.replace('x','9')
print(n)

Buggy submission (verdict: Runtime Error):
n=int(input())
for i in range(3):
  n[i] = 10-n[i]
print(n)

Buggy submission (verdict: Runtime Error):
n=input()
for i in range(3):
  n[i] = 10-n[i]
print(n)
Problem p03250 (python)

Fixed submission:
li=list(map(int,input().split()))
li.sort()
print(li[0]+li[1]+li[2]*10)

Buggy submission (verdict: Runtime Error):
import collections
s=input()
t=input()
s = collections.Count(s)
t = collections.Count(t)
if sorted(s.values()) == sorted(t.values()):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
li = map(int(input().split()))
li.sort()
print(li[0]*10+li[1]+li[2])
Problem p03272 (python)

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

print(a-b+1)

Buggy submission (verdict: Runtime Error):
a,b = map(int,input())

print(a-b+1)
Problem p03317 (python)

Fixed submission:
import math

n,k = map(int,input().split())

print(math.ceil((n-1)/(k-1)))

Buggy submission (verdict: Runtime Error):
import math

n,k = map(int,input().split())
li = [int(i) for i in input().split()]
a = li.index(4)
k -= 1
n -= 1
left = math.ceil(a/k)
right = math.ceil((n-a)/k)
print(left+right)
Problem p02891 (python)

Fixed submission:
s=input()
k=int(input())
if len(s)==1:
  print(k//2)
else:
  ans=0
  chg=0
  for i in range(1,len(s)):
    if chg==0 and s[i-1]==s[i]:
      ans+=1
      chg=1
    else:
      chg=0
  ans2=1
  chg2=1
  for i in range(1,len(s)):
    if chg2==0 and s[i-1]==s[i]:
      ans2+=1
      chg2=1
    else:
      chg2=0
  if s[0]!=s[-1] or chg==1:
    print(k*ans)
  elif chg2==0:
    print((k-1)*ans2+ans)
  else:
    print(ans*((k+1)//2)+ans2*(k//2))

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
ans=0
chg=0
for i in range(1,len(s)):
  if chg==0 and s[i-1]==s[i]:
    ans+=1
    chg=1
  else:
    chg=0
ans2=1
chg2=1
for i in range(1,len(s)):
  if chg==0 and s[i-1]==s[i]:
    ans2+=1
    chg2=1
  else:
    chg2=0
if s[0]!=s[1]:
  print(k*ans)
else:
  print(k*min(ans,ans2))
Problem p03011 (python)

Fixed submission:
p,q,r=map(int,input().split())

print(min([p+q,q+r,r+p]))

Buggy submission (verdict: Runtime Error):
p,q,r=map(int,input().split())

print(min([p+q,q+r,r+p])
Problem p03038 (python)

Fixed submission:
from collections import defaultdict
from collections import Counter
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
AA=dict(Counter(A))
D=defaultdict(int)
for i in range(m):
  b,c=map(int,input().split())
  D[c]+=b
for x in AA.keys():
  D[x]+=AA[x]
D=sorted(D.items(),key=lambda x:x[0],reverse=True)
ans,tot=0,0
for x,y in D:
  if tot+y<=n:
    ans+=x*y
    tot+=y
  else:
    ans+=x*(n-tot)
    tot+=n-tot
  if tot==n:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
D=defaultdict(int)
for i in range(m):
  b,c=map(int,input().split())
  D[c]+=b
D=sorted(D.items(),key=lambda x:x[0],reverse=True)
DD=[0]*n
ct=0
for x,y in D:
  for i in range(y):
    DD[i+ct]+=x
  ct+=y
ans=0
for i in range(n):
  ans+=max(A[i],DD[i])
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
D=dict()
for i in range(m):
  b,c=map(int,input().split())
  D[c]=b
D=sorted(D.items(),key=lambda x:x[0],reverse=True)
DD=[0]*n
ct=0
for x,y in D:
  for i in range(y):
    DD[i+ct]+=x
  ct+=y
ans=0
for i in range(n):
  ans+=max(A[i],DD[i])
print(ans)
Problem p03053 (python)

Fixed submission:
import sys
input = sys.stdin.readline
h,w=map(int,input().split())
A=[[False]*(w+2) for _ in range(h+2)]
chk,chk2=[],[]
for i in range(h):
  s=input()
  for j in range(w):
    A[i+1][j+1]=(s[j]==".")
    if s[j]=="#":
      chk.append((i+1,j+1))
ans=0
d=((1,0),(0,1),(-1,0),(0,-1))
while chk:
  for cx,cy in chk:
    for dx, dy in d:
      if A[cx+dx][cy+dy]==True:
        chk2.append((cx+dx,cy+dy))
        A[cx+dx][cy+dy]=False
  if chk2:
    ans+=1
  chk=chk2
  chk2=[]
print(ans)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B=[]
for i in range(w):
  for j in range(h):
    if A[i][j]=="#":
      B.append([i,j])
ans=0
for i in range(w):
  for j in range(h):
    if [i,j] not in B:
      d=min(abs(i-b[0])+abs(j-b[1]) for b in B)     
      ans=max(d,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B,T=set(),set()
for i in range(w):
  for j in range(h):
    T.add((i,j))
    if A[i][j]=="#":
      B.add((i,j))
T-=B
count=0
while len(T)>0:
  C=set()
  for b in B:
    if b[0]>0:
      C.add((b[0]-1,b[1]))
    if b[1]<w-1:
      C.add((b[0],b[1]+1))
    if b[0]<h-1:
      C.add((b[0]+1,b[1]))
    if b[1]>0:
      C.add((b[0],b[1]-1))
  T-=C
  B=C
  count+=1
print(count)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
B=set()
for i in range(w):
  for j in range(h):
    if A[i][j]=="#":
      B.add((i,j))
count=0
while len(B)<h*w:
  C=set()
  for b in B:
    if b[0]>0:
      C.add((b[0]-1,b[1]))
    if b[1]<w-1:
      C.add((b[0],b[1]+1))
    if b[0]<h-1:
      C.add((b[0]+1,b[1]))
    if b[1]>0:
      C.add((b[0],b[1]-1))
  B=B.union(C)
  count+=1
print(count)
Problem p03077 (python)

Fixed submission:
n=int(input())
A=[int(input()) for i in range(5)]
print(5+(n-1)//min(A))

Buggy submission (verdict: Runtime Error):
n,a,b,c,d,e=[int(input()) for i in range(6)]
dist=[n,0,0,0,0,0]
move=[a,b,c,d,e,0]
t=0
for while dist[5]<n:
  dist_t=[max(0,dist[0]-move[0])]
  for j in range(1,6):
    dist_t.append(max(0,dist[j]-move[j])+min(dist[j-1],move[j-1]))
  t=t+1
  dist=dist_t
print(t)
Problem p03201 (python)

Fixed submission:
import bisect
import collections
def f(n):
  return n.bit_length()
n=int(input())
A=[int(i) for i in input().split()]
D=dict(collections.Counter(A))
C=sorted(list(D.keys()))
ans=0
for i in range(len(C)):
  pair=2**f(C[-(i+1)])-C[-(i+1)]
  k=bisect.bisect_left(C,pair)
  if C[k]==pair:
    if k==len(C)-(i+1):
      ans+=D[pair]//2
      D[pair]%=2
    else:
      aa=min(D[pair],D[C[-(i+1)]])
      ans+=aa
      D[pair]-=aa
      D[C[-(i+1)]]-=aa
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
A=[int(i) for i in input().split()]
B=[]
for a in A:
  B.append(a)
A.sort(reverse=True)
count=0
for i in range(n):
  cur=A[i]
  if cur in B:
    k=int(math.log2(cur))+1
    pair=2**k-cur
    if pair in B:
      B.remove(pair)
      B.remove(cur)
      count+=1
print(count)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
A=[int(i) for i in input().split()]
B=[]
for a in A:
  B.append(a)
A.sort(reverse=True)
count=0
for i in range(n):
  cur=A[i]
  if cur in B:
    k=int(math.log2(cur))+1
    pair=2**k-cur
    if pair in B:
      B.remove(pair)
      count+=1
print(count)
Problem p03253 (python)

Fixed submission:
import collections
import math
n,m=map(int,input().split())
flag=0
P=[]
p=m
while flag==0:
  cur=p
  for i in range(2,int(p**0.5)+1):
    if p%i==0:
      P.append(i)
      p//=i
      break
  if p==cur:
    P.append(p)
    flag=1
c=collections.Counter(P)
Primes=set(P)
def f(i):
  return math.factorial(i)
def fn(i):
  return f(n+i-1)//(f(n-1)*f(i))%(10**9+7)
ans=1
for p in Primes:
  ans*=fn(c[p])
  ans%=(10**9+7)
print(1 if m==1 else ans)

Buggy submission (verdict: Runtime Error):
import collections
import math
n,m=map(int,input().split())
flag=0
P=[]
p=m
while flag==0:
  cur=p
  for i in range(2,int(p**0.5)+1):
    if p%if==0:
      P.append(i)
      p//=i
      break
  if p==cur:
    P.append(p)
    flag=1
c=collections.Counter(P)
Primes=set(P)
def f(i):
  return math.factorial(i)
def fn(i):
  return f(n+i-1)//(f(n-1)*f(i))
ans=1
for p in Primes:
  ans*=fn(c[p])
print(ans)
Problem p03295 (python)

Fixed submission:
n,m=map(int,input().split())
AB=[]
append=AB.append
for i in range(m):
  a,b=map(int,input().split())
  append([a,b])
AB.sort(key=lambda x:x[1])
c,ans=0,0
for a,b in AB:
  if a>=c:
    ans+=1
    c=b
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
AB=[]
append=AB.append
for i in range(m):
  a,b=map(int,input().split())
  append([ra,b])
AB.sort(key=lambda x:x[1])
c,ans=0,0
for a,b in AB:
  if a>=c:
    ans+=1
    c=b
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
AB=[]
for i in range(m):
  a,b=map(int,input().split())
  AB.append([a,b])
AB.sort()
AB.append([float('inf'),float('inf')])
ans,reset,left,right=0,1,0,float('inf')
for i in range(m)t:
    right=min(right,AB[i][1])
    left=AB[i][0]
    if right==left+1 and left!=AB[i+1][0]:
      ans+=1
      right=float('inf')
if right!=float('inf'):
  ans+=1
print(ans)
Problem p03315 (python)

Fixed submission:
s=input()
print(s.count("+")-s.count("-"))

Buggy submission (verdict: Runtime Error):
print(input().count("+")-input().count("-"))
Problem p03426 (python)

Fixed submission:
h,w,d=map(int,input().split())
D=dict()
for i in range(h):
  A=[int(i) for i in input().split()]
  for j in range(w):
    D[A[j]]=[i+1,j+1]
def Dist(x,y):
  return abs(D[x][0]-D[y][0])+abs(D[x][1]-D[y][1])
T=[[0 for _ in range((h*w)//d)] for _ in range(d)]
for i in range(d):
  for j in range((h*w)//d):
    if i+1+d*(j+1)>h*w:
      continue
    elif j==0:
      T[i][j]=Dist(i+1,i+1+d)
    else:  
      T[i][j]=T[i][j-1]+Dist(i+1+d*j,i+1+d*(j+1))
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  x=l%d
  if r==x:
    print(0)
  elif l==x and x!=0:
    print(T[x-1][(r-x)//d-1])
  elif l==x and x==0:
    print(T[x-1][(r-x)//d-2])
  else:
    ll=(l-x)//d-1
    rr=(r-x)//d-1
    if x==0:
      ll-=1
      rr-=1
    print(T[x-1][rr]-T[x-1][ll])

Buggy submission (verdict: Runtime Error):
h,w,d=map(int,input().split())
D=dict()
for i in range(h):
  A=[int(i) for i in input().split()]
  for j in range(w):
    D[A[j]]=[i+1,j+1]
def Dist(x,y):
  return abs(D[x][0]-D[y][0])+abs(D[x][1]-D[y][1])
T=[[0 for _ in range(h*w)] for _ in range(h*w)]
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  ans=0
  rep=(r-l)//d
  for j in range(rep):
    if T[l+j*d][l+(j+1)*d]!=0:
      ans+=T[l+j*d][l+(j+1)*d]
    else:
      ans+=Dist(l+j*d,l+(j+1)*d)
      T[l+j*d][l+(j+1)*d]=Dist(l+j*d,l+(j+1)*d)
  print(ans)
Problem p03805 (python)

Fixed submission:
import itertools
n,m=map(int,input().split())
A=[]
for i in range(m):
  a,b=map(int,input().split())
  A.append([a,b])
N=[int(i+2) for i in range(n-1)]
def f(list,n):
  path=0
  if [1,list[0]] in A:
    path+=1
  for i in range(1,n-1):
    if [list[i],list[i-1]] in A or [list[i-1],list[i]] in A:
      path+=1
  if path==n-1:
    return 1
  else:
    return 0  
ans=0
for p in itertools.permutations(N,n-1):
  ans+=f(list(p),n)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n,m=map(int,input().split())
A=[]
for i in range(n):
  a,b=map(int,input().split())
  A.append([a,b])
N=[int(i+2) for i in range(n-1)]
def f(list,n):
  path=0
  if [1,list[0]] in A:
    path+=1
  for i in range(1,n-1):
    if [list[i],list[i-1]] in A or [list[i-1],list[i]] in A:
      path+=1
  if path==n-1:
    return 1
  else:
    return 0  
ans=0
for p in itertools.permutations(N,n-1):
  ans+=f(list(p),n)
print(ans)