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 <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	int count[3], p[5];
	
	while(true){
		
		for(int i = 0; i < 3; i++){
			count[i] = 0;
		}
		
		cin >> p[0];
		if(p[0] == 0){
			break;
		}
		p[0]--;
		count[p[0]]++;
		
		for(int i = 1; i < 5; i++){
			cin >> p[i];
			p[i]--;
			count[p[i]]++;
		}
		
		int emp = 0;
		
		int win, lose;
		
		for(int i = 0; i < 3; i++){
			if(count[i] == 0){
				win = (i + 1) % 3;
				lose = (i + 2) % 3;
				emp++;
			}
		}
		
		if(emp == 0 || emp == 2){
			for(int i = 0; i < 5; i++){
				cout << "3" << endl;
			}
		}else{
			for(int i = 0; i < 5; i++){
				if(p[i] == win){
					cout << "1" << endl;
				}else{
					cout << "2" << endl;
				}
			}
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
void aiko(){
    for(int i = 0; i < 5; i++){
        cout << 3 << endl;
    }
}
int main(){

	while(1){
	    int a[10] = {0};
	    short flg = 0;
        short aiko1=0,aiko2=0,aiko3=0;
        for(int i = 0; i < 5; i++){
            cin >> a[i];
            if(i != 0){
                if(a[i-1] == a[i])flg++;
            }
            else{
                if(a[i] == 0)goto end;
                else flg++;
            }
            if(a[i] == 1)aiko1++;
            if(a[i] == 2)aiko2++;
            if(a[i] == 3)aiko3++;
        }
        //あいこの出力
        if(flg == 5) aiko();
        else if(aiko1 != 0 && aiko2 != 0 && aiko3!= 0) aiko();
        else if(aiko1 == 0){
            for(int i = 0; i < 5; i++){
                if(a[i] == 2) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
        else if(aiko2 == 0){
            for(int i = 0; i < 5; i++){
                if(a[i] == 3) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
        else if(aiko3 == 0){
            for(int i = 0; i < 5; i++){
                if(a[i] == 1) cout << 1 << endl;
                else cout << 2 << endl;
            }
        }
	}
    end:
	return 0;
}

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

int main() {


  while(1) {
    int a[5];
    int tu[3]={};
    for(int i=0;i<5;i++) {
      cin >> a[i];
      if(a[0] == 0) break;
      tu[a[i]-1]++;
    }

    if(a[0] == 0) break;

    int count = 0;
    int win = a[0];
    for(int i=1;i<5;i++) {
      if(a[0] == 1 && a[i] == 3) win = 3;
      else if(a[0] == 2 && a[i] ==1) win =1;
      else if(a[0] == 3 && a[i] == 2)win = 2;
    }
    for(int i=0;i<3;i++)
      if(tu[i] > 0) count++;
    
    if(count == 3 || count == 1){
      for(int i=0;i<5;i++) cout << 3 << endl;
      continue;
    }

    for(int i=0;i<5;i++) {
      if(a[i] == win) cout << 1 << endl;
      else cout << 2 << endl;
    }

    
  
  }
  
  return 0;
  
}

C++: #include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int a[5],b=0;
        bool use[3]={0};
        for(int i=0;i<5;++i){
            cin>>a[i];if(!a[i])return 0;
            switch(a[i]){
                case 1:use[0]=1;break;
                case 2:use[1]=1;break;
                case 3:use[2]=1;break;
            }
        }
        for(int i=0;i<3;++i){
            b+=use[i];
        }
        if(b!=2){
            for(int i=0;i<5;++i){
                cout<<3<<endl;
            }
        }else{
            for(int i=0;i<5;++i){
                if(use[0]&use[1]){
                    if(a[i]!=2)cout<<1<<endl;
                    else cout<<2<<endl;
                }
                if(use[1]&use[2]){
                    if(a[i]!=3)cout<<1<<endl;
                    else cout<<2<<endl;
                }
                if(use[0]&use[2]){
                    if(a[i]!=1)cout<<1<<endl;
                    else cout<<2<<endl;
                }
            }
        }
    }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

int R;
double x[200], y[200], r[200], v[200];
double dis[200];
bool used[200];

int main(){
	int a[5];
	while(cin >> a[0] && a[0]){
		rep2(i, 1, 5) cin >> a[i];
		rep(i, 5){
			int w = 0;
			int l = 0;
			rep(j, 5){
				if(i == j) continue;
				if((a[i] + 1) % 3 == a[j] % 3) w++;
				if((a[j] + 1) % 3 == a[i] % 3) 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 <string>

using namespace std;

int main() {    
    ios::sync_with_stdio(false);

    while(1){
      int a[5];
      int b[3]={};
      int i;
      cin >> a[0];
      if(a[0]==0)
	break;

      for(i=1;i<5;i++){
	cin >> a[i];
      }

      for(i=0;i<5;i++)
	b[a[i]-1]++;


      if((b[0]*b[1]*b[2]!=0) || (b[0]==0 && b[1]==0) || (b[1]==0 && b[2]==0) || (b[2]==0 && b[1]==0)){
	for(i=0;i<5;i++)
	  cout << 3 << endl;
      }
      
      else{
	//??°??????0
	if(b[0]==0){
	  for(i=0;i<5;i++){
	    if(a[i]==2)
	      cout << 1 << endl;
	    if(a[i]==3)
	      cout << 2 << endl;
	  }
	}

	//?????§??????0
	if(b[1]==0){
	  for(i=0;i<5;i++){
	    if(a[i]==3)
	      cout << 1 << endl;
	    if(a[i]==1)
	      cout << 2 << endl;
	  }
	}

	//?????????0
	if(b[2]==0){
	  for(i=0;i<5;i++){
	    if(a[i]==1)
	      cout << 1 << endl;
	    if(a[i]==2)
	      cout << 2 << endl;
	  }
	}
      }
    }
    return 0;
}