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 a[5],b[5],rock=0,paper=0,scissors=0;
  while(cin >> a[0],a[0]) {
    cin >> a[1] >> a[2] >> a[3] >> a[4];
    rock=0;paper=0;scissors=0;
    for(int i=0;i<5;i++) {
      if(a[i] == 1) rock++;
      else if(a[i] == 2) scissors++;
      else if(a[i] == 3) paper++;
    }

    if(rock >= 1 && scissors >= 1 && paper >= 1) {
      for(int i=0;i<5;i++) {
	b[i] = 3;
      }
    }

    else if(rock == 5 || scissors == 5 || paper == 5) {
      for(int i=0;i<5;i++) {
	b[i] = 3;
      }
    }
    else if(paper == 0) {
      for(int i=0;i<5;i++) {
	if(a[i] == 1) {
	  b[i] = 1;
	}
	else {
	  b[i] = 2;
	}
      }
    }
    else if(rock == 0) {
      for(int i=0;i<5;i++) {
	if(a[i] == 2) {
	  b[i] = 1;
	}
	else {
	  b[i] = 2;
	}
      }
    }
    else if(scissors == 0) {
      for(int i=0;i<5;i++) {
	if(a[i] == 3) {
	  b[i] = 1;
	}
	else {
	  b[i] = 2;
	}
      }
    }

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

C++: //04
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  for(;;){
    int h[5];
    vector<int> k(5);
    for(int i=0;i<5;i++){
      cin>>h[i];
      if(h[i]==0)return 0;
      k[h[i]]=1;
    }
    if(count(k.begin(),k.end(),1)!=2){
      for(int i=0;i<5;i++){
	cout<<3<<endl;
      }
    }else{
      k[4]=k[1];
      int w=*find(k.rbegin(),k.rend(),1);
      for(int i=0;i<5;i++){
	cout<<((h[i]==w)?1:2)<<endl;
      }
    }
  }
  return 0;
}

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

int main(){
  while(true){
    int cnt[3] = {0, 0, 0};
    int t[5];

    for(int i = 0; i < 5; i++){
      cin >> t[i];
      if(t[i] == 0) return 0;
      t[i]--;
      cnt[t[i]]++;
    }

    if(cnt[0] == 5 || cnt[1] == 5 || cnt[2] == 5 ||
       0 < cnt[0] && 0 < cnt[1] && 0 < cnt[2]){
      for(int i = 0; i < 5; i++){
        cout << 3 << endl;
      }
    }
    else{
      for(int i = 0; i < 5; i++){
        if(cnt[(t[i] + 1) % 3] > 0){
          cout << 1 << endl;
        }
        else{
          cout << 2 << endl;
        }
      }
    }
  }
}

C++: #include <cstdio>
#include <utility>
#include <array>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	array<int, 5> H;
	for (;;) {
		array<int, 3> m = {}, r = {3, 3, 3};
		for (int &h: H) {
			if (!(h = in()))
				return 0;
			m[--h]++;
		}
		for (int i = 0; i < 3; i++)
			if (m[i] == 5)
				break;
			else if (m[i] && m[i] + m[(i + 1) % 3] == 5) {
				r[i] = 1, r[++i % 3] = 2;
				break;
			}
		for (int h: H)
			outl(r[h]);
	}
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int c[5];
    while(cin >> c[0], c[0]){
        range(i,1,5)
            cin >> c[i];
        bool rock, paper, scissors;
        rock = paper = scissors = false;
        rep(i,5){
            if(c[i] == 1){
                rock = true;
            }else if(c[i] == 2){
                scissors = true;
            }else{
                paper = true;
            }
        }
        int r, p ,s;
        if(rock && paper && scissors){
            r = p = s = 3;
        }else if(rock && paper && !scissors){
            p = 1;
            r = 2;
        }else if(rock && scissors && !paper){
            r = 1;
            s = 2;
        }else if(paper && scissors && !rock){
            s = 1;
            p = 2;
        }
        rep(i,5){
            if(c[i] == 1)
                cout << r << endl;
            else if(c[i] == 2)
                cout << s << endl;
            else if(c[i] == 3)
                cout << p << endl;
        }
    }
}

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

int main()
{
	int hand[ 5 ], ans[ 5 ];
	while( cin >> hand[ 0 ] && hand[ 0 ] ){
		int flag = ( 1 << ( hand[ 0 ] - 1 ) );
		for( int i = 1; i < 5; ++i ){
			cin >> hand[ i ];
			flag |= ( 1 << ( hand[ i ] - 1 ) );
		}
		if( flag == 1 || flag == 2 || flag == 4 || flag == 7 ){
			for( int i = 0; i < 5; ++i ){
				ans[ i ] = 3;
			}
		}else{
			int win = 0;
			if( flag == 3 ) win = 1;
			if( flag == 6 ) win = 2;
			if( flag == 5 ) win = 3;
			for( int i = 0; i < 5; ++i ){
				if( hand[ i ] == win ) ans[ i ] = 1;
				else ans[ i ] = 2;
			}
		}
		for( int i = 0; i < 5; ++i ){
			cout << ans[ i ] << endl;
		}
	}
	return 0;
}

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

int main()
{
  vector<int> p(5), r(5);
  int i, t;
  while (cin>>p[0]>>p[1]>>p[2]>>p[3]>>p[4], p[0]) {
    t = 0;
    for (i = 0; i < 5; i++) {
      if (p[i] == 3 && !(t&4)) t ^= 4;
      else if (!(t&p[i])) t ^= p[i];
    }
    if (t == (1+2)) for (i = 0; i < 5; i++) if (p[i] == 1) r[i] = 1; else r[i] = 2;
    else if (t == (2+4)) for (i = 0; i < 5; i++) if (p[i] == 2) r[i] = 1; else r[i] = 2;
    else if (t == (4+1)) for (i = 0; i < 5; i++) if (p[i] == 4) r[i] = 1; else r[i] = 2;
    else for (i = 0; i < 5; i++) r[i] = 3;

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

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

int main(){
	int a[5];
	int b[4];
	while(true){
		b[1] = 0;
		b[2] = 0;
		b[3] = 0;
		for(int i=0; i<5; i++){
			cin >> a[i];
			if(!a[0])
				return 0;
			b[a[i]]++;
		}
		if(b[1] == 5 || b[2] == 5 || b[3] == 5 || (b[1] && b[2] && b[3]))
			for(int i=0; i<5; i++)
				cout << 3 << endl;
		else if(!b[1])
			for(int i=0; i<5; i++){
				if(a[i] == 2)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
		else if(!b[2])
			for(int i=0; i<5; i++){
				if(a[i] == 3)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
		else
			for(int i=0; i<5; i++){
				if(a[i] == 1)
					cout << 1 << endl;
				else
					cout << 2 << endl;
			}
	}
}