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++: // 2011/08/09 Tazoe

#include <iostream>
using namespace std;

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

		int gu = 0;
		int ch = 0;
		int pa = 0;
		for(int i=0; i<5; i++)
			if(te[i]==1)
				gu++;
			else if(te[i]==2)
				ch++;
			else
				pa++;

		if(gu==5||ch==5||pa==5||gu*ch*pa!=0)
			for(int i=0; i<5; i++)
				cout << 3 << endl;
		else if(gu==0)
			for(int i=0; i<5; i++)
				if(te[i]==2)
					cout << 1 << endl;
				else
					cout << 2 << endl;
		else if(ch==0)
			for(int i=0; i<5; i++)
				if(te[i]==3)
					cout << 1 << endl;
				else
					cout << 2 << endl;
		else
			for(int i=0; i<5; i++)
				if(te[i]==1)
					cout << 1 << endl;
				else
					cout << 2 << endl;
	}

	return 0;
}

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

int winner(int a, int b)
{
  if (a > b) swap(a, b);

  if (a == 1 && b == 2) return (1);
  else if (a == 2 && b == 3) return (2);
  else if (a == 1 && b == 3) return (3);
}

int main()
{
  int input[5];

  while (scanf("%d", &input[0]), input[0]){
    bool check[4] = {false};
    check[input[0]] = true;
    for (int i = 1; i < 5; i++){
      scanf("%d", &input[i]);
      check[input[i]] = true;
    }
    
    if (check[1] && check[2] && check[3]){
      for (int i = 0; i < 5; i++) printf("3\n");
    }
    else {
      int tmp[2];
      for (int i = 1, j = 0; i <= 3; i++){
        if (check[i]) tmp[j++] = i;
      }
      int win = winner(tmp[0], tmp[1]);
      for (int i = 0; i < 5; i++){
        if (input[i] == win){
          printf("1\n");
        }
        else {
          printf("2\n");
        }
      }
    }
  }

  return (0);
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        vector<int> a(5);
        vector<int> b(4);
        for(int i=0; i<5; ++i){
            cin >> a[i];
            if(a[i] == 0)
                return 0;
            ++ b[a[i]];
        }

        if(b[1] == 5 || b[2] == 5 || b[3] == 5 || (b[1] > 0 && b[2] > 0 && b[3] > 0)){
            a.assign(5, 3);
        }else{
            if(b[1] = 0){
                replace(a.begin(), a.end(), 2, 1);
                replace(a.begin(), a.end(), 3, 2);
            }else if(b[2] == 0){
                replace(a.begin(), a.end(), 1, 2);
                replace(a.begin(), a.end(), 3, 1);
            }
        }

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

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int hand[6]={0};
    while(cin>>hand[0],hand[0]){
            int flg[5]={0};
        for(int i=1;i<5;i++)cin>>hand[i];
        for(int i=0;i<5;i++){
            if(hand[i]==1)flg[1]=1;
            if(hand[i]==2)flg[2]=1;
            if(hand[i]==3)flg[3]=1;
        }
        if(flg[1]==1&&flg[2]==1&&flg[3]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
        else if(flg[1]==1&&flg[2]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==1)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[2]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==2)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[1]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==3)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[1]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
        else if(flg[2]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
        else if(flg[3]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
  int i,j;
  vi hand(5);
  while(1){
    vi n(3,0);
    cin>>hand[0];
    if(hand[0]==0)break;
    hand[0]--;
    n[hand[0]]++;
    rep(i,4){
      cin>>hand[1+i];
      hand[1+i]--;
      n[hand[1+i]]++;
    }
    if(n[0]&&n[1]&&n[2])
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]==5 || n[1]==5 || n[2]==5)
      rep(i,5)
        cout<<"3"<<endl;
    else if(n[0]&&n[1])//gu choki                      
      rep(i,5)
        if(hand[i])cout<<"2"<<endl;
        else cout<<"1"<<endl;
    else if(n[0]&&n[1])//gu pa                         
      rep(i,5)
        if(hand[i])cout<<"1"<<endl;
        else cout<<"2"<<endl;
    else
      rep(i,5)
        if(hand[i]==1)cout<<"1"<<endl;
        else cout<<"2"<<endl;
  }
}

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

int main() 
{
	while (1) {
		int a, b, c, d, e;
		cin >> a;
		if (a == 0)break;
		cin >> b >> c >> d >> e;
		if (a == b == c == d == e) { cout << "3\n3\n3\n3\n3\n"; continue; }
		vector<int>f(5);
		vector<int>q(5);
		f[0] = a;
		f[1] = b;
		f[2] = c;
		f[3] = d;
		f[4] = e;
		q[0] = a;
		q[1] = b;
		q[2] = c;
		q[3] = d;
		q[4] = e;
		sort(f.begin(), f.end());
		if(f[0]==1&&(f[1]==2||f[2]==2||f[3]==2)&&f[4]==3){cout<<"3\n3\n3\n3\n3\n"; continue;}
		if (f[0] == 2) {
			for (int i = 0; i < 5; i++) {
				if (q[i] == 2)cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
		if (f[4] == 3) {
			for (int i = 0; i < 5; i++) {
				if (q[i] == 3)cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
		else {
			for (int i = 0; i < 5; i++) {
				if (q[i] == 1)cout << 1 << endl;
				else cout << 2 << endl;
			}
			continue;
		}
	}
}