Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		h := make([]int, 5)
		h[0], _ = strconv.Atoi(scanner.Text())
		if h[0] == 0 {
			break
		}
		for i := 1; i <= 4; i++ {
			scanner.Scan()
			h[i], _ = strconv.Atoi(scanner.Text())
		}
		tbl := make([]bool, 3)
		aiko := false
		for _, v := range h {
			tbl[v-1] = true
		}
		if tbl[0] && tbl[1] && tbl[2] { // 全ての手があるあいこ
			aiko = true
		}
		if h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4] {
			aiko = true
		}
		if aiko {
			fmt.Printf("3\n3\n3\n3\n3\n")
		} else {
			win := 0
			if !tbl[0] {
				win = 2
			}
			if !tbl[1] {
				win = 3
			}
			if !tbl[2] {
				win = 1
			}
			for i := 0; i < 5; i++ {
				if h[i] == win {
					fmt.Println(1)
				} else {
					fmt.Println(2)
				}
			}
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[5],i,flg,j;
	while(1){
		int g=0,t=0,p=0;
		int mflg=0,kflg=0;
		flg=0;
		for(i=0;i<5;i++){
			cin>>a[i];
			if(a[i]==0) break;
			if(a[i]==1) g=1;
			else if(a[i]==2) t=1;
			else p=1;
		}
		if(a[0]==0) break;
		else if(g==1 && t==1 && p==1) {
			for(i=0;i<5;i++) cout<<"3"<<endl;
		}
		else {
			for(i=0;i<5;i++){
				mflg=0;
				kflg=0;
				for(j=0;j<5;j++){
					if(a[i]==a[j]) ;
					else if(a[i]==1 && a[j]==3 || a[i]==2 && a[j]==1 || a[i]==3 && a[j]==2) mflg=1;
					else kflg=1;
				}
				if(mflg==1) cout<<"2"<<endl;
				else cout<<"1"<<endl;
			}
		}
	}	
	return 0;
}

C++: #include <iostream>
#define rep(i) for(i=0;i<5;i++)
using namespace std;
int main(){
  int a[5],i;
  while(1){
    int b[3]={0};
    for(i=0;i<5;i++){
      cin>>a[i];
      if(!a[i])return 0;
      b[a[i]-1]++;
    }
    if(b[0]&&b[1]&&!b[2])rep(i)cout<<((a[i]==1)?1:2)<<endl;
    else if(b[0]&&!b[1]&&b[2])rep(i)cout<<((a[i]==3)?1:2)<<endl;
    else if(!b[0]&&b[1]&&b[2])rep(i)cout<<((a[i]==2)?1:2)<<endl;
    else rep(i)cout<<'3'<<endl;
  }
}

C++: #include<iostream>
int main(){while(1){int s[6],g[4]={0},n=-2,v=0,i;for(i=5;i;i--){std::cin>>s[i];if(!*s)goto l;if(!g[s[i]]){n++;g[s[i]]=1;if(v-1==s[i]%3||!v)v=s[i];}}for(i=5;i;i--)std::cout<<(!n?(v==s[i]?1:2):3)<<"\n";}l:;return 0;}

C++: // 2010/12/21 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int te[5];
		cin >> te[0];
		if(te[0]==0)
			break;
		for(int i=1; i<5; i++)
			cin >> te[i];

		int gu = 0;
		int ch = 0;
		int pa = 0;
		for(int i=0; i<5; i++)
			if(te[i]==1)
				gu++;
			else if(te[i]==2)
				ch++;
			else
				pa++;

		if(gu==5||ch==5||pa==5||gu*ch*pa!=0)
			for(int i=0; i<5; i++)
				cout << 3 << endl;
		else if(gu==0)
			for(int i=0; i<5; i++)
				if(te[i]==2)
					cout << 1 << endl;
				else
					cout << 2 << endl;
		else if(ch==0)
			for(int i=0; i<5; i++)
				if(te[i]==3)
					cout << 1 << endl;
				else
					cout << 2 << endl;
		else
			for(int i=0; i<5; i++)
				if(te[i]==1)
					cout << 1 << endl;
				else
					cout << 2 << endl;
	}

	return 0;
}

C++: #include<iostream>
using namespace std;

int judge[4];
int input[5];

int main(){
	while(cin >> input[0], input[0]){
		for(int i=0; i < 4; i++) judge[i] = 0;
		judge[input[0]] = 1;
		for(int i=1; i < 5; i++){
			cin >> input[i];
			judge[input[i]] = 1;
		}

		if(judge[1] && judge[2] && judge[3]) for(int i=0; i < 5; i++) cout << '3' << endl;
		else if(judge[1] && judge[2]){
			for(int i=0; i < 5; i++){
				if(input[i] == 1) cout << '1' << endl;
				else cout << '2' << endl;
			}
		}
		else if(judge[2] && judge[3]){
			for(int i=0; i < 5; i++){
				if(input[i] == 2) cout << '1' << endl;
				else cout << '2' << endl;
			}
		}
		else if(judge[1] && judge[3]){
			for(int i=0; i < 5; i++){
				if(input[i] == 3) cout << '1' << endl;
				else cout << '2' << endl;
			}
		}
		else {
			for(int i=0; i < 5; i++){
				cout << '3' << endl;
			}
		}
	}
}

C++: type hand = Rock | Paper | Scissors
 
type result = Win | Lose | Draw
 
module HandSet = Set.Make (
                     struct
                       type t = hand
                       let compare (a : hand) b = compare a b
                     end)
 
let hand_of_int = function
  | 1 -> Some Rock
  | 2 -> Some Scissors
  | 3 -> Some Paper
  | _ -> None
 
let int_of_result = function
  | Win -> 1
  | Lose -> 2
  | Draw -> 3
 
exception BreakLoop
 
let read_hands () =
  try
    let hands = Array.init
                  5
                  (fun _ -> match read_int () |> hand_of_int with
                            | None -> raise BreakLoop
                            | Some hand -> hand) in
    Some (Array.to_list hands)
  with BreakLoop -> None
 
let match_ hands =
  let set = HandSet.of_list hands in
  if HandSet.cardinal set <> 2 then Array.make 5 Draw |> Array.to_list
  else
    let defeats a b =
      match a, b with
      | Rock, Paper -> false
      | Rock, Scissors -> true
      | Paper, Rock -> true
      | Paper, Scissors -> false
      | Scissors, Rock -> false
      | Scissors, Paper -> true
      | _ -> invalid_arg "defeats" in
    List.map
      (fun hand ->
       let match_ = HandSet.remove hand set |> HandSet.choose in
       if defeats hand match_ then Win else Lose)
      hands
 
let rec solve () =
  match read_hands () with
  | None -> ()
  | Some hands ->
     let results = match_ hands in
     List.iter
       (fun result ->
        int_of_result result |> print_int;
        print_newline ())
       results;
     solve ()
 
let () = solve ()

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int a[5];
    while(cin>>a[0]){
        if(a[0]==0)break;
        for(int i=1;i<5;i++){
            cin>>a[i];
        }
        
        rep(i,5){
            bool win=true;
            bool lose=true;
            rep(j,5){
                if(i!=j){
                    if(a[j]==(a[i]+1)%3+1)win=false;
                    if(a[j]==(a[i])%3+1)lose=false;
                }
            }
            if(!win && !lose){
                cout<<"3"<<endl;
            }
            else if(win)cout<<"1"<<endl;
            else if(lose)cout<<"2"<<endl;

        }
        
    }
}

C++: #include<stdio.h>
int main(){
	int i;
	int pl[5];
	int aiko[3];
	for(;;){
		scanf("%d",&pl[0]);
		if(pl[0]==0)break;
		if(pl[0]==1)aiko[0]=1;
		if(pl[0]==2)aiko[1]=1;
		if(pl[0]==3)aiko[2]=1;
		for(i=1;i<5;i++){
			scanf("%d",&pl[i]);
			if(pl[i]==1)aiko[0]=1;
			if(pl[i]==2)aiko[1]=1;
			if(pl[i]==3)aiko[2]=1;
		}
		if(pl[0]==pl[1] &&  pl[1]==pl[2] &&  pl[2]==pl[3] &&  pl[3]==pl[4]){
			for(i=0;i<5;i++){
				pl[i]=3;
			}
		}
		else if(aiko[0]==1 && aiko[1]==1 && aiko[2]==1){
			for(i=0;i<5;i++){
				pl[i]=3;
			}
		}
		
		else if(aiko[0]==1 && aiko[1]==1 && aiko[2]==0){
			for(i=0;i<5;i++){
				if(pl[i]==1)pl[i]=1;
				if(pl[i]==2)pl[i]=2;
			}
		}
		else if(aiko[0]==0 && aiko[1]==1 && aiko[2]==1){
			for(i=0;i<5;i++){
				if(pl[i]==2)pl[i]=1;
				if(pl[i]==3)pl[i]=2;
			}
		}
		else if(aiko[0]==1 && aiko[1]==0 && aiko[2]==1){
			for(i=0;i<5;i++){
				if(pl[i]==1)pl[i]=2;
				if(pl[i]==3)pl[i]=1;
			}
		}
		for(i=0;i<5;i++){
			printf("%d\n",pl[i]);
		}
		for(i=0;i<3;i++)aiko[i]=0;
	}
	return 0;
}