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 <cstdio>
#include <cstring>
using namespace std;

bool flag[4];
int hand[5];
int ans[5];

void solve() {
  for(int i = 0 ; i < 5 ; i++) {
    if(hand[i] == 1) flag[1] = true; //O[
    if(hand[i] == 2) flag[2] = true; //`L
    if(hand[i] == 3) flag[3] = true; //p[
  }
}

int main() { 
  while(cin >> hand[0], hand[0]) {
    for(int i = 1 ; i < 5 ; i++) cin >> hand[i];
    memset(flag, false, sizeof(flag));
    solve();
    
    for(int i = 0 ; i < 5 ; i++) { 
      if(flag[1] == true && flag[2] == true && flag[3] == true) {
	ans[i] = 3;
      }
      else if(flag[1] == true && flag[2] == false && flag[3] == false) {
	ans[i] = 3;
      }
      else if(flag[2] == true && flag[1] == false && flag[3] == false) {
	ans[i] = 3;
      }
      else if(flag[3] == true && flag[2] == false && flag[1] == false) {
	ans[i] = 3;
      }
      else if(flag[1] == true && flag[2] == true && flag[3] == false) {
	if(hand[i] == 1) ans[i] = 1;
	if(hand[i] == 2) ans[i] = 2;
      }	      
      else if(flag[1] == true && flag[3] == true && flag[2] == false) {
	if(hand[i] == 1) ans[i] = 2;
	if(hand[i] == 3) ans[i] = 1;
      }	      
      else if(flag[2] == true && flag[3] == true && flag[1] == false) {
	if(flag[i] == 2) ans[i] = 1;
	if(flag[i] == 3) ans[i] = 2;
      }
    }

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

C++: #include<iostream>
#define rep(k,p) for(int i=k;i<p;i++)
using namespace std;int main(){int s[5],g[4];while(1){rep(0,4)g[i]=0;int n=0,v=0;rep(0,5){cin>>s[i];if(!s[i])break;if(!g[s[i]]){n++;g[s[i]]=1;if(v-1==(s[i]%3)||!v)v=s[i];}}if(!*s)break;rep(0,5)cout<<(n==2?(v==s[i]?1:2):3)<<endl;}return 0;}

C++: #include<stdio.h>

int main(void){
	int t[5]={0},i,R,P,S;

	while(0==0){
		
		R=P=S=0;

		scanf("%d",&t[0]);

		if(t[0]==0) break;
		else if(t[0]==1) R++;
		else if(t[0]==2) S++;
		else P++;
	    

		for(i=1;i<5;i++){
			scanf("%d",&t[i]);
			if(t[i]==1) R++;
		    else if(t[i]==2) S++;
	      	else P++;
		}

		if(R==0){
			if(P!=0 && S!=0)
				for(i=0;i<5;i++){
					if(t[i]==2) t[i]=1;
					else t[i]=2;
				}
		}
		else if(S==0){
			if(P!=0 && R!=0)
				for(i=0;i<5;i++){
					if(t[i]==3) t[i]=1;
					else t[i]=2;
				}
		}
		else if(P==0){
			if(S!=0 && R!=0)
				for(i=0;i<5;i++){
					if(t[i]==1) t[i]=1;
					else t[i]=2;
				}
		}
		
		else if(R==5 || S==5 || P==5 || (R!=0 && S!=0 && P!=0))
			for(i=0;i<5;i++)
				t[i]=3;

		for(i=0;i<5;i++)
			printf("%d\n",t[i]);
	}

	return 0;
}

C++: #include <cstdio>

int main() {
	int te[5];
	while (scanf("%d", &te[0])!=EOF) {
		for (int i=1; i<5; i++) scanf("%d", &te[i]);
		int num[3];
		for (int i=0; i<3; i++) num[i] = 0;
		for (int i=0; i<5; i++) num[te[i]-1]++;
		if (num[0]!=0&&num[1]!=0&&num[2]!=0) {
			for (int i=0; i<5; i++) printf("3\n");
			continue;
		} else if ((num[0]==0&&num[1]==0)||
			(num[1]==0&&num[2]==0)||(num[0]==0&&num[2]==0)) {
			for (int i=0; i<5; i++) printf("3\n");
			continue;
		}
		if (num[0] == 0) {
			for (int i=0; i<5; i++) {
				if (te[i] == 2) {
					printf("1\n");
				} else if (te[i] == 3) {
					printf("2\n");
				}
			}
		} else if (num[1] == 0) {
			for (int i=0; i<5; i++) {
				if (te[i] == 3) {
					printf("1\n");
				} else if (te[i] == 1) {
					printf("2\n");
				}
			}
		} else if (num[2] == 0) {
			for (int i=0; i<5; i++) {
				if (te[i] == 1) {
					printf("1\n");
				} else if (te[i] == 2) {
					printf("2\n");
				}
			}
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[5],i,flg,j;
	while(1){
		int g=0,t=0,p=0;
		int mflg=0,kflg=0;
		flg=0;
		for(i=0;i<5;i++){
			cin>>a[i];
			if(a[i]==0) break;
			if(a[i]==1) g=1;
			else if(a[i]==2) t=1;
			else p=1;
		}
		if(a[0]==0) break;
		else if(g==1 && t==1 && p==1) {
			for(i=0;i<5;i++) cout<<"3"<<endl;
		}
		else {
			for(i=0;i<5;i++){
				mflg=0;
				kflg=0;
				for(j=0;j<5;j++){
					if(a[i]==a[j]) ;
					else if(a[i]==1 && a[j]==3 || a[i]==2 && a[j]==1 || a[i]==3 && a[j]==2) mflg=1;
					else kflg=1;
				}
				if(mflg==1) cout<<"2"<<endl;
				else cout<<"1"<<endl;
			}
		}
	}	
	return 0;
}

C++: #include <cstdio>


int a[3], h[5];

int main(){
    while(scanf("%d", &h[0]) != EOF){
        if(h[0] == 0) break;

        a[h[0] - 1]++;
        for(int i = 1; i < 5; i++){
            scanf("%d", &h[i]);
            a[h[i] - 1]++;
        }

        if((a[0] > 0 && a[1] > 0 && a[2] > 0) || a[0] == 5 || a[1] == 5 || a[2] == 5) printf("3\n3\n3\n3\n3\n");
        else{
            int w;
            if(!a[0]) w = 1;
            if(!a[1]) w = 2;
            if(!a[2]) w = 0;

            for(int i = 0; i < 5; i++){
                if(w == h[i] - 1) printf("1\n");
                else printf("2\n");
            }
        }

        for(int i = 0; i < 3; i++) a[i] = 0;
    }
    return 0;
}

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

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair

int hand[5];

// rock -> 1, scissor -> 2, paper -> 3

void solve() {
  REP(i,1,5) cin>>hand[i];
  
  map<int,int> var;
  rep(i,5) {
    if (!var.count(hand[i])) var.insert(mp(hand[i],0));
  }
  
  if (var.size() == 3 || var.size() == 1) {
    rep(i,5) cout<<3<<endl; return;
  }
  
  // rock vs scissor
  if (!var.count(3)) {
    rep(i,5)
    if (hand[i]==1) {
      cout<<1<<endl;
    } else {
      cout<<2<<endl;
    }
  }
  // rock vs paper
  else if (!var.count(2)) {
    rep(i,5)
    if (hand[i]==3) {
      cout<<1<<endl;
    } else {
      cout<<2<<endl;
    }
  }
  // scissor vs paper
  else if (!var.count(1)) {
    rep(i,5)
    if (hand[i]==2) {
      cout<<1<<endl;
    } else {
      cout<<2<<endl;
    }
  }
}

int main (int argc, char const* argv[]) {
  while (cin>>hand[0], hand[0]) {
    solve();
  }
  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] ) {
					cout << jan[i] << endl;
					if ( i == 1 ) {
						Shori (2);
					} else if ( 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;
		}
	}
}