Harryxun/stf_run huggingface dataset:
import sys
import numpy as np
input = sys.stdin.readline

N, Q = map(int, input().split())
children = [[i] for i in range(N)]  # 各頂点の持つ部分木の頂点の集合
edges = [tuple(map(int, input().split())) for _ in range(N-1)][::-1]
counts = np.zeros(N, dtype=np.int32)

for a, b in edges:
    children[a-1] += children[b-1]

for _ in range(Q):
    p, x = map(int, input().split())
    counts[children[p-1]] += x

for count in counts:
    print(count, end=' ')

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    # edges = [None]*N
    edges = [[] for _ in range(N)]
    # edges[0] = 0
    # edges[0].append = 0
    for _ in range(N-1):
        a, b = map(int, input().split())
        edges[b-1].append(a-1)
        edges[a-1].append(b-1)

    counts = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        counts[p-1] += x

    parent_nodes = deque()
    parent_nodes.append(0)
    visited_nodes = set()
    while parent_nodes:
        parent = parent_nodes.popleft()
        if parent in visited_nodes:
            continue
        visited_nodes.add(parent)
        for child in edges[parent]:
            if child in visited_nodes:
                continue
            counts[child] += counts[parent]
            parent_nodes.append(child)

    print(' '.join(list(map(str, counts))))

if __name__ == "__main__":
    main()
a, b, c, d=map(int,input().split)
k1=abs(a-b)
k2=abs(a-c)
k3=abs(b-c)
if k2<=d:
  print("Yes")
elif k1<=d or k3<=d:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a, b, c, d=map(int,input().split())
k1=abs(a-b)
k2=abs(a-c)
k3=abs(b-c)
if k2<=d:
  print("Yes")
elif k1<=d and k3<=d:
  print("Yes")
else:
  print("No")
i = 1
while True:
     x = int(input())
     if x == 0 break:
         print('Case {} : {}'.format(i, x))
     i += 1

### FIXED CODE ###

i = 1
while True:
     x = int(input())
     if x == 0: break
     print('Case {}: {}'.format(i, x))
     i += 1
def binary_search(list, item):
    low = 0
    lengyh = len(list)
    if list[lengyh - 1] < item:
        return lengyh - 1
    high = lengyh - 1

    while low <= high:
        mid = (low + high) // 2
        guess = list[mid]

        if guess == item - 1 or (mid < lengyh - 1 and (guess < item and list[mid + 1] > item)) or (mid == lengyh - 1 and guess < item):
            return mid
        if guess > item:
            high = mid - 1
        else:
            low = mid + 1

    return None


N = int(input())
str_l = input()
num = 0
L = []
for v in str_l.split(' '):
    L.append(int(v))

L.sort()
for i in range(N):
    a = L[i]
    for j in range(i, N - 1):
        b = L[j + 1]
        index = binary_search(L[j + 2:], a + b)
        if index is None:
            continue
        else:
            for k in range(0, index + 1):
                c = (L[j + 2:])[k]
                if b + c > a and a + c > b:
                    num += 1

print(num)

### FIXED CODE ###

import bisect


N = int(input())
str_l = input()
num = 0
L = []
for v in str_l.split(' '):
    L.append(int(v))

L.sort()
for i in range(N - 1):
    a = L[i]
    for j in range(i, N - 2):
        b = L[j + 1]
        index = bisect.bisect_left(L[j + 2:], a + b)
        num += index
        # for k in range(0, index):
        #     c = (L[j + 2:])[k]
        #     if b + c > a and a + c > b:
        #         num += 1

print(num)
import bisect
N,M=map(int,input().split())

X=max(N,M)
Y=min(N,M)
while X%Y!=0:
    X,Y=Y,X%Y

lcm=(N*M)//Y

#print(lcm)

s=[i*lcm//N for i in range(N)]
t=[i*lcm//M for i in range(M)]
t.append(10000000)
S=input()
T=input()

for i in range(len(s)):
    if t[bisect.bisect_left(t,s[i])]==s[i]:
        if T[bisect.bisect_left(t,s[i])]==S[i]:
            pass
        else:
            print(-1)
            exit()
print(lcm)


### FIXED CODE ###

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)

def lcm(x, y):
    return x*y // gcd(x, y)


N_len_S, M_len_T = map(int, input().split())
S = input()
T = input()
g = gcd(N_len_S, M_len_T)
l = lcm(N_len_S, M_len_T)

ans = l
for k in range(g):
    # S[i]. T[j] : 文字列 X を構成したとき重なる文字。これらが等しければよい数字。
    i = N_len_S // g * k
    j = M_len_T // g * k
    if S[i] != T[j]:
        ans = -1
        break
print(ans)
# 半分全列挙バージョン
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,ma,mb=MI()
    abc=[LI() for _ in range(n)]
    inf=10**9
    # 前半の要素をa1,b1、後半の要素をa2,b2とする
    # (a1+a2):(b1+b2)=ma:mbとなればよい。式変形すると
    # (mb*a1-ma*b1)+(mb*a2-ma*b2)=0となる
    # つまり各要素についてmb*a-ma*bという指標を計算し、前半と後半で和が0になる組合せを探せばよい
    # 前半全列挙
    pre=[(0,0,0)]
    for a,b,c in abc[:n//2]:
        pn=len(pre)
        for i in range(pn):
            pa,pb,pc=abc[i]
            pre.append((a+pa,b+pb,c+pc))
    pre=[(a*mb-b*ma,c) for a,b,c in pre]
    # 後半全列挙
    pos=[(0,0,0)]
    for a,b,c in abc[n//2:]:
        pn=len(pos)
        for i in range(pn):
            pa,pb,pc=abc[i]
            pos.append((a+pa,b+pb,c+pc))
    pos=[(a*mb-b*ma,c) for a,b,c in pos]
    # 指標が昇順になるよう並び替えて、前半は前から後半は後からしゃくとり法で
    # 指標の和が0になるところのコストを求める
    pre.sort()
    pos.sort()
    j=len(pos)-1
    ans=inf
    for val,c in pre:
        while val+pos[j][0]>0 and j>0:j-=1
        while val+pos[j][0]==0 and j>=0:
            now=c+pos[j][1]
            if now and now<ans:ans=now
            j-=1
        if j<0:break
    if ans==inf:print(-1)
    else:print(ans)

main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,ma,mb=MI()
    inf=10**9
    abc=[LI() for _ in range(n)]
    dp=[[[inf]*(n*10+1) for _ in range(10*n+1)] for _ in range(n+1)]
    dp[0][0][0]=0
    for i,(a,b,c) in enumerate(abc):
        for j in range(n*10+1):
            for k in range(n*10+1):
                pre=dp[i][j][k]
                if pre==inf:continue
                dp[i+1][j][k]=min(dp[i+1][j][k],pre)
                dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],pre+c)
    ans=inf
    for i in range(1,105):
        a=i*ma
        b=i*mb
        if a>n*10 or b>n*10:break
        ans=min(ans,dp[n][a][b])
    if ans==inf:print(-1)
    else:print(ans)

main()
# ITP1_2_A

num = input()
a,b = num.split()
a = int(a)
b = int(b)

if a < b :
    print('a < b')
elif a > b :
    print('a > b')
else:
    print('a == b')



### FIXED CODE ###

a,b = map(int, input().split())

if a < b :
    print("a < b")
elif a > b :
    print("a > b")
else:
    print("a == b")
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.reverse()
B.reverse()

t = 0
cnt = 0
c1, c2 = A.pop(), B.pop()
while True:
    
    if t >= K or (t + c1 > K and t + c2 > K):
        break


    if (t + c1 <= K and t + c2 <= K):
        l1 = [c1]
        sum_1 = c1
        for a in A[-1]:
            if t + a <= K:
                l1.append(a)
                sum_1 += a
            else:
                break
        l2 = [c2]
        sum_2 = c2
        for b in B[-1]:
            if t + b <= K:
                l2.append(b)
                sum_2 += b
            else:
                break
        
        if sum_1 <= sum_2:
            t += sum_1
            cnt += len(l1)
            for i in range(len(l1)-1):
                A.pop()
            c1 = A.pop() if bool(A) else 100000000000
        else:
            t += sum_2
            cnt += len(l2)
            for i in range(len(l2)-1):
                B.pop()
            c2 = B.pop() if bool(B) else 100000000000

    elif t + c1 <= K:
        
        t += c1
        cnt += 1
        c1 = A.pop() if bool(A) else 100000000000
    else:
        if t + c2 <= K:
            t += c2
            cnt += 1
            c2 = B.pop() if bool(B) else 100000000000

print(cnt)


### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
    
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
d,t,s = map(int,input().split())
if d <= t*s{
  print("Yes")
}
else{
  print("No")

}

### FIXED CODE ###

d,t,s = map(int,input().split())
if d <= t*s:
  print("Yes")
else:
  print("No")
num = line(map(int,input().split()))
count = 0
for i in range(3):
    if num[i] == 1:
        count += 1
print(count)

### FIXED CODE ###

num = input()
count = 0
for i in range(3):
    if num[i] == '1':
        count += 1
print(count)
import math

n = int(input())
a = []  
  for i in range(n):
    a.append(int(input()))
if n == 1:
  print(a[0])
else:
  lcm = (a[0] * a[1]) // math.gcd(a[0], a[1])
  for i in range(2, n):
    lcm = (lcm * a[i]) // math.gcd(lcm, a[i])
  print(lcm)


### FIXED CODE ###

import math

n = int(input())
a = []  
for i in range(n):
  a.append(int(input()))
if n == 1:
  print(a[0])
else:
  lcm = (a[0] * a[1]) // math.gcd(a[0], a[1])
  for i in range(2, n):
    lcm = (lcm * a[i]) // math.gcd(lcm, a[i])
  print(lcm)
N = input()
if N[-1] in '24579'
    print('hon')
elif N[-1] in  "0168":
    print('pon')
else:
    print('bon')

### FIXED CODE ###

n = input()
if n[-1] in '24579':
    print('hon')
elif n[-1] in '0168':
    print('pon')
else:
    print('bon')
num = int(input())
line = []

while num >= 27:
  amari = num%26
  num = num//26
  line.append(amari)
if num < 27:
  line.append(num)

  
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
line.reverse()
for k in line:
  print(alpha[int(k)-1], end = "")

### FIXED CODE ###

let = input()
if let == let.upper():
  print("A")
else:
  print("a")
def main():
    global results, S
    S = int(input())
    S_str = str(S)
    results = []
    for i in range(len(S_str)):
        digits = len(S_str) - i
        if digits < 3:
            break

        bfs(digits, '')

    print(len(results))


def bfs(i, s):
    #  global results, S
    if i == 0:
        if int(s) <= S and len(set(s)) == 3:
            results.append(s)
        return
    i -= 1
    bfs(i, s + '3')
    bfs(i, s + '5')
    bfs(i, s + '7')


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    global results, S
    S = int(input())
    S_str = str(S)
    results = []
    for i in range(len(S_str)):
        digits = len(S_str) - i
        if digits < 3:
            break

        # 全部7の状態からはじめて、次は5次は3というふうにやる
        bfs(digits, '')

    print(len(results))


def bfs(i, s):
    global results, S
    if i == 0:
        if int(s) <= S and len(set(s)) == 3:
            results.append(s)
        return
    i -= 1
    bfs(i, s + '3')
    bfs(i, s + '5')
    bfs(i, s + '7')


if __name__ == '__main__':
    main()
use proconio::*;
use std::cmp::*;
use std::vec::Vec;

fn main() {
    input! {
        n: usize,
        mut A: [i32; n],
    }
    A.sort();
    let res = A[n - 1] - A[0];
    println!("{}", res);
}

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    print(A[-1] - A[0])


if __name__ == '__main__':
    resolve()
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  P.append([])
  for j in range(26):
    P[i].append(j)
  P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x])
  XX[P[i][0]]-=X[P[i][0]]
  X[P[i][0]]=0
SC,SC2=0,0
for i in range(D):
  SC+=S[i][P[i][0]]
YY=[]
Y=[]
k=0
L=[]
for i in range(25):
  for j in range(50-i):
    L.append(i)
for l in range(555):
  for i in range(D):
    k=L[randrange(0,len(L))]
    SC2=SC
    YY=XX[:]
    Y=X[:]
    SC2-=S[i][P[i][0]]
    SC2+=S[i][P[i][k+1]]
    for j in range(26):
      Y[j]=0
    YY[P[i][0]],YY[P[i][k+1]]=0,0
    for j in range(D):
      if j==i:
        Z=P[j][k+1]
      else:
        Z=P[j][0]
      Y[P[i][0]]+=C[P[i][0]]
      Y[P[i][k+1]]+=C[P[i][k+1]]
      Y[Z]=0
      YY[P[i][0]]+=Y[P[i][0]]
      YY[P[i][k+1]]+=Y[P[i][k+1]]
    if SC2-sum(YY)>SC-sum(XX) or (randrange(0,10)==0 and SC2-sum(YY)+500>SC-sum(XX)):
      P[i].insert(0,P[i][k+1])
      del P[i][k+2]
      XX=YY[:]
      SC=SC2
for l in range(111):
  for i in range(D):
    k=L[randrange(0,len(L))]
    SC2=SC
    YY=XX[:]
    Y=X[:]
    SC2-=S[i][P[i][0]]
    SC2+=S[i][P[i][k+1]]
    for j in range(26):
      Y[j]=0
    YY[P[i][0]],YY[P[i][k+1]]=0,0
    for j in range(D):
      if j==i:
        Z=P[j][k+1]
      else:
        Z=P[j][0]
      Y[P[i][0]]+=C[P[i][0]]
      Y[P[i][k+1]]+=C[P[i][k+1]]
      Y[Z]=0
      YY[P[i][0]]+=Y[P[i][0]]
      YY[P[i][k+1]]+=Y[P[i][k+1]]
    if SC2-sum(YY)>SC-sum(XX):
      P[i].insert(0,P[i][k+1])
      del P[i][k+2]
      XX=YY[:]
      SC=SC2
'''
スコア計算用
UKU=0
X=[0]*26
for i in range(D):
  T=P[i][0]+1
  UKU+=S[i][T-1]
  for j in range(26):
    X[j]+=C[j]
  X[T-1]=0
  UKU-=sum(X)
'''
print(UKU)
for i in range(D):
  print(P[i][0]+1)

### FIXED CODE ###

D=int(input())
for i in range(D):
  print(i%26+1)
a,b=map(int,input().split())
if a<=8&b<=8:
  print('Yay!')
else
  print(':(')

### FIXED CODE ###

a,b=map(int,input().split())
if a<=8 and b<=8:
  print('Yay!')
else:
  print(':(')
num = input()
x = [int(i) for i in num]
for i in range(len(x)):
    if x[i] == 1:
        x[i] = "9"
    else:
        x[i] = "1"
mojiretu = ','.join(x)
print(int(mojiretu))


### FIXED CODE ###

num = input()
x = [int(i) for i in num]
for i in range(len(x)):
    if x[i] == 1:
        x[i] = "9"
    else:
        x[i] = "1"
mojiretu = ''.join(x)
print(int(mojiretu))
N=int(input())
A=list(map(int,input().split()))
count=0
for num in range(N)
    if A[num]>A[num+1]:
        count=count+A[num]-A[num+1]
        A[num+1]=A[num]
    else:
        continue        
print(count)  

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
count=0
for num in range(N-1):
    if A[num]>A[num+1]:
        count=count+A[num]-A[num+1]
        A[num+1]=A[num]
    else:
        continue        
print(count)
def find_next(room, move):
    for next in path[room]:
        if mark[next] != None:
            if mark[next][1] < move:
                continue
            else:
                mark[next] = (room, move)
                # find_next(next, move + 1)
        else:
            mark[next] = (room, move)
            find_next(next, move + 1)

N, M = map(int, input().split())
path = [[] for _ in range(N)]
for i in range(M):
    A_i, B_i = map(int, input().split())
    path[A_i - 1].append(B_i - 1)
    path[B_i - 1].append(A_i - 1)
# print(path)
mark = [None] * N
mark[0] = (0, 0)
find_next(0, 1)
if None in mark:
    print("No")
else:
    print("Yes")
    for i in range(1, len(mark)):
        print(mark[i][0] + 1)

### FIXED CODE ###

from collections import deque
n, m = map(int,input().split())
AB = [tuple(map(int, input().split())) for _ in range(m)]

def bfs(start):
    queue = deque()
    visited = [False] * n
    visited[start-1] = True
    queue.append(start)
    while queue:
        target = queue.popleft()
        for i in g[target]:
            if not visited[i-1]:
                ans[i-2] = target
                visited[i-1] = True
                queue.append(i)

ans = [0] * (n-1)
g = dict()
for a, b in AB:
    if a in g:
        g[a].append(b)
    if b in g:
        g[b].append(a)
    if a not in g:
        g[a] = [b]
    if b not in g:
        g[b] = [a]
start = 1
bfs(start)
if len([i for i in ans if i == 0]) == 0:
    print("Yes")
    print(*ans, sep="\n")
else:
    print("No")
N, M=map(int,input.split())
a=list(map(int,input.split()))
if N-sum(a)>=0:
  print(N-sum(a))
else:
  print(-1)
  

### FIXED CODE ###

N, M=map(int,input().split())
a=list(map(int,input().split()))
if N-sum(a)>=0:
  print(N-sum(a))
else:
  print(-1)
import math
n, m = map(int, input().split())

# 偶数足す偶数
# 奇数たす奇数
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=0
if (n!=1):
    ans = ans+ combinations_count(n, 2)

if (m != 1):
    ans = ans + combinations_count(m, 2)
    
print(ans)

### FIXED CODE ###

import math
n, m = map(int, input().split())

# 偶数足す偶数
# 奇数たす奇数
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=0
if (n==0 and m>=2):
    ans = ans + combinations_count(m, 2)

elif (n>=2 and m== 0):
    ans = ans + combinations_count(n, 2)
else:
    if (n!=1):
        ans = ans+ combinations_count(n, 2)
    
    if (m != 1):
        ans = ans + combinations_count(m, 2)



print(ans)
from functools import reduce
from operator import mul

mod = 10**9 + 7

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

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

if N == K:
    print(reduce(mul, A)%mod)

else:

    AP = []
    AM = []
    for i in A:
        if i < 0:
            AM.append(i)
        else:
            AP.append(i)
            
    if len(AP) == 0 and K%2 != 0:
        AM.sort(reverse=True)
        AM = AM[:K]
        print(reduce(mul, AM)%mod)

    else:
        
        AP.sort(reverse=True)
        AM.sort()

        ans = 1
        p = 0
        m = 0
        cnt = 0
        while True:
            if (K - cnt) == 1:
                ans *= AP[p]
                print(ans%mod)
                break
                
            if 1 == len(AP):
                ans *= (AM[m]*AM[m+1])
                m += 2
                cnt += 2 
            
            elif 1 == len(AM):
                ans *= (AP[p]*AP[p+1])
                p += 2
                cnt += 2
            else:   
                if AP[p]*AP[p+1] >= AM[m]*AM[m+1]:
                    ans *= (AP[p]*AP[p+1])
                    p += 2
                    cnt += 2
                
                else:
                    ans *= (AM[m]*AM[m+1])
                    m += 2
                    cnt += 2 

            if cnt == K:
                print(ans%mod)
                break

### FIXED CODE ###

from bisect import bisect_left,bisect_right
p=10**9+7
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
pi=1
ni=0
ans=1
i=0
while i<k-1:
  if a[ni]*a[ni+1]>a[-pi]*a[-pi-1]:
    ans=ans*a[ni]*a[ni+1]%p
    ni+=2
    i+=2
  else:
    ans=ans*a[-pi]%p
    pi+=1
    i+=1
if i==k-1:
  ans=ans*a[-pi]%p
if a[-1]<0 and k%2==1:
  ans=1
  for i in a[n-k:]:
    ans=ans*i%p
print(ans)
k=int(input())
import fractions

for p in range(1,k+1):
    for q in range(1,k+1):
        for r in range(1,k+1):
            ans=p
            ans = fractions.gcd(ans, q)
            ans = fractions.gcd(ans, r)
            sum_g+=ans
            ans=0
print(sum_g)


### FIXED CODE ###

import math

K=int(input())
sum=0


for i in range(1,K+1):
    for j in range(1,K+1):
        a=math.gcd(i,j)
        for k in range(1,K+1):
            b=math.gcd(a, k)
            sum = sum + b

print(sum)
n = int(input())
if n%4 == 0　or n%7 == 0:
  print('Yes')
  exit()
 
for _ in range(n//7):
  n -=7
if n == 4:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n = int(input())
a = n//4
b = n//7
ans = False

for i in range(a+1):
  for j in range(b+1):
    if i*4+j*7 == n:
      ans = True

if ans == True:
  print('Yes')
else:
  print('No')
weather = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}

in = input()
print(weather[in])

### FIXED CODE ###

weather = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
 
today = input()
print(weather[today])
class Node:
    def __init__(self,data):
        self.data=data
        self.left=None
        self.right=None
class BST:
    def __init__(self,number_list):
        self.root=None
        for node in number_list:
            self.insert(node)
    def insert(self,data):
        n=self.root
        if n is None:
            self.root=Node(data)
            return
        else:
            while True:#これ抜けてた。やばい。
                entry=n.data
                if data<entry:
                    if n.left is None:
                        n.left=Node(data)
                        return
                    n=n.left
                elif data>entry:
                    if n.right is None:
                        n.right=Node(data)
                        return
                    n=n.right
                else:
                    n.data=data
                    return
    def search(self,target):
        n = self.root
        if n is None:
            return None
        else:#深さ優先探索
            lst = []
            lst.append(n)
            while len(lst) > 0:
                node = lst.pop()
                if node is None:
                    return False
                elif node.data == target:
                    self.node_recreate(node)
                    node=None
                    return True
                elif node.data < target :
                    lst.append(node.right)
                elif node.data > target:
                    lst.append(node.left)
            return False
        
    def node_recreate(self,node):
        #ノード再作成機能を装着
        num_lst=[]
        node_lst=[node]
        while len(node_lst)>0:
            node_=node_lst.pop()
            if node_.right is not None:
                node_lst.append(node_.right)
                num_lst.append(node_.right.data)
            if node_.left is not None:
                node_lst.append(node_.left)
                num_lst.append(node_.left.data)
        for num in num_lst:
            self.insert(num)
            
                
    
import math
N=int(input())
a=list(map(int,input().split()))
t_max=int(math.log2(max(a)*2)+1)
ans=0
bst=BST(a)
for t in range(t_max,0,-1):
    i=0
    while i<len(a):
    #forだとout of rangeしてしまうので。
        x,y=0,0
#         bst=BST(a)#二分木も更新しないと。
#更新を削除に変更。大分計算回数は減るはず。
        if bst.search(2**t-a[i]):
            if a[i]!=2**t-a[i]:
                #同じだったらNG
                ans+=1
                x+=a[i]
                y+=2**t-a[i]
                #IDを共有すると、インデックスがずれる。
                a.remove(x)
                bst.search(x)#削除を兼ねて
                print(bst.search(y))
                print(x,y)
                a.remove(y)
            else:
                i+=1#これ忘れてた....sampleも通らないよ
        else:
            i+=1 #ペアが見つからなかったときだけ進めばいい。
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
for i in a:
    if c[i] == 0:
        continue
    c[i] -= 1
    k = 1<<i.bit_length()
    j = k-i
    if j in c and c[j] > 0:
        ans += 1
        c[j] -= 1
print(ans)
n,k=map(int,input().split())
l=list(map(int,input.split()))
l.sort()
c=0
for i in range(k):
    c += l[-1-k]
print(c)

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
c=0
for i in range(k):
    c += l[-1-i]
print(c)