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

# Cumulative Sum Bisect


class SegTree():
    def __init__(self, N, e=0, operator_func=lambda x,y:x+y):
        self.e = e
        self.size = N
        self.node = [self.e] * (2*N)
        self.op = operator_func

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size - 1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        x = self.e
        l += self.size; r += self.size
        a, b = [], []

        while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

        for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
        return x

    def bisect_left(self, x):
        # O(log^2N)なので遅い
        left, right = 0, self.size
        while right-left>1:
            mid = (left+right)//2
            v = self.get(0, mid)
            if v >= x:
                right = mid
            else:
                left = mid
        return left+1


if __name__ == "__main__":
    # ABC140-E sample
    N = int(input())
    l = [(j, i) for i, j in enumerate(map(int, input().split()))]
    l.sort(key=lambda x:-x[0])
    tree = SegTree(N)

    ans = 0

    for n, (value, idx) in enumerate(l, start=1):
        v = tree.get(0, idx + 1)
        a = tree.bisect_left(v - 1) if v > 1 else 0
        b = tree.bisect_left(v - 0) if v else 0
        c = tree.bisect_left(v + 1) if n-v>1 else N+1
        d = tree.bisect_left(v + 2) if n-v>2 else N+1

        tree.update(idx, 1)
        idx += 1
        ans += ((b-a)*(c-idx)+(d-c)*(idx-b)) * value

    print(ans)

### FIXED CODE ###

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.depth = n.bit_length()
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
 
    def lower_bound(self, x):
        sum_ = 0
        pos = 0
        for i in range(self.depth + 1)[::-1]:
            k = pos + (1 << i)
            if k <= self.size and sum_ + self.tree[k] < x:
                sum_ += self.tree[k]
                pos += 1 << i
        return pos + 1, sum_


N = int(input())
l = [(j, i) for i, j in enumerate(map(int, input().split()))]
l.sort(key=lambda x:-x[0])
tree = BIT(N)
m = [0]*N
ans = 0

for value, idx in l:
    v = tree.sum(idx + 1)

    a = tree.lower_bound(v - 1)[0] if v>1 else 0
    b = tree.lower_bound(v - 0)[0] if v else 0
    c = tree.lower_bound(v + 1)[0] 
    d = tree.lower_bound(v + 2)[0]

    tree.add(idx + 1, 1)
    idx += 1
    ans += ((b-a)*(c-idx)+(d-c)*(idx-b)) * value

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

A,B,C,K = map(int,input().split())
if A == B == C:
  print(0)
  exit()
for _ in range(K):
  A,B,C = B+C,A+C,A+B
  ans = abs(A-B)
  if ans > 10**18:
    print('Unfair')
    exit()

print(A-B)

### FIXED CODE ###

A,B,C,K = map(int,input().split())
ans = A-B
if abs(ans) > 10**18:
  ans = 'Unfair'
else:
  if K%2 != 0:
    ans = B-A
print(ans)
### BUGGY CODE ###

from itertools import combinations


def c_count(n, r):  # 組み合わせ
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

ans = set()

for i in combinations(s, 3):
    ans.add(i)

print(len(ans))


### FIXED CODE ###

from itertools import combinations


n = int(input())
s = input()
ans = 0
for i in range(1000):
    num = '{:0=3}'.format(i)
    inds = 0
    indnum = 0
    while inds < len(s) and indnum < 3:
        if s[inds] == num[indnum]:
            indnum += 1
        inds += 1
    if indnum == 3:
        ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
S = [input() for i in range(N)]
check_list = []
count = 0

for i in range(N):
    if S[i] in check_list:
        continue;
    else:
        count += 1
        check_list.append(S[i])

print(count)


### FIXED CODE ###

N = int(input())
S = [input() for i in range(N)]
check_dict = {}
for i in range(N):
    check_dict[S[i]] = 1

print(len(check_dict.keys()))
### BUGGY CODE ###

import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M,Q = IL()
cnt = np.zeros((N+1,N+1))

l = [IL() for i in range(M)]
for i in range(M):
    cnt[:l[i][0]+1,l[i][1]:] += 1

ans = [IL() for i in range(Q)]
for i in range(Q):
    print(int(cnt[ans[i][0]][ans[i][1]]))

### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def imos():
  for j in range(N+1):
    cnt = 0
    for i in range(N+1):
      tmp = l[j][i]
      l[j][i] += cnt
      cnt += tmp

  for j in range(N+1):
    cnt = 0
    for i in range(N+1):
      tmp = l[i][j]
      l[i][j] += cnt
      cnt += tmp

N,M,Q = IL()
l = [[0]*(N+1) for i in range(N+1)]
for i in range(M):
  a,b = IL()
  l[1][b] += 1
  if a+1 <= N:
    l[a+1][b] += -1

imos()

ans = [IL() for i in range(Q)]
for i in range(Q):
    print(l[ans[i][0]][ans[i][1]])
### BUGGY CODE ###

# coding: utf-8
# Your code here!

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
    
    
kosuu = int(input())
nums = list(map(int,input().split()))

temp_arr=[]
for temp in nums:
    temp_arr.extend(make_divisors(temp))
    
temp_arr2 = list(set(temp_arr))
temp_arr2.sort(reverse=True)
temp_arr.sort(reverse=True)
for temp in temp_arr2:
    suuzi = temp_arr.count(temp)
    if suuzi == kosuu -1 or suuzi == kosuu:
        print(temp)
        break

### FIXED CODE ###

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

kosuu = int(input())
nums = list(map(int,input().split()))

L = []
R = []
for temp in range(kosuu-1):
    if temp == 0:
        L.append(nums[0])
    else:
        L.append(gcd(L[temp-1],nums[temp]))

for temp in range(kosuu-1):
    if temp == 0:
        R.append(nums[kosuu-1])
    else:
        R.append(gcd(R[temp-1],nums[len(nums)-temp-1]))

saidai=[]
for i in range(kosuu):
    if i == 0:
        saidai.append(L[-1])
    elif i == kosuu-1:
        saidai.append(R[-1])
    else:
        saidai.append(gcd(L[i-1],R[-1-i]))

print(max(saidai))
### BUGGY CODE ###

S=input()
n=len(S)
ans=0
dp=[]
for i in range(2019):
  dp.append([])
  for j in range(n):
    dp[i].append(0)
dp[int(S[0])][0]=1
for i in range(1,n):
  dp[int(S[i])][i]=1
  for j in range(2019):
    dp[(10*j+int(S[i]))%2019][i]+=dp[j][i-1]
  ans+=dp[0][i]

print(ans)

### FIXED CODE ###

S=input()
n=len(S)
a=[0]*2019
MOD=2019
current=0
a[0]=1
for i in range(n):
  current=(current+int(S[n-1-i])*pow(10,i,MOD))%MOD
  a[current]+=1
ans=0
for i in range(2019):
  ans+=(a[i]*(a[i]-1))//2
print(ans)
### BUGGY CODE ###

T=int(input())
Juice=[None]*T
for i in range(T):
    Juice[i]=list(map(int,input().split()))

#A最初の在庫,Bすぬけ君が買う本数,C以下の場合D追加


#A→A%B
def juicecheck(i):
    if Juice[i][0]<Juice[i][1]:
        print("No")
        return
    juice=Juice[i][0]
    juicelist=set()
    while True:
        juice=juice%Juice[i][1]
        #print(juice)
        if juice in juicelist:
            print("Yes")
            break
        else:
            juicelist=juicelist|{juice}
        if juice<=Juice[i][2]:
            juice+=Juice[i][3]
        #print(juice)
        if juice<Juice[i][1]:
            print("No")
            break

for i in range(T):
    juicecheck(i)


### FIXED CODE ###

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

T=int(input())
Juice=[None]*T
for i in range(T):
    Juice[i]=list(map(int,input().split()))

#A最初の在庫,Bすぬけ君が買う本数,C以下の場合D追加


#A→A%B
def juicecheck(i):
    A=Juice[i][0]
    B=Juice[i][1]
    C=Juice[i][2]
    D=Juice[i][3]

    if A<B:
        print("No")
        return
    elif B>D:
        print("No")
        return
    elif B-1<=C:
        print("Yes")
        return
    else:
        x=A%B
        y=D%B
        

        z=gcd(B,D)

        if z==1 or B-(C+1)>=z or  (C+1)%z<=x%z<=(B-1)%z or ( (C+1)%z>B%z and ((C+1)%z<=x%z or x%z<B%z) ):
            print("No")
            return

        print("Yes")
        return
                
        #(x+n*y)%B==[C+1,B)となるnがあれば"No"

for i in range(T):
    juicecheck(i)
### BUGGY CODE ###

n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
d = []

h.sort()
# print(h)
tmp = 10 ** 10

for i in range(n - 1):
    d.append(h[i + 1] - h[i])
# print(d)
for i in range(n):
    if i + k - 1 >= len(h):
        break
    sub = sum(d[i:i + k - 1])
    # print(sub)
    tmp = min(tmp, sub)

print(tmp)


### FIXED CODE ###

n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
d = []

h.sort()
# print(h)
tmp = 10 ** 10

for i in range(n):
    if i + k - 1 >= len(h):
        break
    tmp = min(tmp, h[i + k - 1] - h[i])

print(tmp)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
    print(k)
cnt = 9
while q:
    x = q.pop(0)
    y = int(str(x)[-1])
    if y != 0:
        cnt += 1
        if cnt == k:
            print(10 * x + y - 1)
            exit()
        q.append(10 * x + y - 1)
    cnt += 1
    if cnt == k:
        print(10 * x + y)
        exit()
    q.append(10 * x + y)
    if y != 9:
        cnt += 1
        if cnt == k:
            print(10 * x + y + 1)
            exit()
        q.append(10 * x + y + 1)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k = int(readline())
runrun = [i + 1 for i in range(9)]
ans = runrun
for n in range(11):
    check = runrun
    runrun = []
    for x in check:
        if x > 3234566667:
            break
        y = x % 10
        if y > 0:
            runrun.append(x * 10 + y - 1)
        runrun.append(x * 10 + y)
        if y < 9:
            runrun.append(x * 10 + y + 1)
    ans += runrun
print(ans[k - 1])
### BUGGY CODE ###

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')

sys.setrecursionlimit(100000)

N, X = in_nn()

blen = [0] * (N + 1)
blen[0] = 1
for i in range(N):
    blen[i + 1] = blen[i] * 2 + 3

dp = dict()


def count(L, X):

    if L == 0:
        return 1

    if X == 1:
        return 0

    global dp
    if (L, X) in dp:
        return dp[(L, X)]

    ret = 0
    if X <= blen[L] // 2:
        ret += count(L - 1, X - 1)
    else:
        ret += count(L - 1, blen[L - 1]) + 1
        if X > blen[L] // 2 + 1:
            X -= blen[L] // 2 + 1
            X = min(X, blen[L - 1])
            ret += count(L - 1, X)

    dp[(L, X)] = ret
    return ret


def main():

    ans = count(N, X)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')

sys.setrecursionlimit(100000)

N, X = in_nn()

blen = [0] * (N + 1)
blen[0] = 1
for i in range(N):
    blen[i + 1] = blen[i] * 2 + 3

pcount = [0] * (N + 1)
pcount[0] = 1
for i in range(N):
    pcount[i + 1] = pcount[i] * 2 + 1


def count(L, X):

    if L == 0:
        return 1

    if X == 1:
        return 0

    ret = 0
    if X <= blen[L] // 2:
        ret += count(L - 1, X - 1)
    else:
        ret += pcount[L - 1] + 1
        if X > blen[L] // 2 + 1:
            X -= blen[L] // 2 + 1
            X = min(X, blen[L - 1])
            ret += count(L - 1, X)

    return ret


def main():

    ans = count(N, X)
    print(ans)


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

import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

N, W = rs()
d = [rs() for _ in range(N)]

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

for i in range(N):
    for w in range(W+1):
        if w >= d[i][0]:
            dp[i][w] = max(dp[i-1][w-d[i][0]] + d[i][1], dp[i-1][w])
        else:
            dp[i][w] = dp[i-1][w]

print(max(dp[-1]))

### FIXED CODE ###

# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
N, W = ri_()
w, v = [0] * N, [0] * N
for i in range(N):
    w[i], v[i] = ri_()
dp = [[INF] * (N * (10 ** 3) + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for j in range(N * (10 ** 3) + 1):
        if j - v[i] >= 0:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])
        else:
            dp[i + 1][j] = dp[i][j]
ans = 0
for j in range(N * (10 ** 3) + 1):
    if dp[N][j] <= W:
        ans = max(ans, j)
print(ans)
### BUGGY CODE ###

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

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

A.sort()
S.sort(key=lambda x: x[1], reverse=True)

X = [0]*(len(A))
idx = 0

for i in range(M):
    if idx <= N:
        X[idx:S[i][0]] = [S[i][1]] * S[i][0]
        idx += S[i][0]
    else:
        break

for i in range(N):
    A[i] = max(A[i], X[i])

print(sum(A))

### FIXED CODE ###

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

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

A.sort()
S.sort(key=lambda x: x[1], reverse=True)

idx = 0

for i in range(M):
    for j in range(idx, min(N, idx + S[i][0])):
        if A[j] < S[i][1]:
            A[j] = S[i][1]
            idx += 1
        else:
            break

print(sum(A))
### BUGGY CODE ###

# 幅優先探索（行きがけ）
import collections
import sys
import math
import copy


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    AArry = LI()
    AArry.sort()

    count = 0
    while AArry:
        a = AArry.pop(0)
        AArry2 = copy.copy(AArry)
        flag = 0
        for v in AArry2:
            if v % a == 0:
                if v == a:
                    flag = 1
                AArry.remove(v)
                count += 1
        if flag == 1:
            count += 1

    print(N-count)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# 幅優先探索（行きがけ）
import collections
import sys
import math
import copy
import collections


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    AArry = LI()
    AArry.sort()
    count = 0
    li = [0 for _ in range(10**6+2)]

    for i, v in enumerate(AArry):
        a = v
        if li[a] == 1:
            count += 1
        if li[a] == 0:
            if i != N-1 and AArry[i+1] == a:
                count += 1

            for j in range(a, 10**6+2, a):
                li[j] = 1

    print(N-count)


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

n = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    ans *= a
print(ans if ans <= pow(10,18) else -1)

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
ans = 1
thld = pow(10,18)
if 0 in A:
    print(0)
else:
    for a in A:
        ans *= a
        if ans > thld:
            print(-1)
            exit()
    print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
s=0
for i in range(m):
  l=li[i][0]
  r=li[i][1]
  temp=range(l,r+1)
  if i==0:
    s=set(temp)
  else:
    s&=set(temp)

print(len(s))

### FIXED CODE ###

n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
maxl=0
minr=1000000
for i in range(m):
  maxl=max(li[i][0],maxl)
  minr=min(minr, li[i][1])
if maxl<=minr:
  print(minr-maxl+1)
else:
  print(0)
### BUGGY CODE ###

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

f_inf = float('inf')
dp = [f_inf] * n
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i-j]+ abs(h[i] - h[i - j]))

print(dp[n-1])


### FIXED CODE ###

import numpy as np
import sys
input = sys.stdin.readline

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

f_inf = float('inf')
dp = np.zeros(n, dtype=int)
h = np.array(h)
for i in range(1, n):
    start = max(0, i - k)
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))

print(dp[n-1])
### BUGGY CODE ###

from scipy.sparse.csgraph import floyd_warshall as wf

N = int(input())
INF = float('inf')

d = [[INF] * (N) for i in range(N)]
for i in range(N):
    d[i][i] = 0
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    d[a - 1][b - 1] = c
    d[b - 1][a - 1] = c
    
wf = wf(d)

Q, K = map(int, input().split())
for i in range(Q):
    x, y = map(int, input().split())
    print(int(wf[x - 1][K - 1] + wf[K - 1][y - 1]))

### FIXED CODE ###

import heapq

N = int(input())
d = [0] * N
INF = float('inf')

class Info:
    def __init__(self, to, cost):
        self.to = to
        self.cost = cost
        
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append(Info(b - 1, c))
    G[b - 1].append(Info(a - 1, c))
    
def dijkstra(s):
    for i in range(N):
        d[i] = INF
    d[s] = 0
    h = []
    heapq.heappush(h, [0, s])
    
    while h != []:
        p = heapq.heappop(h)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(G[v])):
            e = G[v][i]
            if d[e.to] > d[v] + e.cost:
                d[e.to] = d[v] + e.cost
                heapq.heappush(h, [d[e.to], e.to])

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

dijkstra(K - 1)

for _ in range(Q):
    ans = 0
    x, y = map(int, input().split())
    ans += d[x - 1]
    ans += d[y - 1]
    print(ans)
### BUGGY CODE ###

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

for i in range(n):
    print(a.count(i+1))


### FIXED CODE ###

n = int(input())
#n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
count = [0]*n
for i in range(n-1):
    count[a[i]-1] += 1

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

import bisect as b
n=int(input())
ans=1
clist=[int(input())]
for i in range(n-1):
    next=int(input())
    pos=b.bisect_left(clist,next)
    if pos==0:
        clist=[next]+clist
        ans+=1
    else:
        clist[pos-1]=next
print(ans)


### FIXED CODE ###

import bisect as b
from collections import deque
n=int(input())
ans=1
clist=deque([int(input())])
for i in range(n-1):
    next=int(input())
    pos=b.bisect_left(clist,next)
    if pos==0:
        clist.appendleft(next)
        ans+=1
    else:
        clist[pos-1]=next
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if i == 1 or i == n:
        continue
    ans += abs(m-2)
if n == 1:
    if m == 1:
        ans = 1
    else:
        ans = m-2
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
if n == m == 1:
    ans = 1
elif n == 1 or m == 1:
    ans = n*m-2
elif n == 2 or m == 2:
    ans = 0
else:
    ans = (n-2)*(m-2)
print(ans)
### BUGGY CODE ###

n, q = map(int,input().split())
c = [0] * n
c = list(map(int,input().split()))
l = [0] * q
r = [0] * q
for i in range(q):
    l[i] , r[i] =  map(int,input().split())
 
for i in range(q):
    uq = []
    for x in c[l[i]-1:r[i]]:
       if not x in uq:
           uq.append(x)
    print(len(uq))

### FIXED CODE ###

def main(N,Q,C,LR,A):
    data = [0]*(N+1)
    def add(i,x):
        i+=1
        while i <= N:
            data[i]+= x
            i+=i&-i 
            #下桁から最初に1が出現するところまで拾う
            #111 -> 1 , 1100 -> 100 , 1010 -> 1
    def sum(a,b):
        r=0
        i=b
        while i>0:
            r+=data[i]
            i-=i&-i
        i=a
        while i>0:
            r-=data[i]
            i-=i&-i
        return r
    p=[-1]*N
    q=0
    a=[0]*Q
    for i in range(N):
        if p[C[i]-1]>=0:
            add(p[C[i]-1],-1)
        p[C[i]-1]=i
        add(i,1)
        while q<Q and LR[A[q]][1]==i+1:
            a[A[q]]=sum(LR[A[q]][0]-1,LR[A[q]][1])
            q+=1
    return a

import sys
if sys.argv[-1]=='ONLINE_JUDGE':
    from numba import*
    from numba.pycc import CC
    cc = CC('my_module')
  
    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return njit(f)
  
    main=cc_export(main,(i8,i8,i8[:],i8[:,:],i8[:]))
    cc.compile()
    exit()
  
def input(): return sys.stdin.buffer.readline()
N,Q=map(int, input().split())
import numpy as np
C=np.array(input().split(),dtype=np.int64)
#print(C)
LR_ = [0] * (Q*2)
for i in range(Q):
    LR_[i*2],LR_[i*2+1] = input().split()
LR=np.array(LR_, dtype=np.int64).reshape(Q,2)
#print(LR)
A=np.argsort(LR[:,1])

from my_module import main
print(*main(N,Q,C,LR,A),sep='\n')
### BUGGY CODE ###

N, K = map(int, input().split())
As = list(map(int, input().split()))
count = -1
s = []
for k in range(K):
  for a in As:
    i = -1
    for j in range(len(s)):
      if s[j] == a:
        i = j
    if i < 0:
      s.append(a)
    else:
      s = s[0:i]
  #print(s)
  if s == []:
    count = k
    break
#print(count)
if count < 0:
  print(" ".join(map(str, s)))
else:
  K = K%(count+1)
  s = []
  for k in range(K):
    for a in As:
      i = -1
      for j in range(len(s)):
        if s[j] == a:
          i = j
      if i < 0:
        s.append(a)
      else:
        s = s[0:i]
  print(" ".join(map(str, s)))



### FIXED CODE ###

N, K = map(int, input().split())
As = list(map(int, input().split()))
M = [[] for i in range(200001)]
for i, a in enumerate(As):
  M[a].append(i)
S = []
for i, a in enumerate(As):
  l = M[a]
  index = l.index(i)
  if index+1 == len(l):
    n = l[0]+N
  else:
    n = l[index+1]
  S.append(n+1-i)
#print(S)
p = 0
while True:
  p = p+S[p%N]
  if p%N == 0:
    break
count = p//N
#print(count)
K = K%count
#print(K)
p = 0
s = []
while p < N*K:
  q = p+S[p%N]
  if q > N*K:
    s.append(As[p%N])
    p = p+1
  else:
    p = q
print(" ".join(map(str, s)))