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 <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    int A[5], B[5];
    while ( cin >> A[0] && A[0] ) {
        int state = 0;
        for ( int i = 1; i < 5; ++ i ) {
            cin >> A[i];
            state |= 1 << A[i];
        }
        if ( state == ( 1 << 1 | 1 << 2 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 1 ? 1 : 2;
            }
        } else if ( state == ( 1 << 2 | 1 << 3 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 2 ? 1 : 2;
            }
        } else if ( state == ( 1 << 3 | 1 << 1 ) ) {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = A[i] == 3 ? 1 : 2;
            }
        } else {
            for ( int i = 0; i < 5; ++ i ) {
                B[i] = 3;
            }
        }
        for ( int i = 0; i < 5; ++ i ) {
            cout << B[i] << endl;
        }
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){

  int data[5], d[3];

  while(1){

    for(int i = 0; i < 3; i++) d[i] = 0;


    for(int i = 0; i < 5; i++){
      cin >> data[i];
      if(data[0] == 0) return 0;
      if(data[i] == 1) d[0]++;
      else if(data[i] == 2) d[1]++;
      else d[2]++;
    }

      if(d[0] > 0 && d[1] > 0 && d[2] > 0 || d[0] == 5 || d[1] == 5 || d[2] == 5){
	for(int j = 0; j < 5; j++) cout << "3" << endl;
      }else if(d[0] == 0){
	for(int j = 0; j < 5; j++){
	  if(data[j] == 2) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }else if(d[1] == 0){
	for(int j = 0; j < 5; j++){
	  if(data[j] == 3) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }else{
	for(int j = 0; j < 5; j++){
	  if(data[j] == 1) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }
  }
}

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

using namespace std;

int main(){
    vector<int> h(5,0),frg(5,0);

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

        if(frg[0]*frg[1]*frg[2]!=0 || frg[0]==5 || frg[1]==5 || frg[2]==5){
            for(int i=0;i<5;i++)cout << "3" << endl;
        }else if(frg[0]>0){
            if(frg[1]>0){
                for(int i=0;i<5;i++){
                    if(h[i]==1)cout << "1" << endl;
                    else cout << "2" << endl;
                }
            }else{
                for(int i=0;i<5;i++){
                    if(h[i]==3)cout << "1" <<endl;
                    else cout << "2" << endl;
                }
            }
        }else{
            for(int i=0;i<5;i++){
                if(h[i]==2)cout << "1" << endl;
                else cout << "2" << endl;
            }
        }

        for(int i=0;i<5;i++){
            frg[i]=0;
            h[i]=0;
        }
    }


    return 0;


}

C++: #include "iostream"
using namespace std;

int LinearSearch(int x, int S[], int N) {
	S[N] = x;
	for (int i = 0; ; i++) {
		if (S[i] == x)
			if (i < N) {
				return 1;
			}
			else
				return 0;
	}
}

int main()
{
	int h[6] = { 1 };
	int w;
	while (1) {
		for (int i = 0; i < 5; i++) {
			cin >> h[i];
			if (h[i] == 0)
				break;
		}
		if (LinearSearch(0, h, 5))
			break;
		if (LinearSearch(1, h, 5))
			if (LinearSearch(2, h, 5)) {
				if (LinearSearch(3, h, 5))
					w = 4;
				else
					w = 1;
			}
			else {
				if (LinearSearch(3, h, 5))
					w = 3;
				else w = 4;
			}
		else if (LinearSearch(2, h, 5)) {
			if (LinearSearch(3, h, 5))
				w = 2;
			else
				w = 4;
		}
		else
			w = 4;
		for (int i = 0; i < 5; i++) {
			if (w == 4)
				cout << 3 << endl;
			if (w == 1)
				if (h[i] == 1)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			if (w == 2)
				if (h[i] == 2)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			if (w == 3)
				if (h[i] == 3)
					cout << 1 << endl;
				else
					cout << 2 << endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
	while (true){
		int a[5];
		int f[4] = { 0 };
		for (int i = 0; i < 5; i++){
			cin >> a[i];
			if (i == 0 && a[i] == 0){
				return 0;
			}
			f[a[i]]++;
		}
		if (f[1]>0 && f[2] > 0 && f[3] > 0||f[1]>3||f[2]>3||f[3]>3){
			for (int i = 0; i < 5; i++){
				cout << "3" << endl;
			}
		}
		else if (f[1]>0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				if (a[i] == 1){
					cout << "2" << endl;
				}
				else{
					cout << "1" << endl;
				}
			}
		}
		else if (f[2]>0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				if (a[i] == 3){
					cout << "2" << endl;
				}
				else{
					cout << "1" << endl;
				}
			}
		}
		else{
			for (int i = 0; i < 5; i++){
				cout << a[i] << endl;
			}
		}
	}
}

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) {
    if ((count_gu == 5 || count_paa == 5 || count_tyo == 5) ||
        (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;
}