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>
using namespace std;
int main()
{
	while (true){
		int a[5];
		int f[4] = { 0 };
		for (int i = 0; i < 5; i++){
			cin >> a[i];
			if (i == 0 && a[i] == 0){
				return 0;
			}
			f[a[i]]++;
		}
		if (f[1]>0 && f[2] > 0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				cout << "3" << endl;
			}
		}
		else if (f[1]>0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				if (a[i] == f[0]){
					cout << "2" << endl;
				}
				else{
					cout << "1" << endl;
				}
			}
		}
		else if (f[2]>0 && f[3] > 0){
			for (int i = 0; i < 5; i++){
				if (a[i] == f[2]){
					cout << "2" << endl;
				}
				else{
					cout << "1" << endl;
				}
			}
		}
		else{
			for (int i = 0; i < 5; i++){
				cout << a[i] << endl;
			}
		}
	}
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

int te[5],Dte[4];
int ans[5];

int main(void){
	int a;
	while(1){
		for(a=0;a<5;a++)te[a]=0,ans[a]=0;
		for(a=0;a<4;a++)Dte[a]=0;
		for(a=0;a<5;a++){
			cin >> te[a];
			Dte[te[a]]=1;
			if(te[a]==0)break;
		}
		if(te[0]==0)break;
		if(Dte[1]==1 && Dte[2]==1 && Dte[3]==1)for(a=0;a<5;a++)ans[a]=3;
		else if(Dte[1]==1 && Dte[2]==1 && Dte[3]==0){
			for(a=0;a<5;a++)if(te[a]==1)ans[a]=1;else if(te[a]==2)ans[a]=2;
		}else if(Dte[1]==0 && Dte[2]==1 && Dte[3]==1){
			for(a=0;a<5;a++)if(te[a]==2)ans[a]=1;else if(te[a]==3)ans[a]=2;
		}else if(Dte[1]==1 && Dte[2]==0 && Dte[3]==1){
			for(a=0;a<5;a++)if(te[a]==3)ans[a]=1;else if(te[a]==1)ans[a]=2;
		}else for(a=0;a<5;a++)ans[a]=3;
		for(a=0;a<5;a++){
			cout << ans[a] <<endl;
		}
	}
	return 0;
}

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

int main()
{
  int a[5];
  
  while (cin >> a[0] && a[0] != 0){
    cin >> a[1] >> a[2] >> a[3] >> a[4];
    int c[4] = {0};
    int cnt = 0;
    for (int i = 1; i < 5; i++){
      c[a[i]]++;
      if (a[i] == a[i - 1]){
        cnt++;
      }
    }
    if (cnt == 4){
      for (int i = 0; i < 5; i++){
        cout << 3 << endl;
      }
      continue;
    }
    if (c[1] != 0 && c[2] != 0 && c[3] != 0){
      for (int i = 0; i < 5; i++){
        cout << 3 << endl;
      }
      continue;
    }
    for (int i = 1; i < 4; i++){
      if (c[i] == 0) cnt = i;
    }

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

C++: #include<iostream>
using namespace std;
int main(){
	int a[5],i,flg,j;
	while(1){
		int g=0,t=0,p=0;
		int mflg,kflg;
		int aaflg;
		flg=0;
		for(i=0;i<5;i++){
			cin>>a[i];
			if(a[i]==0) break;
			if(a[i]==1) g=1;
			else if(a[i]==2) t=1;
			else p=1;
		}
		if(a[0]==0) break;
		aaflg=0;
		for(i=1;i<5;i++) {
			if(a[0]!=a[i]) aaflg=1;
		}
		if(g==1 && t==1 && p==1 || aaflg==0) {
			for(i=0;i<5;i++) cout<<"3"<<endl;
		}
		else {
			for(i=0;i<5;i++){
				mflg=0;
				kflg=0;
				for(j=0;j<5;j++){
					if(a[i]==a[j]) ;
					else if(a[i]==1 && a[j]==3 || a[i]==2 && a[j]==1 || a[i]==3 && a[j]==2) mflg=1;
					else kflg=1;
				}
				if(mflg==1) cout<<"2"<<endl;
				else cout<<"1"<<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;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int a[5];

    while (cin >> a[0], a[0]) {
        bool flag[4] = {false};

        flag[a[0]] = true;
        for (int i = 1; i < 5; i++) {
            cin >> a[i];
            flag[a[i]] = true;
        }
        
        if ((flag[1] && flag[2] && flag[3]) ||
            (flag[1] && !flag[2] && !flag[3]) ||
            (!flag[1] && flag[2] && !flag[3]) ||
            (!flag[1] && !flag[2] && flag[3]))
            for (int i = 0; i < 5; i++)
                cout << "3\n";
        else if (flag[1] && flag[2] && !flag[3]) {
            for (int i = 0; i < 5; i++) {
                if (a[i] == 1)
                    cout << "1\n";
                else
                    cout << "2\n";
            }
        }
        else if (flag[1] && !flag[2] && flag[3]) {
            for (int i = 0; i < 5; i++) {
                if (a[i] == 3)
                    cout << "1\n";
                else
                    cout << "2\n";
            }
        }
        else if (!flag[1] && flag[2] && flag[3]) {
            for (int i = 0; i < 5; i++) {
                if (a[i] == 2)
                    cout << "1\n";
                else
                    cout << "2\n";
            }
        }
    }

    return 0;
}

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

int main()
{
	while(true){
		int n[5];
		int c1=0,c2=0,c3=0;
		cin >> n[0];
		if(n[0]==0)
				break;
		for(int i=1; i<5; i++)
			cin >> n[i];
			
		for(int i=0; i<4; i++){
			if(n[i] != n[i+1])
				break;
			if(i==3){
				for(int i=0; i<5; i++)
					cout << '3' << endl;
				break;
			}
		}
		for(int i=0; i<5; i++){
			if(n[i] == 1)
				c1++;
			else if(n[i] == 2)
				c2++;
			else if(n[i] == 3)
				c3++;
		}
		if(c1 != 0 && c2 != 0 && c3 !=0)
			for(int i=0; i<5; i++)
				cout << '3' << endl;
		else{
			if(c1 > 0 && c2 > 0 && c3 == 0){
				for(int i=0; i<5; i++){
					if(n[i] == 1)
						cout << '1' << endl;
					else
						cout << '2' << endl;
				}
			}
			else if(c1 > 0 && c2 == 0 && c3 > 0){
				for(int i=0; i<5; i++){
					if(n[i] == 1)
						cout << '2' << endl;
					else
						cout << '1' << endl;
				}
			}
			else if(c1 == 0 && c2 > 0 && c3 > 0){
				for(int i=0; i<5; i++){
					if(n[i] == 3)
						cout << '2' << endl;
					else
						cout << '1' << endl;
				}
			}
		}
	}
	return 0;
}