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: Runtime Error

Solution code:
N,K = map(int, input().split())
A = list(map(int,input().split()))
MAX = 10**5+1
nxt = [-1 for i in range(MAX)]

last_index = [-1 for i in range(MAX)]
next_index = [-1 for i in range(MAX)]
first_index = [-1 for i in range(MAX)]
for i in range(N):
	a = A[i]
	last = last_index[a]
	if last >= 0:
		next_index[last] = i
	else:
		first_index[a] = i
	last_index[a] = i

start_stat = 0
while True:
	current = first_index[start_stat] + 1
	while current < N and next_index[current] != -1:
		current = next_index[current] + 1
	if current >= N:
		nxt[start_stat] = 0
		break
	else:
		stat = A[current]
		nxt[start_stat] = A[current]
		if nxt[A[current]] == -1:
			start_stat = A[current]
		else:
			break

order = [0]
in_order = [False for i in range(MAX)]
in_order[0] = True
last_stat = nxt[0]
while not in_order[last_stat]:
	order.append(last_stat)
	in_order[last_stat] = True
	last_stat = nxt[last_stat]
a,b = 0,len(order)
for x in order:
	if x == last_stat:
		break
	else:
		a += 1
		b -= 1
stat_index = K if K < a else (K-a) % b
init_status = order[stat_index]
before_stat = order[(stat_index - 1) % len(order)]
current = first_index[before_stat] + 1
if init_status == 0:
	print("")
	exit()
ans = []
while current < N:
	if next_index[current] != -1:
		current = next_index[current] + 1
	else:
		ans.append(A[current])
		current += 1
print( " ".join(list(map(str, ans))))

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
A = list(map(int,input().split()))
MAX = 10**5+1
nxt = [-1 for i in range(MAX)]

last_index = [-1 for i in range(MAX)]
next_index = [-1 for i in range(N)]
first_index = [-1 for i in range(MAX)]
for i in range(N):
	a = A[i]
	last = last_index[a]
	if last >= 0:
		next_index[last] = i
	else:
		first_index[a] = i
	last_index[a] = i

start_stat = 0
while True:
	current = first_index[start_stat] + 1
	while current < N and next_index[current] != -1:
		current = next_index[current] + 1
	if current >= N:
		nxt[start_stat] = 0
		break
	else:
		stat = A[current]
		nxt[start_stat] = A[current]
		if nxt[A[current]] == -1:
			start_stat = A[current]
		else:
			break

order = [0]
in_order = [False for i in range(MAX)]
in_order[0] = True
last_stat = nxt[0]
while not in_order[last_stat]:
	order.append(last_stat)
	in_order[last_stat] = True
	last_stat = nxt[last_stat]
a,b = 0,len(order)
for x in order:
	if x == last_stat:
		break
	else:
		a += 1
		b -= 1
stat_index = K if K < a else (K-a) % b
init_status = order[stat_index]
before_stat = order[(stat_index - 1) % len(order)]
current = first_index[before_stat] + 1
if init_status == 0:
	print("")
	exit()
ans = []
while current < N:
	if next_index[current] != -1:
		current = next_index[current] + 1
	else:
		ans.append(A[current])
		current += 1
print( " ".join(list(map(str, ans))))

Submission status: Runtime Error

Solution code:
import random #入力整数列Aの生成に使用

class Node:
    def __init__(self, data): #コンストラクタ
        self.data = data #ノードがもつ数値
        self.left = None #左エッジ
        self.right = None #右エッジ


class BST:
    def __init__(self, number_list): #コンストラクタ
        self.root = None #ルートノード初期化
        for node in number_list: #数値を持つ配列から二分木を生成
            self.insert(node) #挿入メソッドを使ってノードを挿入する
    #挿入
    def insert(self, data):
        n = self.root
        if n == None:
            self.root = Node(data)
            return
        else:
            while True:
                entry = n.data
                if data < entry:
                    if n.left is None:
                        n.left = Node(data)
                        return
                    n = n.left
                elif data > entry:
                    if n.right is None:
                        n.right = Node(data)
                        return
                    n = n.right
                else:
                    n.data = data
                    return
    #検索機能(インターフェース)
    def search(self, search):
        searcher = self._search_bool(search)
        if searcher is None:
            return False
        elif searcher == True:
            return True
        elif searcher == False:
            return False

    #検索機能本体(出力:boolean),深さ優先探索
    #nodeのvisitedはpopで代用
    def _search_bool(self, search):
        n = self.root
        if n is None:
            return None
        else:
            lst = []
            lst.append(n)
            while len(lst) > 0:
                node = lst.pop()
                if node.data == search:
                    return True
                if node.right is not None:
                    lst.append(node.right)
                if node.left is not None:
                    lst.append(node.left)
            return False

    def inorder(self,node): #中順探索 l->r->p^n
        if node is not None:
            self.inorder(node.left)
            print(node.data)
            self.inorder(node.right)
B = BST([0])
import bisect
N, K = map(int, input().split())
A = list(map(int, input().split()))
index = [-1]*(10**5*2+10)
last = [-1]*(N+1)
for i in range(N)[::-1]:
    ind = index[A[i]]
    if ind>=0:
        last[i] = last[ind+1]
        index[A[i]] = -1
    else:
        last[i] = A[i]
        index[A[i]] = i
first_index = [-1]*(10**5*2+10)
for i in range(N):
    if first_index[A[i]]<0:
        first_index[A[i]] = i
loop = [0]
ind = 0
while True:
    next_index = (first_index[last[ind]]+1)%N
    if B.search(next_index):
        for i in range(len(loop)):
            if loop[i]==next_index:
                start = i
                break
        break
    loop.append(next_index)
    B.insert(next_index)
    ind = next_index
    
ll = len(loop)

index = [[] for _ in range(10**5*2+10)]
ans = []
if K-1>=ll:
    ii = loop[(K-start)%(ll-start)-1+start]
else:
    ii = K-1
for i in range(loop[ii], N):
    index[A[i]].append(i)
i=loop[ii]
while i<N:
    if index[A[i]][-1]==i:
        ans.append((str(A[i])))
        i+=1
    else:
        i=index[A[i]][bisect.bisect_left(index[A[i]], i)+1]+1
print(' '.join(ans))

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
l = list(map(int,input().split()))
X = l * K
ans = []
for i in range(N*K):
  if X[i] in ans:
    while X[i] in ans:
      ans.pop()
  else:
    ans.append(X[i])
ans = [str(s) for s in ans]
final_ans = ' '.join(ans)
print(final_ans)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
l = list(map(int,input().split()))
X = l * K
ans = []
for i in range(N*2):
  if X[i] in ans:
    while X[i] in ans:
      ans.pop()
  else:
    ans.append(X[i])
ans = [str(s) for s in ans]
final_ans = ' '.join(ans)
print(final_ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    D = {}
    for j,a in enumerate(A):
        D[a] = D.get(a,[])+[j]

    t,k = 0,0
    T = [0]
    while True:
        k = (D[A[t]].index(t)+1)%len(D[A[t]])
        if k == 0:
            T.append(A[t])
        t = (D[A[t]][k]+1)%N
        if t == 0:
            break

    T[0] = T.pop()
    t = D[T[K%len(T)]][0]+1
    S = []
    while t < N:
        k = (D[A[t]].index(t)+1)%len(D[A[t]])
        if k == 0:
            S.append(A[t])
        t = D[A[t]][k]+1

    res = ' '.join(map(str,S))

    return str(res)

if __name__ == '__main__':
    print(solve())

Submission status: Runtime Error

Solution code:
import math
#試し割法
def trial_division(n):
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    if not factor:
        return 'prime number'
    else:
        factor.append(n)
        return factor

n,k = [int(i) for i in input().split(' ')]
target_numbers = [i - 1 for i in list(set(trial_division(k)))]
# print(target_numbers)
a = [int(i) for i in input().split(' ')]

s = []
for i in range(k):
    for num,j in enumerate(a):
        if j not in s:
            s.append(j)
        else:
            s = s[0:s.index(j)]
    if not s and i in target_numbers:
        break
s = [str(i) for i in s]
print(' '.join(s))

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache
sys.setrecursionlimit(10000)
N, K = [int(i) for i in input().split()]
A = tuple(int(i) for i in input().split())


@lru_cache()
def add_to_list(li, num):
    if num in li:
        li = li[:li.index(num)]
        return li
    else:
        li = li + (num,)
        return li


@lru_cache()
def get(li):
    if len(li) != 1:
        yoi_list_b = get(li[:-1])
        yoi_list = add_to_list(yoi_list_b, li[-1])
    else:
        yoi_list = li
    return yoi_list


li = tuple()
count = 0
for _ in range(K):
    li = get(li + A)
    count += 1
    if not li:
        li = tuple()
        for _ in range(K % count):
            li = get(li + A)
        break

if li:
    for i in li:
        print(i, end=" ")
else:
    pass

Submission status: Runtime Error

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
    for _ in range(len(A)):
        remtop = wordlist[startindex]
        rem.append(remtop)
        if remtop == -1: break
        else: startindex = numpos[remtop] + 1

    #print(rem)

    rep = len(rem)
    ans = K % rep
    ans -= 1
    #print(ans)
    if ans == -1: print("")
    else:
        if ans == 0: startindex = 0
        else: startindex = numpos[rem[ans-1]] + 1
        out = []
        using = dict()
        l = 0
        for i in range(startindex, N):
            if A[i] in using and using[A[i]] <= l:
                out = out[:using[A[i]]]
                l = using[A[i]]
                using.pop(A[i])
            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: Runtime Error

Solution code:
from collections import deque

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

kotae = deque([])
lst = []
d = deque(a)
shugo = []
pattern = 0
while True:
    for kazu in d:
        if kazu in kotae:
            ind = kotae.index(kazu)
            for _ in range(len(kotae) - ind):
                kotae.pop()
        else:
            kotae.append(kazu)
    kotae_lst = list(kotae)
    if kotae_lst in shugo:
        break
    else:
        shugo.append(kotae_lst)
        lst.append(kotae_lst)
        pattern += 1

doko = k % pattern
ans = lst[doko-1]
if ans != []:
    print(' '.join(map(str, ans)))

Submission status: Runtime Error

Solution code:
N_str, K_str = input().split()
N = int(N_str)
K = int(K_str)

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

X = []

def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


def check(J):
    p = 0
    while True:
        inner = my_index_multi(J, J[p])
        if 2 <= len(inner):
            J = J[:inner[0]] + J[inner[1] + 1:]
        else:
            p += 1

        if len(J) <= p:
            return J


air = 0

for i in range(K):
    X.extend(A)
    X = check(X)
    if len(X) == 0:
        air = i + 1
        break

n = int(K / air)

K = K - n * air

for i in range(K):
    X = A * K
    check(X)


for i in range(len(X)):
    print(X[i], end=' ')

Submission status: Runtime Error

Solution code:
n, k = [int(v) for v in input().split()]
al = [int(v) for v in input().split()]

state = []
states = [[]]
ls = 0
for it in range(n):
    for a in al:
        if a in state:
            ia = ls - state[::-1].index(a) - 1
            state = state[0:ia]
            ls = len(state)
        else:
            state.append(a)
            ls += 1
    if state in states:
        period = it + 1
        break
    else:
        states.append(state.copy())

# print(period, states)
print(*states[k%period])

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache
sys.setrecursionlimit(10000)
N, K = [int(i) for i in input().split()]
A = tuple(int(i) for i in input().split()) * K
li = []


@lru_cache()
def add_to_list(li, num):
    if num in li:
        li = li[:li.index(num)]
        return li
    else:
        li = li + (num,)
        return li


@lru_cache()
def get(li):
    if len(li) != 1:
        yoi_list_b = get(li[:-1])
        yoi_list = add_to_list(yoi_list_b, li[-1])
    else:
        yoi_list = li
    return yoi_list


li = get(A)
if li:
    for i in li:
        print(i, end=" ")
else:
    pass

Submission status: Runtime Error

Solution code:
n,k = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')] * k

s = []
for i in a:
    if i not in s:
        s.append(i)
    else:
        s = s[0:s.index(i)]
s = [str(i) for i in s]
print(' '.join(s))

Submission status: Runtime Error

Solution code:
# import numpy as np
# np.set_printoptions(suppress=True)
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())
import sys
sys.setrecursionlimit(10**7)
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N, K = LI()
    a_list = LI()

    pos_dict = {}
    for i, a in enumerate(a_list):
        if a not in pos_dict:
            pos_dict[a] = [i]
        else:
            pos_dict[a].append(i)

    from bisect import bisect_right

    # 開始のj
    head = 0
    irow = 0
    irowth_head = {}
    isloopstop = False

    while True:

        a = a_list[head]

        pos_list = pos_dict[a]
        # 次の位置
        idx = bisect_right(pos_list, head)


        if idx == len(pos_list):
            # これが末尾の場合、次の行の先頭へ
            # 次の行に行く前のこの行の last_head を記録
            irowth_head[irow] = head

            head = pos_list[0] + 1
            irow += 1


            # ループせず目的の行まで来たらいったんbreak
            if irow == K - 1:
                break

        else:
            # 同じ行の場合は続ける
            head = pos_list[idx] + 1


        # 次のheadが先頭の場合、ループするので break
        if head == len(a_list):
            isloopstop = True
            break

    # 最終行は真面目にやる
    # ループしてストップした場合は head を取り直す
    if isloopstop == True:
        nrow_loop = irow + 1
        kthrow_in_loop = (K-1) - nrow_loop * (K // nrow_loop)
        if kthrow_in_loop == nrow_loop - 1:
            # ちょうどループ末尾の場合は出力しない
            print('')
            return
        head = irowth_head[kthrow_in_loop]

    # head からスタートして末尾まで入れていく
    ans = []
    ans_dict = {}
    for i, j in enumerate(range(head, N)):
        a = a_list[j]
        if a not in ans_dict:
            ans.append(a_list[j])
            ans_dict[a] = i
        else:
            ans = ans[:ans_dict[a]]
            del ans_dict[a]


    print(' '.join([str(a) for a in ans]))

solve()

Submission status: Runtime Error

Solution code:
n,k = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')] * k
print(n,k)
print(a)

s = []
for i in a:
    if i not in s:
        s.append(i)
    else:
        s = s[0:s.index(i)]
print(s)

Submission status: Runtime Error

Solution code:
import sys
from bisect import bisect_right
from collections import defaultdict
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))

N, K = inpl()
A = inpl()
places = defaultdict(list)
nextplace = [-1]*N
newloop = [-1]*N
for i in range(N):
    places[A[i]].append(i)
for i in range(N):
    pl = places[A[i]]
    k = bisect_right(pl,i)
    if k >= len(pl):
        nextplace[i] = pl[0]+1
        newloop[i] = 1
    else:
        nextplace[i] = (pl[k]+1)%N
        if nextplace[i] == 0:
            newloop[i] = 1
        else:
            newloop[i] = 0

Nloop = 0
prev_loop = [-1]*N
j = 0
while prev_loop[j] < 0 and (Nloop+newloop[j] < K):
    prev_loop[j] = Nloop
    Nloop += newloop[j]
    j = nextplace[j]
if prev_loop[j] >= 0:
    period = Nloop - prev_loop[j]
    Nloop = K - (K - Nloop) % period
    while Nloop+newloop[j] < K:
        Nloop += newloop[j]
        j = nextplace[j]

S = [0]*N
lenS = 0
XinS = defaultdict(lambda: -1)
for i in range(j,N):
    if XinS[A[i]] < 0:
        S[lenS] = A[i]
        XinS[A[i]] = lenS
        lenS += 1
    else:
        lenS = XinS[A[i]]
        XinS[A[i]] = -1
if lenS > 0:
    print(' '.join(map(str,S[:lenS])))

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/agc036/tasks/agc036_b
from itertools import product
import numpy as np


values_flow_cache = {}


def calc(N: int, K: int, A: np.ndarray) -> np.ndarray:
    loop_values, rest_iter = calc_until_find_loop(N, K, A)
    loop_len = loop_values.shape[0]
    return loop_values[rest_iter % loop_len]


def calc_until_find_loop(N: int, K: int, A: np.ndarray):  # (loop_values, rest_iter)
    results = []
    values_to_idx = {}
    values = np.array([])
    for i in range(K):
        values = one_iter(N, A, values)
        tup_values = tuple(values)

        if tup_values in values_to_idx:
            return np.array(results[values_to_idx[tup_values] :]), (K - i - 1)

        values_to_idx[tup_values] = len(results)
        results.append(values)

    return np.array([values]), 0


def one_iter(N: int, A: np.ndarray, prev_values: np.ndarray) -> np.ndarray:
    values = prev_values.tolist()
    values_to_idx = {v: i for i, v in enumerate(values)}
    for j in range(N):
        tup_values = tuple(values)
        if (tup_values, A[j]) in values_flow_cache:
            values, values_to_idx = values_flow_cache[(tup_values, A[j])]
            continue

        if A[j] not in values_to_idx:
            values_to_idx[A[j]] = len(values)
            values.append(A[j])
        else:
            removing = values[values_to_idx[A[j]] :]
            values = values[: values_to_idx[A[j]]]
            for rm in removing:
                if rm not in values_to_idx:
                    continue
                del values_to_idx[rm]

        values_flow_cache[(tup_values, A[j])] = (tuple(values), values_to_idx.copy())
    return np.array(values)


def load_input_as_int_array():
    return np.array([int(v) for v in input().split(" ")])


N, K = load_input_as_int_array()
A = load_input_as_int_array()
result = calc(N, K, A)
print(" ".join([str(v) for v in result]))

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = []
for i in range(K):
    for value in A:
        if value not in ans:
            ans.append(value)
        else:
            while value in ans:
                ans.pop()
    if ans == []:
        period = i + 1
        break
mod = K % period 
ans = []
for _ in range(mod):
    for value in A:
        if value not in ans:
            ans.append(value)
        else:
            while value in ans:
                ans.pop()
out = ''
for element in ans:
    out += str(element) + ' '
print(out[0:-1])

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
arr = list(map(int, input().split()))
assert(n == 3)
assert(k == 2)
assert(arr[0] == 1)
assert(arr[1] == 2)
assert(arr[2] == 3)

Submission status: Runtime Error

Solution code:
n, k = [ int(v) for v in input().split() ]

num_list = [ int(v) for v in input().split() ]

que = []
que_list = [[]]
f_flg = 0
for i in range(k):
    for j in num_list:
        if j not in que:
            que.append(j)
        else:
            que = que[:que.index(j)]

    if que == []:
        f = i+1
        f_flg = 1
        break
    
    que_list.append(copy.deepcopy(que))

    
if f_flg == 0:
    print(*que)
else:
    mod = k % f
    print(*que_list[mod])

Submission status: Runtime Error

Solution code:
import bisect
N, K = map(int, input().split())
A = list(map(int, input().split()))
index = [-1]*(10**5*2+10)
last = [-1]*(N+1)
for i in range(N)[::-1]:
    ind = index[A[i]]
    if ind>=0:
        last[i] = last[ind+1]
        index[A[i]] = -1
    else:
        last[i] = A[i]
        index[A[i]] = i
first_index = [-1]*(10**5*2+10)
for i in range(N):
    if first_index[A[i]]<0:
        first_index[A[i]] = i
loop = [0]
ind = 0
while True:
    next_index = first_index[last[ind]]+1
    if next_index == N or next_index == 0:
        break
    loop.append(next_index)
    ind = next_index
ll = len(loop)
index = [[] for _ in range(10**5+10)]
ans = []
for i in range(loop[K%ll-1], N):
    index[A[i]].append(i)
i=loop[K%ll-1]
while i<N:
    if index[A[i]][-1]==i:
        ans.append((str(A[i])))
        i+=1
    else:
        i=index[A[i]][bisect.bisect_left(index[A[i]], i)+1]+1
print(' '.join(ans))

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
A = list(input().split())
ans = A[:]
i=0
k_num = 1
while i < len(A)-1:
    if k_num < K:
        ans = ans + A
        k_num+=1
    head = ans[i]
    if head in ans[i+1:]:
        index_head = ans[i+1:].index(head) + i+1
        ans = ans[:i] + ans[index_head+1:]
    else:
        i+=1
print(*ans)

Submission status: Runtime Error

Solution code:
N,K=[int(e) for e in input().split(' ')]
A=[int(e) for e in input().split(' ')]

X=A*K
s=[]
for x in X:
    if x in s:
        s=s[0:s.index(x)]
    else:
        s.append(x)

o=''
for e in s:
    o=o+'{} '.format(e)
print(o)

Submission status: Runtime Error

Solution code:
N_str, K_str = input().split()
N = int(N_str)
K = int(K_str)

A_str = input().split()
A = [int(a) for a in A_str]
print(A)
X = A * K


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


i = 0
while True:
    inner = my_index_multi(X, X[i])
    print(X)
    if 2 <= len(inner):
        X = X[inner[1] + 1:]
        continue
    else:
        i += 1

    if len(X) <= i:
        break


for i in range(len(X)):
    print(X[i], end=' ')

Submission status: Runtime Error

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

i=0
A = A * K
#print(A)
while i < len(A)-1:
    head = A[i]
    if head in A[i+1:]:
        index_head = A[i+1:].index(head) + i+1
        A = A[:i] + A[index_head+1:]
    else:
        i+=1
print(*A)

Submission status: Runtime Error

Solution code:
from sys import exit, setrecursionlimit, stdin, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *
import operator
import math
from fractions import gcd
from random import randint

setrecursionlimit(10**8)

def input():
  return stdin.readline().strip()

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, K = reads()
A = reads()

skip = [-1] * N
first_occ = {}
for i in range(N-1, -1, -1):
  a = A[i]
  if a in first_occ:
    if first_occ[a] < N-1:
      skip[i] = skip[first_occ[a] + 1]
    else:
      skip[i] = first_occ[a] + 1
  else:
    skip[i] = i
  first_occ[a] = i

back = [first_occ[A[i]] + 1 for i in range(N)] + [0]
next_state = [skip[back[q]] for q in range(N+1)]


q = skip[0]

rev = {}
memo = {}
i = 0
while True:
  if q in rev:
    j = rev[q]
    break
  rev[q] = i
  memo[i] = q
  q = next_state[q]
  i += 1

m = i - j
q = memo[j + (K - 1 - j) % m]

s = []
while q < N:
  if skip[q] == q:
    s.append(A[q])
    q += 1
  else:
    q = skip[q]

print(*s)

Submission status: Runtime Error

Solution code:
N_str, K_str = input().split()
N = int(N_str)
K = int(K_str)

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

X = []


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


for _ in range(K):
    X.extend(A)

i = 0
while True:
    inner = my_index_multi(X, X[i])
    if 2 <= len(inner):
        X = X[inner[1] + 1:]
        continue
    else:
        i += 1

    if len(X) <= i:
        break

for i in range(len(X)):
    print(X[i], end=' ')

Submission status: Runtime Error

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

i=0
A = A * K
#print(A)
while i < len(A)-1:
    head = A[i]
    if head in A[i+1:]:
        index_head = A[i+1:].index(head) + i+1
        A = A[:i] + A[index_head+1:]
    else:
        i+=1
print(A)

Submission status: Runtime Error

Solution code:
import math

def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    
    if len(A) > 2:
        if A[-2] == A[-1]:
            print()
            return 

    # X = A * min(K, )
    X = A * K
    dp = {}
    memo = set()
    
    # print(X)
    
    L = []

    K = min(K, K % 10 + 10)
    for k in range(K):
        for a in A:
            # print(L, memo)
            if a not in memo:
                i = len(L)
                L.append(a)
                dp[a] = i
                memo.add(a)
            else:
                i = dp[a]
                L = L[:i]
                # r = memo
                memo = set(L)
                dp = {x: i for i,x in enumerate(L)}

    print(*L, sep=" ")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
x=input().split()
y=input().split()
s=""
for i in range(int(x[0]*int(x[1]))):
  if s.find(y[i%len(y)]) is -1:
    s+=y[i%len(y)]
  elif s.find(y[i%len(y)]) is not -1:
    s=s[i%len(y)-1]

z=""
for i in s:
  z+=i+" "
print(z)

Submission status: Runtime Error

Solution code:
import math

def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    
    if len(A) > 2:
        if A[-2] == A[-1]:
            print()
            return 

    # X = A * min(K, )
    X = A * K
    dp = {}
    memo = set()
    
    # print(X)
    
    L = []

    for k in range(K):
        for a in A:
            # print(L, memo)
            if a not in memo:
                i = len(L)
                L.append(a)
                dp[a] = i
                memo.add(a)
            else:
                i = dp[a]
                L = L[:i]
                # r = memo
                memo = set(L)
                dp = {x: i for i,x in enumerate(L)}

    print(*L, sep=" ")

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

B = []
count = 0
for i in range(N*K):
    a = A[i%N]
    if a not in B:
        B.append(a)
    else:
        x = B.index(a)
        B = B[:x]
    count += 1
    #print(B)
    if len(B)==0:
        break
    
#print(count)
term = count
trial = (K)%term#term+1回で空になる
ans = []
A_net = A * trial

for a in A_net:
    if a not in ans:
        ans.append(a)
    else:
        x = ans.index(a)
        ans = ans[:x]
#print(A)
#print(B)
ans = list(map(lambda x: str(x),ans))
print(" ".join(ans))

Submission status: Runtime Error

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

dic = {}
result = []
result_dic = {}
result_dic_index = {}

loop = 0
for k in range(K):
    for i in range(N):
        v = dic.get(A[i], None)
        # print(result, dic, A[i])
        if v is None:
            dic[A[i]] = 1
            result.append(A[i])
        else:
            while True:
                if result[-1] == A[i]:
                    dic.pop(result.pop(-1))
                    break
                else:
                    dic.pop(result.pop(-1))
    exist_v = result_dic.get(tuple(result), None)
    if exist_v is not None:
        loop = k
        break
    else:
        result_dic[tuple(result)] = k
        result_dic_index[k] = tuple(result)

index = (K - 1) % loop

answers = result_dic_index[index]
for answer in answers:
    print(answer, end=" ")
print()

Submission status: Runtime Error

Solution code:
n,k=map(int, raw_input().split())
a=map(int, raw_input().split())
s=[]

for i in range(k):
#    print "i="+str(i)
    for j in range(n):
#        print "j="+str(j)
        if a[j] in s:
            for l in range(len(s)-1,-1,-1):
#                print "l="+str(l)
                if a[j] == s[l]:
                    s.pop(l)
                    break
                else:
                    s.pop(l)
        else:
            s.append(a[j])
#        print s

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

Submission status: Runtime Error

Solution code:
n,k=[int(i) for i in input().split()]
index=(n-1)%k

s=[input().split()]
s=s[index:]
print(" ".join(s))