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<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[1000001];//動的計画法
int prime[1000001];
int main(){
    int hand[5];
    int gcnt,ccnt,pcnt;
    int ans[5];
    while(cin>>hand[0],hand[0]){
        gcnt=ccnt=pcnt=0;
        for(int i=1;i<5;i++){
            cin>>hand[i];
        }
        for(int i=0;i<5;i++){
            if(hand[i]==1) gcnt++;
            else if(hand[i]==2) ccnt++;
            else pcnt++;
        }
        if(gcnt>0&&ccnt>0&&pcnt>0){
            for(int i=0;i<5;i++){
                ans[i]=3;
                cout<<ans[i]<<endl;
            }
            continue;
        }else if(gcnt==5||ccnt==5||pcnt==5){
             for(int i=0;i<5;i++){
                ans[i]=3;
                cout<<ans[i]<<endl;
            }
            continue;
        }else{
            if(pcnt==0){
                for(int i=0;i<5;i++){
                    if(hand[i]==1) ans[i]=1;
                    else ans[i]=2;
                }
            }else if(gcnt==0){
                for(int i=0;i<5;i++){
                    if(hand[i]==2) ans[i]=1;
                    else hand[i]=2;
                }
            }else{
                for(int i=0;i<5;i++){
                    if(hand[i]==3) ans[i]=1;
                    else hand[i]=2;
                }
            }
            for(int i=0;i<5;i++){
                cout<<ans[i]<<endl;
            }
        }
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

void Aiko ( void ) ;
void Shori ( int ) ;

int jan[4] = {0};
int mem[5];

int main () {
	
	while (cin >> mem[0],mem[0]){
		int hoge = 0;
		
		for ( int i = 0; i < 4; i++ ) {
			jan[i] = 0;
		}
		
		for ( int i = 1; i < 5; i++ ) {
			cin >> mem[i];
			jan[mem[i]]++;
		}
		
		for ( int i = 1; i < 4; i++ ) {
			if ( jan[i] )	hoge++;
		}
		
		if ( hoge != 2 ){
			Aiko ();
		} else {
			for ( int i = 1; i < 4; i++ ) {
				if ( !jan[i] ) {
					if ( jan[i] == 1 ) {
						Shori (2);
					} else if ( jan[i] == 2 ) {
						Shori (3);
					} else {
						Shori (1);
					}
					break;
				}
			}
		}
	}
	return 0;
}

void Aiko () {
	for ( int i = 0; i < 5; i++ ) {
		cout << "3" << endl;
	}
}

void Shori (int Win) {
	for ( int i = 0; i < 5; i++ ) {
		if ( mem[i] == Win ) {
			cout << "1" << endl;
		} else {
			cout << "2" << endl;
		}
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
void func(int in[],int a,int b){
  rep(i,5){
    if(in[i]==a)cout<<1<<endl;
    else cout<<2<<endl;
  }
}
int main(){
  int in[5];
  while(cin>>in[0],in[0]){
    rep(i,4)cin>>in[i+1];
    int c1=0,c2=0,c3=0;
    rep(i,5){
      if(in[i]==1)c1++;
      if(in[i]==2)c2++;
      if(in[i]==3)c3++;
    }
    if((c1&&c2&&c3)||c1==5||c2==5||c3==5)rep(i,5)cout<<3<<endl;
    else{
      if(!c1)func(in,2,3);
      else if(!c2)func(in,3,1);
      else if(!c3)func(in,1,2);
    }
  }
}

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

int main(void){
    for(;;){

	int a[5];
	int b[5];
	int r=0,p=0,s=0;
	for(int i=0;i<5;i++){
        cin>>a[i];
        if(a[i]==0)break;
        else if(a[i]==1)r++;
        else if(a[i]==2)s++;
        else if(a[i]==3)p++;

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


	if(r>0&&p>0&&s>0){
        for(int i=0;i<5;i++){
            b[i]=3;
     //       cout<<a[i]<<"-";
        }
	}
	else if(r>0&&p==0&&s==0){
        for(int i=0;i<5;i++){
            b[i]=3;
       //     cout<<a[i]<<"--";
        }
	}
	else if(r==0&&p>0&&s==0){
        for(int i=0;i<5;i++){
            b[i]=3;
     //       cout<<a[i]<<"---";
        }
	}
	else if(r==0&&p==0&&s>0){
        for(int i=0;i<5;i++){
            b[i]=3;
     //       cout<<a[i]<<".";
        }
	}
	else if(r==0&&s>0&&p>0){
        for(int i=0;i<5;i++){
            if(a[i]==2)b[i]=1;
            else if(a[i]==3)b[i]=2;
      //      cout<<a[i]<<"..";
        }
	}
	else if(r>0&&s==0&&p>0){
        for(int i=0;i<5;i++){
            if(a[i]==3)b[i]=1;
            else if(a[i]==1)b[i]=2;
      //      cout<<a[i]<<"...";
        }
	}
	else if(r>0&&s>0&&p==0){
        for(int i=0;i<5;i++){
            if(a[i]==1)b[i]=1;
            else if(a[i]==2)b[i]=2;
      //     cout<<a[i]<<"....";
        }
	}
	//cout<<endl;
	for(int i=0;i<5;i++){
        cout<<b[i]<<endl;
	}
}

	return 0;
}

C++: #include <stdio.h>
int d[5]; bool p[3];
int main() {
	while (true) {
		for (int i = 0; i < 3; i++) p[i] = false;
		for (int i = 0; i < 5; i++) {
			scanf("%d", &d[i]);
			if (d[i] == 0) break;
			p[d[i] - 1] = true;
		}
		if (d[0] == 0) break;
		if (p[0] && p[1] && p[2]) {
			for (int i = 0; i < 5; i++) {
				printf("3\n");
			}
		}
		else {
			if (p[0] && p[1]) {
				for (int i = 0; i < 5; i++) {
					if (d[i] == 1) {
						printf("1\n");
					}
					else {
						printf("2\n");
					}
				}
			}
			if (p[1] && p[2]) {
				for (int i = 0; i < 5; i++) {
					if (d[i] == 2) {
						printf("1\n");
					}
					else {
						printf("2\n");
					}
				}
			}
			if (p[2] && p[0]) {
				for (int i = 0; i < 5; i++) {
					if (d[i] == 3) {
						printf("1\n");
					}
					else {
						printf("2\n");
					}
				}
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
void func(int in[],int a,int b){
  rep(i,5){
    if(in[i]==a)cout<<1<<endl;
    else cout<<2<<endl;
  }
}
int main(){
  int in[5];
  while(cin>>in[0],in[0]){
    rep(i,4)cin>>in[i+1];
    int c1=0,c2=0,c3=0;
    rep(i,5){
      if(in[i]==1)c1=1;
      if(in[i]==2)c2=1;
      if(in[i]==3)c3=1;
    }
    if(c1+c2+c3==3)rep(i,5)cout<<3<<endl;
    else{
      if(!c1)func(in,2,3);
      else if(!c2)func(in,3,1);
      else if(!c3)func(in,1,2);
    }
  }
}

C++: #include <iostream>
using namespace std;
 
int main() {
while(1){
	int a[5];
	cin>>a[0];
	if(a[0]==0){break;}
	for(int i = 1;i<5;i++){cin>>a[i];}
	int g[3];
	for(int i = 0;i<3;i++){g[i]=0;}
	for(int i = 0;i<5;i++){
		g[a[i]-1]++;
	}
	int aiko = 0;
	for(int i = 0;i<3;i++){
		if(g[i]==0){aiko++;}
	}
	if(aiko==0||aiko ==2){
		for(int i = 0;i<5;i++){cout<<3<<endl;}
	}
	else{
		int kati;
		if(g[0]==0){
			kati = 2;
		}
		else if(g[1]==0){
			kati = 3;
		}
		else{
			kati = 1;
		}
		for(int i = 0;i<5;i++){
			if(a[i]==kati){cout << 1<<endl;}
			else{cout << 2 << endl;}
		}
	}
}
	return 0;
}