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;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int h[5];
  while(cin >> h[0], h[0]) {    
    int rps[3] = {0};
    rps[--h[0]]++;
    reps(i, 1, 5) cin >> h[i], rps[--h[i]]++;
    int win = 3;
    if(rps[0] && rps[1] && rps[2]) win = 3;
    else if(rps[0] && rps[1]) win = 0;
    else if(rps[1] && rps[2]) win = 1;
    else if(rps[2] && rps[0]) win = 2;
    rep(i, 5) {
      if(win == 3) cout << 3 << endl;
      else if(h[i] == win) cout << 1 << endl;
      else cout << 2 << endl;
    }
  }  
  return 0;
}

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

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

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

int a[5];

bool input() {
  cin >> a[0];
  if (!a[0]) {
    return false;
  }
  for (int i = 1; i < 5; ++i) {
    cin >> a[i];
  }
  return true;
}

void print_aiko() {
  for (int i = 0; i < 5; ++i) {
    cout << 3 << endl;
  }
}

void print_win_lose(int d) {
  for (int i = 0; i < 5; ++i) {
    if (a[i] == (d + 1) % 3 + 1) {
      cout << 1 << endl;
    } else {
      cout << 2 << endl;
    }
  }
}

void solve() {
  int c[3] = {0};
  for (int i = 0; i < 5; ++i) {
    ++c[a[i] - 1];
  }
  int b = 0;
  for (int i = 0; i < 3; ++i) {
    if (c[i]) {
      ++b;
    }
  }
  if (b == 1 || b == 3) {
    print_aiko();
    return;
  }
  int d = -1;
  for (int i = 0; i < 3; ++i) {
    if (!c[i]) {
      d = i;
      break;
    }
  }
  print_win_lose(d);
}

int main() {
  while (input()) {
    solve();
  }
}

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[] = {1,2,2,1,1,2};
	while(cin >> n[0], n[0]) {
		int cnt[3] = {};
		cnt[n[0]-1]++;
		rep2(i,1,5) {
			cin >> n[i];
			cnt[n[i]-1]++;
		}
		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++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

//aの勝敗  1-win 2-lose 3-draw
int re(int a, int b) {
	int ret;
	switch (a) {
	case 1:
		ret = (b == 1) ? 3 : (b == 2) ? 1 : 2;
		break;
	case 2:
		ret = (b == 1) ? 2 : (b == 2) ? 3 : 1;
		break;
	case 3:
		ret = (b == 1) ? 1 : (b == 2) ? 2 : 3;
		break;
	}
	return ret;
}

int main() {
	while (true) {
		int x; cin >> x;
		if (x == 0)break;
		VI h(5); h[0] = x;
		rep(i, 4)cin >> h[i + 1];

		rep(i, 5) {
			int win = 0, lose = 0, draw = 0;
			rep(j, 5) {
				if (i != j) {
					switch (re(h[i], h[j])) {
					case 1:
						win++; break;
					case 2:
						lose++; break;
					case 3:
						draw++; break;
					}
				}
			}

			int ans;
			if ((win && lose) || (!win && !lose))ans = 3;
			else if (win)ans = 1;
			else ans = 2;
			Cout(ans);
		}
	}
}

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("%d\n", res[ hand[i] ] );
		}
	}
	return 0;
}

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

main(){
    int T[N];
    while( cin >> T[0] && T[0] ){
	for ( int i = 1; i < N; i++ ) cin >> T[i];
	for ( int i = 0; i < N; i++ ){
	    int w = 0, l = 0;
	    for ( int j = 0; j < N; j++ ){
		if ( T[i]%3 == T[j]-1 ) w++;
		if ( T[j]%3 == T[i]-1 ) l++;
	    }
	    if ( w && l == 0 ) cout << 1 << endl;
	    else if ( l && w == 0 ) cout << 2 << endl;
	    else cout << 3 << endl;
	}
    }
}