Problem:


カードの並び替え

問題

1 から 2n の数が書かれた 2n 枚のカードがあり，上から 1, 2, 3, ... , 2n の順に積み重なっている．

このカードを，次の方法を何回か用いて並べ替える．

整数 k でカット

上から k 枚のカードの山 A と 残りのカードの山 B に分けた後， 山 A の上に山 B をのせる．

リフルシャッフル

    上から n 枚の山 A と残りの山 B に分け， 上から A の1枚目， B の1枚目， A の2枚目， B の2枚目， …， A の n枚目， B の n枚目， となるようにして， 1 つの山にする．

入力の指示に従い，カードを並び替えたあとのカードの番号を，上から順番に出力するプログラムを作成せよ．

入力

  1 行目には n （1 ≦ n ≦ 100）が書かれている． すなわちカードの枚数は 2n 枚である．

 2 行目には操作の回数 m （1 ≦ m ≦ 1000）が書かれている．

 3 行目から m + 2 行目までの m 行には， 0 から 2n-1 までのいずれか 1 つの整数 k が書かれており， カードを並べ替える方法を順に指定している．
     

         
   k = 0 の場合は， リフルシャッフルを行う．

    
 1 ≦ k ≦ 2n-1 の場合は， k でカットを行う． 

     

出力

出力は2n 行からなる． 1 行目には並べ替え終了後の一番上のカードの番号， 2 行目には並べ替え終了後の上から 2 番目のカードの番号というように， i 行目には上から i 番目のカードの番号を出力せよ．

入出力例

入力例 1

2
2
1
0

出力例 1

2
4
3
1

入力例 2

3
4
2
4
0
0

出力例 2

1
5
4
3
2
6

上記問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
2
2
1
0


Sample output:
2
4
3
1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
card = []
def k_cut(k, a):
    a = a[k:] + a[:k]
    return a

def riffle(n, a):
    c = []
    a_card = a[:n]
    b_card = a[n:]
    for i in range(n):
        c += (a_card[i]+b_card[i])
    return c\

n = int(input())
m = int(input())
card = [str(i+1) for i in range(2*n)]
for i in range(m):
    k = int(input())
    if k == 0:
        card = riffle(n, card)
    else:
        card = k_cut(k, card)
for i in range(len(card)):
    print(card[i], end='')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
card = []
def k_cut(k, a):
    a = a[k:] + a[:k]
    return a

def riffle(n, a):
    c = []
    a_card = a[:n]
    b_card = a[n:]
    for i in range(n):
        c += (a_card[i]+b_card[i])
    return c\

n = int(input())
m = int(input())
card = [str(i+1) for i in range(2*n)]
for i in range(m):
    k = int(input())
    if k == 0:
        card = riffle(n, card)
    else:
        card = k_cut(k, card)
for i in range(len(card)):
    print(card[i])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
card = []
def k_cut(k, a):
    a = a[k:] + a[:k]
    return a

def riffle(n, a):
    c = []
    a_card = a[:n]
    b_card = a[n:]
    for i in range(n):
        c += (a_card[i]+b_card[i])
    return c
    
n = int(input())
m = int(input())
card = [str(i+1) for i in range(2*n)]
for i in range(m):
    k = int(input())
    if k == 0:
        card = riffle(n, card)
    else:
        card = k_cut(k, card)
for i in range(len(card)):
    print(card[i])
print()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
card = []
def k_cut(k, a):
    a = a[k:] + a[:k]
    return a

def riffle(n, a):
    c = []
    a_card = a[:n]
    b_card = a[n:]
    for i in range(n):
        c += (a_card[i]+b_card[i])
    return c
    
n = int(input())
m = int(input())
card = [str(i+1) for i in range(2*n)]
for i in range(m):
    k = int(input())
    if k == 0:
        card = riffle(n, card)
    else:
        card = k_cut(k, card)
for i in range(len(card)):
    print(card[i])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
AC
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline


def flatten(listOfLists):
    "Flatten one level of nesting"
    return chain.from_iterable(listOfLists)


def main(args):
    n = int(input())
    m = int(input())

    cards = [x for x in range(1, (2*n)+1)]
    for _ in range(m):
        op = input().strip('\n')
        if op == '0':
            # shuffle()
            temp = [[y, b] for y, b in zip(cards[:n], cards[n:])]
            cards = list(flatten(temp))
        else:
            # cut(k)
            k = int(op)
            cards = cards[:k] + cards[k:]

    print('\n'.join(map(str, cards)))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(range(1,1+2*n))
for _ in[0]*int(input()):
    k=int(input())
    if k:c=c[k:]+c[:k]
    else:
        for a,b in zip(c[:n],c[n:]):
            c+=[a,b]
        c=c[2*n:]
print(c,sep='')

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(range(1,1+2*n))
for _ in[0]*int(input()):
    k=int(input())
    if k:c=c[k:]+c[:k]
    else:
        for a,b in zip(c[:n],c[n:]):
            c+=[a,b]
        c=c[2*n:]
print(*c,sep='')

Submission status: Wrong Answer

Solution code:
import sys
from itertools import chain
n=int(input())
c=list(range(1,1+2*n))
input()
for e in sys.stdin:
    k=int(e)
    c=c[k:]+c[:k]if k else list(chain.from_iterable(x for x in zip(c[:n],c[n:])))
for x in c:print(x)

Submission status: Wrong Answer

Solution code:
import sys
from itertools import chain
n=int(input())
c=list(range(2*n))
input()
for e in sys.stdin:
    k=int(e)
    c=c[k:]+c[:k]if k else list(chain.from_iterable(zip(c[:n],c[n:])))
for x in c:print(x+1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def k_cut(k, nums):
    return nums[k:] + nums[:k]

def riffle_shuffle(n, nums):
    return [nums[i//2 + n*(i%2)] for i in range(2*n)]

n = int(input())
nums = [i + 1 for i in range(2*n)]

m = int(input())
for i in range(m):
    k = int(input())
    if k == 0:
        nums = riffle_shuffle(n, nums)
    else:
        nums = k_cut(k, nums)

print('\n'.join([str(num) for num in nums]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def k_cut(k, nums):
    return nums[k:] + nums[:k]

def riffle_shuffle(n, nums):
    return [nums[i//2 + n*(i%2)] for i in range(2*n)]

n = int(input())
nums = [i + 1 for i in range(2*n)]

m = int(input())
for i in range(m):
    k = int(input())
    if k == 0:
        nums = riffle_shuffle(n, nums)
    else:
        nums = k_cut(k, nums)

for num in nums:
    print(num)

Submission status: Accepted

Solution code:
n = input()
card = range(1, 2*n+1)
for i in xrange(input()):
    k = input()
    if k==0:
        card = [card[i/2 + (i%2)*n] for i in xrange(2*n)]
    else:
        card = card[k:] + card[:k]
for i in xrange(2*n):
    print card[i]

Submission status: Accepted

Solution code:
n = input()
m = input()
l = [i for i in range(1,2*n+1)]
for i in xrange(m):
    k = input()
    nl = [None]*2*n
    if k==0:
        for j in xrange(n): nl[2*j] = l[j]
        for j in xrange(n,2*n): nl[2*(j-n)+1] = l[j]
    else:
        for j in xrange(k): nl[j+2*n-k] = l[j]
        for j in xrange(k,2*n): nl[j-k] = l[j]
    l = nl
for i in xrange(2*n):
    print l[i]

Submission status: Accepted

Solution code:
from itertools import chain

n, m = int(input()), int(input())
cards = list(range(1, 2 * n + 1))
for _ in range(m):
    k = int(input())
    if k:
        cards = cards[k:] + cards[:k]
    else:
        cards = list(chain.from_iterable(zip(cards[:n], cards[n:])))
for c in cards:
    print(c)

Submission status: Accepted

Solution code:
riffle = lambda half, x: [j for i in zip(x[:half], x[half:]) for j in i]
cut = lambda index, x: x[index:] + x[:index]

cards = [str(x) for x in range(1, int(input())*2 + 1)]
half = int(len(cards) / 2)
for _ in range(int(input())):
  order = int(input())
  if order == 0:
    cards = riffle(half, cards)
  else:
    cards = cut(order, cards)
print("\n".join(cards))

Submission status: Accepted

Solution code:
def shuffle(l,k,n):
    if k:return l[k:] + l[:k]
    else:return [l[i+n*f]for i in range(n)for f in [0,1]]

n = int(input())
l = [i+1 for i in range(2*n)]
for _ in range(int(input())):
    l = shuffle(l,int(input()),n)
[print(e)for e in l]

Submission status: Accepted

Solution code:
n=int(input())
s=[i for i in range(1,2*n+1)]
for _ in range(int(input())):
    a=int(input())
    if a:
        s=s[a:]+s[:a]
    else: 
        s=[s[i+n*j]for i in range(n) for j in[0,1]]
print(*s,sep='\n')

Submission status: Accepted

Solution code:
n = int(input())
card = [v for v in range(1, 2*n+1)]
m = int(input())
for _ in range(m):
    k = int(input())
    if k:
        A, B = card[:k], card[k:]
        card = B + A
    else:
        A, B = card[:n], card[n:]
        card = []
        for a, b in zip(A, B):
            card += [a] + [b]
print('\n'.join(map(str, card)))

Submission status: Accepted

Solution code:
# coding: utf-8
card = []
def k_cut(k, a):
    a = a[k:] + a[:k]
    return a

def riffle(n, a):
    c = []
    a_card = a[:n]
    b_card = a[n:]
    for i in range(n):
        c.append(a_card[i])
        c.append(b_card[i])
    return c
    
n = int(input())
m = int(input())
card = [str(i+1) for i in range(2*n)]
for i in range(m):
    k = int(input())
    if k == 0:
        card = riffle(n, card)
    else:
        card = k_cut(k, card)
for i in range(len(card)):
    print(card[i])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513

"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline


def flatten(listOfLists):
    "Flatten one level of nesting"
    return chain.from_iterable(listOfLists)


def cut(k):
    global cards
    yellow = cards[:k]
    blue = cards[k:]
    cards = blue + yellow


def shuffle():
    global cards
    yellow = cards[:N]
    blue = cards[N:]
    temp = [[y, b] for y, b in zip(yellow, blue)]
    cards = list(flatten(temp))


cards = []
N = 0
def main(args):
    global N
    global cards
    n = int(input())
    N = n
    m = int(input())

    cards = [x for x in range(1, (2*n)+1)]
    for _ in range(m):
        op = int(input())
        if op == 0:
            shuffle()
        else:
            cut(op)

    print('\n'.join(map(str, cards)))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
AC
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline


def flatten(listOfLists):
    "Flatten one level of nesting"
    return chain.from_iterable(listOfLists)


def cut(k):
    # ????????¨l
    global cards
    yellow = cards[:k]
    blue = cards[k:]
    cards = blue + yellow


def shuffle():
    # ????????¨l
    global cards
    yellow = cards[:N]
    blue = cards[N:]
    temp = [[y, b] for y, b in zip(yellow, blue)]
    cards = list(flatten(temp))


cards = []
def main(args):
    global cards
    n = int(input())
    N = n
    m = int(input())

    cards = [x for x in range(1, (2*n)+1)]
    for _ in range(m):
        op = int(input())
        if op == 0:
            # shuffle()
            temp = [[y, b] for y, b in zip(cards[:n], cards[n:])]
            cards = list(flatten(temp))
        else:
            # cut(k)
            cards = cards[op:] + cards[:op]

    print('\n'.join(map(str, cards)))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
AC
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline


def flatten(listOfLists):
    "Flatten one level of nesting"
    return chain.from_iterable(listOfLists)


def main(args):
    global cards
    n = int(input())
    m = int(input())

    cards = [x for x in range(1, (2*n)+1)]
    for _ in range(m):
        op = int(input())
        if op == 0:
            # shuffle()
            temp = [[y, b] for y, b in zip(cards[:n], cards[n:])]
            cards = list(flatten(temp))
        else:
            # cut(k)
            cards = cards[op:] + cards[:op]

    print('\n'.join(map(str, cards)))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0513
AC
"""
import sys
from sys import stdin
from itertools import chain
input = stdin.readline


def flatten(listOfLists):
    "Flatten one level of nesting"
    return chain.from_iterable(listOfLists)


cards = []
def main(args):
    global cards
    n = int(input())
    m = int(input())

    cards = [x for x in range(1, (2*n)+1)]
    for _ in range(m):
        op = int(input())
        if op == 0:
            # shuffle()
            temp = [[y, b] for y, b in zip(cards[:n], cards[n:])]
            cards = list(flatten(temp))
        else:
            # cut(k)
            cards = cards[op:] + cards[:op]

    print('\n'.join(map(str, cards)))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
K = []
n = int(input())
num = 2*n
card = [i for i in range(1,num+1)]
m = int(input())
for i in range(m):
    K.append(int(input()))

for k in K:
    new_card = []
    if k == 0:
        A = card[:n]
        B = card[n:num]
        for i in range(n):
            new_card.append(A[i])
            new_card.append(B[i])
    else:
        A = card[:k]
        B = card[k:num+1]
        new_card = B+A
    card = new_card
for i in card:
    print(i)

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(raw_input())
cards = []
for i in range(1, 2*n+1):
	cards.append(i)

m = int(raw_input())
for ope in range(m):
	new_cards = []
	k = int(raw_input())
	if k == 0:
		for i in range(n):
			new_cards.append(cards[i])
			new_cards.append(cards[n+i])
	else:
		for i in range(k,2*n):
			new_cards.append(cards[i])
		for i in range(k):
			new_cards.append(cards[i])
	cards = new_cards

for card in cards:
	print(card)

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())
lst = [i + 1 for i in range(2 * n)]
for _ in range(m):
  k = int(input())
  if k == 0:
    lst1 = lst[0:n]
    lst2 = lst[n:2 * n]
    lst = [lst2[i//2] if i % 2 else lst1[i//2] for i in range(n * 2)]
  else:
    lst1 = lst[0:k]
    lst2 = lst[k:2 * n]
    lst = lst2 + lst1
for i in lst:
  print(i)

Submission status: Accepted

Solution code:
n=int(input())
c=list(range(1,1+2*n))
for _ in[0]*int(input()):
    k=int(input())
    if k:c=c[k:]+c[:k]
    else:
        for a,b in zip(c[:n],c[n:]):
            c+=[a,b]
        c=c[2*n:]
print(*c,sep='\n')

Submission status: Accepted

Solution code:
n=int(input())
c=list(range(1,1+2*n))
for _ in[0]*int(input()):
    k=int(input())
    if k:c=c[k:]+c[:k]
    else:
        for a,b in zip(c[:n],c[n:]):
            c+=[a,b]
        c=c[2*n:]
for x in c:print(x)

Submission status: Accepted

Solution code:
from itertools import chain
n=int(input())
c=list(range(1,1+2*n))
for _ in[0]*int(input()):
    k=int(input())
    c=c[k:]+c[:k]if k else list(chain.from_iterable(x for x in zip(c[:n],c[n:])))
for x in c:print(x)

Submission status: Accepted

Solution code:
from itertools import chain
n=int(input())
c=list(range(2*n))
for _ in[0]*int(input()):
    k=int(input())
    c=c[k:]+c[:k]if k else list(chain.from_iterable(zip(c[:n],c[n:])))
for x in c:print(x+1)

Submission status: Accepted

Solution code:
from itertools import chain
n=int(input())
c=list(range(2*n))
for _ in[0]*int(input()):
 k=int(input())
 c=c[k:]+c[:k]if k else list(chain.from_iterable(zip(c[:n],c[n:])))
for x in c:print(x+1)

Submission status: Accepted

Solution code:
# AOJ 513: Shuffle The Cards
# Python3 2018.6.30 bal4u

n = int(input())*2
c = [ i for i in range(1,n+1)]
m = int(input())
for _ in range(m):
	k = int(input())
	if k == 0:
		a = c[:n//2]
		b = c[n//2:]
		c = []
		for i in range(n//2): c += [a[i], b[i]]
	else: c = c[k:] + c[:k]
print(*c, sep='\n')

Submission status: Accepted

Solution code:
#!/usr/bin/python

def readints(line):
    return map(int, line.split())

def cut(xs, k):
    return xs[k:] + xs[:k] 

def reffle(xs):
    ys = xs[:]
    k = len(ys)/2
    for i in range(k):
        xs[i*2] = ys[i]
        xs[i*2+1] = ys[i+k]
    return xs


def shuffler(f):
    n, = readints(f.readline())
    xs = list(range(1, 2*n+1))
    m, = readints(f.readline())
    for i in range(m):
        k, = readints(f.readline())
        if k == 0:
            xs = reffle(xs)
        else:
            xs = cut(xs, k)
    for x in xs:
        print x


import sys
shuffler(sys.stdin)

Submission status: Accepted

Solution code:
n = int(raw_input())
cs = [i + 1 for i in range(n * 2)]
for i in range(int(raw_input())):
    k = int(raw_input())
    if k == 0:
        cs = reduce(lambda x, y: x + list(y), zip(cs[:n], cs[n:]), [])
    else:
        cs = cs[k:] + cs[:k]
print '\n'.join(map(str, cs))

Submission status: Accepted

Solution code:
n=input()
m=input()
L=range(1,2*n+1)
for i in range(m):
    k=input()
    if k==0:
        T1,T2=L[:n],L[n:]
        for j in range(n):
            L[2*j]=T1[j]
            L[2*j+1]=T2[j]
    else:
        L=L[k:]+L[:k]
for i in range(2*n):
    print L[i]

Submission status: Accepted

Solution code:
n=input()
m=input()
ks=[input() for i in range(m)]
card=[v for v in range(1,n*2+1)]
for k in ks:
    if k==0:
        tmp=[]
        c1,c2=card[:n],card[n:]
        for i in range(n):
            tmp+=[c1[i],c2[i]]
        card=tmp
    else:
        card=card[k:]+card[:k]

for v in card:
    print v

Submission status: Accepted

Solution code:
import sys

def riffle(list):
    n = len(list) / 2
    tmp = [list[:n], list[n:]]
    ret = []
    for i in xrange(2*n):
        ret.append(tmp[i%2][i/2])
    return ret

def cut(list, op):
    return list[op:] + list[:op]

# fp = open("input.txt", "r")
fp = sys.stdin

n = int(fp.readline())
list = range(1, 2*n+1)

m = int(fp.readline())

for i in xrange(m):
    op = int(fp.readline())
    if op == 0:
        list = riffle(list)
    else:
        list = cut(list, op)

for i in xrange(2*n):
    print list[i]

Submission status: Accepted

Solution code:
n = int(raw_input())
m = int(raw_input())
cards = range(n * 2)
for i in range(m):
    k = int(raw_input())
    if k == 0:
        cards = [c for (a,b) in zip(cards[:n],cards[n:]) for c in (a,b)]
    else:
        cards = cards[k:] + cards[:k]

for c in cards:
    print c + 1

Submission status: Accepted

Solution code:
n = input()
m = input()

card = [x + 1 for x in xrange(2 * n)]

for i in xrange(m):
    k = input()
    if k == 0:
        b = card[n:2*n]
        card = card[:n] 

        for j in xrange(n):
            card.insert(2 * (j + 1) - 1, b[j])

    else:
        a = card[:k] 
        b = card[k:2*n]

        card = b + a
        
for i in card:
    print i

Submission status: Accepted

Solution code:
n = int(raw_input())
deck = [i for i in range(1,2*n+1)]
m = int(raw_input())
for i in range(m):
    k = int(raw_input())
    if k == 0:
        for j in range(n):
            deck += [deck[j]]+[deck[n+j]]
        deck = deck[2*n:]
    else:
        deck = deck[k:]+deck[:k]
for i in deck:
    print i

Submission status: Accepted

Solution code:
n = int(raw_input())
d = [i for i in range(1,2*n+1)]
m = int(raw_input())
for i in range(m):
    k = int(raw_input())
    if k == 0:
        for j in range(n):
            d += [d[j]]+[d[n+j]]
        d = d[2*n:]
    else:
        d = d[k:]+d[:k]
for i in d:
    print i

Submission status: Accepted

Solution code:
def shuffleK(k, arr):
	arr[2*N-k:2*N], arr[0:2*N-k] = arr[0:k], arr[k:2*N]
	return arr


def shuffleR(arr):
	arr_after = arr[:]
	for i in range(2*N):
		if i%2==0:
			arr_after[i] = arr[i//2]
		else:
			arr_after[i] = arr[i//2+N]
	return arr_after


N = int(input())  #枚数
A = [x for x in range(1, 2*N+1)]
M = int(input())  #回数
for _ in range(M):
	m = int(input())
	if m==0:
		A = shuffleR(A)
	else:
		A = shuffleK(m, A)

for a in A:
	print(a)

Submission status: Accepted

Solution code:
def reful(C) :
    new = []
    for i in range(len(C)//2) :
        new.append(C[i])
        new.append(C[i+len(C)//2])
    return new
    
def cut(C, k) :
    new=[]
    for i in range(k, len(C)) :
        new.append(C[i])
    for i in range(k) :
        new.append(C[i])
    return new

n = int(input())
card = []
for i in range(2*n) :
    card.append(i+1)
m = int(input())
for i in range(m) :
    k = int(input())
    if k == 0 :
        card = reful(card)
    else :
        card = cut(card, k)
for i in range(2*n) :
    print(card[i])

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())
a = []
for i in range(n*2):
    a.append(i+1)
for i in range(m):
    k = int(input())
    if k == 0:
        b = []
        for j in range(n):
            b.append(a[j])
            b.append(a[j+n])
        a = b.copy()
    else:
        a = (a[k:] + a[:k]).copy()
for i in range(n*2):
    print(a[i])

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())
cards = [ i for i in range(1,2*n+1) ]

def riffle(c):
    length = len(c)//2
    c1 = c[:length]
    c2 = c[length:]
    c3 = []
    for i in range(length):
        c3.append(c1[i])
        c3.append(c2[i])
    return c3

for i in range(m):
    s = int(input())
    if s == 0:
        cards = riffle(cards)
    else:
        cards = cards[s:] + cards[:s]

print(*cards, sep='\n')

Submission status: Accepted

Solution code:
n=int(input())
cards=[i+1 for i in range(2*n)]
m=int(input())
for i in range(m):
    k=int(input())
    if k==0:
        A=cards[0:n]
        B=cards[n:2*n]
        cards=[B[j//2] if j%2 else A[j//2] for j in range(n*2)]
    else:
        A=cards[0:k]
        B=cards[k:2*n] 
        cards=B+A

for i in cards:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())

card = [int(v) + 1 for v in range(2 * n)]
for i in range(m):
    k = int(input())
    if k == 0:
        next = [0] * 2 * n
        for x in range(n):
            next[x * 2] = card[x]
            next[x * 2 + 1] = card[x + n]
        card = next
    else:
        card = card[k:] + card[0: k]

for no in card:
    print(no)

Submission status: Accepted

Solution code:
def cut(list1,k):
    return list1[k:]+list1[:k]
def riffle(list1):
    tmplist=[]
    n=int(len(list1)/2)
    for k in range(n):
        tmplist+=[list1[k],list1[n+k]]
    return tmplist
N=int(input())
list2=list(range(1,2*N+1))
M=int(input())
for _ in range(M):
    j=int(input())
    if j==0:
        list2=riffle(list2)
    else:
        list2=cut(list2,j)
for k in list2:
    print(k)

Submission status: Accepted

Solution code:
n=int(input())
deck=list(range(1,2*n+1))
m=int(input())
for mm in range(m):
    method=int(input())
    if method==0:
        d1=deck[0:n]
        d2=deck[n:2*n]
        deck=[]
        for j in range(n):
            deck.append(d1[j])
            deck.append(d2[j])
    elif method>0:
        d1=deck[0:method]
        d2=deck[method:2*n]
        deck=[]
        deck.extend(d2)
        deck.extend(d1)
for c in deck:
    print(c)

Submission status: Accepted

Solution code:
n = int(input())
m = int(input())
card = list(range(1, 2*n+1))

for _ in range(m):
    ope = int(input())
    if ope == 0:
        card1 = card[:n]
        card2 = card[n:]
        card = []
        for c1, c2 in zip(card1, card2):
            card.append(c1)
            card.append(c2)
    else:
        card1 = card[:ope]
        card2 = card[ope:]
        card = []
        card.extend(card2)
        card.extend(card1)

for c in card:
    print(c)

Submission status: Accepted

Solution code:
from itertools import chain

def cut(lst, k):
    return lst[k:] + lst[:k]

def riffle(lst):
    n = len(lst)//2
    return list(chain.from_iterable(zip(lst[:n], lst[n:])))

n = int(input().strip())
m = int(input().strip())
cards = list(range(1, 2*n+1))
klist = [int(input().strip()) for _ in range(m)]

for k in klist:
    if k == 0:
        cards = riffle(cards)
    else:
        cards = cut(cards, k)

for card in cards:
    print(card)

Submission status: Runtime Error

Solution code:
import copy
n=int(input())
m=int(input())
card=[i for i in range(2n+1)]
sub=[]

for i in range(m):
	move=int(input())
	if move!=0:
		sub+=card[k:]
		sub+=card[:k]
	else:
		for i in range(n+1):
			sub+=card[i]
			sub+=card[n+i]
	card=copy.deepcopy(sub)
for i in range(2n+1):
	print(card[i])

Submission status: Runtime Error

Solution code:
import copy
n=int(input())
m=int(input())
card=[i for i in range(1,2n+1)]
sub=[]

for i in range(m):
	move=int(input())
	if move!=0:
		sub+=card[k:]
		sub+=card[:k]
	else:
		for j in range(n):
			sub+=card[j]
			sub+=card[n+j]
	card=copy.deepcopy(sub)
for i in range(2n):
	print(card[i])

Submission status: Runtime Error

Solution code:
import copy
n=int(input())
m=int(input())
card=[i for i in range(1,2n+1)]
sub=[]

for i in range(m):
	move=int(input())
	if move!=0:
		sub.append(card[k:])
		sub.append(card[:k])
	else:
		for j in range(n):
			sub.append(card[j])
			sub.append(card[n+j])
	card=copy.deepcopy(sub)
	sub=[]
for i in range(2n):
	print(card[i])

Submission status: Runtime Error

Solution code:
n = int(raw_input())
deck = [i for i in range(1,2*n+1)]
m = int(raw_input())
for i in range(m):
    k = int(raw_input())
    if k == 0:
        deck1 = []
        for j in range(n):
            deck1 += deck[i]+deck[n+i]
        deck = deck1
    elif:
       deck = deck[k+1:]+deck[:k+1]
for i in deck:
    print deck