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 <algorithm>
using namespace std;

int main() {
	int a[5],b[]={1,2,3},aa=0,bb=0,cc=0;
	while(1){
		cin>>a[0];
		if(a[0]==0){
			break;
		}
		for(int i=1;i<5;i++){
			cin>>a[i];
		}
		
		for(int j=0;j<5;j++){
			if(b[0]==a[j]){
				aa++;
			}
			else if(b[1]==a[j]){
				bb++;
			}
			else if(b[2]==a[j]){
				cc++;
			}
		}
		
		if(aa>0 && bb>0 && cc==0){
			for(int i=0;i<5;i++){
				if(a[i]==1){
					cout<<1;
				}
				else{cout<<2;}
			}
		}
		else if(cc>0 && bb>0 && aa==0){
			for(int i=0;i<5;i++){
				if(a[i]==2){
					cout<<1;
				}
				else{cout<<2;}
			}
		}
		else if(cc>0 && aa>0 && bb==0){
			for(int i=0;i<5;i++){
				if(a[i]==3){
					cout<<1;
				}
				else{cout<<2;}
			}
		}
		else {
			for(int i=0;i<5;i++){
				cout<<3;
			}
		}
		aa=0;
		bb=0;
		cc=0;
		
		
	}
	// your code goes here
	return 0;
}

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

int main(){
	int human[5];
	while(cin>>human[0],human[0]){
		bool hand[3]={0,0,0};
		for(int i=1;i<5;i++){
			cin>>human[i];
			if(human[i]==1) hand[0]++;
			else if(human[i]==2) hand[1]++;
			else hand[2]++;
		}
		if((hand[0]==true&&hand[0]==hand[1]&&hand[0]==hand[2])||(hand[0]==false&&hand[0]==hand[1])||(hand[0]==false&&hand[0]==hand[2])||(hand[1]==false&&hand[1]==hand[2])){
			for(int i=0;i<5;i++)cout<<'3'<<endl;
		}
		else if(hand[0]==true&&hand[0]==hand[1]){
			for(int i=0;i<5;i++){
				if(human[i]==1)cout<<'1'<<endl;
				else cout<<'2'<<endl;
			}
		}
		else if(hand[0]==true&&hand[0]==hand[2]){
			for(int i=0;i<5;i++){
				if(human[i]==3)cout<<'1'<<endl;
				else cout<<'2'<<endl;
			}
		}
		else if(hand[1]==true&&hand[1]==hand[2]){
			for(int i=0;i<5;i++){
				if(human[i]==2)cout<<'1'<<endl;
				else cout<<'2'<<endl;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	while(1){
		std::vector<int> vec(5);
		int a;
		std::cin>>a;
		if(a==0)break;
		vec[0]=a;
		int d,e,f;
		if(a==1)d++;
		if(a==2)e++;
		if(a==3)f++;
		for(int i=1;i<5;i++){
			int b;
			if(b==1)d++;
			if(b==2)e++;
			if(b==3)f++;
			std::cin>>b;
		}
		std::vector<int> vec2(5);
		if(d>=1&&e>=1&&f>=1||d==5||f==5||e==5){
			for(int i=0;i<5;i++){
				vec2[i]=3;
			}
		}else if(d>=1&&e>=1&&f==0){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=1;
				if(vec[i]==2)vec2[i]=2;
			}
		}else if(d>=0&&e>=1&&f==1){
			for(int i=0;i<5;i++){
				if(vec[i]==2)vec2[i]=1;
				if(vec[i]==3)vec2[i]=2;
			}
		}else if(d>=1&&e>=0&&f==1){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=2;
				if(vec[i]==3)vec2[i]=1;
			}
		}
		for(int i=0;i<5;i++){
			std::cout<<vec2[i]<<std::endl;
		}
	}
	return 0;
}

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

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

C++: #include <iostream>

#define NMAX (5)

using namespace std;

int hand[NMAX];

int main() {
	int result;
	for(int i; cin >> i && i!= 0;) {
		hand[0] = i;
		cin >> hand[1] >> hand[2] >> hand[3] >> hand[4];
		result = 0;
		for(int j=0; j<5; j++) {
			switch(hand[j]) {
			case 1:
				result |= 1;
				break;
			case 2:
				result |= 2;
				break;
			case 3:
				result |= 4;
			}
		}
		int typenum = 0;
		for(int res = result; res; res >>= 1)
			typenum++;
		
		switch(typenum) {
		case 1:
		case 3:
			for(int k=0; k<5; k++)
				cout << 3 << endl;
			break;
		case 2:
			if(result & 1) {
				for(int k=0; k<5; k++)
					if(hand[k] == 2)
						cout << 1 << endl;
					else
						cout << 2 << endl;				
			}else if(result & 2) {
				for(int k=0; k<5; k++)
					if(hand[k] == 3)
						cout << 1 << endl;
					else
						cout << 2 << endl;								
			}else{
				for(int k=0; k<5; k++)
					if(hand[k] == 1)
						cout << 1 << endl;
					else
						cout << 2 << endl;								
			}
			break;
		default:
			cerr << "err" << endl;
		}
	}	
	return 0;
}

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

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

C++: #include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int c[5];
int count_gu;
int count_tyo;
int count_paa;
#define GU 1
#define TYO 2
#define PAA 3

#define WIN 1
#define LOSE 2
#define AIKO 3

void cd(int x) {
  if (x == GU)  count_gu++;
  if (x == TYO) count_tyo++;
  if (x == PAA) count_paa++;
}

void count() {
  count_gu = 0;
  count_tyo = 0;
  count_paa = 0;
  for (int i=0; i<4; i++) {
    cd(c[i]);
  }
}


int main() {
  while (true) {
    cin >> c[0];
    if (c[0] == 0) break;
    cin >> c[1] >> c[2] >> c[3] >> c[4];
    int a[5]; // answer
    count();
    // kati/make
    if (count_gu == 0 || count_tyo == 0 || count_paa == 0) {
      // tyo -> win / paa -> lose
      if (count_gu == 0) {
        rep(i, 5) {
          if (c[i] == TYO) a[i] = WIN;
          else             a[i] = LOSE;
        }
      }
      // tyo -> lose / gu -> win
      if (count_paa == 0) {
        rep(i, 5) {
          if (c[i] == GU) a[i] = WIN;
          else            a[i] = LOSE;
        }
      }
      // paa -> win / gu -> lose
      if (count_tyo == 0) {
        rep(i, 5) {
          if (c[i] == PAA) a[i] = WIN;
          else             a[i] = LOSE;
        }
      }
    }
    // aiko
    else {
      rep(i, 5) a[i] = AIKO;
    }

    rep(i, 5) cout << a[i] << endl;
  }
  return 0;
}