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 <bits/stdc++.h>

using namespace std;

int main()
{
    
    while (1) {
        vector<int> DataBase;

        for (int i = 0; i < 5; ++i) {
            int data;
            cin >> data;
            if (data == 0) break;
            DataBase.push_back(data);
        }

        if (DataBase.size() == 0) {
            break;
        }

        bool win_stone = false;
        bool win_sissor = false;
        bool win_paper = false;
        bool aiko = false;

        win_stone = static_cast<bool>(find(DataBase.begin(), DataBase.end(), 1) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 2) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 3) == DataBase.end());

        win_sissor = static_cast<bool>(find(DataBase.begin(), DataBase.end(), 1) == DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 2) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 3) != DataBase.end());
        win_paper = static_cast<bool>(find(DataBase.begin(), DataBase.end(), 1) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 2) == DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 3) != DataBase.end());
        aiko = static_cast<bool>(find(DataBase.begin(), DataBase.end(), 1) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 2) != DataBase.end() &&
                                        find(DataBase.begin(), DataBase.end(), 3) != DataBase.end());
        
        vector<int> ResultBase(5, 0);

        if (win_stone) {
            for (int i = 0; i < static_cast<int>(DataBase.size()); ++i) {
                switch(DataBase[i]) {
                    case 1:
                        ResultBase[i] = 1;
                        break;
                    case 2:
                        ResultBase[i] = 2;
                        break;
                    default:
                        break;
                }
            }
        }

        if (win_sissor) {
            for (int i = 0; i < static_cast<int>(DataBase.size()); ++i) {
                switch(DataBase[i]) {
                    case 2:
                        ResultBase[i] = 1;
                        break;
                    case 3:
                        ResultBase[i] = 2;
                        break;
                    default:
                        break;
                }
            }
        }

        if (win_paper) {
            for (int i = 0; i < static_cast<int>(DataBase.size()); ++i) {
                switch(DataBase[i]) {
                    case 3:
                        ResultBase[i] = 1;
                        break;
                    case 1:
                        ResultBase[i] = 2;
                        break;
                    default:
                        break;
                }
            }
        }

        if (aiko) {
            for (int i = 0; i < static_cast<int>(DataBase.size()); ++i) {
                 ResultBase[i] = 3;
             }
        }
        
        for (int i = 0; i < static_cast<int>(ResultBase.size()); ++i) {
            cout << ResultBase[i] << endl;
        }
    }

    return 0;
}

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 main()
{
	int h[5];

	cin >> h[0];

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

		int f[3] = { 0, 0, 0 }, r[5] = { 0, 0, 0, 0, 0 };

		for (int i = 0; i < 5; i++)
			f[h[i] - 1] = 1;
		
		if ((f[0] + f[1] + f[2]) % 2 == 1)
			for (int i = 0; i < 5; i++)
				r[i] = 3;
		else {
			for (int j = 0; j < 3; j++) {
				if (!f[j]) {
					for (int i = 0; i < 5; i++) {
						if (h[i] == (j + 1) % 3 + 1)
							r[i] = 1;
						else
							r[i] = 2;
					}
				}
			}
		}

		for (int i = 0; i < 5; i++)
			cout << r[i] << endl;

		cin >> h[0];
	}

	return 0;
}

C++: #include <iostream>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c), (c)+5
#define Contains(c, x) (find(all(c), (x)) != (c)+5)
using namespace std;
int main()
{
    int a[5], b[5];
    while (true) {
        cin >> a[0]; if (a[0] == 0) break;
        REP(i, 1, 5) cin >> a[i];
        if (Contains(a, 1) && Contains(a, 2) && Contains(a, 3)) {
            rep(i, 5) b[i] = 3;
        }
        else if (count(all(a), a[0]) == 5) {
            rep(i, 5) b[i] = 3;
        }
        else {
            if (!Contains(a, 1))
                rep(i, 5) b[i] = (a[i] == 2) ? 1 : 2;
            else if (!Contains(a, 2))
                rep(i, 5) b[i] = (a[i] == 3) ? 1 : 2;
            else
                rep(i, 5) b[i] = (a[i] == 1) ? 1 : 2;
        }
        rep(i, 5) cout << b[i] << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
main(){
  while(1){
    int a[6];
    scanf("%d",&a[0]);
    if(!a[0]) break;
    for(int i=1;i<5;i++) scanf("%d",&a[i]);
    for(int i=0;i<5;i++){
      int d,w,l;
      d=w=l=0;
      for(int j=0;j<5;j++){
	if(i==j) continue;
	if(a[i]==a[j]%3+1){
	  ++w;
	}else if(a[i]==a[j]){
	  ++d;
	}else{
	  ++l;
	}
      }
      if((w && l) || (!l && !w)) puts("3");
      else if(!w) puts("1");
      else if(!l) puts("2");
    }
  }
}