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<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  while(true){
    int people[5];
    int kind[3] = {0};

    REP(i,5){
      if((people[i] = getInt()) == 0) return 0;
      kind[people[i]-1]++;
    }

    bool aiko = false;

    if(kind[0] > 0 && kind[1] > 0 && kind[2] > 0)
      aiko = true;
    if(kind[0] == 5 || kind[1] == 5 || kind[2] == 5)
      aiko = true;

    if(aiko){
      REP(i,5) print(3);
    }else{
      int kati;
      if(kind[0] == 0) kati = 2;
      if(kind[1] == 0) kati = 3;
      if(kind[2] == 0) kati = 1;

      REP(i,5) if(people[i] == kati)
        print(1);
      else
        print(2);
    }
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]){
  int n[5];
  while(std::cin >> n[0], n[0]){
    n[0]--;
    for (int i = 0; i < 4; i++) {
      std::cin >> n[i + 1];
      n[i + 1]--;
    }
    bool used[3] = {}, draw = false;
    for (int i = 0; i < 5; i++) {
      used[n[i]] = true;
    }
    int win = -1;
    set<int> a;
    vector<int> ans;
    for (int i = 0; i < 5; i++) {
      a.insert(n[i]);
    }
    for (int i: a){
      ans.push_back(i);
    }
    if(ans.size() == 1 || ans.size() == 3){
      draw = true;
    }else if(ans[0] == 0 && ans[1] == 1){
      win = 0;
    }else if(ans[0] == 1 && ans[1] == 2){
      win = 1;
    }else if(ans[0] == 0 && ans[1] == 2){
      win = 2;
    }
    if(draw){
      for (int i = 0; i < 5; i++) {
        std::cout << 3 << std::endl;
      }
    }else{
      for (int i = 0; i < 5; i++) {
        if(win == n[i])std::cout << 1 << std::endl;
        else std::cout << 2 << std::endl;
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

VI _array( 5 ), _copy( 5 );
bool is_open[ 3 ];

int main() {
	while ( ~scanf( "%d", &_array[ 0 ] ) && _array[ 0 ] ) {
		memset( is_open, 0, sizeof( is_open ) );
		is_open[ _array[ 0 ] - 1 ] = true;
		for ( int i = 1; i < 5; i++ ) {
			scanf( "%d", &_array[ i ] );
			is_open[ _array[ i ] - 1 ] = true;
		}
		if ( ( is_open[ 0 ] && !is_open[ 1 ] && !is_open[ 2 ] ) || ( !is_open[ 0 ] && is_open[ 1 ] && !is_open[ 2 ] ) || ( !is_open[ 0 ] && !is_open[ 1 ] && is_open[ 2 ] ) || ( is_open[ 0 ] && is_open[ 1 ] && is_open[ 2 ] ) ) {
			for ( int i = 0; i < 5; i++ ) {
				printf( "3\n" );
			}
			continue;
		}
		for ( int i = 0; i < 5; i++ ) {
			if ( is_open[ ( _array[ i ] + 1 ) % 3 ] ) {
				printf( "2\n" );
			}
			else {
				printf( "1\n" );
			}
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int j[5];
  int jj,jk,jp;
  while(cin>>j[0]){
    if(j[0]==0) break;
    for(int i=1;i<5;i++) cin >> j[i];
    jj = 0;
    jk = 0;
    jp = 0;
    for(int i=0;i<5;i++){
      if(j[i]==1) jj++;
      else if(j[i]==2) jk++;
      else jp++;
    }
    if(jj!=0&&jk!=0&&jp!=0||jj==5||jk==5||jp==5){
      for(int i=0;i<5;i++) cout << 3 << endl;
    }
    else if(jj==0){
      for(int i=0;i<5;i++){
	if(j[i]==2) cout << 1 << endl;
	else cout << 2 << endl;
      }
    }
       else if(jk==0){
      for(int i=0;i<5;i++){
	if(j[i]==1) cout << 2 << endl;
	else cout << 1 << endl;
      }
    }
        else{
      for(int i=0;i<5;i++){
	if(j[i]==1) cout << 1 << endl;
	else cout << 2 << endl;
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    vector<int> h(5);
    while(cin >> h[0] && h[0])
    {
        REP(i, 1, 5) cin >> h[i];

        set<int> s;

        rep(i, 5) s.insert(h[i]);

        if(s.count(1) && s.count(2) && s.count(3))
        {
            rep(i, 5) cout << 3 << endl;
        }
        else if(!s.count(1))
        {
            rep(i, 5)
            {
                cout << (h[i] == 2 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(2))
        {
            rep(i, 5)
            {
                cout << (h[i] == 3 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(3))
        {
            rep(i, 5)
            {
                cout << (h[i] == 1 ? 1 : 2) << endl;
            }
        }
    }
    
    return 0;
}