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;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n[5];
	int type[][2] = {{0,1},{0,2},{1,0},{1,2},{2,0},{2,1}};
	int res[] = {2,1,1,2,2,1};
	while(cin >> n[0], n[0]) {
		int cnt[3] = {};
		cnt[--n[0]]++;
		rep2(i,1,5) {
			cin >> n[i];
			cnt[--n[i]]++;
		}
		int max = 0, min = 9, max_te = -1, min_te = -1;
		rep(i,3) {
			if(max < cnt[i]) max = cnt[i], max_te = i;
			if(min > cnt[i]) min = cnt[i], min_te = i;
		}
		if(max == 5 || min >= 1){
			rep(j,5) {
				cout << 3 << endl;
			}
		} else {
			rep(i,6) {
				if(max_te==type[i][0] && min_te==type[i][1]) {
					rep(j,5) {
						if(type[i][0]==n[j]) cout << res[i] << endl;
						else cout << 3-res[i] << endl;
					}
				}
			}
		}
	}
}

C++: #include <cstdio>

using namespace std;

int main()
{
	for(;;){
		int hist[3] = {0};
		int input[5];
		for(int i=0; i<5; ++i){
			scanf("%d", &input[i]);
			--input[i];
			if(input[i] == -1)
				break;
			hist[input[i]]++;
		}
		if(input[0] == -1)
			break;
		
		for(int i=0; i<5; ++i){
			bool weak = !!hist[(input[i]+1)%3];
			bool strong = !!hist[(input[i]+2)%3];
			printf("%d\n", weak ? (strong ? 3 : 1) : (strong ? 2 : 3));
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){

	while(1){
	    int a[10] = {0};
	    short flg = 0;
        short aiko1=0,aiko2=0,aiko3=0;
        for(int i = 0; i < 5; i++){
            cin >> a[i];
            if(i != 0){
                if(a[i-1] == a[i])flg++;
            }
            else{
                if(a[i] == 0)goto end;
                else flg++;
            }
            if(a[i] == 1)aiko1++;
            if(a[i] == 2)aiko2++;
            if(a[i] == 3)aiko3++;
        }
        //あいこの出力
        if(flg == 5 || aiko1 != 0 && aiko2 != 0 && aiko3!= 0){
            for(int i = 0; i < 5; i++)cout << 3 << endl;
        }
        if(aiko1 == 0){
            for(int i = 0; i < 5; i++){
                if(a[i] == 2) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
        if(aiko2 == 0){
            for(int i = 0; i < 5; i++){
                if(a[i] == 3) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
        if(aiko3 == 0){
            for(int i = 0; i < 5; i++){
                if(a[i] == 1) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
	}
    end:
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const string DRAW = "33333";
const int N = 5;

int main(void){
    while(1){
        set<char> comb;
        string in;
        rep(i, N){
            char c; cin >> c;
            if(c == '0') return 0;
            comb.insert(c);
            in.pb(c);
        }
        string res = DRAW;

        if(comb.size() == 2){
            char w;
            COUNT(i, 3) if(comb.insert('0' + i).second) w = '1' + i % 3;
            rep(i, N) res[i] = in[i] == w ? '1':'2';
        }

        rep(i, N) cout << res.at(i) << endl;
    }
 
    return 0;
}

C++: #include <cstdio>


int a[3], d[] = {0, 1, 2, 0}, h[5];

int main(){
    while(scanf("%d", &h[0]) != EOF){
        if(h[0] == 0) break;

        a[h[0] - 1]++;
        for(int i = 1; i < 5; i++){
            scanf("%d", &h[i]);
            a[h[i] - 1]++;
        }

        if((a[0] > 0 && a[1] > 0 && a[2] > 0) || a[0] == 5 || a[1] == 5 || a[2] == 5) printf("3\n3\n3\n3\n3\n");
        else{
            for(int i = 0; i < 3; i++){
                if(a[i] > 0 && a[i + 1] > 0){
                    for(int j = 0; j < 5; j++){
                        if(h[j] - 1 == d[i]) printf("1\n");
                        else printf("2\n");
                    }
                    break;
                }
            }
        }

        for(int i = 0; i < 3; i++) a[i] = 0;
    }
    return 0;
}

C++: #include <iostream>
#include <set>
#define NUM_PEOPLE 5
using namespace std;


bool aiko(int* h);
int win(int* h);

int main(void){
  int h[NUM_PEOPLE];
  int retval[NUM_PEOPLE];
  while(true){
    for(int i=0;i<NUM_PEOPLE;i++){
      cin>>h[i];
      if(h[i]==0){return 0;}
    }
    if(aiko(h)){
      for(int i=0;i<NUM_PEOPLE;i++){
        retval[i]=3;
      }
    }
    else{
      int w=win(h);
      for(int i=0;i<NUM_PEOPLE;i++){
        if(h[i]==w){
          retval[i]=1;
        }
        else{
          retval[i]=2;
        }
      }
    }
    for(int i=0;i<NUM_PEOPLE;i++){
      cout<<retval[i]<<endl;
    }
  }
}

bool aiko(int* h){
  set<int> st(h,h+NUM_PEOPLE);
  int count=0;
  for(auto iter=st.begin();iter!=st.end();iter++){
    count++;
  }
  return count==3 or count==1;
}

int win(int* h){
  set<int> st(h,h+NUM_PEOPLE);
  auto iter=st.begin();
  int h1=*iter;
  iter++;
  int h2=*iter;
  if((h1==1 and h2==2) or (h1==2 and h2==1)){
    return 1;
  }
  else if((h1==3 and h2==2) or (h1==2 and h2==3)){
    return 2;
  }
  else{
    return 3;
  }
}

C++: #include<iostream>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;


const int END_OF_INPUT = 0;


int main() {
	int a_n;
	
	while (cin >> a_n && a_n != 0){
		vector<int> m_list;
		m_list.push_back(a_n);

		for (int i = 0; i < 4; ++i){
			cin >> a_n;
			m_list.push_back(a_n);
		}

		int is_even = 0;
		bool rps[3];
		for (int i = 1; i <= 3; ++i){
			vector<int>::iterator cIter = find(m_list.begin(), m_list.end(), i);
			rps[i - 1] = false;
			if (cIter != m_list.end()){
				++is_even;
				rps[i - 1] = true;
			}
		}
		if (is_even == 3 || is_even == 1){
			// even 
			for (int i = 1; i <= 5; ++i){
				cout << "3" << endl;
			}
		}
		else{
			int winner = 0;
			if (rps[0] && rps[1]){
				// グー
				winner = 1;
			}
			else if (rps[1] && rps[2]){
				// ちょき
				winner = 2;
			}
			else if (rps[2] && rps[3]){
				// パー
				winner = 3;
			}

			for (int i = 0; i < 5; ++i){
				if (m_list[i] == winner){
					cout << "1" << endl;
				}
				else{
					cout << "2" << endl;
				}
			}
		}


		

	}
	


}