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 <cstdio>
#include <cstring>

using namespace std;

int main(void){
	int five[5], i, j, hand[3], var, ans, win, lose;
	while(1){
		scanf("%d",&five[0]);
		if(five[0] == 0){
			break;
		}
		for(i = 1;i < 5;i++){
			scanf("%d",&five[i]);
		}
		memset(hand,0,sizeof(hand));
		for(i = 0;i < 5;i++){ // 手の数をグー(hand[0])、チョキ(hand[1])、パー(hand[2])で数える
			hand[five[i] - 1]++;
		}
		var = 0;
		for(i = 0;i < 3;i++){ // みんなの手の種類を数える
			if(hand[i] != 0){
				var++;
			}
		}
		if(var == 1 || var == 3){ // 1種類の手と3種類の手はあいこ
			for(i = 0;i < 5;i++){
				printf("3\n");
			}
		}else{
			for(i = 0;i < 3;i++){
				if(hand[i] != 0 && hand[(i + 1) % 3] != 0){
					win = i;
					lose = (i + 1) % 3;
				}
			}
			for(i = 0;i < 5;i++){
				if(win == five[i] - 1){
					printf("1\n");
				}else{
					printf("2\n");
				}
			}
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int h[5];
  while(cin>>h[0],h[0]){
    cin>>h[1]>>h[2]>>h[3]>>h[4];
    for(int i=0;i<5;i++){
      bool f1=0,f2=0;
      for(int j=0;j<5;j++){
	if(i==j) continue;
	if(h[i]==1){
	  f1|=h[j]==2;
	  f2|=h[j]==3;
	}
	if(h[i]==2){
	  f1|=h[j]==3;
	  f2|=h[j]==1;
	}
	if(h[i]==3){
	  f1|=h[j]==1;
	  f2|=h[j]==2;
	}
      }
      cout<<(f1|f2?f1+f2*2:3)<<endl;
    }
  }
  return 0;
}

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

using namespace std;

int main() {
  int a[5];
  while (scanf("%d%d%d%d%d", a, a+1, a+2, a+3, a+4) == 5) {
    bool b[3] = {0};
    for (int i = 0; i < 5; i++)
      b[a[i]-1] = true;
    if (b[0] && b[1] && b[2] ||
        b[0] && !b[1] && !b[2] ||
        !b[0] && b[1] && !b[2] ||
        !b[0] && !b[1] && b[2])
      for (int i = 0; i < 5; i++)
        cout << 3 << endl;
    else {
      int w;
      if (b[0] && b[1])
        w = 1;
      else if (b[1] && b[2])
        w = 2;
      else
        w = 3;
      for (int i = 0; i < 5; i++)
        cout << (a[i] == w ? 1 : 2) << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int array[5];
int ret[4];
void p(int a,int b,int c){

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

  while(cin >> array[0] ,array[0]){
    fill(ret,ret + 4,0);
    ret[array[0]-1] = 1;
    for(int i = 1 ; i < 5 ; i++ ){
      cin >> array[i];
      ret[array[i]] = 1;
  }
    if(ret[1] != 0 && ret[2] != 0 && ret[3] == 0){
      p(1,2,3);
    }else if(ret[2] != 0 && ret[3] != 0 && ret[1] == 0){
      p(2,3,1);
    }else if(ret[1] != 0 && ret[3] != 0 && ret[2] == 0){
      p(3,1,2);
    }else p(4,4,4);
  }
}

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[0]){
		cin>>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<vector>
int main(){
	while(1){
		std::vector<int> vec(5);
		std::vector<int> vec2(5);
		int a=0;
		std::cin>>a;
		if(a==0)break;
		int d=0,e=0,f=0;
		if(a==1)d++;
		if(a==2)e++;
		if(a==3)f++;
		vec[0]=a;
		
		for(int i=1;i<5;i++){
			int b;
			std::cin>>b;
			if(b==1)d++;
			if(b==2)e++;
			if(b==3)f++;
			vec[i]=b;
		}
		if(d>=1&&e>=1&&f>=1||d==5||f==5||e==5){
			for(int i=0;i<5;i++){
				vec2[i]=3;
			}
		}else if(d>=1&&e>=1&&f==0){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=1;
				if(vec[i]==2)vec2[i]=2;
			}
		}else if(d>=0&&e>=1&&f>=1){
			for(int i=0;i<5;i++){
				if(vec[i]==2)vec2[i]=1;
				if(vec[i]==3)vec2[i]=2;
			}
		}else if(d>=1&&e>=0&&f>=1){
			for(int i=0;i<5;i++){
				if(vec[i]==1)vec2[i]=2;
				if(vec[i]==3)vec2[i]=1;
			}
		}
		for(int i=0;i<5;i++){
			std::cout<<vec2[i]<<std::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;
    c[a[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 <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>
#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 <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int five[5];
const int winner[4][2] = {{0, 0}, {2, 3}, {3, 1}, {1, 2}};

int main() {
	while(1) {
		cin >> five[0];
		if(!five[0]) break;
		for(int i = 1; i < 5; ++i) {
			cin >> five[i];
		}

		int f[4];
		memset(f, 0, sizeof f);
		for(int i = 0; i < 5; ++i) {
			int t = five[i];
			f[t]++;
		}
		if(f[1] && f[2] && f[3]) {
			for(int i = 0; i < 5; i++) {
				cout << 3 << endl;
			}
			goto NEXT;
		}
		for(int i = 1; i <= 3; ++i) {
			if(f[i] == 5) {
				for(int j = 0; j < 5; ++j) {
					cout << 3 << endl;

				}
				goto NEXT;
			}
		}
		for(int i = 1; i <= 3; ++i) {
			if(f[i] == 0) {
				for(int j = 0; j < 5; ++j) {
					if(winner[i][0] == five[j]) {
						cout << 1 << endl;
					} else {
						cout << 2 << endl;
					}
				}
			}
		}
		NEXT:
		;
	}
	return 0;
}