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

n, m = map(int, input().split())
a = list(map(int, input().split()))
a_t = [0]
for i in range(n):
    a_t.append(a[i] + a_t[i])
ans = 0
for i in range(n):
    ans += sum(list(map(lambda x: not (x - a_t[i]) % m, a_t[i + 1:])))
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a_t = [0]
for i in range(n):
    a_t.append(a[i] + a_t[i])
dict = {}
for i in range(n + 1):
    b = a_t[i] % m
    if b in dict:
        dict[b] += 1
    else:
        dict[b] = 1
ans = 0
for i in dict.values():
    ans += i * (i - 1) // 2
print(ans)
### BUGGY CODE ###

import fractions
A, B = map(int, input().split())
C = fractions.gcd(A, B)
ans = 1
primes = [2]

if C % 2 == 0:
  ans += 1
  while C % 2 == 0:
    C //= 2

p = 1
while C > 1:
  p += 2
  for prime in primes:
    if p % prime == 0:
      break
  else:
    primes.append(p)
    if C % p == 0:
      ans += 1
    while C % p == 0:
      C //= p
print(ans)

### FIXED CODE ###

import fractions
import math

A, B = map(int, input().split())
C = fractions.gcd(A, B)
pfac = []

def get_primes(n):
  primes = [2]
  for i in range(3, (n+1), 2):
    for p in primes:
      if i % p == 0:
        break
      if i < p ** 2:
        primes.append(i)
        break
    else:
      primes.append(i)
  return primes

def get_primes2(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n == 1:
        return []
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

for q in get_primes2(min(C, 10**6)):
  if q ** 2 > C:
    break
  if C % q == 0:
    pfac.append(q)
    while C % q == 0:
      C //= q
if C != 1:
  pfac.append(C)


print(len(pfac) + 1)
### BUGGY CODE ###

num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]

ans = [[arr[0][0], arr[0][1]]]
for i in range(num-1):
    ans.append([arr[i+1][0], arr[i+1][1]])
    while ans[i][0] > ans[i+1][0] or ans[i][1] > ans[i+1][1]:
        ans[i+1][0] += arr[i+1][0]
        ans[i+1][1] += arr[i+1][1]
print(ans[num-1][0] + ans[num-1][1])

### FIXED CODE ###

def divceil(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

num = int(input())
arr = [list(map(int, input().split())) for i in range(num)]
 
t = 1
a = 1
r = 0
for i in range(num):
    r = max(divceil(t, arr[i][0]), divceil(a, arr[i][1]))
    t = arr[i][0] * max(r, 1)
    a = arr[i][1] * max(r, 1)
print(t + a)
### BUGGY CODE ###

n=int(input())
S=input()
anslist=[]
c=0
#3けたの暗証番号なので000~999までの最大1000通り
for i in range(1000):
    c=0
    if i<10:
        i="00"+str(i)
    elif i<100:
        i="0"+str(i)
    else:
        i=str(i)
    tmp=""
    for j in range(n):
        if S[j]==i[0]:
            tmp+=S[j]
            for k in range(j+1,n):
                if c==1:
                    break
                if S[k]==i[1]:
                    tmp+=S[k]
                    for r in range(k+1,n):
                        if c==1:
                            break
                        if S[r]==i[2]:
                            tmp+=S[r]
                            anslist.append(tmp)
                            c=1
                        
#print(anslist)
print(len(anslist))

### FIXED CODE ###

n=int(input())
S=input()
anslist=[]
c=0
#3けたの暗証番号なので000~999までの最大1000通り
for i in range(1000):
    c=0
    if i<10:
        i="00"+str(i)
    elif i<100:
        i="0"+str(i)
    else:
        i=str(i)
    tmp=""
    j=0
    while j<n:
        if S[j]==i[0]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[1]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    while j<n:
        if S[j]==i[2]:
            tmp+=S[j]
            j+=1
            break
        j+=1
    if tmp==i:
        anslist.append(tmp)
                        
#print(anslist)
print(len(anslist))
### BUGGY CODE ###

n = int(input())

N = list(map(int,str(n)))

# print(N)

Nr = list(reversed(N))
Nr.append(0)
# print(Nr)

ans = 0 
for i in range(len(Nr)):
    if i<(10**100):
        if Nr[i] > 5:
            Nr[i+1] += 1
            ans += (10 - Nr[i])
        elif Nr[i]==5:
            if Nr[i+1]>=5:
                Nr[i+1] += 1
                ans += (10 - Nr[i])
            else:
                ans += Nr[i]
        else:
            ans += Nr[i]
    elif i==(10**100):
        A = Nr[i:]
        B = list(map(str,A))
        C = "".join(B)
        D = int(C)
        ans += D
    else:
        break
print(ans)

### FIXED CODE ###

n = input()
Nr = list(map(int,list(reversed(n))))
Nr.append(0)

ans = 0 
for i in range(len(Nr)):
    if Nr[i] > 5:
        Nr[i+1] += 1
        ans += (10 - Nr[i])
    elif Nr[i]==5:
        if Nr[i+1]>=5:
            Nr[i+1] += 1
            ans += (10 - Nr[i])
        else:
            ans += Nr[i]
    else:
        ans += Nr[i]

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

n = int(input())
l = list(map(int,input().split()))
dp = [[-float("INF")]*(n//2+1) for i in range(n+1)]
dp[0][0] = 0
dp[1][0] = 0
dp[1][1] = l[0]
for i in range(1,n):
    for j in range(max(0,i//2-2),min(i//2+2,n//2+1)):
        dp[i+1][j] = max(dp[i][j],dp[i-1][j-1]+l[i])
print(dp[-1][-1])



### FIXED CODE ###

n = int(input())
def main():
    import sys
    input = sys.stdin.readline
    l = list(map(int,input().split()))
    dp = [[-float("INF")]*(3) for i in range(n+1)]
    dp[0][0] = 0
    dp[1][-1] = 0
    dp[1][1] = l[0]
    for i in range(1,n):
        
        dp[i+1][-1] = max(dp[i][0],dp[i-1][-1]+l[i])
        dp[i+1][0] = max(dp[i][1],dp[i-1][0]+l[i])
        dp[i+1][1] = dp[i-1][1]+l[i]
    print(max(dp[-1][0],dp[-1][-1]))

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

N,X,M=map(int,input().split())
A=[X]
A1=X
ans=0
for i in range(1,N):
    if 2*A1>M:
        A2=((M-A1)**2)%M
    else:
        A2=(A1**2)%M
    if A2 in A:
        num=A.index(A2)
        loop=i-num
        loop_A=A[num::]
        loop_val=sum(loop_A)
        rest=N-i
        x=rest%loop
        for _ in range(x):
            ans+=A[num]
            num+=1
        ans=ans+(rest//loop)*loop_val
        break
    else:
       A1=A2 
       A.append(A2)

print(sum(A)+ans)

### FIXED CODE ###

N,X,M=map(int,input().split())
A=[X]
A1=X
ans=0
for i in range(1,N):
    if 2*A1>M:
        A2=((M-A1)**2)%M
    else:
        A2=(A1**2)%M
    if A2 in A:
        num=A.index(A2)
        loop=i-num
        loop_A=A[num::]
        loop_val=sum(loop_A)
        rest=N-i
        x=rest%loop
        for _ in range(x):
            ans+=A[num]
            num+=1
        ans=ans+(rest//loop)*loop_val
        break
    else:
       A1=A2 
       A.append(A2)

print(sum(A)+ans)
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()
cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[k] < L[i] + L[j]:
                cnt += 1
print(cnt)

### FIXED CODE ###

import bisect
N = int(input())
L = list(map(int,input().split()))
L.sort()

cnt = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        num = L[i] + L[j]
        third = bisect.bisect_left(L,num)
        if third > j:
            cnt += third - j - 1
print(cnt)
### BUGGY CODE ###

import math

n, d, a = map(int,input().split())
xh = []
for i in range(n):
    x,h = map(int,input().split())
    xh.append([x,h])

num = 0
xh.sort(key=lambda xh:xh[0])
l = len(xh)
dam = [0]*n
rang = [0]*n
for i in range(n):
    rang[i] = xh[i][0]-d

for i in range(n):
    res = xh[i][1]-dam[i]
    if res > 0:
        nat = math.ceil(res/a)
        pos = xh[i][0]+d
        num += nat
        for j in range(n):
            if rang[j] <= pos:
                dam[j] += a*nat
            else:
                break

print(num)


### FIXED CODE ###

import math

n, d, a = map(int,input().split())
xh = [[0 for i in range(2)] for j in range(n)]
left = [i for i in range(n)]
for i in range(n):
    x,h = map(int,input().split())
    xh[i] = [x,h]

num = 0
xh.sort(key=lambda xh:xh[0])

for i in range(n):
    for j in range(left[i-1],i):
        if xh[j][0]+d >= xh[i][0]-d:
            left[i] = j
            break

dam = [0]*n

def dsum(k):
    if k == 0:
        return 0
    elif left[k] == 0:
        return dam[k-1]
    else:
        return dam[k-1]-dam[left[k]-1]

for i in range(n):
    res = xh[i][1]-dsum(i)
    nat = max([math.ceil(res/a),0])
    dam[i] = dam[i-1]+a*nat
    if res > 0:
        num += nat

print(num)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
k = 0
for i in range(N-K+1):
	K_sum = max(0, sum(A[i:i+K]))
	K_pos = sum(map(lambda x:max(0, x), A[i:i+K]))
	loss = K_pos-K_sum
	if i==0:
		loss_min = loss
	if loss<loss_min:
		k = i
		loss_min = loss
K_sum_result = max(0, sum(A[k:k+K]))
result = K_sum_result + sum(map(lambda x:max(0, x), A[:k]+A[k+K:]))
print(result)




### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
k = 0
for i in range(N-K+1):
	if i>0:
		K_sum = K_sum-A[i-1]+A[i+K-1]
		K_sum0 = max(0, K_sum)
		K_pos = K_pos-max(0, A[i-1])+max(0, A[i+K-1])
	else:
		K_sum = sum(A[i:i+K])
		K_sum0 = max(0, K_sum)
		K_pos = sum(map(lambda x:max(0, x), A[i:i+K]))
	loss = K_pos-K_sum0
	if i==0:
		loss_min = loss
	if loss<loss_min:
		k = i
		loss_min = loss
K_sum_result = max(0, sum(A[k:k+K]))
result = K_sum_result + sum(map(lambda x:max(0, x), A[:k]+A[k+K:]))
print(result)
### BUGGY CODE ###

N, P = map(int, input().split())
S = input()

cnt = 0
if P == 2 or P == 5:
    for i in range(N):
        if int(S[i]) % P == 0:
            cnt += (i+1)
            
else:
    dic = dict()
    dic[0] = 1
    for i in range(N):
        s = int(S[i : N])
        if not s%P in dic:
            dic[s%P] = 1
        else:
            dic[s%P] += 1
    for i in dic:
        cnt += dic[i]*(dic[i]-1)/2
        
print(int(cnt))

### FIXED CODE ###

N, P = map(int, input().split())
S = input()

cnt = 0
if P == 2 or P == 5:
    for i in range(N):
        if int(S[i]) % P == 0:
            cnt += (i+1)
            
else:
    dic = dict()
    dic[0] = 1
    r = 0
    for i in range(N):
        s = (pow(10,i,P)*int(S[N-1-i]) + r) % P
        r = s
        if not s in dic:
            dic[s] = 1
        else:
            dic[s] += 1
    for i in dic:
        cnt += dic[i]*(dic[i]-1)/2
        
print(int(cnt))
### BUGGY CODE ###

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

MOD = 1000000007
SUM = 0
for i in range(N-1):
  for j in range(i+1, N):
    SUM += A[i]*A[j] % MOD
    SUM %= MOD
print(SUM)
    

### FIXED CODE ###

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

MOD = 1000000007
SUM = 0
for i in range(N):
  SUM += A[i]
SUM = SUM*SUM
for i in range(N):
  SUM -= A[i]*A[i]
SUM = SUM // 2
SUM %= MOD
print(SUM)
### BUGGY CODE ###

N = int(input())
ss = []
for _ in range(N):
    ss.append(''.join(sorted(input())))

result = 0
for i in range(N):
    for j in range(i + 1, N):
        if ss[i] == ss[j]:
            result += 1
print(int(result))

### FIXED CODE ###

N = int(input())
ss = []
for _ in range(N):
    ss.append(''.join(sorted(input())))
d = {}
for s in ss:
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
print(sum(int((v * (v - 1)) / 2) for v in d.values() if v > 1))
### BUGGY CODE ###

from collections import deque
 
def main():
    N, M = map(int, input().split())
    route = [[] for _ in range(N)]
 
    for i in range(M):
        a, b = map(int, input().split())
        route[a-1].append(b-1)
        route[b-1].append(a-1)
    
    arrive_time = [0] + [-1] * (N - 1)
    arrive_route = [0] + [-1] * (N - 1)
    q = deque()
    q.append(0)
    while len(q):
        idx = q.pop()
        for c in route[idx]:
            if arrive_time[c] >= 0 and arrive_time[c] <= arrive_time[idx]+1:
                continue
            arrive_time[c] = arrive_time[idx]+1
            arrive_route[c] = idx
            q.append(c)
    if min(arrive_time) < 0:
        print("No") 
    else:
        print("Yes")
        for r in arrive_route[1:]:
            print(r+1)
 
 
if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque, defaultdict
from sys import stdin

input = stdin.readline
def main():
    N, M = map(int, input().split())
    route = defaultdict(list)
    for i in range(M):
        a, b = map(int, input().split())
        route[a-1].append(b-1)
        route[b-1].append(a-1)
    
    arrive_time = [0] + [-1] * (N - 1)
    arrive_route = [0] + [-1] * (N - 1)
    q = deque()
    q.append(0)
    while len(q):
        idx = q.popleft()
        for c in route[idx]:
            if arrive_time[c] >= 0 and arrive_time[c] <= arrive_time[idx]+1:
                continue
            arrive_time[c] = arrive_time[idx]+1
            arrive_route[c] = idx
            q.append(c)
    if min(arrive_time) < 0:
        print("No") 
    else:
        print("Yes")
        for r in arrive_route[1:]:
            print(r+1)


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

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    print(a.index(i+1)+1)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
l = []
for i in range(n):
    l.append((a[i], i+1)) 
c = sorted(l)
for i in range(n):
    print(c[i][1])
### BUGGY CODE ###

n1 = input()
A = map(int, raw_input().split())

n2 = input()
q = map(int, raw_input().split())

list = set()

def solve(i,m):
 if m == 0:
  return True
 if i >= n1:
  return False
 res = solve(i+1,m) or solve(i+1,m-A[i])
 return res

for m in q:
 if solve(0,m):
  print "yes"
 else:
  print "no"

### FIXED CODE ###

n1 = input()
A = map(int, raw_input().split())

n2 = input()
q = map(int, raw_input().split())

list = set()

def solve(i,m):
 if m == 0:
  return True
 if i >= n1 or m > sum(A):
  return False
 res = solve(i+1,m) or solve(i+1,m-A[i])
 return res

for m in q:
 if solve(0,m):
  print "yes"
 else:
  print "no"
### BUGGY CODE ###

import numpy as np
room, route_count = map(int,input().split())
route = np.array([list(map(int,input().split())) for _ in range(route_count)])

object_nums = [1]
ans = [0]*(room-1)

def mem_ans(ans, object_num, next):
    if next is not None:
      for n in next:
        if ans[n-2] == 0:
          ans[n-2] = object_num
    return ans

for object_num in object_nums:
    object_rows = route[np.any(route==object_num, axis=1)]
    route[np.any(route==object_num, axis=1)] = 0
    next = object_rows[object_rows!=object_num]
    ans = mem_ans(ans, object_num, next)
    object_nums.extend(next)

if 0 in set(ans):
  print('No')
else:
  print('Yes')
  for i in ans:
    print(i)

### FIXED CODE ###

import networkx as nx
room, route_count = map(int,input().split())
route = [list(map(int,input().split())) for _ in range(route_count)]

G = nx.Graph()
G.add_nodes_from(range(1,room+1))
G.add_edges_from(route)
pre = nx.predecessor(G, 1)

print('Yes')
for i in range(2,room+1):
  print(pre[i][0])
### BUGGY CODE ###

from collections import Counter
from functools import reduce
import bisect
import random
import fractions
import math
# import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # Greatest Common Divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # Least Common Multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n, v, c = II(), LI(), LI()
# n = 20
# v = [random.random()* 100 for i in range(20)]
# c = [random.random()* 100 for i in range(20)]
y = 0
maxi = -INF
start = time.time()
for i in range(2 ** n):
    x = 0
    y = 0
    for j in range(n):
        if i >> j & 1:
            x += v[j]
            y += c[j]
    maxi = max(maxi, x - y)

# print(time.time() - start)
print(maxi)


### FIXED CODE ###

from collections import Counter
from functools import reduce
import bisect
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # Greatest Common Divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # Least Common Multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n = II()
v = LI()
c = LI()
xy = [v[i] - c[i] for i in range(n)]
print(sum([ xy[i] for i in range(n) if xy[i] > 0]))
### BUGGY CODE ###

from itertools import permutations, tee
import numpy as np

n = int(input())
pos = [np.array(list(map(int, input().split()))) for _ in range(n)]

def pairwise(itr):
    a, b = tee(itr)
    next(b, None)
    return zip(a, b)

dist = np.array([])
for p in permutations(pos):
    d = 0
    for i, j in pairwise(p):
        d += np.linalg.norm(i-j)
    dist = np.append(dist, d)
print(np.mean(dist))


### FIXED CODE ###

n = int(input())
pos = [list(list(map(int, input().split()))) for _ in range(n)]

dst = 0
for i in range(n-1):
    for j in range(i+1, n):
        dst += ((pos[i][0]-pos[j][0])**2 + (pos[i][1]-pos[j][1])**2)**(1/2)
print(dst*2/n)
### BUGGY CODE ###

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

s = X()
s = deque(s)
q = k()
for i in range(q):
    i = L()
    if i[0]=="1":
        s.reverse()
        continue
    d = deque(i)
    a = d.popleft()
    if a == 1:
        pass
    else:
        b = d.popleft()
        c = d.popleft()
        if b == "1":
            s.insert(0,c)
        else:
            s.append(c)

print("".join(s))


### FIXED CODE ###

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

s = deque(X())
n = k()
normal = 0
for i in range(n):
  a = input().split()
  if int(a[0]) == 1:
    normal ^= 1
  else:
    k = int(a[1]) - 1
    k ^= normal
    if k == 1:
      s.append(a[2])
    else:
      s.appendleft(a[2])
print(''.join(s) if normal == 0 else ''.join(list(s)[::-1]))
### BUGGY CODE ###

def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            if i+t < n:
                v = dp[i]+abs(stones[i]-stones[i+t])
                if dp[i+t] > v:
                    dp[i+t] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    h = tuple(map(int, input().split()))
    INF = 10 ** 9
    dp = [INF] * n
    dp[0] = 0
    for i in range(n):
        for j in range(1, k + 1):
            i_j = i + j
            if i_j < n:
                x = dp[i] + abs(h[i] - h[i_j])
                if dp[i_j] > x:
                    dp[i_j] = x
    print(dp[-1])


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

import sys
import heapq
input = sys.stdin.readline

def solve():
    N, M = map(int, input().split())
    abl = [0] * N
    for i in range(N):
        abl[i] = list(map(int, input().split()))
        abl[i][1] *= -1
    
    ans = 0
    hq = []
    hq_hash = []
    for i in range(1, M+1):
        for j in range(N):
            if abl[j][0] <= i and j not in hq_hash:
                heapq.heappush(hq, abl[j][1])
                hq_hash.append(j)
        if len(hq) > 0:
            ans += -heapq.heappop(hq)
    
    print(ans)

if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
import heapq
input = sys.stdin.readline

def solve():
    N, M = map(int, input().split())
    jobs = [[] for _ in range(M)]
    for i in range(N):
        a, b = map(int, input().split())
        if a - 1 < M:
            jobs[a-1].append(-b)
    
    ans = 0
    hq = []
    for i in range(M):
        for job in jobs[i]:
            heapq.heappush(hq, job)
        if len(hq) > 0:
            ans += -heapq.heappop(hq)
    
    print(ans)

if __name__ == '__main__':
    solve()
### BUGGY CODE ###

#!/usr/bin/env python3
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))

before = 1

for i in range(K, 0, -1):
    before *= A[K-i]
for i in range(K, N):
    after = (before//A[i-K])*A[i]
    if before < after:
        print('Yes')
    else:
        print('No')
    before = copy.deepcopy(after)




### FIXED CODE ###

#!/usr/bin/env python3
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))

before = 0
for i in range(K, 0, -1):
    before += A[K-i]
for i in range(K, N):
    after = (before-A[i-K])+A[i]
    if before < after:
        print('Yes')
    else:
        print('No')
    before = copy.deepcopy(after)
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    a[a.index(max(a))] //= 2
print(sum(a))

### FIXED CODE ###

import heapq
n, m = map(int, input().split())
a = [-int(i) for i in input().split()]
heapq.heapify(a)
for _ in range(m):
    mx = -heapq.heappop(a)
    heapq.heappush(a, -(mx // 2))
print(-sum(a))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from sys import stdin
from bisect import bisect_left

d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

N = d_in()
A_list = ds_in()
A_list.sort()

ans = 0
while len(A_list) > 1:
    max_a = A_list.pop()
    order = len(bin(max_a)) - 3
    if max_a == (1 << order) == A_list[-1]:
        del A_list[-1]
        ans += 1
    else:
        cand = (1 << (order+1)) - max_a
        idx = bisect_left(A_list, cand)
        if (idx < len(A_list)) and (cand == A_list[idx]):
            del A_list[idx]
            ans += 1

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
from collections import Counter

d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

N = d_in()
A_list = np.array(ds_in())
A_list.sort()
EPSILON = 10**(-6)

cand_A = 2 ** (np.log2(A_list + EPSILON).astype(int) + 1) - A_list
idx = np.searchsorted(A_list, cand_A)
A_count = dict(Counter(A_list))

ans = 0
for i in range(N-1, -1, -1):
    if A_count[A_list[i]] <= 0:
        continue
    A_count[A_list[i]] -= 1
    if (A_list[idx[i]] == cand_A[i]) and (A_count[cand_A[i]] > 0):
        ans += 1
        A_count[cand_A[i]] -= 1

print(ans)