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

import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# エントリーポイント
def main():
    N, M, P = input([int, 3])
    ABC = input([[int, 3], M])

    # Nから到達できる辺のみ抽出する
    g = nlist([N + 1], [])
    for a, b, _ in ABC:
        g[b] += [a]
    que, rch = [N], {N}
    while que:
        cur = que.pop()
        for nxt in g[cur]:
            if nxt in rch: continue
            rch |= {nxt}
            que.append(nxt)
    edges = [(a, b, c) for a, b, c in ABC if a in rch and b in rch]

    # ベルマンフォード法で負の最短経路(スコアの最大値)を導出する
    g = nlist([N + 1], INF)
    g[1] = 0
    for _ in range(N):
        f = True
        for a, b, c in edges:
            c = -(c - P)
            if g[a] + c < g[b]:
                g[b] = g[a] + c
                f = False
        if f:
            break
    else:
        # 負の閉路を除外する
        print(-1)
        return
    print(max(0, -g[N]))
    return

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# エントリーポイント
def main():
    N, M, P = input([int, 3])
    ABC = input([[int, 3], M])

    # Nから到達できる辺のみ抽出する
    g = nlist([N + 1], [])
    for a, b, _ in ABC:
        g[b] += [a]
    que, rch = [N], {N}
    while que:
        cur = que.pop()
        for nxt in g[cur]:
            if nxt in rch: continue
            rch |= {nxt}
            que.append(nxt)
    edges = [(a, b, c) for a, b, c in ABC if a in rch and b in rch]

    # ベルマンフォード法で負の最短経路(スコアの最大値)を導出する
    g = nlist([N + 1], INF)
    g[1] = 0
    for _ in range(N):
        f = True
        for a, b, c in edges:
            c = -(c - P)
            if g[a] + c < g[b]:
                g[b] = g[a] + c
                f = False
        if f:
            break
    else:
        # 負の閉路を除外する
        print(-1)
        return
    print(max(0, -g[N]))
    return

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()
### BUGGY CODE ###

n, k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
d=sorted([a.count(i) for i in set(a)])[::-1]
if len(d)-k>0: print(len(a)-sum(d[:k]))
else: print("0")


### FIXED CODE ###

n, k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
d={i:0 for i in set(a)}
for i in a: d[i]+=1
print(n-sum([t[1] for t in sorted(d.items(), key=lambda x:-x[1])][:k]))
### BUGGY CODE ###

from bisect import bisect_right
s = input()
n = len(s)
t = input()
m = len(t)
tr = set(s)
for c in t:
  if c not in s:
    print(-1)
    exit(0)
d = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
for i, c in enumerate(s):
  d[c].append(i)
idx = -1
ans = 0
for c in t:
  tmp = bisect_right(d[c], idx)
  if tmp == len(d[c]):
    idx = d[c][0]
    ans += 1
  else:
    idx = d[c][tmp]
print(ans * n + idx + 1)

### FIXED CODE ###

from bisect import bisect_right
s = input()
n = len(s)
t = input()
m = len(t)
tr = set(s)
for c in t:
  if c not in s:
    print(-1)
    exit(0)
d = {c:[] for c in 'abcdefghijklmnopqrstuvwxyz'}
for i, c in enumerate(s):
  d[c].append(i)
idx = -1
ans = 0
for c in t:
  tmp = bisect_right(d[c], idx)
  if tmp == len(d[c]):
    idx = d[c][0]
    ans += 1
  else:
    idx = d[c][tmp]
print(ans * n + idx + 1)
### BUGGY CODE ###

from math import ceil
from itertools import permutations

#S=input()
#D=list(map(int,input().split()))
from heapq import *
"""
import sys
input=sys.stdin.readline
"""
from collections import defaultdict
from fractions import gcd
#S=
from math import sqrt
import sys
sys.setrecursionlimit(100100)

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

n=int(input())
s=int(input())
if s>n:
    print(-1)
    quit()
if s==n :
    print(n+1)
    quit()
def func(b,n):
    res=0
    while(n):
        res+=n%b
        n//=b
    return res
j=1
i=n
ans=10**30
for i in range(2,int(sqrt(n))+1):
    if func(i,n)==s:
        ans=min(ans,i)
for i in range(1,ceil(sqrt(n))):
    b=(n-s)//i+1
    if func(b,n)==s:
        ans=min(ans,b)
if ans==10**30:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

from math import ceil
from itertools import permutations

#S=input()
#D=list(map(int,input().split()))
from heapq import *
"""
import sys
input=sys.stdin.readline
"""
from collections import defaultdict
from fractions import gcd
#S=
from math import sqrt
import sys
sys.setrecursionlimit(100100)

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

n=int(input())
s=int(input())
if s>n:
    print(-1)
    quit()
if s==n :
    print(n+1)
    quit()
def func(b,n):
    res=0
    while(n):
        res+=n%b
        n//=b
    return res
j=1
i=n
ans=10**30
for i in range(2,int(sqrt(n))+1):
    if func(i,n)==s:
        ans=min(ans,i)
l=defaultdict()
for i in range(1,ceil(sqrt(n))):
    b=(n-s)//i+1
    if sqrt(n)<b and n//b+(n%b)==s:
        ans=min(ans,b)
if ans==10**30:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

h,w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
#色が変わるところでコスト
inf = 10**9
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
def check(s,t):
    if (0 <=  s <= h - 1) and (0 <= t <= w - 1):
        return True
    else:
        return False
#graph => そこまでの距離を保存した二次元配列　grid=>与えられた迷路
adjacent_list = [[] for i in range(h*w+1)]
for i in range(h):
    for j in range(w):
        if i == (h-1) and j == (w-1):
            continue
        if j != (w-1):
            if grid[i][j] != grid[i][j+1] and grid[i][j] == '#':
                adjacent_list[w*i + (j + 1)].append([w*(i) + (j + 2), 1])
            else:
                adjacent_list[w*i + (j + 1)].append([w*(i) + (j + 2), 0])
        if i != (h-1):
            if grid[i][j] != grid[i+1][j] and grid[i][j] == '#':
                adjacent_list[w*i + (j + 1)].append([w*(i + 1) + (j + 1), 1])
            else:
                adjacent_list[w*i + (j + 1)].append([w*(i + 1) + (j + 1), 0])
finished = set()
def dfs(node,cost):
    finished.add(node)
    for i in adjacent_list[node]:
        dist[i[0]] = min(dist[i[0]],dist[node] + i[1])
        dfs(i[0],i[1])
dist = [inf for i in range(h*w+1)]
dist[1] = 0
dfs(1,0)
if grid[-1][-1] == '#':
    dist[-1] += 1
print(dist[-1])



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
h,w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
#色が変わるところでコスト
inf = 10**9
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
#graph => そこまでの距離を保存した二次元配列　grid=>与えられた迷路
adjacent_list = [[] for i in range(h*w+1)]
for i in range(h):
    for j in range(w):
        if i == (h-1) and j == (w-1):
            continue
        if j != (w-1):
            if grid[i][j] != grid[i][j+1] and grid[i][j] == '#':
                adjacent_list[w*i + (j + 1)].append([w*(i) + (j + 2), 1])
            else:
                adjacent_list[w*i + (j + 1)].append([w*(i) + (j + 2), 0])
        if i != (h-1):
            if grid[i][j] != grid[i+1][j] and grid[i][j] == '#':
                adjacent_list[w*i + (j + 1)].append([w*(i + 1) + (j + 1), 1])
            else:
                adjacent_list[w*i + (j + 1)].append([w*(i + 1) + (j + 1), 0])
finished = set()
def dfs(node,cost):
    finished.add(node)
    for i in adjacent_list[node]:
        if dist[node] + i[1] < dist[i[0]]:
            dist[i[0]] = dist[node] + i[1]
            dfs(i[0],i[1])
dist = [inf for i in range(h*w+1)]
dist[1] = 0
dfs(1,0)
if grid[-1][-1] == '#':
    dist[-1] += 1
print(dist[-1])
### BUGGY CODE ###

S = input()
N = len(S)
cnt = [0]*N
ans = 0
for i in range(N):
    cnt = [0]*N
    for k in range(i,N):
        cnt[k] = (cnt[k-1]*10 + int(S[k]))%2019
        if cnt[k] == 0:
            ans += 1
            break
print(ans)

### FIXED CODE ###

import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
S = input()[::-1]
N = len(S)
cnt = [0]*(N+1)
ans = 0
keta = 1
for i in range(N):
    cnt[i] = (cnt[i-1] + int(S[i])*keta)%2019
    keta *= 10
    keta %= 2019
cnt2 = [0]*2020
for i in cnt:
    cnt2[i] += 1
for i in cnt2:
    if i >= 2:
        ans += C(i,2)
print(ans)
### BUGGY CODE ###

def spl(a):
    delta=[]
    for i in range(len(a)-1):
        delta.append(abs(a[-1]-2*a[i]))
    m=min(delta)
    index=[]
    for i in range(len(delta)):
        if delta[i]==m:
            index.append(i)
    return index

N=int(input())
A=list(map(int,input().split()))
h=[0]
for a in A:
    h.append(a+h[-1])
h.pop(0)
ans=10**18
for i in range(N):
    if i>0 and i<N-2:
        g=[l-h[i] for l in h[i+1:]]
        for j in spl(h[:i+1]):
            for k in spl(g):
                p=h[j]
                q=h[i]-h[j]
                r=h[k+i+1]-h[i]
                s=h[-1]-h[k+i+1]
                if (max([p,q,r,s])-min([p,q,r,s]))<ans:
                    ans=max([p,q,r,s])-min([p,q,r,s])
print(ans)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
h=[0]
for a in A:
    h.append(a+h[-1])
h.pop(0)
def spl_l(i,b):
    while abs(h[i]-2*h[b])>abs(h[i]-2*h[b+1]):
        b+=1
    return b
def spl_r(i,b):
    while abs(h[-1]-2*h[b]+h[i])>abs(h[-1]-2*h[b+1]+h[i]):
        b+=1
    return b
def calc(j,i,k):
    pqrs=[h[j],h[i]-h[j],h[k]-h[i],h[-1]-h[k]]
    ans=max(pqrs)-min(pqrs)
    return ans

j=0
k=2
ans=18**20
for i in range(1,N-2):
    j=spl_l(i,j)
    k=spl_r(i,k)
    ans=min(ans,calc(j,i,k))
print(ans)
### BUGGY CODE ###

s, cont = input(), 0
while s.find("01") is not -1:    
    s = s.replace("01", "", 1)
    cont += 1    
while s.find("10") is not -1:
    s = s.replace("10", "", 1)
    cont += 1
print(cont * 2)

### FIXED CODE ###

s=input()
o=s.count('1')
z=s.count('0')
print(2*min(o,z))
### BUGGY CODE ###

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


retval=0
for i in range(N):
    for j in range(i,N):
        if j-i==A[i]+A[j]:
            retval+=1

print(retval)


### FIXED CODE ###

from collections import Counter
N=int(input())
A=[int(i) for i in input().split(" ")]

A2=[i-A[i] for i in range(N)]
A3=[i+A[i] for i in range(N)]

c2=Counter(A2)
c3=Counter(A3)

retval=0
for key in c2+c3:
    retval+=c2[key]*c3[key]

print(retval)
### BUGGY CODE ###

n,m=map(int,input().split())
a=[0]*m
for i in range(m):
    a[i]=int(input())
p0=1
if 1 in a:
    p1=0
else:
    p1=1
for i in range(2,n+1):
    if i in a:
        p2=0
    else:
        p2=p1+p0
    p0,p1=p1,p2
print(p1%1000000007)


### FIXED CODE ###


n,m=map(int,input().split())
a=[1]*(n+1)
for i in range(m):
    a[int(input())]=0
p0=a[0]
p1=a[1]
for i in range(2,n+1):
    if a[i]==1:
        p2=p0+p1
    else:
        p2=0
    p0,p1=p1,p2
print(p1%1000000007)
### BUGGY CODE ###

from itertools import accumulate
N, K = map(int, input().split())
An = list(map(int, input().split()))

for cnt in range(K):
    tmp = [0]*(N+1)
    for i in range(N):
        power = An[i]
        left = max(0, i-power)
        right = min(N, i+power+1)
        tmp[left] += 1
        tmp[right] -= 1
    An = list(accumulate(tmp))[:-1]
    if cnt > 40:
        An = [N]*N
        break
print(*An)


### FIXED CODE ###

from itertools import accumulate
import sys
N, K = map(int, input().split())
An = list(map(int, input().split()))

for cnt in range(K):
    tmp = [0]*(N+1)
    for i in range(N):
        power = An[i]
        left = max(0, i-power)
        right = min(N, i+power+1)
        tmp[left] += 1
        tmp[right] -= 1
    An = list(accumulate(tmp))[:-1]
    if cnt > 40:
        An = [N]*N
        print(*An)
        sys.exit()
print(*An)
### BUGGY CODE ###

import sys
def h(i):
 l=2*i;r=l+1
 if r<=H:
  if A[i]<A[l]:
   if A[l]<A[r]:A[i],A[r]=A[r],A[i];h(r)
   else:A[i],A[l]=A[l],A[i];h(l)
  elif A[i]<A[r]:A[i],A[r]=A[r],A[i];h(r)
 elif l<=H and A[i]<A[l]:A[i],A[l]=A[l],A[i];h(l)
H=0
A=[0]*2000001
o=[]
for e in sys.stdin:
 if'i'==e[0]:
  H+=1;A[H]=int(e[7:]);k=H
  while k>1 and A[k//2]<A[k]:A[k],A[k//2]=A[k//2],A[k];k//=2
 elif'x'==e[1]:
  o+=[A[1]];H-=1
  if H:A[1]=A[H+1];h(1)
 else:print('\n'.join(map(str,o)))


### FIXED CODE ###

import sys
from heapq import*
H=[]
O=[]
for e in sys.stdin:
 if'i'==e[0]:heappush(H,-int(e[7:]))
 elif't'==e[2]:O+=[-heappop(H)]
 else:print('\n'.join(map(str,O)))
### BUGGY CODE ###

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

ans = 0
sn = len(s)

r = []
if s[0] == "R":
    r.append(1)
else:
    r.append(0)
g = []
if s[0] == "G":
    g.append(1)
else:
    g.append(0)
b = []
if s[0] == "B":
    b.append(1)
else:
    b.append(0)

for i in range(1, sn):
    if s[i] == "R":
        r.append(r[-1] + 1)
        g.append(g[- 1])
        b.append(b[- 1])
    elif s[i] == "G":
        r.append(r[-1])
        g.append(g[-1] + 1)
        b.append(b[- 1])
    elif s[i] == "B":
        r.append(r[-1])
        g.append(g[-1])
        b.append(b[-1] + 1)
    else:
        r.append(r[-1])
        g.append(g[- 1])
        b.append(b[- 1])

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if s[i] != s[j]:
            tmp = dict()
            tmp[s[i]] = 0
            tmp[s[j]] = 0
            target_idx = j + (j - i)

            if tmp.get("B", 1) == 1:
                ans += b[-1] - b[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "B":
                    ans -= 1
            elif tmp.get("G", 1) == 1:
                ans += g[-1] - g[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "G":
                    ans -= 1
            else:
                ans += r[-1] - r[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "R":
                    ans -= 1

print(ans)


### FIXED CODE ###

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

ans = 0
sn = len(s)

r = []
if s[0] == "R":
    r.append(1)
else:
    r.append(0)
g = []
if s[0] == "G":
    g.append(1)
else:
    g.append(0)
b = []
if s[0] == "B":
    b.append(1)
else:
    b.append(0)

for i in range(1, sn):
    if s[i] == "R":
        r.append(r[-1] + 1)
        g.append(g[- 1])
        b.append(b[- 1])
    elif s[i] == "G":
        r.append(r[-1])
        g.append(g[-1] + 1)
        b.append(b[- 1])
    elif s[i] == "B":
        r.append(r[-1])
        g.append(g[-1])
        b.append(b[-1] + 1)
    else:
        r.append(r[-1])
        g.append(g[- 1])
        b.append(b[- 1])

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if s[i] != s[j]:
            tmp = dict()
            tmp[s[i]] = 0
            tmp[s[j]] = 0
            target_idx = j + (j - i)

            if tmp.get("B", 1) == 1:
                ans += b[-1] - b[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "B":
                    ans -= 1
            elif tmp.get("G", 1) == 1:
                ans += g[-1] - g[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "G":
                    ans -= 1
            else:
                ans += r[-1] - r[j]
                if target_idx >= sn:
                    continue
                if s[target_idx] == "R":
                    ans -= 1

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

def calc_gcm(a, b):
	if a > b:
		r = a % b
		a = r
	
	while a > 0:
		r = b % a
		b = a
		a = r
	
	return b

def calc_lcm(a, b):
	gcm = calc_gcm(a, b)
	return a * b // gcm

N, M = map(int, input().split())
a_list = list(map(int, input().split()))

lcm = 1
for a in a_list:
	lcm = calc_lcm(lcm, a)

def check():
	for a in a_list:
		if (lcm // a) % 2 == 0:
			return False
	return True

if check():
	lcm //= 2
	count = M // lcm + 1
	print(count // 2)
else:
	print(0)


### FIXED CODE ###

def calc_gcm(a, b):
	if a > b:
		r = a % b
		a = r
	
	while a > 0:
		r = b % a
		b = a
		a = r
	
	return b

def calc_lcm(a, b):
	gcm = calc_gcm(a, b)
	return a * b // gcm

N, M = map(int, input().split())
a_list = list(map(int, input().split()))

lcm = 1
for a in a_list:
	lcm = calc_lcm(lcm, a)
	if lcm > 2 * M:
		lcm = 0
		break

def check():
	for a in a_list:
		if (lcm // a) % 2 == 0:
			return False
	return True

if lcm == 0:
	print(0)
elif check():
	lcm //= 2
	count = M // lcm + 1
	print(count // 2)
else:
	print(0)
### BUGGY CODE ###

a, b, c, k = map(int, input().split());
num = 0;

while a > 0 and k > 0:
    num += 1;
    a -= 1;
    k -= 1;
  
while b > 0 and k > 0:
    b -= 1;
    k -= 1;
    
while c > 0 and k > 0:
    num -= 1;
    c -= 1;
    k -= 1;

print(num)

### FIXED CODE ###

a, b, c, k = map(int, input().split());

if a > k:
  print(k)
else:
  num = a; 
  
  if k >= a + b:
      num -= k - (a + b);
  print(num)
### BUGGY CODE ###

def P(x):
    ans=1
    for i in range(x):
        ans=ans*(i+1)
    
    return(ans)

def comb(n, r):
    return P(n)//(P(n - r)*P(r))

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

c=[0]*(n+1)

c[0]=a[0]

for i in range(1,n):
    c[i]=c[i-1]+a[i]


c.sort()

#print(c)

now=c[0]
t=1
ans=0

for i in range(1,n+1):
    if c[i]==now:
        t+=1
    else:
        now=c[i]
        if t>1:
            ans+=comb(t,2)
        t=1
else:
    now=c[i]
    if t>1:
        ans+=comb(t,2)
    
print(ans)


### FIXED CODE ###

import math

N = int(input())

a = list(map(int, input().split()))
b = [a[0] for i in range(N)]

for i in range(1, N):
    b[i] = b[i-1] + a[i]
    
b.sort()
c = 1
ans = 0

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)   

def C(n, r):
    return P(n, r)//math.factorial(r)

if N==1:
    if b[0]==0:
        print(1)
    else:
        print(0)
else:
    for i in range(1, N):
        if b[i]==b[i-1]:
            c = c+1
        else:
            if c>1:
                ans = ans + C(c, 2)
            if b[i-1]==0:
                ans = ans + c
            c=1
    else:
        if c>1:
            ans = ans + C(c, 2)
        if b[i-1]==0:
            ans = ans + c
    
    print(ans)
### BUGGY CODE ###

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

if K > Q:
    for i in range(N):
        print('Yes')
    exit()

for i in range(N):
    B = Q-A.count(i+1)
    if B >= K:
        print('No')
    else:
        print('Yes')


### FIXED CODE ###

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

cnt = [0] * n

for i in a:
    cnt[i - 1] += 1

for c in cnt:
    if k - (q - c) > 0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[0]*(len(bin(max(a+[k])))-2)
ans=""
for i in range(n):
    l=len(bin(a[i])[2:])
    for j in bin(a[i])[2:]:
        b[len(bin(max(a+[k])))-l-2]+=int(j)
        l-=1
for (i,j) in enumerate(b):
    if j<(n/2) and k>=2**i:
        ans=ans+"1"
    else:
        ans=ans+"0"
x=0
ans=int(ans,2)
for i in a:
    x+=ans^i
print(x)

### FIXED CODE ###

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
m=len(bin(max(a+[k])))-2
b=[0]*m
ans=""
x=0
a2=[bin(i)[2:] for i in a]
for i in a2:
    for j in range(-1,-len(i)-1,-1):
        b[j]+=int(i[j])
B=len(b)
for (i,j) in enumerate(b):
    if j<(n/2) and k>=2**(B-i-1):
        ans=ans+"1"
        k-=2**(B-i-1)
    else:
        ans=ans+"0"
ans=int(ans,2)
for i in a:
    x+=ans^i
print(x)
### BUGGY CODE ###


S = list(input())
N = len(S)

def solver(n,m,idx):
    N = n+m
    if (n-m)%2 == 0:
        ans = [0] * N
        ans[idx[0]] = (n+m)//2
        ans[idx[1]] = (n+m)//2
    else:
        ans = [0] * N
        if m%2 == 1:
            ans[idx[1]] = (n+m)//2 + 1
            ans[idx[0]] = (n+m)//2
        else:
            ans[idx[0]] = (n+m)//2 + 1
            ans[idx[1]] = (n+m)//2
    return ans    
    
    
        
        
ans = []
m = 0
n = 0
flagL = False
idx = []
for i,s in enumerate(S):
    if s == 'R':
        if flagL:
            ans = ans + solver(n,m,idx)
            n = 0
            m = 0
            flagL = False
        n = n+1
    elif s == 'L':
        if not flagL:
            flagL = True
            idx = [n-1,n]
        m = m+1
    if i == N-1:
        ans = ans + solver(n,m,idx)
    
print(' '.join(map(str,ans)))

### FIXED CODE ###

#import sys
#input = sys.stdin.readline
S = list(input())
N = len(S)

def solver(n,m,idx):
    if (n-m)%2 == 0:
        ans[idx[0]] = (n+m)//2
        ans[idx[1]] = (n+m)//2
    else:
        if m%2 == 1:
            ans[idx[1]] = (n+m)//2 + 1
            ans[idx[0]] = (n+m)//2
        else:
            ans[idx[0]] = (n+m)//2 + 1
            ans[idx[1]] = (n+m)//2
    return    
    
    
        
        
ans = [0] * N
m = 0
n = 0
flagL = False
idx = []
for i,s in enumerate(S):
    if s == 'R':
        if flagL:
            solver(n,m,idx)
            n = 0
            m = 0
            flagL = False
        n += 1
    elif s == 'L':
        if not flagL:
            flagL = True
            idx = [i-1,i]
        m += 1 
solver(n,m,idx)
    
print(*ans,sep = ' ')
### BUGGY CODE ###

A = [int(input()) for i in range(int(input()))]
for i in range(len(A)):
    print(max(A[:i]+A[i+1:]))


### FIXED CODE ###

A = [int(input()) for i in range(int(input()))]
first = max(A)
second = sorted(A)[-2]
for i in A:
    if i == first:
        print(second)
    else:
        print(first)
### BUGGY CODE ###

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

def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in range(n)]
    ab.sort()
    c=[0]*n
    ans=0
    for i in range(1,m+1):
        mb=0
        mnum=-1
        for j in range(n):
            if ab[j][0]<=i:
                if mb<ab[j][1] and c[j]==0:
                    mb=ab[j][1]
                    mnum=j
            else:
                break
        ans+=mb
        if mnum!=-1:
            c[mnum]=1
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from heapq import heappush, heappop
input = sys.stdin.readline

def main():
    n,m=map(int,input().split())
    ab=[]
    for i in range(n):
        a,b=map(int,input().split())
        if a>m:
            continue
        ab.append((a,b))
    ab.sort(reverse=True)    
    q=[]
    ans=0
    for i in range(1,m+1):
        while ab and ab[-1][0]<=i:
            a,b=ab.pop()
            heappush(q,-b)
        if q:
            b=-heappop(q)
            ans+=b
    print(ans)

if __name__ == '__main__':
    main()