Problem:


 カードゲーム 

問題

次のような2人で行うカードゲームがある．

    
 このゲームでは， 1から2nまでの各整数が書かれた全部で2n枚のカードを使用する． ここで，nは1以上100以下の整数である．

    
 このカードを2人にn枚ずつ配る．

    
 次のルールに従って交互にカードを1枚ずつ場に出す．

    

          
 場にカードが出ていないならば， 好きなカードを出すことができる．

          
 場にカードが出ているならば， 最後に場に出たカードよりも大きい数の書かれたカードを出すことができる．

          
 カードが出せる場合は，必ず場にカードを出す必要がある．

          
 出せるカードが無い場合はパスとなり，相手の番になる． このとき，場に出ているカードは無くなる． 

    
 ゲームは場にカードが出ていない状態で始める．

    
 どちらかの手持ちのカードが無くなった時点でゲームは終了する．

    
 ゲーム終了時に相手の持っているカードの枚数を得点とする．

太郎と花子は，このゲームで対戦することになった．ゲームは太郎の番から始める． 2人は共に，出すことのできるカードのうち必ず一番小さい数が書かれたカードを出すことにしている．

太郎に配られるカードが入力されたとき，太郎と花子の得点を出力するプログラムを作成せよ． 

入力

入力は複数のデータセットからなる．各データセットは以下の形式で与えられる．

入力は n+1 行ある． 1行目には整数nが書かれている． 2行目からn+1行目までの各行には整数が1つずつ書かれており，太郎に配られるカードに書かれた整数を表す．

n が 0 のとき入力の終了を示す. データセットの数は 5 を超えない．

出力

データセットごとに 1行目には太郎の得点を， 2行目には花子の得点を出力せよ． 

入出力例

入力例

5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0

出力例

3
0
2
0

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



Sample input:
5
1
7
9
6
10
10
8
7
14
18
4
11
3
17
5
19
0


Sample output:
3
0
2
0

Submission status: Wrong Answer

Solution code:
n = int(input())
taro = [int(input()) for _ in range(n)]
hanako = [x + 1 for x in range(2*n) if (x + 1) not in taro]
taro.sort()
hanako.sort()

def discard(c, cards):
    for card in cards:
        if c < card:
            return card
    return 0

table = 0
while True:
    if taro:
        table = discard(table, taro)
        if table:
            taro.remove(table)
            
    if not taro:
        print(len(hanako))
        print(0)
        break
        
    if hanako:
        table = discard(table, hanako)
        if table:
            hanako.remove(table)
    if not hanako:
        print(0)
        print(len(taro))

Submission status: Wrong Answer

Solution code:
def discard(c, cards):
    for card in cards:
        if c < card:
            return card
    return 0

while True:
    n = int(input())
    if n == 0: 
        break
    taro = [int(input()) for _ in range(n)]
    hanako = [x + 1 for x in range(2*n) if (x + 1) not in taro]
    taro.sort()
    hanako.sort()

    table = 0
    while True:
        if taro:
            table = discard(table, taro)
            if table:
                taro.remove(table)
            
        if not taro:
            print(len(hanako))
            print(0)
            break
        
        if hanako:
            table = discard(table, hanako)
            if table:
                hanako.remove(table)
        if not hanako:
            print(0)
            print(len(taro))

Submission status: Wrong Answer

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

while True:
    n = int(input())
    if n == 0:
        break

    taro = []
    for i in range(n):
        taro.append(int(input()))

    hanako = [i for i in range(1, 2*n + 1) if not i in taro]

    ret = max(max(taro), max(hanako)) - min(max(taro), max(hanako))

    print(ret + 1 if ret > 0 else 0)
    print(0 if ret > 0 else ret + 1)

Submission status: Wrong Answer

Solution code:
card1 = []
t = input()
for i in range(t):
    n = input()
    card1 += [n]
t *= 2
card1 = sorted(card1)
card2 = range(1,t+1)
for x in card1:
    card2.remove(x)
ba = 0
turn = 1
while 1:
    if len(card1)==0 or len(card2)==0: break
    card = card1 if turn else card2
    cnt = 0
    while cnt < len(card):
        if card[cnt] > ba: break
        cnt+=1
    if cnt != len(card):
        ba = card.pop(cnt); turn = 1 - turn;
    else:
        ba = 0; turn = 1 - turn;
print len(card2)
print len(card1)

Submission status: Wrong Answer

Solution code:
while 1:
    n=int(raw_input())
    if n==0:break
    card=range(1,2*n+1)
    taro=[int(raw_input()) for _ in xrange(n)]
    hanako=[]
    for i in xrange(1,2*n+1):
        if not i in taro:
            hanako.append(i)
    taro.sort()
    hanako.sort()
    now=0
    while 1:
        while len(taro)!=0:
            t=taro.pop(0)
            if now<t:
                now=t
                break
        if len(taro)==0:break
        while len(hanako)!=0:
            h=hanako.pop(0)
            if now<h:
                now=h
                break
        if len(hanako)==0:break
    print(len(taro))
    print(len(hanako))

Submission status: Wrong Answer

Solution code:
def afff(l1,l2,r,f=0):
    if not l1:return l1,l2 ,not f
    if not l2:return l1,l2 ,f
    a = min(e for e in l1 if r<e)
    l1.remove(a)
    if all(a>e for e in l2):return afff(l1,l2,0,f)
    return afff(l2,l1,a,not f)

while 1:
    n = int(input())
    tarou = [input()for _ in range(n)]
    hanako = [e for e in range(1,2*n+1)if not e in tarou]
    if not n:break
    a = afff(tarou,hanako,0)
    if a[2]:
        print len(a[1])
        print 0
    else:
        print 0
        print len(a[0])

Submission status: Wrong Answer

Solution code:
import bisect
while True:
    n = int(input())
    if n == 0:
        break
    tc = sorted([int(input()) for _ in range(n)])
    hc = sorted([v for v in range(1, 2*n+1) if v not in tc])
    ba = []
    flag = True
    while tc and hc:
        if len(ba) == 0:
            try:
                if flag:
                    tmp = tc.pop(0)
                    flag = False
                else:
                    tmp = hc.pop(0)
                    flag = True
            except IndexError:
                pass
            ba = [tmp]
            continue

        last_card = ba[-1]
        if flag:
            x = bisect.bisect_left(tc, last_card)
            flag = False
            try:
                tmp = tc.pop(x)
            except IndexError:
                ba = []
                continue
        else:
            x = bisect.bisect_left(hc, last_card)
            flag = True
            try:
                tmp = hc.pop(x)
            except IndexError:
                ba = []
                continue
        ba.append(tmp)
    print(len(tc))
    print(len(hc))

Submission status: Wrong Answer

Solution code:
import bisect
while True:
    n = int(input())
    if n == 0:
        break
    card_set = [sorted(int(input()) for _ in range(n)), []]
    card_set[1] = sorted({i for i in range(1, 2*n+1)}.difference(card_set[0]))
    card = turn = 0
    flag = 1
    ba = []
    while flag:
        if len(ba) == 0:
            card = card_set[turn].pop(0)
            ba.append(card)
            flag = 0 if len(card_set[turn])==0 else 1
            turn = 0 if turn else 1
            continue
        last_card = ba[-1]
        x = bisect.bisect_left(card_set[turn], last_card)
        try:
            card = card_set[turn].pop(x)
            ba.append(card)
        except IndexError:
            ba = []
        flag = 0 if len(card_set[turn])==0 else 1
        turn = 0 if turn else 1
    print(*[len(cet) for cet in card_set], sep='\n')

Submission status: Accepted

Solution code:
def discard(c, cards):
    for card in cards:
        if c < card:
            return card
    return 0

while True:
    n = int(input())
    if n == 0: 
        break
    taro = [int(input()) for _ in range(n)]
    hanako = [x + 1 for x in range(2*n) if (x + 1) not in taro]
    taro.sort()
    hanako.sort()

    table = 0
    while True:
        if taro:
            table = discard(table, taro)
            if table:
                taro.remove(table)
            
        if not taro:
            print(len(hanako))
            print(0)
            break
        
        if hanako:
            table = discard(table, hanako)
            if table:
                hanako.remove(table)
        if not hanako:
            print(0)
            print(len(taro))
            break

Submission status: Accepted

Solution code:
while 1:
    t = input()
    if t ==0: break
    card1 = []
    for i in range(t):
        card1 += [input()]
    t *= 2
    card1 = sorted(card1)
    card2 = range(1,t+1)
    for x in card1:
        card2.remove(x)
    ba = 0
    turn = 1
    while 1:
        if len(card1)==0 or len(card2)==0: break
        card = card1 if turn else card2
        cnt = 0
        while cnt < len(card):
            if card[cnt] > ba: break
            cnt+=1
        if cnt != len(card):
            ba = card.pop(cnt); turn = 1 - turn;
        else:
            ba = 0; turn = 1 - turn;
    print len(card2)
    print len(card1)

Submission status: Accepted

Solution code:
while 1:
    n = input()
    if n == 0: break
    card1 = sorted([input() for i in range(n)])
    card2 = [i for i in range(1,2*n+1) if i not in card1]
    ba = 0
    turn = 1
    while card1 and card2:
        card = card1 if turn else card2
        for i in range(len(card)):
            if card[i] > ba:
                ba = card.pop(i)
                break
        else:
            ba = 0
        turn ^= 1
    print len(card2)
    print len(card1)

Submission status: Accepted

Solution code:
while 1:
    n=int(raw_input())
    if n==0:break
    card=range(1,2*n+1)
    taro=[int(raw_input()) for _ in xrange(n)]
    hanako=[]
    for i in xrange(1,2*n+1):
        if not i in taro:
            hanako.append(i)
    taro.sort()
    hanako.sort()
    now=0
    while 1:
        for i in xrange(len(taro)):
            t=taro[i]
            if now<t:
                now=t
                del taro[i]
                break
        else:
            now=0
        if len(taro)==0:break
        for i in xrange(len(hanako)):
            h=hanako[i]
            if now<h:
                now=h
                del hanako[i]
                break
        else:
            now=0
        if len(hanako)==0:break
    print(len(hanako))
    print(len(taro))

Submission status: Accepted

Solution code:
import bisect

while True:
    n = int(input())
    if not n:
        break
    cards = [None, None]
    cards[0] = sorted(map(int, (input() for _ in range(n))))
    cards[1] = sorted(set(range(1, 2 * n + 1)).difference(cards[0]))

    turn = 0
    field = 0
    while True:
        idx = bisect.bisect(cards[turn], field)
        if idx < len(cards[turn]):
            field = cards[turn].pop(idx)
            if not cards[turn]:
                break
        else:
            field = 0
        turn = (turn + 1) & 1
    print(len(cards[1]))
    print(len(cards[0]))

Submission status: Accepted

Solution code:
def bisect(a, x, lo=0, hi=None):
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x < a[mid]: hi = mid
        else: lo = mid+1
    return lo

while True:
    n = int(input())
    if n==0: break

    dealt = [0]*(2*n)
    thand = []
    hhand = []

    for i in range(n):
        dealt[int(input())-1] = 1
    for i in range(2*n):
        if dealt[i]:
            thand.append(i)
        else:
            hhand.append(i)

    thand.sort()
    hhand.sort()
    tarosturn = 1
    ba = -1

    while True:
        if len(thand) == 0:
            print(len(hhand))
            print(0)
            break
        elif len(hhand) == 0:
            print(0)
            print(len(thand))
            break

        if tarosturn:
            taro = bisect(thand,ba)
            if taro != len(thand):
                ba = thand.pop(taro)
            else:
                ba = -1
            tarosturn = 0
        else:
            hanako = bisect(hhand,ba)
            if hanako != len(hhand):
                ba = hhand.pop(hanako)
            else:
                ba = -1
            tarosturn = 1

Submission status: Accepted

Solution code:
import bisect
while True:
    n = int(input())
    if n == 0:
        break
    tc = sorted([int(input()) for _ in range(n)])
    hc = sorted([v for v in range(1, 2*n+1) if v not in tc])
    ba = []
    flag = True
    while tc and hc:
        if len(ba) == 0:
            try:
                if flag:
                    tmp = tc.pop(0)
                    flag = False
                else:
                    tmp = hc.pop(0)
                    flag = True
            except IndexError:
                pass
            ba = [tmp]
            continue

        last_card = ba[-1]
        if flag:
            x = bisect.bisect_left(tc, last_card)
            flag = False
            try:
                tmp = tc.pop(x)
            except IndexError:
                ba = []
                continue
        else:
            x = bisect.bisect_left(hc, last_card)
            flag = True
            try:
                tmp = hc.pop(x)
            except IndexError:
                ba = []
                continue
        ba.append(tmp)
    print(len(hc))
    print(len(tc))

Submission status: Accepted

Solution code:
import bisect
while True:
    n = int(input())
    if n == 0:
        break
    card_set = [sorted(int(input()) for _ in range(n)), []]
    card_set[1] = sorted({i for i in range(1, 2*n+1)}.difference(card_set[0]))
    card = turn = 0
    flag = 1
    ba = []
    while flag:
        if len(ba) == 0:
            card = card_set[turn].pop(0)
            ba.append(card)
            flag = 0 if len(card_set[turn])==0 else 1
            turn = 0 if turn else 1
            continue
        last_card = ba[-1]
        x = bisect.bisect_left(card_set[turn], last_card)
        try:
            card = card_set[turn].pop(x)
            ba.append(card)
        except IndexError:
            ba = []
        flag = 0 if len(card_set[turn])==0 else 1
        turn = 0 if turn else 1
    print(*[len(cet) for cet in card_set[::-1]], sep='\n')

Submission status: Accepted

Solution code:
while True:
    n=int(input())
    if n==0:break
    card_t=sorted([int(input())for i in range(n)])
    card_h=[]
    for i in range(2*n):
        if i+1 not in card_t:card_h.append(i+1)
    ba=0
    while True:
        for i in range(len(card_t)):
            if card_t[i]>ba:
                ba=card_t.pop(i)
                break
            if i==len(card_t)-1:ba=0
        if len(card_t)==0:break
        for i in range(len(card_h)):
            if card_h[i]>ba:
                ba=card_h.pop(i)
                break
            if i==len(card_h)-1:ba=0
        if len(card_h)==0:break
    print(len(card_h))
    print(len(card_t))

Submission status: Accepted

Solution code:
while True:
  n = int(input())
  if not n: break
  lst = [0 for i in range(n * 2)]
  for i in range(n):
    lst[int(input()) - 1] = 1
  T = [i for i in range(n * 2) if lst[i]]
  H = [i for i in range(n * 2) if not lst[i]]
  f = -1
  t = 0
  while T and H:
    if not t:
      for i in range(len(T)):
        if T[i] >= f:
          f = T.pop(i)
          t = 1
          break
      else:
        t = 1
        f = -1
    elif t:
      for i in range(len(H)):
        if H[i] >= f:
          f = H.pop(i)
          t = 0
          break
      else:
        t = 0
        f = -1
  print(len(H))
  print(len(T))

Submission status: Accepted

Solution code:
import bisect
for e in iter(input,'0'):
    n=int(e)
    c=[sorted(int(input())for _ in[0]*n)]
    c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
    t=f=0
    while 1:
        x=bisect.bisect(c[t],f)
        if not c[t]:break
        f=c[t].pop(x)if x<len(c[t])else 0
        t^=1
    print(len(c[1]))
    print(len(c[0]))

Submission status: Accepted

Solution code:
import bisect
for e in iter(input,'0'):
 n=int(e)
 c=[sorted(int(input())for _ in[0]*n)]
 c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
 t=f=0
 while 1:
  x=bisect.bisect(c[t],f)
  if not c[t]:break
  f=c[t].pop(x)if x<len(c[t])else 0
  t^=1
 print(len(c[1]))
 print(len(c[0]))

Submission status: Accepted

Solution code:
import bisect
for e in iter(input,'0'):
 n=int(e)
 c=[sorted(int(input())for _ in[0]*n)]
 c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
 t=f=0
 while 1:
  x=bisect.bisect(c[t],f)
  if not c[t]:break
  f=c[t].pop(x)if x<len(c[t])else 0
  t^=1
 for i in[1,0]:print(len(c[i]))

Submission status: Accepted

Solution code:
import bisect
for e in iter(input,'0'):
 n=int(e)
 c=[sorted(int(input())for _ in[0]*n)]
 c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
 t=f=0
 while 1:
  x=bisect.bisect(c[t],f)
  if not c[t]:break
  f=c[t].pop(x)if x<len(c[t])else 0
  t^=1
 for i in'10':print(len(c[int(i)]))

Submission status: Accepted

Solution code:
import bisect
for e in iter(input,'0'):
 n=int(e)
 c=[sorted(int(input())for _ in[0]*n)]
 c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
 t=f=0
 while 1:
  l=len(c[t])
  if l<1:break
  x=bisect.bisect(c[t],f)
  f=c[t].pop(x)if x<l else 0
  t^=1
 for i in[1,0]:print(len(c[i]))

Submission status: Accepted

Solution code:
import bisect
for e in iter(input,'0'):
 n=int(e)
 c=[sorted(int(input())for _ in[0]*n)]
 c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
 t=f=0
 while 1:
  if not c[t]:break
  x=bisect.bisect(c[t],f)
  f=c[t].pop(x)if x<len(c[t])else 0
  t^=1
 for i in[1,0]:print(len(c[i]))

Submission status: Accepted

Solution code:
# AOJ 0523: Card GameI
# Python3 2018.6.30 bal4u

while True:
	n = int(input())
	if n == 0: break
	c = [1] * (2*n+1)
	for i in range(1, n+1): c[int(input())] = 0
	m = [n]*2
	t, ba = 0, 0
	while m[0] > 0 and m[1] > 0:
		f = 1
		for i in range(ba+1, 2*n+1):
			if t == c[i]:
				ba = i
				c[i] = 2
				m[t] -= 1
				f = 0
				break
			if i == 2*n: ba = 0
		if f: ba = 0
		t = 1-t
	print(m[1], m[0], sep='\n')

Submission status: Accepted

Solution code:
while 1:
    n = int(raw_input())
    if n == 0:
        break
    ownlist = [1] * (2 * n + 1)
    for i in range(n):
        ownlist[int(raw_input())] = 0
    cntlist = [n] * 2
    pos = 1
    turn = 0
    while cntlist[0] > 0 and cntlist[1] > 0:
        try:
            pos = ownlist.index(turn, pos)
            ownlist[pos] = -1
            cntlist[turn] -= 1
            pos += 1
        except ValueError:
            pos = 1
        turn ^= 1
    print cntlist[1]
    print cntlist[0]

Submission status: Accepted

Solution code:
while True:
    n=input()
    if n==0:break
    Taro=sorted(input() for i in range(n))
    Hana=[i for i in range(1,2*n+1) if i not in Taro]
    state=0
    while Taro!=[] and Hana!=[]:
        for i in range(len(Taro)):
            if Taro[i]>state:
                state=Taro[i]
                del Taro[i]
                break
        else:
            state=0
        if len(Taro)==0:
            break
        for i in range(len(Hana)):
            if Hana[i]>state:
                state=Hana[i]
                del Hana[i]
                break
        else:
            state=0
    print len(Hana)
    print len(Taro)

Submission status: Accepted

Solution code:
import sys

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

while True:
    n = int(fp.readline()[:-1])
    if n == 0:
        break

    taro = []
    hanako = []

    for i in xrange(n):
        taro.append(int(fp.readline()[:-1]))
    for i in xrange(1, 2*n+1):
        if not i in taro:
            hanako.append(i)

    taro.sort()
    hanako.sort()

    card = [taro, hanako]

    field = 0
    turn = 0
    while len(taro) > 0 and len(hanako) > 0:
        flg = True
        for i in xrange(len(card[turn])):
            if card[turn][i] > field:
                field = card[turn].pop(i)
                flg = False
                break
        if flg:
            field = 0
        turn = 1 - turn
    print len(hanako)
    print len(taro)

Submission status: Accepted

Solution code:
while 1:
	n = input()
	if n == 0: break
	taro = sorted([input() for i in range(n)])
	hana = [i for i in range(1,2*n+1) if i not in taro]
	field = 0
	while hana:
		for i in range(len(taro)):
			if taro[i] > field:
				field = taro.pop(i)
				break
		else:
			field = 0
		if len(taro) == 0: break
		for i in range(len(hana)):
			if hana[i] > field:
				field = hana.pop(i)
				break
		else:
			field = 0
	print len(hana)
	print len(taro)

Submission status: Accepted

Solution code:
while True:
	n = int(input())
	if n == 0:
		exit()
	taro = []
	for _ in range(0, n):
		taro.append(int(input()))
	hanako = []
	for i in range(1, 2 * n + 1):
		if i not in taro:
			hanako.append(i)
	taro.sort()
	#print(taro)
	#print(hanako)

	m = 0
	taro_flg = True
	while len(taro) != 0 and len(hanako) != 0:
		if taro_flg:
			for i in range(len(taro)):
				if taro[i] > m:
					m = taro[i]
					taro.remove(taro[i])
					break
				if i == len(taro)-1:
					m = 0
			taro_flg = False
		else:
			for i in range(len(hanako)):
				if hanako[i] > m:
					m = hanako[i]
					hanako.remove(hanako[i])
					break
				if i == len(hanako)-1:
					m = 0
			taro_flg = True

	#print(taro)
	#print(hanako)
	print(len(hanako))
	print(len(taro))

Submission status: Accepted

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

"""
import sys


from bisect import bisect_right

def solve(taro, hanako):
    ba = taro.pop(0)
    player = hanako
    while taro and hanako:
        i = bisect_right(player, ba)
        if i != len(player):
            ba = player.pop(i)
        else:
            player = taro if player == hanako else hanako
            ba = player.pop(0)
        player = taro if player == hanako else hanako

    return len(hanako), len(taro)


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        taro = sorted([int(input()) for _ in range(n)])
        hanako = sorted(set(range(1, 2*n+1)) - set(taro))
        ans = solve(taro, hanako)
        print(*ans, sep='\n')


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

Submission status: Accepted

Solution code:
class C:
    def __init__(self):
        self.value = []
    def append(self, n):
        self.value.append(n)

    def popleft(self):
        if not self.value:
            return -1
        else:
            ret = self.value[0]
            del self.value[0]
            return ret
    def popover(self, n):
        ret = -1
        for i, v in enumerate(self.value):
            if v > n:
                ret = v
                del self.value[i]
                break
        return ret

    def empty(self):
        return self.value == []

    @property
    def length(self):
        return len(self.value)

def main():
    while True:
        n = int(input())
        if n == 0:
            break
        taro_bool = [False] * (2 * n + 1)
        taro = C()
        hanako = C()
        for i in range(n):
            v = int(input())
            taro_bool[v] = True
        for i in range(1, 2 * n + 1):
            if taro_bool[i]:
                taro.append(i)
            else:
                hanako.append(i)
                
        ba = taro.popleft()
        teban = 1 # 0太郎 1花子
        playing = [taro, hanako]
        while not taro.empty() and not hanako.empty():
            if ba == 0:
                ba = playing[teban].popleft()
            else:
                x = playing[teban].popover(ba)
                ba = x if x > 0 else 0
            teban ^= 1
    
        print(hanako.length)
        print(taro.length)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def taro_turn(ba):
    if ba==0:
        return(taro.pop(-1))
    elif ba>0:
        for i in range(len(taro))[::-1]:
            if taro[i]>ba:
                k=taro[i]
                taro.remove(k)
                return(k)
        return(0)
def hana_turn(ba):
    if ba==0:
        return(hana.pop(-1))
    elif ba>0:
        for i in range(len(hana))[::-1]:
            if hana[i]>ba:
                k=hana[i]
                hana.remove(k)
                return(k)
        return(0)
    
while 1:
    n=int(input())
    if n==0:break
    taro=[]
    hana=[]
    tarop=0
    hanap=0
    for i in range(n):
        taro.append(int(input()))
    for i in range(1,2*n+1)[::-1]:
        if not i in taro:
            hana.append(i)
    taro.sort(reverse=True)
    ba=0
    while 1:
        ba=taro_turn(ba)
        if len(taro)==0:
            tarop+=len(hana)
            break
        ba=hana_turn(ba)
        if len(hana)==0:
            hanap+=len(taro)
            break
    print(tarop)
    print(hanap)

Submission status: Accepted

Solution code:
def hand(card, board):
    for i, c in enumerate(card):
        if board < c:
            board = card.pop(i)
            return board
    else:
        return board


while 1:
    n = int(input())
    if n == 0:
        break

    taro = []
    for _ in range(n):
        taro.append(int(input()))
    taro.sort()

    hanako = []
    for i in range(1, 2*n+1):
        if i not in taro:
            hanako.append(i)
    hanako.sort()

    board = 0
    order = 0
    while 1:
        if order == 0:
            card = hand(taro, board)
            if taro == [] or hanako == []:
                break
            if board == card:
                board = 0
                order = 1
                continue
            board = card
            card = hand(hanako, board)
            if taro == [] or hanako == []:
                break
            if board == card:
                board = 0
                continue
            board = card
        else:
            card = hand(hanako, board)
            if taro == [] or hanako == []:
                break
            if board == card:
                board = 0
                order = 0
                continue
            board = card
            card = hand(taro, board)
            if taro == [] or hanako == []:
                break
            if board == card:
                board = 0
                continue
            board = card

    print(len(hanako))
    print(len(taro))

Submission status: Runtime Error

Solution code:
import bisect
for e in iter(input,'0'):
 n=int(e)
 c=[sorted(int(input())for _ in[0]*n)]
 c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
 t=f=0
 while 1:
  if not c[t]:break
  x=bisect.bisect(c[t],f)
  f=c[t].pop(x)if x<=len(c[t])else 0
  t^=1
 for i in[1,0]:print(len(c[i]))