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<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,ff;
	int jan[5],flg[3];
	while(1) {
		ff=0;
		for(i=0;i<3;i++) flg[i]=0;
		for(i=0;i<5;i++) {
			scanf("%d",&jan[i]);
			if(jan[0]==0) {
				ff=1;
				break;
			}
		}
		if(ff==1) break;
		for(i=0;i<5;i++) {
			if(jan[i]==1) flg[0]=1;
			if(jan[i]==2) flg[1]=1;
			if(jan[i]==3) flg[2]=1;
		}
		if(flg[0]==1 && flg[1]==1 && flg[2]==1) for(i=0;i<5;i++) printf("3\n");
		if(flg[0]==1 && flg[1]==1 && flg[2]==0) {
			for(i=0;i<5;i++) {
				if(jan[i]==1) printf("1\n");
				else printf("2\n");
			}
		}
		if(flg[0]==1 && flg[1]==0 && flg[2]==1) {
			for(i=0;i<5;i++) {
				if(jan[i]==3) printf("1\n");
				else printf("2\n");
			}
		}
		if(flg[0]==0 && flg[1]==1 && flg[2]==1) {
			for(i=0;i<5;i++) {
				if(jan[i]==2) printf("1\n");
				else printf("2\n");
			}
		}
	}
	return 0;
}

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

C++: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<char, int>P;

int main(){
	int b[5];
	while (cin >> b[0], b[0]) {
		int a[4]{};
		a[b[0]] = true;
		for (int i = 1; i < 5; i++) {
			cin >> b[i]; a[b[i]] = true;
		}
		if (a[1] == true && a[2] == true && a[3] == true) {
			rep(i, 5)puts("3");
			continue;
		}
		rep(i, 4) {
			if (b[i] < b[i + 1] || (b[i] == 3 && b[i + 1] == 1))puts("1");
			else puts("2");
		}
		if (b[5] < b[4] || (b[5] == 3 && b[4] == 1))puts("1");
		else puts("2");
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    while (true) {
        int h1;
        cin >> h1;
        
        if (h1==0) {
            break;
        }
        
        int h2, h3, h4, h5;
        cin >> h2 >> h3 >> h4 >> h5;
        
        int l[5] = {h1, h2, h3, h4, h5};
        set<int> s{h1, h2, h3, h4, h5};
        
        if (s.find(1)!=s.end() && s.find(2)!=s.end() && s.find(3)!=s.end()) {
            for (int i=0; i<5; i++) {
                cout << 3 << endl;
            }
        }
        else if (s.find(1)!=s.end() && s.find(2)!=s.end()) {
            for (int i=0; i<5; i++) {
                if (l[i]==1) {
                    cout << 1 << endl;
                }
                else {
                    cout << 2 << endl;
                }
            }
        }
        else if (s.find(2)!=s.end() && s.find(3)!=s.end()) {
            for (int i=0; i<5; i++) {
                if (l[i]==2) {
                    cout << 1 << endl;
                }
                else {
                    cout << 2 << endl;
                }
            }
        }
        else if (s.find(3)!=s.end() && s.find(1)!=s.end()) {
            for (int i=0; i<5; i++) {
                if (l[i]==3) {
                    cout << 1 << endl;
                }
                else {
                    cout << 2 << endl;
                }
            }
        }
        else {
            for (int i=0; i<5; i++) {
                cout << 3 << endl;
            }
        }
    }
}

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

C++: #include <cstdio>

main(){
	while(1){
		int h[5] = {0}, t[4] = {0}, w = 0;
		for(;w<5;w++){
			scanf("%d", h+w);t[h[w]]++;
			if(!*h)break;
		}
		if(!*h)break;

		if(t[1] && t[2] && t[3])
			w = -1;
		else if(t[1] && t[2])
			w = 1;
		else if(t[2] && t[3])
			w = 2;
		else if(t[1] && t[3])
			w = 3;
		else
			w = -1;

		while((*t)++<5)
			puts(w<0?"3":h[*t-1]-w?"2":"1");
	}
}

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

int main() {
  int p[5];
  while(cin >> p[0], p[0]) {
    for(int i = 1; i < 5; i++) cin >> p[i];
    
    bool flag[3] = {};
    for(int i = 0; i < 5; i++) {
      flag[p[i]-1] = true;
    }

    int win, lose;
    if(flag[0] && flag[1] && flag[2]) {
      win = lose = 0;
    } else if(flag[0] && flag[1]) {
      win = 1, lose = 2;
    } else if(flag[1] && flag[2]) {
        win = 2, lose = 3;
    } else {
        win = 3, lose = 1;
    }  
    for(int i = 0; i < 5; i++) {
      if(p[i] == win) p[i] = 1;
      else if(p[i] == lose) p[i] = 2;
      else p[i] = 3;
    }

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

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int a[5];
	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4]) {
		int b[4] = {};
		for (int i = 0; i < 5; i++) {
			if (a[i] == 1)b[1] = 1;
			else if (a[i] == 2)b[2] = 1;
			else if (a[i] == 3)b[3] = 1;
		}

		int f = b[1] + b[2] + b[3];
		if (f == 2)
			if (!b[1])
				for (int i = 0; i < 5; i++)
					a[i] = (a[i] == 2) ? 1 : 2;
			else if (!b[2])
				for (int i = 0; i < 5; i++)
					a[i] = (a[i] == 3) ? 1 : 2;
			else
				for (int i = 0; i < 5; i++)
					a[i] = (a[i] == 1) ? 1 : 2;
		else
			for (int i = 0; i < 5; i++)
				a[i] = 3;

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