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 <set>
#include <vector>

using namespace std;

set<int> con;
vector<int> lcon;

int main(int argc, char* argv[])
{
	int c0, c1, c2, c3, c4;
	
	while(1) {

		cin >> c0;
		if( c0 == 0 )
			break;
		
		cin >> c1 >> c2 >> c3 >> c4;

		con.insert(c0);	lcon.push_back(c0);
		con.insert(c1);	lcon.push_back(c1);
		con.insert(c2);	lcon.push_back(c2);
		con.insert(c3);	lcon.push_back(c3);
		con.insert(c4);	lcon.push_back(c4);

		for( auto c : lcon ) {

			int o0 = c%3 + 1;
			int o1 = (c+1)%3 + 1;

			bool f0 = ( con.find(o0) != con.end() );
			bool f1 = ( con.find(o1) != con.end() );

			if( f0 && !f1 ) cout << 1 << endl;			
			else if( !f0 && f1 ) cout << 2 << endl;
			else if( f0 && f1 ) cout << 3 << endl;
		}

		con.clear();
		lcon.clear();
	}

    return 0;
}

C++: #include<stdio.h>

int main(void)
{
  int t[5]={0},t2=0,t3=0,t1=0,k,i;

while(scanf("%d",&k)!=0){

t2=0; t3=0; t1=0;

for(i=0;i<5;i++){
scnaf("%d",&t[i]);
  if(t[i]==1)
       t1++;
else if(t[i]==2)
   t2++;
else if(t[i]==3)
   t3++;
}

if(t1==0){
  if(t2==0 or t3==0)
   for(i=0;i<5;i++) t[i]=3;
else
   for(i=0;i<5;i++){
       if(t[i]==2)  t[i]=1;
      else if(t[i]==3) t[i]=2;
    }
}
else if(t2==0){
  if(t1==0 or t3==0)
   for(i=0;i<5;i++) t[i]=3;
else
   for(i=0;i<5;i++){
       if(t[i]==1)  t[i]=2;
      else if(t[i]==3) t[i]=1;
}
}

else if(t3==0){
  if(t2==0 or t1==0)
   for(i=0;i<5;i++) t[i]=3;
else
   for(i=0;i<5;i++){
       if(t[i]==2)  t[i]=2;
      else if(t[i]==1) t[i]=1;
}
}
else
   for(i=0;i<5;i++) t[i]=3;
for(i=0;i<5;i++)
   printf("%d\n",t[i]);
}
return 0
}

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[i]==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<stdio.h>
int t[5],a,b;
 
int main(){
  int i,j;
  while(1){
    scanf("%d",&t[0]);
    if(t[0]==0)break;
    for(i=1;i<5;i++)scanf("%d",&t[i]);
    for(i=0;i<5;i++){
      a=0;
      b=0;
      for(j=0;j<5;j++){
        if(i==j)continue;
        if(t[i]%3+1==t[j])a=1;
        if(t[i]==t[j]%3+1)b=1;
      }
      if(a==b)printf("3\n");
      else if(a==0)printf("2\n");
      else printf("1\n");
    }
  }
  return 0;
}

C++: #include <iostream>
#define rep(n) for(int i=0;i<(n);i++)
using namespace std;

int main(void){
	int a[5];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]){
		int b[4];
		b[1]=0;
		b[2]=0;
		b[3]=0;
		rep(5)b[a[i]]++;
		if(b[1]>0&&b[2]>0&&b[3]>0){
			rep(5) cout<<3<<endl;
			continue;
		}
		if(b[1]&&b[2]){
			rep(5){
				if(a[i]==1)cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}else if(b[2]&&b[3]){
			rep(5){
				if(a[i]==2)cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}else if(b[3]&&b[1]){
			rep(5){
				if(a[i]==3)cout<<"1"<<endl;
				else cout<<"2"<<endl;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main() {
	int a[5];
	int b[5];
	while (cin >> a[0]){
		if (a == 0)break;
		else{
			bool b1 = false, b2 = false, b3 = false;
			for (int i = 1; i < 5; i++)
				cin >> a[i];
			for (int i = 0; i < 5; i++){
				if (a[i] == 1)b1 = true;
				else if (a[i] == 2)b2 = true;
				else b3 = true;
			}
			if (b1&&b2&&b3 || b1 && !b2 && !b3 || !b1&&b2 && !b3 || !b1 && !b2&&b3) {
				for (int i = 0; i < 5; i++) {
					b[i] = 3;
				}
			}
			else{
				if (b1 == b2) {
					for (int i = 0; i < 5; i++){
						if (a[i] == 1)b[i] = 1;
						else b[i] = 2;
					}
				}
				else if (b2 == b3) {
					for (int i = 0; i < 5; i++) {
						if (a[i] == 2)b[i] = 1;
						else b[i] = 2;
					}
				}
				else{
					for (int i = 0; i < 5; i++) {
						if (a[i] == 3)b[i] = 1;
						else b[i] = 2;
					}
				}
			}
			for (int i = 0; i < 5; i++) {
				cout << b[i] << endl;
			}
		}
	}
}

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

using namespace std;

int player[5];

int main()
{	
	while (cin >> player[0], player[0]){
		int a[2] = {0}, j = 0;
		int check[4] = {1};

		check[player[0]] = -1;
		for (int i = 1; i < 5; i++){
			cin >> player[i];
			check[player[i]] = -1;
		}
		
		for (int i = 1; i < 4; i++){
			check[0] *= check[i];
			if (check[i] == -1){
				a[j++] = i;
			}
		}
		if (check[0] == -1){
			for (int i = 0; i < 5; i++){
				player[i] = 3;
			}
		}
		else if (check[3] == -1 && check[1] == -1){
			for (int i = 0; i < 5; i++){
				if (player[i] == 3)	player[i] = 1;
				else	player[i] = 2;
			}
		}
		else {
			for (int i = 0; i < 5; i++){
				if (player[i] == min(a[0], a[1]))	player[i] = 1;
				else 	player[i] = 2;
			}
		}
		for (int i = 0; i < 5; i++){
			cout << player[i] << endl;
		}
	}
	return (0);
}

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[4] < b[3] || (b[4] == 3 && b[3] == 1))puts("1");
		else puts("2");
	}
	return 0;
}

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

using namespace std;

set<int> con;
vector<int> lcon;

int main(int argc, char* argv[])
{
	int c0, c1, c2, c3, c4;
	
	while(1) {

		cin >> c0;
		if( c0 == 0 )
			break;
		
		cin >> c1 >> c2 >> c3 >> c4;

		con.insert(c0);	lcon.push_back(c0);
		con.insert(c1);	lcon.push_back(c1);
		con.insert(c2);	lcon.push_back(c2);
		con.insert(c3);	lcon.push_back(c3);
		con.insert(c4);	lcon.push_back(c4);

		for( auto c : lcon ) {

			int o0 = c%3 + 1;
			int o1 = (c+1)%3 + 1;

			bool f0 = ( con.find(o0) != con.end() );
			bool f1 = ( con.find(o1) != con.end() );

			if( c0 == c1 && c1 == c2 && c2 == c3 && c3 == c4 ){
				cout << 3 << endl;				
			}
			
			else if( f0 && !f1 ) cout << 1 << endl;			
			else if( !f0 && f1 ) cout << 2 << endl;
			else if( f0 && f1 ) cout << 3 << endl;
		}

		con.clear();
		lcon.clear();
	}

    return 0;
}

C++: int i,n,d=0b10110001000000;main(c,v){for(;;){for(v=c=i=0;i-5;++i){scanf("%d",&n);if(!n)exit(0);v|=n<<i*2;c|=1<<n;}for(n=((d>>c)&3),i=0;i-5;++i){printf("%d\n",v>>i*2&3-n?(n?2:3):1);}}}