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 <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] == 2) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
			else if(m[1] > 0 && m[3] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 3) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
		}
	}
	return 0;
}

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

using namespace std;

bool win(int a, int b)
{

  return ((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1));     
}
int main()
{
  while (true) {
    int a[5];
    for (int i = 0; i < 5; i++) {
      if (scanf("%d ", a + i) != 1) {return 0;}
      //printf("%d\n", a[i]);
    }
  
  
    bool f[] = {false, false, false};
    bool flag = false;
    f[a[0] - 1] = true;
    for (int i = 1; i < 5; i++) {
      if (a[i] != a[i - 1]) {
	flag = false;
      }
      f[a[i] - 1] = true;
    }
    bool aiko = false;
    if (flag) {
      aiko = true;
    } 
    for (int i = 0; i < 3; i++) {
      if (!f[i]) {goto next;}
    }
    aiko = true;
  next:;
    /*for (int i = 0; i < 5; i++) {
      printf("%d\n", a[i]);
      }*/
    for (int i = 0; i < 5; i++) {
      if (aiko) {printf("3\n");}
      else {
	for (int j = 0; j < 5; j++) {
	  if (i == j) {continue;}
	  if (a[i] == a[j]) {continue;}
	  if (win(a[i], a[j])) {
	    printf("1\n");
	    break;
	  } else if (win(a[j], a[i])) {
	    printf("2\n");
	    break;
	  }
	}
      }
    }
  }
}

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

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

int main(){
   int X[5];

   while(1){
	int con1=0,con2=0,con3=0;
	
	cin >> X[0];
	if(X[0] == 0) break;

	for(int i=1;i<5;i++){
		cin >> X[i];
	}

	for(int i=0;i<5;i++){
		if(X[i] == 1) con1++;
		if(X[i] == 2) con2++;
		if(X[i] == 3) con3++;
	}

	if(((con1 != 0)&&(con2 != 0)&&(con3 != 0))||((con1 == 0)&&(con2 == 0))||((con2 == 0)&&(con3 == 0))||((con1 == 0)&&(con3 == 0))||){
		for(int i=0; i<5; i++){
			cout << "3" << "\n";
		}

	}else if(con1 == 0){
		for(int i=0; i<5; i++){
			if(X[i] == 2) {
				cout << "1";
			}else{
				cout << "2";
			}

			cout << endl;
		}
	}else if(con2 == 0){
		for(int i=0; i<5; i++){
			if(X[i] == 3) {
				cout << "1";
			}else{
				cout << "2";
			}

			cout << endl;
		}
	}else if(con3 == 0){
		for(int i=0; i<5; i++){
			if(X[i] == 1) {
				cout << "1";
			}else{
				cout << "2";
			}

			cout << endl;
		}
	}
   }

   return 0;
}

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

int main(){

  int h[5];
  int f[4];

  while(1){
    for(int i=0;i<4;i++) f[i]=0;
    for(int i=0;i<5;i++){
      cin>>h[i];
      if(h[i]==0) break;
      f[h[i]]=1;
    }
    if(h[0]==0) break;

    int x[2], cnt=0;
    for(int i=1;i<4;i++){
      if(f[i]==1)
	x[cnt++]=i;
      //cout<<i<<" "<<f[i]<<endl;
    }
    //cout<<"    "<<cnt<<" "<<x<<endl;
    if(cnt==2){
      if(x[0]==1&&x[1]==2){
	for(int i=0;i<5;i++){
	  if(h[i]==1) cout<<1<<endl;
	  else cout<<2<<endl;
	}
      }
      if(x[0]==1&&x[1]==3){
	for(int i=0;i<5;i++){
	  if(h[i]==1) cout<<2<<endl;
	  else cout<<1<<endl;
	}
      }
      if(x[0]==2&&x[1]==3){
	for(int i=0;i<5;i++){
	  if(h[i]==2) cout<<1<<endl;
	  else cout<<2<<endl;
	}
      }
    }else{
      for(int i=0;i<5;i++) cout<<3<<endl;
    }
  }
  
  return 0;
}

C++: #include <cstdio>
#include <vector>

using namespace std;

vector<int> hand;

int main(){
	int self;
	while(1){
		hand.clear();
		scanf("%d",&self);
		if(self == 0){break;}
		hand.push_back(self);
		for(int i = 1;i < 5;i++){
			scanf("%d",&self);
			hand.push_back(self);
		
		}
		bool flag[4];
		flag[0] = false;
		flag[1] = false;
		flag[2] = false;
		flag[3] = false;
		vector<int>::iterator it;
		for(it = hand.begin();it < hand.end(); it++){
			flag[*it] = true;
		}
		int re[4];
		if( (flag[1] && flag[2] && flag[3]) || (flag[1] && !flag[2] && !flag[3]) || (!flag[1] && flag[2] && !flag[3]) || (!flag[1] && !flag[2] && flag[3]) ){
			re[1] = 3; // O[
			re[2] = 3; // `L
			re[3] = 3; // p[
		}
		if(flag[1] && flag[2] && !flag[3]){
			re[1] = 1; // O[
			re[2] = 2; // `L
			re[3] = 0; // p[
		}
		if(flag[1] && !flag[2] && flag[3]){
			re[1] = 2; // O[
			re[2] = 0; // `L
			re[3] = 1; // p[
		}
		if(!flag[1] && flag[2] && flag[3]){
			re[1] = 0; // O[
			re[2] = 1; // `L
			re[3] = 0; // p[
		}
		for(it = hand.begin();it < hand.end(); it++){
			printf("%d\n",re[*it]);
		}
	}
	return 0;
}