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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void print_aiko()
{
	rep(i, 5) cout << 3 << endl;
}

int main()
{
	int hand[5];
	map<int, int> num;

	while (cin >> hand[0])
	{
		num.clear();
		if (hand[0] == 0) break;
		num[hand[0]]++;

		for (int i = 1; i < 5; i++)
		{
			cin >> hand[i];
			num[hand[i]]++;
		}

		if ((num[1] > 0 && num[2] > 0 && num[3] > 0)
			|| num[1] == 5 || num[2] == 5 || num[3] == 5)
		{
			print_aiko();
			continue;
		}

		//??°??????0???
		if (num[1] == 0)
		{
			num[2] = 1;
			num[3] = 2;
		}
		//?????§??????0???
		else if (num[2] == 0)
		{
			num[1] = 2;
			num[3] = 1;
		}
		else if (num[3] == 0)
		{
			num[1] = 1;
			num[2] = 2;
		}

		rep(i, 5)
		{
			cout << num[hand[i]] << endl;
		}
	}
}

C++: // Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int t[5];
		cin >> t[0];

		if(t[0]==0)
			break;

		for(int i=1; i<5; i++){
			cin >> t[i];
		}

		int cnt[4] = {0};

		for(int i=0; i<5; i++){
			cnt[t[i]]++;
		}

		int r[5];
		if((cnt[2]==0&&cnt[3]==0)
		 ||(cnt[3]==0&&cnt[1]==0)
		 ||(cnt[1]==0&&cnt[2]==0)
		 ||(cnt[1]!=0&&cnt[2]!=0&&cnt[3]!=0)){
			for(int i=0; i<5; i++){
				r[i] = 3;
			}
		}
		else if(cnt[3]==0){
			for(int i=0; i<5; i++){
				if(t[i]==1){
					r[i] = 1;
				}
				else{
					r[i] = 2;
				}
			}
		}
		else if(cnt[1]==0){
			for(int i=0; i<5; i++){
				if(t[i]==2){
					r[i] = 1;
				}
				else{
					r[i] = 2;
				}
			}
		}
		else if(cnt[2]==0){
			for(int i=0; i<5; i++){
				if(t[i]==3){
					r[i] = 1;
				}
				else{
					r[i] = 2;
				}
			}
		}

		for(int i=0; i<5; i++){
			cout << r[i] << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	int y = 0;
	for (long u = 0; u < 200; u++)
	{
		int a[6],h1 = 0,h2 = 0,h3 = 0;

		for (int i = 0; i < 5; i++)
		{
			a[i] = 0;
		}
		for (int i = 0; i < 5; i++)
		{
			cin >> a[i];
			if (a[i] == 0)
			{
				y = -1;
				break;
			}
		}
		if (y == -1)
		{
			break;
		}

		for (int i = 0; i < 5; i++)
		{
			if (a[i] == 1)
			{
				h1 += 1;
			}
			else if (a[i] == 2)
			{
				h2 += 1;
			}
			else if (a[i] == 3)
			{
				h3 += 1;
			}
		}


		int ke = 0;
		if (h1 != 0 && h2 != 0)
		{
			if (h3 != 0)
			{
				ke += 1;
				for (int gg = 0; gg < 5; gg++)
				{
					cout << '3' << endl;
				}
			}
		}

		if (h1 == 0 && ke == 0)
		{
			for (int j = 0; j < 5; j++)
			{
				if (a[j] == 2)
				{
					cout << '1' << endl;
				}
				else
				{
					cout << '2' << endl;
				}
			}
		}
		else if (h2 == 0 && ke == 0)
		{
			for (int j = 0; j < 5; j++)
			{
				if (a[j] == 1)
				{
					cout << '2' << endl;
				}
				else
				{
					cout << '1' << endl;
				}
			}
		}
		else if (h3 == 0 && ke == 0)
		{
			for (int j = 0; j < 5; j++)
			{
				if (a[j] == 1)
				{
					cout << '1' << endl;
				}
				else
				{
					cout << '2' << endl;
				}
			}
		}
	}
}

C++: #include<stdio.h>

int main(void){
	int t[5]={0},i,R,P,S;

	while(0==0){
		
		R=P=S=0;

		scanf("%d",&t[0]);

		if(t[0]==0) break;
		else if(t[0]==1) R++;
		else if(t[0]==2) S++;
		else P++;
	    

		for(i=1;i<5;i++){
			scanf("%d",&t[i]);
			if(t[i]==1) R++;
		    else if(t[i]==2) S++;
	      	else P++;
		}

		if(R==0){
			if(P!=0 && S!=0)
				for(i=0;i<5;i++){
					if(t[i]==2) t[i]=1;
					else t[i]=2;
				}
		}
		else if(S==0){
			if(P!=0 && R!=0)
				for(i=0;i<5;i++){
					if(t[i]==3) t[i]=1;
					else t[i]=2;
				}
		}
		else if(P==0){
			if(S!=0 && R!=0)
				for(i=0;i<5;i++){
					if(t[i]==1) t[i]=1;
					else t[i]=2;
				}
		}
		
		else
			for(i=0;i<5;i++)
				t[i]=3;

		for(i=0;i<5;i++)
			printf("%d\n",t[i]);
	}

	return 0;
}

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

using namespace std;

int te[5],Dte[4];
int ans[5];

int main(void){
	int a;
	while(1){
		for(a=0;a<4;a++)Dte[a]=0;
		for(a=0;a<5;a++){
			cin >> te[a];
			Dte[te[a]]=1;
			if(te[a]==0)break;
		}
		if(te[0]==0)break;
		if(Dte[1]==1 && Dte[2]==1 && Dte[3]==1)for(a=0;a<5;a++)te[a]=3;
		else if(Dte[1]==1 && Dte[2]==1)for(a=0;a<5;a++)if(te[a]==1)te[a]=1;else if(te[a]==2)te[a]=2;
		else if(Dte[2]==1 && Dte[3]==1)for(a=0;a<5;a++)if(te[a]==2)te[a]=1;else if(te[a]==3)te[a]=2;
		else if(Dte[1]==1 && Dte[3]==1)for(a=0;a<5;a++)if(te[a]==3)te[a]=1;else if(te[a]==1)te[a]=2;
		for(a=0;a<5;a++){
			cout << te[a] <<endl;
		}
	}
	return 0;
}