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<bits/stdc++.h>
using namespace std;
#define N 5
main() {
	int T[N];
	while( cin >> T[0] && T[0] ) {
		for ( int i = 1; i < N; i++ ) cin >> T[i];
		for ( int i = 0; i < N; i++ ) {
			int w = 0, l = 0;
			for ( int j = 0; j < N; j++ ) {
				if ( T[i]%3 == T[j]-1 ) w++;
				if ( T[j]%3 == T[i]-1 ) l++;
			}
			if ( w && !l ) cout << 1 << endl;
			else if ( l && !w ) cout << 2 << endl;
			else cout << 3 << endl;
		}
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;

int a[5];

int main(){
	while (1){
		bool f[5] = {};
		REP(i, 5){
			cin >> a[i];
			if (!a[i])return 0;
			f[a[i]] = 1;
		}
		if ((f[1] && f[2] && f[3]) || (f[1] && !f[2] && !f[3]) || (!f[1] && f[2] && !f[3])
			|| (!f[1] && !f[2] && f[3])){
			REP(i, 5){
				cout << 3 << endl;
			}
			continue;
		}
		REP(i, 5){
			if (!f[2]){
				a[i] = (a[i] + 1) % 3;
			}
			else if (!f[1]){
				a[i]--;
			}
			cout << a[i] << endl;
		}
	}
}

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

int main(){

  int n[5];

  while(cin >> n[0], n[0]){

    for(int i=1;i<5;i++) cin >> n[i];

    int a = 0,b = 0,c = 0;

    for(int i=0;i<5;i++){
      if(n[i] == 1) a++;
      else if(n[i] == 2) b++;
      else if(n[i] == 3) c++;
    }

    if(a && b && c){
      for(int i=0;i<5;i++) cout << 3 << endl;
    }

    else if((!a && !b) || (!b && !c) || (!a && !c)){
      for(int i=0;i<5;i++) cout << 3 << endl;
    }

    else if(!c){
      for(int i=0;i<5;i++) cout << n[i] << endl;
    }

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

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

  }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int h[5];
  while(cin>>h[0],h[0]){
    for(int i=1;i<5;i++) cin>>h[i];
    int x[4]={};
    for(int i=0;i<5;i++) x[h[i]]++;
    int a[5]={};
    if(x[1]&&x[2]&&x[3]){
      for(int i=0;i<5;i++) a[i]=3;
    }else if(!!x[1]+!!x[2]+!!x[3]==1){
      for(int i=0;i<5;i++) a[i]=3;
    }else{
      if(!x[1]){
	for(int i=0;i<5;i++){
	  if(h[i]==2) a[i]=1;
	  else a[i]=2;
	}
      }
      if(!x[2]){
	for(int i=0;i<5;i++){
	  if(h[i]==3) a[i]=1;
	  else a[i]=2;
	}
      }
      if(!x[3]){
	for(int i=0;i<5;i++){
	  if(h[i]==1) a[i]=1;
	  else a[i]=2;
	}
      }
    }
    for(int i=0;i<5;i++) cout<<a[i]<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int p[5];
  while(1){
    int g=0,tyo=0,pa=0;
    cin >> p[0];
    if(p[0]==1){
      g++;
    }
    else if(p[0]==2){
      tyo++;
    }
    else if(p[0]==3){
      pa++;
    }
    if(p[0]==0){
      break;
    }
    for(int i=1;i<5;i++){
      cin >> p[i];
      if(p[i]==1){
	g++;
      }
      else if(p[i]==2){
	tyo++;
      }
      else if(p[i]==3){
	pa++;
      }
    }

    if(g>0 && tyo>0 && pa>0){
      for(int i=0;i<5;i++){
	p[i]=3;
      }
    }
    else if(g==5 || tyo==5 || pa==5){
      for(int i=0;i<5;i++){
	p[i]=3;
      }
    }
    else if(g<=0 && tyo>0 && pa>0){
      for(int i=0;i<5;i++){
	if(p[i]==2){
	  p[i]=1;
	}
	else if(p[i]==3){
	  p[i]=2;
	}
      }
    }
    else if(g>0 && tyo>0 && pa<=0){
      for(int i=0;i<5;i++){
	if(p[i]==1){
	  p[i]=1;
	}
	else if(p[i]==2){
	  p[i]=2;
	}
      }
    }
    else if(g>0 && tyo<=0 && pa>0){
      for(int i=0;i<5;i++){
	if(p[i]==1){
	  p[i]=2;
	}
	else if(p[i]==3){
	  p[i]=1;
	}
      }
    }

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

  }
}

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){
			if(cin >> d[i]) d[i]-- ,  cur |= (1<<d[i]);
			else return 0;
		}
		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<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int hand[6]={0};
    while(cin>>hand[0],hand[0]){
            int flg[5]={0};
        for(int i=1;i<5;i++)cin>>hand[i];
        for(int i=0;i<5;i++){
            if(hand[i]==1)flg[1]=1;
            if(hand[i]==2)flg[2]=1;
            if(hand[i]==3)flg[3]=1;
        }
        if(flg[1]==1&&flg[2]==1&&flg[3]==1)for(int i=0;i<5;i++)cout<<"3"<<endl;
        else if(flg[1]==1&&flg[2]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==1)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[2]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==2)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
        else if(flg[1]==1&&flg[3]==1){
            for(int i=0;i<5;i++){
                if(hand[i]==3)cout<<"1"<<endl;
                else cout<<"2"<<endl;
            }
        }
    }
    return 0;
}

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

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

C++: #include <iostream>

using namespace std;

int main(){
        while(1){
                unsigned char hand[5]={};
                unsigned char sum=0;
                for(int i=0;i<5;i++){
                        int h;
                        cin>>h;
                        if(h==0) return 0;
                        hand[i]=1<<(h-1);
                        sum|=hand[i];
                }
                if(sum==7) cout<<"3\n3\n3\n3\n3\n";
                else {
                        for(int i=0;i<5;i++){
                                if(sum==hand[i]) cout<<"3\n";
                                else if((sum^hand[i])==(hand[i]<<1)||(sum^hand[i])==(hand[i]>>2)) cout<<"1\n";
                                else if((sum^hand[i])==(hand[i]>>1)||(sum^hand[i])==(hand[i]<<2)) cout<<"2\n";
                        }
                }
        }
        return 0;
}