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

n, k, q = map(int, input().split())
points = [k] * n


for _ in range(q):
    win = int(input())
    points = [p-1 for p in points]
    points[win-1] += 1

winner_point = max(points)
winners = [i for i in range(n) if points[i] == winner_point]
for i in range(n):
    if i in winners or points[i] >= 1:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

n, k, q = map(int, input().split())
points = [k] * n


for _ in range(q):
    win = int(input())
    points[win-1] += 1

points = [p-q for p in points]
for i in points:
    if i >= 1:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

def main():
    # 入力
    n = int(input())

    min_l = 10

    for i in range(1, n+1):
        if n % i != 0:
            continue
        j = int(n / i)

        il = len(str(i))
        jl = len(str(j))
        f = max(il, jl)
        if f < min_l:
            min_l = f
        if il > min_l or il == jl or il > jl:
            break

    print(min_l)


main()


### FIXED CODE ###

def main():
    # 入力
    s = input()

    x = len(s)
    limit = int(x/2)+1 if x % 2 == 0 else int(x/2)+2
    limit2 = int(x/2) if x % 2 == 0 else int(x/2)+1

    n = int(s)

    min_l = 11

    # ccc = 0
    for i in range(1, n+1):
        # ccc += 1
        il = len(str(i))
        if il == limit:
            break
        if n % i != 0:
            continue
        if il == min_l:
            break
        j = int(n / i)

        jl = len(str(j))
        f = max(il, jl)
        if f < min_l:
            min_l = f
        if jl == limit2 or il == jl or il > jl:
            break


    # print(ccc)
    print(min_l)


main()
### BUGGY CODE ###

import itertools
n,m,x = map(int, input().split())
book = []
for i in range(n):
  b = list(map(int, input().split()))
  book.append(b)

junretu = itertools.permutations(range(n))
min_nedan = 10**9
for j in junretu:
  count_list = [0]*m
  nedan = 0
  for b in j:
    naiyou = book[b]
    nedan += naiyou[0]
    for i in range(1, m+1):
      count_list[i-1] += naiyou[i]
    if min(count_list)>=x:
      break
  else:
    print(-1)
    exit()
  if nedan < min_nedan:
    min_nedan = nedan
print(min_nedan)
  

### FIXED CODE ###

import itertools
n,m,x = map(int, input().split())
book = []
for i in range(n):
  b = list(map(int, input().split()))
  book.append(b)
book = sorted(book, key=lambda x:x[0])
junretu = itertools.permutations(range(n))
max_ = 2**n
min_nedan = 10**9
for j in range(max_):
  bit = format(j, "0"+str(n)+"b")
  count_list = [0]*m
  nedan = 0
  for b in range(n):
    if bit[b] == "1":
      naiyou = book[b]
      nedan += naiyou[0]
      for i in range(1, m+1):
        count_list[i-1] += naiyou[i]
  if min(count_list)>=x:
    if nedan < min_nedan:
      min_nedan = nedan
if min_nedan == 10**9:
  print(-1)
else:
  print(min_nedan)
### BUGGY CODE ###

import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    L, R = il()
    ret = 2019
    for i in range(L, R+1):
        for j in range(i + 1, R + 1):
            ret = min(ret, (i * j) % 2019)
            if ret == 0:
                break
    else:
        print(ret)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os

MOD = 2019


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    L, R = list(map(int, sys.stdin.readline().split()))
    ret = float('inf')

    if R - L >= 2019:
        print(0)
        exit()

    for i in range(L, R+1):
        for j in range(i+1, R+1):
            ret = min(ret, (i * j) % MOD)

    print(ret)


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

def f(a, b):
    str_a = str(a)
    len_a = len(str_a)
    str_b = str(b)
    len_b = len(str_b)

    return len_a if len_a > len_b else len_b

N = int(input())

min = 10**10
for i in range(1, 10 ** len(str(N))//2):
    a = i
    if N % a == 0:
        b = int(N / a)
    else:
        continue

    if len(str(a)) > len(str(N)) // 2 + 1:
        break

    ret = f(a, b)
    if min > ret:
        min = ret

print(min)


### FIXED CODE ###

def f(a, b):
    str_a = str(a)
    len_a = len(str_a)
    str_b = str(b)
    len_b = len(str_b)

    return len_a if len_a > len_b else len_b

N = int(input())

min = 10**10
max_iter = 10 ** (len(str(N))//2 + 1)

for i in range(1, max_iter):
    a = i
    if N % a == 0:
        b = int(N / a)
    else:
        continue

    ret = f(a, b)
    if min > ret:
        min = ret
        if min <= len(str(N))//2:
            break

print(min)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
    ex = a.pop(i)
    print(max(a))
    a.insert(i, ex)

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]

comp = sorted(a, reverse = True)

Fmax = comp[0]
Smax = comp[1]

for i in range(n):
    if a[i] == Fmax:
        print(Smax)
    
    else:
        print(Fmax)
### BUGGY CODE ###

N, K = map(int, input().split())
ans = 0
if K % 2 != 0:
    M = [a for a in range(0, N+1, K)]
    M.pop(0)
else:
    M = [a for a in range(0, N+1, K//2)]
    M.pop(0)
for a in M:
    for b in M:
        if (a + b) % K != 0:
            continue
        for c in M:
            if ((a + c) % K != 0) or ((b + c ) % K != 0):
                continue
            ans += 1
print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
ans = 0
M1 = []
M2 = []
M1 = [a for a in range(N+1) if a % K == 0]
M1.pop(0)
if K % 2 == 0:
    M2 = [a for a in range(N+1) if a % K == K//2]
print(len(M1)**3 + len(M2)**3)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
A = [list(map(lambda x: int(x)-1, input().split())) for _ in range(N)]
ans = 0
while any(A):
    ok = False
    used = []
    for i in range(N):
        a = A[i]
        if not a or i in used:
            continue
        j = a[0]
        b = A[j]
        if not b or j in used:
            continue
        if i == b[0]:
            ok = True
            A[i].pop(0)
            A[j].pop(0)
            used.append(i)
            used.append(j)
    if not ok:
        print(-1)
        exit()
    ans += 1
print(ans)


### FIXED CODE ###

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


def main():
    N = int(input())
    A = [deque(map(lambda x: int(x)-1, input().split())) for _ in range(N)]
    ans = 0
    used_prev = set(range(N))
    while any(A):
        used = set()
        for i in used_prev:
            a = A[i]
            if not a or i in used:
                continue
            j = a[0]
            b = A[j]
            if not b or j in used:
                continue
            if i == b[0]:
                A[i].popleft()
                A[j].popleft()
                used.add(i)
                used.add(j)
        if not used:
            ans = -1
            break
        used_prev = used
        ans += 1
    print(ans)


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

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = bin(a[i])
    a[i] = a[i][2:]
ans = n
for i in range(n-1):
    flag = 1
    b = list(a[i])
    j = i+1
    while flag == 1 and j < n:
        if len(b) < len(a[j]):
            b = ["0"]*(len(a[j])-len(b))+b
        for k in range(min(len(b), len(a[j]))):
            if b[len(b)-k-1] == "1" and a[j][len(a[j])-k-1] == "1":
                flag = -1
                break
            elif a[j][len(a[j])-k-1] == "1":
                b[len(b)-k-1]="1"
        if flag == 1:
            ans += 1
        j += 1
print(ans)

### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n = I()
    a = LI()
    ans = 0
    l = 0
    r = 0
    s = 0
    while l < n and r < n:
        while s&a[r] == 0:
            s += a[r]
            r += 1
            ans += r-l
            if r == n:break
        if l==r:
            s += a[r]
            r += 1
        s -= a[l]
        l += 1
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()
### BUGGY CODE ###

from bisect import bisect_left as bl
from bisect import bisect_right as br
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    l = [[] for i in range(30)]
    b.sort()
    for i in range(29):
        mod = 2**(i+1)
        for j in b:
            l[i].append(j%mod)
        l[i].sort()

    ans = 0
    for i in range(29):
        al = []
        count = 0
        mod = 2**i
        for j in a:
            al.append(j%(2*mod))
        al.sort(reverse = True)
        r1 = r2 = r3 = 0
        for j in al:
            while r1 < n and l[i][r1]+j < mod:
                r1 += 1
            while r2 < n and l[i][r2]+j < 2*mod:
                r2 += 1
            while r3 < n and l[i][r3]+j < 3*mod:
                r3 += 1
            count += n-r3+r2-r1
        ans += (count%2) << i
    print(ans)

if __name__ =="__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline


n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
l = [[] for i in range(29)]
for i in range(29):
    mod = 2**(i+1)
    for j in b:
        l[i].append(j%mod)
    l[i].sort()

ans = 0
for i in range(29):
    al = []
    count = 0
    mod = 2**i
    for j in a:
        al.append(j%(2*mod))
    al.sort(reverse = True)
    r1 = r2 = r3 = 0
    for j in al:
        while r1 < n and l[i][r1]+j < mod:
            r1 += 1
        while r2 < n and l[i][r2]+j < 2*mod:
            r2 += 1
        while r3 < n and l[i][r3]+j < 3*mod:
            r3 += 1
        count += n-r3+r2-r1
    ans += (count%2) << i
print(ans)
### BUGGY CODE ###

n=input()
a=list(map(int,input().split()))
ans=1
for i in a:
  ans*=i
if ans>10**18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

n=input()
A=list(map(int,input().split()))
ans=1
if A.count(0)==0:
  for i in A:
    ans*=i
    if ans>10**18:
      ans=-1
      break
else:
  ans=0
print(ans)
### BUGGY CODE ###

from math import gcd


def prime_factorize(n):
    a=set()
    while n%2==0:
        a.add(2)
        n //=2
    f=3
    while f**2<=n:
        if n%f==0:
            a.add(f)
            n //=f
        else:f +=2
    if n!=1:a.add(n)
    return a


n=int(input())
A=list(map(int,input().split()))
prime=[True for _ in range(10**6+1)]

flag=0
for i in A:
    for j in prime_factorize(i):
        if prime[j]:
            for k in range(j,10**6+1,j):
                prime[k]=False
        else:
            flag=1
            break
if flag==0:print("pairwise coprime");exit()
line=[0]*n
line[0]=A[0]
for i in range(1,n):
    line[i]=gcd(line[i-1],A[i])
if line[-1]==1:print("setwise coprime");exit()
print("not coprime")


### FIXED CODE ###

from math import gcd


def prime_factorize(n):
    a=set()
    while n%2==0:
        a.add(2)
        n //=2
    f=3
    while f**2<=n:
        if n%f==0:
            a.add(f)
            n //=f
        else:f +=2
    if n!=1:a.add(n)
    return a


n=int(input())
A=list(map(int,input().split()))
prime=[True for _ in range(10**6+1)]

flag=0
for i in A:
    for j in prime_factorize(i):
        if prime[j]:
            for k in range(j,10**6+1,j):
                prime[k]=False
        else:
            flag=1
            break
if flag==0:print("pairwise coprime");exit()
line=[0]*n
line[0]=A[0]
for i in range(1,n):
    line[i]=gcd(line[i-1],A[i])
if line[-1]==1:print("setwise coprime");exit()
print("not coprime")
### BUGGY CODE ###

import itertools
n = int(input())
s = list(input())
ans = 0
idx = [i for i in range(n)]
p = []
for i in list(itertools.permutations(idx, 3)):
    if i[0] < i[1] < i[2]:
        p.append(i)
for a, b, c in p:
    if s[a] == s[b] or s[a] == s[c] or s[b] == s[c]:
        continue
    elif b-a == c-b:
        continue
    else:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = input()

r_count = s.count("R")
g_count = s.count("G")
b_count = s.count("B")
ans = r_count * g_count * b_count

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ans -= 1

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

N,W=map(int,input().split())
w,v=[0]*N,[0]*N

for i in range(N):
    w[i],v[i]=map(int,input().split())
V=sum(v)
dp=[[float('inf')]*(V+1) for i in range(N+1)] #初期化はfor より *の方が早い

dp[0][0]=0
for i in range(N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=dp[i][j-v[i]]+w[i]
        dp[i+1][j]=min(dp[i][j],dp[i+1][j])

for j in range(V+1):
    if dp[N][j]<=W:
        res=j
print(res)


### FIXED CODE ###

N,W=map(int,input().split())
w,v=[0]*N,[0]*N

for i in range(N):
    w[i],v[i]=map(int,input().split())
V=sum(v)
dp=[[float('inf') for i in range(V+1)] for j in range(N+1)]

dp[0][0]=0
for i in range(N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=dp[i][j-v[i]]+w[i]
        dp[i+1][j]=min(dp[i][j],dp[i+1][j])

for j in range(V+1):
    if dp[N][j]<=W:
        res=j
print(res)
### BUGGY CODE ###

N = int(input())
A = []
tmp = 0
for _ in range(N):
    A.append(int(input()))
for i in range(N):
    tmp = A.pop(i)
    print(max(A))
    A.insert(i,tmp)

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
if N == 2:
    for j in A[::-1]:
        print(j)
else:
    tmp = sorted(A)
    del tmp[0:(N-2)]
    for i in range(N):
        if A[i] == tmp[1]:
            print(tmp[0])
        else:
            print(tmp[1])
### BUGGY CODE ###

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

def calc_n_combinations(l):
  ball_unique = set(l)
  sum = 0
  for b in ball_unique:
    n = l.count(b)
    sum += n * (n-1) // 2
  return sum
 
results = []
for i in range(len(balls)):
  tmp = balls.copy()
  tmp.pop(i)
  result = calc_n_combinations(tmp)
  print(result)

### FIXED CODE ###

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

counter = {}
for b in balls:
  counter[b] = counter.get(b, 0) + 1

sum = 0
for v in counter.values():
  sum += v * (v-1) // 2
  
for b in balls:
  n_old = counter[b]
  c_old = n_old * (n_old - 1) // 2
  c_new = (n_old - 1) * (n_old - 2) // 2
  
  result = sum - c_old + c_new
  print(result)
### BUGGY CODE ###

n   = int(input())
li1 = [int(input()) for i in range(n)]
li2 = li1.copy()

for i in range(n):
    li2.remove(li1[i])
    print(max(li2))
    li2.append(li1[i])

### FIXED CODE ###

n   = int(input())
li1 = [int(input()) for i in range(n)]

li2 = li1.copy()
li2.sort(reverse=True)

for i in range(n):
    if li1[i]!=li2[0]:
        print(li2[0])
    else:
        print(li2[1])
### BUGGY CODE ###

def solve(h,w,n,black_list):
  idx_list = []
  for idx, (a,b) in enumerate(black_list):
    left = max(0, b-3)
    top = max(0, a-3)
    for row in range(top, a):
      if row+2 >= h:
        continue
      for col in range(left, b):
        if col+2 >= w:
          continue
        idx_list.append(row*h+col)

  set_count = set(idx_list)
  ans = [0]*len(set_count)
  for idx,i in enumerate(set_count):
    ans[idx] = idx_list.count(i)

  ret = [(h-2)*(w-2)-len(set_count)]
  for i in range(1, 10):
    ret.append(ans.count(i))
  return ret

if __name__ == "__main__":
  h,w,n = map(int,input().split())
  black_list = [tuple(map(int,input().split())) for _ in range(n)]
  ret = solve(h,w,n,black_list)
  for i in ret:
    print(i)


### FIXED CODE ###

def solve(h,w,n,black_list):
  if len(black_list) == 0:
    return [(h-2)*(w-2)]+[0]*9
  idx_list = []
  for idx, (a,b) in enumerate(black_list):
    left = max(0, b-3)
    top = max(0, a-3)
    for row in range(top, a):
      if row+2 >= h:
        continue
      for col in range(left, b):
        if col+2 >= w:
          continue
        idx_list.append(row*w+col)

  set_count = set(idx_list)
  idx_list = sorted(idx_list)

  ans = [0]*9
  now = idx_list[0]
  count = 0
  for item in idx_list:
    if item == now:
      count += 1
    else:
      now = item
      if count == 10:
        print(item)
      ans[count-1] += 1
      count = 1
  ans[count-1] += 1
  return [(h-2)*(w-2)-len(set_count)]+ans


if __name__ == "__main__":
  h,w,n = map(int,input().split())
  black_list = [tuple(map(int,input().split())) for _ in range(n)]
  ret = solve(h,w,n,black_list)
  for i in ret:
    print(i)
### BUGGY CODE ###

import itertools


D, G = map(int, input().split())

P     = [None] * D
C     = [None] * D
count = [None] * D
score = [None] * D

for i in range(D):
    p, c          = map(int, input().split())
    P[i]          = p
    C[i]          = c
    count[i]      = list(range(p+1))
    score[i]      = [100 * (i+1) * j for j in range(p+1)]
    score[i][-1] += c

count = [sum(c) for c in list(itertools.product(*count))]
score = [sum(s) for s in list(itertools.product(*score))]

answer = [count[i] for i in range(len(count)) if score[i] >= G]

print(min(answer))


### FIXED CODE ###

import itertools


D, G = map(int, input().split())

P     = [None] * D
C     = [None] * D
count = [None] * D
score = [None] * D

for i in range(D):
    p, c          = map(int, input().split())
    P[i]          = p
    C[i]          = c
    count[i]      = list(range(p+1))
    score[i]      = [100 * (i+1) * j for j in range(p+1)]
    score[i][-1] += c

answer = sum(P)

for is_complete in itertools.product([True, False], repeat=D):
    score_tmp  = 0
    count_tmp  = 0
    score_tmp += sum([score[i][-1] for i in range(D) if is_complete[i]])
    count_tmp += sum([count[i][-1] for i in range(D) if is_complete[i]])
    if score_tmp < G:
        for i in list(range(D))[::-1]:
            if is_complete[i] == False:
                if (G - score_tmp) % (100 * (i+1)) == 0:
                    count_add  = min((G - score_tmp) // (100 * (i+1)),     P[i] - 1)
                else:
                    count_add  = min((G - score_tmp) // (100 * (i+1)) + 1, P[i] - 1)
                score_add      = 100 * (i+1) * count_add
                count_tmp     += count_add
                score_tmp     += score_add
            if score_tmp >= G:
                break
    if score_tmp >= G:
        answer = min(answer, count_tmp)

print(answer)
### BUGGY CODE ###

n=int(input())
def factor_finder(x):
    fac=0
    for i in range(1,int(x**0.5)+1):
        if x%i==0:
            fac+=2
    if int(x**0.5)==x**0.5:
        fac-=1
    return fac
total=0
for i in range(1,n):
    total+=factor_finder(n-i)
print(total)
        
               


### FIXED CODE ###

c=int(input())
total=c-1
for i in range(2,c):
    total+=(c-1)//i
print(total)
### BUGGY CODE ###

N, K, Q = map(int,input().split())
a = [K] * N
for i in range(Q):
    A = int(input())
    for j in range(N):
        if j != A - 1:
            a[j] -= 1
for i in range(N):
    if a[i] > 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

N, K, Q = map(int,input().split())
a = []
b = [0] * N
for i in range(Q):
    A = int(input())
    a.append(A)

for i in a:
    b[i - 1] += 1
for i in b:
    if i > Q - K:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

n = int(input())
lst = list(map(int, input().split(' ')))
ans = 1
for i in range(0, len(lst)):
  ans *= lst[i]
if ans > 1000000000000000000:
  print("-1")
else:
  print(ans)

### FIXED CODE ###

import sys

if __name__ == "__main__":
    a = int(input())
    n = list(map(int, input().strip().split(' ')))
    ans = 1
    n.sort()
    for i in n:
      ans *= i
      if ans > 10**18:
          break
    if ans > 10**18:
        print(-1)
    else:
        print(ans)
### BUGGY CODE ###

from operator import itemgetter
import bisect


N, Q = map(int, input().split(" "))
check_points = [list(map(int, input().split(" "))) for _ in range(N)]
querys = sorted([int(input()) for i in range(Q)])
time = {}
for q in querys:
    time[q] = 0

check_parsed = []
for s, f, x in sorted(check_points, key=itemgetter(2)):
    start, end = [s-x, f-x]
    left = bisect.bisect_left(querys, start)
    right = bisect.bisect_left(querys, end)
    for q in querys[left:right]:
        if time[q] == 0:
            time[q] = x+1


for q in querys:
    print(time[q]-1)


### FIXED CODE ###

from bisect import bisect_left
from operator import itemgetter

N, Q = map(int, input().split(" "))
check_points = [tuple(map(int, input().split(" "))) for _ in range(N)]
querys = [int(input()) for _ in range(Q)]
time = [-1 for _ in range(Q)]
jump = [-1 for _ in range(Q)]
check_points = sorted(check_points, key=itemgetter(2))
b_left = bisect_left

for line in check_points:
    s, f, x = line
    start = s-x
    end = f-x
    left = b_left(querys, start)
    right = b_left(querys, end)
    while left < right:
        if time[left] == -1:
            time[left] = x
            jump[left] = right
            left += 1
        else:
            left = jump[left]

for t in time:
    print(t)
### BUGGY CODE ###

N, M = map(int,input().split()) # 複数の数字を変数に格納
List = [list(map(int,input().split())) for i in range(N)] # [[1,2],[3,4],[5,6]]

List.sort(key=lambda x: x[1], reverse=True)
List_M = "B" + "A" * M

result = 0

for i in range(N):
    A = List[i][0]
    B = List[i][1]
    p = List_M[A:].find("A")
    if p != -1:
        List_M = List_M[:A+p] + "B" + List_M[A+p+1:]
        result += B

print(result)

### FIXED CODE ###

from operator import itemgetter
import sys
input = sys.stdin.readline

N, M = map(int,input().split()) # 複数の数字を変数に格納
List = [list(map(int,input().split())) for i in range(N)] # [[1,2],[3,4],[5,6]]

List.sort(key=itemgetter(0))
List_S = [0]
 
result = 0
p = 0

for i in range(1, M+1):
    add = 0
    add_list = []
    while p < N and List[p][0] == i:
        if List_S[len(List_S)-1] < List[p][1]:            
            List_S.append(List[p][1])
        else:
            add_list.append(List[p][1])
            add += 1
        p += 1
            
    if len(List_S) != 1:
        result += List_S.pop()
        if add > 0:
            List_S.extend(add_list)
            List_S.sort()
 
print(result)