ZhenlongDai/ACPR huggingface dataset:
Problem: p03178
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
k = int(input())
d = int(input())

li = list(map(int,(list(str(k)))))
leng = len(li)
mod = 10**9+7

dp1 = [0 for _ in range(d)]
dp2 = [0 for _ in range(d)]

mm1 = li[0]
for i in range(mm1):
    dp2[i%d] = 1

for i in range(1,leng):
    for j in range(0,10):
        for l in range(d):
            
            dp1[(l+j)%d] += dp2[l]
            dp1[(l+j)%d] %= mod

        
        if j<li[i]:
            dp1[(mm1+j)%d] += 1
            dp1[(mm1+j)%d] %= mod
    
    

    mm1 = (mm1+li[i])%d
    dp2 = [dp1[i] for i in range(d)]
    dp1 = [0 for _ in range(d)]
dp2[k%d]+=1

print((dp2[0]-1)%mod)   








Failing test case input:
98765432109876543210
6

Expected output:
419788043


Actual output:
419768115


Fixed submission (verdict: Accepted):
k = int(input())
d = int(input())

li = list(map(int,(list(str(k)))))
leng = len(li)
mod = 10**9+7

dp1 = [0 for _ in range(d)]
dp2 = [0 for _ in range(d)]

mm1 = li[0]
for i in range(mm1):
    dp2[i%d] += 1

for i in range(1,leng):
    for j in range(0,10):
        for l in range(d):
            
            dp1[(l+j)%d] += dp2[l]
            dp1[(l+j)%d] %= mod

        
        if j<li[i]:
            dp1[(mm1+j)%d] += 1
            dp1[(mm1+j)%d] %= mod
    
    mm1 = (mm1+li[i])%d
    dp2 = [dp1[i] for i in range(d)]
    dp1 = [0 for _ in range(d)]
dp2[sum(li)%d]+=1
print((dp2[0]-1)%mod)

Problem: p03178
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
K = input()
N = len(K)
D = int(input())
Y = [0] * D
P = 10**9+7
a = 0
for i in range(N):
    nY = [0] * D
    c = int(K[i])
    for j in range(10):
        for k in range(D):
            nk = (j+k)%D
            nY[nk] += Y[k]
        if j < c:
            nk = (j+a)%D
            nY[nk] = (nY[nk] + 1) % P
    
    a = (a+c) % D
    Y = nY
print((Y[0] - 1) % P)


Failing test case input:
98765432109876543210
15

Expected output:
674053666


Actual output:
674053665


Fixed submission (verdict: Accepted):
K = input()
N = len(K)
D = int(input())
Y = [0] * D
P = 10**9+7
a = 0
for i in range(N):
    nY = [0] * D
    c = int(K[i])
    for j in range(10):
        if j < c:
            nk = (j+a) % D
            nY[nk] = (nY[nk] + 1) % P

        for k in range(D):
            nk = (j+k) % D
            nY[nk] = (nY[nk] + Y[k]) % P
        
    a = (a+c) % D
    Y = nY
print((Y[0] - 1 + (a==0)) % P)
Problem: p02624
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
sum=0
for i in range(2,N+1):
    sum+=N
print(sum)    

Failing test case input:
01001001

Expected output:
7250050395922


Actual output:
1002002001000


Fixed submission (verdict: Accepted):
N=int(input())
sum=0
for j in range(1,N+1):
    sum+=((N
print(sum)

Problem: p02624
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
s=0
for i in range(1,int(n**0.5)+1):
  m=n
  s+=i*m*(m+1)
mx=n
for i in range(1,int(n**0.5)):
  mn=n
  s+=i*(i+1)*(mx*(mx+1)-mn*(mn+1))
  mx=mn
print(s)

Failing test case input:
01010001

Expected output:
7385501962172


Actual output:
514652179666309020


Fixed submission (verdict: Accepted):
n=int(input())
s=0
for i in range(1,int(n**0.5)+1):
  m=n
  s+=i*m*(m+1)
mx=n
for i in range(1,int((n-1)**0.5)+1):
  mn=max(n
  s+=i*(i+1)*(mx*(mx+1)-mn*(mn+1))
  mx=mn
print(s)
Problem: p00586
Buggy submission (Python3, verdict: Wrong Answer):
import sys
val = []
count = 0

for line in sys.stdin:
    for word in line.split():
        val.append(int(word))
    count = count + 1
    if count == 1:
        break

print (sum(val))

Failing test case input:
-1 2
0 2
011 5

Expected output:
1
2
16


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
val = []
result = [] 
count = 0

for line in sys.stdin:
    if line != '\n':
        for word in line.split():
            val.append(int(word))
        result.append(sum(val))
        val = []
        count = count + 1
    else:
        break

for x in result:
    print(x)

Problem: p00586
Buggy submission (Python3, verdict: Wrong Answer):
while True:
    try:
        print(sum(list(map(int,a.split()))))
    except:
        break

Failing test case input:
-1 5
0 4
001 43

Expected output:
4
4
44


Actual output:

Fixed submission (verdict: Accepted):
while True:
    try:
        print(sum(list(map(int,input().split()))))
    except:
        break

Problem: p00586
Buggy submission (Python3, verdict: Wrong Answer):
import sys
for line in sys.stdin:
    items = line.split()
    print( items[0] + items[1] )

Failing test case input:
0 0
-3 2
011 1

Expected output:
0
-1
12


Actual output:
00
-32
0111


Fixed submission (verdict: Accepted):
import sys
for line in sys.stdin:
    items = line.split()
    print( int(items[0]) + int(items[1]) )
Problem: p03638
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
h, w = map(int, input().split())
n = int(input().strip())
a = list(map(int, input().split()))
ans = []
tmp = []
for i in range(len(a)):
    tmp += [(i + 1) for _ in range(a[i])]
    if w <= len(tmp):
        ans.append(tmp[:w])
        tmp = tmp[w:]
odd = True
for elem in ans:
    if odd:
        print(*elem)
        odd = False
    else:
        print(*elem[::-1])
        odd = True


Failing test case input:
2 2
3
2 1 1

Expected output:
1 1
2 3

Actual output:
1 1
3 2


Fixed submission (verdict: Accepted):
h, w = map(int, input().split())
n = int(input().strip())
a = list(map(int, input().split()))
ans = []
tmp = []
for i in range(n):
    tmp += [(i + 1)] * a[i]
for i in range(len(tmp) 
    ans.append(tmp[i * w:(i + 1) * w])
odd = True
for elem in ans:
    if odd:
        print(*elem)
        odd = False
    else:
        print(*elem[::-1])
        odd = True
Problem: p03333
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
I,i,H=input,int,range
n,L,R,A,C=i(I()),[],[],0,0
for _ in H(n):l,r=map(i,I().split());L+=[l];R+=[r]
L=sorted(L)[::-1];R.sort()
for j in H(n):C+=(L[j]-R[j])*2;A=max(A,C)
print(A)

Failing test case input:
3
1 2
3 4
5 6

Expected output:
12

Actual output:
6


Fixed submission (verdict: Accepted):
I,i,H=input,int,range
n,L,R,A,C=i(I()),[0],[0],0,0
for _ in H(n):l,r=map(i,I().split());L+=[l];R+=[r]
L=sorted(L)[::-1];R.sort()
for j in H(n
print(A)
Problem: p00103
Buggy submission (Python3, verdict: Wrong Answer):
for i in range(int(input())):
    point = 0
    out = 0
    runner = [0, 0, 0]
    while True:
        event = input()
        if event == 'HIT':
            if runner[2] == 1:
                point += 1
                runner[2] = 0
            if runner[1] == 1:
                runner[2] = 1
                runner[1] = 0
            if runner[0] == 1:
                runner[1] = 1
                runner[0] = 0
            runner[0] = 1
        elif event == 'HOMERUN':
            point += (sum(runner)+1)
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break

Failing test case input:
2
HIT
OUT
HOMERUN
HIT
HIT
HOMERUN
HIT
OUT
HIT
HIT
HIT
HIT
OUT
HIT
HIT
OUT
HIT
OUT
OUT

Expected output:
7
0

Actual output:
11
0


Fixed submission (verdict: Accepted):
for i in range(int(input())):
    point = 0
    out = 0
    runner = [0, 0, 0]
    while True:
        event = input()
        if event == 'HIT':
            if runner[2] == 1:
                point += 1
                runner[2] = 0
            if runner[1] == 1:
                runner[2] = 1
                runner[1] = 0
            if runner[0] == 1:
                runner[1] = 1
                runner[0] = 0
            runner[0] = 1
        elif event == 'HOMERUN':
            point += (sum(runner)+1)
            runner = [0, 0, 0]
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break

Problem: p00103
Buggy submission (Python3, verdict: Wrong Answer):
for i in range(int(input())):
    point = 0
    out = 0
    runner = [0, 0, 0]
    while True:
        event = input()
        if event == 'HIT':
            if runner[2] == 1:
                point += 1
            if runner[1] == 1:
                runner[2] = 1
            if runner[0] == 1:
                runner[1] = 1
            runner[0] = 1
        elif event == 'HOMERUN':
            point += (sum(runner)+1)
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break

Failing test case input:
2
HIT
OUT
HOMERUN
HIT
HIT
HOMERUN
HIT
OUT
HIT
HIT
HIT
HIT
OUT
HIT
HIT
OUT
HIT
OUT
OUT

Expected output:
7
0

Actual output:
11
0


Fixed submission (verdict: Accepted):
for i in range(int(input())):
    point = 0
    out = 0
    runner = [0, 0, 0]
    while True:
        event = input()
        if event == 'HIT':
            if runner[2] == 1:
                point += 1
                runner[2] = 0
            if runner[1] == 1:
                runner[2] = 1
                runner[1] = 0
            if runner[0] == 1:
                runner[1] = 1
                runner[0] = 0
            runner[0] = 1
        elif event == 'HOMERUN':
            point += (sum(runner)+1)
            runner = [0, 0, 0]
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break
Problem: p03345
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B,C,K = map(int,input().split())
print((B - A)*(-1)**K)

Failing test case input:
1000110000 0000000010 1100000010 1000010100000000000

Expected output:
1000109990


Actual output:
-1000109990


Fixed submission (verdict: Accepted):
A,B,C,K=map(int,input().split());print((A-B)*(-1)**K)

Problem: p03345
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B,C,K=map(int,input().split())
print(A-B)


Failing test case input:
0101111000 1010101111 1101011101 1000111101101101011

Expected output:
908990111


Actual output:
-908990111


Fixed submission (verdict: Accepted):
A,B,C,K=map(int,input().split())
print((A-B)*((-1)**K))

Problem: p03345
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
A,B,C,K = map(int,input().split())
if abs(A-B) > 10**8:
    print("Unfair")
else:
    print((A-B)*(-1)**(K))

Failing test case input:
1110110000 1000010111 1011110111 1010001111001000000

Expected output:
110099889


Actual output:
Unfair


Fixed submission (verdict: Accepted):
A,B,C,K = map(int,input().split())
if abs(A-B) > 10**18:
    print("Unfair")
else:
    print((A-B)*(-1)**(K))

Problem: p03345
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,k = map(int, input().split())

x = a-b
if abs(x)>10**18:
    print('Unfair')
else:
    print(x * -1**k)


Failing test case input:
3 -5 1 2

Expected output:
8


Actual output:
-8


Fixed submission (verdict: Accepted):
a,b,c,k = map(int, input().split())

x = a-b
if abs(x)>10**18:
    print('Unfair')
else:
    print(x * (-1)**k)

Problem: p03345
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b, c, k = map(int, input().split())
print((k % 2) * (a - b))

Failing test case input:
0101111010 1010000110 1111100100 1000011101001100011

Expected output:
908889100


Actual output:
-908889100


Fixed submission (verdict: Accepted):
a, b, c, k = map(int, input().split())
print(((-1) ** k) * (a - b))

Problem: p03345
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,k=map(int,input().split());a=a-b*(-1**k%2);print(a)

Failing test case input:
0101111000 1010111111 1101011100 1000111101101101011

Expected output:
909000111


Actual output:
-909000111


Fixed submission (verdict: Accepted):
a,b,c,k=map(int,input().split());print((-1)**k*(a-b))

Problem: p03345
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b,c,k=map(int,input().split())
print((a-b)*(-1)**(k-1))

Failing test case input:
0001111110 1110000110 0011101101 1010001101001100000

Expected output:
-1108889000


Actual output:
1108889000


Fixed submission (verdict: Accepted):
a,b,c,k=map(int,input().split())
print((a-b)*(-1)**k)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from heapq import heappush, heappop, heapify
from bisect import bisect_right

pow2 = [2]
for i in range(29):
  pow2.append(pow2[-1]*2)

N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1

A = [-a for a in A]
heapify(A)
ans = 0
while A:
  a = - heappop(A)
  if d[a] == 0:
    continue
  pair = pow2[bisect_right(pow2, a)] - a
  if pair in d and d[pair] > 0:
    ans += 1
    d[pair] -= 1
    d[a] -= 1

print(ans)

Failing test case input:
5
2 4 25 5 10

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
from heapq import heappush, heappop, heapify
from bisect import bisect_right

pow2 = [2]
for i in range(29):
  pow2.append(pow2[-1]*2)

N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1

A = [-a for a in A]
heapify(A)
ans = 0
while A:
  a = - heappop(A)
  if d[a] == 0:
    continue
  pair = pow2[bisect_right(pow2, a)] - a
  if a == pair:
    if d[a] >= 2:
      d[a] -= 2
      ans += 1
  elif pair in d and d[pair] > 0:
    ans += 1
    d[pair] -= 1
    d[a] -= 1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
print(dic)
ans = 0

for a in A:
    small = (1<<(len(format(a+1,"b")))) - a
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a] = dic.get(a)-1
        dic[small] = dic.get(small)-1
        ans += 1
print(ans)


Failing test case input:
5
3 36 2 10 15

Expected output:
0


Actual output:
{36: 1, 15: 1, 10: 1, 3: 1, 2: 1}
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
ans = 0

for a in A:
    small = (1<<(len(format(a,"b")))) - a
    if small == a:
        if dic[a] >= 2:
            dic[a] -= 2
            ans += 1
        continue
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a] -= 1
        dic[small] -= 1
        ans += 1
print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_left
from collections import deque
 
N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
A = deque(A)
ans = 0
t_max = len(bin(A[-1])) - 2
for t in range(t_max, 0, -1):
    if len(A) < 2: break
    pow2 = 1 << t
    A_tmp = deque()
    while t == len(bin(A[-1])) - 2:
        idx = bisect_left(A, pow2 - A[-1])
        for _ in range(idx):
            A_tmp.append(A.popleft())
        if len(A) < 2: break
        if A[0] + A[-1] == pow2:
            A.popleft()
            ans += 1
        A.pop()
        if len(A) < 2: break
    A.extendleft(A_tmp)
                    
print(ans)


Failing test case input:
5
3 11 14 10 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from bisect import bisect_left, bisect_right
from collections import deque

N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
A = deque(A)
ans = 0
t_max = len(bin(A[-1])) - 2
for t in range(t_max, 0, -1):
    if len(A) < 2: break
    while len(bin(A[-1])) - 2 > t:
        A.pop()
        if len(A) < 2: break
    if len(A) < 2: break
    pow2 = 1 << t
    A_tmp = deque()
    while t == len(bin(A[-1])) - 2:
        r = A.pop()
        idx = bisect_left(A, pow2 - r)
        for _ in range(idx):
            A_tmp.appendleft(A.popleft())
        if len(A) == 0: break
        if A[0] + r == pow2:
            A.popleft()
            ans += 1
        if len(A) < 2: break
    A.extendleft(A_tmp)
                    
print(ans)

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict

def twosum(n):
  now = 1
  while n >= now:
    now *= 2
  return now - n
n=int(input())
a=sorted(list(map(int,input().split())))
d = defaultdict(int)
for i in a:
    d[i] += 1
ans = 0
for i in a[::-1]:
    if not d[i] > 0:
        continue
    find = twosum(i)
    if not d[find] > 0:
        continue
    ans += 1
    d[i] -= 1
    d[find] -= 1
print(ans)

Failing test case input:
5
2 6 24 6 16

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import defaultdict

def twosum(n):
  now = 1
  while n >= now:
    now *= 2
  return now - n
n=int(input())
a=sorted(list(map(int,input().split())))
d = defaultdict(int)
for i in a:
    d[i] += 1
ans = 0
for i in a[::-1]:
    d[i] -= 1
    find = twosum(i)
    if d[find] > 0 and d[i] >= 0:
        ans += 1
        d[find] -= 1
    else:
        d[i] += 1
print(ans)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split(" ")))
A.sort()
used = [0] * N
ans = 0
for i in range(N):
    if used[N-i-1] == 1:
        continue
    used[N-i-1] = 1
    it = 2
    mx = 2 * A[N-i-1]
    while it <= mx:
        it <<= 1
    while it != 1:
        target = (it - A[N-i-1])
        ng,ok = -1 , N-1
        while abs(ok - ng) > 1:
            mid = (ok+ng) 
            if A[mid] < target or (target == A[mid] and used[mid] == 1):
                ng = mid
            else:
                ok = mid
        if target == A[ok] and used[ok] == 0:
            ans += 1
            used[ok] = 1
            break

        it >>= 1


print(ans)

Failing test case input:
5
4 3 4 3 10

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split(" ")))
A.sort()
used = [0] * N
pow2_set = reversed([ 1<<i for i in range(36)])
ans = 0
for pow2 in pow2_set:
    l,r = 0,N-1
    while l < r:
        if A[l] + A[r] < pow2:
            l += 1
        elif A[l] + A[r] == pow2:
            if used[l] == 0 and used[r] == 0:
                ans += 1
                used[l],used[r] = 1,1
            else:
                if used[l] == 1:
                    l += 1
                if used[r] == 1:
                    r -= 1
        else:
            r -= 1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
cnt = Counter(a)
ans = 0

def make(x):
    num = 1
    while num <= x:
        num *= 2
    return num

for i in range(n):
    cnt[a[i]] -= 1
    x = make(a[i])
    if cnt[x - a[i]] > 0:
        ans += 1
        cnt[x - a[i]] -= 1
    
print(ans)

Failing test case input:
5
1 3 45 6 13

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
cnt = Counter(a)
ans = 0

def make(x):
    num = 1
    while num <= x:
        num *= 2
    return num

for i in range(n):
    x = make(a[i])
    if cnt[x - a[i]] > 0 and cnt[a[i]] > 0 and x != 2 * a[i]:
        ans += 1
        cnt[x - a[i]] -= 1
        cnt[a[i]] -= 1
    elif x == 2 * a[i] and cnt[a[i]] > 1:
        ans += 1
        cnt[a[i]] -= 2

print(ans)
Problem: p03201
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = list(map(int,ipt().split()))
    a.sort(reverse=True)
    d = defaultdict(int)
    ans = 0
    for i in a:
        if d[i]:
            ans += 1
        nl = len(format(i,"b"))
        d[(i^(2**(nl)-1))+1] += 1

    print(ans)
    return

if __name__ == '__main__':
    main()


Failing test case input:
5
3 11 14 5 1

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = list(map(int,ipt().split()))
    a.sort(reverse=True)
    d = defaultdict(int)
    ans = 0
    for i in a:
        if d[i]:
            ans += 1
            d[i] -= 1
        else:
            nl = len(format(i,"b"))
            d[(i^(2**(nl)-1))+1] += 1

    print(ans)
    return

if __name__ == '__main__':
    main()

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict

def get_smallest_power_of_2_over_N(N):
    i=2
    while i<N:
        i*=2
    return i

N = int(input())
A = list(map(int,input().split()))


A = sorted(A)

ans=0
D=defaultdict(int)

for a in A:
    D[a]+=1

for i in reversed(range(N)):
    if D[A[i]]<=0:
        continue
    else:
        pair_val = get_smallest_power_of_2_over_N(A[i]) - A[i]
        if D[pair_val]>0:
            ans+=1
            D[pair_val]-=1
        D[A[i]]-=1

print(ans)


Failing test case input:
5
2 3 38 1 1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter

def get_smallest_power_of_2_over_N(N):
    i=2
    while i<=N:
        i*=2
    return i

N = int(input())
A = list(map(int,input().split()))


A = sorted(A)

ans=0
D=Counter(A)

for i in reversed(range(N)):
    pair_val = get_smallest_power_of_2_over_N(A[i]) - A[i]
    if D[A[i]]<=0:
        continue
    elif pair_val==A[i] and D[pair_val]>=2 or pair_val!=A[i] and  D[pair_val]>=1:
        ans+=1
        D[pair_val]-=1
        D[A[i]]-=1

print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A.sort()
d = defaultdict(int)
for a in A:
    d[a] += 1

cnt = 0
for a in reversed(A):
    pair = (1 << a.bit_length()) - a
    if a == pair:
        if d[a] >= 2:
            cnt += 1
            d[a] -= 2
    else:
        if d[pair] >= 1:
            cnt += 1
            d[pair] -= 1
print(cnt)


Failing test case input:
5
2 6 25 3 10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A.sort()
d = defaultdict(int)
for a in A:
    d[a] += 1

cnt = 0
for a in reversed(A):
    if d[a] > 0:
        d[a] -= 1
        pair = (1 << a.bit_length()) - a
        if d[pair] > 0:
            cnt += 1
            d[pair] -= 1
print(cnt)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
ans = 0

for a in A:
    small = (1<<(len(format(a+1,"b")))) - a
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a] -= 1
        dic[small] -= 1
        ans += 1
print(ans)

Failing test case input:
5
4 18 14 5 3

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
ans = 0

for a in A:
    small = (1<<(len(format(a,"b")))) - a
    if small == a:
        if dic[a] >= 2:
            dic[a] -= 2
            ans += 1
        continue
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a] -= 1
        dic[small] -= 1
        ans += 1
print(ans)

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
from collections import Counter

power2 = [1]
while power2[-1] < 10**9:
    power2.append(power2[-1]*2)

N = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
C = Counter(A)

ans = 0
for a in A:
    if C[a] == 0:
        continue

    i = bisect.bisect_left(power2, a)
    if C[power2[i]-a] >= 1:
        ans += 1
        C[power2[i]-a] -= 1

    C[a] -= 1
print(ans)


Failing test case input:
5
3 24 16 16 13

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import bisect
from collections import Counter

power2 = [1]
while power2[-1] < 10**9:
    power2.append(power2[-1]*2)

N = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
C = Counter(A)

ans = 0
for a in A:
    if C[a] == 0:
        continue
    C[a] -= 1

    i = bisect.bisect_right(power2, a)
    if C[power2[i]-a] >= 1:
        ans += 1
        C[power2[i]-a] -= 1

print(ans)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import defaultdict

def twosum(n):
  now = 1
  while n >= now:
    now *= 2
  return now - n
n=int(input())
a=list(map(int,input().split()))
a.sort()
d = defaultdict(int)
for i in a:
    d[i] += 1
ans = 0
for i in a[::-1]:
    if d[i] <= 0:
        continue
    find = twosum(i)
    if d[find] <= 0:
        continue
    ans += 1
    d[i] -= 1
    d[find] -= 1
print(ans)

Failing test case input:
5
2 6 24 5 16

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import defaultdict

def twosum(n):
  now = 1
  while n >= now:
    now *= 2
  return now - n
n=int(input())
a=sorted(list(map(int,input().split())))
d = defaultdict(int)
for i in a:
    d[i] += 1
ans = 0
for i in a[::-1]:
    d[i] -= 1
    find = twosum(i)
    if d[find] > 0 and d[i] >= 0:
        ans += 1
        d[find] -= 1
    else:
        d[i] += 1
print(ans)

Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from bisect import bisect_left
from bisect import bisect_right

n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)

while a:
    s = a.pop()
    if s == -1:
        a.append(s)
        break
    m = 1
    while m <= s:
        m *= 2
    ind = bisect_right(a, m-s)
    if ind == 0:
        continue
    if a[ind-1] == m-s:
        a[ind-1] = -1


print(-sum(a))


Failing test case input:
5
3 36 3 10 13

Expected output:
1


Actual output:
-2


Fixed submission (verdict: Accepted):
from bisect import bisect_left
from bisect import bisect_right

n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)

ans = 0
visited = [False]*n

while a:
    s = a.pop()
    if visited.pop():
        continue
    m = 1
    while m <= s:
        m *= 2
    r = bisect_right(a, m-s)
    l = bisect_left(a, m-s)
    for x in range(l, r)[::-1]:
        if not visited[x]:
            visited[x] = True
            ans += 1
            break

print(ans)
Problem: p03201
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
readline = sys.stdin.readline









N = int(readline())
A = list(map(int,readline().split()))

from collections import defaultdict

balls_count = defaultdict(int) 

import heapq as hq
balls_q = [] 

for a in A:
  balls_count[a] += 1
  hq.heappush(balls_q, -a)

def get_pair_num(x): 
  tar = 2
  while tar < x:
    tar *= 2
  return tar - x

ans = 0
while balls_q:
  ball = -(hq.heappop(balls_q))
  if balls_count[ball] == 0: 
    continue
  
  
  balls_count[ball] -= 1
  pair = get_pair_num(ball)
  if balls_count[pair] > 0:
    ans += 1
    balls_count[pair] -= 1
  

print(ans)

Failing test case input:
5
2 24 16 16 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
readline = sys.stdin.readline









N = int(readline())
A = list(map(int,readline().split()))

from collections import defaultdict

balls_count = defaultdict(int) 

import heapq as hq
balls_q = [] 

for a in A:
  balls_count[a] += 1
  hq.heappush(balls_q, -a)

def get_pair_num(x): 
  tar = 2
  while tar < x:
    tar *= 2
  if tar == x:
    return tar
  return tar - x

ans = 0
while balls_q:
  ball = -(hq.heappop(balls_q))
  if balls_count[ball] == 0: 
    continue
  
  
  balls_count[ball] -= 1
  pair = get_pair_num(ball)
  if balls_count[pair] > 0:
    ans += 1
    balls_count[pair] -= 1
  

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
input()
A=list(map(int,input().split()))
A.sort(reverse=True)
C=Counter(A)
ans=0
for a in A:
    if C[a]==0:
        continue
    t=2**a.bit_length()
    if t==2*a and C[a]==1:
        continue
    if C[t-a]>0:
        C[t-a]-=1
        C[a]-=-1
        ans+=1
print(ans)

Failing test case input:
5
2 41 16 16 1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter
input()
A=list(map(int,input().split()))
A.sort(reverse=True)
C=Counter(A)
ans=0
for a in A:
    if C[a]==0:
        continue
    C[a]-=1
    t=2**a.bit_length()-a
    if C[t]:
        C[t]-=1
        ans+=1
print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
c = Counter(A)

ans = 0
while len(A) > 1:
    a = A.pop()
    c[a] -= 1
    Num = 1 << (a.bit_length())
    cand = Num - a
    if c[cand]:
        ans += 1
        c[cand] -= 1

print(ans)


Failing test case input:
5
4 2 1 3 5

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
c = Counter(A)

ans = 0
while A:
    a = A.pop()
    if c[a] <= 0:
        continue
    c[a] -= 1
    Num = 1 << (a.bit_length())
    cand = Num - a  
    if c[cand] > 0:
        ans += 1
        c[cand] -= 1

print(ans)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


from collections import Counter
n = int(input())
a = list(map(int, input().split( )))
a_c = Counter(a)

a.sort(reverse = True)
ans = 0
for i in range(n):
    j = 0
    while 2**j<a[i]:
        j+=1
    if 2**j-a[i] in a_c and a_c[a[i]]:
        if a_c[2**j-a[i]]:
            a_c[2**j-a[i]] -= 1
            a_c[a[i]] -= 1
            ans += 1
    
print(ans)
            

Failing test case input:
5
2 24 16 16 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):


from collections import Counter
n = int(input())
a = list(map(int, input().split( )))
a_c = Counter(a)

a.sort(reverse = True)
ans = 0
for i in range(n):
    if not a_c[a[i]]:
        continue
    a_c[a[i]] -= 1
    t = (1<<a[i].bit_length()) - a[i]
    if t in a_c:
        if a_c[t]:
            a_c[t] -= 1
            
            ans += 1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort()
a.reverse()
for _ in range(len(a)):
    if len(a)<2:
        break
    else:
        bi=format(a[0], 'b')
        x=2**len(bi)-a[0]
        if x in a:
            ans+=1
            a.remove(x)
        a.pop(0)
print(ans)

Failing test case input:
5
7 3 8 3 10

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import collections
import bisect
n= int(input())
a=list(map(int, input().split()))
c=collections.Counter(a)
ans=0
des=sorted(a,reverse=True)


for i in des:
    if c[i]>0:
        bi=format(i, 'b')
        x=2**len(bi)-i
        c[i]-=1
        if c[x]>0:
            c[x]-=1
            ans+=1
print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for b in a:
    if b:
        bi=format(b, 'b')
        x=2**len(bi)-b
        if x==b:
            ans+=1
            b=None

print(ans)



Failing test case input:
5
6 3 1 3 10

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import collections
import bisect
n= int(input())
a=list(map(int, input().split()))
c=collections.Counter(a)
ans=0
des=sorted(a,reverse=True)


for i in des:
    if c[i]>0:
        bi=format(i, 'b')
        x=2**len(bi)-i
        c[i]-=1
        if c[x]>0:
            c[x]-=1
            ans+=1
print(ans)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

s = [2 ** x for x in range(1, 18)]
N = ri()
A = rl()
A.sort(reverse=True)
used = set()
answer = 0
for i in range(N):
    if A[i] in used:
        continue
    B = A[i+1:]
    for x in s:
        if x - A[i] in B:
            answer += 1
            used.add(x-A[i])

print(answer)



Failing test case input:
5
3 24 22 5 13

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
from collections import Counter

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

N = ri()
A = rl()
A.sort(reverse=True)
c = Counter(A)
answer = 0
for x in A:
    target = (1 << x.bit_length()) - x
    while c[x] > 0:
        c[x] -= 1
        if c[target] > 0:
            c[target] -= 1
            answer += 1

print(answer)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n= int(input())
a=list(map(int, input().split()))
ans=0
a.sort(reverse=True)
for b in a:
    if b:
        bi=format(b, 'b')
        x=2**len(bi)-b
        if x==b and a.count(x)>1:
            ans+=1
            b=None
            a[a.index(x)]=None
print(ans)



Failing test case input:
5
3 24 16 10 13

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import collections
import bisect
n= int(input())
a=list(map(int, input().split()))
c=collections.Counter(a)
ans=0
des=sorted(a,reverse=True)


for i in des:
    if c[i]>0:
        bi=format(i, 'b')
        x=2**len(bi)-i
        c[i]-=1
        if c[x]>0:
            c[x]-=1
            ans+=1
print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A_arr = list(map(int, input().split()))

A_arr = sorted(A_arr, reverse=True)
two_arr = []
for i in range(1,31):
    two_arr.append(2**i)

count = 0
while len(A_arr) != 0:
    v_max = A_arr.pop(0)
    for j in range(30):
        if v_max > two_arr[j]:
            pass
        else:
            v_pair = two_arr[j] - v_max
            break
    if v_pair in A_arr:
        A_arr.remove(v_pair)
        count += 1
    else:
        pass

print(count)

Failing test case input:
5
4 3 4 3 10

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter
N = int(input())
A_arr = list(map(int, input().split()))

A_arr = sorted(A_arr, reverse=True)
C_arr = Counter(A_arr)

count = 0
for i in range(N):
    v_max = A_arr[i]
    if C_arr[v_max] == 0:
        continue
    C_arr[v_max] -= 1
    v_pair = 2**v_max.bit_length() - v_max
    if C_arr[v_pair] > 0:
        C_arr[v_pair] -= 1
        count += 1
    else:
        pass

print(count)
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect

n = int(input())
aa = list(map(int,input().split()))

aa.sort()

a = [aa[0]]
b = [1]

for i in range(1,n):
    if a[-1]==aa[i]:
        b[-1]+=1
    else:
        a.append(aa[i])
        b.append(1)

ans = 0

for i in range(len(a)):
    if b[-i-1]!=0:
        c = 2**(len(bin(a[-i-1]))-2)-a[-i-1]
        d = bisect.bisect_left(a,c)
        e = bisect.bisect_right(a,c)
        if a[d]==c:
            for j in range(d,e):
                if b[j]!=0 and j!=len(a)-i-1:
                    ans += 1
                    b[-i-1]-=1
                    b[j]-=1
                    break

print(ans)


Failing test case input:
5
2 24 16 16 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import bisect

n = int(input())
aa = list(map(int,input().split()))

aa.sort()

a = [aa[0]]
b = [1]

for i in range(1,n):
    if a[-1]==aa[i]:
        b[-1]+=1
    else:
        a.append(aa[i])
        b.append(1)

ans = 0

for i in range(len(a)):
    while b[-i-1]!=0:
        c = 2**(len(bin(a[-i-1]))-2)-a[-i-1]
        d = bisect.bisect_left(a,c)
        if a[d]==c:
            if b[d]>1:
                ans += 1
                b[-i-1] -= 1
                b[d] -= 1
            elif b[d]==1 and a[d]!=a[-i-1]:
                ans += 1
                b[-i-1] -= 1
                b[d] -= 1
            else:
                break
        else:
            break

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

N = int(input())
A = [int(a) for a in input().split()]
A = sorted(A)

c = 0
for i in range(N - 1 , -1, -1):
    b = 1
    while b <= A[i]:
        b <<= 1
    
    j = bisect.bisect_left(A, b - A[i])
    if b - A[i] == A[j]:
        c += 1
        A[j] = A[j] - 0.5
        A[i] = A[i] + 0.5

print(c)


Failing test case input:
5
6 3 1 3 10

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import bisect

N = int(input())
A = [int(a) for a in input().split()]
A = sorted(A)

c = 0
for i in range(N - 1 , -1, -1):
    if A[i] == int(A[i]):
        b = 1
        while b <= A[i]:
            b <<= 1

        j = bisect.bisect_left(A, b - A[i])
        if i > j:
            if b - A[i] == A[j]:
                c += 1
                A[j] = A[j] - 0.5
                A[i] = A[i] + 0.5
print(c)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse = True)
    M = max(A)
    d = dict()
    for x in A:
        if x in d:
            d[x] += 1
        else:
            d[x] = 1
    
    def exp(x):
        l = len(str(bin(x))[2:])
        return 2**l

    ans = 0
    for i in range(N):
        use = A[i]
        if (exp(use)-use) not in d:
            continue
        if d[use] <= 0:
            continue
        if exp(use)-use == use:
            if d[use] >= 2:
                d[use] -= 2
                ans += 1
        else:
            d[use] -= 1
            d[exp(use)-use] -= 1
            ans += 1
            
    print(ans)
    
if __name__ == "__main__":
    main()


Failing test case input:
5
2 6 24 6 16

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import defaultdict
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    d = defaultdict(int)
    for x in A:
        d[x] += 1
    A = list(set(A))
    A.sort(reverse = True)
    l = len(A)
    
    def exp(x):
        l = len(str(bin(x))[2:])
        return 2**l

    ans = 0
    for i in range(l):
        a = A[i]
        if exp(a)
            ans += int(d[a]
        else:
            m = min(d[a],d[exp(a)-a])
            ans += m
            d[a] -= m
            d[exp(a)-a] -= m
            
    print(ans)
    
if __name__ == "__main__":
    main()

Problem: p03201
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = list(map(int,ipt().split()))
    a.sort(reverse=True)
    d = defaultdict(int)
    ans = 0
    for i in a:
        if d[i]:
            ans += 1
        else:
            nl = len(format(i,"b"))
            d[(i^(2**(nl)-1))+1] += 1

    print(ans)
    return

if __name__ == '__main__':
    main()


Failing test case input:
5
2 2 1 5 6

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = list(map(int,ipt().split()))
    a.sort(reverse=True)
    d = defaultdict(int)
    ans = 0
    for i in a:
        if d[i]:
            ans += 1
            d[i] -= 1
        else:
            nl = len(format(i,"b"))
            d[(i^(2**(nl)-1))+1] += 1

    print(ans)
    return

if __name__ == '__main__':
    main()
Problem: p03201
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    D=defaultdict(int)
    for a in A:
        D[a]+=1

    A.sort(reverse=1)
    ans=0
    for a in A:
        k=a.bit_length()
        d=(1<<k)-a
        print(a,d)
        if(a!=d):
            if(D[d]):
                ans+=1
                D[a]-=1
                D[d]-=1
        else:
            if(D[d]>=2):
                ans+=1
                D[d]-=2
    print(ans)
resolve()

Failing test case input:
5
3 34 14 10 13

Expected output:
1


Actual output:
34 30
14 2
13 3
10 6
3 1
1


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    D=defaultdict(int)
    for a in A:
        D[a]+=1

    A.sort(reverse=1)
    ans=0
    for a in A:
        if(D[a]==0): continue
        k=a.bit_length()
        d=(1<<k)-a
        if(a!=d):
            if(D[d]):
                ans+=1
                D[a]-=1
                D[d]-=1
        else:
            if(D[d]>=2):
                ans+=1
                D[d]-=2
    print(ans)
resolve()

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
N=int(input())
alist=list(map(int,input().split()))
alist.sort(reverse=True)

blist=[]
for a in alist:
  a2=a
  digit_a2=0
  while(a2>0):
    a2>>=1
    digit_a2+=1
  b=2**(digit_a2)-a
  blist.append(b)



dic_a={}
for a in alist:
  if a in dic_a:
    dic_a[a]+=1
  else:
    dic_a[a]=1

answer=0
for i in range(N):
  a=alist[i]
  b=blist[i]
  if a==b:
    if dic_a[a]>1:
      dic_a[a]-=2
      answer+=1
      
  else:
    if b in dic_a and dic_a[b]>0:
      dic_a[a]-=1
      dic_a[b]-=1
      answer+=1
      
    
print(answer)

Failing test case input:
5
3 4 1 14 13

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import bisect
N=int(input())
alist=list(map(int,input().split()))
alist.sort(reverse=True)

blist=[]
for a in alist:
  a2=a
  digit_a2=0
  while(a2>0):
    a2>>=1
    digit_a2+=1
  b=2**(digit_a2)-a
  blist.append(b)



dic_a={}
for a in alist:
  if a in dic_a:
    dic_a[a]+=1
  else:
    dic_a[a]=1

answer=0
for i in range(N):
  a=alist[i]
  b=blist[i]
  if a==b:
    if dic_a[a]>1:
      dic_a[a]-=2
      answer+=1
      
  else:
    if dic_a[a]>0 and b in dic_a and dic_a[b]>0:
      dic_a[a]-=1
      dic_a[b]-=1
      answer+=1
      
    
print(answer)
Problem: p03201
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
readline = sys.stdin.readline









N = int(readline())
A = list(map(int,readline().split()))

from collections import defaultdict

balls_count = defaultdict(int) 

import heapq as hq
balls_q = [] 

for a in A:
  balls_count[a] += 1
  hq.heappush(balls_q, -a)

def get_pair_num(x): 
  tar = 2
  while tar < x:
    tar *= 2
  return tar - x

ans = 0
while balls_q:
  ball = hq.heappop(balls_q)
  
  
  balls_count[ball] -= 1
  pair = get_pair_num(-ball)
  if balls_count[pair] > 0:
    ans += 1
    balls_count[pair] -= 1
  

print(ans)

Failing test case input:
5
2 3 38 1 1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
readline = sys.stdin.readline









N = int(readline())
A = list(map(int,readline().split()))

from collections import defaultdict

balls_count = defaultdict(int) 

import heapq as hq
balls_q = [] 

for a in A:
  balls_count[a] += 1
  hq.heappush(balls_q, -a)

def get_pair_num(x): 
  tar = 2
  while tar < x:
    tar *= 2
  if tar == x:
    return tar
  return tar - x

ans = 0
while balls_q:
  ball = -(hq.heappop(balls_q))
  if balls_count[ball] == 0: 
    continue
  
  
  balls_count[ball] -= 1
  pair = get_pair_num(ball)
  if balls_count[pair] > 0:
    ans += 1
    balls_count[pair] -= 1
  

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

N = int(input())
*A, = map(int, input().split())
cnt = Counter(A)
A = sorted(A, reverse=True)
ans = 0
for a in A:
    cand = (1 << ((a - 1).bit_length())) - a
    if cnt[a] == 0 or cnt[cand] == 0: continue
    ans += 1
    cnt[a] -= 1; cnt[cand] -= 1
print(ans)

Failing test case input:
5
4 3 4 3 10

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter

N = int(input())
*A, = map(int, input().split())
cnt = Counter(A)
A = sorted(A, reverse=True)
ans = 0
for a in A:
    if a & (a - 1) != 0:
        cand = (1 << ((a - 1).bit_length())) - a
        if cnt[a] == 0 or cnt[cand] == 0: continue
    else:
        cand = a
        if cnt[a] < 2: continue
    ans += 1
    cnt[a] -= 1; cnt[cand] -= 1
print(ans)
Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict
from math import log2,ceil

def get_smallest_power_of_2_over_N(N):
    i=2
    while i<N:
        i*=2
    return i

N = int(input())
A = list(map(int,input().split()))


pair_cand=[set() for _ in range(N)]
A = sorted(A)

ans=0
D=defaultdict(int)

for a in A:
    D[a]+=1

for i in reversed(range(N)):
    if D[A[i]]<=0:
        continue
    else:
        pair_val = get_smallest_power_of_2_over_N(A[i]) - A[i]
        if D[pair_val]>0:
            ans+=1
            D[pair_val]-=1
            D[A[i]]-=1


print(ans)


Failing test case input:
5
1 34 26 10 25

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
from collections import Counter

def get_smallest_power_of_2_over_N(N):
    i=2
    while i<=N:
        i*=2
    return i

N = int(input())
A = list(map(int,input().split()))


A = sorted(A)

ans=0
D=Counter(A)

for i in reversed(range(N)):
    pair_val = get_smallest_power_of_2_over_N(A[i]) - A[i]
    if D[A[i]]<=0:
        continue
    elif pair_val==A[i] and D[pair_val]>=2 or pair_val!=A[i] and  D[pair_val]>=1:
        ans+=1
        D[pair_val]-=1
        D[A[i]]-=1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

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

a.sort(reverse=True)
c = Counter(a)

ans = 0
for x in a:
    temp = (1 << x.bit_length()) - x
    if temp in c.keys():
        if temp == x:
            if c[temp] >= 2:
                c[temp] -= 1
                ans += 1
        elif c[temp] > 0:
            c[temp] -= 1
            ans += 1
    c[x] -= 1

print(ans)



Failing test case input:
5
2 3 76 6 10

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import Counter

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

a.sort(reverse=True)
c = Counter(a)

ans = 0
for x in a:
    if c[x] == 0:
        continue
    temp = (1 << x.bit_length()) - x
    c[x] -= 1
    if temp in c.keys():
        if c[temp] > 0:
            c[temp] -= 1
            ans += 1

print(ans)

Problem: p03201
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A.sort()
d = defaultdict(int)
for a in A:
    d[a] += 1

cnt = 0
for a in reversed(A):
    d[a] -= 1
    pair = (1 << a.bit_length()) - a
    if d[pair] > 0:
        cnt += 1
        d[pair] -= 1
print(cnt)


Failing test case input:
5
3 4 1 14 13

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A.sort()
d = defaultdict(int)
for a in A:
    d[a] += 1

cnt = 0
for a in reversed(A):
    if d[a] > 0:
        d[a] -= 1
        pair = (1 << a.bit_length()) - a
        if d[pair] > 0:
            cnt += 1
            d[pair] -= 1
print(cnt)