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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main(void){
    for(;;){

	int a[5];
	int b[5];
	int r=0,p=0,s=0;
	for(int i=0;i<5;i++){
        cin>>a[i];
        if(a[i]==0)break;
        else if(a[i]==1)r++;
        else if(a[i]==2)s++;
        else if(a[i]==3)p++;

	}
	if(a[0]==0)break;
	//for(int i=0;i<5;i++)cout<<a[i]<<"+";


	if(r>0&&p>0&&s>0){
        for(int i=0;i<5;i++){
            b[i]=3;
     //       cout<<a[i]<<"-";
        }
	}
	else if(r>0&&p==0&&s==0){
        for(int i=0;i<5;i++){
            b[i]=3;
       //     cout<<a[i]<<"--";
        }
	}
	else if(r==0&&p>0&&s==0){
        for(int i=0;i<5;i++){
            b[i]=3;
     //       cout<<a[i]<<"---";
        }
	}
	else if(r==0&&p==0&&s>0){
        for(int i=0;i<5;i++){
            b[i]=3;
     //       cout<<a[i]<<".";
        }
	}
	else if(r==0&&s>0&&p>0){
        for(int i=0;i<5;i++){
            if(a[i]==2)b[i]=1;
            else if(a[i]==3)b[i]=2;
      //      cout<<a[i]<<"..";
        }
	}
	else if(r>0&&s==0&&p>0){
        for(int i=0;i<5;i++){
            if(a[i]==3)b[i]=1;
            else if(a[i]==1)b[i]=2;
      //      cout<<a[i]<<"...";
        }
	}
	else if(r>0&&s>0&&p==0){
        for(int i=0;i<5;i++){
            if(a[i]==1)b[i]=1;
            else if(a[i]==2)b[i]=2;
      //     cout<<a[i]<<"....";
        }
	}
	//cout<<endl;
	for(int i=0;i<5;i++){
        cout<<b[i]<<endl;
	}
}

	return 0;
}

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

int main()
{
  int p[5];
  while( cin >> p[0], p[0] ) {
    bool flag[3] = {0};
    flag[p[0]-1] = true;
    for(int i=1; i<5; i++) {
      cin >> p[i];
      flag[p[i]-1] = true;
    }

    int flag2[3];
    int cnt = 0;
    for(int i=0; i<3; i++) {
      if( flag[i] ) cnt++;
    }

    if( cnt != 2 ) {
      flag2[0] = flag2[1] = flag2[2] = 3;
    }
    else {
      if( flag[0] && flag[1] ) {
	flag2[0] = 1; flag2[1] = 2;
      }
      if( flag[1] && flag[2] ) {
	flag2[1] = 1; flag2[2] = 2;
      }
      if( flag[2] && flag[0] ) {
	flag2[2] = 1; flag2[0] = 2;
      }
    }

    for(int i=0; i<5; i++) {
      cout << flag2[p[i]-1] << endl;
    }
  }
}

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

using namespace std;

int main(void){
    int i,j,k,l;
    int data[5];
    int result[5];
    int judge[3];
    bool f=false;
    
    while(true){
        memset(judge,0,sizeof(judge));
        
        for(i=0;i<5;i++){
            cin>>data[i];
            if(data[i]==0){
                f=true;
                break;
            }
            judge[data[i]-1]++;
        }
        if(f)break;
        
        if(judge[0]>0&&judge[1]>0&&judge[2]>0){
            for(i=0;i<5;i++){
                cout<<'3'<<endl;
            }
            continue;
        }
        if(judge[0]==0&&judge[1]==0){
            for(i=0;i<5;i++){
                cout<<'3'<<endl;
            }
            continue;
        }
        if(judge[1]==0&&judge[2]==0){
            for(i=0;i<5;i++){
                cout<<'3'<<endl;
            }
            continue;
        }
        if(judge[2]==0&&judge[0]==0){
            for(i=0;i<5;i++){
                cout<<'3'<<endl;
            }
            continue;
        }
        
        if(judge[0]&&judge[1]){
            for(i=0;i<5;i++){
                if(data[i]==1){
                    cout<<'1'<<endl;
                }else{
                    cout<<'2'<<endl;
                }
            }
            continue;
        }
        if(judge[1]&&judge[2]){
            for(i=0;i<5;i++){
                if(data[i]==2){
                    cout<<'1'<<endl;
                }else{
                    cout<<'2'<<endl;
                }
            }
            continue;
        }
        if(judge[2]&&judge[0]){
            for(i=0;i<5;i++){
                if(data[i]==3){
                    cout<<'1'<<endl;
                }else{
                    cout<<'2'<<endl;
                }
            }
            continue;
        }
    }
    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;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    array<int, 5> v{};
    while(cin >> v[0], v[0]){
        array<int, 3> cnt{};
        for (int i = 1; i < 5; ++i) cin >> v[i];
        for (int i = 0; i < 5; ++i) cnt[v[i]-1]++;
        if((!!cnt[0]+!!cnt[1]+!!cnt[2]-1)%2 == 0) {
            for (int i = 0; i < 5; ++i) puts("3");
            continue;
        }
        if(cnt[0] && cnt[1]){
            for (int i = 0; i < 5; ++i) puts(v[i] == 1 ? "1" : "2");
        }else if(cnt[0] && cnt[2]){
            for (int i = 0; i < 5; ++i) puts(v[i] == 1 ? "2" : "1");
        }else {
            for (int i = 0; i < 5; ++i) puts(v[i] == 2 ? "1" : "2");
        }
    }
    return 0;
}