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++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

int main(){
	int gesture[5];
	while(~scanf("%d",&gesture)){
		if(gesture[0]==0) break;
		for(int i=0;i<4;i++){
			scanf("%d",gesture+i+1);
		}

		for(int i=0;i<5;i++){
			int bit,player;
			bit = player = (1 << (gesture[i]-1));

			for(int j=0;j<5;j++){
				if(i==j) continue;
				bit |= (1 << (gesture[j]-1));
			}

			if(bit == ((1<<3)-1)){
				printf("3\n");
			}

			else if(bit == 1 
				|| bit == (1<<1)
				|| bit == (1<<2)){
					printf("3\n");
			}

			else{
				bit &= ~player;
				if(player == 1 && bit == (1<<1)){
					printf("1\n");
				}
				else if(player == 1 && bit == (1<<2)){
					printf("2\n");
				}

				else if(player == (1<<1) && bit == 1){
					printf("2\n");
				}
				else if(player == (1<<1) && bit == (1<<2)){
					printf("1\n");
				}

				else if(player == (1<<2) && bit == 1){
					printf("1\n");
				}
				else if(player == (1<<2) && bit == (1<<1)){
					printf("2\n");
				}
			}
		}
		
	}

}

C++: #include<iostream>
#include<vector>

using namespace std;

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
	vector<int> inp(5);
	while(cin>>inp[0],inp[0]){
		bool judge[3] = {false};
		loop(i,1,5){
			cin>>inp[i];
			judge[inp[i]-1]=true;
		}
		if(judge[0]&&judge[1]&&judge[2])
			rep(i,5)cout<<3<<endl;
		else if(judge[0]&&judge[1]&&!judge[2])
			rep(j,5)
				if(inp[j]-1==0)	cout<<1<<endl;
				else 						cout<<2<<endl;
		else if(!judge[0]&&judge[1]&&judge[2])
			rep(j,5)
				if(inp[j]-1==1)	cout<<1<<endl;
				else 						cout<<2<<endl;
		else if(judge[0]&&!judge[1]&&judge[2])
			rep(j,5)
				if(inp[j]-1==2)	cout<<1<<endl;
				else 						cout<<2<<endl;
		else
			rep(j,5)cout<<3<<endl;
	}
}

C++: #include<iostream>

void solve(int *data);

using namespace std;

int main(){
	int player[5] = {0};
	int cnt = 0;

	while(1){
		int flag = -1;

		cin >> flag;

		if(flag == 0)break;

		player[0] = flag;

		cin >> player[1] >> player[2] >> player[3] >> player[4];

		solve(player);
	}
	return 0;
}

void solve(int *player){
	bool gu = false,pa = false,ty = false;

	for(int i=0;i<5;i++){
		if(player[i] == 1)gu = true;
		else if(player[i] == 2)ty = true;
		else if(player[i] == 3)pa = true;
	}

	if(gu && pa && ty){
		for(int j=0;j<5;j++)
			cout << '3' << endl;
		return ;
	}

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

C++: #include<iostream>
using namespace std;
int main(){
	int a[5],i,flg,j;
	while(1){
		int g=0,t=0,p=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++){
				int 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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi v(5);
  while (cin >> v[0], v[0]) {
    loop(i, 1, 5) cin >> v[i];
    vi w(4);
    rep(i, 5) {
      v[i]--;
      w[v[i]]++;
      if (v[i] == 0) w[3]++;
    }
    if (w[0] > 0 && w[1] > 0 && w[2] > 0 || v[0] == v[1] == v[2] == v[3] == v[4]) {
      rep(i, 5) cout << 3 << endl;
      continue;
    }
    rep(i, 5) {
      cout << 2 - !!w[v[i] + 1] << endl;
    }
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int h[5],n[3];

int main(){
	while(cin>>h[0]>>h[1]>>h[2]>>h[3]>>h[4]){
		fill(n,n+3,0);
		for(int i=0;i<5;i++)n[h[i]-1]++;
		if(n[0]==5||n[1]==5||n[2]==5||n[0]&&n[1]&&n[2])cout<<"3\n3\n3\n3\n3\n";
		else{
			if(!n[0])for(int i=0;i<5;i++){
				if(h[i]==2)cout<<"1\n";
				else cout<<"2\n";
			}
			if(!n[1])for(int i=0;i<5;i++){
				if(h[i]==3)cout<<"1\n";
				else cout<<"2\n";
			}
			if(!n[2])for(int i=0;i<5;i++){
				if(h[i]==1)cout<<"1\n";
				else cout<<"2\n";
			}
		}
	}
}