Problem:


Score : 700 points

Problem Statement

We have a sequence of N \times K integers: X=(X_0,X_1,\cdots,X_{N \times K-1}).
Its elements are represented by another sequence of N integers: A=(A_0,A_1,\cdots,A_{N-1}). For each pair i, j (0 \leq i \leq K-1,\ 0 \leq j \leq N-1), X_{i \times N + j}=A_j holds.

Snuke has an integer sequence s, which is initially empty.
For each i=0,1,2,\cdots,N \times K-1, in this order, he will perform the following operation:

If s does not contain X_i: add X_i to the end of s.

If s does contain X_i: repeatedly delete the element at the end of s until s no longer contains X_i. Note that, in this case, we do not add X_i to the end of s.

Find the elements of s after Snuke finished the operations.

Constraints

1 \leq N \leq 2 \times 10^5

1 \leq K \leq 10^{12}

1 \leq A_i \leq 2 \times 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
A_0 A_1 \cdots A_{N-1}

Output

Print the elements of s after Snuke finished the operations, in order from beginning to end, with spaces in between.

Sample Input 1

3 2
1 2 3

Sample Output 1

2 3

In this case, X=(1,2,3,1,2,3).
We will perform the operations as follows:

i=0: s does not contain 1, so we add 1 to the end of s, resulting in s=(1).

i=1: s does not contain 2, so we add 2 to the end of s, resulting in s=(1,2).

i=2: s does not contain 3, so we add 3 to the end of s, resulting in s=(1,2,3).

i=3: s does contain 1, so we repeatedly delete the element at the end of s as long as s contains 1, which causes the following changes to s: (1,2,3)→(1,2)→(1)→().

i=4: s does not contain 2, so we add 2 to the end of s, resulting in s=(2).

i=5: s does not contain 3, so we add 3 to the end of s, resulting in s=(2,3).

Sample Input 2

5 10
1 2 3 2 3

Sample Output 2

3

Sample Input 3

6 1000000000000
1 1 2 2 3 3

Sample Output 3

s may be empty in the end.

Sample Input 4

11 97
3 1 4 1 5 9 2 6 5 3 5

Sample Output 4

9 2 6



Sample input:
3 2
1 2 3


Sample output:
2 3

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc036/submissions/6506357
# WA: (3)

def get_remain(a, next_, index):
    used = [False] * len(a)
    ans  = []
    
    for i in range(index, len(a)):
        if used[i] == True:
            continue
            
        if next_[i] > i:
            for j in range(i, next_[i]+1):
                used[j] = True
        else:
            ans.append(a[i])
    
    return ans        

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

d    = {}
cur  = 0
pos  = 0

for i, x in enumerate(a):
    if x not in d:
        d[x] = []
    d[x].append(i)    
    
next_  = [0] * n
next   = [0] * n

for v in d.values():
    len_ = len(v)
    for i, x in enumerate(v):
        next_[x] = v[(i+1)%len_]        
        
for i in range(n-1, -1, -1):
    if next_[i] <= i:
        next[i] = next_[i]
        
    else:
        if next_[i] + 1 == n:
            next[i]  =  n - 1
        else:
            next[i]  = next[next_[i] + 1]
            
temp          = (next[0] + 1) % n 
index         = [-1, 0] 

while temp != 0:
    print(temp)
    index.append(temp)
    temp    = (next[temp] + 1) % n
    
    

if len(get_remain(a, next_, index[-1])) == 0:
    length_ = len(index) - 1
else:
    length_ = len(index)
        
r = k % (length_)
    
if r == 0:
    print('')
else:
    ans = get_remain(a, next_, index[r])
    print(' '.join([str(x) for x in ans]))

Submission status: Wrong Answer

Solution code:
# 1,3,2,1,3,2,3,1,3
# 3 1 4 1 5 9 2 6 5 3 5
import random

def get_remain(a, next_, index):
    used = [False] * len(a)
    ans  = []
    
    for i in range(index, len(a)):
        if used[i] == True:
            continue
            
        if next_[i] > i:
            for j in range(i, next_[i]+1):
                used[j] = True
        else:
            ans.append(a[i])
    
    return ans        

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

d    = {}
cur  = 0
pos  = 0

for i, x in enumerate(a):
    if x not in d:
        d[x] = []
    d[x].append(i)    
    
next_  = [0] * n
next   = [0] * n

for v in d.values():
    len_ = len(v)
    for i, x in enumerate(v):
        next_[x] = v[(i+1)%len_]        
        
for i in range(n-1, -1, -1):
    if next_[i] <= i:
        next[i] = next_[i]
        
    else:
        if next_[i] + 1 == n:
            next[i]  =  n - 1
        else:
            next[i]  = next[next_[i] + 1]
            
temp          = (next[0] + 1) % n 
length_period = 0 
index         = [-1, 0] 

while temp != 0:
    #print(temp)
    index.append(temp)
    length_period += 1
    temp    = (next[temp] + 1) % n
    
    
if length_period == 0:
    print('')
else:
    if len(get_remain(a, next_, index[-1])) == 0:
        length_ = len(index) - 1
    else:
        length_ = len(index)
        
    r = k % (length_)
    
    if r == 0:
        print('')
    else:
        ans = get_remain(a, next_, index[r])
        print(' '.join([str(x) for x in ans]))

Submission status: Wrong Answer

Solution code:
# 1,3,2,1,3,2,3,1,3
# 3 1 4 1 5 9 2 6 5 3 5
import random

def get_remain(a, next_, index):
    used = [False] * len(a)
    ans  = []
    
    for i in range(index, len(a)):
        if used[i] == True:
            continue
            
        if next_[i] > i:
            for j in range(i, next_[i]+1):
                used[j] = True
        else:
            ans.append(a[i])
    
    return ans        

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

d    = {}
cur  = 0
pos  = 0

for i, x in enumerate(a):
    if x not in d:
        d[x] = []
    d[x].append(i)    
    
next_  = [0] * n
next   = [0] * n

for v in d.values():
    len_ = len(v)
    for i, x in enumerate(v):
        next_[x] = v[(i+1)%len_]        
        
for i in range(n-1, -1, -1):
    if next_[i] <= i:
        next[i] = next_[i]
        
    else:
        if next_[i] + 1 == n:
            next[i]  =  n - 1
        else:
            next[i]  = next[next_[i] + 1]
            
temp          = (next[0] + 1) % n 
length_period = 0 
index         = [-1, 0] 

while temp != 0:
    #print(temp)
    index.append(temp)
    length_period += 1
    temp    = (next[temp] + 1) % n
    
    
if length_period == 0:
    print('')
else:
    r = k % (len(index) - 1)
    
    if r == 0:
        print('')
    else:
        ans = get_remain(a, next_, index[r])
        print(' '.join([str(x) for x in ans]))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1000000)

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

b = []
for i in range(0,n):
    p = a[i]
    chou = False
    for j in range(i+1,n):
        if a[i] == a[j]:
            chou = True
            b.append(j)
            break
    if not chou:
        for j in range(0,i+1):
            if a[i] == a[j]:
                chou = True
                b.append(j)
                break
print(b)
def f(s,count):
    if s < b[s]:
        if b[s]==n-1:
            return count
        else:
            return f(b[s]+1,count)
    else:
        count += 1
        if b[s]==n-1:
            return count
        else:
            return f(b[s]+1,count)

lasta = []
loop = f(0,0)
if loop == 0:
    lasta = []
else:
    for i in range(0,min(k%(loop+1),k)):
        lasta += a

ans = []
#listaからansをつくる．
t = 0
count = 0
while len(lasta)>0:
    if b[t]<=t:
        count=count+1
        if b[t]+count*n<len(lasta)-1:
            t = (b[t]+1)%n
        elif b[t]+count*n == len(lasta)-1:
            break
        else:
            ans.append(lasta[t])
            count = count -1
            if t+count*n==len(lasta)-1:
                break
            else:
                t = (t + 1)%n
    else:
        if b[t]+count*n<len(lasta)-1:
            t = (b[t]+1)%n
        elif b[t]+count*n == len(lasta)-1:
            break
    


print(" ".join(map(str,ans)))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
*A, = map(int,input().split())

B = [(a,i) for i,a in enumerate(A)]
B.sort(key=lambda x:x)
s_max = len(bin(N*K))-2
step_length = [[N]*N for _ in  [0]*s_max]    

sl = step_length[0]
a0 = 0
j0 = N
for i,b in enumerate(B[:-1]):
    a,j = b
    if a0!=a:
        a0 = a
        j0 = j + N
    if B[i+1][0]!=a:
        sl[j] = j0 - j +1
    else:
        sl[j] = B[i+1][1] - j +1

for s in range(1,s_max):
    psl = step_length[s-1]
    nsl = step_length[s]
    for i in range(N):
        nsl[i] = psl[i] + psl[( i + psl[i] )%N]

i = 0
s = s_max-1
while s>=0:
    sl = step_length[s][i%N]
    if i + sl >= N*K:
        s-=1
    else:
        i = i + sl

S = []
idx = {}
j = 0
for a in A[i%N:]:
    i = idx.get(a,None)
    if i == None:
        idx[a] = j
        S.append(a)
        j += 1
    else:
        for k in range(j-1,i-1,-1):
            idx[S.pop()] = None
        j = i
print(*S)

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]

    n_head_pos = dict() #一番最初にnが出てくるindex
    rem_head_num = [-1] * N #i番目から処理を始めた時に残る数列の先頭の数字
    for i in reversed(range(N)):
        if A[i] not in n_head_pos:
            rem_head_num[i] = A[i]
        else:
            if n_head_pos[A[i]] == N-1: rem_head_num[i] = -1
            else: rem_head_num[i] = rem_head_num[n_head_pos[A[i]] + 1]
        n_head_pos[A[i]] = i
    #print(n_head_pos)
    #print(rem_head_num)

    start_cycle = [] #先頭の数字の周期
    start = -1
    used = set()
    while start not in used:
        used |= {start}
        start_cycle.append(start)
        if start == -1: next = rem_head_num[0]
        elif n_head_pos[start] < N - 1: next = rem_head_num[n_head_pos[start] + 1]
        else: next = -1
        start = next

    #print(start_cycle)

    len_cycle = len(start_cycle)
    last = (K - 1) % len_cycle 
    #print(last)
    if start_cycle[last] == -1: start_index = 0
    elif n_head_pos[start_cycle[last]] < N - 1: start_index =n_head_pos[start_cycle[last]] + 1
    else: start_index == -1
    #print(start_index)
    if start_index > 0:
        out = []
        using = dict()
        l = 0
        for i in range(start_index, N):
            if A[i] in using:
                aindex = using[A[i]]
                l = aindex
                for a in out[aindex:]:
                    using.pop(a)
                out = out[:aindex]
            else:
                out.append(A[i])
                using[A[i]] = l
                l += 1
                #print(out, using, l)
        print(" ".join(map(str, out)))
    else: print(" ")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

#A
def A():
    n = I()
    if n <= 1000000000:
        print(0,0,1,0,0,n)
    else:
        b = 1000000000
        a = 1
        y = -n%1000000000
        x = (n+a*y)//b
        print(0,0,x,y,a,b)
        return

    return

#B
def B():
    n,k = LI()
    a = LI()
    for i in range(n):
        a.append(a[i])
    MA = 200000
    f = [[i,1] for i in range(n)]
    l = [-1]*(MA+1)
    for i in range(n):
        if l[a[i]] < 0:
            l[a[i]] = i
        else:
            if f[l[a[i]]][0] == l[a[i]]:
                f[l[a[i]]] = [(i+1)%n, 0 if i < n-1 else 1]
                l[a[i]] = i
    for i in range(n,2*n):
        if f[l[a[i]]][0] == l[a[i]]:
            f[l[a[i]]] = [(i+1)%n,1]
            l[a[i]] = -1
    b = 57
    g = [[f[i]] for i in range(n)]
    for i in range(b):
        for j in range(n):
            x = g[g[j][i][0]][i][0]
            d = g[j][i][1]+g[g[j][i][0]][i][1]
            if d >= k:break
            g[j].append([x,d])
        else:
            continue
        break
    m = n*k
    i = 0
    while 1:
        l = 0
        r = len(g[i])
        while r-l > 1:
            mid = (l+r)//2
            if g[i][mid][0]+g[i][mid][1]*n-i > m:
                r = mid
            else:
                l = mid
        d = g[i][l][0]+g[i][l][1]*n-i
        m -= d
        pre = d-1
        i = g[i][l][0]
        if m <= n:
            break
    s = []
    f = [1]*(MA+1)
    for j in range(i,i+m):
        k = j%n
        if f[a[k]]:
            s.append(a[k])
            f[a[k]] = 0
        else:
            while 1:
                x = s.pop(-1)
                f[x] = 1
                if x == a[k]:
                    break
    print(*s)
    return

#C
mod = 998244353
def C():
    def comb(a,b):
        if a < b:
            return 1
        return fact[a]*inv[b]*inv[a-b]%mod
    n,m = LI()
    MA = 3*m+max(n,2*m)-1
    fact = [1]*(MA+1)
    for i in range(MA):
        fact[i+1] = fact[i]*(i+1)%mod
    inv = [1]*(MA+1)
    inv[MA] = pow(fact[MA],mod-2,mod)
    for i in range(MA)[::-1]:
        inv[i] = inv[i+1]*(i+1)%mod
    ans = 0
    for k in range(min(m,n)+1):
        if (3*m-k)%2 == 0:
            ans += comb(n,k)*comb((3*m-k)//2+n-1,n-1) #奇数の数がk個かつ総和が3mとなるパターンの総数(n個のうちk個に1を割り振る→総和が3m-kとなるパターンの総数を求める)
            ans %= mod
    ans -= n*comb(3*m-(2*m+1)+n-1,n-1)
    ans %= mod
    print(ans)

    return

#D
def D():
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
s = []
for i in range(n*k):
  if a[i%n] in s:
    s = s[:s.index(a[i%n])]
  else:
    s.append(a[i%n])
print(s)

Submission status: Wrong Answer

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

a = list(set(A))
a.sort()
R = {}
for i in range(len(a)):
  R[a[i]] = i

n = len(a)
L = [[] for _ in range(n)]
P = [[0, 0] for _ in range(N)]
for i in range(N):
  P[i][0] = R[A[i]]
  P[i][1] = len(L[R[A[i]]])
  L[R[A[i]]].append(i)

s = [R[A[0]], 0]
D = [0]

while True:
  while s[1] < len(L[s[0]]) - 1:
    t = L[s[0]][s[1] + 1]
    if t != N - 1:
      s = P[t + 1]
    else:
      break
  else:
    if L[s[0]][0] == N - 1:
      break
    s = P[L[s[0]][0] + 1]
    D.append(L[s[0]][s[1]])
    continue
  break

M = len(D)
m = (K - 1) % M

ans = []
s = P[D[m]]
t = L[s[0]][s[1]]

while t != N:
  if s[1] == len(L[s[0]]) - 1:
    ans.append(A[t])
    t += 1
  else:
    t = L[s[0]][s[1] + 1] + 1
  if t == N:
    break
  s = P[t]

print(" ".join(list(map(str, ans))))

Submission status: Wrong Answer

Solution code:
def solve():
    N, K = [int(_) for _ in raw_input().split()]
    A = [(i, int(ele)) for i, ele in enumerate(raw_input().split())]
    sortA = sorted(A, key = lambda x: x[1])
    _next = [None] * N
    save = 0
    for i in range(1, N):
        if sortA[i][1] == sortA[save][1]:
            _next[sortA[i-1][0]] = sortA[i][0]
        else:
            _next[sortA[i-1][0]] = sortA[save][0]
            save = i
    _next[sortA[N-1][0]] = sortA[save][0]
    # print "_next: " + str(_next)
    start = 0
    minCntToEmpty = 0
    while _next[start] != N - 1:
        if _next[start] <= start:
            minCntToEmpty += 1
        start = _next[start] + 1
        # print "start: " +  str(start)
    minCntToEmpty +=1
    # print "minCntToEmpty: " + str(minCntToEmpty)
    K = K % minCntToEmpty
    cntDown = K
    if cntDown == 0:
        print
        return
    # print "cntDown: " + str(cntDown)
    start = 0
    while cntDown > 1:
        if _next[start] <= start:
            cntDown -= 1
        start = _next[start] + 1
        # print "start: " +  str(start)
    i = start
    # print "i: " + str(i)
    while i < N:
        if _next[i] <= i:
            print A[i][1],
            i += 1
        else:
            i = _next[i] + 1

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:

import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
import math

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

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

def minus():
	return -1

D = defaultdict(minus)
D2 = defaultdict(minus)
jump = []
first = deque()
for i in range(N):
	if D[A[i]] != -1:
		bisect.insort(jump, (D[A[i]], i))
	D[A[i]] = i
	if D2[A[i]] == -1:
		D2[A[i]] = i
	first.append(D2[A[i]])

x = 0
roop = [0]
syugo = set()
syugo.add(x)
while True:
	while True:
		loc = bisect.bisect_left(jump, (x, x))
		#print(x,loc,jump)
		if loc < len(jump):
			if x == jump[loc][0]:
				x = jump[loc][1] + 1
			else:
				break
		else:
			break
	if x == N:
		x = 0
	else:
		x = first[x % N] + 1
	size1 = len(syugo)
	syugo.add(x)
	size2 = len(syugo)
	if size1 == size2:
		break
	else:
		roop.append(x)
mod = (K - 1) % len(roop)
x = roop[mod] %N
#print(roop, first, x)
output = []
while x < N:
	loc = bisect.bisect_left(jump, (x, x))
	if loc < len(jump):
		if x == jump[loc][0]:
			x = jump[loc][1]
			x = x + 1
		else:
			output.extend(A[x:jump[loc][0]])
			x = jump[loc][0]
			break
	else:
		output.extend(A[x:N])
		break

for i in range(len(output)):
	print(output[i], end='')
	print(" ", end='')
print('\n')

Submission status: Wrong Answer

Solution code:

import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
import math

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

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

def minus():
	return -1

D = defaultdict(minus)
D2 = defaultdict(minus)
jump = []
first = deque()
for i in range(N):
	if D[A[i]] != -1:
		bisect.insort(jump, (D[A[i]], i))
	D[A[i]] = i
	if D2[A[i]] == -1:
		D2[A[i]] = i
	first.append(D2[A[i]])

x = 0
roop = [0]
syugo = set()
syugo.add(x)
while True:
	while True:
		loc = bisect.bisect_left(jump, (x, x))
		print(x,loc,jump)
		if loc < len(jump):
			if x == jump[loc][0]:
				x = jump[loc][1] + 1
			else:
				break
		else:
			break
	if x == N:
		x = 0
	else:
		x = first[x % N] + 1
	size1 = len(syugo)
	syugo.add(x)
	size2 = len(syugo)
	if size1 == size2:
		break
	else:
		roop.append(x)
mod = (K - 1) % len(roop)
x = roop[mod] %N
print(roop, first, x)
output = []
while x < N:
	loc = bisect.bisect_left(jump, (x, x))
	if loc < len(jump):
		if x == jump[loc][0]:
			x = jump[loc][1]
			x = x + 1
		else:
			output.extend(A[x:jump[loc][0]])
			x = jump[loc][0]
			break
	else:
		output.extend(A[x:N])
		break

for i in range(len(output)):
	print(output[i], end='')
	print(" ", end='')
print('\n')

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

s = {}
ans = [-1 for _ in range(n)]
cur = 0
times = 0
for r in range(k):
    for ai in a:
        if s.get(ai) is None:
            s[ai] = cur
            ans[cur] = ai
            cur += 1
        else:
            post = s[ai]
            for i in range(cur - 1, post - 1, -1):
                s.pop(ans[i])
            cur = post
        times += 1
        if (k * n) % times == 0 and cur == 0:
            break
    else:
        continue
    break

print(*ans[0:cur])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
As = [int(i) for i in input().split()]

s = []
extra = {}
loop_num = 1

for i in range(K):
    for val in As:
        if val not in s:
            s.append(val)
        elif s.index(val) == 0:
            s = []
        else:
            s = s[0:s.index(val)]
    extra[i] = s[:]

    if len(s) == 0:
        loop_num = i + 1
        break

if loop_num == 1 or K%loop_num == 0:
    print("")
else:
    print(*extra[K%loop_num - 1])

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]

    numpos = dict()
    wordlist = [-1] * N
    for i in reversed(range(N)):
        if A[i] not in numpos:
            wordlist[i] = A[i]
            
        else:
            if numpos[A[i]] == N - 1: wordlist[i] = -1
            else: wordlist[i] = wordlist[numpos[A[i]] + 1]
        numpos[A[i]] = i

    #print(numpos)
    #print(wordlist)

    rem = [] #残る数列の変遷をどうにかして求める
    startindex = 0
    appeared = set()
    appeared_index = dict()
    rep_start = 0
    for i in range(K):
        remtop = wordlist[startindex]
        
        if remtop == -1: 
            rem.append(remtop)
            break
        elif remtop in appeared:
            rep_start = appeared_index[remtop]
            break
        else: 
            appeared |= {remtop}
            appeared_index[remtop] = i
            rem.append(remtop)
            startindex = (numpos[remtop] + 1) % N
        

    #print(rem)

    rep = len(rem) - rep_start
    ans = (K - rep_start) % rep
    ans -= 1
    #print(ans)
    if ans == -1: print("")
    else:
        if ans == 0: startindex = rep_start
        else: startindex = numpos[rem[rep_start + ans - 1]] + 1
        out = []
        using = dict()
        l = 0
        for i in range(startindex, N):
            if A[i] in using:
                aindex = using[A[i]]
                l = aindex
                for a in out[aindex:]:
                    using.pop(a)
                out = out[:aindex]
            else:
                out.append(A[i])
                using[A[i]] = l
                l += 1
            #print(out, using, l)
        print(" ".join(map(str, out)))


    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
s=[]
m=k%(n+1)
for i in range(0,m+1):
    if s.count(A[i%n])==0:
       s.append(A[i%n])
    else:
       while s.count(A[i%n])!=0:
            del s[-1]
for j in range(0,len(s)):
    s[j]=str(s[j])
print(" ".join(s))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
As = list(map(int, input().split()))


# if K % 2 == 1:
#     K = 1
# else:
#     K = 2
n = len(set(As))
K %= n
X = [As[i%N] for i in range(N*K)]

s = []
Nmax = 2*10**5 + 1
dp = [0] * Nmax #最初に入ってあるiの数

set_x = set()
for i,x in enumerate(X):
    seq = dp[x]
    if seq == 0:
        dp[x] = i+1
        set_x.add(x)    
    else:
        set_tmp = set_x.copy()
        for s in set_tmp:
            if seq - dp[s] <= 0:
                dp[s] = 0
                set_x.remove(s)

ans1 = sorted([(dp[s],s) for s in set_x])
ans = [i for x,i in ans1]
print(*ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

cnt = 1
search = True
res_list = []

resA = []
while 1:
    for a in A:
        if len(resA) == 0:
            resA.append(a)
            continue
        for index, resa in enumerate(resA):
            if a == resa:
                if index == 0:
                    resA = []
                    break
                else:
                    resA = resA[:index]
                    break
        else:
            resA.append(a)
    if resA in res_list:
        break
    else:
        res_list.append(resA)
        cnt += 1
print(res_list[K%cnt])

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = list(map(str, input().split()))

s = []
tmp = []
for i in range(K):
        for n in A:
                if n in s:
                        while n in s:
                                s.pop(-1)
                else:
                        s.append(n)
        if s in tmp:
                break
        else:
                tmp.extend(s)

print(tmp)
tmp = list(tmp[K % len(tmp) - 1])
for ans in tmp:
        print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
s=[]
m=k%(n+1)
for i in range(0,m):
    if s.count(A[i%n])==0:
       s.append(A[i%n])
    else:
       while s.count(A[i%n])!=0:
            del s[-1]
for j in range(0,len(s)):
    s[j]=str(s[j])
print(" ".join(s))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

cnt = 1
search = True
res_list = []

resA = []
while 1:
    print('res_list', res_list)
    print('cnt', cnt)
    for a in A:
        if len(resA) == 0:
            resA.append(a)
            continue
        for index, resa in enumerate(resA):
            if a == resa:
                if index == 0:
                    resA = []
                    break
                else:
                    resA = resA[:index]
                    break
        else:
            resA.append(a)
    print('  res_list', res_list)	
    if resA in res_list:
        break
    else:
        res_list.append(resA)
        cnt += 1
print(res_list[K%cnt])

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]

    numpos = dict()
    wordlist = [-1] * N
    for i in reversed(range(N)):
        if A[i] not in numpos:
            wordlist[i] = A[i]
            
        else:
            if numpos[A[i]] == N - 1: wordlist[i] = -1
            else: wordlist[i] = wordlist[numpos[A[i]] + 1]
        numpos[A[i]] = i

    #print(numpos)
    #print(wordlist)

    rem = [] #残る数列の変遷をどうにかして求める
    startindex = 0
    appeared = set()
    appeared_index = dict()
    rep_start = 0
    for i in range(len(A)):
        remtop = wordlist[startindex]
        
        if remtop == -1: 
            rem.append(remtop)
            break
        elif remtop in appeared:
            rep_start = appeared_index[remtop]
            break
        else: 
            appeared |= {remtop}
            appeared_index[remtop] = i
            rem.append(remtop)
            startindex = (numpos[remtop] + 1) % N
        

    #print(rem)

    rep = len(rem) - rep_start
    ans = (K - rep_start) % rep
    ans -= 1
    #print(ans)
    if ans == -1: print("")
    else:
        if ans == 0: startindex = rep_start
        else: startindex = numpos[rem[rep_start + ans-1]] + 1
        out = []
        using = dict()
        l = 0
        for i in range(startindex, N):
            if A[i] in using:
                aindex = using[A[i]]
                l = aindex
                for a in out[aindex:]:
                    using.pop(a)
                out = out[:aindex]
            else:
                out.append(A[i])
                using[A[i]] = l
                l += 1
            #print(out, using, l)
        print(" ".join(map(str, out)))


    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

def main():
  n,k=LI()

  l=LI()

  b=[]

  # print(summarize_list(l))

  a=[]

  # l=l*7
  # for x in l:
  #   y=a.count(x)
    
  #   if y>0:
  #     while True:
  #       if y==0:
  #         break
  
  #       p=a.pop()
  #       # print(a)
  #       if p==x:
  #         y-=1
  
  #   else:
  #     a.append(x)
  #     # print(a)

  # return ' '.join([str(x) for x in a])

  c=1
  while True:
    l=l*c
    # print(l)
    for x in l:
      y=a.count(x)
      
      if y>0:
        while True:
          if y==0:
            break
  
          p=a.pop()
          # print(a)
          if p==x:
            y-=1
  
      else:
        a.append(x)
        # print(a)

    if b.count(a)>0:
      # print(a)
      # print(b)
      return ' '.join([str(x) for x in b[(k+1)%len(b)]])
    else:
      b.append(a)
      a=[]
      c+=1

# main()
print(main())

Submission status: Wrong Answer

Solution code:
#%%
N,K = map(int,input().split())
A = list(input().split())
l = []



tmp = []

T = 100000000000000000000000
h = 0
tmp_copy = []
for i in range(K):
    j = 0
    while j < N :
        print(j)
        if A[j] not in tmp_copy :
            if A[j:].count(A[j])>=2 and A[j:].count(A[j]) %2 == 0 :
                j = [i for i, x in enumerate(A) if x == A[j]][-1]
                print(j)
            elif A[j:].count(A[j])>=3 and A[j:].count(A[j]) %2 != 0:
                j = [i for i, x in enumerate(A) if x == A[j]][-2]

                print(j)
        elif A[j] in tmp_copy :
            if A[j:].count(A[j])>=2 and A[j:].count(A[j]) %2 == 0 :
                j = [i for i, x in enumerate(A) if x == A[j]][-2]
                print(j)                
            elif A[j:].count(A[j])>=3 and A[j:].count(A[j]) %2 != 0:
                j = [i for i, x in enumerate(A) if x == A[j]][-1]
                print(j)

        if A[j] not in tmp :
            tmp.append(A[j])

        else:
            index = len(tmp) - tmp[::-1].index(A[j]) -1
            del tmp[index:]
        j = j+1

    tmp_copy = tmp.copy()
    l.append(tmp_copy)

    if l[i] in l[:i]:
        T = i
        break


ans = l[(K-1)%T]
print(T)
print(' '.join(ans))
print(l)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

itr = min(N, K)
s = []
for i in range(itr):
  for a in A:
    if a not in s:
      s.append(a)
    else:
      while a in s:
        s.pop(-1)
print(" ".join(map(str, s)))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list
def summarize_list(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res

def main():
  n,k=LI()

  l=LI()

  b=[]

  # print(summarize_list(l))

  a=[]

  # l=l*7
  # for x in l:
  #   y=a.count(x)
    
  #   if y>0:
  #     while True:
  #       if y==0:
  #         break
  
  #       p=a.pop()
  #       # print(a)
  #       if p==x:
  #         y-=1
  
  #   else:
  #     a.append(x)
  #     # print(a)

  # return ' '.join([str(x) for x in a])

  c=1
  while True:
    l=l*c
    # print(l)
    for x in l:
      y=a.count(x)
      
      if y>0:
        while True:
          if y==0:
            break
  
          p=a.pop()
          # print(a)
          if p==x:
            y-=1
  
      else:
        a.append(x)
        # print(a)

    if b.count(a)>0:
      # print(a)
      # print(b)
      return ' '.join([str(x) for x in b[k%len(b)]])
    else:
      b.append(a)
      a=[]
      c+=1

# main()
print(main())