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

int main() {
	int a[5];
	while(1){
		int flag1=0,flag2=0,flag3=0;
		for(int i=0;i<5;i++){
			cin>>a[i];
			if(a[i]==1)flag1=1;
			if(a[i]==2)flag2=1;
			if(a[i]==3)flag3=1;
		}
		if(a[0]==0)break;
		for(int i=0;i<5;i++){
			if(flag1==1&&flag2==1&&flag3==1){
				cout<<3<<endl;
			}else if(flag1==1&&flag2==1){
				if(a[i]==1)cout<<1<<endl;
				else cout<<2<<endl;
			}else if(flag2==1&&flag3==1){
				if(a[i]==2)cout<<1<<endl;
				else cout<<2<<endl;
			}else if(flag1==1&&flag3==1){
				if(a[i]==3)cout<<1<<endl;
				else cout<<2<<endl;
			}else{
				cout<<3<<endl;
			}
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int te[5];
int main() {
  while (true) {
    vector<int> cnt(3, 0);
    REP(i, 5) {
      int v;
      if (scanf("%d", &v), v == 0) { return 0; }
      v--;
      te[i] = v;
      cnt[v]++;
    }
    REP(i, 5) {
      int win = 2;
      if (cnt[te[i]] == 5 || (cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0)) {
        win = 3;
      } else if (cnt[(te[i] + 2) % 3] == 0) {
        win = 1;
      }
      printf("%d\n", win);
    }
  }
}

C++: #include<iostream>
using namespace std;
int a, b, c, d, e, x[4], f;
int main() {
	while (true) {
		x[0] = 0;
		x[1] = 0;
		x[2] - 0;
		x[3] - 0;
		cin >> a;
		if (a == 0) { break; }
		x[a]++;
		cin >> b >> c >> d >> e;
		x[b]++;
		x[c]++;
		x[d]++;
		x[e]++;
		if (x[1] >= 1 && x[2] >= 1 && x[3] >= 1) { cout << '3' << endl << '3' << endl << '3' << endl << '3' << endl << '3' << endl; }
		else if (x[1] >= 5 || x[2] >= 5 || x[3] >= 5) { cout << '3' << endl << '3' << endl << '3' << endl << '3' << endl << '3' << endl; }
		else {
			if (x[2] == 0) {
				if (a == 1) { a = 4; }
				if (b == 1) { b = 4; }
				if (c == 1) { c = 4; }
				if (d == 1) { d = 4; }
				if (e == 1) { e = 4; }
			}
			if (x[1] == 0) { f = 2; }
			if (x[2] == 0) { f = 3; }
			if (x[3] == 0) { f = 1; }
			if (a == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (b == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (c == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (d == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (e == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
		}
	}
	return 0;
}

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

int main() {
  int a[5];
  while(cin >> a[0] && a[0]) {
    for(int i=1; i<5; i++) cin >> a[i];
    set<int> s;
    for(int i=0; i<5; i++) {
      a[i]--;
      s.insert(a[i]);
    }
    for(int i=0; i<5; i++) {
      if(s.size()==1||s.size()==3) cout << 3 << endl;
      else {
        if(s.count((a[i]+1)%3)) cout << 1 << endl;
        else cout << 2 << endl;
      }
    }
  }
  return 0;
}

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

int main()
{
  vector<int> v(5);
  while (cin >> v[0] && v[0] != 0) {
    vector<bool> t(3, false);
    --v[0];
    t[v[0]] = true;
    vector<int> ans(5, 3);
    for (int i = 1; i < 5; i++) {
      cin >> v[i];
      --v[i];
      t[v[i]] = true;
    }

    for (int a = 0; a < 3; a++) {
      if (!t[a]) {
        if (!t[(a+1)%3] || !t[(a+2)%3]) {
          // all a+1 or a+2
        } else {
          // a+1 wins, a+2 lose
          for (int i = 0; i < 5; i++) {
            if (v[i] == (a+1)%3) {
              ans[i] = 1;
            } else if (v[i] == (a+2)%3) {
              ans[i] = 2;
            } else {
              while (1) {}
            }
          }
          break;
        }
      }
    }
    for (int i = 0; i < 5; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<cmath>
using namespace std;
int main(){
	
	int a[5];
	int s[5];
	
	while(cin>>a[0],a[0]!=0){
		bool p[4]={false};
		p[a[0]]=true;
		for(int i=1;i<5;i++){
			cin>>a[i];
			p[a[i]]=true;
		}
		int w,l;
		if(p[1]&&p[2]&&p[3]||!p[2]&&!p[3]||!p[1]&&!p[3]||!p[1]&&!p[2]){
			w=3;
			l=3;
		}
		else if(p[1]&&p[3]){
			w=3;
			l=1;
		}
		else if(p[2]&&p[3]){
			w=2;
			l=3;
		}
		else if(p[1]&&p[2]){
			w=1;
			l=2;
		}	
		for(int i=0;i<5;i++){
			if(w==l)
				s[i]=3;
			else{
				if(a[i]==w)
					s[i]=1;
				else 
					s[i]=2;
			}
		}
		for(int i=0;i<5;i++)
			cout<<s[i]<<endl;
	}
	
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

using namespace std;

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

		int g = 0, c = 0, p = 0;
		
		for (int i = 0; i < 5; i++) {
			if (h[i] == 1)g++;
			if (h[i] == 2)c++;
			if (h[i] == 3)p++;
		}
		if ((g != 0 && c != 0 && p != 0)||
			g == 5 || c == 5 || p == 5) {
			for (int i = 0; i < 5; i++)
				cout << 3 << endl;
		}else{
			if (p == 0) {
				for (int i = 0; i < 5; i++)
					cout << (h[i] == 1 ? 1 : 2 )<< endl;
			}
			if (g == 0) {
				for (int i = 0; i < 5; i++)
					cout << (h[i] == 2 ? 1 : 2) << endl;
			}
			if (c == 0) {
				for (int i = 0; i < 5; i++)
					cout << (h[i] == 3 ? 1 : 2) << endl;
			}
		}
	}
	return	0; 
}

C++: #include<iostream>

using namespace std;

int main() {
	int st[5], res[5];
	int g[3], n = 0;
	int val = 0;
	
	while(1) {
	
		for( int i=0; i<3; i++) g[i] = 0;
		n = 0;
		val = 0; // val -> winner

		// Input
		for( int i=0; i<5; i++) {
			cin >> st[i];
			if(st[i]==0) break;
			if(!g[ st[i]-1 ]) {
				n++;
				g[ st[i]-1 ] = 1;
				if( val==0) val = st[i];
				if( val-1==(st[i]%3)) val = st[i];
			}
		}
		if(st[0]==0) break;
		
		if( n==2) {
			for( int i=0; i<5; i++)
				if( val==st[i]) res[i] = 1; else res[i] = 2;
		}else {
			for( int i=0; i<5; i++) res[i] = 3;
		}

		// Output
		for( int i=0; i<5; i++) cout << res[i] << endl;
	}
	return 0;
}