Buggy python submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.readline


R, S, P = 1, 2, 3
W, L, D = 1, 2, 3

rps = {
    (R, S, P):{R:D, S:D, P:D},
    (R, S)   :{R:W, S:L},
    (S, P)   :{S:W, P:L},
    (R, P)   :{P:W, R:L}
}

while True:
    hand = int(readline())
    if hand == 0:
        break
    hands = [hand] + [int(readline()) for _ in range(4)]
    hand_set = tuple(sorted(set(hands)))
    for h in hands:
        print(rps[hand_set][h])

Fixed submission:
from sys import stdin
readline = stdin.readline


R, S, P = 1, 2, 3  # rock, scissors, paper
W, L, D = 1, 2, 3  # win, lose, draw

rps = {
    (R, S, P): {R: D, S: D, P: D},
    (R, S):    {R: W, S: L},
    (S, P):    {S: W, P: L},
    (R, P):    {P: W, R: L},
    (R,):       {R: D},
    (S,):       {S: D},
    (P,):       {P: D}
    }

while True:
    hands = []
    hands.append(int(readline()))
    if hands[0] == 0:
        break
    for _ in range(4):
        hands.append(int(readline()))

    hands_set = tuple(sorted(set(hands)))
    for h in hands:
        print(rps[hands_set][h])

Buggy python submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.readline


R, S, P = 1, 2, 3
W, L, D = 1, 2, 3

rps = {
    (R, S, P):{R:D, S:D, P:D},
    (R, S)   :{R:W, S:L},
    (S, P)   :{S:W, P:L},
    (R, P)   :{P:W, R:L}
}

while True:
    hand = int(readline())
    if hand == 0:
        break
    hands = [hand] + [int(readline()) for _ in range(4)]
    hand_set = tuple(sorted(set(hands)))
    for h in hands:
        print(rps[hand_set][h])

Fixed submission:
from sys import stdin
readline = stdin.readline


R, S, P = 1, 2, 3  # rock, scissors, paper
W, L, D = 1, 2, 3  # win, lose, draw

rps = {
    (R, S, P): {R: D, S: D, P: D},
    (R, S):    {R: W, S: L},
    (S, P):    {S: W, P: L},
    (R, P):    {P: W, R: L},
    (R,):       {R: D},
    (S,):       {S: D},
    (P,):       {P: D}
    }

while True:
    hands = []
    hands.append(int(readline()))
    if hands[0] == 0:
        break
    for _ in range(4):
        hands.append(int(readline()))

    hands_set = tuple(sorted(set(hands)))
    for h in hands:
        print(rps[hands_set][h])

Buggy python submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.readline


def main():
    R, S, P = 1, 2, 3
    W, L, D = 1, 2, 3

    rps = {
        (R, S, P):{R:D, S:D, P:D},
        (R, S)   :{R:W, S:L},
        (S, P)   :{S:W, P:L},
        (R, P)   :{P:W, R:L}
    }

    while True:
        hand = int(readline())
        if hand == 0:
            break
        hands = [hand] + [int(readline()) for _ in range(4)]
        hand_set = tuple(sorted(set(hands)))
        for h in hands:
            print(rps[hand_set][h])
main()

Fixed submission:
from sys import stdin
readline = stdin.readline


R, S, P = 1, 2, 3  # rock, scissors, paper
W, L, D = 1, 2, 3  # win, lose, draw

rps = {
    (R, S, P): {R: D, S: D, P: D},
    (R, S):    {R: W, S: L},
    (S, P):    {S: W, P: L},
    (R, P):    {P: W, R: L},
    (R,):       {R: D},
    (S,):       {S: D},
    (P,):       {P: D}
    }

while True:
    hands = []
    hands.append(int(readline()))
    if hands[0] == 0:
        break
    for _ in range(4):
        hands.append(int(readline()))

    hands_set = tuple(sorted(set(hands)))
    for h in hands:
        print(rps[hands_set][h])

Buggy python submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.readline

def main():
    R, S, P = 1, 2, 3
    W, L, D = 1, 2, 3

    rps = {
        (R, S, P):{R:D, S:D, P:D},
        (R, S)   :{R:W, S:L},
        (S, P)   :{S:W, P:L},
        (R, P)   :{P:W, R:L}
    }

    while True:
        try:
            hands = [int(readline()) for _ in range(5)]
        except:
            break
        hand_set = tuple(sorted(set(hands)))
        for h in hands:
            print(rps[hand_set][h])
main()

Fixed submission:
from sys import stdin
readline = stdin.readline


R, S, P = 1, 2, 3  # rock, scissors, paper
W, L, D = 1, 2, 3  # win, lose, draw

rps = {
    (R, S, P): {R: D, S: D, P: D},
    (R, S):    {R: W, S: L},
    (S, P):    {S: W, P: L},
    (R, P):    {P: W, R: L},
    (R,):       {R: D},
    (S,):       {S: D},
    (P,):       {P: D}
    }

while True:
    hands = []
    hands.append(int(readline()))
    if hands[0] == 0:
        break
    for _ in range(4):
        hands.append(int(readline()))

    hands_set = tuple(sorted(set(hands)))
    for h in hands:
        print(rps[hands_set][h])

Buggy python submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.readline

from io import StringIO
readline = StringIO('''1
2
3
2
1
1
2
2
2
1
0''').readline

R, S, P = 1, 2, 3  # rock, scissors, paper
W, L, D = 1, 2, 3  # win, lose, draw


while True:
    hands = []
    hands.append(int(readline()))
    if hands[0] == 0:
        break
    for _ in range(4):
        hands.append(int(readline()))

    hands_set = tuple(sorted(set(hands)))
    for h in hands:
        print(rps[hands_set][h])

Fixed submission:
from sys import stdin
readline = stdin.readline


R, S, P = 1, 2, 3  # rock, scissors, paper
W, L, D = 1, 2, 3  # win, lose, draw

rps = {
    (R, S, P): {R: D, S: D, P: D},
    (R, S):    {R: W, S: L},
    (S, P):    {S: W, P: L},
    (R, P):    {P: W, R: L},
    (R,):       {R: D},
    (S,):       {S: D},
    (P,):       {P: D}
    }

while True:
    hands = []
    hands.append(int(readline()))
    if hands[0] == 0:
        break
    for _ in range(4):
        hands.append(int(readline()))

    hands_set = tuple(sorted(set(hands)))
    for h in hands:
        print(rps[hands_set][h])