TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
a = list(input())

su = 0
dd = 0
co = 0
for i in range(len(a)-1,-1,-1):
	if a[i] == 'B':
		co += 1
	if co >= 1:
		if a[i] == 'W':
			su += (len(a)-1 - i) - dd
			dd += 1
if dd != 0:
	print(su+dd-1)
else:
	print(su+dd)



a = list(input())

su = 0
dd = 0
co = 0
for i in range(len(a)-1,-1,-1):
	if a[i] == 'B':
		co += 1
	if co >= 1:
		if a[i] == 'W':
			su += (len(a)-1 - i) - dd
	if a[i] == 'W':
		dd += 1
if su == 0:
	print(0)
else:
	print(su+ (len(a) - dd))



a = list(input())

su = 0
dd = 0
co = 0
for i in range(len(a)-1,-1,-1):
	if a[i] == 'W':
		co += 1
	if co >= 1:
		if a[i] == 'B':
			su += (len(a)-1 - i) - dd
	else:
		if a[i] == 'B':
			dd += 1
print(su)


a = list(input())

su = 0
dd = 0
co = 0
for i in range(len(a)):

		if a[i] == 'W':
			su += i - dd
			dd += 1

print(su)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
s=input()
c=0
a=0
for i in s:
  if i=='B':
    c+=1
  else:
    a+=c
print(ans)

s=input()
c=0
a=0
for i in s:
  if i=='B':
    c+=1
  else:
    a+=c
print(a)

Verdicts: Runtime Error

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
s = input()
n  =len(s)
res = 0
ans = 0
for i in range(n):
    if s[i] == 'B':
        res+=1AC
    else:
        ans+=res


print(ans)

s = input()
n  =len(s)
res = 0
ans = 0
for i in range(n):
    if s[i] == 'B':
        res+=1
    else:
        ans+=res


print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
import re
import numpy as np
s = input()
wlen = list(map(len, re.findall(r"(W+)", s)))
print(np.cumsum(wlen[::-1]).sum())


s = input()

cnt = 0
result = 0
for v in reversed(s):
    if v == "W":
        cnt += 1
    else:
        result += cnt
print(result)



Verdicts: Wrong Answer

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
S = input().strip()

count = 0
suma = 0
for i in S:
  if i=="W":
    suma += count
  else:
    count += 1


S = input().strip()

count = 0
suma = 0
for i in S:
  if i=="W":
    suma += count
  else:
    count += 1
print(suma)

Verdicts: Wrong Answer

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
s=input()
n=len(s)
cnt=0
for i in range(n):
  if s[i]=='W':
    cnt+=1
ans=0
for i in range(n):
  if s[i]=='W':
    cnt--
  else:
    ans+=cnt
print(ans)
 
  

s=input()
n=len(s)
cnt=0
for i in range(n):
  if s[i]=='W':
    cnt+=1
ans=0
for i in range(n):
  if s[i]=='W':
    cnt-=1
  else:
    ans+=cnt
print(ans)
 



Verdicts: Runtime Error

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
def main():
        s = input()
        start = forward = backward = 0
        intervals = []
        
        if len(s) > 3:
            for i in range(1, len(s)):
                if s[start] != s[i]:
                    intervals.append((start, i-1, s[start]))
                    if s[start] == 'B':
                        forward += 1
                    else:
                        backward += 1
                    start = i
            intervals.append((start, len(s)-1, s[start]))
            print(len(intervals))
        
        elif s =='WBW' or 'BWB' or 'BW':
            print(1)
            
        else:
            print(0)
main()

def main():
    S=input()
    b_n = 0; ans = 0
    for s in S:
        if s=='B': b_n += 1
        else: ans += b_n
    print(ans)
main()

Verdicts: Wrong Answer

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
S = list(input())
cnt = 0

for i in range(len(S)-1):
    if S[i] == 'B' and S[i+1] == 'W':
        S[i] = 'W'
        S[i+1] = 'B'
        cnt += 1
        # print(S)
        j = 1
        while True:
            if S[i-j] == 'B':
                S[i-j] = 'W'
                S[i-j+1] = 'B'
                cnt += 1
                j += 1
                # print(S)
            else :
                break
            
print(cnt)

S = list(input())
cnt = 0
ans = 0

for i in range(len(S)):
    if S[i] =='W':
        ans += i - cnt
        cnt += 1
    i += 1
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
N = int(input())

X = [[] for i in range(N)]
P = [-1] * N

for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)


def set_parent(i):
    # print(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            # print(a)
            X[a].remove(i)
            set_parent(a)
    
set_parent(0)

B = [-1] * N
def set_block(i):
    for a in X[i]:
        B[a] = max(i, B[i])
        set_block(a)

B_id = [-1] * N
B_id_cnt = [0] * N
def BID(i):
    for a in X[i]:
        if a > B[i]:
            B_id[a] = a
        else:
            B_id[a] = B_id[i]
            
        # print(a, B_id)
        B_id_cnt[B_id[a]] += 1
        BID(a)
        
Ans = [1] * N
def flow(i):
    for a in X[i]:
        if B_id[a] == B_id[i]:
            Ans[a] = Ans[i]
        else:
            Ans[a] = Ans[i] + B_id_cnt[a]
        flow(a)

set_block(0)







# print(Ans)
print(" ".join(map(str, Ans[1:])))


s = input()
n = len(s)
a = 0
b = 0
for i in range(n):
    if s[i] == "W":
        a += 1
        b += i
        
print(b - a*(a-1)//2)

Verdicts: Runtime Error

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
S = input()
N = len(S)
sum = 0
flg = False
S = S[::-1]

for i in range(N):
  if S[i] == 'W':
    flg = True
  elif S[i] == 'B' and flg:
    sum += i
print(sum)

S = input()
N = len(S)
sum = 0
count = 0
flg = False
S = S[::-1]

for i in range(N):
  if S[i] == 'W':
    count += 1
    flg = True
  elif S[i] == 'B' and flg:
    sum += count
print(sum)

Verdicts: Wrong Answer

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
s = input()

cw = 0
ans = 0
for i in range(n):
  if s[i] == 'W':
    ans += i-cw
    cw += 1
    
print(ans)    
    
  

s = input()
 
cw = 0
ans = 0
for i in range(len(s)):
  if s[i] == 'W':
    ans += i-cw
    cw += 1
    
print(ans)    

Verdicts: Runtime Error

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
S = list(input())

print(S)

count = 0
i = 0
while i < len(S)-1:
    if S[i]=='B' and S[i+1]=='W':
        S[i]='W'
        S[i+1]='B'
        count += 1
        if i > 0:
            i -= 1
        else:
            i += 1
    else:
            i += 1
print(count)

S = input()

count = 0
black = 0
white = 0

for i in range(len(S)-1):
    if S[i] == 'B':
        black +=1
    else :
        white +=1
    if  S[i+1] == 'W':
        count += i+1 -white

print(count)

Verdicts: Wrong Answer

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
def ans():
    global cnt, s, l
    if s.count("BW") == 0:
        return None
    for i in range(s.count("BW")):
        print(s)
        cnt += 1
        l.pop(s.index("BW") + 1)
        l[s.index("BW"):s.index("BW") + 1] = ["W", "B"]
        s = "".join(l)
    ans()
s = input()
l = list(s)
cnt = 0
ans()
print(cnt)

s=input()
c=0
a=0
for i in range(len(s)):
 if s[i]=="W":a+=i-c;c+=1
print(a)

Verdicts: Runtime Error

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
# AtCoder Grand Contest 029
# December 15, 2018
#

S = input()
count = 0

while True:
  if S.find('BW') >= 0:
    S = S.replace('BW', 'WB', 1)
    count += 1
    print(S)
  else:
    break

print(count)

S = input()
N = len(S)

count = 0
num = 0
idx = -1
while True:
  idx = S.find('W', idx + 1)
  if idx < 0:
    break
  count += idx - num
  num += 1

print(count)

Verdicts: Runtime Error

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
from collections import Counter as C
n = int(input())
l = sorted(map(int, input().split()), reverse = True)
c = C(l)
res = 0
for e in l:
    for p in range(32, 0, -1):
        e_ = (1 << p) - e
        if c.get(e_, 0) > 0:
            # print(e, e_, c)
            c[e_] -= 1
            c[e] -= 1
            res += 1
            break
print(res)

s = input()
l = []
i = 0
n = len(s)
while i < n:
    j = 0
    while i < n and s[i] == 'B':
        j += 1
        i += 1
    l.append(j)

    j = 0
    while i < n and s[i] == 'W':
        j += 1
        i += 1
    l.append(j)
# print(l)
res = 0
for i in range(0, len(l), 2):
    if l[i] > 0:
        res += l[i] * l[i + 1]
    if i + 2 < len(l):
        l[i + 2] += l[i]
print(res)

Verdicts: Runtime Error

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
S = input()
print(S.count('w')*2)


# -*- coding: utf-8 -*-
S = input()
bcount=S.count('B')
wcount=S.count('W')
Slen=len(S)
ans=0
bb=0
for i in range(Slen):
    if i!=Slen:
        if S[Slen-i-1]=="B":
            ans=ans+bb
        else:
            bb=bb+1
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white.  Consider performing the following operation:    * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black.  Find the maximum possible number of times this operation can be performed.

Submission attempts (in order):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction


# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
s=list(input())
k=0
i=0
while(i+1<len(s)):
    if(s[i]=="B" and s[i+1]=="W"):
        s[i],s[i+1]=s[i+1],s[i]
        k+=1
    i+=1
print(k)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction


# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
s=list(input())
A=[]
for i in range(len(s)):
    if(s[i]=="W"):
        A.append(i)
k=0
i=0
for x in A:
    k+=(x-i)
    i+=1
print(k)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
import math
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[]
for i in range(1,50):
  b.append(2**i)
ct=0
check=[1]*n
for i in range(n-1,-1,-1):
  if a[i]==1:
    break
  if check[i]==1 and a[i] not in b:
    check[i]=0
    x=math.floor(math.log2(a[i]))
    x=b[x]-a[i]
    y=bisect.bisect_left(a,x)
    z=bisect.bisect_right(a,x)
    t=bisect.bisect_left(check[y:z],1)+y
    if t!=z:
      check[t]=0
      ct+=1

ctb=0
w=1
for i in range(30):
  if a[i] in b or a[i]==1:
    if a[i]==w:
      if check[i]==1:
        ctb+=1
    else:
      ct+=ctb//2
      w=a[i]
      if check[i]==1:
        ctb=1
      else:
        ctb=0
  else:
    ct+=ctb//2
    ctb=0
ct+=ctb//2

print(ct)

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

M=max(a)
for i in range(100):
  if 2**i>M:
    x=i
    break
L=[]
for j in range(2**x-1):
  L.append(0)

for j2 in range(n):
  L[a[j2]-1]+=1

for k in range(x,1,-1):
  l1=L[0:2**(k-1)-1]
  l2=L[2**(k-1):2**k]
  l2.reverse()
  ct+=int(L[2**(k-1)-1]/2)
  for m in range(len(l1)):
    if l1[m]>=1 and l2[m]>=1:
      ct+=min(l1[m],l2[m])
      l1[m]-=min(l1[m],l2[m])
      l2[m]-=min(l1[m],l2[m])
  L=l1
ct+=int(L[0]/2)
print(ct)
print(x)

n=int(input())
a=list(map(int,input().split()))
ct=0
 
M=max(a)
min=min(a)

if m>=10**8:
  print(0)
else:
  for i in range(100):
    if 2**i>M:
      x=i
      break
  L=[]
  for j in range(2**x-1):
    L.append(0)
  
  for j2 in range(n):
    L[a[j2]-1]+=1
  
  for k in range(x,1,-1):
    l1=L[0:2**(k-1)-1]
    l2=L[2**(k-1):2**k]
    l2.reverse()
    ct+=int(L[2**(k-1)-1]/2)
    for m in range(len(l1)):
      if l1[m]>=1 and l2[m]>=1:
        ct+=min(l1[m],l2[m])
        l1[m]-=min(l1[m],l2[m])
        l2[m]-=min(l1[m],l2[m])
    L=l1
  ct+=int(L[0]/2)
  print(ct)

import math
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()

x=a[0];ctn=1;l=[];l2=[]
for i in range(1,n):
  if x==a[i]:
    ctn+=1
  else:
    l.append([x,ctn])
    l2.append(x)
    x=a[i]
    ctn=1
l.append([x,ctn])
l2.append(x)

b=[2**i for i in range(1,50)]

ct=0
for i in range(len(l2)-1,-1,-1):
  x=math.floor(math.log2(l2[i]))
  x=b[x]-l2[i]
  y=bisect.bisect_left(l2,x)
  if l2[y]==x:
    if l2[y]!=l2[i]:
      m=min(l[i][1],l[y][1])
    else:
      m=l[i][1]//2
    l[i][1]-=m
    l[y][1]-=m
    ct+=m
print(ct)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
from collections import Counter
import math

N=int(input())

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

answer=0
A.sort(reverse=True)

Amax=A[0]
limit=1
while(True):
  if limit>Amax:
    break;
  limit*=2

Acounter=Counter(A)
print(Acounter)

while(limit!=1):
  for number,count in Acounter.items():
    if limit-number in Acounter.keys():
      if number==limit-number:
        dec=math.floor(Acounter[number]/2)
        Acounter[number]-=dec
      else:
        dec=min(Acounter[number],Acounter[limit-number])
        Acounter[number]-=dec
        Acounter[limit-number]-=dec
      answer+=dec
  limit=int(limit/2)
print(answer)

from collections import Counter
import math

N=int(input())

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

answer=0
A.sort(reverse=True)

Amax=A[0]
limit=1
while(True):
  if limit>Amax:
    break;
  limit*=2

Acounter=Counter(A)
print(Acounter)

while(limit!=1):
  eraserlist=[]
  for number,count in Acounter.items():
    if limit-number in Acounter.keys():
      if number==limit-number:
        dec=math.floor(Acounter[number]/2)
        Acounter[number]-=dec*2
      else:
        dec=min(Acounter[number],Acounter[limit-number])
        Acounter[number]-=dec
        Acounter[limit-number]-=dec
        if Acounter[limit-number]==0:
          eraserlist.append(limit-number)
      if Acounter[number]==0:
        eraserlist.append(number)
      answer+=dec
    if number>=limit/2:
      eraserlist.append(number)
  for i in range(len(eraserlist)):
    if eraserlist[i] in Acounter.keys():
      Acounter.pop(eraserlist[i])
  limit=int(limit/2)
print(answer)
print(Acounter)

from collections import Counter
import math

N=int(input())

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

answer=0
A.sort(reverse=True)

Amax=A[0]
limit=1
while(True):
  if limit>Amax:
    break;
  limit*=2

Acounter=Counter(A)
#print(Acounter)

while(limit!=1):
  eraserlist=[]
  for number,count in Acounter.items():
    if limit-number in Acounter.keys():
      if number==limit-number:
        dec=math.floor(Acounter[number]/2)
        Acounter[number]-=dec*2
      else:
        dec=min(Acounter[number],Acounter[limit-number])
        Acounter[number]-=dec
        Acounter[limit-number]-=dec
        if Acounter[limit-number]==0:
          eraserlist.append(limit-number)
      if Acounter[number]==0:
        eraserlist.append(number)
      answer+=dec
    if number>=limit/2:
      eraserlist.append(number)
  for i in range(len(eraserlist)):
    if eraserlist[i] in Acounter.keys():
      Acounter.pop(eraserlist[i])
  limit=int(limit/2)
print(answer)
#print(Acounter)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
from collections import defaultdict
def log2(n):
  if n < 2:
    return 0
  else:
    return 1 + log2(n // 2)

n = int(input())
a_list = list(map(int, input().split()))
d = defaultdict(int)
a_list.sort()

for a in a_list:
  d[a] += 1

a_list = list(set(a_list))
c = 0
for a in a_list:
  m = log2(a, 2)
  x = 2 ** (m+1) - a
  if x == a:
    c += d[a] // 2
    d[a] -= d[a] // 2
  else:
    c += min(d[x], d[a])
    d[x] -= min(d[x], d[a])

print(c)
    

def two_power(m):
  if m < 2:
    return 0
  else:
    return two_power(m//2) + 1

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

a.sort()
a.reverse()
c = 0
skip = []
for i in range(len(a)):
  if i in skip:
    continue
  m = two_power(a[i])
  if 2 ** (m+1) - a[i] in a:
    j = a.index(2 ** (m+1) - a[i])
    if j not in skip:
      c += 1
      skip.append(j)
    
print(c)



from collections import defaultdict
import math

n = int(input())
a_list = list(map(int, input().split()))
d = defaultdict(int)

for a in a_list:
  d[a] += 1

a_list = reversed(sorted(list(set(a_list))))
c = 0
for a in a_list:
  m = int(math.log(a, 2))
  x = 2 ** (m+1) - a
  if x == a:
    c += d[a] // 2
    d[a] -= d[a] // 2
  else:
    c += min(d[x], d[a])
    d[x] -= min(d[x], d[a])

print(c)
    

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
N = int(input())
A = set([int(i) for i in input().split()])
ans = 0
while A:
    a = A.pop()
    for i in range(2, 32):
        if (pow(2, i) - a) in A:
            ans += 1
            print(pow(2, i), a)
print(ans)

from collections import defaultdict
from bisect import bisect_right

balls_count = defaultdict(int)

N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
ans = 0
beki_list = [pow(2, i) for i in range(1, 32)]
for a in A:
    balls_count[a] += 1

for a in A:
    if balls_count[a] == 0:
        continue
    balls_count[a] -= 1
    index = bisect_right(beki_list, a)
    pair = beki_list[index] - a
    if balls_count[pair] > 0:
        balls_count[pair] -= 1
        ans += 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
from collections import Counter
n = int(input())
A = sorted(list(map(int, input().split())))[-1::-1]
c = Counter(A)
ans = 0
for a in A:
    b = (1<<m.bit_length()) - a
    if a == b and c[a] > 1:
        c[a] -= 2
        ans += 1
    elif a != b and c[a] > 0 and c[b] > 0:
        c[a] -= 1
        c[b] -= 1
        ans += 1
print(ans)


from collections import Counter
n = int(input())
A = sorted(list(map(int, input().split())))[-1::-1]
c = Counter(A)
ans = 0
for a in A:
    b = (1<<a.bit_length()) - a
    if a == b and c[a] > 1:
        c[a] -= 2
        ans += 1
    elif a != b and c[a] > 0 and c[b] > 0:
        c[a] -= 1
        c[b] -= 1
        ans += 1
print(ans)


Verdicts: Runtime Error

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
import bisect

N = int(input())
A = list(map(int, input().split()))
list_ = [2 ** i for i in range(30)]
A.sort(reverse=True)

ans = 0
while(len(A) > 0):
    a = A.pop()
    tmp = [i - a for i in list_ if i - a > 0]
    for b in tmp:
        i = bisect.bisect_left(A, b)
        if i < len(A) and A[i] == b:
            ans += 1
            A.pop(i)
            break

print(ans)

from collections import Counter

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

ans = 0
for a in A:
    b = (1 << a.bit_length()) - a
    if b in c.keys():
        if a == b and c[a] > 1:
            c[a] -= 2
            ans += 1
        elif a != b and c[a] > 0 and c[b] > 0:
            c[a] -= 1
            c[b] -= 1
            ans += 1

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
import math
n = int(input())
l = sorted(list(map(int,input().split())))
c = 0
b = {}
for i in range(len(l)):
    if l[i] in b:
        b[l[i]] += 1
    else:
        b[l[i]] = 1

for i in range(len(l) - 1, -1, -1):
    if  b[l[i]] == 0:
        continue
    t = l[i]
    b[l[i]] -= 1
    s = 2 ** math.floor(math.log2(temp))
    st = 2*s - t 
    if l == []:
        break
    if st in b and b[st] > 0:
        b[2 * s - t] -= 1
        c += 1
print(c)

import math
n = int(input())
l = sorted(list(map(int,input().split())))
c = 0
b = {}
for i in range(len(l)):
    if l[i] in b:
        b[l[i]] += 1
    else:
        b[l[i]] = 1

for i in range(len(l) - 1, -1, -1):
    if  b[l[i]] == 0:
        continue
    t = l[i]
    b[l[i]] -= 1
    s = 2 ** math.floor(math.log2(t))
    st = 2*s - t 
    if l == []:
        break
    if st in b and b[st] > 0:
        b[2 * s - t] -= 1
        c += 1
print(c)

Verdicts: Runtime Error

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
n= int(input())
a = list(map(int, input().split()))

li = []

for i in range(n):
    for t in range(1, 31):
        try:
            tmp = a[(i+1):n].index(2**t - a[i])
            li.append([a[i], a[tmp+i+1]])
        except:
            pass

from itertools import combinations

MAX = len(li)

flag=0
for j in range(MAX, 0, -1):
    for c in combinations(li, j):
        # print(c)

        cntSet = set()
        for _ in range(2):
            for i in range(len(c)):
                # print(c, c[i])
                if c[i][_] in cntSet:
                    flag = 1
                    break
                else:
                    cntSet.add(c[i][_])
        
        if flag==0:
            break

    if flag==0:
        break
print(len(cntSet))

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

def nibeki(x):
    cnt = 0
    while(x>1):
        x //=2
        cnt += 1
    return 2**(cnt+1)

# a.sort(reverse=True)
a.sort()

from collections import Counter
c = Counter(a)
print(c)

# print(a)
cntSet = 0
cntList = [0 for _ in range(len(a))]

for i in range(len(a)-1, 0, -1):
    pair = nibeki(a[i])-a[i]
    if pair in a and cntList[i]==0:
        
        cntList[i]=1
        if cntList[a.index(pair)]==0:
            cntList[a.index(pair)]=1
            cntSet += 1

print(cntSet)

from collections import Counter

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

def nibeki(x):
    cnt = 0
    while(x>1):
        x //=2
        cnt += 1
    return 2**(cnt+1)

a.sort(reverse=True)

print(a)
cntSet = 0
cntList = [0 for _ in range(len(a))]
c = Counter(a)

for i in range(len(a)):
    pair = nibeki(a[i])-a[i]
    if pair in c.keys() and cntList[i]==0 and cntList[a.index(pair)]==0:
        cntList[i]=1
        cntList[a.index(pair)]=1
        cntSet += 1

print(cntSet)

import math

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

def nibeki(x):
    cnt = 0
    while(x>1):
        x //=2
        cnt += 1
    return 2**(cnt+1)

    

a.sort(reverse=True)

print(a)

from collections import Counter

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

def nibeki(x):
    cnt = 0
    while(x>1):
        x //=2
        cnt += 1
    return 2**(cnt+1)

cntSet = 0
c = Counter(a)
ks = list(c.keys())
ks.sort(reverse=True)

for k in ks:
    pair = nibeki(k)-k
    if k==pair:
        cntSet += c[k]//2

    elif c[k]>0 and c[pair]>0:
        COUNT = min(c[k], c[pair])
        c[k] -= COUNT
        c[pair] -= COUNT
        cntSet +=COUNT

print(cntSet)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(c.keys(), reverse=True)

    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            if a in C:
                cur = min(c[a], c[b])
            else:
                cur = 0
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()


n = int(input())
A = [int(i) for i in input().split()]

A.sort()
m = 1 << 30
used = [False] * n
ans = 0

def search(ok, ng, n):
    if abs(ok-ng) <= 1:
            return ok
    mid = (ok+ng) // 2
    if A[mid] < n or (A[mid] == n and used[mid]):
        return search(mid, ng, n)
    else:
        return search(ok, mid, n)

for i in range(30):
    for j in range(n):
        if A[j] >= m:
            break
        if used[j]:
            cotinue
        a = search(-1, n, m - A[j]) + 1
        if a >= n:
            continue
        if A[a] == m - A[j]:
            if a == j:
                a += 1
                if a >= n or not A[a] == A[j]:
                    continue
            used[a] = True
            used[j] = True
            ans += 1
    m >>= 1

print(ans)



def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(input())
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(c.keys(), reverse=True)

    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            if a in c.keys():
                cur = min(c[a], c[b])
            else:
                cur = 0
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

ans1, ans2 = 0,0

maxA = max(A)
B = [1]
t = 1
while t < maxA:
    t *= 2
    B.append(t)

d = dict()
for i in range(N):
    if A[i] in d:
        d[A[i]] += 1
    else:
         d[A[i]] = 1

for i in range(N):
    t = 2**len(bin(A[i])[2::]) - A[i]
    if t in d:
        if d[t] > 0:
            ans2 += 1
            d[t] -= 1
            d[A[i]] -= 1

print(ans1+ans2)

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

ans1, ans2 = 0,0

maxA = max(A)
B = [1]
t = 1
while t < maxA:
    t *= 2
    B.append(t)

d = dict()
for i in range(N):
    if A[i] in B:
        ans1 += 1
        M -= 1
    else:
        if A[i] in d:
            d[A[i]] += 1
        else:
            d[A[i]] = 1

for i in range(N):
    if A[i] not in B:
        t = 2**len(bin(A[i])[2::]) - A[i]
        if t in d:
            if d[t] > 0:
                ans2 += 1
                d[t] -= 1
                d[A[i]] -= 1

print(ans1+ans2)

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

ans1, ans2 = 0,0

maxA = max(A)
B = [1]
t = 1
while t < maxA:
    t *= 2
    B.append(t)

d = dict()
for i in range(N):
    if A[i] in d:
        d[A[i]] += 1
    else:
         d[A[i]] = 1

for i in range(N):
    t = 2**len(bin(A[i])[2::]) - A[i]
    if t in d:
        if t != A[i]:
            if d[t]>0 and d[A[i]]>0:
                ans2 += 1
                d[t] -= 1
                d[A[i]] -= 1
        else:
            if d[t] > 1:
                ans2 += 1
                d[t] -= 2


print(ans1+ans2)

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
import bisect
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
 
res = 0
for i in range(n - 1 , -1, -1):
    if a[i] == int(a[i]):
        b = 1
        while b <= a[i]:
            b =b*2
 
        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(res)

import bisect
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
 
res = 0
for i in range(n - 1 , -1, -1):
    if a[i] == int(a[i]):
        b = 1
        while b <= A[i]:
            b =b*2
 
        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(res)

import bisect
 
n = int(input())
a = list(map(int, input().split()))
a.sort()
 
res = 0
for i in range(n - 1 , -1, -1):
    if a[i] == int(a[i]):
        b = 1
        while b <= a[i]:
            b =b*2
 
        j = bisect.bisect_left(a, b - a[i])
        if i > j:
            if b - a[i] == a[j]:
                res += 1
                a[j] = a[j] - 0.5
                a[i] = a[i] + 0.5
print(res)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
from collections import Counter

def ans_solve(N, As):
    C = Counter(As)
    ans = 0
    for d in As:
        n = (2 ** d.bit_length()) - d
        if d != n:
            if C[d] > 0 and C.get(n, 0) > 0:
                C[d] -= 1
                C[n] -= 1
                ans += 1
        else:
            ans += C[d]//2
            C[d] = 0
    return ans
 
 
if __name__ == "__main__":
    N = input()
    As = [int(c) for c in input().split()]
    print(ans_solve(N, As))

def ans_solve(N, As):
    C = Counter(As)
    ans = 0
    for d in As:
        n = (2 ** d.bit_length()) - d
        if d != n:
            if C[d] > 0 and C.get(n, 0) > 0:
                C[d] -= 1
                C[n] -= 1
                ans += 1
        else:
            ans += C[d]//2
            C[d] = 0
    return ans
 

if __name__ == "__main__":
    N = input()
    As = [int(c) for c in input().split()]
    print(ans_solve(N, As))


from collections import Counter

def ans_solve(N, As):
    C = Counter(As)
    ans = 0
    for d in reversed(sorted(As)):
        n = (2 ** d.bit_length()) - d
        if d != n:
            if C[d] > 0 and C.get(n, 0) > 0:
                C[d] -= 1
                C[n] -= 1
                ans += 1
        else:
            ans += C[d]//2
            C[d] = 0
    return ans
 
 
if __name__ == "__main__":
    N = input()
    As = [int(c) for c in input().split()]
    print(ans_solve(N, As))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
import bisect

N = int(input())
A = list(map(int, input().split()))
#N = 5
#A = [3, 11, 14, 5, 13]
A.sort()
#A = range(100000, 0, -1)

def index(a, x):
    'Locate the leftmost value exactly equal to x'
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    else:
        return None


two_bekis = set()
tmp = 1
while True:
    if tmp>2*10**9:
        break
    two_bekis.add(tmp)
    tmp *= 2

used = [False] * N
ans = 0
for i, a in enumerate(reversed(A)):
    for two_beki in two_bekis:
        tmp = index(A, two_beki-a)
        if tmp is not None and not used[tmp]:
            ans += 1
            used[tmp] = True
            used[N-i-1] = True

        


print(ans)


from collections import Counter

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

ans = 0
cnt = Counter(A)
for a in A:
    if cnt[a] == 0:
        continue
    cnt[a] -= 1
    b = 2**a.bit_length() - a
    if cnt[b] > 0:
        ans += 1
        cnt[b] -= 1
print(ans)


Verdicts: Wrong Answer

Accepted