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

using namespace std;

int judge(int a, int b) { // aがbにかつかどうか
//    cout << a << ' ' << b << endl;
    if (a == 1) {
        if (b == 1) return 3;
        if (b == 2) return 1;
        if (b == 3) return 2;
    } 
    if (a == 2) {
        if (b == 1) return 2;
        if (b == 2) return 3;
        if (b == 3) return 1;
    } 
    if (a == 3) {
        if (b == 1) return 1;
        if (b == 2) return 2;
        if (b == 3) return 3;
    }
}


void result(int *h) {
    // 3つ同じ手
    if (h[0] == h[1] && h[1] == h[2] && h[2] == h[3] && h[3] == h[4]) {
        for (int i = 0; i < 5; i++) h[i] = 3;
        return;
    }

    // 3つ違う手
    bool hand_used[3+1];
    memset(hand_used, 0, sizeof(hand_used));
    for (int i = 0; i < 5; i++) {
        hand_used[h[i]] = true;
    }
    if (hand_used[1] && hand_used[2] && hand_used[3]) {
        for (int i = 0; i < 5; i++) h[i] = 3;
        return;
    }

    if (hand_used[1] && hand_used[2]) {
        for (int i = 0; i < 5; i++) {
            if (h[i] == 1) h[i] = judge(1, 2);
            else           h[i] = judge(2, 1);
        }
        return;
    }
    if (hand_used[2] && hand_used[3]) {
        for (int i = 0; i < 5; i++) {
            if (h[i] == 2) h[i] = judge(2, 3);
            else           h[i] = judge(3, 2);
        }
        return;
    }
    if (hand_used[3] && hand_used[1]) {
        for (int i = 0; i < 5; i++) {
            if (h[i] == 3) h[i] = judge(3, 1);
            else           h[i] = judge(1, 3);
        }
        return;
    }
}



int main() {
    int h[5];
    while (cin >> h[0], h[0] != 0) {
        for (int i = 1; i < 5; i++) {
            cin >> h[i];
        }
        result(h);
        for (int i = 0; i < 5; i++) {
            cout << h[i] << endl;
        }
    }
    return 0;
}

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

int main(){
	int hand[5],num[3],result[5],win;
  while(cin>>hand[0]>>hand[1]>>hand[2]>>hand[3]>>hand[4]){
		for(int i=0;i<3;i++){
			num[i] = 0;
			result[i] = 0;
		}
		for(int i=0;i<5;i++){
			hand[i]--;
			num[hand[i]]++;
		}
		if(num[0]*num[1]*num[2] == 0 
			 && (num[0]+1)*(num[1]+1)*(num[2]+1) != 6){
			for(win = 0;num[win] != 0;win++);
			win = (++win)%3;
			for(int i=0;i<5;i++){
				result[i] = (hand[i] == win) ? 1 : 2;
			}
		}
		else{
			for(int i=0;i<5;i++)
				result[i] = 3;
		}
		for(int i=0;i<5;i++)
			cout<<result[i]<<endl;
	}
  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <set>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int h[5];
void solve() {
    set<int> s;
    rep(i, 5) s.insert(h[i]);
    if (s.size() == 3 || s.size() == 1) {
        rep(i, 5) cout << "3" << endl;
    } else {
        int a1 = *max_element(h, h + 5);
        int a2 = *min_element(h, h + 5);
        int b1, b2;
        if ((a1 + 1) % 3 == a2) {
            b1 = 1;
            b2 = 2;
        } else {
            b1 = 2;
            b2 = 1;
        }
        rep(i, 5) {
            if (h[i] == a1)
                cout << b1 << endl;
            else
                cout << b2 << endl;
        }
    }
}
int main() {
    while (cin >> h[0], h[0]) {
        rep(i, 4) cin >> h[i + 1];
        solve();
    }
}

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

void search(int a[], int c[]) {
  for (int i = 0; i < 5; i++) {
    if (a[i] == 1) {
      c[0]++;
    } else if (a[i] == 2) {
      c[1]++;
    } else {
      c[2]++;
    }
  }
}

int main() {
  int h[5];
  
  while (true) {
    cin >> h[0];
    if (h[0] == 0) break;
    for (int i = 1; i < 5; i++)
      cin >> h[i];

    int count[3] = {0};
    search(h, count);
    int count0 = 0;
    for (int i = 0; i < 3; i++)
      if (count[i] == 0) count0++;
    if (count0 != 1) {
      for (int i = 0; i < 5; i++)
	cout << 3 << endl;
    } else {
      for (int j = 0; j < 5; j++) {
	if (count[0] && count[1]) {
	  if (h[j] == 1) cout << 1 << endl;
	  else cout << 2 << endl;
	} else if (count[1] && count[2]) {
	  if (h[j] == 2) cout << 1 << endl;
	  else cout << 2 << endl;
	} else {
	  if (h[j] == 3) cout << 1 << endl;
	  else cout << 2 << endl;
	}
      }
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main (){

  int a[5],cnt[3];

  while(1){

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

    for(int i=1 ; i < 5 ; i++)cin >>a[i];
    
    for(int i=0 ; i < 3 ; i++)cnt[i]=0;

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

    }else if(cnt[1] == 0){

      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;
	}
      }
      
    }

  }
  return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	int y = 0;
	for (int u = 0; u < 200; u++)
	{
		int a[6],h1 = 0,h2 = 0,h3 = 0;

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

		for (int i = 0; i < 5; i++)
		{
			if (a[i] == 1)
			{
				h1 += 1;
			}
			else if (a[i] == 2)
			{
				h2 += 1;
			}
			else if (a[i] == 3)
			{
				h3 += 1;
			}
		}


		int ke = 0;
		if (h1 != 0 && h2 != 0)
		{
			if (h3 != 0)
			{
				ke += 1;
				for (int gg = 0; gg < 5; gg++)
				{
					cout << '3' << endl;
				}
			}
		}

		if (h1 == 0 && ke == 0)
		{
			for (int j = 0; j < 5; j++)
			{
				if (a[j] == 2)
				{
					cout << '1' << endl;
				}
				else
				{
					cout << '2' << endl;
				}
			}
		}
		else if (h2 == 0)
		{
			for (int j = 0; j < 5; j++)
			{
				if (a[j] == 1)
				{
					cout << '2' << endl;
				}
				else
				{
					cout << '1' << endl;
				}
			}
		}
		else if (h3 == 0)
		{
			for (int j = 0; j < 5; j++)
			{
				if (a[j] == 1)
				{
					cout << '1' << endl;
				}
				else
				{
					cout << '2' << endl;
				}
			}
		}
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    vector<int>V(5);
    while(cin>>V[0],V[0]){
         vector<int>cnt(3,0);
         cnt[--V[0]]++;
         for(int i=1;i<5;i++){
            cin>>V[i];
            cnt[--V[i]]++;
         }
         bool flag=false;
         if(cnt[0]==5||cnt[1]==5||cnt[2]==5)flag=true;
         else if(cnt[0]&&cnt[1]&&cnt[2])flag=true;

         if(flag)for(int i=0;i<5;i++)cout<<3<<endl;
         else for(int i=0;i<5;i++)cout<<((cnt[V[i]]&&cnt[(V[i]+1)%3])?1:2)<<endl;
    }
    return 0;
}