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

def gcd(x, y):
    xx = 0; yy = 0
    if x >= y:
        xx = x; yy = y
    else:
        xx = y; yy = x
    while yy > 0:
        xx, yy = yy, xx%yy
    return xx


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    ans = 1
    for i in range(n):
        tmp = -1
        for j in range(n):
            if j == i:
                continue
            if tmp == -1:
                tmp = a[j]
            tmp = gcd(tmp, a[j])
        ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def gcd(x, y):
    xx = 0; yy = 0
    if x >= y:
        xx = x; yy = y
    else:
        xx = y; yy = x
    while yy > 0:
        xx, yy = yy, xx%yy
    return xx


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    # i を入れた場合のgcdと i を入れない場合のgcdを考える
    ans = 1
    # gcd の結合則を利用する(X, Y, Zがありgcd(gcd(x,y),z)==gcd(x,gcd(x, y)))
    l = [0 for i in range(n)]
    r = [0 for i in range(n+1)]
    for i in range(n-1):
        l[i+1] = gcd(l[i], a[i])
    for i in range(n-1, -1, -1):
        r[i] = gcd(r[i+1],a[i])
    for i in range(n):
        ans = max(ans, gcd(l[i], r[i+1]))
    print(ans)


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

import numpy

N,M,K = map(int, input().split())
ans = 0
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A = numpy.cumsum(numpy.array(A))
A = list(A)
A.insert(0, 0)
B = numpy.cumsum(numpy.array(B))
B = list(B)
B.insert(0, 0)
ans = 0

for i in range(N+1):
    if A[i] > K:
        break
    for j in range(M+1):
        if A[i] + B[j] <= K:
            ans = max(i+j,ans)
        else :
            break

print(ans)

### FIXED CODE ###

import numpy
import bisect

N,M,K = map(int, input().split())
ans = 0
A = list(map(int,input().split()))
B = list(map(int,input().split()))

A = numpy.cumsum(numpy.array(A))
A = list(A)
A.insert(0, 0)
B = numpy.cumsum(numpy.array(B))
B = list(B)
B.insert(0, 0)
ans = 0

for i in range(N+1):
    if K - A[i] < 0:
        break
    b = bisect.bisect(B, K - A[i])
    ans = max(ans, i+b-1)

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

from sys import stdin
input = stdin.readline

n = int(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 ###

def main():
    import sys
    n = int(input())
    a = list(map(int, input().split()))

    try:
        if a.index(0):
            print(0)
            sys.exit()
    except ValueError:
        pass

    ans = 1
    for i in range(n):
        ans *= a[i]
        if ans > 10 ** 18:
            print(-1)
            sys.exit()

    print(ans)


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

a,b,q=map(int,input().split())
s=[0]*a
t=[0]*b
x=[0]*q
for i in range(a):
  s[i]=int(input())
for i in range(b):
  t[i]=int(input())
import bisect
for i in range(q):
  x=int(input())
  ids=bisect.bisect_left(s,x)
  idt=bisect.bisect_left(t,x)
  mi=14857363987569617
  if ids < a:
    if idt < b:
      mi=min(mi,min([abs(s[ids]-x)+abs(s[ids]-t[idt]),
                    abs(t[idt]-x)+abs(t[idt]-s[ids])]))
    if idt > 0:
      mi=min(mi,min([abs(s[ids]-x)+abs(s[ids]-t[idt-1]),
                    abs(t[idt-1]-x)+abs(t[idt-1]-s[ids])]))
  if ids > 0:
    if idt < b:
      mi=min(mi,min([abs(s[ids-1]-x)+abs(s[ids-1]-t[idt]),
                    abs(t[idt]-x)+abs(t[idt]-s[ids-1])]))
    if idt > 0:
      mi=min(mi,min([abs(s[ids-1]-x)+abs(s[ids-1]-t[idt-1]),
                    abs(t[idt-1]-x)+abs(t[idt-1]-s[ids-1])]))
  print(mi)


### FIXED CODE ###

a,b,q=map(int,input().split())
s=[0]*a
t=[0]*b
x=[0]*q
for i in range(a):
  s[i]=int(input())
for i in range(b):
  t[i]=int(input())
import bisect
for i in range(q):
  x=int(input())
  ids=bisect.bisect_left(s,x)
  idt=bisect.bisect_left(t,x)
  mi=14857363987569617
  if ids < a:
    if idt < b:
      mi=min(mi,min([abs(s[ids]-x)+abs(s[ids]-t[idt]),
                    abs(t[idt]-x)+abs(t[idt]-s[ids])]))
    if idt > 0:
      mi=min(mi,min([abs(s[ids]-x)+abs(s[ids]-t[idt-1]),
                    abs(t[idt-1]-x)+abs(t[idt-1]-s[ids])]))
  if ids > 0:
    if idt < b:
      mi=min(mi,min([abs(s[ids-1]-x)+abs(s[ids-1]-t[idt]),
                    abs(t[idt]-x)+abs(t[idt]-s[ids-1])]))
    if idt > 0:
      mi=min(mi,min([abs(s[ids-1]-x)+abs(s[ids-1]-t[idt-1]),
                    abs(t[idt-1]-x)+abs(t[idt-1]-s[ids-1])]))
  print(mi)
### BUGGY CODE ###

N=int(input())
come=input()
come=come.split()
come_list=[]
for i in come:
    come_list.append(int(i)) 
rank=[]
for i in range(N):
    rank.append(0)
count=1

for i in come_list:
    rank[i-1]=count
    count+=1


out_put=str(rank[0])

for i in rank[1:]:
    out_put+=" "+str(i)

print(out_put)

### FIXED CODE ###

N=int(input())
come=input()
come=come.split()
come_list=[]
for i in come:
    come_list.append(int(i)) 
rank=[]
for i in range(N):
    rank.append(0)
count=1

for i in come_list:
    rank[i-1]=count
    count+=1


out_put=str(rank[0])

for i in rank[1:]:
    out_put+=" "+str(i)

print(out_put)
### BUGGY CODE ###

# Problem A - Frog 2 - Algoritmos e Grafos - MATA52
def frog2(n, h, k_max):
    global stones
    for i in range(n - 1):
        for j in range(k_max):
            if i + j + 1 <= n - 1:
                w1 = stones[i + j + 1]
                w2 = abs(h[i + j + 1] - h[i])
                stones[i + j + 1] = min(w1, stones[i] + w2)
            else:
                break
    return stones[n - 1]

n, k_max = list(map(int, input().split()))
h = list(map(int, input().split()))

stones = [0] + [float("inf") for x in range(n + k_max)]
print(frog2(n, h, k_max))

### FIXED CODE ###

n, k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]

def abs(x):
    if x >= 0:
        return x
    return -x

c = [0]
c.append(abs(h[1] - h[0]))
for i in range(2, n):
    cmin = None
    for cur in range(i-1, i-1-k, -1):
        if cur < 0:
            break
        val = abs(h[i] - h[cur]) + c[cur]
        if cmin is None or val < cmin:
            cmin = val
    c.append(cmin)

print(c[-1])
### BUGGY CODE ###

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    res = 0
    maxI = 0
    maxV = 0
    for i in range(N-K+1):
        v = sum(P[i:i+K])
        if v > maxV:
            maxV = v
            maxI = i
    # print(maxI)
    for p in P[maxI:maxI+K]:
        res += (1.0/p) * (p*(p+1.0)/2.0)
    print(res)

main()

### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    maxI = 0
    maxV = sum(P[:K])
    curV = maxV
    for i in range(1, N-K+1):
        curV = curV + P[i+K-1] - P[i-1]
        if curV > maxV:
            maxV = curV
            maxI = i

    res = (sum(P[maxI:maxI+K]) + K) / 2.0
    print(res)

main()
### BUGGY CODE ###

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

ali.sort(reverse=True)

# rings = [ali[0], ali[1]]
comforts = [ali[1], ali[1]]

answer = ali[0]

for i in ali[2:]:
    max_com = comforts.index(max(comforts))
    answer += comforts[max_com]

    comforts.pop(max_com)
    comforts.insert(max_com, i)
    comforts.insert(max_com, i) #新しく入った人の隣同士

print(answer)

### FIXED CODE ###

from collections import deque
import sys

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

ali.sort(reverse=True)

comforts = deque([ali[1], ali[1]])
answer = ali[0]
if len(ali) < 3:
    print(answer)
    sys.exit()

for i in ali[2:]:
    answer += comforts.pop()
    comforts.appendleft(i)
    comforts.appendleft(i)

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

H,W,D = map(int,input().split())
grid = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
info = [list(map(int,input().split())) for i in range(Q)]

note = [0]*(H*W+1)
for i in range(H):
    for j in range(W):
        A = grid[i][j]
        note[A] = (i,j)

def cal(n):
    s = info[n][0]; e = info[n][1]
    cost = 0
    for A in range(s,e-D+1,D):
        i,j = note[A]; ni,nj = note[A+D]
        cost += abs(ni-i) + abs(nj-j)
    return cost

for i in range(Q):
    print(cal(i))

### FIXED CODE ###

H,W,D = map(int,input().split())
grid = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
info = [list(map(int,input().split())) for i in range(Q)]

note = [0]*(H*W+1)
for i in range(H):
    for j in range(W):
        A = grid[i][j]
        note[A] = (i,j)

cost = []
for s in range(D):
    acc = [0]
    tmp = 0
    for A in range(s,H*W+1-D,D):
        if s == 0 and A == 0:
            acc.append(tmp)
            continue
        i,j = note[A]; ni,nj = note[A+D]
        tmp += abs(ni-i) + abs(nj-j)
        acc.append(tmp)
    cost.append(acc)

def cal(n):
    L,R = info[n]
    index = L % D
    L = L // D; R = R // D
    ans = cost[index][R] - cost[index][L]
    return ans

for loop in range(Q):
    print(cal(loop))
### BUGGY CODE ###

import math
n, k = map(int, input().split())
a_in = list(map(int, input().split()))

diff_list = [0 for num in range(n)]
diff_list[0] = a_in[0]
for i in range(1, n):
    diff_list[i] = a_in[i] - a_in[i-1]

itr = k
if k > 41:
    itr = 41
for i in range(itr):
    new_list = [0 for num in range(n)]
    d_sum = 0
    for j, d in enumerate(diff_list):
        d_sum += d
        if j-d_sum > 0:
            new_list[j-d_sum] += 1
        else:
            new_list[0] += 1
        if d_sum+j+1 < n:
            new_list[j+d_sum+1] -= 1
    # print(new_list)
    diff_list = new_list.copy()

ans = 0
for d in diff_list:
    ans += d
    print(ans, end= ' ')


### FIXED CODE ###

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

diff_list = [0 for num in range(n)]
diff_list[0] = a_in[0]
for i in range(1, n):
    diff_list[i] = a_in[i] - a_in[i-1]

itr = k
if k > 41:
    itr = 41
for i in range(itr):
    new_list = [0 for num in range(n)]
    d_sum = 0
    for j, d in enumerate(diff_list):
        d_sum += d
        if j-d_sum > 0:
            new_list[j-d_sum] += 1
        else:
            new_list[0] += 1
        if d_sum+j+1 < n:
            new_list[j+d_sum+1] -= 1
    # print(new_list)
    diff_list = new_list.copy()

ans = 0
for d in diff_list:
    ans += d
    print(ans, end= ' ')
### BUGGY CODE ###

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



Asum=[0]
for i in A:
  if Asum[-1]+i>K:break
  Asum.append(Asum[-1]+i)
    
Bsum=[0]
for i in B:
  if Bsum[-1]+i>K:break
  Bsum.append(Bsum[-1]+i)

maxval=len(Asum)-1

tmp=0
for i in range(len(Asum)):
  for j in range(len(Bsum)):
    j=tmp+j
    if j>=len(Bsum)-1:j=len(Bsum)-1
    if Asum[-i-1]+Bsum[j]>K:
      maxval=max(maxval,len(Asum)-1-i+j-1)
      tmp=j
      break
    elif j==len(Bsum)-1:
      maxval=max(maxval,len(Asum)-1-i+j)
      
print(maxval)

### FIXED CODE ###

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

Asum=[0]
for i in A:
  if Asum[-1]+i>K:break
  Asum.append(Asum[-1]+i)
import numpy as np
Asum=np.array(Asum)
Bsum=[0]
for i in B:
  if Bsum[-1]+i>K:break
  Bsum.append(Bsum[-1]+i)
Bsum=np.array(Bsum)

maxval=len(Asum)-1

tmp=0
lenB=len(Bsum)
lenA=len(Asum)
for i in range(lenA):
  if lenA-1-i+lenB<maxval:break
  for j in range(lenB):
    j=tmp+j
    if Asum[-i-1]+Bsum[j]>K:
      maxval=max(maxval,len(Asum)-1-i+j-1)
      tmp=j
      break
    elif j==lenB-1:
      maxval=max(maxval,lenA-1-i+j)
      break
print(maxval)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
n , q = map(int,input().split())
point = [0] * n
edge = [[] for i in range(n)]

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

for _ in range(q):
    a , b = map(int,input().split())
    point[a-1] += b

def dfs(now, last=-1):
    for nxt in edge[now]:
        if nxt==last: continue
        point[nxt] += point[now]
        dfs(nxt, now)
dfs(0)
print(*point)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

n , q = map(int,input().split())
point = [0] * n
edge = [[] for i in range(n)]

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

for _ in range(q):
    a , b = map(int,input().split())
    point[a-1] += b

def dfs(now, last=-1):
    for nxt in edge[now]:
        if nxt==last: continue
        point[nxt] += point[now]
        dfs(nxt, now)
dfs(0)
print(*point)
### BUGGY CODE ###

x = [int(e) for e in input().split()]
a = x[0]
b = x[1]
c = x[2]
ans = 0
for i in range(a,b+1):
    if(c !=0)and(i%c)==0:
        ans+=1
print(ans)

### FIXED CODE ###

x = [int(e) for e in input().split()]
a = x[0]
b = x[1]
c = x[2]
ans = 0
ans = (b//c) - (a-1)//c 
print(ans)
### BUGGY CODE ###

import math
import heapq
xs,ys,xe,ye = map(int,input().split())
cs = [(xs,ys,0), (xe,ye,0)]
N = int(input())
for i in range(N):
    cs.append(tuple(map(int,input().split())))

def dist(x1,y1,x2,y2):
    dx,dy = x2-x1,y2-y1
    return math.sqrt(dx**2 + dy**2)

def calc_cost(i,j):
    if i == j: return float('inf')
    x1,y1,r1 = cs[i]
    x2,y2,r2 = cs[j]
    cost = max(0, dist(x1,y1,x2,y2) - r1 - r2)
    return cost

INF = float('inf')
direct = calc_cost(0,1)
hq = []
for i in range(1,N+2):
    c = calc_cost(0,i)
    if c > direct: continue
    hq.append((c,i))
heapq.heapify(hq)
visited = [1] + [0] * (N+1)
cost = [0] + [INF] * (N+1)
while hq:
    c,v = heapq.heappop(hq)
    if v == 1:
        print(c)
        exit()
    cost[v] = c
    visited[v] = 1
    for to in range(1,N+2):
        if to == v or visited[to]: continue
        newcost = calc_cost(v, to)
        if cost[to] <= cost[v] + newcost: continue
        if direct < cost[v] + newcost: continue
        heapq.heappush(hq, (cost[v] + newcost, to))

### FIXED CODE ###

import math,heapq,sys
input = sys.stdin.readline
xs,ys,xe,ye = map(int,input().split())
cs = [(xs,ys,0), (xe,ye,0)]
N = int(input())
for i in range(N):
    cs.append(tuple(map(int,input().split())))

def calc_cost(i,j):
    if i == j: return float('inf')
    x1,y1,r1 = cs[i]
    x2,y2,r2 = cs[j]
    cost = max(0, math.hypot(x1-x2,y1-y2) - r1 - r2)
    return cost

INF = float('inf')
direct = calc_cost(0,1)
hq = []
for i in range(1,N+2):
    c = calc_cost(0,i)
    if c > direct: continue
    hq.append((c,i))
heapq.heapify(hq)
not_visited = set(range(1,N+2))
cost = [0] + [INF] * (N+1)
while hq:
    c,v = heapq.heappop(hq)
    if v not in not_visited: continue
    if v == 1:
        print(c)
        exit()
    cost[v] = c
    not_visited.remove(v)
    for to in not_visited:
        newcost = calc_cost(v, to)
        if cost[to] <= cost[v] + newcost: continue
        if direct < cost[v] + newcost: continue
        heapq.heappush(hq, (cost[v] + newcost, to))
### BUGGY CODE ###

q=int(input())
n=10**5

work=[1 if i%2==1 else 0 for i in range(n+1)]
primes=[2]
lst=[0]*(n+1)
work[1]==0

for i in range(3,n,2):
    if not work[i]: continue
    primes.append(i)
    index=1
    while i*index<=n:
        work[i*index]=0
        index+=1

for i in primes[1:]:
    if (i+1)//2 in primes:
        lst[i]=1

for _ in range(q):
    left,right=map(int,input().split())
    print(sum(lst[left:right+1]))

### FIXED CODE ###

q=int(input())
n=10**5

work=[1 if i%2==1 else 0 for i in range(n+1)]
primes=[2]
lst=[0]*(n+1)
work[1]==0

for i in range(3,n,2):
    if not work[i]: continue
    primes.append(i)
    index=1
    while i*index<=n:
        work[i*index]=0
        index+=1

for i in primes[1:]:
    if (i+1)//2 in primes:
        lst[i]=1

for i in range(3,n+1):
    lst[i]+=lst[i-1]

for _ in range(q):
    left,right=map(int,input().split())
    print(lst[right]-lst[left-1])
### BUGGY CODE ###

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

buff = []
a = []
ans = 0
b = 0
for i in range(N):
    _a, _b = list(map(int, input().split()))
    b += _b
    a.append((_a, _b))
    # if b >= K and ans == 0:
    #     ans = _a
    # buff += [_a]*_b


a = sorted(a)

for i in range(N):
    buff += [a[i][0]] * a[i][1]

# buff = sorted(buff)
print(buff[K-1])


# print(ans)


### FIXED CODE ###

amax = 100000
cnt = [0 for i in range(amax+1)]


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

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


for ans in range(1, amax+1):
    if K <= cnt[ans]:
        print(ans)
        break
    K -= cnt[ans]
### BUGGY CODE ###

hlist = list(str(input()))
ch = 0
hh = 0
f = 0 #홍수구역인지 아닌지 판단
s = 0
slist = []
chlist = [0]
for i in range(len(hlist)):
    if (hlist[i] == '/'):
        ch += 1
    elif (hlist[i] == '\\' ):
        ch -= 1
    chlist.append(ch)
for i in range(len(hlist)):
    ch = chlist[i+1]
    d = ch - chlist[i]
    if (hh > max(chlist[i+1:])):
        hh = max(chlist[i+1:])
    elif (ch > hh):
        hh = ch
    elif (ch < hh):
        s += ((hh - ch) + d * 0.5)
    elif (ch == hh and chlist[i+1] == chlist[i] + 1):
        f = 0
        s += 1/2
        slist.append(s)
        s = 0


print(int(sum(slist)))
if len(slist) != 0:
    print(len(slist), end = ' ')
else:
    print(len(slist), end = '')
for i in range(len(slist)):
    if (i == len(slist) - 1):
        print(int((slist[i])), end = '')
    else:
        print(int((slist[i])), end = ' ')
print()


### FIXED CODE ###

s=j=0
a=[];b=[];d=[]
for i,x in enumerate(input()):
    if x=='\\':a+=[i]
    elif x=='/' and a:
        j=a.pop()
        c=i-j;s+=c
        while b and b[-1]>j:c+=d.pop();b.pop()
        b+=[j];d+=[c]
print(s)
print(len(b),*(d))
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A=[int(input()) for _ in range(Q)]
P = [K] * N



for A_ch in A:
    for i in range(N):
        if A_ch - 1 != i:
            P[i] -= 1 
        
for P_ch in P:
    if P_ch > 0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

N, K, Q = map(int, input().split())
P = [0] * N

for i in range(Q):
    P[int(input())-1] += 1
for i in range(N):
    ans = K - Q + P[i]
    # print(ans)
    if ans > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N,X,Y=map(int,input().split())

X-=1
Y-=1

dist={}

for k in range(N):
    dist[k]=0

for i in range(N):
    for j in range(N):
        dist[(min(abs(i-j),abs(i-Y)+abs(X-j)+1,abs(i-X)+abs(Y-j)+1))]+=1
for d in range(1,N):
    print(dist[d]//2)
    
    

### FIXED CODE ###

N,X,Y=map(int,input().split())

X-=1
Y-=1

dist=[0]*(N+1)


for i in range(N):
    for j in range(i+1,N):
        dist[(min(abs(i-j),abs(i-Y)+abs(X-j)+1,abs(i-X)+abs(Y-j)+1))]+=1
for d in range(1,N):
    print(dist[d])
### BUGGY CODE ###

def bit_add(bit, i, x):
    i += 1
    while i <= len(bit):
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def main():
    from sys import stdin
    from builtins import int, list, map, range
    readline = stdin.readline
    N, D, A = map(int, readline().split())
    XH = [list(map(int, readline().split())) for _ in range(N)]

    XH.sort()
    result = 0
    bit = [0] * (N + 1)
    for i in range(N):
        x, h = XH[i]
        h -= bit_sum(bit, i)
        if h <= 0:
            continue
        c = (h + A - 1) // A
        result += c
        bit_add(bit, i, c * A)

        ok = i
        ng = N
        while ng - ok != 1:
            m = ok + (ng - ok) // 2
            if XH[m][0] <= x + 2 * D:
                ok = m
            else:
                ng = m
        bit_add(bit, ng, -c * A)
    print(result)


main()


### FIXED CODE ###

N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
q = []
t = 0
result = 0
for x, h in XH:
    while True:
        if len(q) == 0:
            break
        if x <= q[0][0]:
            break
        t -= q[0][1]
        q.pop(0)
    h -= t
    if h < 0:
        continue
    c = (h + A - 1) // A
    result += c
    t += c * A
    q.append((x + 2 * D, c * A))
print(result)
### BUGGY CODE ###

import sys
from collections import defaultdict
n, m = map(int, sys.stdin.readline().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
dic = defaultdict(list)
for ele in a_b:
    dic[ele[0]].append(ele[1])

L =[]
money = 0
for d in range(1, m+1):
    L+= dic[d]
    if L:
        max_money = max(L)
        money +=max_money
        L.remove(max_money)
print(money)

### FIXED CODE ###

import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

for _ in range(n):
    a, b = map(int, input().split())
    dic[a].append(b)

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)
### BUGGY CODE ###

mod = 10**9+7
S = list(input())
Thankyou = 1
DP=[]
#DP[x][y] x+1文字目までを見たときの、
#y=0,1,2 : A,AB,ABCの登場回数
if S[0] == "A" or S[0]=="?":
    DP.append([1,0,0])
    if S[0]=="?":
        Thankyou = 3
else:
    DP.append([0,0,0])
for i,s in enumerate(S):

    if i==0:continue
    a,b,c = DP[i-1]
    if s=="A":
        DP.append([(a+Thankyou)%mod,b,c])
    elif s=="B":
        DP.append([a,(a+b)%mod,c])
    elif s=="C":
        DP.append([a,b,(b+c)%mod])
    else:
        DP.append([(Thankyou+3*a)%mod,(a+3*b)%mod,(b+3*c)%mod])
        Thankyou *= 3
print(DP[len(S)-1][2]%mod)

### FIXED CODE ###

mod = 10**9+7
S = list(input())
Thankyou = 1
DP=[]
#DP[x][y] x+1文字目までを見たときの、
#y=0,1,2 : A,AB,ABCの登場回数
if S[0] == "A" or S[0]=="?":
    DP.append([1,0,0])
    if S[0]=="?":
        Thankyou = 3
else:
    DP.append([0,0,0])
for i,s in enumerate(S):

    if i==0:continue
    a,b,c = DP[i-1]
    if s=="A":
        DP.append([(a+Thankyou)%mod,b,c])
    elif s=="B":
        DP.append([a,(a+b)%mod,c])
    elif s=="C":
        DP.append([a,b,(b+c)%mod])
    else:
        DP.append([(Thankyou+3*a)%mod,(a+3*b)%mod,(b+3*c)%mod])
        Thankyou *= 3
        Thankyou %= mod
print(DP[len(S)-1][2]%mod)
### BUGGY CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))

mx = []

for i in range(N-K+1):
    mx.append(sum(p[i:i+K]))

print((max(mx)+K)/2)

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))

S = [0]
E = []

for i in range(0, N):
    S.append(S[i]+p[i])

for i in range(0, N-K+1):
    E.append(S[i+K]-S[i])


print((max(E)+K)/2)
### BUGGY CODE ###

d = int(input())
t = 0 
while True:
  if t*(t+1)//2 >=d:
    print(t)
    exit()

### FIXED CODE ###

x = int(input())
i = 0
n = 1
while n <=x:
    n +=i
    i +=1
    
print(i-1)
### BUGGY CODE ###

n= int(input())

list= list(map(int, input().split()))
cnt=0

for i in range(n):
	if cnt<n:	
		listi=list[cnt:]	
		a=listi.count(i+1)
		cnt+=a
		print(a)
	else:
		print(0)

### FIXED CODE ###

n = int(input())
lis = list(map(int, input().split()))
cnt = [0]*(n)

for i in range(n-1):
	cnt[lis[i]-1]+=1

for i in range(n):
	print(cnt[i])
### BUGGY CODE ###

# C - management

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

for i in range(1, N + 1): print(A.count(i))


### FIXED CODE ###

# C - management

N = int(input())
A = [0] * N
for a in [*map(int, input().split())]: A[a - 1] += 1
print(*A, sep='\n')
### BUGGY CODE ###


def q3():
    import math
    k = int(input())
    sum_n = 0
    gcd_2_dict = {}

    def gcd(n1, n2):
        key = tuple([n1, n2])
        if key in gcd_2_dict:
            return gcd_2_dict[key]
        gcd_num = math.gcd(n1, n2)
        gcd_2_dict[key] = gcd_num
        return gcd_num

    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sorted_nums = sorted([a, b, c])
                sum_n += gcd(gcd(sorted_nums[0], sorted_nums[1]), sorted_nums[2])

    print(sum_n)

q3()

### FIXED CODE ###


from math import gcd

K = int(input())

a = 0
for ai in range(1, K + 1):
  for bi in range(1, K + 1):
    gcd_ab = gcd(ai, bi)
    for ci in range(1, K + 1):
      a += gcd(gcd_ab, ci)

print(a)