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 a, b, c, d, e, x[4], f;
int main() {
	while (true) {
		x[0] = 0;
		x[1] = 0;
		x[2] = 0;
		x[3] = 0;
		cin >> a;
		if (a == 0) { break; }
		x[a]++;
		cin >> b >> c >> d >> e;
		x[b]++;
		x[c]++;
		x[d]++;
		x[e]++;
		if (x[1] >= 1 && x[2] >= 1 && x[3] >= 1) { cout << '3' << endl << '3' << endl << '3' << endl << '3' << endl << '3' << endl; }
		else if (x[1] >= 5 || x[2] >= 5 || x[3] >= 5) { cout << '3' << endl << '3' << endl << '3' << endl << '3' << endl << '3' << endl; }
		else {
			if (x[2] == 0) {
				if (a == 1) { a = 4; }
				if (b == 1) { b = 4; }
				if (c == 1) { c = 4; }
				if (d == 1) { d = 4; }
				if (e == 1) { e = 4; }
			}
			if (x[1] == 0) { f = 2; }
			if (x[2] == 0) { f = 3; }
			if (x[3] == 0) { f = 1; }
			if (a == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (b == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (c == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (d == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
			if (e == f) { cout << '1' << endl; }
			else { cout << '2' << endl; }
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int P[5];
bool B[3];
int R[5];

int main(int argc, char** argv)
{
	while( 1 )
	{
		cin >> P[0];

		if(P[0]==0) break;

		cin >> P[1];
		cin >> P[2];
		cin >> P[3];
		cin >> P[4];

		B[0] = false; B[1] = false; B[2] = false;
		for(int i=0; i<5; i++)
		{
			B[P[i]-1] = true;
		}

		if(B[0] && B[1] && B[2])
		{
			for(int i=0; i<5; i++)
			{
				R[i] = 3;
			}
		}
		else if(B[0] && B[1])
		{
			for(int i=0; i<5; i++)
			{
				if(P[i]==1) R[i] = 1;
				if(P[i]==2) R[i] = 2;
			}
		}
		else if(B[1] && B[2])
		{
			for(int i=0; i<5; i++)
			{
				if(P[i]==2) R[i] = 1;
				if(P[i]==3) R[i] = 2;
			}
		}
		else if(B[2] && B[0])
		{
			for(int i=0; i<5; i++)
			{
				if(P[i]==3) R[i] = 1;
				if(P[i]==1) R[i] = 2;
			}
		}
		else
		{
			for(int i=0; i<5; i++)
			{
				R[i] = 3;
			}
		}

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

	return 0;
}

C++: #include <iostream>

using namespace std;

main(){
  int te[5];
  bool f[4];
  while(1){
    cin >> te[0];
    if(te[0]==0) break;
    for(int i=0;i<4;i++) f[i]=false;
    for(int i=1;i<5;i++){
      cin >> te[i];
    }
    for(int i=0;i<5;i++){
      f[te[i]]=true;
    }
    if(f[1] && f[2] && f[3]){
      for(int i=0;i<5;i++){
	cout << 3 << endl;
      }
    }else if(f[1] && f[2]){
      for(int i=0;i<5;i++){
	if(te[i]==1){
	  cout << 1 << endl;
	}else{
	  cout << 2 << endl;
	}
      }
    }else if(f[2] && f[3]){
      for(int i=0;i<5;i++){
	if(te[i]==2){
	  cout << 1 << endl;
	}else{
	  cout << 2 << endl;
	}
      }
    }else if(f[3] && f[1]){
      for(int i=0;i<5;i++){
	if(te[i]==3){
	  cout << 1 << endl;
	}else{
	  cout << 2 << endl;
	}
      }
    }else if(f[1]){
      for(int i=0;i<5;i++){
	cout << 3 << endl;
      }
    }else if(f[2]){
      for(int i=0;i<5;i++){
	cout << 3 << endl;
      }
    }else{
      for(int i=0;i<5;i++){
	cout << 3 << endl;
      }
    }
  }
  return 0;
}

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

C++: #include <iostream>

using namespace std;

int main(void){

  int j[5];
  bool R,S,P;


  while(cin >> j[0], j[0]){
    for( int i = 1 ; i < 5 ; i++ ){
      cin >> j[i];
    }
    R = S = P = false;
    for( int i = 0 ; i < 5 ; i++ ){
      if(j[i] == 1 ) R = true;
      if(j[i] == 2 ) S = true;
      if(j[i] == 3 ) P = true;
    }
    if( R && S && P )
      for( int i = 0 ; i < 5 ; i++ )
	cout << "3" << endl;

    else if( R && S && !P ) // パーなし
      for( int i = 0 ; i < 5 ; i++ ){
	switch(j[i]){
	case 1:
	  cout << "1" << endl;
	  break;
	case 2:
	  cout << "2" << endl;
	  break;
	}
      }
    else if( R && !S && P ) // チョキなし
      for( int i = 0 ; i < 5 ; i++ ){
	switch(j[i]){
	case 1:
	  cout << "2" << endl;
	  break;
	case 2:
	  cout << "1" << endl;
	  break;
	}
      }
    else if( !R && S && P ) // グーなし
      for( int i = 0 ; i < 5 ; i++ ){
	switch(j[i]){
	case 2:
	  cout << "1" << endl;
	  break;
	case 3:
	  cout << "2" << endl;
	  break;
	}
      }
  }
  return 0;
}

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

using namespace std;

int main() {
  for (;;) {
    int a[5], c[4];
    cin >> a[0];
    if (!a[0]) return 0;
    fill(c+1, c+4, 0);
    for (int i = 1; i < 5; i++) {
      cin >> a[i];
      c[a[i]]++;
    }
    int w = 0;
    if (!c[1] && c[2] && c[3])
      w = 2;
    else if (c[1] && !c[2] && c[3])
      w = 3;
    else if (c[1] && c[2] && !c[3])
      w = 1;
    if (w)
      for (int i = 0; i < 5; i++)
        cout << (a[i] == w ? 1 : 2) << endl;
    else
      for (int i = 0; i < 5; i++)
        cout << 3 << endl;
  }
}

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

int main(void){
	int i,sum,x[5],ans[3];
	bool flg[3];

	while(1){
		memset(flg,0,sizeof(flg));
		for(i=0;i<5;i++){
			cin>>x[i];
			if(x[i] == 0) return 0;
			flg[x[i]-1] = true;
		}

		sum = flg[0] + flg[1] + flg[2];
		if(sum==1 || sum==3){
			for(i=0;i<5;i++) printf("3\n");
		}
		else{
			if(flg[0] && flg[1]){
				ans[0] = 1;
				ans[1] = 2;
			}
			else if(flg[0] && flg[2]){
				ans[0] = 2;
				ans[2] = 1;
			}
			else{
				ans[1] = 1;
				ans[2] = 2;
			}
			for(i=0;i<5;i++){
				printf("%d\n",ans[x[i]-1]);
			}
		}
	}
}

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++) result[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");
			}
		}
	}
}