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<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int hand[6]={0};
    while(cin>>hand[0],hand[0]){
            int flg[5]={0};
        for(int i=1;i<5;i++)cin>>hand[i];
        for(int i=0;i<5;i++){
            if(hand[i]==1)flg[1]=1;
            if(hand[i]==2)flg[2]=1;
            if(hand[i]==3)flg[3]=1;
        }
        if(flg[1]==1&&flg[2]==1&&flg[3]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
        else if(flg[1]==1&&flg[2]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==1)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[2]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==1)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[1]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==1)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
    }
    return 0;
}

C++: #include <stdio.h>
#include <set>

using namespace std;

int main(){
  while (1){

    set<int> s;

    int n[5];
    for(int i=0;i<5;i++){
      scanf("%d", n+i);
      if(n[i]==0) return 0;
      s.insert(n[i]);
    }

    if(s.size() == 2){
      if(s.find(1) != s.end()){
        if(s.find(2) != s.end()){
          for(int i=0;i<5;i++) printf("%d\n", (n[i] == 1)? 1:2);
        }else {
          for(int i=0;i<5;i++) printf("%d\n", (n[i] == 1)? 2:1);
        }
      }else {
        for(int i=0;i<5;i++) printf("%d\n", (n[i] == 2)? 1:2);
      }
    }else {
      for(int i=0;i<5;i++) puts("3");
    }

  }
}

C++: #include <iostream>
using namespace std;
int main(){
	int rps[5],res[5];
	while(cin>>rps[0]){
		if(!rps[0])break;
		int f1=0,f2=0,f3=0,max=1,min=3;
		for(int i=1;i<5;++i)cin>>rps[i];
		for(int i=0;i<5;++i){
			if(max<rps[i]) max=rps[i];
			else if(min>rps[i]) min=rps[i];
			if(rps[i]==1) f1=1;
			else if(rps[i]==2) f2=1;
			else if(rps[i]==3) f3=1;
		}
		if((f1&&f2&&f3)||max==min) for(int i=0;i<5;++i)res[i]=3;
		else{
			for(int i=0;i<5;++i){
				if(rps[i]==max)res[i]=1+((max%3>min%3)?1:0);
				else res[i]=1+((max%3>min%3)?0:1);
			}
		}
		for(int i=0;i<5;++i)cout<<res[i]<<"\n";
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#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 all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a;
	while(cin>>a,a){
		vector<int>in(5);
		in[0]=a;
		rep(i,4)cin>>in[i+1];
		bool h[3]={0};
		rep(i,5)in[i]--;
		rep(i,5)h[in[i]]=true;
		int sum=h[0]+h[1]+h[2];
		if(sum==3||sum==1){
			rep(i,5)cout<<3<<endl;
			continue;
		}
		if(!h[0]){
			rep(i,5)if(in[i]==1)cout<<1<<endl;
			else cout<<2<<endl;
		}else if(!h[1]){
			rep(i,5)if(in[i]==2)cout<<1<<endl;
			else cout<<2<<endl;
		}else if(!h[2]){
			rep(i,5)if(in[i]==0)cout<<1<<endl;
			else cout<<2<<endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int t[5];
int main(){
  while(cin>>t[0]&&t[0]){
    for(int i=1;i<5;i++)cin>>t[i];
    for(int i=0;i<5;i++){
      int a=0,b=0;
      for(int j=0;j<5;j++){
	if(i==j)continue;
	if(t[i]%3+1==t[j])a++;
	if(t[i]==t[j]%3+1)b++;
      }
      if((a>0)==(b>0))cout<<3<<endl;
      else if(a>0)cout<<1<<endl;
      else cout<<2<<endl;
    }
  }
  return 0;
}

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

int main(){
  int te[3] = {1,2,3};
  int paper[10],Min;
  while(true){
    Min = 10000000;
    map<int,bool> exist;
    cin >> paper[0];
    exist[paper[0]] = true;
    Min = min(Min,paper[0]);
    if(paper[0] == 0)break;
    for(int i=1;i<5;i++){
      cin >> paper[i];
      Min = min(Min,paper[i]);
      exist[paper[i]] = true;
    }
    if(exist[1] && exist[2] && exist[3]){
      for(int i=0;i<5;i++)cout << 3 << endl;
    }
    else if(exist[1] && exist[3]){
      for(int i=0;i<5;i++){
	if(paper[i] == 3)cout << 1 << endl;
	else cout << 2 << endl;
      }
    }
    else {
      for(int i=0;i<5;i++){
	if(paper[i] == Min)cout << 1 << endl;
	else cout << 2 << endl;
      }

    }
  }
  return 0;
}

C++: #include<stdio.h>
using namespace std;

int main(){
  int h[5],count[3],win,lose,drow;
  int i;
  
  while(1){

    count[0]=0; count[1]=0; count[2]=0;
    
    for(i=0;i<5;i++){
      scanf("%d",&h[i]);
      if(h[0]==0) return -1;
      if(h[i]==1) count[0]++;
      if(h[i]==2) count[1]++;      
      if(h[i]==3) count[2]++;
    }

    if(count[0] > 0 && count[1] > 0 && count[2] > 0){
      for(i=0;i<5;i++) printf("%d\n",3);
    }
    
    if(h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4]){
      for(i=0;i<5;i++) printf("%d\n",3);
    }

    if(count[0]==0 && count[1]!=0 && count[2]!=0){
      win=2; lose=3;
    }

    if(count[0]!=0 && count[1]==0 && count[2]!=0){
      win=3; lose=1;
    }

    if(count[0]!=0 && count[1]!=0 && count[2]==0){
      win=1; lose=2;
    }

    for(i=0;i<5;i++){
      if(win==h[i]) printf("%d\n",1);
      if(lose==h[i]) printf("%d\n",2);
    }
    
  }
  return 0;
}

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

int winner(int a, int b)
{
  if (a == 1 && b == 2) return (1);
  else if (a == 2 && b == 3) return (2);
  else if (a == 1 && b == 3) return (3);
}

int main()
{
  int input[5];

  while (scanf("%d", &input[0]), input[0]){
    bool check[4] = {false};
    check[input[0]] = true;
    for (int i = 1; i < 5; i++){
      scanf("%d", &input[i]);
      check[input[i]] = true;
    }
    bool only = false;
    int cnt = 0;
    for (int i = 1; i <= 3; i++){
      if (!check[i]) cnt++;
    }
    if (cnt == 2) only = true;

    if ((check[1] && check[2] && check[3]) || only){
      for (int i = 0; i < 5; i++) printf("3\n");
    }
    else {
      int tmp[2];
      for (int i = 1, j = 0; i <= 3; i++){
        if (check[i]) tmp[j++] = i;
      }
      int win = winner(tmp[0], tmp[1]);
      for (int i = 0; i < 5; i++){
        if (input[i] == win){
          printf("1\n");
        }
        else {
          printf("2\n");
        }
      }
    }
  }

  return (0);
}