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: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
aa, ab = [], []
ans, ans_cheak = 0, 0
for _ in a:
    if _%2 == 0:
        aa.append(_)
    else:
        ab.append(_)
count_aa, count_ab = len(aa), len(ab)

m = [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]

if len(aa) >= 2:
    max_aa = aa[0]+aa[1]
    aa.sort(reverse=True)

    for match_aa in range(len(m)):
        if m[match_aa] >= max_aa:
            m_aa = m[0:match_aa+1]
            break

    for i in range(count_aa):
        for j in range(count_aa-1):
            if aa[0]+aa[j+1] in m_aa:
                ans_cheak = 1
            
                aa.remove(aa[0])
                aa.remove(aa[j])
                break

        if ans_cheak != 0:
            ans += ans_cheak
            ans_cheak = 0
        else:
            aa.remove(aa[0])
        if len(aa) <= 1:
            break

if len(ab) >= 2:
    max_ab = ab[0]+ab[1]
    ab.sort(reverse=True)
    
    for match_ab in range(len(m)):
        if m[match_ab] >= max_ab:
            m_ab = m[0:match_ab+1]
            break

    for k in range(count_ab):
        for l in range(count_ab-1):
            if ab[0]+ab[l+1] in m_ab:
                ans_cheak = 1
            
                ab.remove(ab[0])
                ab.remove(ab[l])
                break

        if ans_cheak != 0:
            ans += ans_cheak
            ans_cheak = 0
        else:
            ab.remove(ab[0])
        if len(ab) <= 1:
            break

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
k = 1
twos = []
while k<2*10**5+1:
    twos += [k]
    k = k<<1
l = []
key = a[-1]
a.pop()
ans = 0
while True:
    for k in range(len(twos)-1):
        if twos[k]<key and key<twos[k+1]:
            two = twos[k+1]
            break
    for j in range(len(a)):
        if a[j]==two-key:
            a.remove(a[j])
            ans +=1
            break
    if not a==[]:
        key = a[-1]
        a.pop()
    else:
        break
print(ans)

Submission status: Runtime Error

Solution code:
import bisect

def number(num):
  #0bのぶんを引きます
  number_len = len(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()
  #整数でないならその数は存在しないと同義なので処理を行わない
  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: Runtime Error

Solution code:
import bisect

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

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

count=0

while len(line)>0:
  #最後の数を取ってくる(最後尾なのでO(1)で済む)
  k=line.pop()
  #整数でないならその数は存在しないと同義なので処理を行わない
  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: Runtime Error

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:
  x=reversed_num(number.pop())+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: Runtime Error

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:
  x=reversed_num(number.pop())+1
  if number[bisect.bisect_left(number,x)] ==x:
    number.pop(bisect.bisect_left(number,x))
    count+=1
print(count)

Submission status: Runtime Error

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:
  x=reversed_num(number.pop())+1
  if number[bisect.bisect_left(number,x)] ==x:
    number[bisect.bisect_left(number,x)]=0
    count+=1
print(count)

Submission status: Runtime Error

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:
  q=number[-1]
  x=reversed_num(number[-1])+1
  number.pop()
  if x!=q:
    if x in list:
      number.remove(x)
      count+=1
print(count)

Submission status: Runtime Error

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:
    number.remove(x)
    count+=1
  number.pop()
print(count)

Submission status: Runtime Error

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()
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: Runtime Error

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()
goal=[]
for i in number:
  if i != reversed_num(i)+1:
    goal.append(reversed_num(i)+1)
    number.remove(reversed_num(i)+1)
print(len(set(number)&set(goal)))

Submission status: Runtime Error

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.reversed()
goal=[]
for i in number:
  if i != reversed_num(i)+1:
    goal.append(reversed_num(i)+1)
    number.remove(reversed_num(i)+1)
print(len(set(number)&set(goal)))

Submission status: Runtime Error

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] * (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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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):
    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(A)
                    
print(ans)

Submission status: Runtime Error

Solution code:
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: Runtime Error

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.append(A.popleft())
        if len(A) == 0: break
        if A[0] + r == pow2:
            A.popleft()
            ans += 1
    A.extendleft(A_tmp)
                    
print(ans)

Submission status: Runtime Error

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 = A_tmp + A
                    
print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_left, bisect_right
 
N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
 
ans = 0
while len(A) > 1:
    pow2 = 1 << (len(bin(A[-1])) - 2)
    idx = bisect_left(A, pow2 - A[-1])
    if A[idx] + A[-1] == pow2 and idx != len(A) - 1:
        A.pop(idx)
        ans += 1
    A.pop(-1)
print(ans)
from bisect import bisect_left, bisect_right

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

ans = 0
while len(A) > 1:
    pow2 = 1 << (len(bin(A[-1])) - 2)
    idx = bisect_left(A, pow2 - A[-1])
    if A[idx] + A[-1] == pow2 and idx != len(A) - 1:
        A.pop(idx)
        ans += 1
    A.pop()
print(ans)

Submission status: Runtime Error

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:
    for j in range(30):
        if A_arr[0] > two_arr[j]:
            pass
        else:
            v_pair = two_arr[j] - A_arr[0]
            break
    if v_pair in A_arr:
        A_arr.remove(v_pair)
        count += 1
    else:
        pass
    A_arr.pop(0)

print(count)

Submission status: Runtime Error

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_idx.remove(another)
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
A = collections.deque(sorted(map(int,input().split())))


def func1(a, r, rnext):
    p = A.popleft()
    q = A.pop()
    ans = 0
    a1 = collections.deque()
    while True:
        if p + q == r:
            ans += 1
            try:
                p = a.popleft()
            except:
                break
            try:
                q = a.pop()
            except:
                if p < rnext:
                    a1.append(p)
                break
        elif p + q > r:
            try:
                q = a.pop()
            except:
                if p < rnext:
                    a1.append(p)
                break
        else:
            a1.append(p)
            try:
                p = a.popleft()
            except:
                if q < rnext:
                    a1.append(q)
                break
    return ans, a1

t = int.bit_length(A[-1])
r = 2 ** t
rnext = 2 ** (t - 1)
anser = 0
a = A

while True:
    ans, a1 = func1(a, r, rnext)
    anser += ans
    if len(a1) < 2:
        break
    a = a1
    t -= 1
    r = rnext
    rnext = 2 ** (t - 1)

print(anser)

Submission status: Runtime Error

Solution code:
import bisect

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]
for i in range(1,10):
    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)
#print(B)

Submission status: Runtime Error

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 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.1
print(ans)

Submission status: Runtime Error

Solution code:
import bisect

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[]
for i in range(1,10):
    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: Runtime Error

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

k = 0
two = []
while 2**k < ld[0] + ld[1]:
    k+=1
    two.append(2**k)
p = 0

while len(ld) > 0:
    for m in range(1,len(ld)):
        if (ld[0] + ld[m]) in two:
            del ld[m]
            p += 1
            break
    if len(ld) > 0:
        del ld[0]
    if len(ld) = 0:
        break
print(p)

Submission status: Runtime Error

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

k = 0
two = []
while 2**k < ld[0] + ld[1]:
    k+=1
    two.append(2**k)
p = 0

while len(ld) > 0:
    for m in range(1,len(ld)):
        if (ld[0] + ld[m]) in two:
            del ld[m]
            p += 1
    if len(ld) > 0:
        del ld[0]
print(p)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(reversed(sorted(a)))
ans = 0
while len(b) > 0:
    c = list(map(int,str(format(b[0],'b'))))
    d = [1-c[i] for i in range(len(c))]
    d[-1] = d[-1]+1 
    try:
        e = b.index(int(''.join(list(map(str,d))),2))
        del b[e]
        del b[0]
        ans += 1
    except:
        del b[0]
print(ans)

Submission status: Runtime Error

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__':
    main(map(int, sys.stdin))

Submission status: Runtime Error

Solution code:
N = int(raw_input())
n = map(int, raw_input().split())

#new_n = list( filter (lambda x, y: (x+y)%2==0, n) )
#print n, new_n

#print N, n, range(N)
#print range(1, N)

number = 0
for i in range(N-1):
    for j in range ( i + 1, N ):
        #print n[i], n[j],   (n[i]+n[j]) %2
        if (n[i] + n[j]) % 2 == 0:
            number = number+1
            #print n[i]+n[j], number
            del n[i]
            del n[j-1]
            #print n
            i = i + 1
            if len(n)==1:
                print number
                exit()
            continue

Submission status: Runtime Error

Solution code:
#AGC030 B - Powers of two
import collections
import math
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnter=collections.Counter(A)
ans=0
for a in A:
    inv=2**(int(math.log2(a))+1)
    if cnter[a]==0:
        continue
    if cnter[a]>=2 and a==inv//2:a
        cnter[a]=cnter[a]-2
        ans=ans+1
        continue
    if inv-a in cnter:
        cnter[inv-a]=cnter[inv-a]-1
        ans=ans+1
print(ans)

Submission status: Runtime Error

Solution code:
#AGC030 B - Powers of two
import collections
import math
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnter=collections.Counter(A)
ans=0
for a in A:
    inv=2**(int(math.log2(a))+1)
    if cnter[a]==0:
        continue
    if cnter[a]>=2 and a=inv//2:
        cnter[a]=cnter[a]-2
        ans=ans+1
        continue
    if inv-a in cnter:
        cnter[inv-a]=cnter[inv-a]-1
        ans=ans+1
print(ans)

Submission status: Runtime Error

Solution code:
#AGC030 B - Powers of two
import collections
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnter=collections.Counter(A)
ans=0
for i in (reversed(beki)):
    for a in A:
        if (i//2<a<i and (i-a in cnter) )or(i//2==a and cnter[a]>=2):
            ans=ans+1
            A.remove(i-a)
print((N-len(A))//2)

Submission status: Runtime Error

Solution code:
#AGC030 B - Powers of two
import collections
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=map(int,input().split())
A.sorted(reverse=True)
cnter=collections.Counter(A)
ans=0
for i in (reversed(beki)):
    for a in A:
        if (i//2<a<i and (i-a in cnter) )or(i//2==a and cnter[a]>=2):
            ans=ans+1
            A.remove(i-a)
print((N-len(A))//2)

Submission status: Runtime Error

Solution code:
#AGC030 B - Powers of two
import copy
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=input().split()
for i in range(N):
    A[i]=int(A[i])
for i in (reversed(beki)):
    B=copy.deepcopy(A)
    for j in B:
        if i//2<j<i:
            if i-j in B:
                A.remove(i-j)
                A.remove(j)
        if j==i//2:
            if B.count(j)>=2:
                A.remove(j)
                A.remove(j)
print((N-len(A))//2)

Submission status: Runtime Error

Solution code:
#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
N=int(input())
A=input().split()
for i in range(N):
    A[i]=int(A[i])
sorted(A)#Aを昇順にソート
for i in (reversed(beki)):
    B=A
    for j in B:
        if j==i/2 and B.count(j)=>2:
            A.remove(j)
            A.remove(j)
        if i-j in A:
            A.remove(j)
            A.remove(i-j)
print((N-len(A))//2)

Submission status: Runtime Error

Solution code:
#AGC030 B - Powers of two
beki=[]
for i in range(1,32):
    beki.append(2**i)#bekiは２のべき乗の配列
def tasitekesu(data,n):#dataの中で足したらnになるやつを消し、消した結果とペア数を報告する
    result=[]
    kosu=0
    for i in range(len(data)):
        if i in result:
            continue
        for j in range(i):
            if j in result:
                continue
            if data[i]+data[j]==n:
                result.append(i)
                result.append(j)
                kosu=kosu+1
                break
    result.sort(reverse=True)
    for i in result:
        del data[i]
    return [data,kosu]

N=int(input())
A=input().split()
ans=0
for i in range(N):
    A[i]=int(A[i])
sorted(A)#Aを昇順にソート
for i in (reversed(beki)):
    kesi=[]
    for j in range(len(A)):
        if j==len(A):
            break
        if i-A[j] in A:
            A.remove(i-A[j])
            kesi.append(j)
            ans=ans+1
    for j in (reversed(kesi)):
        A.pop(j)
print(ans)

Submission status: Runtime Error

Solution code:
def solve():
    N = int(input())
    data = list(map(int, input().split()))
    temp = data
    while True:
        temp = list(itertools.combinations(sorted(temp, reverse=True), 2))
        temp2 = list(filter(lambda i: not (i[0] + i[1] & (i[0] + i[1] - 1)), temp))
        x = []

        [x.extend(list(i)) for i in temp2]
        ans = list(set(x))
        if len(ans) == len(set(ans)):
            break
        temp = ans


    print(len(ans)/2)


solve()

Submission status: Runtime Error

Solution code:
def solve():
    N = int(input())
    data = list(map(int, input().split()))
    temp = data
    while True:
        temp = list(itertools.combinations(sorted(temp, reverse=True), 2))
        temp2 = list(filter(lambda i: not (i[0] + i[1] & (i[0] + i[1] - 1)), temp))
        x = []

        [x.extend(list(i)) for i in temp2]
        ans = list(set(x))
        if len(ans) == len(set(ans)):
            break
        temp = ans


    print(ans/2)


solve()

Submission status: Runtime Error

Solution code:
b = []
for i in range(2):
  b += input('').split()
n = int(b[0])
l = b[1:]
l = [int(i) for i in l]
c = 0
for i in range(n):
  for j in range(n):
    if i>=j:
      pass
    else:
      a = float([i]+l[j])
      while a > 1.0:
        a /= 2
      if a == 1.0:
        c += 1
      else:
        pass
print(c)

Submission status: Runtime Error

Solution code:
b = []
for i in range(2):
  b += input('').split()
n = int(b[0])
l = b[1:]
l = [int(l[i]) for i in l]
c = 0
for i in range(n):
  for j in range(n):
    if i>=j:
      pass
    else:
      a = l[i]+l[j]
      while a > 1:
        a /= 2
      if a == 1:
        c += 1
      else:
        pass
print(c)

Submission status: Runtime Error

Solution code:
b =[]
for i in range(2)
  b +== input('').split
n = int[b[0]]
l = b[1:]
l = [int(i) for i in l]
c = 0
for i in range(n):
  for j in range(n):
    if i>=j:
      pass
    else:
      a = l[i]+l[j]
      while a > 1:
        a /= 2
      if a == 1:
        c += 1
      else:
        pass
print(c)

Submission status: Runtime Error

Solution code:
n = int(input(''))
l = input('').split
l = [int(l[i]) for i in range(n)]
c = 0
for i in range(n):
  for j in range(n):
    if i>=j:
      pass
    else:
      a = l[i]+l[j]
      while a > 1:
        a /= 2
      if a == 1:
        c += 1
      else:
        pass
print(c)

Submission status: Runtime Error

Solution code:
n = int(input(''))
l = input('').split
l = [int(l[i]) for i in range(n)]
c = 0
for i in range(n):
  for j in range(n):
    if i>=j:
      pass
    else:
      a = l[i]+l[j]
      while a > 1:
        a /= 2
      if a == 1:
        c += 1
      else:
        pass

Submission status: Runtime Error

Solution code:
n = input('')
l = input('').split
l = [int(l[i]) for i in range(n)]
c = 0
for i in range(n):
  for j in range(n):
    if i>=j:
      pass
    else:
      a = l[i]+l[j]
      while a > 1:
        a /= 2
      if a == 1:
        c += 1
      else:
        pass

Submission status: Runtime Error

Solution code:
n = input('')
l = input('').split
l = [int(l[i]) for i in range(len(l))]
c = 0
for i in range(n):
  for j in range(n):
    if i>=j:
      pass
    else:
      while l[i] > 1.0:
        l[i] /= 2
      if l[i] == 1:
        c += 1
      else:
        pass

Submission status: Runtime Error

Solution code:
n = input('')
l = int(input('').split
l = [int(l[i]) for i in range(len(l))]
c = 0
for i in range(n):
  for j in range(n):
    if i>=j:
      pass
    else:
      while l[i] > 1.0:
        l[i] /= 2
      if l[i] == 1:
        c += 1
      else:
        pass

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
count = 0
i = 0
reg = 1
while True:
    if i >= N - 1:
        break
    now = A[i]
    reg = 1
    for j in range(32):
        reg *= 2
        if reg <= now:
            continue
        elif A.count(reg - now) == 0:
            break
        else:
            del(A[A.index(reg - now)])
            count += 1
            i += 1
    i += 1
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import collections
    
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
c=collections.Counter(A)
    
pairCounter=0
    
beki=29
nibeki=2**beki
    
for i in range(N):
    target = A[i]
    if c[target] < 1:
    continue
    c[target]-= 1
    
    while (nibeki > target):
    beki-=1
    nibeki=2**beki
    
    pair = nibeki * 2 - target
    if pair in c.keys() and c[pair] > 0:
        c[pair]-= 1
        pairCounter+=1
     
print(pairCounter)