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 <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
typedef pair<int,int> P;
const int INF = 1<<29;


int main(){
    while(1){
        int hand[5];
        int gcp[4] = {};
        scanf("%d",&hand[0]);
        if(hand[0]==0)break;

        gcp[hand[0]]++;
        int hand_num = 1;
        for(int i=1;i<5;i++){
            scanf("%d",&hand[i]);
            gcp[hand[i]]++;
            if(gcp[hand[i]]==1){
                hand_num++;
            }
        }
        if(hand_num==2){
            int win;
            if(gcp[1]>0 && gcp[2]>0){
                win = 1;
            }else if(gcp[2]>0 && gcp[3]>0){
                win = 2;
            }else{
                win = 3;
            }
            for(int i=0;i<5;i++){
                if(hand[i]==win){
                    printf("1\n");
                }else{
                    printf("2\n");
                }
            }
        }else{
            for(int i=0;i<5;i++)printf("3\n");
        }
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

const int N=5;

int main(void){
  int cnt[3];
  int h[N];
  
  while (cin >> h[0], h[0]){
    for (int i=1; i<N; i++) cin >> h[i];
    for (int i=0; i<3; i++) cnt[i]=0;
    for (int i=0; i<N; i++) cnt[h[i]-1]++;
    //cout << cnt[0] << " " << cnt[1] << " " << cnt[2] << endl;
    if (cnt[0]+cnt[1]==0 ||
      cnt[1]+cnt[2]==0 ||
      cnt[2]+cnt[0]==0 ||
      cnt[0]*cnt[1]*cnt[2]){
      for (int i=0; i<N; i++){
        cout << 3 << endl;
      }
    } else {
      for (int i=0; i<N; i++){
        cout << (cnt[(h[i]+1)%3]?2:1) << endl;
      }
    }
  }
  return 0;
}

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

int main(){
    int data[4],n[5];
    while(1){
        memset(data,0,sizeof(data));
        cin >> n[0];
        data[n[0]] = 1;
        if(n[0] == 0) break;
        for(int i=1;i<5;i++){
            cin >> n[i];
            data[n[i]] = 1;
        }
        if((data[1] == 1 && data[2] == 1 && data[3] == 1) || (data[1] == 1 && data[2] == 0 && data[3] == 0) || (data[1] == 0 && data[2] == 1 && data[3] == 0) || (data[1] == 0 && data[2] == 0 && data[3] == 1)){
            for(int i=0;i<5;i++) cout << 3 << endl;
        }
        else if(data[1] == 1 && data[2] == 1){
            for(int i=0;i<5;i++){
                if(n[i] == 1) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
        else if(data[2] == 1 && data[3] == 1){
            for(int i=0;i<5;i++){
                if(n[i] == 2) cout << 1 <<endl;
                else cout << 2 <<endl;
            }
        }
        else if(data[1] == 1 && data[3] == 1){
            for(int i=0;i<5;i++){
                if(n[i] == 1) cout << 2 << endl;
                else cout << 1 << endl;
            }
        }
    }
}

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

int main() {
  int p[5];
  while(cin >> p[0], p[0]) {
    for(int i = 1; i < 5; i++) cin >> p[i];
    
    bool flag[3] = {};
    for(int i = 0; i < 5; i++) {
      flag[p[i]-1] = true;
    }

    int win = 0, lose = 0;
    if(flag[0] && flag[1] && flag[2]) {
      win = lose = 0;
    } else if(flag[0] && flag[1]) {
      win = 1, lose = 2;
    } else if(flag[1] && flag[2]) {
        win = 2, lose = 3;
    } else if(flag[2] && flag[0]) {
        win = 3, lose = 1;
    }  
    for(int i = 0; i < 5; i++) {
      if(p[i] == win) p[i] = 1;
      else if(p[i] == lose) p[i] = 2;
      else p[i] = 3;
    }

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

C++: #include<iostream>

using namespace std;

int main() {
	int st[5], res[5];
	int g[3], n = 0;
	int val = 0;
	
	while(1) {
	
		for( int i=0; i<3; i++) g[i] = 0;
		n = 0;
		val = 0; // val -> winner

		// Input
		for( int i=0; i<5; i++) {
			cin >> st[i];
			if(st[i]==0) break;
			if(!g[ st[i]-1 ]) {
				n++;
				g[ st[i]-1 ] = 1;
				if( val==0) val = st[i];
				if( val-1==st[i]) val = st[i];
			}
		}
		if(st[0]==0) break;
		
		if( n==2) {
			for( int i=0; i<5; i++)
				if( val==st[i]) res[i] = 1; else res[i] = 2;
		}else {
			for( int i=0; i<5; i++) res[i] = 3;
		}

		// Output
		for( int i=0; i<5; i++) cout << res[i] << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int RPS[5], R, P, S;
    while (1) {
	R = P = S = 0;
	for (int i = 0; i < 5; i++) {
            cin >> RPS[i];
            if (RPS[0] == 0) break;
            if (RPS[i] == 1) R++;
            else if (RPS[i] == 2) S++;
            else P++;
        }
	if (RPS[0] == 0) break;
        
	if ((R > 0 && S > 0 && P > 0) || R == 5 || S == 5|| P == 5) {
            for (int i = 0; i < 5; i++) {
                cout << "3" << endl;
            }
        } else if (R == 0) {
            for (int i = 0; i < 5; i++) {
                if (RPS[i] == 2) {
                    cout<<"1"<<endl;
                } else {
                    cout<<"2"<<endl;
                }
            }
        } else if (S == 0) {
            for (int i = 0; i < 5; i++) {
                if (RPS[i] == 3) {
                    cout << "1" << endl;
                } else {
                    cout << "2" << endl;
                }
            }
        } else if (P == 0) {
            for (int i = 0; i < 5; i++) {
                if (RPS[i] == 1) {
                    cout << "1" << endl;
                } else {
                    cout << "2" << endl;
                }
            }
        }
    }
    return 0;
}

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