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 <cstring>

using namespace std;

int judge(int a, int b) { // aがbにかつかどうか
    if (a == 1) {
        if (b == 1) return 3;
        if (b == 2) return 1;
        if (b == 3) return 2;
    } 
    if (a == 2) {
        if (b == 1) return 2;
        if (b == 2) return 3;
        if (b == 3) return 1;
    } 
    if (a == 3) {
        if (b == 1) return 1;
        if (b == 2) return 2;
        if (b == 3) return 3;
    }
}


void result(int *h) {
    // 3つ同じ手
    if (h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4]) {
        for (int i = 0; i < 5; i++) h[i] = 3;
        return;
    }

    // 3つ違う手
    bool hand_used[3+1];
    memset(hand_used, 0, sizeof(hand_used));
    for (int i = 0; i < 5; i++) {
        hand_used[h[i]] = true;
    }
    if (hand_used[1] && hand_used[2] && hand_used[3]) {
        for (int i = 0; i < 5; i++) h[i] = 3;
        return;
    }

    if (hand_used[1] && hand_used[2]) {
        for (int i = 0; i < 5; i++) {
            if (h[i] == 1) h[i] = judge(1, 2);
            if (h[i] == 2) h[i] = judge(2, 1);
        }
        return;
    }
    if (hand_used[2] && hand_used[3]) {
        for (int i = 0; i < 5; i++) {
            if (h[i] == 2) h[i] = judge(2, 3);
            if (h[i] == 3) h[i] = judge(3, 2);
        }
        return;
    }
    if (hand_used[3] && hand_used[1]) {
        for (int i = 0; i < 5; i++) {
            if (h[i] == 3) h[i] = judge(3, 1);
            if (h[i] == 1) h[i] = judge(1, 3);
        }
        return;
    }
}



int main() {
    int h[5];
    while (cin >> h[0], h[0] != 0) {
        for (int i = 1; i < 5; i++) {
            cin >> h[i];
        }
        result(h);
        for (int i = 0; i < 5; i++) {
            cout << h[i] << endl;
        }
    }
    return 0;
}

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

int main() {
	int hand[5];
	while(cin >> hand[0], hand[0]) {
		for(int i = 1; i < 5; i++)
			cin >> hand[i];

		int win[5] = {-1,-1,-1,-1,-1};
		bool flg = true;
		for(int i = 0; i < 5; i++) {
			for(int j = 0; j < 5; j++) {
				if(i != j) {
					int tmp = (hand[j] - hand[i] + 3) % 3;
					if(win[i] == -1 && tmp != 0)
						win[i] = tmp;
					else if(win[i] != tmp && tmp != 0)
						flg = false;
				}
			}
		}

		if(flg) {
			for(int i = 0; i < 5; i++)
				cout << ((win[i] == 0 || win[i] == -1)? 3 : win[i]) << endl;
		}
		else {
			for(int i = 0; i < 5; i++)
				cout << 3 << endl;
		}
	}
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int main()
{
	int a[5];
	while(1)
	{
		int t[4]={0};
		for(int i=0;i<5;i++)
		{
			cin >> a[i];
			if(a[i]==0)goto end;
			t[a[i]]++;
		}
		int cnt=0;
		for(int i=1;i<=3;i++)if(t[i]==0)cnt++;
		if(cnt==0||cnt==2)
		{
			for(int i=0;i<5;i++)cout << 3 << endl;
		}
		else
		{
			if(t[2]==0)
			{
				for(int i=0;i<5;i++)
				{
					if(a[i]==3)cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
			else
			{
				int win=100;
				for(int i=1;i<=3;i++)
				{
					if(t[i]==0)continue;
					else win=min(win,i);
				}
				for(int i=0;i<5;i++)
				{
					if(a[i]==win)cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
		}
	}
	end:;
	return 0;
}

C++: #include <iostream>

using namespace std;

void solve()
{
	int hand[5];
	while(cin >> hand[0], hand[0])
	{
		for(int i = 1; i < 5; ++i)
		{
			cin >> hand[i];
		}
		int rockCount = 0;
		int paperCount = 0;
		int scissorsCount = 0;
		for(int i = 0; i < 5; ++i)
		{
			if(hand[i] == 1)
			{
				++rockCount;
			}
			else if(hand[i] == 2)
			{
				++scissorsCount;
			}
			else
			{
				++paperCount;
			}
		}
		if((rockCount && scissorsCount && paperCount)
			|| (rockCount == 0 && scissorsCount == 0) 
			|| (scissorsCount == 0 && paperCount == 0) 
			|| (paperCount == 0 && rockCount == 0))
		{
			for(int i = 0; i < 5; ++i)
			{
				cout << "3" << endl;
			}
		}
		else if(rockCount == 0)
		{
			for(int i = 0; i < 5; ++i)
			{
				if(hand[i] == 2)
				{
					cout << "1" << endl;
				}
				else
				{
					cout << "2" << endl;
				}
			}
		}
		else if(scissorsCount == 0)
		{
			for(int i = 0; i < 5; ++i)
			{
				if(hand[i] == 3)
				{
					cout << "1" << endl;
				}
				else
				{
					cout << "2" << endl;
				}
			}
		}
		else if(paperCount == 0)
		{
			for(int i = 0; i < 5; ++i)
			{
				if(hand[i] == 1)
				{
					cout << "1" << endl;
				}
				else
				{
					cout << "2" << endl;
				}
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

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;

void cd(int x) {
  if (x == 1) count_gu++;
  if (x == 2) count_tyo++;
  if (x == 3) count_paa++;
}

void count() {
  count_gu = 0;
  count_tyo = 0;
  count_paa = 0;
  for (int i=0; i<4; i++) {
    cd(c[i]);
  }
}
#define GU 1
#define TYO 2
#define PAA 3

#define WIN 1
#define LOSE 2
#define AIKO 3


int main() {
  while (true) {
    cin >> c[0];
    if (c[0] == 0) break;
    cin >> c[1] >> c[2] >> c[3] >> c[4];
    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) {
            println(WIN);
          }
          else println(LOSE);
        }
      }
      // tyo -> lose / gu -> win
      if (count_paa == 0) {
        rep(i, 5) {
          if (c[i] == GU) {
            println(WIN);
          }
          else println(LOSE);
        }
      }
      // paa -> win / gu -> lose
      if (count_tyo == 0) {
        rep(i, 5) {
          if (c[i] == PAA) {
            println(WIN);
          }
          else println(LOSE);
        }
      }
    }
    // aiko
    else {
      for (int i=0; i<5; i++) cout << 3 << '\n';
    }
  }
  return 0;
}