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<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 <iostream>

int a[5];
bool f[3];
int res[5];

int main() {
	while (1) {
		std::cin >> a[0];
		if (!a[0])
			break;
		std::fill(f, f + 3, false);

		for (int i = 1; i < 5; ++i) {
			std::cin >> a[i];
			if (!f[a[i] - 1]) {
				switch (a[i]) {
				case 1:
					f[0] = true; break;
				case 2:
					f[1] = true; break;
				case 3:
					f[2] = true; break;
				}
			}
		}
		if (f[0] && f[1] && f[2])
			std::fill(res, res + 5, 3);

		else if ((f[0] && !f[1] && !f[2]) ||
			(f[1] && !f[0] && !f[2]) ||
			(f[2] && !f[0] && !f[1]))
			std::fill(res, res + 5, 3);

		else {
			for (int i = 0; i < 5; ++i) {
				if (f[0] && f[1])
					res[i] = (a[i] == 1) ? 1 : 2;
				else if (f[1] && f[2])
					res[i] = (a[i] == 2) ? 1 : 2;
				else if (f[0] && f[2])
					res[i] = (a[i] == 3) ? 1 : 2;
			}
		}
		for (int i = 0; i < 5; ++i)
			std::cout << res[i] << std::endl;
	}
	return 0;
}

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

int main() {
	int y;
	int a[5];
	while(cin>>y){
		if (y==0) break;
		a[0]=y;
		for(int i=1;i<5;i++) cin>>a[i];
		
//		for(int i=0;i<5;i++) cout<<a[i];
//		cout<<endl;
		
		int shu[4]={0};
		for(int i=0;i<5;i++) shu[a[i]]=1;
		int kazu=shu[1]+shu[2]+shu[3];
		
		if(kazu==3 || kazu==1){
			for (int i=0;i<5;i++) cout<<"3"<<endl;
		}
		else if(shu[1]==0){
	//		cout<<"aiko1"<<endl;
			for (int i=0;i<5;i++){
				if(a[i]==2) cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}
		else if(shu[2]==0){
	//		cout<<"aiko2"<<endl;
			for (int i=0;i<5;i++){
				if(a[i]==3) cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}
		else if(shu[3]==0){
	//		cout<<"aiko3"<<endl;
			for (int i=0;i<5;i++){
				if(a[i]==1) cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}
		
		a[0]=0;
	}


}

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

int main(){
	int hand[5];
	int result[5];
	int r, s, p;
	bool rock, scissors, paper;
	
	
	for(;;){
		rock = scissors = paper = false;
		r = p = s = 0;
		for(int i = 0; i < 5; i++){
			cin >> hand[i];
			if(hand[i] == 0) return 0;
		}
		
		for(int i = 0; i < 5; i++){
			if(hand[i] == 1){
				rock = true;
			}else if(hand[i] == 2){
				scissors = true;
			}else if(hand[i] == 3){
				paper = true;
			}
			
			// あいこではない場合
			
		}
		
		if(rock == true && paper == true){
			r = 2;
			p = 1;
		}else if(rock == true && scissors == true){
			r = 1;
			s = 2;
		}else if(paper = true && scissors == true){
			p = 2;
			s = 1;
		}

		
		if(rock == true && paper == true && scissors == true){ // グーチョキパーすべてが場に出ている場合あいこ
			r = p = s = 3;
		}
		
		for(int i = 0; i < 5; i++){
			if(hand[i] == 1){
				result[i] = r;
			}else if(hand[i] == 2){
				result[i] = s;
			}else if(hand[i] == 3){
				result[i] = p;
				
			}
		}	
		
		for(int i = 0; i < 5; i++){
			cout << result[i] << endl;
		}
	}
	
	return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int a[5];
	int i;
	int g,t,p;
	
	for(;;)
	{
		
		g=t=p=0;
		
		for(i=0;i<5;i++)
		{
			cin >> a[i] ;
			if(a[0]==0)
				break;
			if(a[i]==1)
				g=1;
			if(a[i]==2)
				t=1;
			if(a[i]==3)
				p=1;
		}
		if(a[0]==0)
			break;
		
		
		if(g==1 && t==1 && p==1 || g+t+p==1)
		{
			for(i=0;i<5;i++)
			 cout << "3" << endl;
		}
		else if(g==1 && t==1)
		{
			for(i=0;i<5;i++)
			{
					cout << a[i] << endl;
			}
		}
		else if(t==1 && p==1)
		{
			for(i=0;i<5;i++)
			{
				if(a[i]==2)
					cout << "1" << endl;
				else
					cout << "2" << endl;
			}
		}
		else if(g==1 && p==1)
		{
			for(i=0;i<5;i++)
			{
				if(a[i]==1)
					cout << "2" << endl;
				else
					cout << "1" << endl;
			}
		}
	}
}

C++: #include <iostream>
using namespace std;
int array[5];
int ret[4];
void p(int a,int b,int c){

  for(int i = 0 ; i < 5 ; i++){
    if(array[i] == a)cout << 1 << endl;
    else if(array[i] == b)cout << 2 << endl;
    else cout << 3 << endl;
  }
}
int main(){

  while(cin >> array[0] ,array[0]){
    fill(ret,ret + 4,0);
    ret[array[0]] = 1;
    for(int i = 1 ; i < 5 ; i++ ){
      cin >> array[i];
      ret[array[i]] = 1;
  }
    if(ret[1] != 0 && ret[2] != 0 && ret[3] == 0){
      p(1,2,3);
    }else if(ret[2] != 0 && ret[3] != 0 && ret[1] == 0){
      p(2,3,1);
    }else if(ret[1] != 0 && ret[3] != 0 && ret[2] == 0){
      p(3,1,2);
    }else p(4,4,4);
  }
}

C++: #include<stdio.h>
bool f[3];
int t[5];
int i,j;
int w,l;

int main(){
	while(1){
		for(i=0;i<3;i++)f[i]=false;
		for(i=0;i<5;i++){
			scanf("%d",&t[i]);
			if(t[i]==0)return 0;
		}
		for(i=0;i<5;i++)f[t[i]-1]=true;
		if(f[0]&&f[1]&&f[2]){w=-1;l=-1;}
		else if(f[0]&&f[1]){w=1;l=2;}
		else if(f[0]&&f[2]){w=3;l=1;}
		else if(f[1]&&f[2]){w=2;l=3;}
		for(i=0;i<5;i++){
			if(t[i]==w)printf("1\n");
			else if(t[i]==l)printf("2\n");
			else printf("3\n");
		}
	}
}