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++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	vector<int>h(5);
	while (cin >> h[0], h[0]) {
		vector<int>aiko(4, 0);
		aiko[h[0]]++;
		rep(i, 1, 5) {
			cin >> h[i]; aiko[h[i]]++;
		}
		if (aiko[1] && aiko[2] && aiko[3]||aiko[1]==5||aiko[2]==5||aiko[3]==5)rep(i,0,5)cout << 3 << endl;
		else {
			int win, lose;
			if (aiko[1] == 0) { win = 2; lose = 3; }
			else if (aiko[2] == 0) { win = 3; lose = 1; }
			else win = 1; lose = 2;
			rep(i, 0, 5) {
				if (h[i] == win)cout << 1 << endl;
				else cout << 2 << endl;
			}


		}

	}
	return 0;
}

C++: #include<iostream>
int main(){while(1){int s[6],g[4]={0},n=-2,v=0,i;for(i=5;i;i--){std::cin>>s[i];if(!*s)goto l;if(!g[s[i]]){n++;g[s[i]]=1;if(v-1==s[i]%3||!v)v=s[i];}}for(i=5;i;i--)std::cout<<(!n?(v==s[i]?1:2):3)<<"\n";}l:;exit(0);}

C++: #include<iostream>

using namespace std;

int main(){

  int data[5], d[3];

  while(1){

    for(int i = 0; i < 3; i++) d[i] = 0;


    for(int i = 0; i < 5; i++){
      cin >> data[i];
      if(data[0] == 0) return 0;
      if(data[i] == 1) d[0]++;
      else if(data[i] == 2) d[1]++;
      else d[2]++;
    }

      if(d[0] > 0 && d[1] > 0 && d[2] > 0 || d[0] == 5 || d[1] == 5 || d[2] == 5){
	for(int j = 0; j < 5; j++) cout << "3" << endl;
      }else if(d[0] == 0){
	for(int j = 0; j < 5; j++){
	  if(data[j] == 2) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }else if(d[1] == 0){
	for(int j = 0; j < 5; j++){
	  if(data[j] == 3) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }else{
	for(int j = 0; j < 5; j++){
	  if(data[j] == 1) cout << "1" << endl;
	  else cout << "2" << endl;
	}
      }
  }

  return 0;
}

C++: 3
3
3

C++: #include<iostream>
int main(){while(1){int s[6],g[4]={0},n=-2,v=0,i;for(i=5;i;i--){std::cin>>s[i];if(!s[5])goto l;if(!g[s[i]]){n++;g[s[i]]=1;if(v-1==s[i]%3||!v)v=s[i];}}for(i=5;i;i--)std::cout<<(!n?(v==s[i]?1:2):3)<<"\n";}l:;return 0;}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int a[5];
  int r,p,s;
  while(1){
    r=0;
    p=0;
    s=0;
    for(int i=0;i<5;i++){
      cin>>a[i];
      switch(a[i]){
      case 0:
	return 0;
      case 1:
	r=1;
	break;
      case 2:
	s=1;
	break;
      case 3:
	p=1;
	break;
      }
    }
    for(int i=0;i<5;i++){
      if((r==1&&p==1&&s==1)||(r==1&&p==0&&s==0)||(r==0&&p==1&&s==0)||(r==0&&p==0&&s==1)){
	printf("3\n");
      }
      else{
	switch(a[i]){
	case 1:
	  if(s==1){
	    printf("1\n");
	  }
	  else{
	    printf("2\n");
	  }
	  break;
	case 2:
	  if(p==1){
	    printf("1\n");
	  }
	  else{
	    printf("2\n");
	  }
	  break;
	case 3:
	  if(r==1){
	    printf("1\n");
	  }
	  else{
	    printf("2\n");
	  }
	  break;
	}
      }
    }
  }
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[5];
 int arr_2[5];
 
 int main()
 {
   int n;
   while(1)
   {
     cin>>n;
     if(n==0) break;
     else arr[0]=n;
     for(int i=1;i<5;i++) cin>>arr[i];
     int min=4;
     int max=0;
     for(int i=0;i<5;i++) arr_2[i]=arr[i];
     sort(arr_2,arr_2+5);
     int count=0;
     for(int i=0;i<4;i++)
     {
       if((arr_2[i+1]-arr_2[i])==1) count++;          
     }
     if(count==2)
     {
       int count2=5;
       while(count2--) cout<<"3"<<endl;          
     }
     for(int i=0;i<5;i++)
     {
       if(arr[i]>max) max=arr[i];
       if(arr[i]<min) min=arr[i];        
     }  
     if(min==1&&max==2)
     {
       for(int i=0;i<5;i++)
       {
         if(arr[i]==1) cout<<"1"<<endl;
         else cout<<"2"<<endl;        
       }                  
     }
     else if(min==2&&max==3)
     {
       for(int i=0;i<5;i++)
       {
         if(arr[i]==2) cout<<"1"<<endl;
         else cout<<"2"<<endl;        
       }                  
     }
     else if(min==1&&max==3)
     {
       for(int i=0;i<5;i++)
       {
         if(arr[i]==1) cout<<"2"<<endl;
         else cout<<"1"<<endl;        
       }                  
     }
   }
   //while(1);
   return 0;
 }

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






























































































































































































































































































































































































































int main()
{
	for(;;){
		int a;
		int b;
		int c;
		int d;
		int e;
		cin >> a;
		if(a==0)break;
		cin >> b >> c >> d >> e;
		int x1=0;
		int x2=0;
		int x3=0;
		if(a==1)x1++;
		if(a==2)x2++;
        if(a==3)x3++;
		if(b==1)x1++;
		if(b==2)x2++;
        if(b==3)x3++;
		if(c==1)x1++;
		if(c==2)x2++;
        if(c==3)x3++;
		if(d==1)x1++;
		if(d==2)x2++;
        if(d==3)x3++;
		if(e==1)x1++;
		if(e==2)x2++;
        if(e==3)x3++;
		if(x1>=1&&x2>=1&&x3>=1){
			printf("3\n3\n3\n3\n3\n");
		}
		else if(x1==5){
			printf("3\n3\n3\n3\n3\n");
		}
		else if(x2==5){
			printf("3\n3\n3\n3\n3\n");
		}
		else if(x3==5){
			printf("3\n3\n3\n3\n3\n");
		}
		else if(x3==0){
			if(a==1)printf("1\n");
			if(a==2)printf("2\n");
			if(b==1)printf("1\n");
			if(b==2)printf("2\n");
			if(c==1)printf("1\n");
			if(c==2)printf("2\n");
			if(d==1)printf("1\n");
			if(d==2)printf("2\n");
			if(e==1)printf("1\n");
			if(e==2)printf("2\n");
		}
		else if(x2==0){
			if(a==3)printf("1\n");
			if(a==1)printf("2\n");
			if(b==3)printf("1\n");
			if(b==1)printf("2\n");
			if(c==3)printf("1\n");
			if(c==1)printf("2\n");
			if(d==3)printf("1\n");
			if(d==1)printf("2\n");
			if(e==3)printf("1\n");
			if(e==1)printf("2\n");
		}
		else if(x1==0){
			if(a==2)printf("1\n");
			if(a==3)printf("2\n");
			if(b==2)printf("1\n");
			if(b==3)printf("2\n");
			if(c==2)printf("1\n");
			if(c==3)printf("2\n");
			if(d==2)printf("1\n");
			if(d==3)printf("2\n");
			if(e==2)printf("1\n");
			if(e==3)printf("2\n");
		}
	}
	return 0;
}