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>
using namespace std;

int main(){
    int h[5];
    while(cin >> h[0]){
        if(h[0] == 0) break;
        cin >> h[1] >> h[2] >> h[3] >> h[4];
        int rs[5];
        bool r = false;
        bool s = false;
        bool p = false;
        for(int i=0; i<5; ++i){
            switch(h[i]){
                case 1:
                    r = true;
                    break;
                case 2:
                    s = true;
                    break;
                case 3:
                    p = true;
            }
        }
        if(r&&s&&p)
            rs[0] = rs[1] = rs[2] = rs[3] = rs[4] = 3;
        else if((r&&!s&&!p)||(!r&&s&&!p)||(!r&&!s&&p))
            rs[0] = rs[1] = rs[2] = rs[3] = rs[4] = 3;
        else if(!r)
            for(int i=0; i<5; ++i)
                (h[i]==2)?rs[i]=1:rs[i]=2;
        else if(!s)
            for(int i=0; i<5; ++i)
                (h[i]==3)?rs[i]=1:rs[i]=2;
        else
            for(int i=0; i<5; ++i)
                (h[i]==1)?rs[i]=1:rs[i]=2;
        for(int i=0; i<5; ++i){
            cout << rs[i] << endl;
        }
    }
    return 0;
}

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

using namespace std;

int result[5];

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
	while(cin>>result[0],result[0]){
		bool d = 0;
		bool	hand[3] = {false};
		loop(i,1,5)cin>>result[i];
		rep(i,5)hand[result[i]-1]=true;
		if(!hand[0]&&!hand[1]) d = true;
		else if(!hand[1]&&!hand[2]) d = true;
		else if(!hand[0]&&!hand[2]) d = true;
		if(hand[0]&&hand[1]&&hand[2]||d)
			rep(i,5)cout<<3<<endl;
		else if(!hand[0])
			rep(i,5)
				if(result[i]==2)cout<<1<<endl;
				else cout<<2<<endl;
		else if(!hand[1])
			rep(i,5)
				if(result[i]==3)cout<<1<<endl;
				else cout<<2<<endl;
		else if(!hand[2])
			rep(i,5)
				if(result[i]==1)cout<<1<<endl;
				else cout<<2<<endl;
	}
}

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

int main(){
	int hand[5], result[5];
	int rock, scissors, paper, win;
	
	while(cin >> hand[0], hand[0]){
		cin >> hand[1] >> hand[2] >> hand[3] >> hand[4];
		
		rock = scissors = paper = 0;
		for(int i = 0; i < 5; ++i){
			switch(hand[i]){
				case 1: ++rock; break;
				case 2: ++scissors; break;
				case 3: ++paper; break;
				default: break;
			}
		}
		
		if(rock == 5 || scissors == 5 || paper == 5 || (rock > 0 && scissors > 0 && paper > 0)){
			for(int i = 0; i < 5; ++i) result[i] = 3;
		}else{
			if(rock == 0) win = 2;
			else if(scissors = 0) win = 3;
			else win = 1;
			
			for(int i = 0; i < 5; ++i){
				if(hand[i] == win) result[i] = 1;
				else result[i] = 2;
			}
		}
		
		for(int i = 0; i < 5; ++i) cout << result[i] << endl;
	}
	
	return 0;
}

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

int main(){
  while(true){
    int t[5];
    int cnt[3] = {0, 0, 0};
    for(int i = 0; i < 5; i++){
      if(!(cin >> t[i])) return 0;
      t[i]--;
      cnt[t[i]]++;
    }

    for(int i = 0; i < 5; i++){
      if(cnt[t[i]] == 5 || cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0){
        cout << 3 << endl;
      }
      else if(cnt[(t[i] + 1) % 3] > 0){
        cout << 1 << endl;
      }
      else{
        cout << 2 << endl;
      }
    }
  }
}

C++: #define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
#include<map>
#include<string>
using namespace std;

int main(){
	while(true){
		int hand[5], res[3];
		bool latte[3] = {};
		for(int i = 0; i < 5; i++){
			cin >> hand[i];
			if(hand[i] == 0) return 0;
			hand[i]--;
			latte[hand[i]] = true;
		}
		for(int i = 0; i < 3; i++){
			if( latte[ (i+1)%3 ] && !latte[ (i+2)%3 ] ) res[i] = 1;
			else if( latte[ (i+2)%3 ] && !latte[ (i+1)%3 ] ) res[i] = 2;
			else res[i] = 3;
		}
		for(int i = 0; i < 5; i++){
			printf("\t%d\n", res[ hand[i] ] );
		}
	}
	return 0;
}

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

int main(){
	int p[5];
	while(1){
	int t[3]={0};
		for(int i=0;i<5;i++){
			cin >> p[i];
			if(!p[i])return(0);
			t[p[i]-1]++;
		}
		if(t[0]&&t[1]&&!t[2])
			for(int i=0;i<5;i++)
				if(p[i]==1)p[i]=1;
				else p[i]=2;
		else if(t[0]&&!t[1]&&t[2])
			for(int i=0;i<5;i++)
				if(p[i]==1)p[i]=2;
				else p[i]=1;
		else if(!t[0]&&t[1]&&t[2])
			for(int i=0;i<5;i++)
				if(p[i]==2)p[i]=1;
				else p[i]=2;
		else
			for(int i=0;i<5;i++)p[i]=3;
		
		for(int i=0;i<5;i++)cout<<p[i]<<endl;
	}
}

C++: #include <cstdio>
main(){while(1){int h[5]={0},t[4]={0},w=0;for(;w<5;w++){scanf("%d",h+w);t[h[w]]++;if(!*h)return 0;}w=t[1]&&t[2]&&t[3]?-1:t[1]&&t[2]?1:t[2]&&t[3]?2:t[1]&&t[3]?3:-1;while((*t)++<5)puts(w<0?"3":h[*t-1]-w?"2":"1");}}

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

int main() {
	typedef pair<int, int>P;

	int a;
	while (cin >> a, a) {
		vector<int>rv;
		vector<int>sv;
		vector<int>pv;

		if (a == 1)rv.push_back(1);
		else if (a == 2)sv.push_back(1);
		else pv.push_back(1);

		for (int i = 2;i <= 5;i++) {
			int b;
			cin >> b;
			if (b == 1)rv.push_back(i);
			else if (b == 2)sv.push_back(i);
			else pv.push_back(i);
		}

		int r = 0,p = 0,s = 0;

		if (rv.empty() && !sv.empty() && !pv.empty()) {
			s = 1;
			p = -1;
		}
		else if (!rv.empty() && sv.empty() && !pv.empty()) {
			r = -1;
			p = 1;
		}
		else if (!rv.empty() && !sv.empty() && pv.empty()) {
			r = 1;
			s = -1;
		}

		int k[5];
		int a = rv.size();
		for (int i = 0;i < a;i++) {
			if (r == 1) k[rv[i] - 1] = 1;
			else if (r == -1) k[rv[i] - 1] = 2;
			else k[rv[i] - 1] = 3;
		}

		int b = sv.size();
		for (int i = 0;i < b;i++) {
			if (s == 1)k[sv[i] - 1] = 1;
			else if (s == -1)k[sv[i] - 1] = 2;
			else k[sv[i] - 1] = 3;
		}

		int c = pv.size();
		for (int i = 0;i < c;i++) {
			if (p == 1)k[pv[i] - 1] = 1;
			else if (p == -1)k[pv[i] - 1] = 2;
			else k[pv[i] - 1] = 3;
		}

		for (int i = 0;i < 5;i++) {
			cout << k[i] << endl;
		}
	}
	return 0;
}