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<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
  int i,j;
  vi hand(5);
  while(scanf("%d",&hand[0])!=EOF){
    vi n(3,0);
    hand[0]--;
    n[hand[0]]++;
    rep(i,4){
      cin>>hand[1+i];
      hand[1+i]--;
      n[hand[1+i]]++;
    }
    if(n[0]&&n[1]&&n[2])
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]==5 || n[1]==5 || n[2]==5)
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]&&n[1])//gu choki                      
      rep(i,5)
        if(hand[i])cout<<"2"<<endl;
        else cout<<"1"<<endl;
    else if(n[0]&&n[1])//gu pa                         
      rep(i,5)
        if(hand[i])cout<<"1"<<endl;
        else cout<<"2"<<endl;
    else
      rep(i,5)
        if(hand[i]==1)cout<<"1"<<endl;
        else cout<<"2"<<endl;
  }
}

C++: #include<iostream>
using namespace std;
#define GOO 1
#define CHO 2
#define PA 3
#define WIN 1
#define LOSE 2
#define EVEN 3
int main()
{
    while(true)
    {
        int field[5] ={};
        int te[5] = {};
        bool fin= false;
        cin >> te[0];
        if(te[0] == 0)break;
        field[te[0] ] = 1;
        for(int i=1;i<5;i++)
        {
            cin >> te[i];
            field[te[i]] = 1;
            //if(cin.eof()){fin = true; break;}
        }
        if(fin)break;


        //  aiko
        int tekazu = 0;
        for(int i=1;i<=3;i++)
        {
            tekazu += field[i];
        }
        //cout << tekazu << endl;
        if((tekazu == 3) || (tekazu == 1) )
        {
            for(int i=0;i<5;i++){ cout << EVEN << endl;}
            continue;
        }
        if(field[GOO] == 0)
        {
            for(int i=0;i<5;i++)
            {
                if(te[i] == CHO) cout << WIN<<endl;
                else cout << LOSE << endl;
            }
        }
        if(field[CHO] == 0)
        {
            for(int i=0;i<5;i++)
            {
                if(te[i] == PA) cout << WIN<<endl;
                else cout << LOSE << endl;
            }
        }
        if(field[PA] == 0)
        {
            for(int i=0;i<5;i++)
            {
                if(te[i] == GOO) cout << WIN<<endl;
                else cout << LOSE << endl;
            }
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	while(1){
		int d[5]={},kd[4]={},c=0;
		cin>>d[0];
		if(d[0]==0) break;
		rep(i,1,5) cin>>d[i];
		rep(i,0,5) if(kd[d[i]]==0) kd[d[i]]++;
		rep(i,1,4) if(kd[i]) c++;
		//o(c);
		if(c==1||c==3) rep(i,0,5) o(3);
		else if(kd[1]==1&&kd[2]==1){
			rep(i,0,5){
				if(d[i]==1) o(1);
				else o(2);
			}
		}else if(kd[2]==1&&kd[3]==1){
			rep(i,0,5){
				if(d[i]==2) o(1);
				else o(2);
			}
		}else if(kd[3]==1&&kd[1]==1){
			rep(i,0,5){
				if(d[i]==3) o(1);
				else o(2);
			}
		}
	}
}

C++: #include <stdio.h>
int main(){
    int d[5],a[4];
    while(1){
        scanf("%d",&d[0]);
        if(d[0]==0)return 0;
        a[1]=a[2]=a[3]=0;
        a[d[0]]++;
        for(int i=1;i<=4;i++){
            scanf("%d",&d[i]);
            a[d[i]]++;
        }
        if(a[1]==0){
            if(a[2]==0||a[3]==0)for(int i=0;i<5;i++)printf("3\n");
            else for(int i=0;i<5;i++)printf("%c\n",d[i]==2?'1':'2');
        }
        else if(a[3]==0){
            if(a[2]==0||a[1]==0)for(int i=0;i<5;i++)printf("3\n");
            else for(int i=0;i<5;i++)printf("%c\n",d[i]==1?'1':'2');
        }
        else if(a[2]==0){
            if(a[1]==0||a[3]==0)for(int i=0;i<5;i++)printf("3\n");
            else for(int i=0;i<5;i++)printf("%c\n",d[i]==3?'1':'2');
        }
        else for(int i=0;i<5;i++)printf("3\n");
    }
}

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

int main(){
	int human[5];
	while(cin>>human[0],human[0]){
		bool hand[3]={};
		for(int i=1;i<5;i++){
			cin>>human[i];
			if(human[i]==1) hand[0]++;
			else if(human[i]==2) hand[1]++;
			else hand[2]++;
		}
if((hand[0]==true&&hand[0]==hand[1]&&hand[0]==hand[2])||(hand[0]==false&&hand[0]==hand[1])||(hand[0]==false&&hand[0]==hand[2])||(hand[1]==false&&hand[1]==hand[2])){
	for(int i=0;i<5;i++)cout<<'3'<<endl;
}
		else if(hand[0]==true&&hand[0]==hand[1]){
			for(int i=0;i<5;i++){
				if(human[i]==1)cout<<'1'<<endl;
				else cout<<'2'<<endl;
			}
		}
		else if(hand[0]==true&&hand[0]==hand[2]){
			for(int i=0;i<5;i++){
				if(human[i]==3)cout<<'1'<<endl;
				else cout<<'2'<<endl;
			}
		}
		else if(hand[1]==true&&hand[1]==hand[2]){
			for(int i=0;i<5;i++){
				if(human[i]==2)cout<<'1'<<endl;
				else cout<<'2'<<endl;
			}
		}
	}
	return 0;
}

C++: #include<stdio.h>

int main(){

int p[6];
int P=0;
bool f=true;
while(1){
scanf("%d",&p[0]);if(p[0]==0)break;
scanf("%d",&p[1]);if(p[1]==0)break;
scanf("%d",&p[2]);if(p[2]==0)break;
scanf("%d",&p[3]);if(p[3]==0)break;
scanf("%d",&p[4]);if(p[4]==0)break;
P=0;f=true;
for(int i=0;i<5;i++){
if(p[i]==1)f=false;
}
if(f==true){P=2;}

f=true;
for(int i=0;i<5;i++){
if(p[i]==2)f=false;
}
if(f==true){P=3;}

f=true;
for(int i=0;i<5;i++){
if(p[i]==3)f=false;
}
if(f==true){P=1;}
f=true;
for(int i=0;i<4;i++)
if(p[i]!=p[i+1])f=false;
if(f==true)P=0;

for(int i=0;i<5;i++)
{if(P!=0){if(p[i]==P)printf("1\n");else printf("2\n");}
else if(P==0)printf("3\n");
}
}
return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[5],i,flg,j;
	while(1){
		int g=0,t=0,p=0;
		int mflg,kflg;
		int aaflg;
		flg=0;
		for(i=0;i<5;i++){
			cin>>a[i];
			if(a[i]==0) break;
			if(a[i]==1) g=1;
			else if(a[i]==2) t=1;
			else p=1;
		}
		if(a[0]==0) break;
		aaflg=0;
		for(i=1;i<5;i++) {
			if(a[0]!=a[i]) aaflg=1;
		}
		if(g==1 && t==1 && p==1 || aaflg==0) {
			for(i=0;i<5;i++) cout<<"3"<<endl;
		}
		else {
			for(i=0;i<5;i++){
				mflg=0;
				kflg=0;
				for(j=0;j<5;j++){
					if(a[i]==a[j]) ;
					else if(a[i]==1 && a[j]==3 || a[i]==2 && a[j]==1 || a[i]==3 && a[j]==2) mflg=1;
					else kflg=1;
				}
				if(mflg==1) cout<<"2"<<endl;
				else cout<<"1"<<endl;
			}
		}
	}	
	return 0;
}