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>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    int A[5], B[5];
    while ( cin >> A[0] && A[0] ) {
        int state = 1 << A[0];
        for ( int i = 1; i < 5; ++ i ) {
            cin >> A[i];
            state |= 1 << A[i];
        }
        if ( state == ( 1 << 1 | 1 << 2 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 1 ? 1 : 2;
            }
        } else if ( state == ( 1 << 2 | 1 << 3 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 2 ? 1 : 2;
            }
        } else if ( state == ( 1 << 3 | 1 << 1 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 3 ? 1 : 2;
            }
        } else {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = 3;
            }
        }
        for ( int i = 0; i < 5; ++ i ) {
            cout << B[i] << endl;
        }
    }
    return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	while(true){
		bool flag =true;
		map<int,int> data;
		data.clear();
		bool draw =false;
		bool goo,tyoki,pa;
		goo=tyoki=pa=false;
		int a[5]={0};
		for(int i =0;i <5;i++){
			int x;
			cin>>x;
			if(x==0){
				flag =false;
				break;
			}
			data[x]++;
			a[i]=x;
		}
		if((data[1]&&data[2]&&data[3])||(data[1]&&data[2]==0&&data[3]==0)||(
		   data[1]==0&&data[2]&&data[3]==0)||(data[1]==0&&data[2]==0&&data[3])){
			draw =true;
		}else if((data[1]&&data[2]&&data[3]==0)){
			goo =true;
		}else if((data[1]==0&&data[2]&&data[3])){
			tyoki =true;
		}else if((data[1]&&data[2]==0&&data[3])){
			pa =true;
		}
		if(draw){
			for(int i =0;i <5;i++){
				cout <<3<<endl;
			}
			continue;
		}else if(goo){
			for(int i =0;i <5;i++){
				if(a[i]==1){
					cout <<1<<endl;
				}else{
					cout <<2<<endl;
				}
			}
		}else if(tyoki){
			for(int i =0;i <5;i++){
				if(a[i]==2){
					cout <<1<<endl;
				}else{
					cout <<2<<endl;
				}
			}
		}else if(pa){
			for(int i =0;i <5;i++){
				if(a[i]==3){
					cout <<1<<endl;
				}else{
					cout <<2<<endl;
				}
			}
		}
		if(!flag)break;
	}
	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string C;
string sA, strB;
vector<vector<char>> map;
vector<int> card;
vector<string> str;

int sum = 0;


void input() {

	while (true) {
		CI n;
		if (n == 0) {
			break;
		}
		card.push_back(n);
	}

	return;
}


int main(void) {
	int goo = 0;
	int choki = 0;
	int paa = 0;
	input();

	REP(i, card.size() / 5) {
		for (int j = (i * 5); j < (i * 5) + 5; j++) {
			switch (card[j]) {
			case 1:
				goo++;
				break;
			case 2:
				choki++;
				break;
			case 3:
				paa++;
				break;
			default:
				break;
			}
		}
		if (goo > 0 && choki > 0 && paa > 0) {
			REP(j, 5)CO 3 E
		}
		else {
			if (goo > 0 && choki > 0 && paa <= 0) {
				for (int j = i * 5; j < (i * 5) + 5; j++) {
					switch (card[j]) {
					case 1:
						CO 1 E
							break;
					case 2:
						CO 2 E
							break;
					default:
						break;
					}
				}
			}
			if (goo <= 0 && choki > 0 && paa > 0) {
				for (int j = i * 5; j < (i * 5) + 5; j++) {
					switch (card[j]) {
					case 1:
						break;
					case 2:
						CO 1 E
							break;
					case 3:
						CO 2 E
							break;
					default:
						break;
					}
				}
			}
			if (goo > 0 && choki <= 0 && paa > 0) {
				for (int j = i * 5; j < (i * 5) + 5; j++) {
					switch (card[j]) {
					case 1:
						CO 2 E
						break;
					case 2:
						break;
					case 3:
						CO 1 E
						break;
					default:
						break;
					}
				}
			}
			

		}
		goo = 0;
		choki = 0;
		paa = 0;
	}


	return 0;
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    vector<int> h(5);
    while(cin >> h[0] && h[0])
    {
        REP(i, 1, 5) cin >> h[i];

        set<int> s;

        rep(i, 5) s.insert(h[i]);

        if(!s.count(1))
        {
            rep(i, 5)
            {
                cout << (h[i] == 2 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(2))
        {
            rep(i, 5)
            {
                cout << (h[i] == 3 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(3))
        {
            rep(i, 5)
            {
                cout << (h[i] == 1 ? 1 : 2) << endl;
            }
        }
        else
        {
            cout << 3 << endl;
        }
    }

    return 0;
}