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

import sys
input=sys.stdin.readline

def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=[0]*40
    p=[1]*40
    for i in range(39):
        p[i+1]=p[i]*2
    for i in a:
        for j in range(40):
            if i&p[j]>0:
                b[j]+=1
    ans=0
    for i in range(k+1):
        kai=0
        for j in range(40):
            if i&p[j]==0:
                kai+=b[j]*p[j]
            else:
                kai+=(n-b[j])*p[j]
        ans=max(ans,kai)
    print(ans)
if __name__=='__main__':
    main()

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
a=[0]*42
for i in range(n):
    p=l[i]
    j=0
    while p>0:
        a[j]+=p%2
        p=p//2
        j+=1
ans=0
for i in range(41,-1,-1):
    if a[i]<n-a[i]:
        if k>=2**i:
            k-=2**i
            ans+=(2**i)*(n-a[i])
        else:
            ans+=(2**i)*a[i]
    else:
        ans+=(2**i)*a[i]
print(ans)
### BUGGY CODE ###

import sys

input = sys.stdin.buffer.readline

n, k = map(int, input().split())

max_n = 300000
num = 1 << ((max_n - 1).bit_length())
SEG = [0] * (2 * num)

func = max
ele = 0


def update(idx, val):
    idx += num
    SEG[idx] = val
    for i in reversed(range(1, num)):
        SEG[i] = func(SEG[2 * i], SEG[2 * i + 1])


def query(left, right):
    res_left = ele
    res_right = ele
    left += num
    right += num
    while left < right:
        if left & 1:
            res_left = func(res_left, SEG[left])
            left += 1
        if right & 1:
            right -= 1
            res_right = func(SEG[right], res_right)
        left //= 2
        right //= 2
    return func(res_left, res_right)


for _ in range(n):
    val = int(input())
    temp = query(max(0, val - k), min(max_n + 1, val + k + 1))
    temp += 1
    update(val, temp)


print(SEG[1])



### FIXED CODE ###

import sys

input = sys.stdin.buffer.readline


class SegmentTree:
    ele = 0
    func = max
    # SEG木は1-index
    # Aに関しては0-index

    def __init__(self, n):  # Aは0-idx
        self.n = n
        self.num = 2 ** ((self.n - 1).bit_length())
        self.SEG = [self.ele] * (2 * self.num)

    def search(self, idx):
        return self.SEG[idx + self.num]

    def initialize(self, A):
        for i in range(self.n):
            self.SEG[i + self.num] = A[i]
        for i in range(self.num - 1, 0, -1):
            self.SEG[i] = self.func(self.SEG[2 * i], self.SEG[2 * i + 1])

    # 1点更新
    def set(self, idx, val):
        idx += self.num
        self.SEG[idx] = val
        idx //= 2
        while idx:
            self.SEG[idx] = self.func(self.SEG[2 * idx], self.SEG[2 * idx + 1])
            idx //= 2

    # 区間取得
    def query(self, left, right):
        # 開区間
        resleft = self.ele
        resright = self.ele
        left += self.num
        right += self.num
        while right - left > 0:
            if left % 2 == 1:
                resleft = self.func(resleft, self.SEG[left])
                left += 1
            if right % 2 == 1:
                right -= 1
                resright = self.func(resright, self.SEG[right])
            left //= 2
            right //= 2
        return self.func(resleft, resright)


n, k = map(int, input().split())
ans = 0
ST = SegmentTree(3000001)
for _ in range(n):
    val = int(input())
    lower = val - k
    lower = max(lower, 0)
    upper = val + k
    upper = min(upper, 3000000)
    temp = ST.query(lower, upper + 1) + 1
    ST.set(val, temp)
    ans = max(ans, temp)
print(ans)
### BUGGY CODE ###

from collections import deque
n = int(input())
q = deque(maxlen=n-1)

for i in range(n - 1):
    a, b, c = map(int, input().split())
    q.append([a-1, b-1, c])

cllist = [-1] * n
a, b, c = q.popleft()
cllist[a] = 0
cllist[b] = c % 2
while q:
    a, b, c = q.popleft()
    if cllist[a] != -1:
        cllist[b] = (cllist[a] + c) % 2
    elif cllist[b] != -1:
        cllist[a] = (cllist[b] + c) % 2
    else:
        q.append([a, b, c])
for i in cllist:
    print(i)


### FIXED CODE ###

from collections import deque
n = int(input())
q = deque(maxlen=n-1)

for i in range(n - 1):
    a, b, c = map(int, input().split())
    q.append([a-1, b-1, c % 2])

cllist = [-1] * n
a, b, c = q.popleft()
cllist[a] = 0
cllist[b] = c
while q:
    a, b, c = q.popleft()
    if cllist[a] != -1:
        cllist[b] = (cllist[a] + c) % 2
    elif cllist[b] != -1:
        cllist[a] = (cllist[b] + c) % 2
    else:
        q.append([a, b, c])
print(*cllist)
### BUGGY CODE ###

def main():
    s = [input() for l in range(2)]
    N, A = int(s[0]), [int(x) for x in s[1].split()]
    results = []

    for i in range(0, (N), 1):
        flag = 0
        for j in range(0, (N), 1):
            if i == j:
                pass
            else:
                if A[i] % A[j] == 0:
                    flag = 1
                    break
                else:
                    pass
        if flag == 1:
            results.append(0)
        else:
            results.append(1)
    cnt = 0
    for x in results:
        if x == 1:
            cnt += 1
    print(cnt)



if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    s = [input() for l in range(2)]
    N, A = int(s[0]), [int(x) for x in s[1].split()]
    """
    results = []

    for i in range(0, (N), 1):
        flag = 0
        for j in range(0, (N), 1):
            if i == j:
                pass
            else:
                if A[i] % A[j] == 0:
                    flag = 1
                    break
                else:
                    pass
        if flag == 1:
            results.append(0)
        else:
            results.append(1)
    cnt = 0
    for x in results:
        if x == 1:
            cnt += 1
    print(cnt)
    """
    # 最大値
    maxA = max(A)
    # 要素の個数を管理
    C = {a: 0 for a in A}
    # 同じ要素が複数ある時点で必ず割り切れる
    # c[a] > 1なら無視できるよ
    for a in A:
        C[a] += 1
    # D
    D = {a: 0 for a in A}
    for a in A:
        if C[a] > 0:
            t = 2
            while a * t <= maxA:
                D[a*t] = 1
                t+= 1

    ans = 0
    for a in A:
        # 重複なし&約数なし
        if C[a] == 1 and D[a] == 0:
            ans += 1
    print(ans)



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

#!/usr/bin/env python3

S = str(input())
Q = int(input())
# print(S, Q)

S_copy = S
for i in range(Q):
    query = list(input().split())
    # print(query)
    if int(query[0]) == 1:
        # print("reverse")
        # Sを反転
        S_copy = S_copy[::-1]
    else:
        if int(query[1]) == 1:
            # Sの先頭にC_iを追加
            # print("prepend C_i")
            S_copy = query[2] + S_copy
        else:
            # Sの末尾にC_iを追加
            # print("append C_i")
            S_copy = S_copy + query[2]

print(S_copy)


### FIXED CODE ###

#!/usr/bin/env python3

from collections import deque

S = str(input())
Q = int(input())
# print(S, Q)

is_reverse = False

d = deque()
d.append(S)
# print(d)

for i in range(Q):
    query = list(input().split())
    # print(query)
    if int(query[0]) == 1:
        # print("reverse")
        # Sを反転
        is_reverse = not is_reverse
    else:
        if int(query[1]) == 1:
            # Sの先頭にC_iを追加
            if is_reverse:
                d.append(query[2])
            else:
                d.appendleft(query[2])
        else:
            # Sの末尾にC_iを追加
            if is_reverse:
                d.appendleft(query[2])
            else:
                d.append(query[2])

if is_reverse:
    print("".join(d)[::-1])
else:
    print("".join(d))
### BUGGY CODE ###

n = int(input())
ai = [int(i) for i in input().split()]

ans = 1

for i in range(n):
    ans *= ai[i]
    
if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
ai = [int(i) for i in input().split()]

ans = 1

ai.sort(reverse=True)

if ai[n-1] == 0:
    print(0)
    exit()

for i in range(n):
    ans *= ai[i]
    if ans > 10**18:
        print(-1)
        exit()
    
print(ans)
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
ans  =2*10**9
for i in range(1, N):
    ans = min(ans, abs(sum(a[:i])-sum(a[i:])))
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
sunu = sum(a)
arai = 0
ans = 2*10**9
for i in range(n-1):
  sunu -= a[i]
  arai +=  a[i]
  ans = min(ans,abs(sunu-arai))
  
print(ans)
### BUGGY CODE ###

import fractions
import functools

MOD = 10**9+7

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
def arr(lis):
    return functools.reduce(lcm, lis)

n = int(input())
a = [int(_) for _ in input().split()]
LCM = arr(a)

arr = [0] * n
for i in range(n):
    arr[i] = LCM // a[i]
print(sum(arr) % MOD)

### FIXED CODE ###

from fractions import gcd
from functools import reduce

MOD = 1000000007

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

n = int(input())
a = [int(_) for _ in input().split()]
LCM = reduce(lcm, a)

arr = [LCM // _ for _ in a]
print(sum(arr) % MOD)
### BUGGY CODE ###

n, a, b = [int(i) for i in input().split()]

def cmb(n, r, mod):
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = n+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

total = 2**n - 1

at = cmb(n,a,mod)
bt = cmb(n,b,mod)

result = total - at - bt
result %= mod
if result < 0:
  result += mod
print(result)

### FIXED CODE ###

n, a, b = [int(i) for i in input().split()]
mod = 10**9 + 7

total = (2**n - 1) % mod
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

at = combination(n,a)
bt = combination(n,b)

result = total - at - bt
result %= mod
if result < 0:
  result += mod
print(result)
### BUGGY CODE ###

import numpy as np

N = int(input())
A = sorted([int(i) for i in input().split()])
A = np.array(A)

ans = 0
while len(A) > 1:
    if A[0] != A[1]:
        ans += 1
    n = A[0]
    A = A[np.where(A % n != 0)[0]]
    
if len(A) == 1:
    print(ans+1)
else:
    print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
num = set(A)
count = Counter(A)
dp = [True] * (10**6 + 1)

for a in num:
    for n in range(a+a, 10**6+1, a):
        dp[n] = False

ans = 0
for a in num:
    if count[a] == 1 and dp[a] == True:
        ans += 1

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

import numpy as np
A, B, N= map(int, input().split())
max=0

for i in range(N):
    x=i+1
    f=np.math.floor(A*x/B)-A*np.math.floor(x/B)
    if max<f:
        max=f
print(max)


### FIXED CODE ###

A,B,N=map(int,input().split())
if N+1>=B:
    T=int(A*(B-1)/B)
    print(T)
else:
    T=int(A*N/B)
    print(T)
### BUGGY CODE ###

N,M=map(int,input().split())
mod=10**9+7

from math import factorial
from collections import Counter

def soinsuu(n):
    list_=[]
    while(n!=1):
        for i in range(2,int(n**0.5)+1):
            if n%i==0:
                list_.append(i)
                n=n//i
                break
        else:
            list_.append(n)
            n=1
    return sorted(list_)

def product(a):
    pro=1
    for b in a:
        pro=pro*b%mod
    return pro

#n!,nPr,nCrの高速計算
def n_func(n,mod=10**9+7):
    ans=1
    for i in range(1,n+1):
        ans=(ans*i)%mod
    return ans
def inv_n(n,mod=10**9+7):
    return pow(n,mod-2,mod)
def nPr(n,r,mod=10**9+7):
    ans=n_func(n-r,mod)
    ans=inv_n(ans,mod)
    return ans*n_func(n,mod)%mod

def dp(cur,init,seq,lest,num):
    if cur==N:
        if lest==0:
            cnt=sorted(list(Counter(seq).values()),reverse=True)
            bunbo=product(map(factorial,cnt[1:]))
            memo[num]=(memo[num]+nPr(sum(cnt),sum(cnt[1:]),mod)*inv_n(bunbo))%mod
    elif lest==0:
        dp(N,init,seq+[0]*(N-cur),0,num)
    else:
        for i in range(1,lest+1):
            if cur==0:
                dp(cur+1,init,seq+[i],lest-i,num)
            elif i<=seq[-1]:
                dp(cur+1,init,seq+[i],lest-i,num)

p=list(Counter(soinsuu(M)).values())
memo=[0]*len(p)

for i in range(len(p)):
    dp(0,p[i],[],p[i],i)
print(product(memo))

### FIXED CODE ###

N,M=map(int,input().split())
mod=10**9+7
 
from math import factorial
from collections import Counter
 
def soinsuu(n):
    list_=[]
    while(n!=1):
        for i in range(2,int(n**0.5)+1):
            if n%i==0:
                list_.append(i)
                n=n//i
                break
        else:
            list_.append(n)
            n=1
    return sorted(list_)
 
def product(a):
    pro=1
    for b in a:
        pro=pro*b%mod
    return pro
 
#n!,nPr,nCrの高速計算
def n_func(n,mod=10**9+7):
    ans=1
    for i in range(1,n+1):
        ans=(ans*i)%mod
    return ans
def inv_n(n,mod=10**9+7):
    return pow(n,mod-2,mod)
def nPr(n,r,mod=10**9+7):
    ans=n_func(n-r,mod)
    ans=inv_n(ans,mod)
    return ans*n_func(n,mod)%mod
    
nPr_list=[nPr(N,i) for i in range(30)]
bunbo_list=dict()

def dp(cur,init,seq,lest,num):
    #print(cur,init,seq,lest,num)
    if cur==N:
        if lest==0:
            cnt=sorted(list(Counter(seq).values())+[N-len(seq)],reverse=True)
            bunbo=product(map(factorial,cnt[1:]))
            if bunbo not in bunbo_list.keys():
                bunbo_list[bunbo]=inv_n(bunbo)
            memo[num]=(memo[num]+nPr_list[N-cnt[0]]*bunbo_list[bunbo])%mod
    elif lest==0:
        dp(N,init,seq,0,num)
    else:
        if cur==0:
            for i in range(1,lest+1):
                dp(cur+1,init,seq+[i],lest-i,num)
        else:
            for i in range(1,min(lest,seq[-1])+1):
                dp(cur+1,init,seq+[i],lest-i,num)
 
p=list(Counter(soinsuu(M)).values())
memo=[0]*len(p)


for i in range(len(p)):
    dp(0,p[i],[],p[i],i)
print(product(memo))
### BUGGY CODE ###

from statistics import median
n = int(input())
x = [int(i) for i in input().split()]
sortedx = sorted(x)
med = (n-1)//2
for i in x:
    tmp = sortedx[:]
    tmp.remove(i)
    print(tmp[med])


### FIXED CODE ###

n = int(input())
X = [int(i) for i in input().split()]
sX = sorted(X)
r,l = sX[n//2],sX[n//2-1]
if r != l:
    for x in X:
        if x<=l: print(r)
        else: print(l)
else:
    for _ in range(n): print(l)
### BUGGY CODE ###

n=int(input())
list=[""]*n
number=0
already=[]
bad=0
for i in range(n):
  list[i]=input()
  for j in range(len(already)):
    if list[i]==already[j]:
      bad=1
      break
  if bad==0:
    number+=1
    already.append(list[i])
  bad=0
print(number)

### FIXED CODE ###

n=int(input())
list=[]
for i in range(n):
  list.append(input())
print(len(set(list)))
### BUGGY CODE ###

N = int(input())
S = input()
sum = 0

R = []
B = []
G = []
p = 0
for i in S:
    if(i == "R"):
        R.append(p)
    elif(i == "B"):
        B.append(p)
    elif(i == "G"):
        G.append(p)
    p += 1
for r in R:
    for b in B:
        rb = abs(r - b)
        for g in G:
            rg = abs(r - g)
            bg = abs(b - g)
            if(rb==rg or rg==bg or bg==rb):
                continue
            else:
                sum += 1

print(sum)

### FIXED CODE ###

N = int(input())
S = input()


R = []
B = []
G = []
p = 0
for i in S:
    if(i == "R"):
        R.append(p)
    elif(i == "B"):
        B.append(p)
    elif(i == "G"):
        G.append(p)
    p += 1
R = set(R)
B = set(B)
G = set(G)
sum = len(R) * len(B) * len(G)
for r in R:
    for b in B:
        up = max(r, b)
        dw = min(r, b)
        d = up-dw
        if up + d in G:
            sum -= 1
        if dw - d in G:
            sum -= 1
        if (r+b)/2 in G:
            sum -= 1

print(sum)
### BUGGY CODE ###

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

MAX = 1e9

def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    link = [[MAX if j != i else 0 for j in range(N+1)] for i in range(N+1)]

    for i in range(M):
        a, b, c = map(int, input().split())
        link[a][b] = c
        link[b][a] = c

    for i in range(N+1):
        for j in range(N+1):
            for k in range(N+1):
                link[j][k] = min(link[j][k], link[j][i] + link[i][k])

    ans = MAX
    for per in list(itertools.permutations(r)):
        tmp = 0
        for i in range(R-1):
            tmp += link[per[i]][per[i+1]]
        ans = min(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque
import itertools
from scipy.sparse.csgraph import floyd_warshall as wf
import sys
input = sys.stdin.readline

MAX = 1e9

def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    link = [[MAX if j != i else 0 for j in range(N+1)] for i in range(N+1)]

    for i in range(M):
        a, b, c = map(int, input().split())
        link[a][b] = c
        link[b][a] = c

    link = wf(link)

    ans = MAX
    for per in list(itertools.permutations(r)):
        tmp = 0
        for i in range(R-1):
            tmp += link[per[i]][per[i+1]]
        ans = min(ans, tmp)
    print(int(ans))

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

from math import ceil,floor,comb,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, n = MAP()
a = [0]*n
b = [0]*n
dp = [inf]*(h+1)
dp[0] = 0
# dp[j]: ダメージ>=jとするために必要な魔力の最小値

for i in range(n):
    a[i], b[i] = MAP()

for i in range(n):
    for j in range(0,h+1):
        if j < a[i]:
            dp[j] = min(dp[j], b[i])
        else:
            dp[j] = min(dp[j], dp[j-a[i]]+b[i])

print(dp[h])

### FIXED CODE ###

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, n = MAP()
a = [0]*n
b = [0]*n
dp = [inf]*(h+1)
dp[0] = 0
# dp[j]: ダメージ>=jとするために必要な魔力の最小値

for i in range(n):
    a[i], b[i] = MAP()

for i in range(n):
    for j in range(0,h+1):
        if j < a[i]:
            dp[j] = min(dp[j], b[i])
        else:
            dp[j] = min(dp[j], dp[j-a[i]]+b[i])

print(dp[h])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = list(map(int, input().split()))
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  while stack:
    v = stack[-1]
    marker = 0
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u]=v
        stack.append(u)
      else: #子から吸い上げる
        ans[v] *= ans[u]+1
    if marker==0:
      stack.pop()
  return ans

def dfs2(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  while stack:
    v = stack.pop()
    for u in edge[v]:
      if u==parent[v]:
        continue
      parent[u]=v
      ans[u] *= (ans[v] // (ans[u]+1))+1
      stack.append(u)
    ans[v] %= M
  return ans

ans = [1]*N
dfs(0)
dfs2(0)
print(*ans, sep='\n')

### FIXED CODE ###

import sys,os,io
input = sys.stdin.readline
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = list(map(int, input().split()))
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  while stack:
    v = stack[-1]
    marker = 0
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u]=v
        stack.append(u)
      else: #子から吸い上げる
        ans[v] *= ans[u]+1
        ans[v] %=M
    if marker==0:
      stack.pop()
  return

def dfs2(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  p_value = [0]*N
  while stack:
    v = stack.pop()
    cum1 = [1]*(len(edge[v])+1)
    cum2 = [1]*(len(edge[v])+1)
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        cum1[i+1] = cum1[i]*(p_value[v]+1)%M
      else:
        cum1[i+1] = cum1[i]*(ans[u]+1)%M
    for i,u in enumerate(edge[v][::-1]):
      if u==parent[v]:
        cum2[-i-2] = cum2[-i-1]*(p_value[v]+1)%M
      else:
        cum2[-i-2] = cum2[-i-1]*(ans[u]+1)%M
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        continue
      parent[u]=v
      p_value[u] = cum1[i]*cum2[i+1]%M
      ans[u] *= (p_value[u]+1)
      ans[u] %= M
      stack.append(u)
    ans[v] %= M
  return

ans = [1]*N
dfs(0)
dfs2(0)
print(*ans, sep='\n')
### BUGGY CODE ###

import numpy as np

N = int(input())
A = []
B = []
for _ in range(N):
    s = input().split()
    A.append(int(s[0]))
    B.append(int(s[1]))

def list_add(in1, in2):
    wrk = np.array(in1) + np.array(in2)
    return wrk.tolist()

C = list_add(A, B)

ind = 0

a_happy = 0
b_happy = 0

for i in range(N):
    if i%2 == 0:
        ind = C.index(max(C))
        a_happy += A[ind]
        A.pop(ind)
        B.pop(ind)
        C.pop(ind)
    if i%2 == 1:
        ind = C.index(max(C))
        b_happy += B[ind]
        A.pop(ind)
        B.pop(ind)
        C.pop(ind)

print(a_happy - b_happy)


### FIXED CODE ###

import numpy as np

N = int(input())
C = []
for _ in range(N):
    a, b = map(int, input().split())
    C.append([a+b, a, b])

D = sorted(C, reverse=True)

ans = 0

for i in range(N):
    if i % 2 == 0:
        ans += D[i][1]
    elif i % 2 == 1:
        ans -= D[i][2]

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

from fractions import gcd

k = int(input())
cnt = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            d = gcd(a+1,b+1)
            cnt = cnt + gcd(d,c+1)
print(cnt)


### FIXED CODE ###

n = int(input())
n1 = n//10
n2 = n1//10
if n%10 == 7 or n1%10 == 7 or n2%10 == 7:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

n, k = map(int, input().split())
array = []
for i in range(n):
   a, b = map(int, input().split())
   array.extend([a for _ in range(b)])

array.sort()
print(array[k-1])


### FIXED CODE ###

n, k = map(int, input().split())

x = [0 for _ in range(0, 100001)]

for i in range(n):
   a, b = map(int, input().split())
   x[a] += b

l = 0
for i in range(1, 100001):
   if (l < k and (l + x[i]) >= k ):
      print(i)
      exit()

   l += x[i]