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>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int h[5],f[4],w,c;
	while(cin>>h[0],h[0]){
		rep(i,4)f[i]=0; f[h[0]]=1;
		rep(i,4)cin>>h[i+1],f[h[i+1]]=1;
		c=0; rep(i,4)c+=f[i];
		if(c==1||c==3)w=0;
		else{
			if(!f[1])w=2;
			if(!f[2])w=3;
			if(!f[3])w=1;
		}
		rep(i,5)cout<<(w?h[i]==w?1:2:3)<<endl;
	}
	return 0;
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi v(5);
  while (cin >> v[0], v[0]) {
    loop(i, 1, 5) cin >> v[i];
    vi w(4);
    rep(i, 5) {
      v[i]--;
      w[v[i]]++;
      if (v[i] == 0) w[3]++;
    }
    if ((w[0] > 0 && w[1] > 0 && w[2] > 0) || (v[0] == v[1] && v[1] == v[2] && v[2] == v[3] && v[3] == v[4])) {
      rep(i, 5) cout << 3 << endl;
      continue;
    }
    rep(i, 5) {
      cout << 2 - !!w[v[i] + 1] << endl;
    }
  }
}

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++){
      cin >> t[i];
      if(t[i] == 0) return 0;
      cnt[t[i] - 1]++;
    }

    for(int i = 0; i < 5; i++){
      //ツつ?つ「ツつア
      if(cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0 ||
         cnt[0] == 5 || cnt[1] == 5 || cnt[2] == 5){
        cout << 3 << endl;
      }
      //ツ渉淞つソ
      else if(cnt[t[i] % 3] > 0){
        cout << 1 << endl;
      }
      //ツ閉可つッ
      else{
        cout << 2 << endl;
      }
    }
  }
}

C++: #include<iostream>
main(){
  int N;std::cin>>N;
  while(N>0){
    int v[5],b=0,f=0,d[]={0,0,0,1,0,3,2,0};
    for(;b<5;++b){v[b]=N;f|=1<<--N;std::cin>>N;}
    for(b=0;b<5;++b)std::cout<<((v[b]==d[f])?1:(d[f]?2:3))<<std::endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;

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

        int cnt1, cnt2, cnt3;
        cnt1 = cnt2 = cnt3 = 0;
        rep(i, 5) {
            if (h[i] == 1) cnt1++;
            else if (h[i] == 2) cnt2++;
            else cnt3++;
        }
        
        if (cnt1 == 5 || cnt2 == 5 || cnt3 == 5 || cnt1*cnt2*cnt3 > 0) rep(i, 5) cout << 3 << endl;
        else {
            if (cnt1 == 0) rep(i, 5) {
                if (h[i] == 2) cout << 1 << endl;
                else cout << 2 << endl;
            } else if (cnt2 == 0) rep(i, 5) {
                if (h[i] == 3) cout << 1 << endl;
                else cout << 2 << endl;
            } else rep(i, 5) {
                if (h[i] == 1) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
    }

    return 0;
}

C++: #include<iostream>
main(){for(;;){int d[5],s=0,i=0;for(;i<5;i++){int h;std::cin>>h;if(!h)return 0;s|=d[i]=1<<(h-1);}for(i=0;i<5;i++){int k=d[i];std::cout<<(s==7|s==k?3:((s^k)==k*2|(s^k)==k/4?1:2))<<"\n";}}}

C++: #include<iostream>
int main(){
for(;;){
	int n,h[3]={0},i,a;
	std::cin>>n;
	if(!n)break;
	h[n-1]=1;
	for(i=1;i<5;i++)
		std::cin>>n,
		h[n-1]|=1<<i;
	for(i=0;i<5;i++){
		for(n=0;!(h[n]&1<<i);n++);
		a=!!h[(n+1)%3]+(h[(3+n-1)%3]?2:0);
		std::cout<<(a?a:3)<<'\n';
	}
}
return 0;
}

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

typedef set<int> S;

const int NMAX = 500;
const double EPS = 1.0e-6;
const double INF = 1.0e10;

int N;
double R;
double x[NMAX];
double y[NMAX];
double r[NMAX];
double v[NMAX];

bool input() {
  cin >> R >> N;
  if (!R && !N) {
    return false;
  }
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i] >> r[i] >> v[i];
  }
  return true;
}

void solve() {
  S s;
  for (int i = 0; i < N; ++i) {
    s.insert(i);
  }

  int ans = 0;
  while (!s.empty()) {
    int t = -1;
    double td = INF;
    for (S::iterator it = s.begin(); it != s.end();) {
      int n = *it;
      double d = sqrt(x[n] * x[n] + y[n] * y[n]);
      double nd = d - v[n];
      if (nd < R - EPS) {
        s.erase(it++);
        ++ans;
        continue;
      }
      if (td > nd) {
        td = nd;
        t = n;
      }
      x[n] *= nd / d;
      y[n] *= nd / d;
      ++it;
    }
    if (t == -1) {
      break;
    }
    double zt = atan2(y[t], x[t]);
    for (S::iterator it = s.begin(); it != s.end();) {
      int n = *it;
      double d2 = x[n] * x[n] + y[n] * y[n];
      double d = sqrt(d2);
      double z1 = atan2(y[n], x[n]);
      double z2;
      if (d - r[n] < EPS - R) {
        z2 = M_PI;
      } else if (d - r[n] >= 0) {
        z2 = atan2(r[n], sqrt(d2 - r[n] * r[n]));
      } else {
        double k = (r[n] * r[n] - R * R - d * d) / (2 * d);
        z2 = atan2(k, sqrt(R * R - k * k)) + M_PI / 2;
      }
      double zu = z1 + z2;
      double zl = z1 - z2;
      bool hit;
      if (zu > M_PI) {
        hit = ((zl - EPS < zt && zt <= M_PI)
            || (-M_PI <= zt && zt < zu + EPS - 2 * M_PI));
      } else if (zl < -M_PI) {
        hit = ((zl + 2 * M_PI - EPS < zt && zt <= M_PI)
            || (-M_PI <= zt && zt < zu + EPS));
      } else {
        hit = (zl - EPS < zt && zt < zu + EPS);
      }
      if (hit) {
        s.erase(it++);
      } else {
        ++it;
      }
    }
  }
  cout << ans << endl;
}

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