Problem:


Score : 600 points

Problem Statement

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.

Constraints

1 \leq N \leq 2\times 10^5

1 \leq A_i \leq 10^9

A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible number of pairs such that the sum of the integers written on each pair of balls is a power of 2.

Sample Input 1

3
1 2 3

Sample Output 1

1

We can form one pair whose sum of the written numbers is 4 by pairing the first and third balls.
Note that we cannot pair the second ball with itself.

Sample Input 2

5
3 11 14 5 13

Sample Output 2

2



Sample input:
3
1 2 3


Sample output:
1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import bisect

N = int(input())
X = sorted(list(map(int, input().rstrip().split(' '))), reverse=False)
pow_2 = [2**i for i in range(40)]

count = 0
is_used = [False] * N
for i, x in enumerate(X[::-1]): 
    if is_used[i] == False:
        index1 = bisect.bisect_left(pow_2, x)
        index2 = bisect.bisect_left(X, pow_2[index1] - x)
        if pow_2[index1] - x == X[index2]:
            is_used[-i-1] = True
            is_used[index2] = True
            count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
ctr = Counter(A)
sa = sorted(ctr.keys(),reverse=True)

ans = 0
for a in sa:
    p = 2**(len(bin(a))-2)
    rem = p - a
    if a == rem: continue
    v = min(ctr[a], ctr[rem])
    ans += v
    ctr[a] -= v
    ctr[rem] -= v
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
ctr = Counter(A)
sa = sorted(ctr.keys(),reverse=True)

ans = 0
for a in sa:
    p = 2**(len(bin(a))-2)
    rem = p - a
    if a == rem: continue
    v = min(ctr[a], ctr[rem])
    ans += v
    ctr[rem] -= v
print(ans)

Submission status: Wrong Answer

Solution code:
n  =  int(input())
a  =  list(map(int, input().split()))
a.sort(reverse = True)
d  =  {}
count = 0
overlap = -1 

for x in a:
    if x not in d: d[x] = 0
    d[x] += 1
    
for i in range(len(a)):
    if a[i] == overlap or d[a[i]] == 0:continue
        
    y = 2**a[i].bit_length() - a[i]
    
    if y == a[i]: 
        count += d[y] // 2
        overlap = y
        d[y] = d[y] % 2
        continue 
            
    if y in d and d[y] > 0:
        count += 1
        d[y]  -= 1
        
print(count)

Submission status: Wrong Answer

Solution code:
##https://atcoder.jp/contests/agc029/tasks/agc029_b

n  =  int(input())
a  =  list(map(int, input().split()))
a.sort(reverse = True)
d  =  {}
count = 0
overlap = -1 

for x in a:
    if x not in d: d[x] = 0
    d[x] += 1
    
for i in range(len(a)):
    if a[i] == overlap or d[a[i]] == 0:continue
        
    y = 2**a[i].bit_length() - a[i]
    
    if y == a[i]: 
        count += d[y] // 2
        overlap = y
        continue 
            
    if y in d and d[y] > 0:
        count += 1
        d[y]  -= 1
        
print(count)

Submission status: Wrong Answer

Solution code:
n  =  int(input())
a  =  list(map(int, input().split()))
a.sort(reverse = True)
d  =  {}
count = 0
overlap = -1 

for x in a:
    if x not in d: d[x] = 0
    d[x] += 1
    
for i in range(len(a)):
    if a[i] == overlap:continue
        
    y = 2**a[i].bit_length() - a[i]
    
    if y == a[i]: 
        count += d[y] // 2
        overlap = y
        continue 
            
    if y in d and d[y] > 0:
        count += 1
        d[y]  -= 1
        
print(count)

Submission status: Wrong Answer

Solution code:
n  =  int(input())
a  =  list(map(int, input().split()))
a.sort(reverse = True)
d  =  {}
count = 0

for x in a:
    if x not in d: d[x] = 0
    d[x] += 1
    
for i in range(len(a)):
    y = 2**a[i].bit_length() - a[i]
    if y in d and d[y] > 0:
        count += 1
        d[y]  -= 1
        
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
from collections import Counter
dic = Counter(a)
ans = 0
for k in range(len(a)-1,-1,-1):
    if dic[a[k]]:
        dic[a[k]] -= 1
    t = 2**a[k].bit_length()-a[k]
    if dic[t]:
        dic[t] -= 1
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()

import math
from bisect import bisect_left
T = 30

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

cnt = 0

while len(A)>0:
	a = A.pop()
	t = math.ceil(math.log2(a))
	b = 2**t-a
	ib = index(A, b)
	if ib!=None:
		del A[ib]
		cnt += 1
	else:
		continue

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
tmp = 1
beki = []
while tmp < 2*10**9:
	tmp *= 2
	beki.append(tmp)

ans = 0
for i in range(N):
	for j in range(i+1, N):
		if A[i]+A[j] in beki:
			ans += 1
			A[j] = 10**10
			continue
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
tmp = 1
beki = []
while tmp < 2*10**9:
	tmp *= 2
	beki.append(tmp)

ans = 0
for i in range(N):
	for j in range(i+1, N):
		if A[i]+A[j] in beki:
			ans += 1
			A[j] = 10**10
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  k=number.pop()
  if len(number)==0:
    break
  if k==int(k):
    x=reversed_num(k)+1
    y=bisect.bisect_left(number,x)
    if x>number[-1]:
      y-=1
    if number[y] ==x:
      number[y]+=0.5
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import bisect

def number(num):
  #0bのぶんを引きます
  number_len = len(bin(num))-2
  #numと同じ桁数で各桁が全て1である数を求めます。
  f = 2**number_len - 1
  #排他的論理和をとって1を足したものを返します
  return (num^f)+1

n=int(input())
line=list(map(int,input().split()))
#sortを忘れないようにしてください
line.sort()

count=0

while len(line)>0:
  #最後の数を取ってくる(最後尾なのでO(1)で済む)
  k=line.pop()
  #lineに要素が存在しないならループから抜ける
  if len(line)==0:
    break
  #整数でないならその数は存在しないと同義なので処理を行わない
  if int(k) != k:
    continue
  x=number(k)
  #もしlineの最大値よりxが大きければ条件を満たすxは存在しないので処理を行わない
  if x>line[-1]:
    continue
  #その数が存在するならば、その数をlistから消去して、カウントする
  if line[bisect.bisect_left(line,x)]==x:
    #0.5を足すことでremoveの代わりとする
    line[bisect.bisect_left(line,x)] += 0.5
    count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import bisect

def number(num):
  #0bのぶんを引きます
  number_len = len(bin(num))-2
  #numと同じ桁数で各桁が全て1である数を求めます。
  f = 2**number_len - 1
  #排他的論理和をとって1を足したものを返します
  return (num^f)+1

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

count=0

while len(line)>0:
  #最後の数を取ってくる(最後尾なのでO(1)で済む)
  k=line.pop()
  #lineに要素が存在しないならループから抜ける
  if len(line)==0:
    break
  #整数でないならその数は存在しないと同義なので処理を行わない
  if int(k) != k:
    continue
  x=number(k)
  #もしlineの最大値よりxが大きければ条件を満たすxは存在しないので処理を行わない
  if x>line[-1]:
    continue
  #その数が存在するならば、その数をlistから消去して、カウントする
  if line[bisect.bisect_left(line,x)]==x:
    #0.5を足すことでremoveの代わりとする
    line[bisect.bisect_left(line,x)] += 0.5
    count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import bisect
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  k=number.pop()
  if k==int(k):
    x=reversed_num(k)+1
    if len(number)==0:
      break
    y=bisect.bisect_left(number,x)
    if x>number[-1]:
      y-=1
    if number[y] ==x:
      number[y]+=0.5
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  x=reversed_num(number[-1])+1
  if x!=number[-1]:
    number.pop()
    if x in number:
      number.remove(x)
      count+=1
  else:
    number.pop()
print(count)

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  x=reversed_num(number[-1])+1
  if x in number:
    if x!=number[-1]:
      number.remove(x)
      count+=1
  number.pop()
print(count)

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  x=reversed_num(number[-1])+1
  if x in number and x!=number[-1]:
    number.remove(x)
    count+=1
  number.pop()
print(count)

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  if reversed_num(number[-1])+1 in number and number[-1]!=reversed_num(number[-1])+1:
    number.remove(reversed_num(number[-1])+1)
    count+=1
  number.pop()
print(count)

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  if (number[-1]!=reversed_num(number[-1])+1) and (reversed_num(number[-1])+1 in number):
    number.remove(reversed_num(number[-1])+1)
    count+=1
  number.pop(-1)
print(count)

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
count=0
while len(number)>0:
  if number[-1]!=reversed_num(number[-1])+1 and reversed_num(number[-1])+1 in number:
    number.remove(reversed_num(number[-1])+1)
    count+=1
  number.pop(-1)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
B = [False]*N
Bi = []
for i in range(0,32):
  Bi.append(2**i)
ans = 0
L.sort()
for i in range(N):
  cur = L[N-i-1]
  if B[N-i-1] == True:
    None
  else:
    B[N-i-1] = True
    for j in range(N-i-1):
      if B[j] == False:
        S = cur+L[j]
        if S in Bi:
          ans += 1
          B[j] = True
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
B = [False]*N
ans = 0
L.sort()
for i in range(N):
  cur = L[N-i-1]
  if B[N-i-1] == True:
    None
  else:
    B[N-i-1] = True
    for j in range(N-i-1):
      if B[j] == False:
        S = cur+L[j]
        while S > 1:
          if S%2 == 0:
            S = S/2
          else:
            break
        if S == 1:
          ans += 1
          B[j] = True
print(ans)

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number.sort()
number.reverse()
count=0
for i in number:
  if i!=reversed_num(i)+1 and reversed_num(i)+1 in number:
    number.remove(reversed_num(i)+1)
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
number2=[i for i in number]
number.sort()
number.reverse()
goal=[]
for i in number:
  if i != reversed_num(i)+1:
    goal.append(reversed_num(i)+1)
    if reversed_num(i)+1 in number:
      number.remove(reversed_num(i)+1)
print(len(set(number2)&set(goal)))

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2**num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
goal=[]
for i in number:
  if i != reversed_num(i)+1:
    goal.append(reversed_num(i)+1)
print(len(set(number)&set(goal)))

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2*num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
goal=[]
for i in number:
  if i != reversed_num(i)+1:
    goal.append(reversed_num(i)+1)
print(len(set(number)&set(goal)))

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2*num_len-1
  return num^f
n=int(input())
number=list(map(int,input().split()))
goal=[]
for i in number:
  goal.append(reversed_num(i)+1)
print(len(set(number)&set(goal)))

Submission status: Wrong Answer

Solution code:
def reversed_num(num):
  num_len=len(bin(num))-2
  f=2*num_len-1
  return num^f

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    N = int(sys.stdin.readline().rstrip())
    A = list(map(int,sys.stdin.readline().rstrip().split()))
    A = sorted(A, reverse=True)
    maxA = A[0]
    cntA = [0 for i in range(maxA+1)]
    for a in A:
        cntA[a] += 1

    ans = 0
    twos = 1 << 32
    for a in A:
        if a <= 2:
            return ans
        if cntA[a] == 0:
            continue
        cntA[a] -= 1
        #print('a =',a)
        while True:
            b = twos - a
            #print('b =',b)
            if b <= a:
                break
            twos //= 2
            if twos == 1:
                return ans
        if cntA[b] > 0:
            cntA[b] -= 1
            ans += 1
    return ans

print(solve())

Submission status: Wrong Answer

Solution code:
import bisect
inpl = lambda: list(map(int,input().split()))
_ = int(input())
A = sorted(inpl())
Anlist = []
ap = 0
for a in A:
  if a > ap:
    Anlist.append([a,1])
    ap = a
  else:
    Anlist[-1][1] += 1

As = [ a for a,n in Anlist]
N = len(Anlist)

ans = 0
for i in range(1,N+1):
  if Anlist[-i][1] == 0:
    continue
  
  p = len(bin(A[-i]))-3
  B = (1 << (p+1)) - A[-i]
  if A[-i] == B:
    ans += Anlist[-i][1]//2
  else:
    m = bisect.bisect_left(As,B,0,N-i)
    if m < N-i and A[m] == B:
      pairs = min(Anlist[m][1],Anlist[-i][1])
      ans += pairs
      Anlist[m][1] -= pairs

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
inpl = lambda: list(map(int,input().split()))
_ = int(input())
A = sorted(inpl())
Anlist = []
ap = 0
for a in A:
  if a > ap:
    Anlist.append([a,1])
  else:
    Anlist[-1][1] += 1

As = [ a for a,n in Anlist ]
N = len(Anlist)

ans = 0
for i in range(1,N+1):
  if Anlist[-i][1] == 0:
    continue
  
  p = len(bin(A[-i]))-3
  B = (1 << (p+1)) - A[-i]
  if A[-i] == B:
    ans += Anlist[-i][1]//2
  else:
    m = bisect.bisect_left(As,B,0,N-i)
    if m < N-i and A[m] == B:
      pairs = min(Anlist[m][1],Anlist[-i][1])
      ans += pairs
      Anlist[m][1] -= pairs

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
inpl = lambda: list(map(int,input().split()))
N = int(input())
A = sorted(inpl())
used = [0] * N

ans = 0
for i in range(1,N):
  if used[-i] == 1:
    continue
  p = len(bin(A[-i]))-3
  B = (1 << (p+1)) - A[-i]
  m = bisect.bisect_left(A,B,0,N-i)
  if m < N-i and used[m] == 0 and A[m] == B:
    ans += 1
    used[m] = 1

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
inpl = lambda: list(map(int,input().split()))
N = int(input())
A = sorted(inpl())
used = [0] * N

ans = 0
for i in range(1,N):
  if used[-i] == 1:
    continue
  p = len(bin(A[-i]))-3
  B = (1 << (p+1)) - A[-i]
  m = bisect.bisect_left(A,B,0,N-i)
  if m < N-i and used[m] == 0 and A[m] == B:
    ans += 1
    used[m] = 1
    print((A[-i],A[m]))

print(ans)

Submission status: Wrong Answer

Solution code:
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:
        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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

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

def bsearch_list(a, x):
    l = bisect_left(a, x)
    r = bisect_right(a, x)
    if l < r:
        return list(range(l, r))
    else:
        return []

pair_list = [[i, set()] for i in range(N)]
for t in range(1, 50):
    pow2 = 2 ** t
    if A[-1] * 2 < pow2:
        break
    for i in range(N):
        pair = set(bsearch_list(A, pow2 - A[i])) - {i}
        pair_list[i][1] = pair_list[i][1] | pair
        
pair_list_idx = [p[0] for p in sorted(pair_list, key=lambda x: len(x[1]))]
ans = 0
for i in pair_list_idx:
    if len(pair_list[i][1]) == 0: continue
    another = pair_list[i][1].pop()
    pair_list[another][1].clear()
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
two = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648}
odd = []
even = []
for i in a:
    if i % 2:
        odd.append(i)
    else:
        even.append(i)
ans = 0
for i in range(len(odd)):
    for j in range(i + 1, len(odd)):
        if odd[i] + odd[j] in two:
            ans += 1
            break
for i in range(len(even)):
    for j in range(i + 1, len(even)):
        if even[i] + even[j] in two:
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
a = list(map(int, input().split()))
two = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824}
odd = []
even = []
for i in a:
    if i % 2:
        odd.append(i)
    else:
        even.append(i)
ans = 0
for i in range(len(odd)):
    for j in range(i + 1, len(odd)):
        if odd[i] + odd[j] in two:
            ans += 1
            break
for i in range(len(even)):
    for j in range(i + 1, len(even)):
        if even[i] + even[j] in two:
            ans += 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
a=input()
s=a.split(" ")
s=[int(x) for x in s]
count=0
for i in range(n-2,-1,-1):
    for j in range(n-1,i,-1):
        if math.log(int(s[i]+s[j]),2).is_integer():
            count+=1
            break
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import math
n=int(input())
a=input()
s=a.split(" ")
s=[int(x) for x in s]
stop_list=[]
count=0
for i in range(n-2,-1,-1):
    for j in range(i+1,n):
        if j in stop_list:
            continue
        if math.log(int(s[i]+s[j]),2).is_integer():
            count+=1
            stop_list.append(j)
            break
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import math
n=int(input())
a=input()
s=a.split(" ")
s=[int(x) for x in s]
p_com=list(itertools.combinations(s,2))
p_t=[1 if math.log(x[0]+x[1],2).is_integer() else 0 for x in p_com ]
index=[]
count=0
for i in range(1,n):
    for j in range(i+1,n+1):
        if (p_t[count]==1):
            index.append((i,j))
        count+=1
a=[]
for i in index:
    a.append(i[0])
print(len(set(a)))

Submission status: Wrong Answer

Solution code:
import itertools
import math
n=int(input())
a=input()
s=a.split(" ")
s=[int(x) for x in s]
p_com=list(itertools.combinations(s,2))
p_t=[1 if math.log(x[0]+x[1],2).is_integer() else 0 for x in p_com ]
index=[]
count=0
for i in range(1,n):
    for j in range(i+1,n+1):
        if (p_t[count]==1):
            index.append((i,j))
        count+=1
x=[]
for i in index:
    x.extend(i)
xlen=len(x)
x=len(set(x))
x=math.ceil((xlen-x)/2)
print(len(index)-x)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
S = input()

count = 0
for i in range(len(S)):
    if S[i] == 'W':
        continue
    else:
        break
S = S[i:]

count = 0
score = 0
for i in range(len(S)):
    if S[i] == 'W':
        score += (i - count)
        count += 1
print(score)

Submission status: Wrong Answer

Solution code:
N = int(input())
gu = []
ki = []
for x in map(int, input().split()):
    if x % 2 == 0:
        gu.append(x)
    else:
        ki.append(x)
gu.sort()
ki.sort()

cache = {}
for x in gu:
    for y in gu:
        if y <= x:
            continue
        if not ((x + y) & ((x + y)-1)):
            if x in cache:
                cache[x].append(y)
            else:
                cache[x] = [y]
for x in ki:
    for y in ki:
        if y <= x:
            continue
        if not ((x + y) & ((x + y)-1)):
            if x in cache:
                cache[x].append(y)
            else:
                cache[x] = [y]

cache = list(cache.items())
cache.sort(key=lambda x:len(x[1]))

count = 0
used = []
for k,v in cache:
    if k in used:
        continue
    for x in v:
        if v in used:
            continue
        used.append(k)
        used.append(v)
        count += 1
        break
print(count)

Submission status: Wrong Answer

Solution code:
two_power = set()
temp = 2
power = 1
while temp <=  (10**9) * 2:
    two_power |= {temp}
    power += 1
    temp = 2 ** power

answer = 0
length = int(input())
targets = sorted([int(n) for n in input().split(" ")])
choosed = set()
for i in range(length):
    if i in choosed:
        continue
    for j in range(i + 1, length):
        if targets[i] + targets[j] in two_power:
            answer += 1
            choosed |= {j}
            break
print(answer)

Submission status: Wrong Answer

Solution code:
two_power = set()
temp = 2
power = 1
while temp <=  (10**9) * 2:
    two_power |= {temp}
    power += 1
    temp = 2 ** power

answer = 0
length = int(input())
targets = sorted([int(n) for n in input().split(" ")])
for i in range(length):
    for j in range(i + 1, length):
        if targets[i] + targets[j] in two_power:
            answer += 1
print(answer)

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
A=list(map(int,input().split()))
A.sort()
A.append(999999999999999)
B=[]
for i in range(1,35):
    B.append(2**i)
ans=0
for i in range(N):
    if A[N-1-i]==int(A[N-1-i]):
        for j in range(len(B)):
            if A[N-1-i]<B[j]:
                break
        if A[bisect.bisect_left(A,B[j]-A[N-1-i])]==B[j]-A[N-1-i]:
            if bisect.bisect_left(A,B[j]-A[N-1-i])<N-1-i:
                A[bisect.bisect_left(A,B[j]-A[N-1-i])]-=0.1
                A[N-1-i]-=0.1
                ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(35):
    B.append(2**i)

A.sort()
A.append(9999999999)
ans=0
for i in range(N):
    X=bisect.bisect_left(B,A[N-1-i])
    if A[N-1-i]==B[X]:
        X+=1
        A[N-1-i]+=0.4
        if A[bisect.bisect_left(A,B[X]-A[N-1-i]+0.4)]==B[X]//2:
            ans+=1
            A[bisect.bisect_left(A,B[X]-A[N-1-i]+0.4)]-=0.1
    elif A[bisect.bisect_left(A,B[X]-A[N-1-i])]==B[X]-A[N-1-i]:
        ans+=1
        A[N-1-i]+=0.2
        A[bisect.bisect_left(A,B[X]-A[N-1-i])]-=0.1
    #print(A)
print(ans)
#print(A)
#print(B)

Submission status: Wrong Answer

Solution code:
import bisect

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]
for i in range(1,100):
    if 2**i>2*(10**9):
        break
    else:
        B.append(2**i)
B.append(2**(i+1))
ans=0
#print(B)
for i in range(N):
    X=bisect.bisect_left(B,A[N-1-i])
    if B[X]==A[N-1-i]:
        X+=1
    #print(X)
    if B[X]==2*A[N-1-i]:
        #print(B[X],A[N-i])
        A[N-1-i]+=0.3
        #print(A[bisect.bisect_left(A,B[X]-A[N-i]+0.3)],B[X]-A[N-i]+0.3)
        if A[bisect.bisect_left(A,B[X]-A[N-1-i]+0.3)]==B[X]-A[N-1-i]+0.3:
            ans+=1
            #print(B[X],i)
            #print(B[X])
            A[bisect.bisect_left(A,B[X]-A[N-1-i]-0.2)]-=0.1
    elif A[bisect.bisect_left(A,B[X]-A[N-1-i])]==B[X]-A[N-1-i]:
        ans+=1
        #print(B[X],i)
        A[bisect.bisect_left(A,B[X]-A[N-1-i])]-=0.1
        A[N-1-i]+=0.2
print(ans)
#print(A)

Submission status: Wrong Answer

Solution code:
import bisect

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]
for i in range(1,100):
    if 2**i>2*(10**9):
        break
    else:
        B.append(2**i)
B.append(2**(i+1))
ans=0
#print(B)
for i in range(N):
    X=bisect.bisect_left(B,A[N-1-i])
    if B[X]==A[N-1-i]:
        X+=1
    #print(X)
    if B[X]==2*A[N-1-i]:
        A[N-1-i]+=0.3
        if A[bisect.bisect_left(A,B[X]-A[N-1-i]+0.3)]==B[X]-A[N-1-i]+0.3:
            ans+=1
            A[bisect.bisect_left(A,B[X]-A[N-1-i]-0.2)]-=0.1
    elif A[bisect.bisect_left(A,B[X]-A[N-1-i])]==B[X]-A[N-1-i]:
        ans+=1
        A[bisect.bisect_left(A,B[X]-A[N-1-i])]-=0.1
        A[N-1-i]+=0.2
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]
for i in range(1,100):
    if 2**i>2*(10**9):
        break
    else:
        B.append(2**i)
B.append(2**(i+1))
ans=0
#print(B)
for i in range(N):
    X=bisect.bisect_left(B,A[N-1-i])
    if B[X]==A[N-1-i]:
        X+=1
    #print(X)
    if B[X]==2*A[N-1-i]:
        A[N-1-i]+=0.2
        if A[bisect.bisect_left(A,B[X]-A[N-1-i]-0.2)]==B[X]-A[N-1-i]-0.2:
            ans+=1
            A[bisect.bisect_left(A,B[X]-A[N-1-i]-0.2)]-=0.1
    elif A[bisect.bisect_left(A,B[X]-A[N-1-i])]==B[X]-A[N-1-i]:
        ans+=1
        A[bisect.bisect_left(A,B[X]-A[N-1-i])]-=0.1
        A[N-1-i]+=0.2
print(ans)
#print(A)

Submission status: Wrong Answer

Solution code:
import bisect

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]
for i in range(1,100):
    if 2**i>2*(10**9):
        break
    else:
        B.append(2**i)
B.append(2**(i+1))
ans=0
#print(B)
for i in range(N):
    X=bisect.bisect_left(B,A[N-1-i])
    #print(X)
    if A[bisect.bisect_left(A,B[X]-A[N-1-i])]==B[X]-A[N-1-i]:
        ans+=1
        A[bisect.bisect_left(A,B[X]-A[N-1-i])]-=0.1
print(ans)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
l = list(map(int, input().split()))
ld = sorted(l, reverse=True)

k = 0
while 2**k < ld[0] + ld[1]:
    k += 1
p = 0

for n in range(1,k):

    for m in range(0,math.floor(len(ld) / 2) + 1):

        if 2**n - ld[m] in ld:
            p += 1
print(p)

Submission status: Wrong Answer

Solution code:
import sys

def main(l):
    u = set()
    l = list(sorted(l))
    for i, a in enumerate(reversed(l)):
        searching = (1 << a.bit_length()) - a
        for j, b in enumerate(l[:-i-1]):
            if b == searching and not j in u:
                u.add(j)
                break

    return len(u)


if __name__ == '__main__':
    input()
    print(main(map(int, input().split())))

Submission status: Wrong Answer

Solution code:
import sys

def main(l):
    u = set()
    l = list(sorted(l))
    for i, a in enumerate(reversed(l)):
        searching = (1 << a.bit_length()) - a
        for j, b in enumerate(l[:-i-1]):
            if b == searching and not j in u:
                u.add(j)
                break

    return len(u)


if __name__ == '__main__':
    input()
    main(map(int, input().split()))

Submission status: Wrong Answer

Solution code:
def next_power(nb):
    nb |= nb >> 1
    nb |= nb >> 2
    nb |= nb >> 4
    nb |= nb >> 8
    nb |= nb >> 16
    nb += 1
    return nb


input()
nbs = list(sorted(map(int, input().split())))
used = set()

for i, big in enumerate(reversed(nbs)):
    searching = next_power(big) - big
    for j, small in enumerate(nbs[:-i-1]):
        if small > searching:
            break
        if small == searching and j not in used:
            used.add(j)
            break

print(len(used))

Submission status: Wrong Answer

Solution code:
def next_power(nb):
    nb |= nb >> 1
    nb |= nb >> 2
    nb |= nb >> 4
    nb |= nb >> 8
    nb |= nb >> 16
    nb += 1
    return nb


input()
nbs = list(map(int, input().split()))
used = set()

for i, big in enumerate(reversed(nbs)):
    searching = next_power(big) - big
    for j, small in enumerate(nbs[:-i-1]):
        if small > searching:
            break
        if small == searching and j not in used:
            print(-i-1, big, j, small)
            used.add(j)

print(len(used))

Submission status: Wrong Answer

Solution code:
import sys

def next_power(nb):
    nb |= nb >> 1
    nb |= nb >> 2
    nb |= nb >> 4
    nb |= nb >> 8
    nb |= nb >> 16
    nb += 1
    return nb


nbs = list(sys.stdin)[1]
nbs = list(sorted(map(int, nbs.split())))
used = set()

for i, big in enumerate(reversed(nbs)):
    searching = next_power(big) - big
    for j, small in enumerate(nbs[:-i-1]):
        if small > searching:
            break
        if small == searching and j not in used:
            print(-i-1, big, j, small)
            used.add(j)

print(len(used))