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>
using namespace std;
int main()
{
	while (true){
		int a[5];
		int f[4] = { 0 };
		for (int i = 0; i < 5; i++){
			cin >> a[i];
			if (i == 0 && a[i] == 0){
				return 0;
			}
			f[a[i]]++;
		}
		if (f[1]>0 && f[2] > 0 && f[3] > 0|| f[1] > 5 || f[2] > 5 || f[3] > 5){
			for (int i = 0; i < 5; i++){
				cout << "3" << endl;
			}
		}
		else if (f[1]>0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				if (a[i] == 1){
					cout << "2" << endl;
				}
				else{
					cout << "1" << endl;
				}
			}
		}
		else if (f[2]>0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				if (a[i] == 3){
					cout << "2" << endl;
				}
				else{
					cout << "1" << endl;
				}
			}
		}
		else{
			for (int i = 0; i < 5; i++){
				cout << a[i] << endl;
			}
		}
	}
}

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

int main(){
  int te[5];
  int wi[3];
  bool ju[3];
  while(cin>>te[0] && te[0]){
    for(int i=0;i<3;i++) ju[i]=0;
    ju[te[0]-1]=1;
    for(int i=1;i<5;i++){
      cin >>te[i];
      ju[te[i]-1]=1;
    }
    int co=0;
    for(int i=0;i<3;i++)
      if(ju[i]==1) 
	co++;
    if(co==1 || co==3)
      for(int i=0;i<3;i++) 
	wi[i]=3;
    else{
      if(ju[0]==1 && ju[1]==1) wi[0]=1,wi[1]=2;
      else if(ju[1]==1&&ju[2]==1) wi[1]=1,wi[2]=2;
      else wi[2]=1,wi[0]=2;
    }
    for(int i=0;i<5;i++)
      cout<<wi[te[i]-1]<<endl;
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h[5];
    while(true) {
        cin >> h[0];
        if(h[0] == 0) break;
        
        cin >> h[1] >> h[2] >> h[3] >> h[4];
        
        int table[3];
        for(int i = 0; i < 3; i++) {
            table[i] = 0;
        }
        for(int i = 0; i < 5; i++) {
            table[h[i]-1] = 1;
        } 

        int s = table[0] + table[1] + table[2];
        int win, lose;
        if(s != 2) {
            for(int i = 0; i < 5; i++) {
                cout << 3 << endl;
            }
        } else {
            if(table[0] == 0) {
                win = 2;
                lose = 3;
            } else if(table[1] == 0) {
                win = 3;
                lose = 1;
            } else if(table[2] == 0) {
                win = 1;
                lose = 2;
            }
            for(int i = 0; i < 5; i++) {
                if(h[i] == win) {
                    cout << 1 << endl;
                } else {
                    cout << 2 << endl;
                }
            }
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#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>
int main(){
	while(1){
		int n,h[3]={0},i,a;
		std::cin>>n;
		if(!n)break;
		h[n-1]=1;
		for(i=1;i<5;i++){
			std::cin>>n;
			h[n-1]|=1<<i;
		}
		for(i=0;i<5;i++,a=0){
			for(n=0;!(h[n]&1<<i);n++);
			if(h[(n+1)%3])a+=1;
			if(h[(3+n-1)%3])a+=2;
			std::cout<<(a?a:3)<<'\n';
		}
	}
	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	int y = 0;
	for (int u = 0; u < 200; u++)
	{
		int a[6],h1 = 0,h2 = 0,h3 = 0;

		for (int i = 0; i < 5; i++)
		{
			a[i] = 0;
		}
		for (int i = 0; i < 5; i++)
		{
			cin >> a[i];
			if (a[i] == 0)
			{
				y = -1;
				break;
			}
		}
		if (y == -1)
		{
			break;
		}

		for (int i = 0; i < 5; i++)
		{
			if (a[i] == 1)
			{
				h1 += 1;
			}
			else if (a[i] == 2)
			{
				h2 += 1;
			}
			else if (a[i] == 3)
			{
				h3 += 1;
			}
		}


		int ke = 0;
		if (h1 != 0 && h2 != 0)
		{
			if (h3 != 0)
			{
				ke += 1;
				for (int gg = 0; gg < 5; gg++)
				{
					cout << '3' << endl;
				}
			}
		}

		if (h1 == 0 && ke == 0)
		{
			for (int j = 0; j < 5; j++)
			{
				if (a[j] == 2)
				{
					cout << '1' << endl;
				}
				else
				{
					cout << '2' << endl;
				}
			}
		}
		else if (h2 == 0)
		{
			for (int j = 0; j < 5; j++)
			{
				if (a[j] == 1)
				{
					cout << '2' << endl;
				}
				else
				{
					cout << '1' << endl;
				}
			}
		}
		else if (h3 == 0)
		{
			for (int j = 0; j < 5; j++)
			{
				if (a[j] == 1)
				{
					cout << '1' << endl;
				}
				else
				{
					cout << '2' << endl;
				}
			}
		}
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> res = {
    {},
    {0,3,0,1,0,2,0,3},
    {0,0,3,2,0,0,1,3},
    {0,0,0,0,3,1,2,3}
};
int main() {
    int a[5], st;
    while (1) {
        st = 0;
        for (int i=0; i<5; ++i) {
            if (cin >> a[i] && a[i]) ; // pass
            else return 0;
            st |= 1 << (a[i] - 1);
        }
        for (int i=0; i<5; ++i) {
            cout << res[a[i]][st] << endl;
        }
    }
}

C++: #include<stdio.h>
int main(void)
{
	int guu=0,tyoki=0,paa=0;
	int a[5]={0};
	int i=0;
	int n=1;
	while (n!=0)
	{
		for (i=0;i<5;i++)
		{
			scanf("%d",&a[i]);
			n=a[0];
			if (n==0)
			{
				break;
			}
			else if (a[i]==1)
			{
				guu=1;
			}
			else if (a[i]==2)
			{
				tyoki=1;
			}
			else if (a[i]==3)
			{
				paa=1;
			}
		}
		if(guu==1)
		{
			if (tyoki==1)
			{
				if (paa==1)
				{
					for (i=0;i<5;i++)
					{
						printf("3\n");
					}
				}
				else
				{
					for (i=0;i<5;i++)
					{
						if (a[i]==1)
						{
							printf("1\n");
						}
						else
						{
							printf("2\n");
						}
					}
				}
			}
			else if (paa==1)
			{
				for (i=0;i<5;i++)
				{
					if (a[i]==1)
					{
						printf("2\n");
					}
					else
					{
						printf("1\n");
					}
				}
			}
			else
			{
				for (i=0;i<5;i++)
				{
					printf("3\n");
				}
			}
		}
		else if (tyoki==1)
		{
			if (paa==1)
			{
				for (i=0;i<5;i++)
				{
					if (a[i]==2)
					{
						printf("1\n");
					}
					else
					{
						printf("2\n");
					}
				}
			}
			else
			{
				for (i=0;i<5;i++)
				{
					printf("3\n");
				}
			}
		}
		else if (paa==1)
		{
			for (i=0;i<5;i++)
			{
				printf("3");
				a[i]=0;
			}
		}
		guu=0;
		tyoki=0;
		paa=0;
		n=1;
	}
	return 0;
}