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 <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int a[5], tmp, *b;
	
	while(1){
		cin >> tmp;
		if(tmp == 0){
			break;
		}
		a[0] = tmp;
		b = (int *)calloc(4, sizeof(int));
		b[tmp]++;
		for(int i = 1; i < 5; i++){
			cin >> tmp;
			a[i] = tmp;
			b[tmp]++;
		}
		
		if((b[1] != 0 && b[2] != 0 && b[3] != 0) || (b[1] == 0 && b[1] == b[2]) || (b[2] == 0 && b[2] == b[3]) || (b[3] == 0 && b[1] == b[3])){
			for(int i = 0; i < 5; i++){
				cout << "3" << endl;
			}
			free(b);
			continue;
		} else if(b[1] == 0){
			tmp = 2;
		} else if(b[2] == 0){
			tmp = 3;
		} else {
			tmp = 1;
		}
		
		for(int i = 0; i < 5; i++){
			cout << ((a[i] == tmp)? "1" : "2") << endl;
		}
		free(b);
	}
	
	return 0;
}

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

int main(){
  int te[3] = {1,2,3};
  int paper[10],Min;
  while(true){
    Min = 10000000;
    map<int,int> exist;
    cin >> paper[0];
    exist[paper[0]]++;
    Min = min(Min,paper[0]);
    if(paper[0] == 0)break;
    for(int i=1;i<5;i++){
      cin >> paper[i];
      Min = min(Min,paper[i]);
      exist[paper[i]]++;
    }
    if(exist[1]!=0 && exist[2]!=0 && exist[3]!=0){
      for(int i=0;i<5;i++)cout << 3 << endl;
    }
    else if(exist[1] == 5 || exist[2] == 5 || exist[3] == 5){
for(int i=0;i<5;i++)cout << 3 << endl;
    }
    else if(exist[1]!=0 && exist[3]!=0 && exist[2] == 0){
      for(int i=0;i<5;i++){
	if(paper[i] == 3)cout << 1 << endl;
	else cout << 2 << endl;
      }
    }
    else {
      for(int i=0;i<5;i++){
	if(paper[i] == Min)cout << 1 << endl;
	else cout << 2 << endl;
      }

    }
  }
  return 0;
}

C++: #include <iostream>
#define rep(i) for(i=0;i<5;i++)
using namespace std;
int main(){
  int a[5],i;
  while(1){
    int b[3]={0};
    for(i=0;i<5;i++){
      if(!a[i])return 0;
      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 <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;
		}
		int cnt = 0;
		for (int i = 1; i <= 3; i++)if (a[i])cnt++;
		if (cnt == 1 || cnt == 3) {
			rep(i, 5)puts("3");
			continue;
		}
		int m; for (int i = 1; i <= 3; i++)if (!a[i])m = i;
		int k;
		switch (m) {
		case 1:k = 2; break;
		case 2:k = 3; break;
		case 3:k = 1; break;
		}
		rep(i, 5) {
			if (b[i] == k)puts("1");
			else puts("2");
		}
	}
	return 0;
}

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

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

    if(rock >= 1 && scissors >= 1 && paper >= 1) {
      for(int i=0;i<5;i++) {
        b[i] = 3;
      }
    }
    else if(paper == 0) {
      for(int i=0;i<5;i++) {
        if(a[i] == 1) {
          b[i] = 1;
        }
        else {
          b[i] = 2;
        }
      }
    }
    else if(rock == 0) {
      for(int i=0;i<5;i++) {
        if(a[i] == 2) {
          b[i] = 1;
        }
        else {
          b[i] = 2;
        }
      }
    }
    else if(scissors == 0) {
      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>
using namespace std;
int main (){

  int a[5],cnt[3];

  while(1){

    cin >>a[0];
    
    if(a[0] == 0)break;

    for(int i=1 ; i < 5 ; i++)cin >>a[i];
    
    for(int i=0 ; i < 3 ; i++)cnt[i]=0;

    for(int i=0 ; i < 5 ; i++)cnt[a[i]-1]++;
    
    if((cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0)||a[0] == 5 || a[1] == 5 || a[2] == 5){
      
      for(int i=0 ; i < 5 ; i++)cout <<"3"<< endl;
    
    }else if(cnt[0] == 0){
      
      for(int i=0 ; i < 5 ; i++){
	if(a[i] == 2){
	  cout <<"1"<<endl;
	}else{
	  cout <<"2"<<endl;
	}
      }

    }else if(cnt[1] == 0){

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

    }else{

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

  }
  return 0;
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

int main(){
	int a[5], h[4] = { 0 };
	cin >> a[0];
	h[a[0]]++;
	while (a[0]){
		for (int i = 1; i < 5; i++){
			cin >> a[i];
			h[a[i]]++;
		}
		if ((h[1] && h[2] && h[3]) || (h[1] == 5 || h[2] == 5 || h[3] == 5)){
			for (int i = 0; i < 5; i++){
				cout << 3 << endl;
			}
		} else {
			if (h[1] == 0){
				for (int i = 0; i < 5; i++){
					if (a[i] == 2){
						cout << 1 << endl;
					} else{
						cout << 2 << endl;
					}
				}
			} else if (h[2] == 0){
				for (int i = 0; i < 5; i++){
					if (a[i] == 3){
						cout << 1 << endl;
					} else{
						cout << 2 << endl;
					}
				}
			} else {
				for (int i = 0; i < 5; i++){
					if (a[i] == 1){
						cout << 1 << endl;
					} else{
						cout << 2 << endl;
					}
				}
			}
		}
		for (int i = 0; i < 5; i++){
			a[i] = 0;
		}
		for (int i = 1; i < 4; i++){
			h[i] = 0;
		}
		cin >> a[0];
		h[a[0]]++;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	while(true){
		int cur = 0 ,d[5];
		rep(i,5) cin >> d[i] , d[i]-- ,  cur |= (1<<d[i]);
		if(__builtin_popcount(cur) == 2){
			rep(i,5)
				cout << 2 - !!count(d,d+5,(d[i]+1)%3) << endl;
		}else{
			rep(i,5)cout << 3 << endl;
		}
	}
}

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

int a[5];

void slove(int win){
  for(int i=0; i<5; i++){
    if(a[i] == win) cout << "1" << endl;
    else cout << "2" << endl;
  }
}

int main(){
  while(cin >> a[0]){
    if(a[0]==0) break;
    cin >> a[1] >> a[2] >> a[3] >> a[4];
    int count[5],flag=0;
    for(int i=0; i<5; i++) count[i] = 0;
    for(int i=0; i<5; i++){
      count[a[i]]++;
    }
    
    if((count[1]>0 && count[2]>0 && count[3]>0) || count[1]==5 || count[2]==5 || count[3]==5){
      for(int i=0; i<5; i++) cout << "3" << endl;
    }
    else{
      if(count[1] == 0) slove(2);
      if(count[2] == 0) slove(3);
      if(count[3] == 0) slove(1);
    }
  }
  return 0;
}