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

import fractions
import functools
N=int(input())
A=[int(i) for i in input().split()] 
#max_gcd=functools.reduce(fractions.gcd, A)
max_gcd = 1
for i in range(N):
	tmp=A.copy()
	tmp.pop(i)
	gcd=functools.reduce(fractions.gcd, tmp)
	if max_gcd<gcd:
		max_gcd=gcd
print(max_gcd)


### FIXED CODE ###

# -*- coding: utf-8 -*-

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

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

# GCDの結合則を利用する
# 左端、右端からの累積GCDを求めておくと、Aiを取り除いた場合のGCDがすぐに計算できる。
# つまり、
# L(i): n=0,...,iまでのGCD 
# R(i): n=i,...,N-1までのGCD
# このとき、Aiを除いた全体のGCDは、GCD(L(i-1), R(i+1))で計算できる。

L = [0] * N
R = [0] * N

L[0] = A[0]
R[-1] = A[-1]
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i])
    idx = N-1-i
    R[idx] = gcd(R[idx+1], A[idx])

mx = 0
for i in range(N):
    if i == N-1:
        v = L[N-2]
    elif i == 0:
        v = R[1]
    else:
        v = gcd(R[i+1], L[i-1])
    mx = max(v, mx)
print(mx)
### BUGGY CODE ###

import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n, c, k = ns()
    t = [ni() for _ in range(n)]
    t.sort()
    
    ans = 0
    while True:
        for i, ti in enumerate(t):
            if ti-t[0] > k:
                t = t[i:]
                break
            elif i+1 >= c:
                t = t[i+1:]
                break

        ans += 1

        if len(t) == 0 or i == len(t) - 1:
            break

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n, c, k = ns()
    t = [ni() for _ in range(n)]
    t.sort()

    ans = 0
    idx = 0
    while True:
        ans += 1

        k_idx = bisect.bisect_right(t, t[idx] + k)
        c_idx = idx + c

        idx = min(k_idx, c_idx)
        if idx > n-1:
            break

    print(ans)


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

from collections import deque
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
maze=[]

for i in range(H):
  l=list(input())
  for j in range(len(l)):
    if l[j]=='.':l[j]=-1
    if l[j]=='#':l[j]=-2
  maze.append(l)

def isIn(h,w):
  if h<0 or h>=H or w<0 or w >=W:return False
  return True
l=[[Ch-1,Cw-1]]
l=deque(l)
maze[Ch-1][Cw-1]=0
while l:
  vectors=[[-1,0],[1,0],[0,1],[0,-1]]

  target=l[0]
  h,w=target
  l.popleft()
  for vector in vectors:
    if not isIn(h+vector[0],w+vector[1]):continue
    if maze[h+vector[0]][w+vector[1]]>maze[h][w] or maze[h+vector[0]][w+vector[1]]==-1:
      maze[h+vector[0]][w+vector[1]]=maze[h][w]
      l.appendleft([h+vector[0],w+vector[1]])
  for i in range(25):
    if not isIn(h+i//5-2,w+i%5-2):continue
    if maze[h+i//5-2][w+i%5-2]>maze[h][w] or maze[h+i//5-2][w+i%5-2]==-1:
      maze[h+i//5-2][w+i%5-2]=maze[h][w]+1
      l.append([h+i//5-2,w+i%5-2])
print(maze[Dh-1][Dw-1])


### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
maze=[]

for i in range(H):
  l=list(input())
  for j in range(len(l)):
    if l[j]=='.':l[j]=-1
    if l[j]=='#':l[j]=-2
  maze.append(l)

def isIn(h,w):
  if h<0 or h>=H or w<0 or w >=W:return False
  return True
l=[[Ch-1,Cw-1]]
l=deque(l)
maze[Ch-1][Cw-1]=0
l2=[[0]*W for i in range(H)]

cnt=0
while l:
  cnt+=1
  vectors=[[-1,0],[1,0],[0,1],[0,-1]]

  target=l[0]
  h,w=target
  l.popleft()
  if l2[h][w]:
    continue
  l2[h][w]=1
  for vector in vectors:
    if not isIn(h+vector[0],w+vector[1]):continue
    if maze[h+vector[0]][w+vector[1]]>maze[h][w] or maze[h+vector[0]][w+vector[1]]==-1:
      maze[h+vector[0]][w+vector[1]]=maze[h][w]
      l.appendleft([h+vector[0],w+vector[1]])
  for i in range(25):
    if not isIn(h+i//5-2,w+i%5-2):continue
    if maze[h+i//5-2][w+i%5-2]>maze[h][w] or maze[h+i//5-2][w+i%5-2]==-1:
      maze[h+i//5-2][w+i%5-2]=maze[h][w]+1
      l.append([h+i//5-2,w+i%5-2])
print(maze[Dh-1][Dw-1])
### BUGGY CODE ###

import sys
from heapq import *
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    
    key = []
    for i in range(n):
        s, t, x = map(int, input().split())
        l, r = max(0, s-x), max(0, t-x)
        key.append((l, 1, x))
        key.append((r, -1, x))

    key.sort()
    judge = []
    now = set()
    already = dict()
    
    index = 0
    ans = -1
    for i in range(q):
        d = int(input())
        for i in range(index, 2*n):
            s, j, x = key[i]
            if s > d:
                index = i
                break
            if j == 1:
                heappush(judge, x)
                now = now.union({x})
            else:
                now.discard(x)
                if x in already:
                    already[x] += 1
                else:
                    already[x] = 1
                    
                    
        while judge:
            if judge[0] in already and already[judge[0]] > 0:
                already[judge[0]] -= 1
                heappop(judge)
            else:
                break
        if judge:
            ans = judge[0]
        else:
            ans = -1      
            
        print(ans)

    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from heapq import *
input = sys.stdin.readline

def main():
    n, q = map(int, input().split())
    
    key = []
    for i in range(n):
        s, t, x = map(int, input().split())
        l, r = max(0, s-x), max(0, t-x)
        key.append((l, 1, x))
        key.append((r, -1, x))
    
    for i in range(q):
        d = int(input())
        key.append((d, 2))

    key.sort()
    judge = []
    already = dict()
    
    for i in range(2*n+q):
        k = key[i]
        if k[1] == -1:
            if k[2] in already:
                already[k[2]] += 1
            else:
                already[k[2]] = 1
        elif k[1] == 1:
            heappush(judge, k[2])
        else:
            while judge:
                if judge[0] in already and already[judge[0]] > 0:
                    already[judge[0]] -= 1
                    heappop(judge)
                else:
                    break
            if judge:
                print(judge[0])
            else:
                print(-1)
    

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

import sys

def insertHeap(H, A, key):
    A.append(key)
    i = H + 1

    while i > 1 and A[i] > A[i // 2]:
        A[i], A[i // 2] = A[i // 2], A[i]
        i //= 2

def popHeap(H, A):
    max_ = A[1]

    A[1] = A[H]
    A.pop()
    maxHeapify(H - 1, A, 1)

    return max_

def maxHeapify(H, A, i):
    left = 2 * i
    right = 2*i + 1

    if left <= H and A[left] > A[i]:
        largest = left
    else:
        largest = i
    if right <= H and A[right] > A[largest]:
        largest = right

    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapify(H, A, largest)

def buildMaxHeap(H, A):
    for i in range(H // 2, 0, -1):
        maxHeapify(H, A, i)

H = 0
A = [None]

while 1:
    cmd = sys.stdin.readline().split()
    # print(A, file=sys.stderr)

    if cmd[0] == 'end':
        break

    if cmd[0] == 'extract':
        print(popHeap(H, A))
        H -= 1
    else:
        insertHeap(H, A, int(cmd[1]))
        H += 1

### FIXED CODE ###

import sys
from heapq import heappush, heappop

heap = []

while 1:
    cmd = sys.stdin.readline().split()

    if cmd[0] == 'end':
        break

    if cmd[0] == 'extract':
        print(-heappop(heap))
    else:
        heappush(heap, -int(cmd[1]))
### BUGGY CODE ###

import bisect

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)

ans = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    min_sum = L[i]+L[j]
    more_than = bisect.bisect_left(L[j+1:], min_sum)
    ans += more_than
print(ans)

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += bisect_left(L, L[i]+L[j])-j-1
print(ans)
### BUGGY CODE ###

# 厳しい
n, s = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
W_MAX = s
dp = [[0]*(n+1) for _ in range(W_MAX+1)]
dp[0][0] = 1

for i in range(n):
    a = A[i]
    for j in reversed(range(W_MAX+1)):
        for k in range(n):
            if W_MAX < j+a:
                continue
            dp[j+a][k+1] += dp[j][k]

ans = 0
for k in range(1, n+1):
    cnt = dp[-1][k]
    ans += cnt*pow(2, n-k, MOD)
print(ans % MOD)

### FIXED CODE ###

n, s = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
W_MAX = s
dp = [0]*(W_MAX+1)
dp[0] = 1
inv_2 = pow(2, MOD-2, MOD)
for a in A:
    for j in reversed(range(W_MAX+1)):
        if W_MAX < j+a:
            continue
        dp[j+a] += dp[j]*inv_2
        dp[j+a] %= MOD

print(dp[-1]*pow(2, n, MOD) % MOD)
### BUGGY CODE ###

import sys
import itertools
input = sys.stdin.readline

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

vv = []
for v in itertools.combinations(S[0:-1], 3):
	vv.append(str(v))
print(len(list(set(vv))))


### FIXED CODE ###

import sys
import itertools
input = sys.stdin.readline

N = int(input())
S = input()
cc = [0]*1000
ans = [0]*1000
for j in range(len(S)-1):
	p = int(S[j])
	for i in range(1000):
		if(p==i%10 and cc[i]==2):
			cc[i]+=1
			ans[i]=1
		elif(p==(i//10)%10 and cc[i]==1):
			cc[i]+=1
		elif(p==i//100 and cc[i]==0):
			cc[i]+=1
print(sum(ans))
### BUGGY CODE ###

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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if S[i] == S[j]:
            equal = 1
            for k in range(1, min(j-i, N-j)):
                if S[i+k] == S[j+k]:
                    equal += 1
                else:
                    break
            ans = max(ans, equal)

print(ans)

### FIXED CODE ###

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

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-1, -1, -1):
    for j in range(N-1, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1

ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(dp[i][j], j-i)
        ans = max(ans, now)

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

def main():
    s = list(map(int, list(input())))
    m = [0]*2019
    num = 0
    ans = 0
    n = len(s)
    ten = [(10**i)%2019 for i in range(n)]
    for i in range(n):
        num += s[n-i-1]*ten[i]
        num %= 2019
        m[num] += 1 
    for mi in m:
        if mi:
            ans += (mi*(mi-1))//2
    ans += m[0]
    print(ans)
        
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    s = list(map(int, list(input())))
    m = [0]*2019
    num = 0
    ans = 0
    n = len(s)
    ten = 1
    for i in range(n):
        num += s[n-i-1]*ten
        num %= 2019
        m[num] += 1 
        ten = (ten*10)%2019
    for mi in m:
        if mi:
            ans += (mi*(mi-1))//2
    ans += m[0]
    print(ans)
        
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

ans = 1
INF = 10 ** 18
for n in a:
    ans *= n

if ans > INF:
    ans = -1

print(ans)


### FIXED CODE ###

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

INF = 10 ** 18
ans = 1
if any([n == 0 for n in a]):
    print(0)
    exit()

for n in a:
    ans *= n
    if ans > INF:
        ans = -1
        break
print(ans)
### BUGGY CODE ###

H = int(input())

count = 0
while True:
    H //= 2
    count += 1
    if H == 1:
        break

total = 0
for n in range(count + 1):
    total += 2 ** n

print(total)


### FIXED CODE ###

import math
H = int(input())

count = 0
count = int(math.log2(H))

total = 0
total = int((1 - (2**(count + 1)))/(1 - 2))
print(total)
### BUGGY CODE ###

N = int(input())
s = ['']*N
ans = 0
for i in range(N):
    s[i] = ''.join(sorted(input()))
    if i != 0:
        for j in range(i):
#            print(i, j)
            if s[i] == s[j]:
                ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]

ans = 0
d = {}
for i in s:
    if i in d:
        ans += d[i]
        d[i] += 1
    else:
        d[i] = 1
print(ans)
### BUGGY CODE ###

from collections import deque
import sys 
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
n, m = map(int, input().split())
adjacent_list = [[] for i in range(n+1)]
not_root = set()
for i in range(m):
    x, y = map(int, input().split())
    not_root.add(y)
    adjacent_list[x].append(y)
root_cand = set(list(range(1, n+1))) - not_root
root_cand = deque(root_cand)
dp = [0] * (n+1)
def dfs(node, count):
    dp[node] = max(dp[node], count + 1)
    if len(adjacent_list[node]) != 0:
        for i in adjacent_list[node]:
            if dp[i] <= dp[node]:
                dfs(i, dp[node])
while len(root_cand) != 0:
    root = root_cand.pop()
    dfs(root, -1)
print(max(dp))


### FIXED CODE ###

from collections import deque
import sys 
input = sys.stdin.readline
sys.setrecursionlimit(10**5)
n, m = map(int, input().split())
adjacent_list = [[] for i in range(n+1)]
not_root = set()
for i in range(m):
    x, y = map(int, input().split())
    not_root.add(y)
    adjacent_list[x].append(y)
dp = [-1 for i in range(n+1)]
def cul(x):
    if dp[x] != -1:
        return dp[x]
    else:
        if len(adjacent_list[x]) == 0:
            return 0
        dp[x] = max([cul(i) + 1 for i in adjacent_list[x]])
        return dp[x]
for i in range(1,n+1):
    cul(i)
print(max(dp))
### BUGGY CODE ###

S = input()

N = len(S)

mod2019 = []
ans = 0

mod2019.append(0)

for i in range(1,N+1):
  Smod = mod2019[i-1] + int(S[N-i])*10**(i-1)
  mod2019.append(Smod%2019)

for i in range(2019):
  m = mod2019.count(i)
  ans += (m*(m-1))//2



print(ans)

### FIXED CODE ###

S = input()
counts =[0] * 2019
counts[0] = 1
num, d = 0,1

for s in S[::-1]:
  num += int(s) *d
  d *= 10
  num %= 2019
  d %= 2019
  counts[num] += 1

ans = 0
for count in counts:
  ans += count * (count - 1) //2
print(ans)
### BUGGY CODE ###

n = int(input())
print(sum(range(n)))

### FIXED CODE ###

n = int(input())
print(sum(range(n)))
### BUGGY CODE ###

def absFunc(A_, b):
    result = 0
    for a_ in A_:
        result += abs(a_ - b)
    return result
    
input()
A = list(map(int, input().split()))
A_ = []

for i, a in enumerate(A):
    A_.append(a - i - 1)

b = 0
result_o = absFunc(A_, b)
result_n = 0

while True:
    b += 1
    result_n = absFunc(A_, b)
    
    if result_n < result_o:
        result_o = result_n
        continue
    break

b = 0
while True:
    b -= 1
    result_n = absFunc(A_, b)
    
    if result_n < result_o:
        result_o = result_n
        continue
    break

print(result_o)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A_ = []
result = 0

for i, a in enumerate(A):
    A_.append(a - i - 1)

b = sorted(A_)[N//2]

for a_ in A_:
    result += abs(a_ - b)

print(result)
### BUGGY CODE ###

from collections import deque
from itertools import combinations

H, W = map(int, input().split())
c = [list(input()) for _ in range(H)]

points = []
for i in range(H):
    for j in range(W):
        if c[i][j] == '.':
            points.append((j, i))

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]        
def bfs(start, goal):
    s = [[-1] * W for _ in range(H)]
    d = [[0] * W for _ in range(H)]

    sx, sy = start
    gx, gy = goal

    que = deque([])
    que.append((sx, sy))
    s[sy][sx] = 1
    
    while que:
        x, y = que.popleft()
        s[y][x] = 1

        if x == gx and y == gy:
            return d[y][x]
        
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if 0 <= nx < W and 0 <= ny < H and s[ny][nx] != 1 and c[ny][nx] == '.':
                que.append((nx, ny))
                d[ny][nx] = d[y][x] + 1

ans = 0
for comb in combinations(points, 2):
    start, goal = comb
    ans = max(ans, bfs(start, goal))

print(ans)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
c = [list(input()) for _ in range(H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(sx, sy):
    d = [[-1] * W for _ in range(H)]

    que = deque([])
    que.append((sx, sy))
    d[sy][sx] = 0

    res = 0
    while que:
        x, y = que.popleft()

        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]

            if 0 <= nx < W and 0 <= ny < H and d[ny][nx] == -1 and c[ny][nx] == '.':
                que.append((nx, ny))
                tmp = d[y][x] + 1
                d[ny][nx] = tmp
                res = max(res, tmp)

    return res

ans = 0
for i in range(H):
    for j in range(W):
        if c[i][j] == '.':
            tmp = bfs(j, i)
            ans = max(ans, tmp)

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

N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]

table = {i: [0]*(W+1) for i in range(N+1)}
def dp(N, W):
  for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(1, W+1):
      if w <= j:
        table[i][j] = max(table[i-1][j-w]+v, table[i-1][j])
      else:
        table[i][j] = table[i-1][j]
  return table[N][W]

print(dp(N, W))

### FIXED CODE ###

N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]

table = {i: [0]*(W+1) for i in range(N+1)}
def dp(N, W):
  for i in range(1, N+1):
    w, v = items[i-1]
    for j in range(1, W+1):
      if w <= j:
        table[i][j] = max(table[i-1][j-w]+v, table[i-1][j])
      else:
        table[i][j] = table[i-1][j]
  return table[N][W]

print(dp(N, W))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1
MOD = 10 ** 9 + 7


S = input().rstrip()
length = len(S)
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1  # 桁数

for i in range(length):
    x = S[-(i + 1)]
    if x == '?':
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j] % MOD
    else:  # 数字
        for j in range(13):
            dp[i + 1][(mul * int(x) + j) % 13] += dp[i][j] % MOD
    mul = mul * 10 % 13

print(dp[-1][5] % MOD)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1
MOD = 10 ** 9 + 7


S = input().rstrip()
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1  # 桁数

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == '?':
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= MOD
    else:  # 数字
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= MOD
    mul = mul * 10 % 13

print(dp[len(S)][5])
### BUGGY CODE ###

import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import lil_matrix

N, X, Y = [int(_) for _ in input().split()]
G = lil_matrix((N, N))
G[X - 1, Y - 1] = 1
for i in range(N - 1):
    G[i, i + 1] = 1
D = floyd_warshall(G, directed=False)
for i in range(1, N):
    print(np.sum(D == i) // 2)


### FIXED CODE ###

import numpy as np
N, X, Y = [int(_) for _ in input().split()]
X -= 1
Y -= 1
cnt = np.zeros(N, dtype=int)
for i in range(0, (X + Y) // 2):
    #t-i<=abs(i-X)+1+Y-t
    #2*t<=abs(i-X)+1+Y+i
    #t<= tmax = 0 - - (abs(i-X)+1+Y+i)//2
    #tmin=i-X+1
    #range(tmin,tmin+Y-tmax) + range(1,tmax-i+1) + range(tmin+1,tmin+N-Y)
    tmin = abs(i - X) + 1
    tmax = 0 - -(abs(i - X) + 1 + Y + i) // 2
    cnt[1:tmax - i] += 1
    cnt[tmin:tmin + Y - tmax + 1] += 1
    cnt[tmin + 1:tmin + N - Y] += 1
for i in range((X + Y) // 2, N):
    cnt[1:N - i] += 1
print(*cnt[1:], sep='\n')
### BUGGY CODE ###

from bisect import insort_left as sort

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
list = sorted(list)
for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      sort(temp,list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans += temp.pop()
print(ans)

### FIXED CODE ###

import heapq as hp
import sys
def input():
    return sys.stdin.readline()

n,m = map(int,input().split())
list = [[int(i) for i in input().split()] for i in range(n)]
temp = [0]
ans = 0
a = 0
j = 0
list = sorted(list)

for i in range(1,1+m):
  for j in range(a,len(list)):
    if list[j][0] == i:
      hp.heappush(temp,-list[j][1])
    else:
      a = j
      break
  if len(temp) > 0:
    ans -= hp.heappop(temp)
print(ans)
### BUGGY CODE ###

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

max_=0
for _ in range(n-1):
  res=li[0]
  del li[0]
  ans=max(li)
  if ans>max_:
    print(ans)
  else:
    print(max_)
  if res>max_:
    max_=res
    
print(max_)

### FIXED CODE ###

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

lis=sorted(li)
max1=lis[-1]
max2=lis[-2]
for i in li:
  if(i==max1):
    print(max2)
  else:
    print(max1)
### BUGGY CODE ###

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

for i in range(M):
  B, C = map(int, input().split())
  for j in range(B):
    A.append(C)

print( sum(sorted(A, reverse=True)[:N]) )

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
D = [(A[i], 1) for i in range(N)]

for i in range(M):
  B, C = (map(int, input().split()))
  D.append((C, B))
  
D.sort()
D.reverse()

ans, left = 0, N
for (i, j) in D:
    use = min(j, left)
    ans += use * i
    left -= use
print(ans)
### BUGGY CODE ###

import numpy as np
from time import time
N = int(input())
s = list(map(int,input().split()))
s = np.array(s).astype(np.int64)

start = time()
ans = 0
for c in range(1,N-1):
    ltor = np.cumsum(s[::c])
    rtol = np.cumsum(s[N-1::-c])

    cand = np.array([A for A in range(N-1-c,c,-c) if A % c != 0 or 2*A-c >= N-1])
    if cand.size > 0:
        indexes = (N-1-cand)//c
        temp = ltor[indexes] + rtol[indexes]
        ans = max(ans,np.max(temp))

print(ans)



### FIXED CODE ###

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

ans = 0
for c in range(1,N-1):
    ltor = [0]
    for p in s[::c]:
        ltor.append(ltor[-1] + p)
    rtol = [0]
    for p in s[N-1::-c]:
        rtol.append(rtol[-1] + p)
    A = N-1-c
    while c < A:
        if A % c == 0 and A + c * (A//c-1) < N-1:
            break
        ind = (N-1-A)//c+1
        temp = ltor[ind] + rtol[ind]
        ans = max(temp,ans)
        A -= c

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

n=int(input())
a=list(map(int,input().split()))
if n%2==0:
  for i in range(0,n,2):
    if a.count(i+1)!=2:
        print(0)
        exit()
else:
  if a.count(0)==1:
    for i in range(2,n,2):
      if a.count(i)!=2:
        print(0)
        exit()
  else:
    print(0)
    exit()
    
print(2**(n//2))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
a.sort()
if n%2==0:
  for i in range(0,n,2):
    if a[i]!=i+1 or a[i+1]!=i+1:
        print(0)
        exit()
else:
  if a[0]!=0:
    print(0)
    exit()
  for i in range(2,n,2):
    if a[i-1]!=i or a[i]!=i:
      print(0)
      exit()
      
print((2**(n//2))%(10**9+7))