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<vector>

using namespace std;

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
	vector<int> inp(5);
	while(cin>>inp[0],inp[0]){
		bool judge[3] = {false};
		loop(i,1,5){
			cin>>inp[i];
			judge[inp[i]-1]=true;
		}
		if(judge[0]&&judge[1]&&judge[2])
			rep(i,5)cout<<3<<endl;
		else if(judge[0]&&judge[1]&&!judge[2])
			rep(j,5)
				if(inp[j]-1==0)	cout<<1<<endl;
				else 						cout<<2<<endl;
		else if(!judge[0]&&judge[1]&&judge[2])
			rep(j,5)
				if(inp[j]-1==0)	cout<<1<<endl;
				else 						cout<<2<<endl;
		else if(judge[0]&&!judge[1]&&judge[2])
			rep(j,5)
				if(inp[j]-1==2)	cout<<1<<endl;
				else 						cout<<2<<endl;
	}
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <complex>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

typedef vector<int> vi;

vi solve(vi v){
    vi app(3);
    vi even{3,3,3,3,3};

    rep(i,5) v[i]--;
    rep(i,5) app[v[i]]++;
    
    if(app[0] && app[1] && app[2]) return even;
    rep(i,3){
        if(app[i]==0 && app[(i+1)%3]==0){
            return even;
        }
    }

    int win;
    rep(i,3){
        if(app[i] && app[(i+1)%3]) win=i;
    }
    rep(i,5){
        if(v[i]==win) v[i]=1;
        else v[i]=2;
    }
    return v;
}

int main(){
    while(1){
        vi v(5);
        if(cin >> v[0] && v[0]){
            rep(i,4) cin>>v[i+1];
            vi ans=solve(v);
            rep(i,5){
                cout<<ans[i]<<endl;
            }
        }else break;
    }
}

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

bool isDraw(const vector<int>& hands)
{
  int h = hands[0];
  bool f1 = true;
  bool f2;
  vector<bool> hs(3, false);
  for (int i = 1, size = hands.size(); i < size; ++i)
  {
    if ( h != hands[i] ) f1 = false;
    h = hands[i];
    hs[h - 1] = true;
  }
  f2 = hs[0] and hs[1] and hs[2];
  return f1 or f2;
}

vector<int> setAns(const vector<int>& hands, int n)
{
  vector<int> result(5);
  for(int i = 0; i < 5; i++)
  {
    if(hands[i] == n)
    {
      result[i] = 1;
    }
    else
    {
      result[i] = 2;
    }
  }
  return result;
}

vector<int> winLose(const vector<int>& hands)
{
  vector<bool> hs(3, false);
  for (auto h : hands)
  {
    hs[h - 1] = true;
  }
  if (hs[0] and hs[1])
  {
    return setAns(hands, 1);
  }
  else if(hs[1] and hs[2])
  {
    return setAns(hands, 2);
  }
  else
  {
    return setAns(hands, 3);
  }
}

int main(void)
{
  while(true){
    vector<int> hands(5);
    for (auto& h : hands)
    {
      cin >> h;
    }
    if (cin.eof() ) break;
  
    if (isDraw(hands) )
    {
      for (int i = 0; i < 5; i++)
      {
        cout << 3 << endl;
      }
    }
    else
    {
      for (auto n : winLose(hands) )
      {
        cout << n << endl;
      }
    }
  }
}

C++: #include<iostream>

void evaluate(const int *input,int *output);

int main()
{
	while(1)
	{
		int input[5],output[5];
		bool end=false;
		for(int i=0;i<5;i++)
		{
			std::cin>>input[i];
			if(input[i]==0){end=true;break;}
		}
		if(end)break;
		evaluate(input,output);
		for(int i=0;i<5;i++)
		{
			std::cout<<output[i]<<std::endl;
		}
	}
}

void evaluate(const int *input,int *output)
{
	int used[3]={0};
	for(int i=0;i<5;i++)
	{
		used[input[i]-1]=1;
	}
	
	int sum=0;
	for(int i=0;i<3;i++){sum+=used[i];}
	
	if(sum==2)
	{
		int hand;
		int win,lose;
		int j=0;
		for(int i=0;i<3;i++)
		{
			if(used[i]==0)
			{
				hand=i+1;
			}
		}
		switch(hand)
		{
		case 1:
			win=2;
			lose=3;
			break;
		case 2:
			win=3;
			lose=1;
			break;
		case 3:
			win=1;
			lose=2;
			break;
		}
		for(int i=0;i<5;i++)
		{
			if(input[i]==win)
			{
				output[i]=1;
			}
			else if(input[i]==lose)
			{
				output[i]=2;
			}
		}
	}
	else
	{
		for(int i=0;i<5;i++)
		{
			output[i]=3;
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int h[5],cnt[4];
  
  while(cin >> h[0],h[0]!=0){
    for(int i=1;i<5;i++) cin >> h[i];
    
    cnt[1] = 0;
    cnt[2] = 0;
    cnt[3] = 0;
    
    for(int i=0;i<5;i++) cnt[ h[i] ]++;
    
    for(int i=0;i<5;i++){
      
      if(cnt[1] == 5 || cnt[2] == 5 || cnt[3] == 5) cout << 3 << endl;
      else if(cnt[1] != 0 && cnt[2] != 0 && cnt[3] != 0) cout << 3 << endl;
      
      else if(cnt[1] == 0){
	if(h[i] == 2) cout << 1 << endl;
	if(h[i] == 3) cout << 2 << endl;
      }
      else if(cnt[2] == 0){
	if(h[i] == 3) cout << 1 << endl;
	if(h[i] == 1) cout << 2 << endl;
      }
      else if(cnt[3] == 0){
	if(h[i] == 1) cout << 1 << endl;
	if(h[i] == 2) cout << 2 << endl;
      }
    }

  }
  return(0);
}

C++: #include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

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

signed main()
{
  ios::sync_with_stdio(false);
  int input[5];
  
  while (cin >> input[0], input[0]){
    bool check[4] = {false};
    check[input[0]] = true;
    REPS(i, 1, 5){
      cin >> input[i];
      check[input[i]] = true;
    }

    int out[2], j = 0;
    int only = 0;
    REPS(i, 1, 4){
      if (!check[i]){
        only++;
      }
      else {
        out[j++] = i;
      }
    }

    if ((check[1] && check[2] && check[3]) || only == 2){
      REP(i, 5){
        print("3");
      }
    }
    else {
      int win = winner(out[0], out[1]);
      REP(i, 5){
        if (input[i] == win){
          print("1");
        }
        else {
          print("2");
        }
      }
    }
  }

  return (0);
}

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,win=(max%3+1==min%3)?max:min;i<5;++i){
				if(rps[i]==win)res[i]=1;
				else res[i]=2;
			}
		}
		for(int i=0;i<5;++i)cout<<res[i]<<"\n";
	}
	return 0;
}