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 <stdio.h>
#include <iostream>

using namespace std;

void syuturyoku(int p, int q[]) 
{
	for (int i = 0; i < 5; i++) {
		if (q[i] == p) {
			cout << 1 << endl;
		} else {
			cout << 2 << endl;
		}
	}
	return;
}

int main() {
	int a[5];
	while (1) {
		cin >> a[0];
		if (a[0] == 0) {
			break;
		}
		int b[3] = {0};
		b[a[0]-1] = 1;
		for (int i = 1; i< 5; i++) {
			cin >> a[i];
			b[a[i]-1] = 1;
		}
		if ((b[0] == 1 && b[1] == 1 && b[2] == 1) || (b[0] == 1 && b[1] == 0 && b[2] == 0) || (b[0] == 0 && b[1] == 1 && b[2] == 0) || (b[0] == 0 && b[1] == 0 && b[2] == 1)) {
			for (int i = 0; i < 5; i++) {
				cout << 3 << endl;
			}
		} else {
			if (b[0] == 0) {
				syuturyoku(2,a);
			} else if (b[1] == 0) {
				syuturyoku(3,a);
			} else {
				syuturyoku(1,a);
			}
		}
	}
}

C++: #include<stdio.h>
bool f[3];
int t[5];
int i,j;
int w,l;

int main(){
	while(1){
		for(i=0;i<3;i++)f[i]=false;
		for(i=0;i<5;i++){
			scanf("%d",&t[i]);
			if(t[i]==0)return 0;
		}
		for(i=0;i<5;i++)f[t[i]-1]=true;
		if(f[0]&&f[1]&&f[2]){w=-1;l=-1;}
		else if(f[0]&&f[1]){w=1;l=2;}
		else if(f[0]&&f[2]){w=3;l=1;}
		else if(f[1]&&f[2]){w=2;l=3;}
		else{w=-1;l=-1;}
		for(i=0;i<5;i++){
			if(t[i]==w)printf("1\n");
			else if(t[i]==l)printf("2\n");
			else printf("3\n");
		}
	}
}

C++: #include<iostream>

using namespace std;

int main(){
  int hands[5], i, numRock, numScis, numPaper;
  while(cin >> hands[0], hands[0]){
    for(i=1; i<5; i++){
      cin >> hands[i];
    }
    numRock=0, numScis=0, numPaper=0;
    for(i=0; i<5; i++){
      if(hands[i]==1)numRock++;
      if(hands[i]==2)numScis++;
      if(hands[i]==3)numPaper++;
    }
    if(numRock==0){
      for(i=0; i<5; i++){
        if(hands[i]==2){
          cout << 1 << endl;
        }else{
          cout << 2 << endl;
	}
      }
    }else if(numScis==0){
      for(i=0; i<5; i++){
	if(hands[i]==3){
          cout << 1 << endl;
	}else{
          cout << 2 << endl;
        }
      }
    }else if(numPaper==0){
      for(i=0; i<5; i++){
        if(hands[i]==1){
          cout << 1 << endl;
        }else{
          cout << 2 << endl;
        }
      }
    }else{
      for(i=0; i<5; i++){
	cout << 3 << endl;
      }
    }
  }
}

C++: #include<iostream>
using namespace std;
int main(){
long x[5],h[4],i;
while(cin>>x[0]){
if(x[0]==0)break;
for(i=1;i<=3;i++)h[i]=0;
h[x[0]]++;
for(i=1;i<5;i++){cin>>x[i];h[x[i]]++;}
for(j=0,i=1;i<=3;i++)if(h[i]==0)j++;
if(j==2||j==0){
for(i=0;i<5;i++)cout<<"3"<<endl;
else if(j==1){
for(i=1;i<=3;i++)if(h[i]==0)break;
if(i==1){
for(i=0;i<5;i++)cout<<x[i]-1<<endl;
}else if(i==2){
for(i=0;i<5;i++)cout<<(x[i]+1)%3<<endl;
}else if(i==3){
for(i=0;i<5;i++)cout<<x[i]<<endl;
}
}
}
return 0;
}

C++: #include <iostream>
#define rep(i) for(i=0;i<5;i++)
using namespace std;
int main(){
  int n,a[5],i;
  while(cin>>a[0],a[0]){
    int b[3]={0};
    for(i=1;i<5;i++){
      cin>>a[i];
      b[a[i]-1]++;
    }
    if(b[0]&&b[1]&&!b[2])rep(i)cout<<((a[i]==1)?1:2)<<endl;
    else if(b[0]&&!b[1]&&b[2])rep(i)cout<<((a[i]==3)?1:2)<<endl;
    else if(!b[0]&&b[1]&&b[2])rep(i)cout<<((a[i]==2)?1:2)<<endl;
    else rep(i)cout<<'3'<<endl;
  }
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for(int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    vector<int> h(5);
    while(cin >> h[0] && h[0])
    {
        REP(i, 1, 5) cin >> h[i];

        set<int> s;

        rep(i, 5) s.insert(h[i]);

        if(!s.count(1) && s.count(2) && s.count(3))
        {
            rep(i, 5)
            {
                cout << (h[i] == 2 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(2) && s.count(1) && s.count(3))
        {
            rep(i, 5)
            {
                cout << (h[i] == 3 ? 1 : 2) << endl;
            }
        }
        else if(!s.count(3) && s.count(1) && s.count(2))
        {
            rep(i, 5)
            {
                cout << (h[i] == 1 ? 1 : 2) << endl;
            }
        }
        else
        {
            rep(i, 5) cout << 3 << endl;
        }
    }

    return 0;
}

C++: #include <cstdio>

int hand[3], result[5];

int main(){
	while(scanf("%d", &result[0])){
		if(result[0] == 0) break;
		bool d = false;
		for(int i = 0; i < 3; i++) hand[i] = 0;
		for(int i = 0; i < 5; i++) hand[i] = 0;
		for(int i = 1; i < 5; i++) scanf("%d", &result[i]);
		for(int i = 0; i < 5; i++) hand[result[i]-1]++;
		if(hand[0]==0&&hand[1]==0) d = 1;
		else if(hand[1]==0&&hand[2]==0) d = 1;
		else if(hand[0]==0&&hand[2]==0) d = 1;
		if((hand[0]>0&&hand[1]>0&&hand[2]>0)||d==1){
			for(int i = 0; i < 5; i++) printf("3\n");
			continue;
		}
		if(hand[0]==0){
			for(int i = 0; i < 5; i++){
				if(result[i]==1) printf("1\n");
				else printf("2\n");
			}
		} else if(hand[1] == 0){
			for(int i = 0; i < 5; i++){
				if(result[i]==2) printf("1\n");
				else printf("2\n");
			}
		} else if(hand[2] == 0){
			for(int i = 0; i < 5; i++){
				if(result[i]==0) printf("1\n");
				else printf("2\n");
			}
		}
	}
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  int arm[5];
  while(cin>>arm[0]&&arm[0]){
    bool d[3];
    memset(d,false,sizeof(d));
    arm[0]--;
    d[arm[0]]=true;
    for(int i=1;i<5;i++){
      cin>>arm[i];
      arm[i]--;
      d[arm[i]]=true;
    }
    int cnt=0;
    for(int i=0;i<3;i++){
      if(d[i])cnt++;
    }
    if(cnt!=2){
      for(int i=0;i<5;i++){
        cout<<3<<endl;
      }
    }else{
      int win,lose;
      if(d[0]&&d[1]){
        win=0;lose=1;
      }else if(d[1]&&d[2]){
        win=1;lose=2;
      }else if(d[2]&&d[0]){
        win=2;lose=0;
      }
      for(int i=0;i<5;i++){
        if(arm[i]==win)cout<<1<<endl;
        else cout<<2<<endl;
      }
    }
  }
}

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

bool isdraw(int used)
{
	if(used == (1<<3)-1) return true;
	for(int i=0; i<3; i++)
		if(used == (1<<i)) return true;
		
	return false;
}

int main()
{
	int t;
	while(scanf("%d", &t), t)
	{
		int ar[5], used=0;
		ar[0]=t;
		used|=(1<<(ar[0]-1));
		for(int i=1; i<5; i++)
		{
			scanf("%d", &ar[i]);
			used|=(1<<(ar[i]-1));
		}
		
		for(int i=0; i<5; i++)
		{
			if(isdraw(used)) puts("3");
			else
			{
				if(used&(1<<(ar[i])%3)) puts("1");
				else puts("2");
			}
		}
	}
}