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],h[0]!=0){
    int judge[4]={};
    for(int i=1;i<5;i++){
      cin>>h[i];
      judge[h[i]]++;
    }
    judge[h[0]]++;
    int pointer=0;
    int zerocnt=0;
    int ans[5]={};
    for(int i=1;i<4;i++){
      if(judge[i]==5){
	for(int j=0;j<5;j++)
	  ans[j]=3;
      }
      if(judge[i]==0){
	zerocnt++;
	pointer=i;
      }
    }
    if(zerocnt==1){
      int te1=0,te2=0;
      for(int i=1;i<=3;i++){
	if(i!=pointer){
	  if(te1==0){
	    te1=i;
	  }else{
	    te2=i;
	  }
	}
      }
      if(te1%3>te2%3){
	for(int i=0;i<5;i++){
	  if(h[i]==te1){
	    ans[i]=2;
	  }else{
	    ans[i]=1;
	  }
	}
      }else{
	for(int i=0;i<5;i++){
	  if(h[i]==te1){
	    ans[i]=1;
	  }else{
	    ans[i]=2;
	  }
	}
      }
    }else if(zerocnt==0){
      for(int i=0;i<5;i++)
	ans[i]=3;
    }
    for(int i=0;i<5;i++)
      cout<<ans[i]<<endl;
  }
  return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    if(n == 0) break;
    set<int> s;
    vary(int,v,5,0);
    v[0] = n;
    s.insert(n);
    REP(i,1,5){
      cin >> v[i];
      s.insert(v[i]);
    }
    rep(i,5){
      if(s.size() != 2){
        cout << 3 << endl;
      }
      else{
        if((v[i] == 2 && *s.begin() == 1) || (v[i] == 3 && *s.begin() == 2) || (v[i] == 1 && (*(++s.begin())== 3))){
          cout << 2 << endl;
        }
        else cout << 1 << endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int main() {
  int a[5];
  while(cin >> a[0], a[0]) {
    REP(i,4)
      cin >> a[i+1];
    int te[3] = {};
    REP(i,5)
      te[a[i]-1]++;
    int hoge=0;
    REP(i,3)
      if (te[i])
        hoge++;
    if (hoge != 2) {
      REP(i,5)
        cout << 3 << endl;
      continue;
    }
    int win = 0;
    if (!te[0])
      win = 1;
    else if (!te[1])
      win = 2;
    REP(i,5) {
      if (a[i]-1 == win)
        cout << 1 << endl;
      else
        cout << 2 << endl;
    }
  }
}

C++: #include <stdio.h>
int main()
{
	int hund[5],hundkind[4];
	int winkind[5],win,lose;
	bool chek;

	scanf("%d",&hund[0]);

	while(hund[0] != 0){
		for(int i = 1; i < 5; i++){
			scanf("%d",&hund[i]);
		}

		for(int i = 1; i < 4; i++){
			hundkind[i] = 0;
		}
		chek = false;
		for(int i = 0; i < 5; i++){
			hundkind[ hund[i] ]++;
		}

		if(hundkind[1] != 0 && hundkind[2] != 0 && hundkind[3] != 0){
			for(int i = 0; i < 5; i++){
				winkind[i] = 3;
				chek = false;
			}
		}
		else if(hundkind[1] == 5 || hundkind[2] == 5 || hundkind[3] == 5){
			for(int i = 0; i < 5; i++){
				winkind[i] = 3;
				chek = false;
			}
		}
		else if(hundkind[3] != 0 && hundkind[1] != 0){
			win = 3;
			lose = 1;
			chek = true;
		}
		else{
			for(int i = 1; i < 3; i++){
				if(hundkind[i] != 0 && hundkind[i+1] != 0){
					win = i;
					lose = i+1;
					chek = true;
				}
			}
		}
		for(int i = 0; i < 5 && chek; i++){
			if(hund[i] == win){
				winkind[i] = 1;
			}
			else{
				winkind[i] = 2;
			}
		}

		for(int i = 0; i < 5; i++){
			printf("%d\n",winkind[i]);
		}

		scanf("%d",&hund[0]);
	}

	return 0;
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    vector<int> h(5);
    while(cin >> h[0] && h[0])
    {
        REP(i, 1, 5) cin >> h[i];

        set<int> s;

        rep(i, 5) s.insert(h[i]);

        if((s.count(1) && s.count(2) && s.count(3)) ||
             (s.count(1) && s.size() == 1) || (s.count(2) && s.size() == 1)
              || (s.count(3) && s.size() == 1))
        {
            rep(i, 5) cout << 3 << endl;
        }
        if(!s.count(1))
        {
            rep(i, 5)
            {
                cout << (h[i] == 2 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(2))
        {
            rep(i, 5)
            {
                cout << (h[i] == 3 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(3))
        {
            rep(i, 5)
            {
                cout << (h[i] == 1 ? 1 : 2) << endl;
            }
        }
    }

    return 0;
}