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 <vector>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(c) (c).begin(), (c).end()
#define Contains(c, x) (find(all(c), (x)) != (c).end())
using namespace std;
int main()
{
    vector<int> a(5), b(5);
    while (true) {
        cin >> a[0]; if (a[0] == 0) break;
        REP(i, 1, 5) cin >> a[i];
        if (Contains(a, 1) && Contains(a, 2) && Contains(a, 3)) {
            rep(i, 5) b[i] = 3;
        }
        else if (count(all(a), a[0]) == 5) {
            rep(i, 5) b[i] = 3;
        }
        else {
            if (!Contains(a, 1))
                rep(i, 5) b[i] = (a[i] == 2) ? 1 : 2;
            else if (!Contains(a, 2))
                rep(i, 5) b[i] = (a[i] == 3) ? 1 : 2;
            else
                rep(i, 5) b[i] = (a[i] == 1) ? 1 : 2;
        }
        rep(i, 5) cout << b[i] << endl;
    }
    return 0;
}

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

int main()
{
  int hand[5];

  for(;cin>>hand[0],hand[0];)
    {
      int ans[5]={3,3,3,3,3};
      bool check[4]={false,false,false,false};
      
      for(int i=1;i<5;i++)
	{
	  cin>>hand[i];
	  check[hand[i]]=true;
	}
      for(int i=0;i<5;i++)
	{
	  if(hand[i]==1)
	    {
	      if(check[2])
		ans[i]=1;
	      if(check[3])
		ans[i]=2;
	    }
	 else if(hand[i]==2)
	    {
	      if(check[3])
		ans[i]=1;
	      if(check[1])
		ans[i]=2;
	    }
	 else if(hand[i]==3)
	    {
	      if(check[1])
		ans[i]=1;
	      if(check[2])
		ans[i]=2;
	    }	  
	}

      for(int i=1;i<4;i++)
	{
	  if(!check[i])
	    {
	      for(int j=0;j<5;j++)
		cout<<ans[j]<<endl;
	      break;
	    }
	  if(i==3)
	    {
	      for(int j=0;j<5;j++)
		cout<<"3"<<endl;
	    }
	}
    }
}

C++: //04
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  for(;;){
    int h[5];
    int k[4]={};
    for(int i=0;i<5;i++){
      cin>>h[i];
      if(h[i]==0)return 0;
      k[h[i]]=1;
    }
    if(count(k,k+4,1)!=2){
      for(int i=0;i<5;i++){
	cout<<3<<endl;
      }
    }else{
      int n=find(k+1,k+4,0)-k;
      for(int i=0;i<5;i++){
	cout<<((n%3+1==h[i])?1:2)<<endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        vector<int> a(5);
        vector<int> b(4);
        for(int i=0; i<5; ++i){
            cin >> a[i];
            if(a[i] == 0)
                return 0;
            ++ b[a[i]];
        }

        if(b[1] == 5 || b[2] == 5 || b[3] == 5 || (b[1] > 0 && b[2] > 0 && b[3] > 0)){
            a.assign(5, 3);
        }else{
            if(b[1] == 0){
                replace(a.begin(), a.end(), 2, 1);
                replace(a.begin(), a.end(), 3, 2);
            }else if(b[2] == 0){
                replace(a.begin(), a.end(), 1, 2);
                replace(a.begin(), a.end(), 3, 1);
            }
        }

        for(int i=0; i<5; ++i)
            cout << a[i] << endl;
    }
}

C++: #include<stdio.h>

int main(void){
  int a[5],i;
  while(scanf("%d",&a[0]),a[0]!=0){
    int used[3];
    used[0]=used[1]=used[2]=0;
    used[a[0]-1]=1;
    for(i=1;i<5;i++)scanf("%d",&a[i]),used[a[i]-1]=1;
    int sum=used[0]+used[1]+used[2];
    if(sum!=2){
      for(i=0;i<5;i++)printf("3\n");
      continue;
    }
    for(i=0;i<5;i++){
      switch(a[i]){
      case 1:
	if(used[1])printf("1\n");
	else printf("2\n");
	break;
      case 2:
	if(used[2])printf("1\n");
	else printf("2\n");
	break;
      case 3:
	if(used[0])printf("1\n");
	else printf("2\n");
	break;
      }
    }
  }
}

C++: #include<iostream>

using namespace std; 
int main()
{
  int in[5], a[3]; 
  while(true)
  {
    a[0] = a[1] = a[2] = 0;
    cin >> in[0];
    if(!in[0])
      break;
    cin >> in[1] >> in[2] >> in[3] >> in[4];
    for(int i = 0; i < 5; i++)
      a[in[i] - 1]++;
    if(a[0] > 0 && a[1] > 0 && a[2] > 0
        || !a[0] && !a[1] || !a[1] && !a[2] || !a[2] && !a[0])
    {
      for(int i = 0; i < 5; i++)
        cout << 3 << endl;
      continue;
    }
    if(!a[0])
    {
      for(int i = 0; i < 5; i++)
      {
        cout << (in[i] == 2 ? 1 : 2) << endl;
      }
      continue;
    }
    if(!a[1])
    {
      for(int i = 0; i < 5; i++)
      {
        cout << (in[i] == 3 ? 1 : 2) << endl;
      }
      continue;
    } 
    if(!a[2])
    {
      for(int i = 0; i < 5; i++)
      {
        cout << (in[i] == 1 ? 1 : 2) << endl;
      }
      continue;
    }
  }
}

C++: #include <cstdio>
#include <vector>

using namespace std;

vector<int> hand;

int main(){
	int self;
	while(1){
		hand.clear();
		scanf("%d",&self);
		if(self == 0){break;}
		hand.push_back(self);
		for(int i = 1;i < 5;i++){
			scanf("%d",&self);
			hand.push_back(self);
		
		}
		bool flag[4];
		flag[0] = false;
		flag[1] = false;
		flag[2] = false;
		flag[3] = false;
		vector<int>::iterator it;
		for(it = hand.begin();it < hand.end(); it++){
			flag[*it] = true;
		}
		int re[4];
		if( (flag[1] && flag[2] && flag[3]) || (flag[1] && !flag[2] && !flag[3]) || (!flag[1] && flag[2] && !flag[3]) || (!flag[1] && !flag[2] && flag[3]) ){
			re[1] = 3; // O[
			re[2] = 3; // `L
			re[3] = 3; // p[
		}
		if(flag[1] && flag[2] && !flag[3]){
			re[1] = 1; // O[
			re[2] = 2; // `L
			re[3] = 0; // p[
		}
		if(flag[1] && !flag[2] && flag[3]){
			re[1] = 2; // O[
			re[2] = 0; // `L
			re[3] = 1; // p[
		}
		if(!flag[1] && flag[2] && flag[3]){
			re[1] = 0; // O[
			re[2] = 1; // `L
			re[3] = 2; // p[
		}
		for(it = hand.begin();it < hand.end(); it++){
			printf("%d\n",re[*it]);
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int rps[5],res[5];
	while(cin>>rps[0]){
		if(!rps[0])break;
		int f1=0,f2=0,f3=0,max=1,min=3;
		for(int i=1;i<5;++i)cin>>rps[i];
		for(int i=0;i<5;++i){
			if(max<rps[i]) max=rps[i];
			else if(min>rps[i]) min=rps[i];
			if(rps[i]==1) f1=1;
			else if(rps[i]==2) f2=1;
			else if(rps[i]==3) f3=1;
		}
		if((f1&&f2&&f3)||max==min) for(int i=0;i<5;++i)res[i]=3;
		else{
			for(int i=0,w=(max%3>min%3)?2:1;i<5;++i){
				if(rps[i]==min)res[i]=w-1;
				else res[i]=w;
			}
		}
		for(int i=0;i<5;++i)cout<<res[i]<<"\n";
	}
	return 0;
}