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 <cstdio>


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

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

        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) 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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	while(true)
	{
		int d[3] = {0};
		vint v(5);
		rep(i, 5)
		{
			cin >> v[i];
			if(!v[i]) return 0;
			d[--v[i]]++;
		}

		rep(i, 5)
		{
			if((d[(v[i] + 1) % 3] && d[(v[i] + 2) % 3]) || (!d[(v[i] + 1) % 3] && !d[(v[i] + 2) % 3]))
				cout << 3 << endl;
			else if(d[(v[i] + 1) % 3])
				cout << 1 << endl;
			else
				cout << 2 << endl;
		}
	}
}

C++: #include <iostream>
using namespace std;
int main(){
	int a[5],j,i;
	while(cin>>a[0],a[0]){
		j=0;
		if(!(j & 1<<a[0]))j+=1<<a[0];
		for(i=1;i<5;i++){
			cin>>a[i];
			if(!(j & 1<<a[i]))j+=1<<a[i];
		}
		if(j==14||j==2||j==4||j==8)for(int i=0;i<5;i++)cout<<'3'<<endl;
		else{
			for(int i=0;i<5;i++){
				if(j==10)cout<< ((j-(1<<a[i]))>(1<<a[i])?'2':'1') << endl;
				else cout<< ((j-(1<<a[i]))>(1<<a[i])?'1':'2') << endl;
			}
		}
	}
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int a[5];
	int b[3] = {0};
	cin >> a[0];
	if(a[0] == 0) break;
	b[a[0]-1]++;
	REP(i,4){ 
	    cin >> a[1+i];
	    b[a[1+i]-1]++;
	}
	int c = 0;
	if(b[0] > 0) c++;
	if(b[1] > 0) c++;
	if(b[2] > 0) c++;
	if(c % 2 == 1){
	    REP(i,5) cout << 3 << endl;
	}else if(b[0] == 0){
	    REP(i,5){
		if(a[i] == 2) cout << 1 << endl;
		else cout << 2 << endl;
	    }
	}else if(b[1] == 0){
	    REP(i,5){
		if(a[i] == 3) cout << 1 << endl;
		else cout << 2 << endl;
	    }
	}else{
	    REP(i,5){
		if(a[i] == 1) cout << 1 << endl;
		else cout << 2 << endl;
	    }
	}
    }
    return 0;
}

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

int main(){
	int a[5];
	while( cin >> a[0] , a[0] ){
		for(int i=1 ; i<5 ; ++i ){
			cin >> a[i];
			if( a[i] == 3 ) a[i]++;
		}
		int x=0;
		for(int i=0; i<5 ; ++i ){
			x |= a[i];
		}
		for(int i=0 ; i<5 ; ++i ){
			if( x == 1 || x == 2 || x == 4 || x == 7 ){
				cout << 3 << endl;
			}else{
				int y = x ^ a[i];
				if( (y>>1) == a[i] || (a[i] == 4 && y == 1) ){
					cout << 1 << endl;
				}else{
					cout << 2 << endl;
				}
			}
		}
	}
}

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

int exist(int a[5], int n)
{
	for (int i = 0; i < 5; i++)
	{
		if (a[i] == n)
			return n*n;
	}
	return 0;
}

int r3(int a[5])
{
	int c = 0;
	for (int i = 1; i < 4; i++)
	{
		c += exist(a, i);
	}
	if (c == 5 || c == 10 || c == 13)
		return c;
	return -1;
}


int main()
{
	int a[5];
	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] && a[0] != 0)
	{
		int p = r3(a);
		if (p == -1)
		{
			for (int i = 0; i < 5; i++)
				cout << 3 << endl;
		}
		else
		{
			if (p == 5)
			{
				for (int i = 0; i < 5; i++)
					cout << a[i] << endl;
			}
			else if (p == 10)
			{
				for (int i = 0; i < 5; i++)
					cout << (a[i] - 3) / (-2) + 1 << endl;
			}
			else
				for (int i = 0; i < 5; i++)
					cout << a[i] - 1 << endl;
		}
	}
	
	return 0;
}

C++: #include <cstdio>

int main(){
  int h[5], c[4];

  while(scanf("%d", h) && h[0]){
    c[0] = c[1] = c[2] = c[3] = 0;
    c[h[0]]++;
    for(int i = 1; i < 5; ++i){ scanf("%d", h + i); c[h[i]]++;}

    if(c[1] && c[2] && c[3]) for(int i = 0; i < 5; ++i) puts("3");
    else if(c[1] && c[2]) for(int i = 0; i < 5; ++i) puts(h[i] == 1 ? "1" : "2");
    else if(c[2] && c[3]) for(int i = 0; i < 5; ++i) puts(h[i] == 2 ? "1" : "2");
    else if(c[3] && c[1]) for(int i = 0; i < 5; ++i) puts(h[i] == 3 ? "1" : "2");
    else for(int i = 0; i < 5; ++i) puts("3");
  }
  return 0;
}

C++: #include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int a[5], tmp, *b;
	
	while(1){
		cin >> tmp;
		if(tmp == 0){
			break;
		}
		a[0] = tmp;
		b = (int *)calloc(4, sizeof(int));
		b[tmp]++;
		for(int i = 1; i < 5; i++){
			cin >> tmp;
			a[i] = tmp;
			b[tmp]++;
		}
		
		if((b[1] != 0 && b[2] != 0 && b[3] != 0) || (b[1] == b[2] && b[2] == b[3])){
			for(int i = 0; i < 5; i++){
				cout << "3" << endl;
			}
			free(b);
			continue;
		} else if(b[1] == 0){
			tmp = 2;
		} else if(b[2] == 0){
			tmp = 3;
		} else {
			tmp = 1;
		}
		
		for(int i = 0; i < 5; i++){
			cout << ((a[i] == tmp)? "1" : "2") << endl;
		}
		free(b);
	}
	
	return 0;
}

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

int main(){
	int hand[5],num[3],result[5],lose;
  while(cin>>hand[0]>>hand[1]>>hand[2]>>hand[3]>>hand[4]){
		for(int i=0;i<3;i++){
			num[i] = 0;
			result[i] = 0;
		}
		for(int i=0;i<5;i++){
			num[hand[i]-1]++;
		}
		if(num[0]*num[1]*num[2] == 0 
			 && (num[0]+1)*(num[1]+1)*(num[2]+1) != 6){
			for(lose = 0;num[lose] != 0;lose++);
			lose%=3;
			for(int i=0;i<5;i++){
				result[i] = (hand[i] == lose) ? 2 : 1;
			}
		}
		else{
			for(int i=0;i<5;i++)
				result[i] = 3;
		}
		for(int i=0;i<5;i++)
			cout<<result[i]<<endl;
	}
  return 0;
}