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>
#define rep(i) for(i=0;i<5;i++)
using namespace std;
int main(){
  int a[5],i;
  while(cin>>a[0],a[0]){
    int b[3]={0};
    b[a[0]-1]++;
    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 <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;
		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");
			}
		}
	}
}

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] == 2)
						cout << '2' << endl;
					else
						cout << '1' << endl;
				}
			}
		}
	}
	return 0;
}

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

int main(){
	int hand[5], result[5];
	int rock, scissors, paper, win;
	
	while(cin >> hand[0], hand[0]){
		cin >> hand[1] >> hand[2] >> hand[3] >> hand[4];
		
		rock = scissors = paper = 0;
		for(int i = 0; i < 5; ++i){
			switch(hand[i]){
				case 1: ++rock; break;
				case 2: ++scissors; break;
				case 3: ++paper; break;
				default: break;
			}
		}
		
		if(rock == 5 || scissors == 5 || paper == 5 || (rock > 0 && scissors > 0 && paper > 0)){
			for(int i = 0; i < 5; ++i) result[i] = 3;
		}else{
			if(rock == 0) win = 2;
			else if(scissors == 0) win = 3;
			else win = 1;
			
			for(int i = 0; i < 5; ++i){
				if(hand[i] == win) result[i] = 1;
				else result[i] = 2;
			}
		}
		
		for(int i = 0; i < 5; ++i) cout << result[i] << endl;
	}
	
	return 0;
}

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

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

using namespace std;

int main()
{
	int t;
	while(cin >> t && t)
	{
		vector<int> v;
		v.push_back(t);

		rep(i,4)
		{
			cin >> t;
			v.push_back(t);
		}
		
		map<int,int> m;
		rep(i,5)
		{
			m[v[i]]++;
		}

		if(m.size() >= 3 || m.size() == 1)
		{
			rep(i,5) cout << 3 << endl;
		}
		else
		{
			if(m[1] > 0 && m[2] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 1) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
			else if(m[2] > 0 && m[3] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 1) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
			else if(m[1] > 0 && m[3] > 0)
			{
				rep(i,5)
				{
					if(v[i] == 3) cout << 1 << endl;
					else cout << 2 << endl;
				}
			}
		}
	}
	return 0;
}

C++: #include <cstdio>

int main(){
  int h[5], c[4];

  while(scanf("%d", h) && h[0]){
    c[0] = c[1] = c[2] = c[3] = 0;
    c[h[0]]++;
    for(int i = 1; i < 5; ++i){ scanf("%d", h + i); c[h[i]]++;}

    if(c[1] && c[2] && c[3]) for(int i = 0; i < 5; ++i) puts("3");
    else if(c[1] && c[2]) for(int i = 0; i < 5; ++i) puts(h[i] == 1 ? "1" : "2");
    else if(c[2] && c[3]) for(int i = 0; i < 5; ++i) puts(h[i] == 2 ? "1" : "2");
    else if(c[3] && c[1]) for(int i = 0; i < 5; ++i) puts(h[i] == 3 ? "1" : "2");
  }
  return 0;
}

C++: #include <cstdio>

#define CH_G(a, g) (a == 1) ? true : g
#define CH_C(a, c) (a == 2) ? true : c
#define CH_P(a, p) (a == 3) ? true : p


int main(void)
{
	int hand[5];
	int i;
	bool g, c, p;
	
	while (1){
		g = c = p = false;
		
		scanf("%d", &hand[0]);
		if (hand[0] == 0) break;
		g = CH_G(hand[0], g);
		c = CH_C(hand[0], c);
		p = CH_P(hand[0], p);
		
		for (i = 1; i < 5; i++){
			scanf("%d", &hand[i]);
			g = CH_G(hand[i], g);
			c = CH_C(hand[i], c);
			p = CH_P(hand[i], p);
		}
		
		if ((g && c && p) || (g && !c && !p) || (!g && c && !p) || (!g && !c && p)){
			for (i = 0; i < 5; i++) printf("3\n");
		}
		else if (g && c){
			for (i = 0; i < 5; i++){
				if (hand[i] == 1) printf("1\n");
				else printf("2\n");
			}
		}
		else if (c && p){
			for (i = 0; i < 5; i++){
				if (hand[i] == 2) printf("1\n");
				else printf("2\n");
			}
		}
		else if (g && p){
			for (i = 0; i < 5; i++){
				if (hand[i] == 3) printf("1\n");
				else printf("2\n");
			}
		}
	}
	
	return (0);
}