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 <stdio.h>
#include <iostream>

using namespace std;

int main(){
	int a[5], h[4] = { 0 };
	cin >> a[0];
	while (a[0]){
		for (int i = 1; i < 5; i++){
			cin >> a[i];
			h[a[i]]++;
		}
		if ((h[1] && h[2] && h[3]) || (h[1] == 5 || h[2] == 5 || h[3] == 5)){
			for (int i = 0; i < 5; i++){
				cout << 3 << endl;
			}
		} else {
			if (h[1] == 0){
				for (int i = 0; i < 5; i++){
					if (a[i] == 2){
						cout << 1 << endl;
					} else{
						cout << 2 << endl;
					}
				}
			} else if (h[2] == 0){
				for (int i = 0; i < 5; i++){
					if (a[i] == 3){
						cout << 1 << endl;
					} else{
						cout << 2 << endl;
					}
				}
			} else {
				for (int i = 0; i < 5; i++){
					if (a[i] == 1){
						cout << 1 << endl;
					} else{
						cout << 2 << endl;
					}
				}
			}
		}
		for (int i = 0; i < 5; i++){
			a[i] = 0;
		}
		for (int i = 1; i < 4; i++){
			h[i] = 0;
		}
		cin >> a[0];
	}
	return 0;
}