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 "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

void sit(vector<int>&seats, int who) {
	if (who == 1) {
		for (int i = 0; i < seats.size(); ++i) {
			if (!seats[i]) {
				seats[i] = who;
				return;
			}
		}
	}
	else if (who == 2) {
		for (int i = seats.size()-1; i >= 0; --i) {
			if (!seats[i]) {
				bool ok = true;
				for (int k = i+1; k >= i-1; k -= 2) {
					if (k >= 0 && k < seats.size()) {
						if (seats[k] == 1)ok = false;
					}
				}
				if (ok) {
					seats[i] = who;
					return;
				}
			}
		}
		for (int i = 0; i < seats.size(); ++i) {
			if (!seats[i]) {
				seats[i] = who;
				return;
			}
		}
	}
	else if (who == 3) {
		for (int i = 0; i < seats.size(); ++i) {
			if (seats[i]) {
				if (i!=seats.size()-1&&!seats[i+1]) {
					seats[i+1] = who;
					return;
				}
				else if (i != 0 && !seats[i - 1]) {
					seats[i - 1] = who;
					return;
				}
			}
		}
		seats[seats.size() / 2] = who;
		return;
	}
	else {
		vector<int>diss(seats.size(), 1000);
		for (int i = 0; i < seats.size(); ++i) {
			if (seats[i]) {
				diss[i] = 0;
				for (int j = i - 1; j >= 0; --j) {
					diss[j] = min(diss[j], i-j);
				}
				for (int j = i + 1; j < seats.size(); ++j) {
					diss[j] = min(diss[j], j - i);
				}
			}
		}
		int maxdis = -1;
		int ans = -1;
		for (int i = 0; i < seats.size(); ++i) {
			if (maxdis < diss[i]) {
				maxdis = diss[i];
				ans = i;
			}
		}
		seats[ans] = who;
		return;
	}
	assert(false);
}

int main() {
	while (1) {
		vector<int>nums(3);
		vector<int>hs(5);
		for (int i = 0; i < 5; ++i) {
			int h; cin >> h;
			if (!i&&!h)return 0;
			h--; nums[h]++;
			hs[i] = h;
		}
		if (nums[0] == 5 || nums[1] == 5 || nums[2] == 5 || (nums[0] && nums[1] && nums[2])) {
			for (int i = 0; i < 5; ++i) {
				cout << 3 << endl;
			}
		}
		else {
			for (int j = 0; j < 3; ++j) {
				if (nums[j] && nums[(j + 1) % 3]) {
					for (int k = 0; k < 5; ++k) {
						if (hs[k] == j) {
							cout << 1 << endl;
						}
						else {
							cout << 2 << endl;
						}
					}
				}
			}
		}
	}
	return 0;
}

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

int main(){
	int a,b,c,d,e;
	while(cin >> a >> b >> c >> d >> e && a ){
		a--,b--,c--,d--,e--;
		set<int> v;
		v.insert(a);
		v.insert(b);
		v.insert(c);
		v.insert(d);
		v.insert(e);
		if( v.size() == 3 || v.size() == 1){
			for(int i = 0 ; i < 5 ; i++)
			 cout << 3 << endl;
		}else{
			set<int>::iterator it = v.begin();
			set<int>::iterator it2 = it;
			it++;
			int W[3] = {};
			if( (*it2) == ((*it)+1)%3 ){
				W[*it] = 1;
				W[*it2] = 2;
			}else{
				W[*it] = 2;
				W[*it2] = 1;
			}
			cout << W[a] << endl;
			cout << W[b] << endl;
			cout << W[c] << endl;
			cout << W[d] << endl;
			cout << W[e] << endl;
		}
	}
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

vi a(5);

int main(){
	while(1){
		cin>>a[0];
		if(!a[0]) break;
		a[0]--;
		for(int i=1;i<5;i++){
			cin>>a[i];
			a[i]--;
		}
		vb tmp(3);
		for(int i=0;i<5;i++) tmp[a[i]]=1;
		int num=0;
		for(int i=0;i<3;i++){
			if(tmp[i]) num++;
		}
		if(num==1||num==3){
			for(int i=0;i<5;i++) cout<<3<<endl;
		}
		else{
			int w,l;
			if(tmp[0]&&tmp[1]) w=0;
			if(tmp[1]&&tmp[2]) w=1;
			if(tmp[2]&&tmp[0]) w=2;
			for(int i=0;i<5;i++){
				if(a[i]==w) cout<<1<<endl;
				else cout<<2<<endl;
			}
		}
	}
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vii;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

 



int main(){
	int v[5];
	while(1){
		rep(i,5) cin>>v[i];
		if(cin.eof()) break;
		vi a(3,0);
		bool f=true;
		for(int i=0; i<5; i++){
			a[v[i]-1]++;
		}
		if(a[0]>0&&a[1]>0&&a[2]>0)f=false;
		for(int i=0; i<3; i++){
			if(a[i]==0&&a[(i+1)%3]==0){
				f=false;
				// rep(j,5){
				// 	cout<<"3"<<endl;
				// }
				break;
			}
		}
		if(f){
			int k;
			for(int i=0; i<3; i++){
				if(a[i]==0){
					k=i+1;
					break;
				}
			}
			for(int i=0; i<5; i++){
				cout<<(v[i]==k%3+1?1:2)<<endl;
			}
		}
		else{
			rep(i,5){
				cout<<3<<endl;
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int h[5];
  while(cin>>h[0],h[0]){
    cin>>h[1]>>h[2]>>h[3]>>h[4];
    for(int i=0;i<5;i++){
      bool f1=0,f2=0;
      for(int j=0;j<5;j++){
	if(i==j) continue;
	if(h[i]==1){
	  f1|=h[j]==2;
	  f2|=h[j]==3;
	}
	if(h[i]==2){
	  f1|=h[j]==3;
	  f2|=h[j]==1;
	}
	if(h[i]==3){
	  f1|=h[j]==1;
	  f2|=h[j]==2;
	}
      }
      cout<<(f1|f2?f1+f2*2:3)<<endl;
    }
  }
  return 0;
}

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

int main() {
	const int n = 5;
	int hand[n];
	while(cin >> hand[0], hand[0]) {
		int ans[5];
		bool flag[4] = {false};
		for(int i = 1; i < n; ++i) {
			cin >> hand[i];
			flag[hand[i]] = true;
		}
		for(int i = 0; i < n; ++i) {
			if(flag[1] && flag[2] && !flag[3]) ans[i] = (hand[i] == 1) ? 1 : 2;
			else if(!flag[1] && flag[2] && flag[3]) ans[i] = (hand[i] == 2) ? 1 : 2;
			else if(flag[1] && !flag[2] && flag[3]) ans[i] = (hand[i] == 3) ? 1 : 2;
			else ans[i] = 3;
			cout << ans[i] << endl;
		}
	}
}