Problem:


じゃんけん

 仲良し 5 人組でじゃんけんをすることになりました。じゃんけんとは、グー、チョキ、パーという 3つの手があり、グーとチョキの勝負ならグーが「勝ち」・チョキが「負け」、チョキとパーなら、チョキが「勝ち」・パーが「負け」、パーとグーならパーが「勝ち」・グーが「負け」というルールです。全員が同じ手、またはグー、チョキ、パー全てが出た場合は「あいこ」となります。

 5 人のじゃんけんの手を入力とし、それぞれの人の勝敗を出力するプログラムを作成してください。じゃんけんの手は、グーは 1、チョキは 2、パーは 3 の数字で表します。勝敗は「勝ち」を 1、「負け」を 2、「あいこ」を 3 の数字で表し、入力順に従って出力します。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。

h1
h2
h3
h4
h5

i 行目に i  人目の手 hi (1, 2 または 3) が与えられます。

データセットの数は 200 を超えません。

Output

入力データセットごとに、5 人の勝敗を出力します。i 行目に i 人目の勝敗(1, 2 または 3) を出力してください。

Sample Input

1
2
3
2
1
1
2
2
2
1
0

Output for the Sample Input

3
3
3
3
3
1
2
2
2
1



Sample input:
1
2
3
2
1
1
2
2
2
1
0


Sample output:
3
3
3
3
3
1
2
2
2
1

Submission status: Wrong Answer

Solution code:
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:
            pass
            #print(rps[hand_set][h])
main()

Submission status: Wrong Answer

Solution code:
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:
            if h < 1 or 3 < h:
                raise ValueError
            #print(rps[hand_set][h])
main()

Submission status: Wrong Answer

Solution code:
""" Created by Jieyi on 8/22/16. """


def check_aiko(arr):
    rps = [1, 2, 3]
    for t in rps:
        if t not in arr:
            return False

    return True


def check_v(arr):
    rps = {}
    o = []
    for t in arr:
        if t not in rps:
            rps[t] = 0
    if 1 in rps.keys() and 2 in rps.keys():
        rps[1], rps[2] = 1, 2
    elif 2 in rps.keys() and 3 in rps.keys():
        rps[2], rps[3] = 1, 2
    elif 1 in rps.keys() and 3 in rps.keys():
        rps[3], rps[1] = 1, 2

    for n in arr:
        o.append(rps.get(n))
    return o


def algorithm():
    g = []
    out = []

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

        g.append(inp)
        if len(g) == 5:
            if check_aiko(g):
                out = [3] * 5
            else:
                out = check_v(g)

            for o in out:
                print(o)
            g.clear()
            out.clear()


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
hs = []
while True:
    h= int(input())
    if h== 0: break
    hs = hs+[h]
    if len(hs)==5:
        for i in range(5):
            if 1 in hs and 2 in hs and 3 in hs:
                print("3")
            elif hs[i]==1:
                print("2" if 3 in hs else "1")
            elif hs[i]==2:
                print("2" if 1 in hs else "1")
            else:
                print("2" if 2 in hs else "1")
        hs= []

Submission status: Wrong Answer

Solution code:
while True:
    h1= int(input())
    if h1== 0: break
    h2, h3, h4, h5= [int(input()) for _ in range(4)]
    sh= set([h1, h2, h3, h4, h5])
    if len(sh)== 3:
        print("\n".join(["3","3","3","3","3"]))
    else:
        for h in [h1, h2, h3, h4, h5]:
            if h== 1:
                print(1 if 2 in sh else 2)
            elif h== 2:
                print(1 if 3 in sh else 2)
            else:
                print(1 if 1 in sh else 2)

Submission status: Wrong Answer

Solution code:
while True:
    h1= int(input())
    if h1== 0: break
    h2, h3, h4, h5= [int(input()) for _ in range(4)]
    sh= set([h1, h2, h3, h4, h5])
    if len(sh)== 3:
        print("\n".join(["3","3","3","3","3"]))
    else:
        for h in [h1, h2, h3, h4, h5]:
            if h== 1:
                print('1' if 2 in sh else '2')
            elif h== 2:
                print('1' if 3 in sh else '2')
            else:
                print('1' if 1 in sh else '2')

Submission status: Wrong Answer

Solution code:
while True:
    h1= int(input())
    if h1== 0:
        break
    h2,h3,h4,h5= [int(input()) for _ in range(4)]
    l= [h1,h2,h3,h4,h5]
    if 1 and 2 and 3 in l:
        for _ in range(5): print("3")
    else:
        for i in range(5):
            if l[i]==1:
                print('1' if 2 in l else '2')
            elif l[i]==2:
                print('1' if 3 in l else '2')
            else:
                print('1' if 1 in l else '2')

Submission status: Wrong Answer

Solution code:
while 1:
    a=int(input())
    if a==0:break
    a=[a]+[int(input()) for _ in range(4)]
    r=a.count(1);s=a.count(2);p=5-r-s
    if not r or not s or not p and [r,s,p].count(0)!=2:
        if r and s:w=1
        elif r and p:w=3
        else:w=2
        [print([2,1][w==x])for x in a]
    else:print('3\n'*5,end='')

Submission status: Wrong Answer

Solution code:
while True:
    h = int(input())
    if h == 0:break
    h = [h] + [int(input()) for _ in range(4)]
    if 1 and 2 and 3 in h:
        print("\n".join(['3','3','3','3','3']))
    else:
        for i in range(len(h)):
            if h[i]==1:
                print('1' if 2 in h else '2')
            elif h[i]==2:
                print('1' if 3 in h else '2')
            else:
                print('1' if 1 in h else '2')

Submission status: Wrong Answer

Solution code:
d = {'1': '3', '2': '1', '3': '1'}
while True:
    h = input()
    if h == '0':
        break
    h = [h] + [input() for _ in range(4)]
    if set(h) == {'1', '2', '3'}:
        print('\n'.join(['3']*5))
    else:
        for v in h:
            print('2' if d[v] in h else '1')

Submission status: Wrong Answer

Solution code:
while True:
    h = int(input())
    if h == 0:
        break
    h = [h] + [int(input()) for _ in range(4)]
    if len(set(h)) == 3:
        print(*["3"]*5, sep='\n')
        continue
    for c in h:
        if c == 1:
            print("1" if 2 in h else "2")
        elif c == 2:
            print("1" if 3 in h else "2")
        else:
            print("1" if 1 in h else "2")

Submission status: Wrong Answer

Solution code:
while True:
    h = int(input())
    if h == 0:
        break
    dataset = [h] + [int(input()) for _ in range(4)]
    if len(set(dataset)) == 3 or len(set(dataset)) == 1:
        print(*[3]*5, sep="\n")
    for data in dataset:
        if data == 1:
            print(2 if 3 in dataset else 1)
        elif data == 2:
            print(2 if 1 in dataset else 1)
        else:
            print(2 if 2 in dataset else 1)

Submission status: Wrong Answer

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

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


def main(args):
    while True:
        hands = [0] * 5
        hands[0] = int(input())
        if hands[0] == 0:
            break
        hands[1] = int(input())
        hands[2] = int(input())
        hands[3] = int(input())
        hands[4] = int(input())

        # ?????????????????????????????±???????????????
        if 1 in hands and 2 in hands and 3 in hands: #  ??¨????????????????????´???
            for _ in range(5):
                print(3)
        elif hands.count(hands[0]) == 5: #  ??¨????????????????????´???
            for _ in range(5):
                print(3)
        # ??????????????????????????±???????????????
        else:
            for h in hands:
                if h+1 in hands:
                    print(1)
                else:
                    print(2)


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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#import pdb;    pdb.set_trace()
import sys

def solv(v):
    w = set(v)
    if len(w)==1 or len(w)==3:
        d={1:2, 2:2, 3:2}
    elif 1 in w and 2 in w:
        d={1:1, 2:2}
    elif 2 in w and 3 in w:
        d={2:1, 3:2}
    else:
        d={3:1, 1:2}
    return(list(map(lambda x:d[x], v) ))
def main():
    if True:
        fh = sys.stdin
    else:
        fh = open('vol2_0205.txt', 'r')
    try:
        while True:
            te = []
            for _ in range(5):
                x=int(fh.readline().strip())
                if x==0:
                    raise Exception
                te.append(x)
            b=(solv(te))
            for i in b:
                print(i)
    except Exception:
        1
    fh.close()
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# AOJ 0205: Rock, Paper, Scissors
# Python3 2018.6.25 bal4u

h = [0]*5
while True:
	try:
		for i in range(5): h[i] = int(input())
	except: break
	print(type(h), h)
	if len(set(h)) == 1 or len(set(h)) == 3:
		print(*[3]*5, sep='\n')
		continue
	ans = [1]*5
	for i in range(5):
		if   h[i] == 1: ans[i] += (h.count(3) > 0)
		elif h[i] == 2: ans[i] += (h.count(1) > 0)
		else:           ans[i] += (h.count(2) > 0)
	print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
def judge(h, hset):
  rest = hset - {h}
  if len(rest) in (0, 2):
    return 3
  if (h + 1) % 3 in rest:
    return 1
  else:
    return 2

while True:
  h1 = int(input())
  if h1 == 0:
    break
  hlst = []
  hset = set()
  hlst.append(h1)
  hset.add(h1)
  for _ in range(4):
    h = int(input())
    hlst.append(h)
    hset.add(h)
  for h in hlst:
    print(judge(h, hset))

Submission status: Wrong Answer

Solution code:
while True:
 try:
  ho = []
  for i in range(5):
    a = int(input())
    ho.append(a)
  if 1 in ho and 2 in ho and 3 in ho:
    for i in range(5):
      print 3
  if not(1 in ho):
    for i in range(5):
      if ho[i] == 2:
        print 1
      else: print 2
  if not(2 in ho):
    for i in range(5):
      if ho[i] == 3:
        print 1
      else: print 2
  elif not(3 in ho):
    for i in range(5):
      if ho[i] == 1:
        print 1
      else: print 2
 except EOFError: break

Submission status: Wrong Answer

Solution code:
while True:
  hoge,ans =[],[]
  a = raw_input()
  if int(a) == 0: break
  hoge.append(a)
  for i in range(4):
    a = raw_input()
    hoge.append(a)
  for i in range(5):
    if "1" not in hoge:
      for j in range(5):
        if hoge[j] == "2": ans.append(1)
        else: ans.append(2)
      else: break
    if "2" not in hoge:
      for j in range(5):
        if hoge[j] == "3": ans.append(1)
        else: ans.append(2)
      else: break
    if "3" not in hoge:
      for j in range(5):
        if hoge[j] == "1": ans.append(1)
        else: ans.append(2)
      else: break
    else:
      for j in range(5):
        ans.append(3)
      else: break
  for i in range(5):
    print ans[i]

Submission status: Wrong Answer

Solution code:
while 1:
	try:
		h=[input() for i in [1]*5]
		if (1 in h and 2 in h and 3) in h or max(h.count(1),h.count(2),h.coun(3))==5:
			for i in h:
				print 3
		if 1 in h:
			if 2 in h:
				for i in h:
					print 1 if i==1 else 2
			else:
				for i in h:
					print 1 if i==3 else 2
		elif 2 in h:
			for i in h:
				print 1 if i==2 else 1
	except:
		break

Submission status: Wrong Answer

Solution code:
while 1:
	try:
		h=[input() for i in [1]*5]
		if (1 in h and 2 in h and 3) in h or max(h.count(1),h.count(2),h.count(3))==5:
			for i in h:
				print 3
		elif 1 in h:
			if 2 in h:
				for i in h:
					print 1 if i==1 else 2
			else:
				for i in h:
					print 1 if i==3 else 2
		elif 2 in h:
			for i in h:
				print 1 if i==2 else 1
	except:
		break

Submission status: Wrong Answer

Solution code:
while 1:
	try:
		h=[input() for i in [1]*5]
		if 1 and 2 in h:w=1
		elif 1 and 3 in h:w=3
		else:w=2
		if len(set(h))!=2:
			for i in h:print 3
		else:
			for i in h:print 1 if i==w else 2
	except:break

Submission status: Accepted

Solution code:
import sys
while True:
 list=[]
 a=0
 b=0
 c=0
 for i in range(0,5):
  n=input()
  if(n==0):sys.exit()
  list.append(n)
  if(n==1):a+=1
  if(n==2):b+=1
  if(n==3):c+=1
 if a>0 and b>0 and c>0 or a==5 or b==5 or c==5:
  for i in range(0,5):
   print "3"
 elif a>0 and b>0:
  for i in range(0,5):
   if list[i]==1:print 1
   else :print 2
 elif b>0 and c>0:
  for i in range(0,5):
   if list[i]==2:print 1
   else :print 2
 else:
  for i in range(0,5):
   if list[i]==3:print 1
   else :print 2

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
def f1():
    if check[0] - check[-1] == 0:
        return result1()
        
def f2():
    g = None; c = None; p = None
    for n in check:
        if n == 1: g = 1
        if n == 2: c = 1
        if n == 3: p = 1
        if g and c and p:
            return result1()
        
def f3():
    if check[0] == 1 and check[-1] == 2:
        result2(1, 2)
    elif check[0] == 1 and check[-1] == 3:
        result2(3, 1)
    elif check[0] == 2 and check[-1] == 3:
        result2(2, 3)
    
def result1():
    for i in range(5):
        print 3
    return True

def result2(p, q):
    for v in data:
        if v == p:
            print 1
        elif v == q:
            print 2

while True:
    a = int(raw_input())
    if a == 0: break
    data = [a]
    for i in range(1, 5):
        data.append(int(raw_input()))
    check = sorted(data)
    if f1(): continue
    if f2(): continue
    f3()

Submission status: Accepted

Solution code:
while True:
    te = []
    tmp = 0
    for i in range(5):
        tmp = input()
        if tmp == 0:
            break
        te.append(tmp)
    if tmp == 0:
        break
    out = []
    if te[0]==te[1] and te[1]==te[2] and te[2]==te[3] and te[3]==te[4]:
        out += [3, 3, 3, 3, 3]
    elif 1 in te and 2 in te and 3 in te:
        out += [3, 3, 3, 3, 3]
    else:
        if not 1 in te:
            for i in range(5):
                    if te[i] == 2:
                        out.append(1)
                    elif te[i] == 3:
                        out.append(2)

        elif not 2 in te:
            for i in range(5):
                    if te[i] == 1:
                        out.append(2)
                    elif te[i] == 3:
                        out.append(1)

        elif not 3 in te:
            for i in range(5):
                    if te[i] == 1:
                        out.append(1)
                    elif te[i] == 2:
                        out.append(2)
    for o in out:
        print"%d" % o

Submission status: Accepted

Solution code:
def check_aiko(arr):
    if all(arr[0] == a for a in arr):
        return True

    rps = [1, 2, 3]
    for t in rps:
        if t not in arr:
            return False

    return True


def check_v(arr):
    rps = {}
    o = []
    for t in arr:
        if t not in rps:
            rps[t] = 0
    if 1 in rps.keys() and 2 in rps.keys():
        rps[1], rps[2] = 1, 2
    elif 2 in rps.keys() and 3 in rps.keys():
        rps[2], rps[3] = 1, 2
    elif 1 in rps.keys() and 3 in rps.keys():
        rps[3], rps[1] = 1, 2

    for n in arr:
        o.append(rps.get(n))
    return o


def algorithm():
    g = []
    out = []

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

        g.append(inp)
        if len(g) == 5:
            if check_aiko(g):
                out = [3] * 5
            else:
                out = check_v(g)

            for o in out:
                print(o)
            g.clear()
            out.clear()


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while 1:
    state = [input()]
    if state[0] == 0: exit()
    for i in xrange(4): state.append(input())
    set_state = set(state)
    if set_state == set([1, 2]): result = state
    elif set_state == set([2, 3]): result = map(lambda x:x -1, state)
    elif set_state == set([1, 3]): result = map(lambda x:x - 2 if x == 3 else x + 1, state)
    else: result = [3] * 5
    for i in result: print i

Submission status: Accepted

Solution code:
while 1:
    a=int(input())
    if a==0:break
    a=[a]+[int(input()) for _ in range(4)]
    r=a.count(1);s=a.count(2);p=5-r-s
    if [r,s,p].count(0)==1:
        if r and s:w=1
        elif r and p:w=3
        else:w=2
        [print([2,1][w==x])for x in a]
    else:print('3\n'*5,end='')

Submission status: Accepted

Solution code:
def solve(a, b, c, d, e):
	if a == b == c == d == e:
		for i in range(5):
			print 3
	elif [a,b,c,d,e].count(1) > 0 and [a,b,c,d,e].count(2) > 0 and [a,b,c,d,e].count(3) > 0:
		for i in range(5):
			print 3
	else:
		w = sorted([a,b,c,d,e])[0]
		l = sorted([a,b,c,d,e])[-1]
		if w == 1:
			for f in [a,b,c,d,e]:
				if l == 2:
					if f == 2:
						print 2
					else:
						print 1
				else:
					if f == 3:
						print 1
					else:
						print 2
		elif w == 2:
			for f in [a,b,c,d,e]:
				if l == 1:
					if f == 1:
						print 1
					else:
						print 2
				else:
					if f == 3:
						print 2
					else:
						print 1
		else:
			for f in [a,b,c,d,e]:
				if l == 2:
					if f == 2:
						print 2
					else:
						print 1
				else:
					if f == 1:
						print 1
					else:
						print 2
				

a = input()
while a != 0:
	b = input()
	c = input()
	d = input()
	e = input()
	solve(a, b, c, d, e)
	a = input()

Submission status: Accepted

Solution code:
while True:
    h = int(input())
    if h == 0:
        break
    h = [h] + [int(input()) for _ in range(4)]
    if len(set(h)) == 3 or len(set(h)) == 1:
        print(*["3"]*5, sep='\n')
        continue
    for c in h:
        if c == 1:
            print("1" if 2 in h else "2")
        elif c == 2:
            print("1" if 3 in h else "2")
        else:
            print("1" if 1 in h else "2")

Submission status: Accepted

Solution code:
d = {1:2, 2:3, 3:1}
while True:
    h = int(input())
    if h == 0:
        break
    h = [h] + [int(input()) for _ in range(4)]
    if len(set(h)) == 3 or len(set(h)) == 1:
        print(*[3]*5, sep='\n')
        continue
    for c in h:
        print([2, 1][d[c] in h])

Submission status: Accepted

Solution code:
while True:
    h = int(input())
    if h == 0:
        break
    h = [h] + [int(input()) for _ in range(4)]
    if len(set(h)) == 3 or len(set(h)) == 1:
        print(*[3]*5, sep='\n')
        continue
    d = {1:2, 2:3, 3:1}
    for c in h:
        print([2, 1][d[c] in h])

Submission status: Accepted

Solution code:
# Aizu Problem 0205: Rock Paper Scissor
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

        
while True:
    try:
        game = [int(input()) for _ in range(5)]
    except EOFError:
        break
    if 1 in game and 2 in game:
        w = 1
    elif 1 in game:
        w = 3
    else:
        w = 2
    if len(set(game)) != 2:
        for g in game:
            print(3)
    else:
        for g in game:
            print(1 if g == w else 2)

Submission status: Accepted

Solution code:
while True:
    h = int(input())
    if h == 0:
        break
    dataset = [h] + [int(input()) for _ in range(4)]
    if len(set(dataset)) == 3 or len(set(dataset)) == 1:
        print(*[3]*5, sep="\n")
        continue
    
    for data in dataset:
        if data == 1:
            print(2 if 3 in dataset else 1)
        elif data == 2:
            print(2 if 1 in dataset else 1)
        else:
            print(2 if 2 in dataset else 1)

Submission status: Accepted

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

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


def main(args):
    while True:
        hands = [0] * 5
        hands[0] = int(input())
        if hands[0] == 0:
            break
        hands[1] = int(input())
        hands[2] = int(input())
        hands[3] = int(input())
        hands[4] = int(input())

        # ?????????????????????????????±???????????????
        if 1 in hands and 2 in hands and 3 in hands: #  ??¨????????????????????´???
            for _ in range(5):
                print(3)
        elif hands.count(hands[0]) == 5: #  ??¨????????????????????´???
            for _ in range(5):
                print(3)
        # ??????????????????????????±???????????????
        else:
            for h in hands:
                if (h+1 in hands) or (h==3 and 1 in hands):
                    print(1)
                else:
                    print(2)


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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#import pdb;    pdb.set_trace()
import sys

def solv(v):
    w = set(v)
    if len(w)==1 or len(w)==3:
        d={1:3, 2:3, 3:3}
    elif 1 in w and 2 in w:
        d={1:1, 2:2}
    elif 2 in w and 3 in w:
        d={2:1, 3:2}
    else:
        d={3:1, 1:2}
    return(list(map(lambda x:d[x], v) ))
def main():
    if True:
        fh = sys.stdin
    else:
        fh = open('vol2_0205.txt', 'r')
    try:
        while True:
            te = []
            for _ in range(5):
                x=int(fh.readline().strip())
                if x==0:
                    raise Exception
                te.append(x)
            b=(solv(te))
            for i in b:
                print(i)
    except Exception:
        1
    fh.close()
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# AOJ 0205: Rock, Paper, Scissors
# Python3 2018.6.25 bal4u

h = [0]*5
while True:
	try:
		for i in range(5): h[i] = int(input())
	except: break
	if len(set(h)) == 1 or len(set(h)) == 3:
		print(*[3]*5, sep='\n')
		continue
	ans = [1]*5
	for i in range(5):
		if   h[i] == 1: ans[i] += (h.count(3) > 0)
		elif h[i] == 2: ans[i] += (h.count(1) > 0)
		else:           ans[i] += (h.count(2) > 0)
	print(*ans, sep='\n')

Submission status: Accepted

Solution code:
def judge(h, hset):
  rest = hset - {h}
  if len(rest) in (0, 2):
    return 3
  if h % 3 + 1 in rest:
    return 1
  else:
    return 2

while True:
  h1 = int(input())
  if h1 == 0:
    break
  hlst = []
  hset = set()
  hlst.append(h1)
  hset.add(h1)
  for _ in range(4):
    h = int(input())
    hlst.append(h)
    hset.add(h)
  for h in hlst:
    print(judge(h, hset))

Submission status: Accepted

Solution code:
while True:
  ans=[]
  a=int(input())
  if a ==0: break
  ans.append(a)
  for i in range(4):
    b=int(input())
    ans.append(b)
  if 1 in ans and 2 in ans and 3 in ans:
    for i in range(5): print "3"
  elif 1 in ans and 2 in ans and 3 not in ans:
    for i in range(5):
      if ans[i] == 1: print 1
      else: print 2
  elif 2 in ans and 3 in ans and 1 not in ans:
    for i in range(5):
      if ans[i] == 2: print 1
      else: print 2
  elif 3 in ans and 1 in ans and 2 not in ans:
    for i in range(5):
      if ans[i] == 3: print 1
      else: print 2
  else:
    for i in range(5): print "3"

Submission status: Accepted

Solution code:
while True:
    a=input()
    if a==0:break
    L=[a]+[input() for i in range(4)]
    S=set(L)
    if len(S)<>2:
        print "\n".join(["3"]*5)
    else:
        if set([1,2])==S:
            for i in range(5):
                print 1 if L[i]==1 else 2
        elif set([1,3])==S:
            for i in range(5):
                print 1 if L[i]==3 else 2
        else:
            for i in range(5):
                print 1 if L[i]==2 else 2

Submission status: Accepted

Solution code:
D = [[],[0,0,1,-1],[0,-1,0,1],[0,1,-1,0]]
E = map(str, [3,1,2])
while True:
    d = []
    try:
        d = [int(raw_input()) for _ in xrange(5)]
    except:
        break
    h = set(d)
    print "\n".join(E[sum(D[dd][hh] for hh in h)] for dd in d)

Submission status: Accepted

Solution code:
while 1:
	try:
		h=[input() for i in [1]*5]
		if (1 in h and 2 in h and 3) in h or max(h.count(1),h.count(2),h.count(3))==5:
			for i in h:print 3
		elif 1 in h:
			if 2 in h:
				for i in h:print 1 if i==1 else 2
			else:
				for i in h:print 1 if i==3 else 2
		elif 2 in h:
			for i in h:print 1 if i==2 else 2
	except:
		break

Submission status: Accepted

Solution code:
while 1:
	try:
		h=[input() for i in [1]*5]
		l=set(h)
		if 1 in h and 2 in h:w=1
		if 1 in h and 3 in h:w=3
		if 2 in h and 3 in h:w=2
		if len(l)==3 or len(l)==1:
			for i in h:print 3
		else:
			for i in h:print 1 if i==w else 2
	except:
		break

Submission status: Accepted

Solution code:
while 1:
	try:
		h=[input() for i in [1]*5]
		l=set(h)
		if 1 in l and 2 in l:w=1
		elif 1 in l and 3 in l:w=3
		else:w=2
		if len(l)!=2:
			for i in h:print 3
		else:
			for i in h:print 1 if i==w else 2
	except:break

Submission status: Accepted

Solution code:
while 1:
	try:
		h=[input() for i in [1]*5]
		if 1 in h and 2 in h:w=1
		elif 1 in h:w=3
		else:w=2
		if len(set(	h))!=2:
			for i in h:print 3
		else:
			for i in h:print 1 if i==w else 2
	except:break

Submission status: Accepted

Solution code:
while 1:
	try:
		h=[input() for i in [1]*5]
		if 1 in h and 2 in h:w=1
		elif 1 in h:w=3
		else:w=2
		if len(set(h))!=2:
			for i in h:print 3
		else:
			for i in h:print 1 if i==w else 2
	except:break

Submission status: Accepted

Solution code:
while 1:
	try:
		h=[input() for i in [1]*5]
		if 1 in h and 2 in h:w=1
		elif 1 in h:w=3
		else:w=2
		for i in h:
			if len(set(h))!=2:print 3
			else:print 1 if i==w else 2
	except:break

Submission status: Accepted

Solution code:
#5個のうち1番目の入力が0なら処理を終わる。
while True:
    line = []
    line.append(int(input()))
    if line[0] == 0:break

    #標準入力をしリストをセットにしたものを作る。
    for _ in range(4):line.append(int(input()))
    se = set(line)
    
    #全員が同じ数を出すか3種類の手が出たら5こ"3"を出力する。
    if len(se) == 1 or len(se) == 3:
        for _ in range(5):print("3")
        ""
    #じゃんけんの勝敗に基づき勝ちだったら"1"負けだったら"2"を出力する
    else:
        if sum(se) == 3:
            for i in line:
                if i == 1:print("1")
                else:print("2")
        if sum(se) == 4:
            for i in line:
                if i == 3:print("1")
                else:print("2")
        if sum(se) == 5:
            for i in line:
                if i == 2:print("1")
                else:print("2")

Submission status: Accepted

Solution code:
while True:
    h1 = int(input())
    if h1 == 0:
        break
    h = [h1] + [int(input()) for _ in range(4)]
    if len(set(h)) == 1 or len(set(h)) == 3:
        print(*[3]*5, sep="\n")
        continue
    for hi in h:
        print([2, 1][(hi%3)+1 in h])

Submission status: Accepted

Solution code:
# グー:1,チョキ:2,パー:3
# 勝ち:1,負け:2,あいこ:3
datas = [0] * 5
while(1):
    try:
        lens = [0] * 3
        status = [0] * 3
        for i in range(0,5):
            datas[i] = int(input())
            lens[datas[i] - 1] += 1
        # あいこ
        if (lens[0] > 0 and lens[1] > 0 and lens[2] > 0) or (lens[0] == 5 or lens[1] == 5 or lens[2] == 5):
            for i in range(0,5):
                print(3)
        else:
            # グー
            if lens[0] > 0:
                status[1] = 2
                status[2] = 1
            # チョキ
            if lens[1] > 0:
                status[0] = 1
                status[2] = 2
            # パー
            if lens[2] > 0:
                status[0] = 2
                status[1] = 1
            for i in range(0,5):
                print(status[datas[i] - 1])
    except:
        break

Submission status: Accepted

Solution code:
while True:
    try:
        a = [int(input()) for i in range(5)]
    except:
        break
    if (1 in a and 2 in a and 3 in a) or a.count(a[0]) == 5:
        for i in range(5):
            print(3)
    elif not 3 in a:
        for b in a:
            if b == 1:
                print(1)
            else:
                print(2)
    elif not 2 in a:
        for b in a:
            if b == 1:
                print(2)
            else:
                print(1)
    else:
        for b in a:
            if b == 2:
                print(1)
            else:
                print(2)

Submission status: Accepted

Solution code:

while True:
    L = []
    H = []
    for _ in range(5):
        c = int(input())
        if c == 0:
            exit()
        L.append(c)

    h = set(L)

    if len(h) in [1, 3]:
        for _ in range(5):
            H.append(3)
    else:
        r = list(set([1,2,3])-h)[0]
        if r == 1:
            w = 2
        elif r == 2:
            w = 3
        else:
            w = 1
        for i in L:
            if i == w:
                H.append(1)
            else:
                H.append(2)
    for i in H:
        print(i)

Submission status: Accepted

Solution code:
win=[0,2,3,1]
lose=[0,3,1,2]
while True:
    exist=[False for i in range(4)]
    h=[0 for i in range(5)]
    h[0] = int(input())
    exist[h[0]]=True
    if h[0] == 0 :
        break
    for i in range(1,5):
        h[i]=int(input())
        exist[h[i]]=True
    for i in range(5):
        if exist[win[h[i]]] and not exist[lose[h[i]]]:
            print(1)
        elif not exist[win[h[i]]] and exist[lose[h[i]]]:
            print(2)
        else:
            print(3)

Submission status: Accepted

Solution code:
while True:
    
    has=[False, False, False, False]
    
    n=input()
    if n=='0':
        break
    te=[]
    te.append(n)
    has[int(n)]=True
    for adf in range(4):
        n=input()
        has[int(n)] = True
        te.append(n)
        
    if has[1] and has[2] and has[3]:
        for qwer in range(5):
            print(3)
    elif te[1]==te[2] and te[2]==te[3] and te[3]==te[4] and te[0]==te[4]:
        for asdd in range(5):
            print(3)
    elif not has[3]:
        for g in range(5):
            if te[g]=='1':
                print('1')
            else:
                print('2')
    elif not has[2]:
        for g in range(5):
             if te[g]=='3':
                print('1')
             else:
                print('2')
    else:
        for g in range(5):
            if te[g]=='2':
                print('1')
            else:
                print('2')

Submission status: Accepted

Solution code:
def judge(h, hands):
  if h == '1':
    if '2' in hands:
      if '3' not in hands:
        return 1
      else:
        return 3
    elif '2' not in hands:
      if '3' not in hands:
        return 3
      else:
        return 2
  elif h == '2':
    if '3' in hands:
      if '1' not in hands:
        return 1
      else:
        return 3
    elif '3' not in hands:
      if '1' not in hands:
        return 3
      else:
        return 2
  else:
    if '1' in hands:
      if '2' not in hands:
        return 1
      else:
        return 3
    elif '1' not in hands:
      if '2' not in hands:
        return 3
      else:
        return 2

while True:
  hands = []
  for _ in range(5):
    h = input()
    if h == '0':
      exit()
    else:
      hands.append(h)
  for h in hands:
    print(judge(h, hands))