qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def mi(): return map(int, input().split())


def li(): return list(mi())


def li_(): return [int(x) - 1 for x in input().split()]


def lin(n: int): return [input() for _ in range(n)]


def llin(n: int): return [li() for _ in range(n)]


def llin_(n: int): return [li_() for _ in range(n)]


def lli(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def f(): return float(input())


def s(): return input().replace('\n', '')


def main():
    N, K = mi()
    h = li()
    dp = [0] * N
    dp[1] = abs(h[0]-h[1])
    for i in range(2, N):
        dp[i] = min((dp[i-j]+abs(h[i-j]-h[i])
                     for j in range(1, min(K+1, i+1))))
    print(dp)
    print(dp[N-1])


if __name__ == '__main__':
    main()


# Fixed code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def mi(): return map(int, input().split())


def li(): return list(mi())


def li_(): return [int(x) - 1 for x in input().split()]


def lin(n: int): return [input() for _ in range(n)]


def llin(n: int): return [li() for _ in range(n)]


def llin_(n: int): return [li_() for _ in range(n)]


def lli(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def f(): return float(input())


def s(): return input().replace('\n', '')


def main():
    N, K = mi()
    h = li()
    dp = [0] * N
    dp[1] = abs(h[0]-h[1])
    for i in range(2, N):
        dp[i] = min((dp[i-j]+abs(h[i-j]-h[i])
                     for j in range(1, min(K+1, i+1))))
    print(dp[N-1])


if __name__ == '__main__':
    main()
# Buggy code:
import sys
# import pdb
input = sys.stdin.readline

N, K = map(int, input().split())
hs = list(map(int, input().split()))

inf = 1e10

dp_list = [inf for _ in range(N)]
dp_list[0] = 0

# import heapq

sys.setrecursionlimit(1000000)
def dp_memo(p):
  if dp_list[p] != -1:
    return dp_list[p]

  costs = []
  # heapq.heapify(costs)
  if K <= p:
    for i in range(1,K+1):
        # heapq.heappush(costs, dp_memo(p-i) + abs(hs[p] - hs[p-i]))
        costs.append(dp_memo(p-i) + abs(hs[p] - hs[p-i]))
  else:
    for i in range(1,p+1):
        # heapq.heappush(costs, dp_memo(p-i) + abs(hs[p] - hs[p-i]))
        costs.append(dp_memo(p-i) + abs(hs[p] - hs[p-i]))
  result = min(costs)
  # result = heapq.heappop(costs)
  dp_list[p] = result
  return result


def dp_recur(N):
  for i in range(1, N):
    for j in range(1,K+1):
      if i-j < 0:
        break
      dp_list[i] = min(dp_list[i], dp_list[i-j] + abs(hs[i] - hs[i-j]))
  return dp_list[N-1]

# Fixed code:
import sys
# import pdb
input = sys.stdin.readline

N, K = map(int, input().split())
hs = list(map(int, input().split()))

inf = 1e10

dp_list = [inf for _ in range(N)]
dp_list[0] = 0

# import heapq

sys.setrecursionlimit(1000000)
def dp_memo(p):
  if dp_list[p] != -1:
    return dp_list[p]

  costs = []
  # heapq.heapify(costs)
  if K <= p:
    for i in range(1,K+1):
        # heapq.heappush(costs, dp_memo(p-i) + abs(hs[p] - hs[p-i]))
        costs.append(dp_memo(p-i) + abs(hs[p] - hs[p-i]))
  else:
    for i in range(1,p+1):
        # heapq.heappush(costs, dp_memo(p-i) + abs(hs[p] - hs[p-i]))
        costs.append(dp_memo(p-i) + abs(hs[p] - hs[p-i]))
  result = min(costs)
  # result = heapq.heappop(costs)
  dp_list[p] = result
  return result


def dp_recur(N):
  for i in range(1, N):
    for j in range(1,K+1):
      if i-j < 0:
        break
      dp_list[i] = min(dp_list[i], dp_list[i-j] + abs(hs[i] - hs[i-j]))
  return dp_list[N-1]

print(dp_recur(N))
# print(dp_memo(N-1))
# Buggy code:
n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[10**9]*n
c[1]=abs(l[0]-l[1])
for i in range(2,n):
    c[i]=min( c[i-j]+abs(l[i]-l[i-j]) for j in range(1,h+1) if i-j > -1 )
print(c[-1])

# Fixed code:
n,h=map(int,input().split())
l=list(map(int,input().split()))
c=[10**9]*n
c[0]=0
c[1]=abs(l[0]-l[1])
for i in range(2,n):
    c[i]=min( c[j]+abs(l[i]-l[j]) for j in range(max(0,i-h),i) )
print(c[-1])
# Buggy code:
n,k= map(int, input().split())
h= list(map(int, input().split()))
dp=[2000000000]*n
dp[0]=0
for i in range(1,k+1):
    for j in range(0,i):
        dp[i]=min(abs(h[i]-h[0])+dp[j],dp[i])
for i in range(k+1,n):
    for j in range(1,k+1):
        dp[i]=min(abs(h[i]-h[i-j])+dp[i-j],dp[i])
#print(dp)
print(dp[n-1])

# Fixed code:
n,k= map(int, input().split())
h= list(map(int, input().split()))
dp=[2000000000]*n
dp[0]=0
for i in range(1,min(n,k+1)):
    for j in range(0,i):
        dp[i]=min(abs(h[i]-h[0])+dp[j],dp[i])
if n>k:
    for i in range(k+1,n):
        for j in range(1,k+1):
            dp[i]=min(abs(h[i]-h[i-j])+dp[i-j],dp[i])
#print(dp)
print(dp[n-1])
# Buggy code:
N,K = map(int,input().split())
h = list(map(int,input().split()))
 
def main(N,K,H):
    dp = [0]*N
    for i in range(1,N):
        L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
        dp[i] = min(L)
    print(dp[-1])
main(N,K,H)

# Fixed code:
N,K = map(int,input().split())
H = [int(x) for x in input().split()]
 
def main(N,K,H):
    dp = [0]*N
    for i in range(1,N):
        L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
        dp[i] = min(L)
    print(dp[-1])
main(N,K,H)
# Buggy code:
n,k=map(int,input().split())
h=list(map(int,input().split()))
h+=[0]*k
inf=100000
dp=[inf]*(n+k)
dp[0]=0
for i in range(n):
    for j in range(1,k+1):
        dp[i+j]=min(dp[i]+abs(h[i]-h[i+j]),dp[i+j])
        print(dp)
print(dp)


# Fixed code:
n,k=map(int,input().split())
h=list(map(int,input().split()))
h+=[0]*k
inf=10**9
dp=[inf]*(n+k)
dp[0]=0
for i in range(n):
    for j in range(1,k+1):
        dp[i+j]=min(dp[i]+abs(h[i]-h[i+j]),dp[i+j])
print(dp[n-1])
# Buggy code:
import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))
dp = [0]*(n)
dp[0] = 0
for i in range(n):
  for j in range(i+1,k+i+1):
    if j<n:
      dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))

print(dp[n-1])

 

# Fixed code:
import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))
dp = [sys.maxsize]*(n)
dp[0] = 0
for i in range(n):
  for j in range(i+1,k+i+1):
    if j<n:
      dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))

print(dp[n-1])
# Buggy code:
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [100000 for i in range(n)]
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        if i+j<n:
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
    print(dp)
print(dp[n-1])

# Fixed code:
n,k = map(int,input().split())
h = list(map(int,input().split()))

dp = [1000000000 for i in range(n)]
dp[0] = 0

for i in range(n):
    for j in range(k+1):
        if i+j<n:
            dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j])
print(dp[n-1])
# Buggy code:
import sys
sys.setrecursionlimit(10**6)
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))
dp = np.zeros(N,dtype=int)
for i in range(1, N):
    s=max(0, i-k)
    dp[i] = min(dp[s:i]+abs(h[s:i]-h[i])
print(dp[-1])

# Fixed code:
import sys
sys.setrecursionlimit(10**6)
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))
dp = np.zeros(N,dtype=int)
for i in range(1, N):
    s=max(0, i-K)
    dp[i] = min(dp[s:i]+abs(h[s:i]-h[i]))
print(dp[-1])
# Buggy code:
N, K = map(int, raw_input().split())

h = list(map(int, raw_input().split()))
dp = [10 ** 9 + 1] * N
dp[0] = 0
for i in range(N):
    for j in range(i + 1, i + K + 1):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
        else:
            break
print(dp[N - 1])

# Fixed code:
N, K = map(int, input().split())

h = list(map(int, input().split()))
dp = [10 ** 9 + 1] * N
dp[0] = 0
for i in range(N):
    for j in range(i + 1, i + K + 1):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
        else:
            break
print(dp[N - 1])
# Buggy code:
n,k=map(int,input().split())
# k=int(input())
h=list(map(int,input().split()))

dp=[1000001 for i in range(n+1)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(1,n+1):
    for j in range(1,k+1):
        if(i+j<n):
            dp[i+j]=min(dp[i]+abs(h[i+j]-h[i]),dp[i+j])
print(dp[n-1])


# Fixed code:
n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[10000000000 for i in range(n+1)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(n+1):
    for j in range(i+1,i+k+1):
        if(j<n):
            dp[j]=min(dp[i]+abs(h[j]-h[i]),dp[j])

print(dp[n-1])
# Buggy code:
import numpy as np  

n, k = map(int, input().split())
h = np.array([int(i) for i in input().split()])

dp = np.zeros(n+1)

for i in range(1, n):
    j = max(0, i-k)
    dp[i] = np.min(dp[j:i] + abs(h[i] - h[j:i]))

print(dp[-1])



# Fixed code:
import numpy as np  

n, k = map(int, input().split())
h = np.array([int(i) for i in input().split()])

dp = np.array([0] * n)

for i in range(1, n):
    j = max(i-k, 0)
    dp[i] = np.min(np.abs(h[i] - h[j:i]) + dp[j:i])

print(dp[-1])
# Buggy 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)        

# Fixed 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)):
    if d[a[i]] == 0:continue
        
    d[a[i]] -= 1
    
    y = 2**a[i].bit_length() - a[i]
    
    if y in d and d[y] > 0:
        count += 1
        d[y]  -= 1
        
print(count)
# Buggy code:
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

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

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

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

    print(ans)


if __name__ == '__main__':
    main()


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

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

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

    print(ans)


if __name__ == '__main__':
    main()
# Buggy code:
from collections import Counter

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

# Fixed code:
from collections import Counter

N = int(input())
*A, = map(int, input().split())
cnt = Counter(A)
A = sorted(A, reverse=True)
ans = 0
for a in A:
    if a & (a - 1) != 0:
        cand = (1 << ((a - 1).bit_length())) - a
        if cnt[a] == 0 or cnt[cand] == 0: continue
    else:
        cand = a
        if cnt[a] < 2: continue
    ans += 1
    cnt[a] -= 1; cnt[cand] -= 1
print(ans)
# Buggy code:
from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
t = 1
valids = []
while t < 2 * 10 ** 9:
  t *= 2
  valids.append(t)
result = 0
while True:
  prev = result
  keys = list(d.keys())
  keys.sort(reverse = True)
  for x in keys:
    t = valids[bisect_right(valids, 13)] - x
    if t not in d:
      continue
    result += 1
    if d[x] == 1:
      del d[x]
    else:
      d[x] -= 1
    if d[t] == 1:
      del d[t]
    else:
      d[t] -= 1
    break
  if prev == result:
    break
print(result)

# Fixed code:
from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
t = 1
valids = []
while t < 2 * 10 ** 9:
  t *= 2
  valids.append(t)
result = 0
while True:
  prev = result
  keys = list(d.keys())
  keys.sort(reverse = True)
  for x in keys:
    if x not in d:
      continue
    t = valids[bisect_right(valids, x)] - x
    while True:
      if t not in d:
        break
      if x == t and d[x] == 1:
        break
      result += 1
      if d[x] == 1:
        del d[x]
      else:
        d[x] -= 1
      if d[t] == 1:
        del d[t]
      else:
        d[t] -= 1
      if x not in d:
        break
  if prev == result:
    break
print(result)
# Buggy code:
from collections import Counter
size_a = int(input())
a = Counter(int(x) for x in input().split())
keys = list(a.keys())
keys.sort()
pair_cnt = 0
print(a)
while size_a >= 2:
    x = keys[-1]
    if a[x] == 0:
        keys.pop()
        continue
    print('search', x, a[x])
    a[x] -= 1
    size_a -= 1
    if a[x] == 0:
        keys.pop()
    b = 2 ** x.bit_length() - x
    if a[b] > 0:
        a[b] -= 1
        size_a -= 1
        if a[b] == 0:
            del a[b]
        pair_cnt += 1
        print('found')
print(pair_cnt)

# Fixed code:
from collections import Counter
size_a = int(input())
a = Counter(int(x) for x in input().split())
keys = list(a.keys())
keys.sort()
pair_cnt = 0
while size_a >= 2:
    x = keys[-1]
    if a[x] == 0:
        keys.pop()
        continue
    a[x] -= 1
    size_a -= 1
    if a[x] == 0:
        keys.pop()
    b = 2 ** x.bit_length() - x
    if a[b] > 0:
        a[b] -= 1
        size_a -= 1
        if a[b] == 0:
            del a[b]
        pair_cnt += 1
print(pair_cnt)
# Buggy 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)


# Fixed 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)
# Buggy code:
from collections import Counter
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    A.sort(reverse=True)
    C = Counter(A)
    for a in A:
        if C[a] == 0: continue
        p = (1 << a.bit_length()) - a
        if p > a: continue
        if p in C and C[p] > 0:
            ans += 1
            C[p] -= 1
    print(ans)

if __name__ == '__main__':
    main()

# Fixed code:
from collections import Counter
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    A.sort(reverse=True)
    C = Counter(A)
    for a in A:
        if C[a] == 0: continue
        C[a] -= 1
        p = (1 << a.bit_length()) - a
        if p in C and C[p] > 0:
            ans += 1
            C[p] -= 1
    print(ans)

if __name__ == '__main__':
    main()
# Buggy code:
from collections import defaultdict

N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
dic = defaultdict(int)
for a in A:
    dic[a] = 1

ans = 0
for i in range(N):
    if dic[A[i]] != 0:
        b = 2**(A[i].bit_length()) - A[i]
        if dic[b]:
            ans += 1
            dic[A[i]], dic[b] = 0, 0

print(ans)

# Fixed code:
from collections import defaultdict

N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
dic = defaultdict(int)
for a in A:
    dic[a] += 1

ans = 0
for a in A:
    if dic[a] != 0:
        b = 2**(a.bit_length()) - a
        if dic[b] != 0:
            if b == a and dic[b] == 1:
                continue
            ans += 1
            dic[a] -= 1
            dic[b] -= 1

print(ans)
# Buggy code:
from collections import Counter

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

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

ans = 0
flag = False
for i in range(n):
    if c[A[i]] == 0:
        continue

    pow_2 = 2 ** len(format(A[i], "b"))
    if pow_2 - A[i] != A[i]:
        c[pow_2 - A[i]] -= 1
        ans += 1
    elif c[pow_2 - A[i]] > 1 and pow_2 - A[i] == A[i]:
        if flag is True:
            c[A[i]] -= 2
            ans += 1
            flag = False
        else:
            flag = True

print(ans)

# Fixed code:
from collections import Counter

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

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

ans = 0
flag = False
for i in range(n):
    if c[A[i]] == 0:
        continue

    pow_2 = 2 ** len(format(A[i], "b"))
    if c[pow_2 - A[i]] > 0 and pow_2 - A[i] != A[i]:
        c[pow_2 - A[i]] -= 1
        c[A[i]] -= 1
        ans += 1
    elif c[pow_2 - A[i]] > 1 and pow_2 - A[i] == A[i]:
        if flag is True:
            c[A[i]] -= 2
            ans += 1
            flag = False
        else:
            flag = True

print(ans)
# Buggy code:
from collections import defaultdict

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

a.sort()
memo = defaultdict(int)
for i in range(n):
    memo[a[i]] += 1

count = 0
for i in reversed(range(n)):
    if memo[a[i]] == 0:
        continue
    if memo[1 << (len(bin(a[i])) - 2) - a[i]] == 0:
        continue
    memo[a[i]] -= 1
    memo[1 << (len(bin(a[i])) - 2) - a[i]] -= 1
    count += 1

print(count)

# Fixed code:
from collections import defaultdict

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

a.sort()
memo = defaultdict(int)
for i in range(n):
    memo[a[i]] += 1

count = 0
for i in reversed(range(n)):
    if memo[a[i]] == 0:
        continue
    if (memo[(1 << (len(bin(a[i])) - 2)) - a[i]] > 0 and (1 << (len(bin(a[i])) - 2)) - a[i] != a[i]) or memo[(1 << (len(bin(a[i])) - 2)) - a[i]] > 1:
        memo[a[i]] -= 1
        memo[(1 << (len(bin(a[i])) - 2)) - a[i]] -= 1
        count += 1

print(count)
# Buggy code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
print(dic)
ans = 0

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


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

for a in A:
    small = (1<<(len(format(a,"b")))) - a
    if small == a:
        if dic[a] >= 2:
            dic[a] -= 2
            ans += 1
        continue
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a] -= 1
        dic[small] -= 1
        ans += 1
print(ans)
# Buggy code:
from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(d.keys(), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  if t not in d:
    continue
  if d[a] != d[t]:
    i = min(d[a], d[t])
  else:
    i = d[a] // 2
  result += i
  d[a] -= i
  d[t] -= 1
print(result)


# Fixed code:
from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(d.keys(), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if a not in d or d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  while True:
    if t not in d or d[t] == 0:
      break
    if a == t and d[a] == 1:
      break
    i = 1
    if a != t:
      i = min(d[a], d[t])
    result += i
    d[a] -= i
    d[t] -= i
    if a not in d or d[a] == 0:
      break
print(result)
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

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

ans=0
for num in sorted(d,reverse=True):
    while d[num]>=1:
        d[num]-=1

        now=1
        while now<=num:
            now*=2

        cand = now - num
        print(num,cand)

        if d[cand]>=1:
            d[cand]-=1
            ans+=1
        else:
            break
print(ans)

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

from collections import defaultdict
d = defaultdict(int)

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

ans=0
for num in sorted(d,reverse=True):
    while d[num]>=1:
        d[num]-=1

        now=1
        while now<=num:
            now*=2

        cand = now - num
        if d[cand]>=1:
            d[cand]-=1
            ans+=1
        else:
            break
print(ans)
# Buggy code:
from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(d.keys(), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if a not in d or d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  if t not in d or d[t] == 0:
    continue
  if a != t:
    i = min(d[a], d[t])
  else:
    i = d[a] // 2
  if i == 0:
    continue
  result += i
  d[a] -= i
  d[t] -= i
  if a not in d or d[a] == 0:
    break
print(result)


# Fixed code:
from bisect import bisect_right
n = int(input())
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(d.keys(), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if a not in d or d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  while True:
    if t not in d or d[t] == 0:
      break
    if a == t and d[a] == 1:
      break
    result += 1
    d[a] -= 1
    d[t] -= 1
    if a not in d or d[a] == 0:
      break
print(result)
# Buggy code:
from collections import Counter
N,*A = map(int, open(0).read().split())
Cnt = Counter(A)
m = 2**31
ans = 0
for i in range(31,0,-1):
  for k in Cnt.keys():
    if Cnt[k]==0:
      continue
    if Cnt[m-k]>0:
      Cnt[k] -= 1
      Cnt[m-k] -= 1
      ans += 1
  m >>= 1
print(ans)

# Fixed code:
from collections import Counter
N,*A = map(int, open(0).read().split())
Cnt = Counter(A)
m = 2**31
ans = 0
for i in range(31):
  for k in Cnt.keys():
    if Cnt[k]==0:
      continue
    if k==m-k:
      ans += Cnt[k]//2
      Cnt[k] %= 2
    else:
      if Cnt[m-k]==0:
        continue
      if Cnt[k]<Cnt[m-k]:
        ans += Cnt[k]
        Cnt[m-k] -= Cnt[k]
        Cnt[k] = 0
      else:
        ans += Cnt[m-k]
        Cnt[k] -= Cnt[m-k]
        Cnt[m-k] = 0
  m >>= 1
print(ans)