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



void solve(vector<int>& a){
  int f[3]={};
  int s[]={0,1,3};
  int t[]={1,2,1};
  for(int i=0;i<a.size();i++){
    f[a[i]-1]=1;
  }
  if( (f[0]+f[1]+f[2])%2 == 1 )
    for(int i=0;i<5;i++) cout << "3\n";

  else
    for(int j=0;j<3;j++){
      if( f[s[j]]==1 && f[t[j]]==1 ){
	for(int i=0;i<5;i++){
	  if(a[i] == s[j]+1) cout << "1\n";
	  if(a[i] == t[j]+1) cout << "2\n";
	}
      }
    }
}

int main(){
  bool f=true;
  while(1){
    vector<int> x;
    for(int i=0;i<5;i++){
      int tmp;
      cin >> tmp;
      if(i==0 && tmp == 0){
	f=0;
	break;
      }
      x.push_back(tmp);
    }
    if(!f) break;
    solve(x);
  }
}

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
        {   rep(i, 5)
                cout << 3 << endl;
        }
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	while(1){
		std::vector<int> vec(5);
		std::vector<int> vec2(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;

void printResult(int win, int* array) {
    for (int i = 0; i < 5; i++) {
        if (array[i] == win) {
            cout << 1 << endl;
        } else {
            cout << 2 << endl;
        }
    }
}

int main() {
    while (true) {
        int hands[5];
        for (int i = 0; i < 5; i++) {
            cin >> hands[i];
            if (hands[i] == 3) {
                hands[i] = 4;
            }
        }
        if (hands[0] == 0) {
            break;
        }
        int result = hands[0] | hands[1] | hands[2] | hands[3] | hands[4];
        switch (result) {
        case 1: case 2: case 4: case 7:
            for (int i = 0; i < 5; i++) {
                cout << 3 << endl;
            }
            break;
        case 3:
            printResult(1, hands);
            break;
        case 6:
            printResult(2, hands);
            break;
        case 5:
            printResult(4, hands);
            break;
        }
    }
}

C++: #include<iostream>
#include<vector>
int main(){
	while(1){
		std::vector<int> vec(5);
		std::vector<int> vec2(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;
		}
		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()
{
	while (true){
		int a[5];
		int f[4] = { 0 };
		for (int i = 0; i < 5; i++){
			cin >> a[i];
			if (i == 0 && a[i] == 0){
				return 0;
			}
			f[a[i]]++;
		}
		if (f[1]>0 && f[2] > 0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				cout << "3" << endl;
			}
		}
		else if (f[1]>0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				if (a[i] == 1){
					cout << "2" << endl;
				}
				else{
					cout << "1" << endl;
				}
			}
		}
		else if (f[2]>0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				if (a[i] == 3){
					cout << "2" << endl;
				}
				else{
					cout << "1" << endl;
				}
			}
		}
		else{
			for (int i = 0; i < 5; i++){
				cout << a[i] << endl;
			}
		}
	}
}

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

int main() {
	int hn[5];
	int i,j,fl1=0,fl2=0,fl3=0;
	while(1){
		for(i=0;i<5;i++){
			cin >> hn[i];
			if(hn[i]==1) fl1=1;
			if(hn[i]==2) fl2=1;
			if(hn[i]==3) fl3=1;
		}
		if(hn[0]==0) break;
		if((fl1==1 && fl2==1) && fl3==0){
			for(j=0;j<5;j++){
				if(hn[j]==1) cout << "1" << endl;
				if(hn[j]==2) cout << "2" << endl;
			}
		}else if((fl1==1 && fl3==1) && fl2==0){
			for(j=0;j<5;j++){
				if(hn[j]==1) cout << "2" << endl;
				if(hn[j]==3) cout << "1" << endl;
			}
		}else if((fl3==1 && fl2==1) && fl1==0){
			for(j=0;j<5;j++){
				if(hn[j]==2) cout << "1" << endl;
				if(hn[j]==3) cout << "2" << endl;
			}
		}else{
			for(j=0;j<5;j++) cout << "3" << endl;
		}
		fl1=0;
		fl2=0;
		fl3=0;
	}
	return 0;
}

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

int calc(std::vector<int>&v){

	int cnt = 0;
	std::vector<int>::iterator g, t, p;

	g = std::find(v.begin(), v.end(), 1);
	t = std::find(v.begin(), v.end(), 2);
	p = std::find(v.begin(), v.end(), 3);

	if (g != v.end())cnt++;
	if (t != v.end())cnt++;
	if (p != v.end())cnt++;

	if (cnt == 1 || cnt == 3)return -1;
	else if (cnt == 2){
		if (g == v.end())return 2;
		if (t == v.end())return 3;
		if (p == v.end())return 1;
	}
	return -1;
}

int main(){

	std::vector<int>jan(5);
	while (std::cin >> jan[0], jan[0]){

		std::cin >> jan[1] >> jan[2] >> jan[3] >> jan[4];

		int res = calc(jan);

		if (res == -1){
			for (int i = 0; i < 5; i++){
				std::cout << 3 << std::endl;
			}
		}

		else{
			for (int i = 0; i < 5; i++){
				if (jan[i] == res)std::cout << 1 << std::endl;
				else std::cout << 2 << std::endl;
			}
		}

	}
	return 0;
}