Title: Card Game

Problem:
There is a card game played by two people. In this game, 2n cards with integers from 1 to 2n are used, where n is an integer between 1 and 100, inclusive. The cards are distributed equally between the two players. Players take turns placing a card on the table according to specific rules. The game starts with no cards on the table. The game ends when one player runs out of cards, and the opponent's remaining cards determine their score.

Taro and Hanako are playing this game, starting with Taro's turn. Both players always play the smallest available card. Given the cards Taro receives, create a program to output the scores of Taro and Hanako.

Input:
The input consists of multiple datasets. Each dataset has the following format: The first line contains an integer n. The next n lines each contain an integer representing the cards Taro receives. When n is 0, it indicates the end of input. The number of datasets does not exceed 5.

Output:
For each dataset, output Taro's score on the first line and Hanako's score on the second line.

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

Output Example:
3
0
2
0

# Buggy version:
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))

# Fixed version:
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

# Buggy version:
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))

# Fixed version:
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))

# Buggy version:
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')

# Fixed version:
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')