Harryxun/stf_run huggingface dataset:
import numpy as np
h, w, m = map(int, input().split())
arr = np.zeros([h,w])
for _ in range(m):
    c_h, c_w = map(int, input().split())
    arr[c_h-1, c_w-1] = 1
    
row_sum = np.sum(arr, axis=1)
col_sum = np.sum(arr, axis=0)
row_max_pos = np.argwhere(row_sum == np.max(row_sum))
col_max_pos = np.argwhere(col_sum == np.max(col_sum))
    
row_max = int(max(row_sum))
col_max = int(max(col_sum))
ans = row_max + col_max

### FIXED CODE ###

h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()

for i in range(m):
    _h, _w = map(int, input().split())
    h_cnt[_h-1] += 1
    w_cnt[_w-1] += 1
    bomb.add(((_h-1),(_w-1))) #爆破対象の位置を判断

h_max = max(h_cnt)
w_max = max(w_cnt)

max_h = []
max_w = []

for i in range(h):
    if h_cnt[i] == h_max:
        max_h.append(i)

for i in range(w):
    if w_cnt[i] == w_max:
        max_w.append(i)

flg = True

for i in max_h:
    for j in max_w:
        if (i,j) not in bomb:
            flg = False
            break
print(h_max+w_max-1 if flg else h_max+w_max)
r = input()
 print(r**2)

### FIXED CODE ###

r = int(input())
print("{}".format(int(r**2)))
def main():
	# a,b,k = map(int,input().split())
	# n,k = map(int,input().split())
	n = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(5)]
	# s = list(s)
	
	for i in range(n):
		if n % 2 != 0:
			ans += 1
	print(ans/n)


 
if __name__ == '__main__':
	main()

### FIXED CODE ###

def main():
	# a,b,k = map(int,input().split())
	# n,k = map(int,input().split())
	n = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(5)]
	# s = list(s)
	ans = 0
	for i in range(1,n+1):
		if i % 2 != 0:
			ans += 1
	print(ans/n)


 
if __name__ == '__main__':
	main()
a, b = [int(i) in input().split(" ")]
c = "{0:.f6}".format(a/b)
print(int(a/b), a%b, c, sep = " ")

### FIXED CODE ###

a, b = [int(i) for i in input().split(" ")]
num1 = a // b
num2 = a % b
num3 = "{:.8f}".format(a / b)

print(num1, num2, num3)
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    if n % 2 != 0:
        a, b = ab[n // 2]
        print(b - a + 1)
    else:
        a1, b1 = ab[(n - 1) // 2]
        a2, b2 = ab[(n + 1) // 2]
        print(len(list(range(a1 + a2, b1 + b2 + 1))))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


### FIXED CODE ###

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    min_arr = sorted(ab, key=lambda x: x[0])
    max_arr = sorted(ab, key=lambda x: x[1])
    if n % 2 != 0:
        a = min_arr[n // 2][0]
        b = max_arr[n // 2][1]
        print(b - a + 1)
    else:
        a1 = min_arr[(n - 1) // 2][0]
        b1 = max_arr[(n - 1) // 2][1]
        a2 = min_arr[(n + 1) // 2][0]
        b2 = max_arr[(n + 1) // 2][1]
        print(b1 + b2 - a1 - a2 + 1)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
grid = [[0] * w for _ in range(h)]
cnt = 0


def dfs(x, y, num):
    for i in range(-1, 2):
        for j in range(-1, 2):
            next_x = x + i
            next_y = y + j
            global cnt
            if 0 <= next_x and next_x < h and 0 <= next_y and next_y < w and grid[next_x][next_y] == 0 and cnt > 0:
                grid[next_x][next_y] = num
                cnt -= 1
                dfs(next_x, next_y, num)


for i in range(n):
    cnt = a[i]
    for j in range(h):
        for k in range(w):
            dfs(j, k, i + 1)
for i in range(h):
    print(*grid[i])

### FIXED CODE ###

h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
grid = [[0] * w for _ in range(h)]
cnt = 0
color = []
for i in range(n):
    for j in range(a[i]):
        color.append(i + 1)
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            grid[i][j] = color[cnt]
            cnt += 1
    else:
        for j in range(w - 1, -1, -1):
            grid[i][j] = color[cnt]
            cnt += 1
for i in range(h):
    print(*grid[i])
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, M = map(int, raw_input().split())
X = map(int, raw_input().split())

cnt = [0]*100005
for x in X:
    cnt[x%M] += 1

ans = 0
for i in xrange(M):
    if i == M - i:
        ans += cnt[i]/2
        print "=", cnt[i]
        cnt[i] %= 2
    else:
        m = min(cnt[i], cnt[M - i])
        print min(cnt[i], cnt[M - i])
        ans += m
        cnt[i] -= m
        cnt[M - i] -= m
for i in xrange(M):
    ans += cnt
print ans


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, M = map(int, raw_input().split())
X = map(int, raw_input().split())

cnt = [0]*100005
for x in X:
    cnt[x] += 1

pair = [0]*M
for i in xrange(100005):
    pair[i%M] += cnt[i]/2
    cnt[i] %= 2

mod = [0]*M
for i in xrange(100005):
    mod[i%M] += cnt[i]

ans = sum(pair)
for i in xrange(M):
    if i == 0 or i == M - i:
        ans += mod[i]/2 
        mod[i] %= 2
    else:
        m = min(mod[i], mod[M - i])
        ans += m
        mod[i] -= m
        mod[M - i] -= m

for i in xrange(1, M):
    while pair[i] >= 1 and mod[M - i] >= 2:
        ans += 1
        pair[i] -= 1
        mod[M - i] -= 2


print ans
n = int(input())
s = input()

max_diff = 0
for i in range(1, len(s)):
  s1 = s[:i]
  s2 = s[i:]
  diff = len(set(s1) & set(s2))
  if diff > max_diff:
    max_diff = diff
print max_diff

### FIXED CODE ###

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

max_diff = 0
for i in range(1, len(s)):
  s1 = s[:i]
  s2 = s[i:]
  diff = len(set(s1) & set(s2))
  if diff > max_diff:
    max_diff = diff
print(max_diff)
n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        if 2*t-k>=0:
            a=get(t,i)
            tmp=sum(a)
            for j in range(k-t):
                tmp-=a[j]
                res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
v=list(map(int,input().split()))
def get(t,s): # t個のうち前からs個
    return sorted(v[:s]+v[n-(t-s):])

def f(t):
    res=0
    for i in range(t+1):
        a=get(min(t,n),min(i,n))
        tmp=sum(a)
        res=max(res,tmp)
        for j in range(min(k-t,t,n)):
            tmp-=a[j]
            res=max(res,tmp)
    return res

ans=0
for i in range(1,k+1):
    ans=max(ans,f(i))
print(ans)
get = map(int, input().split())
A = get[0]
B = get[1]
if A >= 10 or B >= 10:
  print(-1)
else:
  print(A * B)

### FIXED CODE ###

get = list(map(int, input().split()))
A = get[0]
B = get[1]
if A >= 10 or B >= 10:
  print(-1)
else:
  print(A * B)
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

n,k,l=map(int,input().split())
uf1=UnionFind(n)
uf2=UnionFind(n)
for _ in range(k):
  u,v=map(int,input().split())
  uf1.unite(u-1,v-1)
for _ in range(k):
  u,v=map(int,input().split())
  uf2.unite(u-1,v-1)
ans=[]
for i in range(n):
  x=set(uf1.members(i))&set(uf2.members(i))
  ans.append(len(x))
print(*ans)

### FIXED CODE ###

from collections import defaultdict
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

n,k,l=map(int,input().split())
uf1=UnionFind(n)
uf2=UnionFind(n)
for _ in range(k):
  u,v=map(int,input().split())
  uf1.unite(u-1,v-1)
for _ in range(l):
  u,v=map(int,input().split())
  uf2.unite(u-1,v-1)
d=defaultdict(int)
for i in range(n):
  d[(uf1.find(i),uf2.find(i))]+=1
ans=[d[(uf1.find(i),uf2.find(i))] for i in range(n)]
print(*ans)
# coding: utf-8
n_S, n_T = 0, 0

if c in input():
    if c == "S":
        n_S += 1
    else:
        if n_S:
            n_S -= 1
        else:
            T += 1
print(n_S + n_T)


### FIXED CODE ###

# coding: utf-8
X = input()
tmp = " "
cnt = 0
for x in X:
    if x == "S":
        tmp += x
        cnt += 1
    elif x == "T" and tmp[-1]=="S":
            cnt -= 1
            tmp = tmp[0:len(tmp)-1]
    else:
        tmp += x
        cnt += 1
print(cnt)
for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        n = max((n // (10**k)) * (n % (10**k))
                for k in range(1, int(log10(n)) + 1))
        j += 1
    print(j)

### FIXED CODE ###

from math import log10

for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        n = max((n // (10**k)) * (n % (10**k)) for k in range(1, int(log10(n)) + 1))
        j += 1
    print(j)
import sys
sys.setrecursionlimit(2000)
h,w = map(int,input().split())
s = []

for i in range(h):
    s.append(list(input()))

from collections import deque

def bfs(i,j,dist):
    seen[i][j] = dist
    lis = [[i-1,j],[i,j-1],[i+1,j],[i,j+1]]
    for place in lis:
        if place[0]<0 or place[0]>=h or place[1]<0 or place[1]>=w:
            continue
        if seen[place[0]][place[1]] != -1 or s[place[0]][place[1]]=="#":
            continue
        que.append([place[0],place[1],dist+1])
    if len(que):
        new = que.popleft()
        bfs(new[0],new[1],new[2])
    else:
        return


mx = 0
for i in range(h):
    for  j in range(w):
        if s[i][j]=="#":
            continue
        seen = [[-1 for _ in range(w)]for _ in range(h)]
        que = deque()
        bfs(i,j,0)
        mx = max(mx,max(max(seen)))
        print(seen)
#print(seen)
print(mx)


### FIXED CODE ###

import sys
sys.setrecursionlimit(3000)

import numpy as np

h,w = map(int,input().split())
s = []

for i in range(h):
    s.append(list(input()))

from collections import deque

def bfs(i,j,dist):
    seen[i][j] = dist
    lis = [[i-1,j],[i,j-1],[i+1,j],[i,j+1]]
    for place in lis:
        if place[0]<0 or place[0]>=h or place[1]<0 or place[1]>=w:
            continue
        if seen[place[0]][place[1]] != -1 or s[place[0]][place[1]]=="#":
            continue
        if [place[0],place[1],dist+1] in que:
            continue
        que.append([place[0],place[1],dist+1])
    if len(que):
        new = que.popleft()
        bfs(new[0],new[1],new[2])
    else:
        return


mx = 0
for i in range(h):
    for  j in range(w):
        if s[i][j]=="#":
            continue
        seen = [[-1 for _ in range(w)]for _ in range(h)]
        que = deque()
        bfs(i,j,0)
        ast = np.array(seen)
        tmp = np.amax(ast)
        mx = max(mx,tmp)
        #print(seen)
            #print(*seen,sep="\n")
print(mx)
A,B,K=map(int,input().split())
ans_list=[]
C=min(A,B)+1
for i in range(1,C):
    if A%i == 0 and B%i == 0:
        ans_list.append(i)
print(ans_list[-K])

### FIXED CODE ###

a_list=list(map(int,input().split()))
A=a_list[0]
B=a_list[1]
C=a_list[2]
if B//A <= C:
    answer=B//A
else:
    answer=C
print(answer)
S=str(input())
l=len(S)
ans=0

mod=[0]*2019
mod[0]+=1
t=0
for i in range(l):
    t=int(S[l-i:-1:-1])*pow(10,i,2019)
    mod[t%2019]+=1
    
for j in range(len(mod)):
    m=mod[j]
    ans=ans+m*(m-1)//2
print(ans)

### FIXED CODE ###

S=str(input())
l=len(S)
ans=0
dig=1
mod=[0]*2019
mod[0]=1
t=0
for i in range(l):
    t=(t+int(S[-i-1])*dig)%2019
    mod[t]+=1
    dig=(dig*10)%2019
    
for j in mod:
    ans=ans+(j*(j-1))//2
print(ans)
A, B, X = map(int, raw_input().split())

if X >= A and X <= A + B:
    print('YES')
else:
    print('NO')


### FIXED CODE ###

A, B, X = map(int, input().split())

if X >= A and X <= A + B:
    print('YES')
else:
    print('NO')
url = "https://atcoder.jp//contests/abc073/tasks/abc073_c"

def main():
    li = [0] * (10 ** 5)
    li.append(0)

    n = int(input())
    for i in range(n):
        ind = int(input())
        if li[ind] == 0:
            li[ind] = 1
        else:
            li[ind] = 0
    print(li.count(1))
if __name__ == '__main__':
    main()


### FIXED CODE ###


url = "https://atcoder.jp//contests/abc073/tasks/abc073_c"

def main():
    li = {}
    n = int(input())
    for i in range(n):
        ind = int(input())
        li.setdefault(ind, 0)
        if li[ind] == 0:
            li[ind] = 1
        else:
            li[ind] = 0
    print(list(li.values()).count(1))


if __name__ == '__main__':
    main()
import sys
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
from itertools import combinations
read = sys.stdin.read

N, M, *abc = map(int, read().split())
a, b, c = zip(*zip(*[iter(abc)] * 3))

graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = shortest_path(graph, directed=False)

answer = 0

for i, j in zip(a, b):
    for s in range(1, N + 1):
        if distance[i][j] + distance[j][s] == distance[i][s]:
            continue

        if distance[j][i] + distance[i][s] == distance[j][s]:
            continue

        answer += 1

print(answer)

### FIXED CODE ###

import sys
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
read = sys.stdin.read

N, M, *abc = map(int, read().split())
a, b, c = zip(*zip(*[iter(abc)] * 3))

graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False)

answer = 0

for i, j, k in zip(a, b, c):
    k = float(k)
    if k == distance[i][j]:
        continue

    for s in range(1, N + 1):
        if i == s or j == s:
            continue

        if k + distance[j][s] == distance[i][s]:
            break

        if k + distance[i][s] == distance[j][s]:
            break

    else:
        answer += 1

print(answer)
n=input()
n=int(n)
og=n
rev=0
while(n>0):
    d=n%10
    n=n/10
    rev=rev+d
if(og==rev):
    print("Yes)
    else:
    print("No")    


### FIXED CODE ###

n=input()
n=int(n)
og=n
rev=0
while(n>0):
    d=n%10  
    n=n//10
    rev=rev*10+d
if(rev==og):
    print("Yes")
else:
    print("No")
N, M = map(int, input.split())

inf = 10 ** 10

dp = [inf] * (1 << N)

for _ in range(M):
    a, b = map(int, input.split())
    c = sum([2 ** (i - 1) for i in map(int, input.split())])

    for j in range(1 << N):
        if dp[j] + a < dp[j | c]:
            dp[j | c] = dp[j] + a

res = dp[-1] if dp[-1] != inf else -1
print(res)

### FIXED CODE ###

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

inf = 10 ** 10

dp = [inf] * (1 << N)
dp[0] = 0

for _ in range(M):
    a, b = map(int, input().split())
    c = sum([2 ** (i - 1) for i in map(int, input().split())])

    for j in range(1 << N):
      dp[j | c] = min(dp[j] + a, dp[j | c])

res = dp[-1] if dp[-1] != inf else -1
print(res)
n,m,k=map(int,input().split())
x='No'
for i in range(m+1)
  t=n*i
  if t==k:
    x='Yes'
    break
  for j in range(n):
    t+=m-2*i
    if t==k:
      x='Yes'
      break
print(x)

### FIXED CODE ###

n,m,k=map(int,input().split())
x='No'
for i in range(m+1):
  t=n*i
  if t==k:
    x='Yes'
    break
  for j in range(n):
    t+=m-2*i
    if t==k:
      x='Yes'
      break
print(x)
D,N = map(int,input().split())
K = (100**D)*N
if K%100 == 0:
　K = (100**D)*(N+1)
print(K)

### FIXED CODE ###

D,N = map(int,input().split())
K = (100**D)*N
if N%100 == 0:
  K = (100**D)*(N+1)
print(K)
n, k = map(int, input().split())
a = list(map(int, input().split()))

if max(a) < k:
    print('IMPOSSIBLE')
elif k in a:
    print('POSSIBLE')
else:
    for i in a:
        if i %2 == 0:
            flag_e = True
        else:
            flag_o = True
    if flag_e is True and flag_o is True:
        for i in a:
            if i == min(a):
                continue
            else:
                if i %2 == 0:
                    if (i-min(a)) % min(a) != 0:
                        print('POSSIBLE')
                        exit()
                    else:
                        continue
                else:
                    if i % min(a) != 0:
                        print('POSSIBLE')
                        exit()
                    else:
                        continue
        print('IMPOSSIBLE')
        exit()
    elif flag_e is True:
        if k %2 == 0:
            print('POSSIBLE')
            exit()
        else:
            print('IMPOSSIBLE')
            exit()
    else:
        for i in a:
            if i == min(a):
                continue
            else:
                if i % min(a) != 0:
                    print('POSSIBLE')
                    exit()
                else:
                    continue
        print('IMPOSSIBLE')
        exit()


### FIXED CODE ###

import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


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

b = gcd_list(a)
if max(a) >= k and k % b == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
if __name__ == "__main__":
    n,a,b = input(),input(),input()
    print (max(n*a,b))


### FIXED CODE ###

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

print(min(n*a,b))
import math
a,b=map(int,input().split())
print(math.ceil((a+b)/2)

### FIXED CODE ###

import math
a,b=map(int,input().split())
print(math.ceil((a+b)/2))
S = input()
import numpy as np
length = len(S)
arr = np.array([int(S[i:j]) for i in range(0,length-3) for j in range(i+4, length+1)])
arr2 = arr % 2019
print(len(arr2)- np.count_nonzero(arr2))

### FIXED CODE ###

S, W = map(int, input().split())
if W >= S:
    print("unsafe")
else:
    print("safe")
n,m,q=map(int,input().split())
a=[0]*q
b=[0]*q
c=[0]*q
d=[0]*q
A=[]
for i in range(q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
def score(A):
  sum=0
  for (ai,bi,ci,di) in zip(a,b,c,d):
    if A[ai-1]-A[bi-1]==A[ci-1]:
      sum+=di
  return sum
def fbs(A):
  if len(A)==n:
    return score(A)
  res=0
  for v in range(1,m+1):
    A.append(v)
    res=max(res,fbs(A))
    A.pop()
  return res

print(fbs(A))

### FIXED CODE ###

n,m,q=map(int,input().split())
a=[0]*q
b=[0]*q
c=[0]*q
d=[0]*q
A=[]
for i in range(q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
def score(A):
  sum=0
  for (ai,bi,ci,di) in zip(a,b,c,d):
    if A[bi-1]-A[ai-1]==ci:
      sum+=di
  return sum
def fbs(A):
  if len(A)==n:
    return score(A)
  if len(A)>0:
    pre_last=A[-1]
  else:
    pre_last=0
  res=0
  for v in range(pre_last,m):
    A.append(v)
    res=max(res,fbs(A))
    A.pop()
  return res

print(fbs(A))
import math
xyzk = list(map(int,input().split()))
abc = [list(map(int,input().split())) for a in range(3)]
ab=[]
for a in abc[0]:
    for b in abc[1]:
        ab.append(a+b)
ab.sort()
ab.reverse()
abc[2].sort()
abc[2].reverse()
abc2=[]
for c in range(len(abc[2])):
    for a in range(min([xyzk[3]/(c+1),len(ab)])):
        abc2.append(abc[2][c]+ab[a])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
    print(abc2[a])

### FIXED CODE ###

import math
xyzk = list(map(int,input().split()))
abc = [list(map(int,input().split())) for a in range(3)]
ab=[]
for a in abc[0]:
    for b in abc[1]:
        ab.append(a+b)
ab.sort()
ab.reverse()
abc[2].sort()
abc[2].reverse()
abc2=[]
for c in range(len(abc[2])):
    for a in range(min([math.ceil(xyzk[3]/(c+1)),len(ab)])):
        abc2.append(abc[2][c]+ab[a])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
    print(abc2[a])
import sys
input = sys.stdin.readline
import heapq

flg = False
n, m = map(int, input().split())
jobs = [[] for i in range(m)]
for i in range(n):
    a, b = map(int, input().split())
    if a > m and flg == False:
        jobs[m - a].append(b)
    else:
        flg = True
        jobs[m - a].append(b)

if flg == False:
    print(0)
    exit(0)

q = []
heapq.heapify(q)
ans = 0
for i in reversed(range(m)):
    for b in jobs[i]:
        heapq.heappush(q, -b)
    if len(q) != 0:
        ans += heapq.heappop(q) * -1

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline
import heapq

n, m = map(int, input().split())
jobs = [[] for i in range(m)]
for i in range(n):
    a, b = map(int, input().split())
    if a > m:
        pass
    else:
        jobs[m - a].append(b)

if len(jobs) == 0:
    print(0)
    exit(0)

q = []
heapq.heapify(q)
ans = 0
for i in reversed(range(m)):
    for b in jobs[i]:
        heapq.heappush(q, -b)
    if len(q) != 0:
        ans += heapq.heappop(q) * -1

print(ans)
N,M = [int(i) for i in input().split()]

items = [int(i) for i in input().join(' ')]
items.sort()
total = sum(items)

flag = 1
for i in range(M):
  if 1 // (4 * M) >= items[i]:
    pass
  else:
    flag = 0
if not flag:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N,M = [int(i) for i in input().split()]

items = [int(i) for i in input().split()]
items.sort(reverse=True)
total = sum(items)

flag = 1
for i in range(M):
  if total / (4 * M) <= items[i]:
    pass
  else:
    flag = 0
if flag:
  print('Yes')
else:
  print('No')
n=int(input())
b=list(map(int,input().split()))
a=b[:]
condition=''
cnt=0
wa=0
for i in range(n):
  wa+=a[i]
  if i == 0:
    if a[i]>0:
      condition='minus'
    else:
      condition='plus'
  elif condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt1=cnt
a=b[:]
condition=''
cnt=0
wa=0
for i in range(n):
  wa+=a[i]
  if i == 0:
    a[i]=int(a[i]/abs(a[i])*(-1))
    cnt+=abs(a[i])+1
    wa=a[i]
    if a[i]>0:
      condition='minus'
    else:
      condition='plus'
  elif condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt2=cnt
print(min(cnt1,cnt2))

### FIXED CODE ###

n=int(input())
b=list(map(int,input().split()))
a=b[:]

cnt=0
wa=0
condition='plus'
for i in range(n):
  wa+=a[i]
  if condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt1=cnt
a=b[:]
cnt=0
wa=0
condition='minus'
for i in range(n):
  wa+=a[i]
  if condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt2=cnt
print(min(cnt1,cnt2))