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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(vi a(5);cin>>a[0],a[0];){
		repi(i,1,5) cin>>a[i];
		int flg=0;
		rep(i,5)
			flg|=1<<a[i]-1;
		if(flg==7 || __builtin_popcount(flg)==1)
			rep(i,5) cout<<3<<endl;
		else if(flg==3)
			rep(i,5) cout<<(a[i]==1?1:2)<<endl;
		else if(flg==5)
			rep(i,5) cout<<(a[i]==4?1:2)<<endl;
		else if(flg==7)
			rep(i,5) cout<<(a[i]==2?1:2)<<endl;
	}
	
	return 0;
}

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

int main() {
	int i,j,k,d[5],f[3];
	while (cin >> d[0]) {
		f[0]=f[1]=f[2]=k=0;
		if (d[0]==0) break;
		f[d[0]-1]=1;
		for (i=1;i<5;i++) { cin >> d[i]; f[d[i]-1]=1;}
		if (f[0]==1 && f[1]==1 && f[2]==1) k=3;
		for (i=0;i<3;i++) if (f[i]==1 && f[(i+1) % 3]==1) break;
		for (j=0;j<5;j++) {
			if (k!=3) { if (d[j]==i+1) k=1; else k=2;}
			cout << k << endl;
		}
	} 
	return 0;
}

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

int main() {
    vector<int> v(5);
    while (cin >> v[0], v[0]) {
        bool g = false, c = false, p = false;
        for (int i = 1; i < 5; i++) cin >> v[i];

        for (auto i : v) {
            if (i == 1) g = true;
            if (i == 2) c = true;
            if (i == 3) p = true;
        }

        if ((g&&c&&p)||(g&&!c&&!p)||(!g&&c&&!p)||(!g&&!c&&p)) {
            for (int i = 0; i < 5; i++) cout << 3 << endl;
        } else if (g && c && !p) {
            for (auto i : v) {
                if (i == 1) cout << 1 << endl;
                else cout << 2 << endl;
            }
        } else if (g && !c && p) {
            for (auto i : v) {
                if (i == 3) cout << 1 << endl;
                else cout << 2 << endl;
            }
        } else if (!g && c && p) {
            for (auto i : v) {
                if (i == 2) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
    }

    return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int t;
	while(cin >> t && t)
	{
		vector<int> v;
		v.push_back(t);

		rep(i,4)
		{
			cin >> t;
			v.push_back(t);
		}
		
		map<int,int> m;
		rep(i,5)
		{
			m[v[i]]++;
		}

		if(m.size() >= 3 || m.size() == 1)
		{
			rep(i,5) cout << 3 << endl;
		}
		else
		{
			if(m[1] > 0 && m[2] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 1) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
			else if(m[2] > 0 && m[3] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 1) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
			else if(m[1] > 0 && m[3] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 1) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
		}
	}
	return 0;
}

C++: 

#include<iostream>
#include<vector>
using namespace std;

int main()
{
  vector<int> p(5), r(5);
  int i, t;
  while (cin>>p[0]>>p[1]>>p[2]>>p[3]>>p[4], p[0]) {
    t = 0;
    for (i = 0; i < 5; i++) {
      if (p[i] == 3 && !(t&4)) t ^= 4;
      else if (!(t&p[i])) t ^= p[i];
    }
    if (t == (1+2)) for (i = 0; i < 5; i++) if (p[i] == 1) r[i] = 1; else r[i] = 2;
    else if (t == (2+4)) for (i = 0; i < 5; i++) if (p[i] == 2) r[i] = 1; else r[i] = 2;
    else if (t == (4+1)) for (i = 0; i < 5; i++) if (p[i] == 3) r[i] = 1; else r[i] = 2;
    else for (i = 0; i < 5; i++) r[i] = 3;

    for (i = 0; i < 5; i++) cout<<r[i]<<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) 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");
				}
			}
		}
		
	}

}

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<<endl;
				}
				else{cout<<2<<endl;}
			}
		}
		else if(cc>0 && bb>0 && aa==0){
			for(int i=0;i<5;i++){
				if(a[i]==2){
					cout<<1<<endl;
				}
				else{cout<<2<<endl;}
			}
		}
		else if(cc>0 && aa>0 && bb==0){
			for(int i=0;i<5;i++){
				if(a[i]==3){
					cout<<1<<endl;
				}
				else{cout<<2<<endl;}
			}
		}
		else {
			for(int i=0;i<5;i++){
				cout<<3<<endl;
			}
		}
		aa=0;
		bb=0;
		cc=0;
		
		
	}
	// your code goes here
	return 0;
}