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

import sys

def main():

	input = sys.stdin.readline

	N = int(input().strip())
	P = list(map(int,input().strip().split()))

	ips = [0]*(N)
	for i, val in enumerate(P):
		ips[val-1] = i
	P.sort(reverse=True)

	x = 0
	largeind = [-1,-1,N,N]
	for i in range(N):
		target = ips[P[i]-1]

		larger = len(largeind)-2
		smaller = 1
		while larger-smaller!=1:
			medium = int((larger+smaller)/2)
			if largeind[medium]>target:
				larger = medium
			else:
				smaller = medium
		# largeind.insert(larger,target)
		largeind[larger:larger]=[target]

		L1ind = largeind[larger-1]
		L2ind = largeind[larger-2]
		R1ind = largeind[larger+1]
		R2ind = largeind[larger+2]

		x += ((L1ind-L2ind)*(R1ind-target) + (target-L1ind)*(R2ind-R1ind))*P[i]

	print(x)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

def main():

	input = sys.stdin.readline

	N = int(input().strip())
	P = list(map(int,input().strip().split()))

	RR = [i+1 for i in range(N)]
	LL = [i-1 for i in range(N)]
	ips = [0]*(N)
	for i, val in enumerate(P):
		ips[val-1] = i
	P.sort()

	x = 0
	for i in range(N):
		target = ips[P[i]-1]
		R1ind = RR[target]
		R2ind = RR[ min(R1ind,N-1) ]
		L1ind = LL[target]
		L2ind = LL[ max(L1ind,0) ]

		x += ((L1ind-L2ind)*(R1ind-target) + (target-L1ind)*(R2ind-R1ind))*P[i]

		if L1ind!=-1:
			RR[L1ind] = R1ind
		if R1ind!=N:
			LL[R1ind] = L1ind

	print(x)

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

def main():
	n,p = map(int,input().split())
	s = [int(c) for c in input()] 
	num = 0
	ans = 0
	if p == 2 or p == 5:
		for i in range(n):
			if s[i]%p == 0:
				ans += i+1	
		print(ans)
		exit()
	arr = [0]*p
	s = s[::-1]
	arr[0]=1
	z = 1
	t = 0
	for ss in s:
		t = (t + z*ss)%p	
		z *=10 %p
		arr[t] += 1
	for l in arr:
		ans += l * (l - 1) // 2
	print(ans)
if __name__ == '__main__':
	main()


### FIXED CODE ###

def main():
	N,P = map(int,input().split())
	S = [int(s) for s in list(input().strip())][::-1]
	num = 0
	ans = 0
	if P == 2 or P == 5:
		for i in range(N):
			if S[i]%P == 0:
				ans += N-i
		print(ans)
		return
	L = [0]*P
	L[0]=1
	t = 0
	s = 1
	for z in S:
		t = (z*s+t)%P	
		L[t]+=1
		s=s*10%P
	for l in L:
		ans += l * (l - 1) // 2
	print(ans)

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

L, R = map(int, input().split())
a = 0
b = 2019
for i in range(L, R):
    for j in range(i + 1, R + 1):
        a = i * j % 2019
        if a <= b:
            b = a

print(b)


### FIXED CODE ###

L, R = map(int, input().split())
a = 0
b = 2019
if R - L >= 2018:
    b = 0
else:
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            a = i * j % 2019
            if a <= b:
                b = a

print(b)
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split()))
ans = 0
for i, pi in enumerate(P):
    if all([pi < pj for pj in P[:i]]):
        ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
pp = P[0]
ans = 0
for p in P:
    if p <= pp:
        ans += 1
        pp = p
print(ans)
### BUGGY CODE ###

s=input()
t=int(input())
u=[input().split()for i in range(t)]
a=0
for i in range(t):
  if u[i][0]=='1':
    a+=1
  else:
    if u[i][1]=='1':
      if a%2==0:
        s=u[i][2]+s
      else:
        s=s+u[i][2]
    else:
      if a%2==0:
        s=s+u[i][2]
      else:
        s=u[i][2]+s
if a%2==0:
  print(s)
else:
  print(s[::-1])

### FIXED CODE ###

s=input()
t=int(input())
u=[input().split()for i in range(t)]
a=0
b=''
c=''
for i in range(t):
  if u[i][0]=='1':
    a+=1
  else:
    if u[i][1]=='1':
      if a%2==0:
        b=b+u[i][2]
      else:
        c=c+u[i][2]
    else:
      if a%2==0:
        c=c+u[i][2]
      else:
        b=b+u[i][2]
if a%2==0:
  b=b[::-1]
  s=b+s+c
  print(s)
else:
  s=s[::-1]
  c=c[::-1]
  s=c+s+b
  print(s)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
now='.'
ans=0
x,y=0,0
if S[x][y]=='#':
  ans+=1
  now='#'
  
def findroot(x,y,S,d,now):
  global nextkouho
  nextkouho.add((x,y))
  if x<H-1 and S[x+1][y]==now:
    findroot(x+1,y,S,d+1,now)
  if y<W-1 and S[x][y+1]==now:
    findroot(x,y+1,S,d+1,now)
kouho=[(0,0)]
while 1:
  nextkouho=set()
  for x,y in kouho:
    if x<H-1 and S[x+1][y]==now:
      findroot(x+1,y,S,0,now)
    else:
      nextkouho.add((x,y))
    if y<W-1 and S[x][y+1]==now:
      findroot(x,y+1,S,0,now)
    else:
      nextkouho.add((x,y))
  if (H-1,W-1) in nextkouho:
    break
  if now=='#':
    now='.'
  else:
    ans+=1
    now='#'
  kouho=list(nextkouho)
  #print(nextkouho,kouho,now,ans)
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
dp=[0]*W
if S[0][0]=='#':
  dp[0]=1
for j in range(1,W):
  if S[0][j]!=S[0][j-1] and S[0][j-1]=='.':
    dp[j]=dp[j-1]+1
  else:
    dp[j]=dp[j-1]
for i in range(1,H):
  if S[i][0]!=S[i-1][0] and S[i-1][0]=='.':
    dp[0]=dp[0]+1
  for j in range(1,W):
    hidari=1 if S[i][j]!=S[i][j-1] and S[i][j-1]=='.' else 0
    ue=1 if S[i][j]!=S[i-1][j] and S[i-1][j]=='.' else 0
    dp[j]=min(dp[j-1]+hidari,dp[j]+ue)
print(dp[-1])
### BUGGY CODE ###

k, s = map(int, input().split())

cnt = 0
for i in range(k + 1):
  for j in range(k + 1):
    for k in range(k + 1):
      if i + j + k == s:
        cnt += 1

print(cnt)


### FIXED CODE ###

k, s = map(int, input().split())

cnt = 0
for i in range(k + 1):
  for j in range(k + 1):
      if 0 <= s - (i + j) <= k:
        cnt += 1

print(cnt)
### BUGGY CODE ###

import itertools
from collections import deque

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

ans = [-1] * N
ans[0] = 0
d = deque([1])
while any(i == -1 for i in ans) and len(d) != 0:
    now = d[0]
    d.popleft()
    for i in itertools.product(range(M), range(2)):
        if AB[i[0]][i[1]] == now:
            if ans[AB[i[0]][1 - i[1]] - 1] == -1:
                ans[AB[i[0]][1 - i[1]] - 1] = now
                d.append(AB[i[0]][1 - i[1]])

if any(i == -1 for i in ans):
    print('No')
else:
    print('Yes')
    for i in ans[1:]:
        print(i)


### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
g = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    g[A-1].append(B)
    g[B-1].append(A)

ans = [-1] * N
ans[0] = 0
d = deque([1])
while len(d) != 0:
    now = d[0]
    d.popleft()
    for i in g[now-1]:
        if ans[i-1] != -1:
            continue
        ans[i-1] = now
        d.append(i)

if -1 in ans:
    print('No')
else:
    print('Yes')
    for i in ans[1:]:
        print(i)
### BUGGY CODE ###

from os import path
import sys
if(path.exists('C:/Users/prana/Desktop/sublime/input.txt')):
    sys.stdin = open("C:/Users/prana/Desktop/sublime/input.txt","r")
    sys.stdout = open("C:/Users/prana/Desktop/sublime/output.txt","w")

import math
def solve():
    ans = 0
    a = int(input()) 
    for i in range(a):
        for j in range(a):
            for k in range(a):
                ans += math.gcd(k+1,math.gcd(i+1,j+1))
    print(ans)

test_case = 1
while(test_case):
    solve()
    test_case -= 1

### FIXED CODE ###

from os import path
if(path.exists('C:/Users/prana/Desktop/sublime/input.txt')):
    import sys
    sys.stdin = open("C:/Users/prana/Desktop/sublime/input.txt","r")
    sys.stdout = open("C:/Users/prana/Desktop/sublime/output.txt","w")

from math import gcd
def solve():
    ans = 0
    a = int(input()) 
    for i in range(a):
        for j in range(a):
            for k in range(a):
                ans += gcd(k+1,gcd(i+1,j+1))
    print(ans)

test_case = 1
while(test_case):
    solve()
    test_case -= 1
### BUGGY CODE ###

K, S = map(int, input().split())

ans = 0

for X in range(K+1):
    for Y in range(K+1):
        for Z in range(K+1):
            if X + Y + Z == S:
                ans += 1

print(ans)  

### FIXED CODE ###

K, S = map(int, input().split())

ans = 0

for X in range(K+1):
    for Y in range(K+1):
        Z = S - (X + Y)
        if 0 <= Z <= K:
            ans += 1

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

n,m = map(int,input().split())

p_list=[]
cnt=[0]*(n+1)
ans=0
plt=0
for i in range(m):
    p,s=map(str,input().split())
    
    if s == "WA":
        cnt[int(p)] += 1;
    if s == "AC":
        if p not in p_list:
            ans+=1
            plt+=cnt[int(p)]
            p_list.append(p)
        
print(str(ans) + " " + str(plt))



### FIXED CODE ###

n,m = map(int,input().split())

p_list=[0]*(n+1)
cnt=[0]*(n+1)
ans=0
plt=0
for i in range(m):
    p,s=map(str,input().split())
    if s == "WA":
        cnt[int(p)] += 1;
    if s == "AC":
        if p_list[int(p)] == 0:
                ans+=1
                plt+=cnt[int(p)]
                p_list[int(p)] += 1
        
print(str(ans) + " " + str(plt))
### BUGGY CODE ###

n = int(input())
ab = [list(map(int, (input()+' '+str(i)).split())) for i in range(n-1)]
ab.sort()
uc = [0]*n
coloring = [0]*(n-1)
for i in range(n-1):
  j = 0
  while (uc[ab[i][0]-1]>>j | uc[ab[i][1]-1]>>j) & 1:
    j+=1
  else:
    coloring[ab[i][2]] = j+1
    uc[ab[i][0]-1] += 2**j
    uc[ab[i][1]-1] += 2**j
print(max(coloring))
for i in range(n-1):
  print(coloring[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n = int(input())
ab = [list(map(int, input().split())) for i in range(n-1)]
ab2 = [[] for i in range(n)]
for i in range(n-1):
  ab2[ab[i][0]-1].append([ab[i][1]-1, i])
  ab2[ab[i][1]-1].append([ab[i][0]-1, i])
coloring = [0]*(n-1)

def f(x, y, z):
  c = 0
  for i in ab2[x]:
    if i[0] != y:
      c += 1
      if c == z:
        c += 1
      coloring[i[1]] = c
      x1 = i[0]
      y1 = x
      z1 = c
      f(x1, y1, z1)

f(0, None, None)
print(max(coloring))
for i in range(n-1):
  print(coloring[i])
### BUGGY CODE ###

# C - Attack Survival
n,k,q= map(int, input().split())

list = [k] * n

for i in range(q):
    a = int(input())
    for j in range(n):
        if j != a - 1:
            list[j] = list[j] - 1

for k in range(n):
    if(list[k] > 0):
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

# C - Attack Survival
n,k,q= map(int, input().split())

list = [0] * n

for i in range(q):
    a = int(input())
    list[a - 1] = list[a - 1] + 1

for j in range(n):

    if(k - q + list[j] > 0):
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import numpy as np
MOD = 10**9+7

N = int(input())
A = np.array(list(map(int, input().split())))
A = A % MOD

AS = [np.sum(A[:i+1])%MOD for i in range(N)]
s = 0

for i in range(len(A)-1):
  s = (A[i] * ((AS[N-1]-AS[i])) % MOD + s) % MOD
  
print(s)


### FIXED CODE ###

import numpy as np
MOD = 10**9+7

N = int(input())
A = np.array(list(map(int, input().split())))
A = A % MOD

AS = []
s = 0
for a in range(len(A)):
  s = (s + A[a]) % MOD
  AS.append(s)
AS = np.array(AS)

s = 0
for i in range(len(A)-1):
  s = (A[i] * ((AS[N-1]-AS[i])) % MOD + s) % MOD
  
print(s)
### BUGGY CODE ###

from collections import deque
N,M,Q = map(int,input().split())

numbers = deque([[i+1] for i in range(M)])

for i in range(N):
    a = deque([])
    while numbers:
        l = numbers.pop()
        b = l[-1]
        for j in range(b,M+1):
            a.append(l+[j])
    numbers = a

X = []
for i in range(Q):
    a,b,c,d = map(int,input().split())
    X.append((a,b,c,d))

ans = 0
while numbers:
    cnt = 0
    L = numbers.pop()
    for x in X:
        a,b,c,d = x
        if L[b-1]-L[a-1]==c:
            cnt+=d
    ans = max(ans,cnt)
print(ans)

### FIXED CODE ###

from collections import deque
N,M,Q = map(int,input().split())

numbers = deque([[i+1] for i in range(M)])

for i in range(N):
    a = deque([])
    while numbers:
        l = numbers.pop()
        b = l[-1]
        for j in range(b,M+1):
            a.append(l+[j])
    numbers = a

X = []
for i in range(Q):
    a,b,c,d = map(int,input().split())
    X.append((a,b,c,d))

ans = 0
while numbers:
    cnt = 0
    L = numbers.pop()
    for x in X:
        a,b,c,d = x
        if L[b-1]-L[a-1]==c:
            cnt+=d
    ans = max(ans,cnt)
print(ans)
### BUGGY CODE ###

def solve():
    h, k = read()
    result = think(h, k)
    write(result)


def read():
    n, k = read_int(2)
    return read_int(n), k


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h, k):
    cache = preprocess(h, k)
    cost = [0 for x in range(len(h))]
    # element of h <= 10 ** 4, elements <= 10 ** 5, +1 in case
    initial_value_of_cost = 10 ** (4 + 5) + 1
    for dst in range(1, len(h)):
        minimum_cost = initial_value_of_cost
        for src in range(max(0, dst - k), dst):
            minimum_cost = min(minimum_cost, cost[src] + cache[src][dst])
        cost[dst] = minimum_cost
    return cost[len(h) - 1]


def preprocess(h, k):
    cache = [[0 for x in range(len(h))] for y in range(len(h))]
    for src in range(len(h) - 1):
        for dst in range(src + 1, min(len(h), src + k + 1)):
            cost = abs(h[src] - h[dst])
            cache[src][dst] = cost
    return cache


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

### FIXED CODE ###

def solve():
    h, k = read()
    result = think(h, k)
    write(result)


def read():
    n, k = read_int(2)
    return read_int(n), k


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h, k):
    cost = [0 for x in range(len(h))]
    for dst in range(1, len(h)):
        start_point = max(0, dst - k)
        cost[dst] = min([cost[src] + abs(h[src] - h[dst]) for src in range(start_point, dst)])
    return cost[len(h) - 1]


def write(result):
    print(result)


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

from collections import deque

h, w = (int(x) for x in input().split())
ch, cw = (int(x) - 1 for x in input().split())
dh, dw = (int(x) - 1 for x in input().split())
S = [list(input()) for _ in range(h)]
grid = [[-1] * w for _ in range(h)]
grid[ch][cw] = 0
NX = [1, 0, -1, 0]
NY = [0, 1, 0, -1]
PX = [-2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2]
PY = [-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2]

que = deque([(0, ch, cw)])
while que:
    count, y, x = que.popleft()
    if grid[y][x] < count:
        continue
    for i in range(4):
        nx = x + NX[i]
        ny = y + NY[i]
        if 0 <= nx < w and 0 <= ny < h and S[ny][nx] != "#":
            if grid[ny][nx] == -1 or grid[ny][nx] > count:
                grid[ny][nx] = count
                que.appendleft((count, ny, nx))
    for i in range(20):
        px = x + PX[i]
        py = y + PY[i]
        if 0 <= px < w and 0 <= py < h and S[py][px] != "#":
            if grid[py][px] == -1 or grid[py][px] > count + 1:
                grid[py][px] = count + 1
            que.append((count + 1, py, px))

print(grid[dh][dw])


### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
s = [list(input()) for _ in range(h)]

Ch, Cw = Ch - 1, Cw - 1
Dh, Dw = Dh - 1, Dw - 1
d = [[-1] * w for _ in range(h)]
d[Ch][Cw] = 0
walk = [[0, 1], [0, -1], [1, 0], [-1, 0]]
warp = [[2, 2], [2, 1], [2, 0], [2, -1], [2, -2], [1, 2], [1, 1], [1, -1], [1, -2], [0, 2], [0, -2], [-1, 2], [-1, 1],
        [-1, -1], [-1, -2], [-2, 2], [-2, 1], [-2, 0], [-2, -1], [-2, -2]]

que = deque([[0, Ch, Cw]])
while que:
    count, y, x = que.popleft()
    if d[y][x] < count:
        continue
    for NY, NX in walk:
        if 0 <= y + NY < h and 0 <= x + NX < w and s[y + NY][x + NX] != '#':
            if d[y + NY][x + NX] == -1 or d[y + NY][x + NX] > count:
                d[y + NY][x + NX] = count
                que.appendleft([count, y + NY, x + NX])
    for NY, NX in warp:
        if 0 <= y + NY < h and 0 <= x + NX < w and s[y + NY][x + NX] != '#':
            if d[y + NY][x + NX] == -1 or d[y + NY][x + NX] > count + 1:
                d[y + NY][x + NX] = count + 1
                que.append([count + 1, y + NY, x + NX])

print(d[Dh][Dw])
### BUGGY CODE ###

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

dx = [[0]*W for _ in range(H)]
dy = [[0]*H for _ in range(W)]

Sy = [[0]*H for _ in range(W)]
for i in range(H):
    for j in range(W):
        Sy[j][i] = S[i][j]
for i,s in enumerate(S):
    tmp = []
    prev = '#'
    start = -1
    for j,char in enumerate(s):
        if char == '#':
            if prev == '.':
                val = j-start-1
                for k in range(start+1, j):
                    dx[i][k] = val
                prev = char
            start = j
        prev = char
    if start == 0:
        dx[i] = [W]*W
    elif prev == '.':
        val = W - start - 1
        for k in range(start + 1, W):
            dx[i][k] = val
for i,s in enumerate(Sy):
    tmp = []
    prev = '#'
    start = -1
    for j,char in enumerate(s):
        if char == '#':
            if prev == '.':
                val = j-start-1
                for k in range(start+1, j):
                    dy[i][k] = val
                prev = char
            start = j
        prev = char
    if start == 0:
        dy[i] = [H]*H
    elif prev == '.':
        val = H - start - 1
        for k in range(start + 1, H):
            dy[i][k] = val

res = 0
for i in range(H):
    for j in range(W):
        tmp = dx[i][j] + dy[j][i]
        if tmp > res:
            res = tmp
print(res-1)


### FIXED CODE ###

import sys
input = sys.stdin.readline
H, W = map(int,input().split())
S = [ str(input()) for i in range(H) ]
sumlist = []
for i in range(H):
    tmp = 0
    for j in range(W):
        if S[i][j] == '#':
            for k in range(tmp):
                sumlist.append(tmp)
            sumlist.append(0)
            tmp = 0
            continue
        else:
            tmp += 1
    for k in range(tmp):
        sumlist.append(tmp)
sumlist2 = []
for i in range(W):
    tmp = 0
    for j in range(H):
        if S[j][i] == '#':
            for k in range(tmp):
                sumlist2.append(tmp)
            sumlist2.append(0)
            tmp = 0
            continue
        else:
            tmp += 1
    for k in range(tmp):
        sumlist2.append(tmp)
res = [sumlist[i]+sumlist2[(i%W)*H+(i//W)] for i in range(H*W)]
print(max(res)-1)
### BUGGY CODE ###

n = int(input())
s = list(input())
q = int(input())
for _ in range(q):
    c = list(map(str, input().split()))
    if int(c[0]) == 1:
        s[int(c[1]) - 1] = c[2]
    else:
        d = []
        for i in range(int(c[1]) - 1, int(c[2])):
            if not s[i] in d:
                d.append(s[i])
        print(len(d))

### FIXED CODE ###

def RSQ_add(i, x, y):
    while True:
        if i > n:
            break
        BIT[y][i] += x
        i += i & -i

def RSQ_getsum(i, x):
    s = 0
    while True:
        if i <= 0:
            break
        s += BIT[x][i]
        i -= i & -i
    return s

n = int(input())
s = list(input())
q = int(input())
BIT = [[0] * (n + 1) for _ in range(26)]
for i in range(n):
    y = ord(s[i]) - 97
    RSQ_add(i + 1, 1, y)
for _ in range(q):
    com, a, b = map(str, input().split())
    com, a = int(com), int(a)
    if com == 1:
        RSQ_add(a, -1, ord(s[a - 1]) - 97)
        RSQ_add(a, 1, ord(b) - 97)
        s[a - 1] = b
    else:
        b = int(b)
        ans = 0
        for i in range(26):
            if RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1:
                ans += 1
        print(ans)
### BUGGY CODE ###

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

def gcd(m, n):
    if n == 0:
        return m
    return gcd(n, m % n)

LCM = A[0]
for a in A:
    LCM = LCM * a // gcd(LCM, a)

step = max(A)

if step == 1:
    print(M // 2 + 1)
    exit()

X = step // 2
while X <= M:
    for a in A:
        if (X - a // 2) % a != 0:
            break
    else:
        cnt = X // LCM + (M - X) // LCM + 1
        print(cnt)
        exit()
    X += step
print(0)

### FIXED CODE ###

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

def gcd(m, n):
    if n == 0:
        return m
    return gcd(n, m % n)

LCM = A[0]
for a in A:
    LCM = LCM * a // gcd(LCM, a)

step = max(A)
X = step // 2
while X <= M:
    for a in A:
        if (X - a // 2) % a != 0:
            break
    else:
        cnt = X // LCM + (M - X) // LCM + 1
        print(cnt)
        exit()
    X += step
print(0)
### BUGGY CODE ###

n, m = map(int, input().split())
data = [[int(e) for e in input().split()] for _ in range(n)]
d1 = {}
for i in range(n):
  if data[i][0] in d1:
    d1[data[i][0]].append(data[i][1])
  else:
    d1[data[i][0]] = [data[i][1]]
result = 0
d2 = {}
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j in d2:
        d2[j] += 1
      else:
        d2[j] = 1
  if len(d2.keys()) == 0:
    continue
  maxb = max(d2.keys())
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
  else:
    d2[maxb] -= 1
print(result)


### FIXED CODE ###

n, m = map(int, input().split())
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
d2 = {}
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j not in d2:
        d2[j] = 0
      d2[j] += 1
      if j > maxb:
        maxb = j
  else:
    if len(d2) == 0:
      continue
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
    if len(d2) == 0:
      maxb = 0
    else:
      maxb = max(d2.keys())
  else:
    d2[maxb] -= 1
print(result)
### BUGGY CODE ###

import functools
import operator

a=int(input())
b=list(map(int,input().split()))
c = functools.reduce(operator.mul, b)
if c>10**18:
  print(-1)
else:
  print(c)

### FIXED CODE ###

import numpy as np
a=int(input())
b=list(map(int,input().split()))
c=1
if 0 in b:
    print(0)
    exit()
else:
    for i in range(a):
        c=c*b[i]
        if c>10**18:
            print(-1)
            exit()
        else:
            continue
print(c)
### BUGGY CODE ###

import math

x = int(input())

primes = []

for n in range(2, 10000000000, 2):
    f = True
    mp = math.ceil(math.sqrt(n))
    for p in primes:
        if p > mp:
            break
        if n % p == 0:
            f = False
            break
    if f:
        primes.append(n)
        if n >= x:
            print(n)
            exit(0)


### FIXED CODE ###

import math

x = int(input())

primes = []

if x == 2:
    print(2)
    exit(0)

for n in range(3, 10000000000, 2):
    f = True
    mp = math.ceil(math.sqrt(n))
    for p in primes:
        if p > mp:
            break
        if n % p == 0:
            f = False
            break
    if f:
        primes.append(n)
        if n >= x:
            print(n)
            exit(0)