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>
int main(){
	while(1){
		std::vector<int> vec(5);
		std::vector<int> vec2(5);
		int a=0;
		std::cin>>a;
		if(a==0)break;
		vec[0]=a;
		int d=0,e=0,f=0;
		if(a==1)d++;
		if(a==2)e++;
		if(a==3)f++;
		for(int i=1;i<5;i++){
			int b;
			std::cin>>b;
			if(b==1)d++;
			if(b==2)e++;
			if(b==3)f++;
			
		}
		if(d>=1&&e>=1&&f>=1||d==5||f==5||e==5){
			for(int i=0;i<5;i++){
				vec2[i]=3;
			}
		}else if(d>=1&&e>=1&&f==0){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=1;
				if(vec[i]==2)vec2[i]=2;
			}
		}else if(d>=0&&e>=1&&f==1){
			for(int i=0;i<5;i++){
				if(vec[i]==2)vec2[i]=1;
				if(vec[i]==3)vec2[i]=2;
			}
		}else if(d>=1&&e>=0&&f==1){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=2;
				if(vec[i]==3)vec2[i]=1;
			}
		}
		for(int i=0;i<5;i++){
			std::cout<<vec2[i]<<std::endl;
		}
	}
	return 0;
}

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

int main()
{
  vector<int> p(5), r(5);
  int i, t;
  while (cin>>p[0]>>p[1]>>p[2]>>p[3]>>p[4], p[0]) {
    t = 0;
    for (i = 0; i < 5; i++) {
      if (p[i] == 3 && !(t&4)) t ^= 4;
      else if (p[i] != 3 && !(t&p[i])) t ^= p[i];
    }
    if (t == (1+2)) for (i = 0; i < 5; i++) if (p[i] == 1) r[i] = 1; else r[i] = 2;
    else if (t == (2+4)) for (i = 0; i < 5; i++) if (p[i] == 2) r[i] = 1; else r[i] = 2;
    else if (t == (4+1)) for (i = 0; i < 5; i++) if (p[i] == 3) r[i] = 1; else r[i] = 2;
    else for (i = 0; i < 5; i++) r[i] = 3;

    for (i = 0; i < 5; i++) cout<<r[i]<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	while (true)
	{
		int t[5];
		for (int i = 0; i < 5; ++i)
			scanf("%d", t+i);
		if (t[0] == 0)
			break;

		int c[3];
		memset(c, 0, sizeof(c));
		for (int i = 0; i < 5; ++i)
			++c[t[i]-1];
		if (c[0] && c[1] && c[2]
		|| c[0] == 5 || c[1] == 5 || c[2] == 5)
			for (int i = 0; i < 5; ++i)
				puts("3");
		else
			for (int i = 0; i < 5; ++i)
				if (c[(t[i])%3])
					puts("1");
				else
					puts("2");
	}

	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	bool a,b,c;//グーチョキパー
	int hand[5];
	while(cin>>hand[0], hand[0]){
		for(int i=1;i<5;i++)
			cin>>hand[i];
		a=b=c=false;
		for(int i=0;i<5;i++){
			if(hand[i]==1)a=true;
			else if(hand[i]==2)b=true;
			else c=true;
		}
		for(int i=0;i<5;i++){
			if(a&&b&&c || a&&!b&&!c || !a&&b&&!c || !a&&!b&&c){
				cout<<3<<endl;
				continue;
			}
			if(hand[i]==1){
				if(b)cout<<1;
				else cout<<2;
			}
			else if(hand[i]==2){
				if(c)cout<<1;
				else cout<<2;
			}
			else{
				if(a)cout<<1;
				else cout<<2;
			}
			cout<<endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int cnt[4];
int a[5];
main()
{
	while(cin>>a[0],a[0])
	{
		cnt[1]=cnt[2]=cnt[3]=0;
		int C=0;
		for(int i=1;i<5;i++)cin>>a[i];
		for(int i=0;i<5;i++)C+=!cnt[a[i]]++;
		if(C==2)
		{
			if(cnt[1]&&cnt[2])
			{
				for(int i=0;i<5;i++)
				{
					cout<<2-(a[i]==1)<<endl;
				}
			}
			else if(cnt[1]&&cnt[3])
			{
				for(int i=0;i<5;i++)
				{
					cout<<2-(a[i]==3)<<endl;
				}
			}
			else
			{
				for(int i=0;i<5;i++)
				{
					cout<<2-(a[i]==2)<<endl;
				}
			}
		}
		else cout<<"3\n3\n3\n3\n3\n";
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define N 5

using namespace std;

void RockWin(vector<int>&);
void ScissorsWin(vector<int>&);
void PaperWin(vector<int>&);
void Draw(vector<int>&);

int main(){
  int i, x;
  vector<int> data;
  vector<int>::iterator rock, scissors, paper;

  while(1){
    cin >> x;
    if(x == 0) break;
    data.push_back(x);
    for(i=1; i<N; ++i){
      cin >> x;
      data.push_back(x);
    }

    rock = find(data.begin(), data.end(), 1);
    scissors = find(data.begin(), data.end(), 2);
    paper = find(data.begin(), data.end(), 3);

    if(rock != data.end() && scissors != data.end() && paper == data.end())
      RockWin(data);
    else if(rock == data.end() && scissors != data.end() && paper != data.end())
      ScissorsWin(data);
    else if(rock != data.end() && scissors == data.end() && paper != data.end())
      PaperWin(data);
    else
      Draw(data);

    for(i=0; i<data.size(); ++i)
      cout << data[i] << endl;

    data.clear();
  }

  return 0;
}

void RockWin(vector<int>& data){
  int i;
  for(i=0; i<data.size(); ++i){
    if(data[i] == 1) data[i] = 1;
    else data[i] = 2;
  }
}

void ScissorsWin(vector<int>& data){
  int i;
  for(i=0; i<data.size(); ++i){
    if(data[i] == 2) data[i] = 1;
    else data[i] = 2;
  }
}

void PaperWin(vector<int>& data){
  int i;
  for(i=0; i<data.size(); ++i){
    if(data[i] == 3) data[i] = 1;
    else data[i] = 2;
  }
}

void Draw(vector<int>& data){
  int i;
  for(i=0; i<data.size(); ++i)
    data[i] = 3;
}

C++: #include<iostream>
#include<vector>
int main(){
	while(1){
		std::vector<int> vec(5);
		std::vector<int> vec2(5);
		int a=0;
		std::cin>>a;
		if(a==0)break;
		vec[0]=a;
		int d=0,e=0,f=0;
		if(a==1)d++;
		if(a==2)e++;
		if(a==3)f++;
		for(int i=1;i<5;i++){
			int b;
			std::cin>>b;
			if(b==1)d++;
			if(b==2)e++;
			if(b==3)f++;
			
		}
		if(d>=1&&e>=1&&f>=1||d==5||f==5||e==5){
			for(int i=0;i<5;i++){
				vec2[i]=3;
			}
		}else if(d>=1&&e>=1&&f==0){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=1;
				if(vec[i]==2)vec2[i]=2;
			}
		}else if(d>=0&&e>=1&&f==1){
			for(int i=0;i<5;i++){
				if(vec[i]==2)vec2[i]=1;
				if(vec[i]==3)vec2[i]=2;
			}
		}else if(d>=1&&e>=0&&f==1){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=2;
				if(vec[i]==3)vec2[i]=1;
			}
		}
		for(int i=0;i<5;i++){
			std::cout<<vec2[i]<<std::endl;
		}
	}
	return 0;
}

C++: 
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

bool win(int a, int b)
{
  return ((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1));     
}
int main()
{
  while (true) {
    int a[5];
    for (int i = 0; i < 5; i++) {
      scanf("%d ", a + i);
      //printf("%d\n", a[i]);
    }
    if (a[0] == 0) {break;}
  
  
    bool f[] = {false, false, false};
    bool flag = true;
    f[a[0] - 1] = true;
    for (int i = 1; i < 5; i++) {
      if (a[i] != a[i - 1]) {
	flag = false;
      }
      f[a[i] - 1] = true;
    }
    bool aiko = false;
    if (flag) {
      aiko = true;
    } 
    for (int i = 0; i < 3; i++) {
      if (!f[i]) {goto next;}
    }
    aiko = true;
  next:;
    /*for (int i = 0; i < 5; i++) {
      printf("%d\n", a[i]);
      }*/
    for (int i = 0; i < 5; i++) {
      if (aiko) {printf("3\n");}
      else {
	for (int j = 0; j < 5; j++) {
	  if (i == j) {continue;}
	  if (a[i] == a[j]) {continue;}
	  if (win(a[i], a[j])) {
	    printf("1\n");
	    break;
	  } else if (win(a[j], a[i])) {
	    printf("2\n");
	    break;
	  }
	}
      }
    }
  }
}