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>
using namespace std;
int main(){
  int p[5];
  while(1){
    int g=0,tyo=0,pa=0;
    cin >> p[0];
    if(p[0]==0){
      break;
    }
    for(int i=1;i<5;i++){
      cin >> p[i];
      if(p[i]==1){
	g++;
      }
      else if(p[i]==2){
	tyo++;
      }
      else if(p[i]==3){
	pa++;
      }
    }

    if(g>0 && tyo>0 && pa>0){
      for(int i=0;i<5;i++){
	p[i]=3;
      }
    }
    else if(g<=0 && tyo>0 && pa>0){
      for(int i=0;i<5;i++){
	if(p[i]==2){
	  p[i]=1;
	}
	else if(p[i]==3){
	  p[i]=2;
	}
      }
    }
    else if(g>0 && tyo>0 && pa<=0){
      for(int i=0;i<5;i++){
	if(p[i]==1){
	  p[i]=1;
	}
	else if(p[i]==2){
	  p[i]=2;
	}
      }
    }
    else if(g>0 && tyo<=0 && pa>0){
      for(int i=0;i<5;i++){
	if(p[i]==1){
	  p[i]=2;
	}
	else if(p[i]==3){
	  p[i]=1;
	}
      }
    }

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

  }
}

C++: #include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int c[5];
int count_gu;
int count_tyo;
int count_paa;
#define GU 1
#define TYO 2
#define PAA 3

#define WIN 1
#define LOSE 2
#define AIKO 3

void count() {
  count_gu = 0; count_tyo = 0; count_paa = 0;
  rep(i, 5) {
    switch (c[i]) {
      case GU:  count_gu++;  break;
      case TYO: count_tyo++; break;
      case PAA: count_paa++; break;
    }
  }
}


int main() {
  while (true) {
    cin >> c[0];
    if (c[0] == 0) break;
    cin >> c[1] >> c[2] >> c[3] >> c[4];
    int a[5]; // answer
    count();
    // kati/make
    if (!((count_gu == 5 || count_paa == 5 || count_tyo == 5) ||
        (count_gu != 0 && count_tyo != 0 && count_paa != 0))) {
      // tyo -> win / paa -> lose
      if (count_gu == 0) {
        rep(i, 5) {
          if (c[i] == TYO) a[i] = WIN;
          else             a[i] = LOSE;
        }
      }
      // tyo -> lose / gu -> win
      if (count_paa == 0) {
        rep(i, 5) {
          if (c[i] == GU) a[i] = WIN;
          else            a[i] = LOSE;
        }
      }
      // paa -> win / gu -> lose
      if (count_tyo == 0) {
        rep(i, 5) {
          if (c[i] == PAA) a[i] = WIN;
          else             a[i] = LOSE;
        }
      }
    }
    // aiko
    else rep(i, 5) a[i] = AIKO;

    rep(i, 5) cout << a[i] << endl;
  }
  return 0;
}

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

int main()
{
  vector<int> t(5);
  while (cin >> t[0] >> t[1] >> t[2] >> t[3] >> t[4]) {
    if (t[0] == 0)
      break;

    for (int i = 0; i < 5; ++i) {
      int w = 0, l = 0;
      for (int j = 0; j < 5; ++j) {
	if (i == j || t[i] == t[j])
	  continue;
	if (t[i] == 1) {
	  if (t[j] == 2)
	    ++w;
	  else
	    ++l;
	} else if (t[i] == 2) {
	  if (t[j] == 1)
	    ++l;
	  else
	    ++w;
	} else {
	  if (t[j] == 1)
	    ++w;
	  else
	    ++l;
	}
      }
      if (w > 0 && l == 0)
	cout << "1" << endl;
      else if (w == 0 && l > 0)
	cout << "2" << endl;
      else
	cout << "3" << endl;
    }
  }
  return 0;
}

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

int main(void)
{
	int te[5];
	set<int> check;
	while(cin>>te[0]){
		if(!te[0]) break;
		check.clear();
		for(int i=1; i< 5; i++){
			cin >> te[i];
		}
		for(int i=0; i<5; i++){
			check.insert(te[i]);
		}
		int tmp = 0;
		if(check.size()==2){
			if(check.find(1) == check.end()){
				tmp = -1;
			}else if(check.find(2) == check.end()){
				tmp = -2;
			}
			for(int i=0;i<5;i++){
				if(te[i]+tmp==1){
					cout << "1" << endl;
				}else{
					cout << "2" << endl;
				}
			}
			
		}else{
			for(int i=0;i<5; i++){
				cout <<"3"<< endl;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	while(1){
		std::vector<int> vec(5);
		std::vector<int> vec2(5);
		int a=0;
		std::cin>>a;
		if(a==0)break;
		vec[0]=a;
		int d=0,e=0,f=0;
		if(a==1)d++;
		if(a==2)e++;
		if(a==3)f++;
		for(int i=1;i<5;i++){
			int b;
			if(b==1)d++;
			if(b==2)e++;
			if(b==3)f++;
			std::cin>>b;
		}
		if(d>=1&&e>=1&&f>=1||d==5||f==5||e==5){
			for(int i=0;i<5;i++){
				vec2[i]=3;
			}
		}else if(d>=1&&e>=1&&f==0){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=1;
				if(vec[i]==2)vec2[i]=2;
			}
		}else if(d>=0&&e>=1&&f==1){
			for(int i=0;i<5;i++){
				if(vec[i]==2)vec2[i]=1;
				if(vec[i]==3)vec2[i]=2;
			}
		}else if(d>=1&&e>=0&&f==1){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=2;
				if(vec[i]==3)vec2[i]=1;
			}
		}
		for(int i=0;i<5;i++){
			std::cout<<vec2[i]<<std::endl;
		}
	}
	return 0;
}

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];
    for(int i = 1 ; i < 4 ; i++) flag[i] = false;
    solve();
    
    for(int i = 0 ; i < 5 ; i++) { 
      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] == false && flag[2] == true && flag[3] == true) {
	if(hand[i] == 2) ans[i] = 1;
	if(hand[i] == 3) ans[i] = 2;
      }	      
      else if(flag[1] == true && flag[2] == false && flag[3] == true) {
	if(flag[i] == 3) ans[i] = 1;
	if(flag[i] == 1) ans[i] = 2;
      }
      else ans[i] = 3;
    }

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