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:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

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

sum = 0
i = 0
u = [0 for i in range(len(a))]
while True:

    t = 0
    for bb in b :
        if bb > a[i]:
            t = bb - a[i]
            break
    
    try:
        idx = a.index(t)
        if idx != i and u[idx] != 1:            
            sum += 1
            u[idx] = 1
    except Exception as e:
        pass
    
    i = i + 1
    if i >= len(a)-1:
        break

print(sum)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter


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

n_pears = 0
counter = Counter(A)

for i in reversed(range(0, len(A))):
    if counter[A[i]] <= 0:
        continue
    counter[A[i]] -= 1
    Aj = 2 * int(math.log2(A[i]) + 1) - A[i]
    if counter[Aj] > 0:
        n_pears += 1
        counter[Aj] -= 1

print(n_pears)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = list(map(int,input().split()))
a.sort()

b = [2147483648, 1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2,0]

c = [0]*n #使ったら1

res = 0

for i in range(31):
    k1 = bisect.bisect_left(a,b[i+1])
    k2 = bisect.bisect_right(a,b[i])

    if k2 > k1:

        for j in range(k1,k2):
            if c[j] == 0:
                w1 = bisect.bisect_left(a,b[i]-a[j])
                w2 = bisect.bisect_right(a,b[i]-a[j])

                if w2 >w1:
                    p = w1
                    while p != w2:
                        if c[p] == 0 and j != p:
                            res += 1
                            c[p] = 1
                            p = w2-1
                        p += 1

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)

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

sum = 0
i = 0
u = [0 for i in range(len(a))]
while True:

    t = 0
    for bb in b :
        if bb > a[i]:
            t = bb - a[i]
            break
    
    try:
        idx = a.index(t)
        if u[idx] != 1:            
            sum += 1
            u[idx] = 1
    except Exception as e:
        pass
    
    i = i + 1
    if i >= len(a)-1:
        break

print(sum)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = list(map(int,input().split()))
a.sort()

b = [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]
b = b[::-1]

c = [0]*n #使ったら1

res = 0

for i in range(len(b)-1):
    k1 = bisect.bisect_left(a,b[i+1])
    k2 = bisect.bisect_right(a,b[i])

    if k2 > k1:

        for j in range(k1,k2):
            if c[j] == 0:
                w1 = bisect.bisect_left(a,b[i]-a[j])
                w2 = bisect.bisect_right(a,b[i]-a[j])

                if w2 >w1:
                    p = w1
                    while p != w2:
                        if c[p] == 0 and j != p:
                            res += 1
                            c[p] = 1
                            p = w2-1
                        p += 1

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N-1) :
    A = sorted(A,reverse=True)
    if A[i] == -1 : continue
    x = bin(A[i])
    for j in range(i+1,N) :
        y = bin(A[j])
        z = int(x, 0) + int(y, 0)
        if bin(z).count("1") == 1 and (z != 1) :
            ans += 1
            A[j] = -1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
aA = sorted([int(_) for _ in input().split()],reverse=True)
aA1 = [ _ for _ in aA if _ % 2 ]
aA0 = [ _ for _ in aA if _ % 2 == 0 ]


def searchPair(aD):
    iL = len(aD)
    dsT =set()
    iC = 0
    for i in range(iL):
        for j in range(i+1,iL):
            if i in dsT or j in dsT:
                continue
            iWa =  aD[i] + aD[j]
            if not ( iWa & (iWa - 1)):
                dsT.add(i)
                dsT.add(j)
                iC += 1
                continue

    return iC
iC = 0
iC += searchPair(aA1)
iC += searchPair(aA0)
iC += searchPair(aA)
print(iC)

Submission status: Wrong Answer

Solution code:
import numpy as np


N=int(input())
A = list(map(int,input().split()))
 
A.sort()
 
A=A[::-1]

d = {A[0]:1}
prev=A[0]
for i in range(N):
    if A[i]!=prev:
        d[A[i]]=1
    else:
        d[A[i]]+=1
    prev = A[i]

count=0

for i in range(N):
    d[A[i]]-=1
    want=2**(int(np.log2(A[i]))+1) - A[i]
    if want in d.keys():
        if d[want]>=0:
            d[want]-=1
            count+=1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int( input())
A = list( map( int, input().split()))
V = [0]*N
ans = 0
for i in range(31,0,-1):
    D = defaultdict( lambda:[])
    T = 2**i
    for j in range(N-1,-1,-1):
        if V[j] == 1:
            continue
        if A[j] < T:
            if D[T - A[j]]:
                ans += 1
                V[D[T-A[j]].pop()]=1
                V[i] = 1
            else:
                D[A[j]].append(j)
print(ans)

Submission status: Wrong Answer

Solution code:
input()
a=sorted(map(int,input().split()))[::-1]
s={}
r=0
for v in a:
	for i in range(31)[::-1]:
		p=2**-~i-v
		if p in s and s[p]>0:r+=1;s[p]-=1;break
		else:s[v]=s.get(v,0)+1
print(r)

Submission status: Wrong Answer

Solution code:
import math
def is_power2(num):
	return num != 0 and ((num & (num - 1)) == 0)
 
 
a = input()
b = input().split()
b = [int(i) for i in b]
b.sort()
dicter = dict()
counter = 0
i = 0
while i < len(b):
	temp = b[i]
	if temp not in dicter:
		dicter[temp] = 1
		i += 1
	else:
		dicter[temp] += 1
		i += 1
		if is_power2(temp) == True and dicter[temp] == 2:
			counter += 1
			dicter[temp] = 0
		
for i in b:
	if dicter[i] > 0:
		j = 2**math.ceil(math.log2(i))-i
		if j - i in dicter and dicter[j - i] >= 1 and not (i == j - i):
			dicter[j - i] -= 1
			dicter[i] -= 1
			counter += 1
			 
	
print(counter)

Submission status: Wrong Answer

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

b = []

i = 1
max = 10**9
while True:
    t = 2**i
    if t < max:
        b.append(t)
    else:
        break
    i = i+1

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

sum = 0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        t = a[i] + a[j]
        #print(a[i],a[j],t)
        flag = False
        for k in b:
            if k >= (a[i]<<1) :
                break
            if t == k :
                sum += 1
                flag = True
                a.remove(a[j])
                break
        if flag :
            break
print(sum)

Submission status: Wrong Answer

Solution code:
from math import log2

N = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = [True for _ in range(N)]

ans = 0
for i in range(N):
    t = a[i]
    p = int(log2(t)) + 1
    pair = 2 ** p - t
    for j in range(i + 1, N):
        if a[j] == pair:
            if b[j]:
                # b[i] = False
                b[j] = False
                ans += 1
                break

print(ans)

Submission status: Wrong Answer

Solution code:
import math

num = int(input())
balls = set(map(int, input().rstrip().split(" ")))
count = 0
done = set()

length = len(balls)
for i in balls:
  if i in done:
    continue
  for j in balls:
    if j in done or i is j or i in done:
      continue
    if math.sqrt(i + j) % 1 == 0.0:
      count += 1
      done.add(i)
      done.add(j)

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
a,b=[],[]
for i in range(n):
    a.append((l[i],i))
    b.append((l[i],i))
a.sort()
b.sort(reverse=True)

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        t=a[i][0]+a[j][0]
        if a[i][1]!=a[j][1] and "1" not in bin(t)[3:]:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ret = 0 
def pair(x):
    k = 1 
    while (x - k > 0): 
        k = k*2 
    return k - x 
def search(p,i):
    for j in range(i,len(a)):
        if a[j] == p:
            return j
        elif a[j] < p:
            break
    return -1
nav = []
for i in range(len(a)):
    if nav.count(i)==0:
        res = search(pair(a[i]),i+1)
        if res != -1: 
            ret += 1
            nav.append(res)
print(ret)

Submission status: Wrong Answer

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

A.sort()
m = 2 ** 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 j in used or A[j] >= m:
            continue
        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 //= 2

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
two_list = [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]

count = 0
items = {}
for a in A_list:
    if a in items:
        items[a] += 1

    else:
        items[a] = 1
A_list.sort()
two_list.reverse()

for a in A_list:
    if items[a] >= 1:
        for t in two_list:
            m = t -a
            if m in items:
                if m == a and items[a] >= 2:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break

                elif m != a and items[m] >= 1 and items[a] >=1:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 0

while len(A)>1:
    large = A.pop(-1)
    t=1
    while (1<<t)<=large:
        t+=1
        if (1<<t)>large:
            small = (1<<t)-large
    if small in A:
        ans += 1
        A.remove(small)
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
import math

n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[]
kari=[]
ma=[]
m2=[]
n2=[]
vt=[]
vp=[]
visited=[]
ans=0
for i in range(n):
  kari=[]
  for j in range(20):
    for k in range(bisect.bisect_left(a,2**j-a[i]),bisect.bisect_right(a,2**j-a[i])):
      if(k==i):
        continue
      kari.append(k)
  ma.append(kari)
for i in range(n):
  j=n-1-i
  if j in visited:
    continue
  for k in range(len(ma[j])):
    if(ma[j][len(ma[j])-1-k] in visited):
      continue
    ans+=1
    visited.append(ma[j][len(ma[j])-1-k])
    break
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ret = 0 
def pair(x):
    k = 1 
    while (x - k > 0): 
        k = k*2 
    return k - x 
def search(p,i):
    for j in range(i,len(a)):
        if a[j] == p:
            return j
        elif a[j] < p:
            break
    return -1
nav = []
for i in range(len(a)):
    if nav.count(i)==0:
        print(pair(a[i]))
        res = search(pair(a[i]),i+1)
        if res != -1: 
            ret += 1
            nav.append(res)
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
two_list = [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]

count = 0
items = {}
for a in A_list:
    if a in items:
        items[a] += 1

    else:
        items[a] = 1
A_list.sort(reverse=True)
two_list.reverse()

for a in A_list:
    if items[a] >= 1:
        for t in two_list:
            m = t -a
            if m in items:
                if m == a and items[a] >= 2:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break

                elif m != a and items[m] >= 1 and items[a] >=1:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int( input())
A = list( map( int, input().split()))
V = [0]*N
ans = 0
for i in range(31,0,-1):
    D = defaultdict( lambda:[])
    T = 2**i
    for j in range(N):
        if V[j] == 1:
            continue
        if A[j] < T:
            if D[T - A[j]]:
                ans += 1
                V[D[T-A[j]].pop()]=1
                V[i] = 1
            else:
                D[A[j]].append(j)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

bekis = set([2**i for i in range(32)])

n = ni()
a = list(li())
acnt = Counter(a)
akeys = set(a)

ans = 0
for ai in sorted(a,reverse=True):
    for bi in bekis:
        if ai >= bi:
            if acnt[ai] > 0 and acnt[ai-bi] > 0:
                ans += 1
                acnt[ai] -= 1
                acnt[ai-bi] -= 1
                
print(ans)

Submission status: Wrong Answer

Solution code:
def search(_a, tmp):
    while _a >= 2 ** tmp:
        tmp += 1
    return tmp


def func(n, a):
    # a[i] + a[j] = 2^tとなる組の最大数
    a.sort()
    a.reverse()
    available = [True for _ in range(len(a))]
    # print(a)
    # diff = [search(a[i]) - a[i] for i in range(len(a))]
    diff = [[0, i] for i in range(len(a))]
    tmp = 0
    for i in reversed(range(len(diff))):
        tmp = search(a[i], tmp)
        diff[i][0] = 2 ** tmp - a[i]
    diff.sort()
    # a.reverse()
    diff.reverse()
    i = 0
    j = 0
    count = 0
    while i < len(a) and j < len(diff):
        while j < len(diff) and (diff[j][0] > a[i] or not available[diff[j][1]]):
            j += 1
        while i < len(a) and not available[i]:
            i += 1
        # print("i:{} j:{} count:{} avail:{}".format(i, j, count, available))
        if i < len(a) and j < len(a) and a[i] == diff[j][0]:
            if i != diff[j][1]:
                count += 1
                available[i] = False
                available[diff[j][1]] = False
                i += 1
                # if i > 0 and a[i - 1] == a[i] and i == diff[j][1]:
                # i += 1
                j += 1
            else:
                j += 1
        else:
            i += 1
    # print("   a:{}".format(a))
    # print("diff:{}".format(diff))
    return count


n = int(input())
a = [int(i) for i in input().split()]
print("{}".format(func(n, a)))
# print("{}".format(func(3, [1, 2, 3])))
# print("{}".format(func(5, [3, 11, 14, 5, 13])))
# print("{}".format(func(3, [1, 3, 29, 35])))
# print("{}".format(func(5, [1, 2, 2, 2, 2])))
# print("{}".format(func(6, [1, 2**50-1])))
# print("{}".format(func(7, [1, 7, 7, 25, 63, 127, 127])))
# print("{}".format(func(4, [1, 1, 2, 3])))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        t=a[i]+a[j]
        if "1" not in bin(t)[3:]:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import itertools

num = int(input())
balls = list(itertools.combinations(map(int, input().rstrip().split(" ")), 2))
count = 0
pairs = []

for a, b in balls:
  if a in pairs or b in pairs:
    continue
  elif math.sqrt(a+b) % 1 == 0.0:
    count += 1
    pairs.append(a)
    pairs.append(b)

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

M = int(input())
X = np.sort(list(map(int, input().split())))
S = []
C = {}
b = -1
c = -1
O = {}
for i, x in enumerate(X):
  if x != b:
    S.append(x)
    C[x] = 0
    O[x] = i
  elif x == b and x != c:
    S.append(x)
    c = x
  b = x
  C[x] += 1
  
N = len(S)

pair = {}
for x in [2**i for i in range(32)][1:]:
  for i in range(N):
    a = S[i]
    if a >= x:
      break
    if x-a in C:
      b = x-a
      for p in range(C[a]):
        if O[a]+p not in pair:
          pair[O[a]+p] = []
        for q in range(C[b]):
          if (O[a]+p < O[b]+q):
            pair[O[a]+p].append(O[b]+q)

match = -1 * np.ones(M, dtype=int)
used = np.zeros(M)

def dfs(v):
  used[v] = True
  if v in pair:
    for u in pair[v]:
      w = match[u]
      if w < 0:
        match[v] = u
        match[u] = v
        return True
      if used[w] == 0 and dfs(w):
        match[v] = u
        match[u] = v
        return True
  return False

res = 0
for v in range(M):
  if (match[v] < 0):
    used = np.zeros(M)
    if (dfs(v)):
      res += 1
print(res)

Submission status: Wrong Answer

Solution code:
_ = input()
s = input()
data = list(map(int, s.split()))
data.sort()
max_num = data[-1] + data[-2]
even = []
odd = []
for it in data:
    if it%2 == 0:
        even.append(it)
    else:
        odd.append(it)

# src is sorted
def get_pair(src, target):
    pair = []
    pair_id = []
    for i, first in enumerate(src):
        if first > target:
            break
        for j, second in enumerate(src[i+1:]):
            if first + second == target:
                pair.append([first, second])
                pair_id.append([i,j+i+1])
            elif first + second > target:
                break

#     print('pair,',pair)
#     print('pair_id',pair_id)
    return pair, pair_id

two = []
tmp = 1
while True:
    tmp *= 2
    if tmp > max_num:
        break
    two.append(tmp)

# for odd
all_pair =[]
all_pair_id = []
if len(odd) > 1:
    for target in two:
        pair, pair_id = get_pair(odd, target)
        all_pair += pair
        all_pair_id += pair_id
        
# make list
p_list = [[] for it in range(len(odd))]
for it in all_pair_id:
    p_list[it[0]].append(it[1])
    p_list[it[1]].append(it[0])

cnt = 0
while(True):
    END = True
    for i, it in enumerate(p_list):
        if len(it) == 1:
            p_list[it[0]] = []
            p_list[i] = []
            END = False
            cnt += 1
            break
    if END:
        break

# for even
all_pair =[]
all_pair_id = []
if len(even) > 1:
    for target in two:
        pair, pair_id = get_pair(even, target)
        all_pair += pair
        all_pair_id += pair_id
        
# make list
p_list = [[] for it in range(len(even))]
for it in all_pair_id:
    p_list[it[0]].append(it[1])
    p_list[it[1]].append(it[0])

while(True):
    END = True
    for i, it in enumerate(p_list):
        if len(it) == 1:
            p_list[it[0]] = []
            p_list[i] = []
            END = False
            cnt += 1
            break
    if END:
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ret = 0 
def pair(x):
    k = 1 
    while (x - k > 0): 
        k = k*2 
    return k - x 
def search(p,i):
    for j in range(i,len(a)):
        if a[j] == p:
            return i
        elif a[j] < p:
            break
    return -1
nav = []
for i in range(len(a)):
    if nav.count(i)==0:
        res = search(pair(a[i]),i+1)
        if res != -1: 
            ret += 1
            nav.append(res)
print(ret)

Submission status: Wrong Answer

Solution code:
def two_power(m):
  if m < 2:
    return 0
  else:
    return two_power(m//2) + 1
  
def nibun(x, *args):
  l = len(args)
  if l == 0:
    return -float('inf')
  else:
    u = l // 2
    v = args[l // 2]
  for i in range(n):
    if v != -1:
      if v == x:
        return l // 2
      elif v < x:
        b = args[:l //2]
        return nibun(x, *b)
      else:
        b = args[l // 2+1:]
        return u + 1 + nibun(x, *b)
    else:
      u += 1
      u %= l
      v = args[u]
  return -1
  
n = int(input())
a = list(map(int, input().split()))

a.sort()
a.reverse()
c = 0
skip = []
for i in range(len(a)):
  if a[i] == -1:
    continue
  m = two_power(a[i])
  x = 2 ** (m+1) - a[i]
  b = a[i+1:]
  index = nibun(x, *b)
  if index >= 0:
    c += 1
    a[i+1+index] = -1
    a.pop(i + 1 + index)
    a.append(-1)

print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
num = 1
minus = 0
rep = 0
plus = False
for i in range(1, n):
	if a[i] > a[i-1]:
		rep = 0
		plus = True
	elif a[i] < a[i-1]:
		rep = 0
		plus = False
		minus += 1
		if minus>num:
			num += 1
	else:
		rep += 1
		if plus == True:
			if rep >= num:
				num += 1
		else:
			if rep -1 >= num:
				num += 1
print(num)

Submission status: Wrong Answer

Solution code:
N, = [int(i) for i in input().split(' ')]
As = [int(i) for i in input().split(' ')]

M = pow(2, 30)

def mm(m):
    x = 1
    while True:
        if m<=x:
            return (M-x) + m, (M-x)+(x-m)
        x *= 2

nAs = sorted([mm(a)[0] for a in As])
mAs = sorted([mm(a)[1] for a in As])[::-1]

ma = mAs.pop()
c = 0
for na in nAs:
    if ma == None:
        break
    while True:
        if ma == na:
            c+=1
            if len(mAs) == 0:
                ma = None
                break
            ma = mAs.pop()
            break
        elif ma < na:
            if len(mAs) == 0:
                ma = None
                break
            ma = mAs.pop()
            continue
        break
print(c)

Submission status: Wrong Answer

Solution code:
aaa = [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, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888]

a = int(input())

b = list(map(int,input().split()))
ma = 0
ppp = 0
lllll = 0
su = 0
k = [[] for i in range(a)]
kk =[0 for i in range(a)]
for i in range(a-1 - lllll):
	for j in range(1,a-i - lllll):
		for l in range(39):
			if b[i] + b[i+j] == aaa[l]:
				if ma <= b[i+j]:
					ma = b[i+j]
					ppp = i+j
	if ppp != 0:
		su += 1
		b.pop(ppp)
		lllll += 1
		ppp = 0
	ma = 0

print(su)

Submission status: Wrong Answer

Solution code:
N = int(input())
aList = list(map(int, input().split()))
aLL = len(aList)

def check_pt(x):
    bin_v = str(bin(x))
    c = bin_v[3:]
    return len(c) == c.count('0')

ans = 0

for i in range(aLL):
    for j in range(aLL):
        if i != j:
            s = aList[i] + aList[j]
            if check_pt(s):
                ans = ans + 1
            else:
                ans = ans


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

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

from collections import Counter

n = ni()
a = list(li())

one_pos = [Counter() for _ in range(32)]

ans = 0

for ai in a:
    one = bin(ai)[::-1].index('1')
    ai = ai>>(one+1)
    one_pos[one][ai] += 1

for cnt in one_pos:

    for key in sorted(cnt.keys(),reverse=True):
        val = cnt[key]
        krv = int_reverse(key)
        vlr = cnt[krv]
        if val and vlr:
            plus = min(val,vlr)
            ans += plus
            cnt[key] -= plus
            cnt[krv] -= plus

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ret = 0 
def pair(x):
    k = 1 
    while (x - k > 0): 
        k = k*2 
    return k - x 
def search(p,i):
    for j in range(i,len(a)):
        if a[j] == p:
            return i
        elif a[j] < p:
            break
    return -1
nav = []
for i in range(len(a)):
    if nav.count(i)==0:
        res = search(a[i],i+1)
        if res != -1: 
            ret += 1
            nav.append(res)
print(ret)

Submission status: Wrong Answer

Solution code:
import math

def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(arr)
    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right

def main():
  kosu=int(input())
  kazulist=input().split(' ')
  for kzls in range(len(kazulist)):
    kazulist[kzls]=int(kazulist[kzls])
  #print(kazulist)
  nl=quick_sort(kazulist)
  #print(nl)
  max2nd=math.ceil(math.log(nl[-1], 2))
  
  nowpos=0
  mokuhyo=2
  count=0
  
  octlist=[]
  
  xxx=0
  smalllist=[]
  while nl[xxx]<128:
    smalllist.append(nl[xxx])
    xxx+=1
    if xxx>=kosu:
      break
  #print(smalllist)
  
  for sl_1 in range(len(smalllist)):
    for sl_2 in range(len(smalllist) - sl_1 - 1):
      aaaaa=math.sqrt(smalllist[sl_1]+smalllist[sl_1+sl_2+1])
      if aaaaa==int(aaaaa):
        count+=1
  
  for i in range(256):
    octlist.append([])
  #print(octlist)
  for x_n in range(len(nl)):
    amari=nl[x_n]%256
    octlist[amari].append(nl[x_n])
    if amari==0:
      if len(octlist[0])>0:
        for ol_n in octlist[0]:
          aaaaa=math.sqrt(nl[x_n]+ol_n)
          if aaaaa==math.ceil(aaaaa):
            count+=1
    else:
      if len(octlist[256-amari])>0:
        for ol_n in octlist[256-amari]:
          aaaaa=math.sqrt(nl[x_n]+ol_n)
          if aaaaa==math.ceil(aaaaa):
            count+=1
  print(count)
  
  
  

main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(0,n):
    for j in range(0,n):
        if i < j:
            p = a[i]+a[j]
            q = math.log2(p)
            if q.is_integer():
                b.append(p)
c = set(b)
print(len(c))

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
count=0
skip=[]
for i in range(len(A)-1):
    if i in skip:
            continue
    for j in range(i+1,len(A)):
        if j in skip:
            continue
        else:
            A_num = A[i]+A[j]
            A_num = format(A_num, 'b')
            if sum(list(map(int,str(A_num)))) ==1:
                skip.append(int(i))
                skip.append(int(j))
                count+=1
                continue
print(count)