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 <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){
    while(true){
        vector<int> te(3);
        vector<int> per(5);
        for(int i=0;i<5;i++){
            int x;
            cin >> x;
            x--;
            if(x == -1) return 0;
            te[x]++;
            per[i] = x;

        }
        if(*min_element(all(te)) > 0 or *max_element(all(te)) == 5){
            for(int i=0;i<5;i++){
                cout << 3 << endl;
            }
        }else{
            vector<char> win(5,false);
            if(te[0] > 0 and te[1] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 0) win[i] = true;
                }
            }
            else if(te[1] > 0 and te[2] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 1) win[i] = true;
                }
            }
            else if(te[2] > 0 and te[0] > 0){
                for(int i=0;i<5;i++){
                    if(per[i] == 2) win[i] = true;
                }
            }
            for(int i=0;i<5;i++){
                if(win[i]){
                    cout << 1 << endl;
                }else{
                    cout << 2 << endl;
                }
            }
        }
    }
    return 0;
}

C++: #include <cstdio>

main(){
	while(1){
		int h[5] = {0}, t[4] = {0}, w = 0;
		for(;w<5;w++){
			scanf("%d", h+w);t[h[w]]++;
			if(!*h)break;
		}
		if(!*h)break;

		if(t[1] && t[2] && t[3])
			w = -1;
		else if(t[1] && t[2])
			w = 1;
		else if(t[2] && t[3])
			w = 2;
		else if(t[1] && t[3])
			w = 3;
		else
			w = -1;
		for(int i=0;i<5;i++){
			if(w < 0)
				puts("3");
			else if(h[i] - w)
				puts("2");
			else
				puts("1");
		}
	}
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	vector<int> data;
	data.resize( 5 );

	while( cin >> data[0] && data[0] != 0 ){
		for( int i = 1;i < 5;i++ ) cin >> data[i];
		int rock = count( data.begin(), data.end(), 1 );
		int paper = count( data.begin(), data.end(), 3 );
		int scissors = count( data.begin(), data.end(), 2 );

		if( rock && paper && scissors ){
			for( int i = 0;i < 5;i++ ) cout << 3 << endl;
			continue;
		}

		if( rock == 0 ){
			for( unsigned int i = 0;i < data.size();i++ ){
				if( data[i] == 2 ) cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}

		if( paper == 0 ){
			for( unsigned int i = 0;i < data.size();i++ ){
				if( data[i] == 1 ) cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}

		if( scissors == 0 ){
			for( unsigned int i = 0;i < data.size();i++ ){
				if( data[i] == 3 ) cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    if(n == 0) break;
    set<int> s;
    vary(int,v,5,0);
    v[0] = n;
    s.insert(n);
    REP(i,1,5){
      cin >> v[i];
      s.insert(v[i]);
    }
    rep(i,5){
      if(s.size() != 2){
        cout << 3 << endl;
      }
      else{
        if((v[i] == 2 && *s.begin() == 1) || (v[i] == 3 && *s.begin() == 2) || (v[i] == 1 && (*(s.begin()) +1 )== 3)){
          cout << 2 << endl;
        }
        else cout << 1 << endl;
      }
    }
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

int main(){
	int gesture[5];
	while(~scanf("%d",&gesture)){
		if(gesture[0]==0) break;
		for(int i=0;i<4;i++){
			scanf("%d",gesture+i+1);
		}

		for(int i=0;i<5;i++){
			int bit,player;
			bit = player = (1 << (gesture[i]-1));

			for(int j=0;j<5;j++){
				if(i==j) continue;
				bit |= (1 << (gesture[j]-1));
			}

			if(bit == ((1<<3)-1)){
				printf("3\n");
			}

			else{
				bit &= ~player;
				if(player == 1 && bit == (1<<1)){
					printf("1\n");
				}
				else if(player == 1 && bit == (1<<2)){
					printf("2\n");
				}

				else if(player == (1<<1) && bit == 1){
					printf("2\n");
				}
				else if(player == (1<<1) && bit == (1<<2)){
					printf("1\n");
				}

				else if(player == (1<<2) && bit == 1){
					printf("1\n");
				}
				else if(player == (1<<2) && bit == (1<<1)){
					printf("2\n");
				}
			}
		}
		
	}

}