Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import Counter as C

_, k = map(int, input().split())
a = [int(i) for i in input().split()]

ans = 0
c = sorted(C(a).values())
while k < len(c):
    ans += c.pop(0)
else:
    print(ans)

### FIXED CODE ###

from collections import Counter, deque

_, k = map(int, input().split())
a = [int(i) for i in input().split()]

ans = 0
d = deque(sorted(Counter(a).values()))
while k < len(d):
    ans += d.popleft()
else:
    print(ans)
### BUGGY CODE ###

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

def factorize(x):
    """xの素因数分解を表す辞書 {素因数: 指数}"""
    f = {}
    d = 2
    while x > 1:
        while x % d == 0:
            if d not in f:
                f[d] = 0
            f[d] += 1
            x //= d
        d += 1
    return f

def dropmin(ls):
    """[min(ls[:i] + ls[i + 1:]) for i in range(len(ls))]"""
    # l = [min(ls[:i]) for i in range(len(ls))]
    l = [float('inf')] * len(ls)
    for i in range(1, len(ls)):
        l[i] = min(l[i - 1], ls[i - 1])
    # r = [min(ls[i + 1:]) for i in range(len(ls))]
    r = [float('inf')] * len(ls)
    for i in range(len(ls) - 2, -1, -1):
        r[i] = min(r[i + 1], ls[i + 1])
    return [min(a, b) for a, b in zip(l, r)]

def prod(ls):
    p = 1
    for x in ls:
        p *= x
    return p

# 各A_iの素因数
F = [factorize(a) for a in A]

# 素因数の集合 (2要素に出現しない素因数は無視)
D =  set(F[0].keys())
D.update(F[1].keys())

# Dの要素 d → dが各A_iに含まれる個数のリスト
X = {d: [f[d] if d in f else 0 for f in F] for d in D}

# Dの要素 d → A_iを削除したときのdの個数の最小値のリスト
X = {d: dropmin(X[d]) for d in D}

S = [prod(d ** X[d][i] for d in D if X[d][i] > 0) for i in range(N)]
print(max(S))


### FIXED CODE ###

# math.gcd is introduced in python 3.5
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a

N = int(input())
A = [int(a) for a in input().split()]

# L[i] = gcd(A[:i + 1])
# R[i] = gcd(A[i:])
L = [0] * N
L[0] = A[0]
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i])
R = [0] * N
R[-1] = A[-1]
for i in range(N - 2, -1, -1):
    R[i] = gcd(R[i+1], A[i])

G = [0] * N
G[0]  = R[1]
G[-1] = L[-2]
for i in range(1, N - 1):
    G[i] = gcd(L[i-1], R[i+1])

print(max(G))
### BUGGY CODE ###

from collections import deque
import math

def explore(C, D):
    queue = deque([[C[0]-1, C[1]-1]])
    maze_visited[C[0]-1][C[1]-1] = 0
    while queue:
        y, x = queue.popleft()
        mv_cur = maze_visited[y][x]
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            n_x, n_y = x + i, y + j
            if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                mv_n = maze_visited[n_y][n_x]
                if mv_n > mv_cur:
                    if S[n_y][n_x] == '.':
                        maze_visited[n_y][n_x] = mv_cur
                        queue.append([n_y, n_x])
        for i in range(-2, 3):
            for j in range(-2, 3):
                if abs(i) + abs(j) <= 1:
                    continue
                n_x, n_y = x + i, y + j
                if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                    mv_n = maze_visited[n_y][n_x]
                    if mv_n > mv_cur + 1:
                        if S[n_y][n_x] == '.':
                            maze_visited[n_y][n_x] = mv_cur + 1
                            queue.append([n_y, n_x])
    
H, W = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))

S = [list(input()) for i in range(H)]

maze_visited = [[math.inf] * W for i in range(H)]

explore(C,D)

if maze_visited[D[0] - 1][D[1] - 1] == math.inf:
    print('-1')
else:
    print(maze_visited[D[0] - 1][D[1] - 1])

### FIXED CODE ###

from collections import deque
import math
 
def explore(C, D):
    queue = deque([(C[0]-1, C[1]-1)])
    maze_visited[C[0]-1][C[1]-1] = 0
    while queue:
        y, x = queue.popleft()
        mv_cur = maze_visited[y][x]
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            n_x, n_y = x + i, y + j
            if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                mv_n = maze_visited[n_y][n_x]
                if mv_n > mv_cur:
                    if S[n_y][n_x] == '.':
                        maze_visited[n_y][n_x] = mv_cur
                        queue.appendleft((n_y, n_x))
        for i in range(-2, 3):
            for j in range(-2, 3):
                if abs(i) + abs(j) <= 1:
                    continue
                n_x, n_y = x + i, y + j
                if n_x >= 0 and n_y >= 0 and n_x < W and n_y < H:
                    mv_n = maze_visited[n_y][n_x]
                    if mv_n > mv_cur + 1:
                        if S[n_y][n_x] == '.':
                            maze_visited[n_y][n_x] = mv_cur + 1
                            queue.append((n_y, n_x))
    
H, W = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
 
S = [list(input()) for i in range(H)]
 
maze_visited = [[math.inf] * W for i in range(H)]
 
explore(C,D)
 
if maze_visited[D[0] - 1][D[1] - 1] == math.inf:
    print('-1')
else:
    print(maze_visited[D[0] - 1][D[1] - 1])
### BUGGY CODE ###

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

X = []
Y = []
P = []
for i in range(N):
	coor = tuple(map(int, input().split()))
	P.append(coor)
	X.append(coor[0])
	Y.append(coor[1])
	
X.sort()
Y.sort()

answer = (X[-1] - X[0])*(Y[-1] - Y[0])

for xmin in range(N):
	for xmax in range(xmin+1, N):
			for ymin in range(N):
				for ymax in range(ymin+1, N):
						cnt = 0
						for i in range(N):
							if X[xmin] <= P[i][0] and P[i][0] <= X[xmax] and Y[ymin] <= P[i][1] and P[i][1] <= Y[ymax]:
								cnt += 1
						if cnt >= K:
							answer = min(answer, (X[xmax]-X[xmin])*(Y[ymax]-Y[ymin]))
print(int(answer))


### FIXED CODE ###

import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
 
N,K = LI()
p = []
for i in range(N):
    a,b = LI()
    p.append((a,b))
sx = sorted(p)
ans = 10**50
for x,y in sx:
    for x2,y2 in sx:
        if x2 <= x:
            continue
        points = sx.index((x2,y2)) - sx.index((x,y)) + 1
        if points < K:
            continue
        sy = sorted(sx[sx.index((x,y)):sx.index((x2,y2))+1],key=lambda sx: sx[1])
        for j in range(len(sy)-K+1):
            if sy[j][1] <= y and y2 <= sy[j+K-1][1]:
                ans = min(ans, (x2 - x) * (sy[j+K-1][1]-sy[j][1])) 
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    sumA=[sum(A[:i+1])for i in range(N)]
    #print(sumA)
    ans=2020202020
    t=sumA[-1]
    for i in range(N):
        ans=min(ans,abs(t-sumA[i]*2))
    print(ans)
#%%submit!
resolve()

### FIXED CODE ###

#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    temp=0
    sumA=[0]*N
    sumA[0]=A[0]
    for j in range(1,N):
        sumA[j]=sumA[j-1]+A[j]
    #print(sumA)
    ans=2**32-1
    t=sumA[-1]
    for i in range(N):
        ans=min(ans,abs(t-sumA[i]*2))
        
    print(ans)
#%%submit!
resolve()
### BUGGY CODE ###

# DP
def main():
    from builtins import max

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

    dp = [-1] * (W + 1)
    dp[0] = 0
    max_w = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for j in range(min(max_w, W - w), -1, -1):
            if dp[j] != -1:
                dp[j + w] = max(dp[j + w], dp[j] + v)
            max_w = max(max_w, j + w)
    print(max(dp))


main()


### FIXED CODE ###

n, w = [int(e) for e in input().split()]
d = [[int(e) for e in input().split()] for i in range(n)]
t = {}
t[w] = 0
for i in range(n):
  keys = list(sorted(t.keys()))
  tw, tv = d[i]
  for j in keys:
    nw = j - tw
    if nw < 0:
      continue
    nv = t[j] + tv
    if nw in t:
      if nv > t[nw]:
        t[nw] = nv
    else:
      t[nw] = nv
print(max(t.values()))
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    for j in range(len(A)):
        if A[j] == b:
            A[j] = c
    print(sum(A))

### FIXED CODE ###

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int, input().split()))
ans = sum(A)
cnt = collections.Counter(A)
#print(cnt)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    ans += (c-b)*cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    #print(cnt)
    print(ans)
### BUGGY CODE ###

s = input()

mod = 1000000007
length = len(s)
ans = list([0]*13 for i in range(length+1))
ans[0][0] = 1

for i in range(length):
    for j in range(13):
        if s[i] == '?':
            for k in range(10):
                x = (j*10+k)%13
                ans[i+1][x] += ans[i][j]
        else:
            x = (j*10 + int(s[i])) % 13
            ans[i+1][x] += ans[i][j]

print(ans[length][5] % mod)


### FIXED CODE ###

MOD = 1000000007;

s = [int(x) if x!="?" else -1 for x in input()]

n=len(s)

r=[0]*13

c=s[0]
if (c!=-1):
	r[c]=1
else:
	for i in range(10):r[i]=1

for i in range(1,n):
	dp=[0]*26
	for j in range(13):dp[j*10%13]+=(r[j]%MOD)
	dp[13:26]=dp[0:13]
	c=s[i]
	r=[0]*13
	if (c==-1):
		w=sum(dp[4:14])
		for j in range(13):
				r[j]+=w
				w=w+dp[j+1]-dp[4+j]
	else:
		for j in range(13):
			r[j]+=dp[13-c+j]
print (r[5]%MOD)
### BUGGY CODE ###

N=int(input())
tmp = 0
while N>0:
    for i in range(1,N+1):
        if N <= i*(i+1)//2:
            print(i)
            N -=i
            break

### FIXED CODE ###

N=int(input())
tmp = 0
while N>0:
    for i in range(1,N+1):
        if N <= i*(i+1)//2:
            print(i)
            N -=i
            break
### BUGGY CODE ###

N = int(input())

cnt = 0
for A in range(1,N):
    for B in range(1,N):
        if A * B <= N-1:
            cnt += 1
        else:
            break
print(cnt)


### FIXED CODE ###

N = int(input())
cnt = 0
for A in range(1,N):
    cnt += (N-1) // A
print(cnt)
### BUGGY CODE ###


def main():
  x, y, _a, _b, _c = map(int, input().split())
  p = sorted(map(int, input().split()))[-x:]
  q = sorted(map(int, input().split()))[-y:]
  r = sorted(map(int, input().split()), reverse=True)[:x + y]

  arr = sorted(p + q)

  for nc_apple in r:
    apple = arr[0]
    if apple >= nc_apple: break

    arr[0] = nc_apple

    for i in range(len(arr) - 1):
      if arr[i] < arr[i + 1]: break

      arr[i], arr[i + 1] = arr[i + 1], arr[i]

  print(sum(arr))


main()


### FIXED CODE ###


def main():
  x, y, _a, _b, _c = map(int, input().split())
  p = sorted(map(int, input().split()))[-x:]
  q = sorted(map(int, input().split()))[-y:]
  r = sorted(map(int, input().split()), reverse=True)[:x + y]

  arr = sorted(p + q)
  new_num = 0

  for i, nc_apple in enumerate(r):
    if arr[i] >= nc_apple: break

    new_num += nc_apple - arr[i]

  print(sum(arr) + new_num)


main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline  # NOQA
sys.setrecursionlimit(10 ** 7)  # NOQA


def dfs(G, v, p, counter, x):
    """G: graph, v: vertex, p: parent"""
    counter[v] += x
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue  # Avoid multiple access to parent
        dfs(G, c, v, counter, x)


def calc_parent(G, v, p, parent):
    parent[v] = p
    for c in G[v]:
        if c == p:
            continue
        calc_parent(G, c, v, parent)


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

    parent = [-1] * N
    calc_parent(G, 0, -1, parent)
    counter = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1
        dfs(G, p, parent[p], counter, x)

    print(*counter)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def dfs(G, v, p, point):
    """G: graph, v: vertex, p: parent"""
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue
        point[c] += point[v]
        dfs(G, c, v, point)


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

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

    dfs(G, 0, -1, point)
    print(" ".join(map(str, point)))


if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
from collections import defaultdict
from string import ascii_uppercase
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N,Q = read_int()
s = read_str()
td = [list(read_str().split()) for _ in range(Q)]
d = defaultdict(list)
for a in ascii_uppercase:
    d[a] = []
for i in range(N):
    d[s[i]].append(i)
d = dict(d)
lr = {"L":-1, "R":1}

dp = [1 for _ in range(N)]
def solve():
    for i in range(Q):
        char = td[i][0]
        move = lr[td[i][1]]
        plus = []
        minus = []
        for cur in d[char]:
            if dp[cur] < 1:
                continue
            if cur + move >= 0 and cur + move < N:
                plus.append([cur + move, dp[cur]])
            minus.append([cur, dp[cur]])
        while plus:
            p = plus.pop()
            dp[p[0]] += p[1]
        while minus:
            p = minus.pop()
            dp[p[0]] -= p[1]


if __name__ == "__main__":
    solve()
    print(sum(dp))

### FIXED CODE ###

import sys
from collections import defaultdict
from string import ascii_uppercase
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N,Q = read_int()
s = read_str()
td = [list(read_str().split()) for _ in range(Q)]
lr = {"L":-1, "R":1}


def solve():
    # left
    lb = -1
    ub = N
    lefr = (lb + ub) // 2
    while ub - lb > 1:
        lefr = (lb + ub) // 2
        md = lefr
        over = False
        for i in range(Q):
            t, d = td[i]
            if t != s[md]:
                continue
            md += lr[d]
            if md > N - 1:
                over = True
                break
            elif md < 0:
                break
        if over:
            ub = lefr
        else:
            lb = lefr
    l = ub
	
    # right
    lb = -1
    ub = N
    refl = (lb + ub) // 2
    while ub - lb > 1:
        refl = (lb + ub) // 2
        md = refl
        over = False
        for i in range(Q):
            t, d = td[i]
            if t != s[md]:
                continue
            md += lr[d]
            if md < 0:
                over = True
                break
            elif md > N - 1:
                break
        if over:
            lb = refl
        else:
            ub = refl
    r = lb
    res = l - r - 1
    return res

if __name__ == "__main__":
    print(solve())
### BUGGY CODE ###

from collections import*;n,k,*a=map(int,open(0).read().split());print(n-sum(Counter(a).most_common()[i][1] for i in range(min(len(set(a)),k))))

### FIXED CODE ###

from collections import Counter
n,k,*a=map(int,open(0).read().split())
if len(set(a))<=k:
	print(0)
	exit()
else:
	c=Counter(a).most_common(k)
	n-=sum(c[i][1] for i in range(k))
	print(n)
### BUGGY CODE ###

from collections import deque

def bfs(graph, start, goal, connection):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        if now == goal or goal in c[now]:
            c[start].add(goal)
            c[goal].add(start)
            return "yes"
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return "no"

n, m = map(int, input().split())
g = [[] for i in range(n)]
c = [set() for i in range(n)]

for i in range(m):
    inp = list(map(int, input().split()))
    g[inp[0]].append(inp[1])
    g[inp[1]].append(inp[0])
    c[inp[0]].add(inp[1])
    c[inp[1]].add(inp[0])

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    print(bfs(g, s, t, c))

### FIXED CODE ###

from collections import deque

def bfs(graph, start):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return visited

n, m = map(int, input().split())
g = [set() for i in range(n)]
group = []

for i in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    for j in range(len(group)):
        if s in group[j] and t in group[j]:
            print("yes")
            break
        elif s in group[j]:
            print("no")
            break
    else:
        group_tmp = set(bfs(g, s).keys())
        if t in group_tmp:
            print("yes")
        else:
            print("no")
        group.append(group_tmp)
### BUGGY CODE ###

import numpy as np
N = int(input())
temp = input()
a = np.array([int(i) for i in temp.split()])

num_X = 0

for ele in a:
    X_new = 0
    X_new += len(a) - np.count_nonzero(a - ele)
    X_new += len(a) - np.count_nonzero(a - ele -1)
    X_new += len(a) - np.count_nonzero(a - ele +1)
    num_X = max(num_X, X_new)

print(num_X)

### FIXED CODE ###

import numpy as np
N = int(input())
temp = input()
a = np.array([int(i) for i in temp.split()])

list_X = [0]*1000000

for ele in a:
    list_X[ele] += 1
    list_X[ele-1] += 1
    list_X[ele+1] += 1

print(max(list_X))
### BUGGY CODE ###

import array

def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count

def merge(left, right):
    lpos = 0
    rpos = 0
    rcount = 0
    merged = array.array('I', [])
    len_left = len(left)
    len_right = len(right)
    while lpos < len_left and rpos < len_right:
        if left[lpos] < right[rpos]:
            merged.append(left[lpos])
            lpos += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            rcount += len(left[lpos:])
    
    if left[lpos:]:
        merged.extend(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
    
    return merged, rcount
    
if __name__ == '__main__':
    n = int(raw_input())
    A = array.array('I', map(int, raw_input().split()))
    
    sorted, count = merge_sort(A)
    #print ' '.join(str(x) for x in sorted)
    print count

### FIXED CODE ###

from array import array

def merge_sort(A):
    if len(A) <= 1:
        return A, 0
    mid = len(A) // 2
    left, lcount = merge_sort(A[:mid])
    right, rcount = merge_sort(A[mid:])
    merged, count = merge(left, right)
    return merged, lcount + rcount + count

def merge(left, right):
    lpos = 0
    rpos = 0
    rcount = 0
    merged = array('I', [])  # List is too slow. Use an array instead.
    len_left = len(left)
    len_right = len(right)
    while lpos < len_left and rpos < len_right:
        if left[lpos] < right[rpos]:
            merged.append(left[lpos])
            lpos += 1
        else:
            merged.append(right[rpos])
            rpos += 1
            #rcount += len(left[lpos:])
            rcount += len_left - lpos
    
    if left[lpos:]:
        merged.extend(left[lpos:])
    if right[rpos:]:
        merged.extend(right[rpos:])
    
    return merged, rcount
    
if __name__ == '__main__':
    n = int(raw_input())
    A = array('I', map(int, raw_input().split()))
    
    sorted, count = merge_sort(A)
    #print ' '.join(str(x) for x in sorted)
    print count
### BUGGY CODE ###

import numpy as np
import sys
import math

n=int(input())
A=np.array(sorted(list(map(int,input().split()))))
B=np.append(np.append(A,A+1),A-1)
ans=0
for i in set(B):
    ans=max(ans,np.count_nonzero(B==i))
print(ans)

### FIXED CODE ###

import numpy as np
import sys
import math

n=int(input())
A=np.array(sorted(list(map(int,input().split()))))
C=np.bincount(A)
D=C.copy()
D[1:]+=C[:-1]
D[:-1]+=C[1:]
print(np.max(D))
### BUGGY CODE ###


N = int(input())

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

"""

2べきになる条件は？
→片方が2の補数であること

Nが大きい→貪欲的に
最大の奴はそれより小さい奴としかペアを組めない
→大きい奴から貪欲にとっけいけばいける？

いけそうかなぁ
"""

A.sort()
An = []
for i in range(N):
    if i == 0 or An[-1][0] != A[i]:
        An.append([ A[i] , 1 ])
    else:
        An[-1][1] += 1

import bisect
ans = 0

#print (An)

for i in range(len(An)-1,-1,-1):

    for j in range(An[i][1]):

        An[i][1] -= 1

        for k in range(30,-1,-1):
            if 2**k <= An[i][0]:
                continue

            ind = bisect.bisect_left(An,[2**k - An[i][0],0])
            if ind < len(An) and An[ind][0] == 2**k - An[i][0] and An[ind][1] > 0:
                An[ind][1] -= 1
                ans += 1
                break

print (ans)

### FIXED CODE ###


import bisect

"""
def wantp(n):

    wq = []
    while p[n] != n:
        wq.append(n)
        n = p[n]

    for i in wq:
        p[i] = n

    return n
"""


N = int(input())

B = list(map(int,input().split()))
B.sort()

A = []
AS = []
for i in range(N):
    if len(A) == 0:
        A.append(B[0])
        AS.append(1)
    else:
        if A[-1] == B[i]:
            AS[-1] += 1
        else:
            A.append(B[i])
            AS.append(1)


"""
p = [i for i in range(N)]
rank = [1] * N
"""
ans = 0

for i in range(len(A)):

    i = len(A) - 1 - i
    now = 2 ** 33

    while A[i] * 2 < now:
        now //= 2

    ind = bisect.bisect_left(A,now-A[i])

    if A[ind] + A[i] == now:

        if ind == i:
            ans += AS[i] // 2
            AS[i] = AS[i] % 2

        else:
            ans += min(AS[i],AS[ind])
            AS[ind] = max(AS[ind] - AS[i] , 0)



    #print (now,na,ind)

print (ans)
### BUGGY CODE ###

def main():
  import sys
  input = sys.stdin.readline

  r,c,k = map(int,input().split())
  b = [[0 for _ in range(c)] for _ in range(r)]
  for i in range(k):
    y,x,v = map(int,input().split())
    y -= 1
    x -= 1
    b[y][x] = v

  # dp[i][j][l]:(i,j)に居て、i行目のアイテムをl個拾ったときの価値最大値。
  dp = [[[0 for _ in range(4)] for _ in range(c+1)] for _ in range(r+1)]
  for i in range(r):
    for j in range(c):
      # アイテムを拾う遷移。個数が多い方から計算する。
      for l in range(2,-1,-1):
        dp[i][j][l+1] = max(dp[i][j][l]+b[i][j],dp[i][j][l+1])
      # 移動する遷移。行を移動する際は、拾ったアイテム数はリセットされる。
      for l in range(4):
        dp[i+1][j][0] = max(dp[i][j][l],dp[i+1][j][0])
        dp[i][j+1][l] = max(dp[i][j][l],dp[i][j+1][l])
  ans = 0
  for i in range(4):
    ans = max(dp[r-1][c-1][i],ans)
  print(ans)

main()

### FIXED CODE ###

def main():
  import sys
  input = sys.stdin.readline

  r,c,k = map(int,input().split())
  b = [[0 for _ in range(c)] for _ in range(r)]
  for i in range(k):
    y,x,v = map(int,input().split())
    y -= 1
    x -= 1
    b[y][x] = v

  # dp[j][l]:(i,j)に居て、i行目のアイテムをl個拾ったときの価値最大値。
  dp = [[0 for _ in range(4)] for _ in range(c+1)]
  for i in range(r):
    for j in range(c):
      # アイテムを拾う遷移。個数が多い方から計算する。
      for l in range(2,-1,-1):
        dp[j][l+1] = max(dp[j][l]+b[i][j],dp[j][l+1])
      # 移動する遷移。行を移動する際は、拾ったアイテム数はリセットされる。
      for l in range(4):
        dp[j+1][l] = max(dp[j][l],dp[j+1][l])
        dp[j][0] = max(dp[j][l],dp[j][0])
  ans = 0
  for i in range(4):
    ans = max(dp[c-1][i],ans)
  print(ans)

main()