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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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 []
    else:
        factor.append(n)
        return factor

n,k = [int(i) for i in input().split(' ')]
target_numbers = list(set(trial_division(k)))
if target_numbers:
    target_numbers = [i - 1 for i in 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: Time Limit Exceeded

Solution code:
from sys import stdin, exit

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

X = []
Y = []
for k in range(len(A) + 1):
    X.extend(A)
    Y.extend(A)
cnt = 0
while cnt == 0 or cnt % len(A) != 0:
    x = X[0]
    ind = 1
    while X[ind] != x:
        ind += 1
    X = X[ind + 1:]
    cnt += ind + 1

res = (N * K) % cnt
if res == 0:
    print(*[])
    exit()

Y = Y[0:res]

cc = 0
ans = []
T = [[] for _ in range(max(Y) + 1)]
while cc < res - 1:
    y = Y[0]
    index = 1
    while index < len(Y):
        if Y[index] != y:
            index += 1
        else:
            break
    if index != len(Y):
        Y = Y[index + 1:]
        cc += index + 1
    else:
        ans.append(y)
        Y = Y[1:]
        cc += 1

print(*(ans + Y))

Submission status: Time Limit Exceeded

Solution code:
# B
if __name__=='__main__':
    N,K = map(int,input().split())
    A = [int(x) for x in input().split()]
    s_list = []
    s = []
    for i in range(N):
        for j in range(N):
            if A[j] in s:
                del s[s.index(A[j]):]
            else:
                s.append(A[j])
        s_list.append(' '.join(map(str,s)))
        if len(s)==0:
            break
    print(s_list[K%len(s_list)-1])

Submission status: Time Limit Exceeded

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

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

#aa = [ ai for i in range(k) for ai in a]
#aa = [ ai for ai in a]

s = []
j = 0
#for j in range(5):
while j < k :
  for i in aa:
    try:
      p = s.index(i)
      del s[p:]
    except ValueError:
      s.append(i)
      
  if j == 0 and len(s) == 0:
    break
  elif j > 1 and len(s) == 0:
    j = k - k % j - 1
    
  else:
    j += 1

if len(s) > 0:
  print(s[0:1][0],end="")
  
  if len(s) > 1:
    for ss in s[1:]:
      print(" {}".format(ss),end="")

print()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import bisect

d = defaultdict(list)
N,K=[int(x) for x in input().split()] 
K=N*K
A=[int(x) for x in input().split()]
for i in range(N):
    a=A[i]
    d[a].append(i)
keys=d.keys()
L={}
for k in keys:
    L[k]=len(d[k])
E=[0 for i in range(N)]
for i in range(N):
    a=A[i]
    ci=bisect.bisect_left(d[a], i)
    ni=(ci+1)%L[a]
    E[i]=(d[a][ni]-d[a][ci])%N
    if E[i]==0:
        E[i]=N
    E[i]+=1
#ss=sum(E)
ss=0
j=0
while(1):
    ss+=E[j]
    j=(j+E[j])%N
    if j==0:
        break
#print(ss)
K%=ss
j=0
#print(E)
while(K > E[j]):
    K-=E[j]
    j=(j+E[j])%N
    #print(j)
s=[]
for k in range(K):
    if A[j] not in s:
        s.append(A[j])
    else:
        ind=s.index(A[j])
        s=s[:ind]
    j=(j+1)%N
#print(s)
print(" ".join([str(x) for x in s]))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import collections



def solve(N: int, K: int, A: "List[int]"):
    last = {}
    dp = {}
    for i,a in enumerate(A):
        if a in last:
            dp[(a,last[a])] = i
        else:
            dp[(a,-1)] = i
        last[a] = i

    s = []
    for i in range(K):
        j = 0
        if len(s) > 0:
            j = dp[(s[0],-1)] + 1
            s = []
        while j < N:
            if (A[j],j) in dp:
                j = dp[(A[j],j)] + 1
            else:
                s.append(A[j])
                j += 1

    print(" ".join([str(c) for c in s]))
                


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N-1-0+1) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

ans = []
s = set()
q = deque([])

def solve():
  N, K = map(int, input().split())
  A = [int(i) for i in input().split()]
  for i in range(K):
    skipped = True
    if len(q) != 0:
      skipped = False
      head = q.popleft()
    for a in A:
      if not skipped:
        if a != head: continue
        skipped = True
        q.clear()
        s.clear()
        continue
      if a not in s:
        q.append(a)
        s.add(a)
      else:
        while True:
          out = q.pop()
          s.remove(out)
          if a == out: break
    ans.append(list(q))
    if len(q) == 0: break

  return ans[K % len(ans) - 1]

print(*solve())

Submission status: Time Limit Exceeded

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())
super_flag = False
try:
    A = A * K
except BaseException:
    super_flag = True


@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


if not super_flag:
    li = get(A)
else:
    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[:-1]:
        print(i, end=" ")
    print(li[-1])
else:
    pass

Submission status: Time Limit Exceeded

Solution code:
import sys
p = [[int(t) for t in r.split()] for r in  sys.stdin.read().split('\n') if r != '']
N, K = p[0]
A = p[1]
s = []
d = {}
e = []
for i in range(K):
    for j in range(N):
        x = A[j]
        if x in d:
            ix = d.pop(x)
            for k in range(len(s) - 1, ix, -1):
                d.pop(s[k]) if s[k] in d else None
            s = s[:ix]
        else:
            d[x] = len(s)
            s += [x]
    if s in e:
        print(' '.join(str(i) for i in e[(N * K - 1) % len(e)]))
        quit()
    e += [s.copy()]
print(' '.join(str(i) for i in e[(N * K - 1) % len(e)]))

Submission status: Time Limit Exceeded

Solution code:
import math

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

_X = list(map(int, input("").strip().split(" ")))

X = []

for _ in range(K):
  X += _X

output_X = []
  
for i in X:
  if i in output_X:
    i_index = output_X.index(i)
    output_X = output_X[:i_index]
  else:
    output_X += [i]
  
out_string = ""

out_string = " ".join(list(map(str, output_X)))

print(out_string)

Submission status: Time Limit Exceeded

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

remain = []
T = 0
flag = True
while flag:
    B = remain + A
    num_list = []
    for i in range(len(B)):
        if(not B[i] in num_list):
            num_list.append(B[i])
        else:
            index = num_list.index(B[i])
            num_list = num_list[:index]
    remain = num_list
    T += 1
    if(remain == []):
        break

M = K % T

remain = []
for i in range(M):
    B = remain + A
    num_list = []
    for i in range(len(B)):
        if(not B[i] in num_list):
            num_list.append(B[i])
        else:
            index = num_list.index(B[i])
            num_list = num_list[:index]
    remain = num_list

ans = ''
for i in range(len(remain)):
    ans += str(remain[i]) + ' '
print(ans)

Submission status: Time Limit Exceeded

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 = list(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: Time Limit Exceeded

Solution code:
import copy

n,k=list(map(int,input().split()))
li=list(map(int,input().split()))
first_list=copy.deepcopy(li)

remain_list=[]
pre_list=[[]]

for j in range(k):
  for i in range(len(li)):
    if li[i] not in remain_list:
      remain_list.append(li[i])
    else:
      remain_list=remain_list[:remain_list.index(li[i])]
  if remain_list not in pre_list:
    pre_list.append(remain_list)
    li=remain_list+first_list
    remain_list=[]
  else:
    pre_list.append(remain_list)
    break

ans_count=pre_list.index(pre_list[-1])

answer=ans_count
pre_list=pre_list[ans_count:]
ans_count=len(pre_list)-ans_count
k-=answer

L=[str(a) for a in pre_list[k%(ans_count-1)]]
L=" ".join(L)
print(L)

Submission status: Time Limit Exceeded

Solution code:
import math

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

_X = list(map(int, input("").strip().split(" ")))

X = []

for _ in range(K):
  X += _X

output_X = []
  
for i in X:
  if i in output_X:
    i_index = output_X.index(i)
    output_X = output_X[:i_index]
  else:
    output_X += [i]
  
out_string = ""
for output_x in output_X:
  out_string += str(output_x) + " "
print(out_string)

Submission status: Time Limit Exceeded

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

s = []
i = 0
while i < n * k:
    r = i % n
    if r == 0 and s == [] and i != 0:
        i = i * (n * k // i)
    x = a[r]
    j = 0
    try:
        seq = list(a)
        if i // n < k - 1:
            seq.extend(a)
        j = seq[r+1:].index(x)
        i = i + j + 2
    except:
        s.append(a[r])
        i += 1
print(' '.join(str(y) for y in s))

Submission status: Time Limit Exceeded

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 = 1

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
    X = check(X)


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

Submission status: Time Limit Exceeded

Solution code:
def roop(A, s):
    for v in A:
        if s.__contains__(v):
            del s[s.index(v) :]
        else:
            s.append(v)

    return


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    s = list()
    t = list()

    for i in range(K):
        roop(A, s)
        t.append(s.copy())
        if len(s) == 0:
            if i == 0:
                break
            else:
                s = t[K % i]
                break

    print(*(t for t in s))

    return


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

_X = [0 for _ in range(N)]
for i, l in enumerate(list(map(int, input("").strip().split(" ")))):
  _X[i] = l

X = []

for _ in range(K):
  X += _X

output_X = []
  
for i in X:
  output_X_set = set(output_X)
  if i in output_X_set:
    i_index = output_X.index(i)
    output_X = output_X[:i_index]
  else:
    output_X += [i]
  
out_string = ""
for output_x in output_X:
  out_string += str(output_x) + " "
print(out_string)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
As = list(map(int, input().split()))
S = []
for i in range(N):
  a = As[i]
  try:
    j = As.index(a, i+1)+1
    S.append((j//N, j%N))
  except:
    j = As.index(a)+1
    S.append((1+j//N, j%N))
#print(S)
count = 0
p = 0
while True:
  c, p = S[p]
  count += c
  if p == 0:
    break
#print(count)
K = K%count
#print(K)
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)))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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


def solve(remain_count):
    s = deque()
    for i in range(0, remain_count):
        for j in range(0, N):
            if a[j] in s:
                while s[-1] != a[j] and a[j] in s:
                    s.pop()
                s.pop() # pop last

                # 子数列の最後の時点で結果がカラであれば、その倍数分は省略できる実装
                if len(s) == 0 and (j == N - 1):
                    new_remain_count = K % (i + 1)
                    if new_remain_count < remain_count and ( N * new_remain_count < (N * remain_count - i * j)):
                        solve(new_remain_count)
                        print(' '.join(map(str, s)))
                        exit(0)

            else:
                s.append(a[j])

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

solve(K)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
numlist = list(map(int,input().split()))
s=[]
for i in range(0,k):
    for j in range(0,n):
        if numlist[j] in s:
            while numlist[j] in s:
                del s[-1]
        else:
            s.append(numlist[j])
print (' '.join(map(str,(s))))

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = A[:]
i=0
k_num = 1
roop_point = 0
Ans_list = [[]]

while 1:
    while i < len(ans)-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

    if ans not in Ans_list:
        Ans_list.append(ans)
        if k_num < K:
            ans = ans + A
            i=0
            k_num+=1
        elif k_num == K:
            print(*ans)
            exit()
    else:
        roop_point = Ans_list.index(ans)
        break
#print(Ans_list)
print(*Ans_list[(K-roop_point)%len(Ans_list)])

Submission status: Time Limit Exceeded

Solution code:
import math

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

_X = [0 for _ in range(N)]
for i, l in enumerate(list(map(int, input("").strip().split(" ")))):
  _X[i] = l

X = []

for _ in range(K):
  X += _X

output_X = []
  
for i in X:
  if i in output_X:
    i_index = output_X.index(i)
    output_X = output_X[:i_index]
  else:
    output_X += [i]
  
out_string = ""
for output_x in output_X:
  out_string += str(output_x) + " "
print(out_string)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = A[:]
i=0
k_num = 1
roop_point = 0
Ans_list = [[]]

while 1:
    while i < len(ans)-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

    if ans not in Ans_list:
        Ans_list.append(ans)
        if k_num < K:
            ans = ans + A
            i=0
            k_num+=1
        elif k_num == K:
            print(*ans)
    else:
        roop_point = Ans_list.index(ans)
        break
#print(Ans_list)
print(*Ans_list[(K-roop_point)%len(Ans_list)])

Submission status: Time Limit Exceeded

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

gap = [0] * n
num = {}
for i in range(n):
    num.setdefault(a[i], [])
    num[a[i]].append(i)
for i in num.values():
    for j in range(len(i)):
        gap[i[j]] = (i[(j + 1) % len(i)] - i[j] - 1) % n + 1
count = 0
x = 0
while True:
    if count % n == 0 and count > 0:
        term = count // n
        break
    else:
        count += (gap[x % n] + 1)
        x += (gap[x % n] + 1)
k = (k - 1) % term + 1
count2 = 0
x2 = 0
while count2 < k * n:
    temp = gap[x2 % n]
    count2 += (temp + 1)
    x2 += (temp + 1)
else:
    count2 -= (temp + 1)
    x2 -= (temp + 1)
queue = []
for i in range(x2, x2 + k * n - count2):
    if a[i % n] not in set(queue):
        queue.append(a[i % n])
    else:
        while a[i % n] in set(queue):
            del queue[-1]
for i in queue:
    print(i, end = " ")

Submission status: Time Limit Exceeded

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] * N
dic = {}
for i in range(N):
    a = A[i]
    if dic.get(a, None) is None:
        dic[a] = 1
    else:
        dic[a] += 1

count = 0
for i in range(N):
    a = A[i]
    v = dic.get(a)
    if v % 2 == 1:
        B[count] = a
        count += 1
B = B[0:count]
dic = {}
for i in range(N):
    a = A[i]
    v = dic.get(a, None)
    if v is None:
        dic[a] = [i]
    else:
        v.append(i)

result = []
result_dic = {}
result_dic_index = {}
count = 0
loop = 0
while count < K:
    index = 0
    if count != 0:
        if result:
            a = result[index]
            v = dic.get(a)
            next_i = v[0]
            index = next_i + 1
            result = []
    while index < N:
        a = A[index]
        v = dic.get(a)
        next_i = -1
        for i in v:
            if i > index:
                next_i = i
                break
        if next_i == -1:
            result.append(a)
            index += 1
        else:
            index = next_i + 1
    tu = tuple(result)
    t = result_dic.get(tu, None)
    if t is None:
        result_dic[tu] = count
        result_dic_index[count] = tu
    else:
        loop = count
        break
    count += 1

answers = None
if loop == 0:
    answers = tu
else:
    index = (K - 1) % loop
    answers = result_dic_index[index]

for answer in answers:
    print(answer, end=" ")
print()

Submission status: Time Limit Exceeded

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

B=[[]]
tmp=[]

cycle_begin=0
cycle=0
for i in range(1,K+1):
    for j in range(N):
        if A[j] in tmp:
            tmp=tmp[0:tmp.index(A[j])]
        else:
            tmp.append(A[j])
    if tmp not in B:
        B.append(tmp[:])
    else:
        cycle_begin=B.index(tmp)
        cycle=i-cycle_begin
        tmp=B[cycle_begin+(K-cycle_begin)%cycle]
        break

print(' '.join(map(str,tmp)))

Submission status: Time Limit Exceeded

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

cpA=A[:]

head=[]
tail=[]

while True:
    n=len(A)
    for i in range(n//2):
        head.append(A[i])
        if A[i] in tail and A.count(A[i])%2==0:
            p=A.index(A[i])
            q=A[::-1].index(A[i])
            break
        tail.append(A[n-i-1])
        if A[n-i-1] in head and A.count(A[n-i-1])%2==0:
            p=A.index(A[n-i-1])
            q=A[::-1].index(A[n-i-1])
            break
    else:
        break
    A=A[:p]+A[n-q:]


cnt=0
arc=[]
while True:
    head=[]
    
    while True:
        #print(A)
        head=[]
        for i in A:
            if i in head:
                p=A.index(i)
                q=A[p+1:].index(i)+p+1
                break
            else:
                head.append(i)  
        else:
            break
        A=A[:p]+A[q+1:]
    cnt+=1
    arc.append(A[:])
    #print(A)
    if A == []:
        #print(cnt)
        break
    else:
        A.extend(cpA)
        
        

lenA=len(A)

k=(k-1)%(cnt)

print(" ".join([str(i) for i in arc[k]]))

Submission status: Time Limit Exceeded

Solution code:
import copy

n,k=list(map(int,input().split()))
li=list(map(int,input().split()))
first_list=copy.deepcopy(li)

remain_list=[]
pre_list=[[]]

for j in range(k):
  for i in range(len(li)):
    if li[i] not in remain_list:
      remain_list.append(li[i])
    else:
      remain_list=remain_list[:remain_list.index(li[i])]
  if remain_list not in pre_list:
    pre_list.append(remain_list)
    li=remain_list+first_list
    remain_list=[]
  else:
    pre_list.append(remain_list)
    break

ans_count=0
while(pre_list[-1]!=pre_list[ans_count]):
  ans_count+=1

answer=ans_count
pre_list=pre_list[ans_count:]
ans_count=len(pre_list)-ans_count
k-=answer

L=[str(a) for a in pre_list[k%(ans_count-1)]]
L=" ".join(L)
print(L)

Submission status: Time Limit Exceeded

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
if ans != []:
    out = ''
    for element in ans:
        out += str(element) + ' '
    print(out[0:-1])
    exit()
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: Time Limit Exceeded

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

tmp = []
res = []

while 1:
    #print(tmp+A)
    NEW = tmp + A
    tmp = []
    for a in NEW:
        if a not in tmp:
            tmp.append(a)
        else:
            i = tmp.index(a)
            del tmp[i:]
    #print(tmp,k)
    res.append(tmp)
    if tmp == []:
        break
#print(res)

m = len(res)
MOD = K%m
answer = res[MOD-1]
for x in answer:
    print(x,end=" ")

Submission status: Time Limit Exceeded

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

c = 0
while True:
  c += 1
  for i in a:
    if i in s:
      del s[s.index(i):]
    else:
      s.append(i)
  if len(s) == 0:
    break

rep = k % c
for j in range(rep):
  for i in a:
    if i in s:
      del s[s.index(i):]
    else:
      s.append(i)

print(*s)

Submission status: Time Limit Exceeded

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

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

ptn = [[]]
tmp = []
cnt = 0
while(cnt<K):
    for a in A:
        try:
            tmp = tmp[:tmp.index(a)]
        except ValueError as e:
            tmp.append(a)

    if tmp == []: break
    ptn.append(copy.copy(tmp))
    cnt += 1

s = list(map(str, ptn[K%len(ptn)]))
print(" ".join(s))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

for i in range(0, K):
    for j in range(0, N):
        if a[j] in s:
            while s[-1] != a[j] and a[j] in s:
                s.pop()
            s.pop() # pop last

            # 子数列の最後の時点で結果がカラであれば、その倍数分は省略できる実装
            if len(s) == 0 and (j == N - 1):

                rest_count = K % (i + 1)

                # print("zero i " + str(i))
                # print("zero j " + str(j))
                # print(rest_count)
                # todo 再起使うようにかける
                ss = deque()
                for ii in range(0, rest_count):
                    for jj in range(0, N):
                        if a[jj] in ss:
                            while ss[-1] != a[jj] and a[jj] in ss:
                                ss.pop()
                            ss.pop()  # pop last
                        else:
                           ss.append(a[jj])
                print(' '.join(map(str, ss)))
                exit(0)

        else:
            s.append(a[j])

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

Submission status: Time Limit Exceeded

Solution code:
n,k = [int(i) for i in input().split(' ')]
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 == 0:
        break
s = [str(i) for i in s]
print(' '.join(s))

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
import copy
input = sys.stdin.readline
N,K = map(int,input().split())
A= list(int(i) for i in input().split())
chk = collections.Counter(A)
im_chk = copy.deepcopy(chk)
New_list=[]
ans_list = []
dup = 0
modul=1
comp=0
for i in range(N*K):
	l = i%N
	if A[l] == dup:
		chk[A[l]] -= 1
		dup = 0
	elif dup == 0:
		if chk[A[l]] == 1:
			New_list.append(A[l])
		else:
			chk[A[l]] -=1
			dup = A[l]
	else:
		chk[A[l]] -= 1
	if l == N-1:
		if New_list == []:
			modul = (i+1)//N
			break
		else:
			if i == N*K-1:
				comp = 1
			ans_list.append(New_list)
			dup = New_list[0]
			chk = copy.deepcopy(im_chk)
			New_list = []
if comp == 1:
	print(*ans_list[-1])
else:
	ans = K%modul
	if ans == 0:
		print("")
	else:
		print(*ans_list[ans-1])

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int, input().split())
a = [int(i) for i in input().split()]
b = []
cnt = 0

def has_duplicates(seq):
    return len(seq) != len(set(seq))

if not(has_duplicates(a)):
	cnt = len(a) + 1
	ad = k % cnt
	if ad == 0:
		print([])
	else:
		b = a[ad-1:]
		[print(i) for i in b]
else:
	for i in range(k):
		for j in range(n):
			if a[j] not in b:
				b.append(a[j])
			else:
				ind = b.index(a[j])
				b = b[:ind]
		cnt += 1
		if b == []:
			break

	ad = k % cnt

	for i in range(ad):
		for j in range(n):
			if a[j] not in b:
				b.append(a[j])
			else:
				ind = b.index(a[j])
				b = b[:ind]

	[print(i) for i in b]

Submission status: Time Limit Exceeded

Solution code:
def solve(array):
    ans = []
    memo1 = {}
    for i in range(len(array)):
        if array[i] not in memo1:
            memo1[array[i]] = 1
        else:
            memo1[array[i]] += 1
    i = 0
    while i < len(array):
        if memo1[array[i]] == 1:
            ans.append(array[i])
            i += 1
        else:
            tmp = array[i]
            memo1[array[i]] -= 1
            i += 1
            while True:
                memo1[array[i]] -= 1
                if tmp == array[i]:
                    i += 1
                    break
                else:
                    i += 1
    return ans   

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

start = {}
for i in range(len(a))[::-1]:
    start[a[i]] = i

li = []
tmp = []
while True:
    memo = {}
    if not tmp:
        start_num = 0
    else:
        start_num = start[tmp[-1]] + 1
    tmp = solve(a[start_num:n])
    #print(tmp)
    li.append(tmp)
    if not tmp:
        break

t = 1
for i in range(len(li)):
    t += len(li[i])
#print(li)
#print(t)
ans = k % t
if ans == 0:
    print()
else:
    for i in range(len(li)):
        if ans <= len(li[i]):
            print(" ".join(map(str, li[i][ans-1:])))
            break
        ans -= len(li[i])

Submission status: Time Limit Exceeded

Solution code:

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] * N
dic = {}
for i in range(N):
    a = A[i]
    if dic.get(a, None) is None:
        dic[a] = 1
    else:
        dic[a] += 1

count = 0
for i in range(N):
    a = A[i]
    v = dic.get(a)
    if v % 2 == 1:
        B[count] = a
        count += 1

dic = {}
for i in range(N):
    a = A[i]
    v = dic.get(a, None)
    if v is None:
        dic[a] = [i]
    else:
        v.append(i)

result = []
result_dic = {}
result_dic_index = {}
count = 0
loop = 0
while count < K:
    index = 0
    if count != 0:
        if result:
            a = result[index]
            v = dic.get(a)
            next_i = v[0]
            index = next_i + 1
            result = []
    while index < N:
        a = A[index]
        v = dic.get(a)
        next_i = -1
        for i in v:
            if i > index:
                next_i = i
                break
        if next_i == -1:
            result.append(a)
            index += 1
        else:
            index = next_i + 1
    tu = tuple(result)
    t = result_dic.get(tu, None)
    if t is None:
        result_dic[tu] = count
        result_dic_index[count] = tu
    else:
        loop = count
        break
    count += 1

answers = None
if loop == 0:
    answers = tu
else:
    index = (K - 1) % loop
    answers = result_dic_index[index]

for answer in answers:
    print(answer, end=" ")
print()