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

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

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

A=[X]
s=N
for i in range(1,N):
    a=A[i-1]**2%M
    if a in A:
        s=A.index(a)
        break
    else:
        A.append(a)

if len(A)==N:
    ans=sum(A)
else:
    Z=[0]*(len(A)+1)
    for i in range(1,len(A)+1):
        Z[i]=Z[i-1]+A[i-1]  

    ans=0
    l=len(A)-s
    #ans+=sum(A[:s])
    ans+=Z[s]
    #S=sum(A[s:])
    S=Z[len(A)]-Z[s]
    T=(N-s)//l
    ans+=T*S
    K=N-s-l*T
    #ans+=sum(A[s:(s+K)])
    ans+=Z[s+K]-Z[s]


print(ans)


### FIXED CODE ###

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

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

A=[0]*10**5
A[0]=X
D=dict()
#A=[X]
s=N
for i in range(1,N):
    a=A[i-1]**2%M
    if a in D:
        s=A.index(a)
        break
    else:
        #A.append(a)
        A[i]=a
        D[a]=0

if s==N:
    ans=sum(A)
else:
    A=A[:i]
    Z=[0]*(len(A)+1)
    for i in range(1,len(A)+1):
        Z[i]=Z[i-1]+A[i-1]  

    ans=0
    l=len(A)-s
    #ans+=sum(A[:s])
    ans+=Z[s]
    #S=sum(A[s:])
    S=Z[len(A)]-Z[s]
    T=(N-s)//l
    ans+=T*S
    K=N-s-l*T
    #ans+=sum(A[s:(s+K)])
    ans+=Z[s+K]-Z[s]


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

#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N, Q = next(it), next(it)
    N1 = (2*N+1)//2
    N2 = N1*2
    dp = [None] * N2

    dp[N2-1] = set()
    for i in range(N):
        ci = next(it)
        dp[N1+i] = {ci}
    for i in reversed(range(1, N1)):
        dp[i] = dp[2*i] | dp[2*i+1]

    ans = [0] * Q
    for i in range(Q):
        li, ri = next(it)-1, next(it)-1

        li += N1; ri += N1

        cx = set()
        while li < ri:
            if li & 1:
                cx |= dp[li]
                li += 1
            if ri & 1 == 0:
                cx |= dp[ri]
                ri -= 1
            li >>= 1; ri >>= 1
        if li == ri:
            cx |= dp[li]
        ans[i] = len(cx)

    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()


### FIXED CODE ###

#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    X = 19
    N, Q = next(it), next(it)
    X = Q.bit_length()
    b1, br, bc = (1 << X)-1, 2*X+1, 1<<X

    Aa = [next(it)-1 for i in range(N)]
    Aq = [0] * Q
    Ac = [0] * Q
    for i in range(Q):
        l, r = next(it)-1, next(it)-1
        Aq[i] = r<<X | i
        Ac[i] = l

    Aq.sort()
    dp = [0] * N

    N1 = (2*N+1)//2
    dp2 = [0] * (N1*2)

    ans = [0] * Q
    offset = 0
    for arg in Aq:
        r = arg >> X
        i = arg & b1

        for j in range(offset, r+1):
            ci = Aa[j]

            lo = N1 + dp[ci]
            hi = N1 + j

            while lo < hi:
                if lo & 1:
                    dp2[lo] += 1
                    lo += 1
                if not hi & 1:
                    dp2[hi] += 1
                    hi -= 1
                lo >>= 1; hi >>= 1;

            if lo == hi: dp2[lo] += 1

            dp[ci] = j + 1
        offset = r+1
        l = Ac[i]

        num = 0
        j = l + N1
        while j > 0:
            num += dp2[j]
            j >>= 1
        ans[i] = num

    print(*ans, sep="\n")


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


import sys
input = sys.stdin.readline
#区間の管理は　[a, b)で管理していることに注意

# INT_MIN = -10 ** 18
# MAX_N = 4 * 10 ** 5
# MAX_N = 20


# def init(n_):
#     #簡単にするために2のべき乗に揃える
#     n = 1
#     while n <= n_:
#         n *= 2
#     return n

#初期化
N = int(input())
n = 1
while n <= N:
    n *= 2

data = [0] * (2 * n - 1)

def update(k, a):
    k += n - 1
    data[k] = a
    while k > 0:
        data[k] = max(a, data[k])
        k = (k - 1) // 2
        # data[k] = max(data[2 * k + 1], data[2 * k + 2])

def query(a, b, k = 0, l = 0, r = n):
    if r <= a or b <= l:
        return 0
    elif a <= l and r <= b:
        return data[k]
    else:
        return max(query(a, b, 2 * k + 1, l, (l + r)//2), query(a, b, 2 * k + 2, (l + r)//2, r))

H = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))

# ans = 0

dp = [A[0]] + [0] * (N - 1)
update(H[0], A[0])
for i in range(1, N):
    # h = int(input())
    # a = int(input())
    dp[i] = query(1, H[i]) + A[i]
    # h = H[i]
    # a = A[i]
    # tmp = query(1, h + 1) #[1, h)での最大値
    # print (h, tmp)
    update(H[i], dp[i])
    # ans = max(ans, tmp + a)
    # print (data)

print (max(dp))

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    #区間の管理は　[a, b)で管理していることに注意

    # INT_MIN = -10 ** 18
    # MAX_N = 4 * 10 ** 5
    # MAX_N = 20


    # def init(n_):
    #     #簡単にするために2のべき乗に揃える
    #     n = 1
    #     while n <= n_:
    #         n *= 2
    #     return n

    #初期化
    N = int(input())
    # n = 1
    # while n <= N:
    #     n *= 2

    n = 262144
    data = [0] * (2 * n - 1)

    def update(k, a):
        k = k + n - 1
        # data[k] = a
        while k >= 0:
            data[k] = max(a, data[k])
            k = (k - 1) // 2
            # data[k] = max(data[2 * k + 1], data[2 * k + 2])

    def query(a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        elif a <= l and r <= b:
            return data[k]
        else:
            return max(query(a, b, 2 * k + 1, l, (l + r)//2), query(a, b, 2 * k + 2, (l + r)//2, r))

    H = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))

    # ans = 0

    dp = [A[0]] + [0] * (N - 1)
    update(H[0] - 1, A[0])
    for i in range(1, N):
        # h = int(input())
        # a = int(input())
        dp[i] = query(0, H[i] - 1, 0, 0, n) + A[i]
        # h = H[i]
        # a = A[i]
        # tmp = query(1, h + 1) #[1, h)での最大値
        # print (h, tmp)
        update(H[i] - 1, dp[i])
        # ans = max(ans, tmp + a)
        # print (data)

    print (query(0, N, 0, 0, n))

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

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
#import random
#
#N = 10**5
#A = [random.randrange(1,10**9+1) for _ in range(N)]


def main():
    l = 0
    r = N
    while r-l > 1:
        m = (r+l)//2
        ok = True
        if m == 1:
            pre = -1
            for a in A:
                if pre >= a:
                    ok = False
                    break
                pre = a
        else:
            dp = {}
            needreset = 10**15
            exception = set()
            pre = -1
            for a in A:
                ind = a
                for _ in range(100):
                    # 修正
                    if needreset >= ind or ind in exception:
                        if not ind in dp.keys():
                            dp[ind] = 0 if pre < a else 1
                    else:
                        dp[ind] = 0 if pre < a else 1
                        exception.add(ind)
                    # たす
                    if dp[ind] < m:
                        dp[ind] += 1
                        break
                    elif ind == 1:
                        ok = False
                        break
                    else:
                        # 繰り上がり
                        dp[ind] = 1
                        ind -= 1
                if not ok: break
                # 更新
                if pre > a:
                    needreset = a
                    exception = set()
                pre = a

        if ok:
            r = m
        else:
            l = m

    print(r)


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

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


def check(m):
    if m == 1:
        pre = -1
        for a in A:
            if pre >= a:
                return False
            pre = a
    else:
        dp = {}
        pre = 0
        #count = 0
        for a in A:
            if pre < a:
                pre = a
                continue
            todelete = []
            for b in dp.keys():
                if b > a:
                    todelete.append(b)
            ind = a
            while ind > 0:
                if ind in dp and dp[ind] >= m-1:
                    todelete.append(ind)
                else:
                    break
                ind -= 1
            # 更新
            if ind in dp:
                dp[ind] += 1
            else:
                dp[ind] = 1
            if ind == 0 or dp[ind] >= m:
                return False
            for d in todelete:
                del dp[d]
            pre = a
    #print(m, count)
    return True



def main():
    l = 0
    r = N
    while r-l > 1:
        m = (r+l)//2
        if check(m):
            r = m
        else:
            l = m
    print(r)


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

N = int(input())
ans = 1
A = list(map(int, input().split()))
flag = 0

for j in range(len(A)):
  if A[j] == 0:
    flag = 1
    ans = 0

if flag == 0:
  for i in range(N):
    ans = ans * A[i]
    if ans == 0:
      break


if ans > 10 ** 18:
  print('-1')
else:
  print(ans)

### FIXED CODE ###

N = int(input())
ans = 1
A = list(map(int, input().split()))
flag = 0

for j in range(len(A)):
  if A[j] == 0:
    flag = 1
    ans = 0

if flag == 0:
  for i in range(N):
    ans = ans * A[i]
    if ans > 10 ** 18:
      break


if ans > 10 ** 18:
  print('-1')
else:
  print(ans)
### BUGGY CODE ###

n = int(input())
a = input().rstrip().split()
i = 0
j = 0
ans = []

for i in range(int(n)):
    for j in range(int(n)):
        if int(i) + 1 == int(a[j]):
            ans.append(int(j) + 1)
            
for k in range(int(n)):
    print(ans[k] , end = " ")

### FIXED CODE ###

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

for i in range(n):
    b[a[i] - 1] = i + 1
    
for i in range(n):
    print(b[i],end=" ")
### BUGGY CODE ###

import math
res = 0
N = int(input())
for a in range(1,N+1):
  for b in range(1,N+1):
    for c in range(1,N+1):
      res += math.gcd(math.gcd(a,b),c)
print(res)

### FIXED CODE ###

N = int(input())
L = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
print(L[N-1])
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

from heapq import *

H, W = map(int, input().split())
m1 = lambda s: int(s)-1
sy, sx = map(m1, input().split())
fy, fx = map(m1, input().split())
G = [list(input()) for _ in range(H)]

Q = [(0, sx, sy)]
while Q:
	d, x, y = heappop(Q)
	if G[y][x] == '#': continue
	G[y][x] = '#'

	if (x, y) == (fx, fy):
		print(d)
		break

	for dx in range(-2, 3):
		for dy in range(-2, 3):
			nx = x + dx
			ny = y + dy
			if nx < 0 or ny < 0 or nx >= W or ny >= H or G[ny][nx] == '#': continue
			heappush(Q, (d + (0 if abs(dx) + abs(dy) == 1 else 1), nx, ny))
else:
	print(-1)


### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()

from heapq import *

H, W = map(int, input().split())
m1 = lambda s: int(s)-1
sy, sx = map(m1, input().split())
fy, fx = map(m1, input().split())
G = [list(input()) for _ in range(H)]
D = [[10 ** 18] * W for _ in range(H)]

D[sy][sx] = 0
Q = [(0, sx, sy)]
while Q:
	d, x, y = heappop(Q)
	if D[y][x] < d: continue

	if (x, y) == (fx, fy):
		print(d)
		break

	for dx in range(-2, 3):
		for dy in range(-2, 3):
			nx = x + dx
			ny = y + dy
			if nx < 0 or ny < 0 or nx >= W or ny >= H or G[ny][nx] == '#': continue
			nd = d + (0 if abs(dx) + abs(dy) == 1 else 1)
			if nd >= D[ny][nx]: continue
			D[ny][nx] = nd
			heappush(Q, (nd, nx, ny))
else:
	print(-1)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect
def main():
    h, w, m = map(int,input().split()) 
    h_lis = [0] * h
    w_lis = [0] * w
    hw_lis = [] 
    for i in range(m):
        hh, ww = map(int,input().split())
        hh -= 1
        ww -= 1
        h_lis[hh] += 1
        w_lis[ww] += 1
        hw_lis.append((hh, ww))
    h_max_index = [i for i, h in enumerate(h_lis) if h == max(h_lis)]
    w_max_index = [i for i, w in enumerate(w_lis) if w == max(w_lis)]
    for h_i in h_max_index:
        for w_i in w_max_index:
            if not (h_i, w_i) in hw_lis:
                print(h_lis[h_i] + w_lis[w_i])
                sys.exit()
    else:
        print(h_lis[h_i] + w_lis[w_i] - 1)

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
from bisect import bisect_left,bisect
def main():
    h, w, m = map(int,input().split()) 
    h_lis = [0] * (h+1)
    w_lis = [0] * (w+1)
    bombs = set([tuple(map(int,input().split())) for i in range(m)])
    for hh, ww in bombs:
        h_lis[hh] += 1
        w_lis[ww] += 1
    max_h = max(h_lis)
    max_w = max(w_lis)
    h_max_index = [i for i, h in enumerate(h_lis) if h == max_h]
    w_max_index = [i for i, w in enumerate(w_lis) if w == max_w]
    for h_i in h_max_index:
        for w_i in w_max_index:
            if not (h_i, w_i) in bombs:
                print(h_lis[h_i] + w_lis[w_i])
                sys.exit()
    else:
        print(h_lis[h_i] + w_lis[w_i] - 1)

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

import sys
input = sys.stdin.readline

"""

"""

tot = 1
n = int(input())
arr = map(int, input().split())

for v in arr:
    tot *= v

if tot > 10**18:
    print(-1)
else:
    print(tot)


### FIXED CODE ###

import sys
input = sys.stdin.readline

"""

"""

tot = 1
n = int(input())
arr = map(int, input().split())

for v in arr:
    if v == 0:
        tot = 0
        break
    if tot <= 10**18:
        tot *= v
    

if tot > 10**18:
    print(-1)
else:
    print(tot)
### BUGGY CODE ###

import numpy as np

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = np.array(a, dtype=np.int64)

for i in range(k):
    b = np.zeros(n, dtype=np.int64)
    for j in range(n):
        lb = max(j - a[j], 0)
        ub = min(j + a[j], n - 1)

        b[lb] += 1
        if ub + 1 < n:
            b[ub + 1] -= 1

    a = b.cumsum()

    if np.all(a == n):
        break

print(' '.join(a.astype(str)))


### FIXED CODE ###

import numpy as np
from numba import njit

@njit('i8,i8,i8[::1]', cache=True)
def fn(n, k, a):
    for _ in range(k):
        b = np.zeros(n, dtype=np.int64)
        for i in range(n):
            lb = max(i - a[i], 0)
            ub = min(i + a[i], n - 1)

            b[lb] += 1
            if ub + 1 < n:
                b[ub + 1] -= 1

        a = b.cumsum()
        if np.all(a == n):
            return a
    return a

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = np.array(a, dtype=np.int64)

b = fn(n, k, a)
print(' '.join(b.astype(str)))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
for _ in range(Q):
    B.append(list(map(int,input().split())))
for i in range(Q):
    for j in range(N):
        if A[j]==B[i][0]:
            A[j]=B[i][1]
    print(sum(A))

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
for _ in range(Q):
    B.append(list(map(int,input().split())))
s=sum(A)
from collections import Counter
a=Counter(A)
b=list(a.keys())
c=list(a.values())
for i in range(Q):
    s-=B[i][0]*a[B[i][0]]
    s+=B[i][1]*a[B[i][0]]
    a[B[i][1]]+=a[B[i][0]]
    a[B[i][0]]=0
    print(s)
### BUGGY CODE ###

n=int(input())
s=input()
cnt=[0,0,0]
for i in range(n):
    if s[i]=='R':
        cnt[0]+=1
    elif s[i]=='G':
        cnt[1]+=1
    elif s[i]=='B':
        cnt[2]+=1
ans=cnt[0]*cnt[1]*cnt[2]
for i in range(n):
    for j in range(i+1,n):
        if 2*j-i>=n:
          continue
        if len(set([s[i],s[j],s[2*j-i]]))==3:
          ans-=1
print(ans)

### FIXED CODE ###

n=int(input())
s=input()
cnt=[[0,0,0] for _ in range(n)]
for i in range(n):
    if s[i]=='R':
        cnt[i][0]+=1
    elif s[i]=='G':
        cnt[i][1]+=1
    elif s[i]=='B':
        cnt[i][2]+=1
acum=[[0,0,0]]
for i in range(n):
    tmp=[0,0,0]
    for j in range(3):
        tmp[j]+=acum[-1][j]
        tmp[j]+=cnt[i][j]
    acum.append(tmp)
ans=0
for i in range(n):
    for j in range(i+1,n):
        if s[i]==s[j]:
            continue
        if 'R' not in (s[i],s[j]):
            ans+=acum[-1][0]-acum[j][0]
            if 2*j-i<n and s[2*j-i]=='R':
                ans-=1
        elif 'G' not in (s[i],s[j]):
            ans+=acum[-1][1]-acum[j][1]
            if 2*j-i<n and s[2*j-i]=='G':
                ans-=1
        elif 'B' not in (s[i],s[j]):
            ans+=acum[-1][2]-acum[j][2]
            if 2*j-i<n and s[2*j-i]=='B':
                ans-=1
print(ans)
### BUGGY CODE ###

s=input()
l=len(s)
mod = pow(10,9)+7

dp = [0 for i in range(13)]
dp2 = [0 for i in range(13)]
dp[0] = 1

for i in range(1,l+1):
	num = s[-i]
	keta = pow(10,i-1)
	dp2 = dp.copy()
	if num == '?':
		for j in range(1,10):
			tmp = ( j * keta ) % 13
			for k in range(13):
				index = (tmp + k) % 13
				dp[index] += dp2[k]
	else:
		tmp = ( int(num) * keta ) % 13
		for k in range(13):
			index = (tmp + k) % 13
			dp[index] = dp2[k]
print(dp[5] % mod)


### FIXED CODE ###

INF = 10 ** 9 + 7

S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
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] %= INF
    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] %= INF
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

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

N=int(input())
A=list(map(int,input().split()))
from functools import reduce
from math import gcd
g=reduce(lambda x,y:gcd(x,y),A,0)
if g>1:
    print('not coprime')
    exit()
def prime(N):
    p=set(range(2,N+1))
    for i in range(int(N**.5)+1):
        if i in p:
            p-=set(range(i*2,N+1,i))
    return p
p=prime(max(A))
r=1
for a in A:
    p2=p.copy()
    for x in p:
        if a%x==0:
            p2.remove(x)
        while a%x==0:
            a//=x
    p=p2
    if a>1:
        r=0
print(['setwise coprime','pairwise coprime'][r])

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
from functools import reduce
from math import gcd
g=reduce(lambda x,y:gcd(x,y),A,0)
if g>1:
    print('not coprime')
    exit()
def prime(N):
    p=set(range(2,N+1))
    for i in range(int(N**.5)+1):
        if i in p:
            p-=set(range(i*2,N+1,i))
    return p
p=prime(1000)
r=1
s=set()
for a in A:
    f=0
    for x in p:
        if a%x==0:
            if f==0:
                p2=p.copy()
                f=1
            p2.remove(x)
        while a%x==0:
            a//=x
        if a==1:
            break
    if a>1:
        if 1000<a and a not in s:
            s.add(a)
        else:
            r=0
            break
    if f:
        p=p2
print(['setwise coprime','pairwise coprime'][r])
### BUGGY CODE ###

n=int(input())
mod=10**9+7
X=[]
for i in range(n):
  X.append([int(input()),0])
for i in range(n):
  X.append([int(input()),1])
X.sort(key=lambda x:x[0])
ct=0
Y=[]
for a,b in X:
  if b==0:
    ct+=1
  else:
    ct-=1
  Y.append(ct)
ans=1
m,mm=0,1
key=0
for i in range(2*n):
  if Y[i]==0:
    ans*=mm
    m,mm=0,1
  elif m==0:
    m=1
    key=X[i][1]
  else:
    if X[i][1]==key:
      m+=1
      mm*=m
    else:
      m-=1
print(ans%mod)

### FIXED CODE ###

n=int(input())
ans=1
mod=10**9+7
A=[0,0]
AB=[]
for i in range(n):
  a=int(input())
  AB.append((a,0))
for i in range(n):
  b=int(input())
  AB.append((b,1))
AB.sort(key=lambda x:x[0])
for i in range(2*n):
  a,b=AB[i]
  if b==0:
    if A[1]>0:
      ans=(ans*A[1])%mod
      A[1]-=1
    else:
      A[0]+=1
  else:
    if A[0]>0:
      ans=(ans*A[0])%mod
      A[0]-=1
    else:
      A[1]+=1
print(ans)
### BUGGY CODE ###

NM = input().split(" ")
A_LIST = input().split(" ")
A = []
for i in A_LIST:
    A.append(int(i))

N = int(NM[0])
M = int(NM[1])

#.sort()
for i in range(0, M):
    m = max(A)
    n = A.index(m)
    m = m // 2
    A[n] = m
S = 0
for i in A:
    S += i
print(S)

### FIXED CODE ###

import heapq

NM =input().split(" ")
A_LIST = input().split(" ")
N = int(NM[0])
M = int(NM[1])

A = []
for i in A_LIST:
    heapq.heappush(A, -1 * int(i))
    
for i in range(0, M):
    m = heapq.heappop(A)
    m = -1 * m
    m = m // 2
    heapq.heappush(A, -1 * m)

S = 0    
for i in A:
    S += (-1 * i)

print(S)
### BUGGY CODE ###

def main():
    l, r = map(int, input().split())
    ans = 2020
    for i in range(l, r):
        for j in range(i+1, r+1):
            tmp = (i % 2019) * (j % 2019) % 2019
            if tmp < ans:
                ans = tmp
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    l, r = map(int, input().split())
    q, ll = l // 2019, l % 2019
    rr = r % 2019
    rng = [*range(ll, rr+1)] if r - l < (2019 * q - ll) % 2019 else [*range(ll, 2019)] + [*range(rr+1)]
    lenrng = len(rng)
    ans = 2020
    for i in range(lenrng-1):
        for j in range(i+1, lenrng):
            tmp = rng[i] * rng[j] % 2019
            if tmp < ans:
                ans = tmp
    print(ans)

if __name__ == "__main__":
    main()