/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	static void separate4Colors(int[] a) {
		int[] index = new int[4];
		for(int n : a) {
    		int r = n % 4;
    		if (r != 3) {
        		index[r+1]++;
    		}
		}
		index[2] += index[1];
		index[3] += index[2];
		int[] res = new int[a.length];
		for(int n : a) {
    		res[index[n%4]++] = n;
		}
		System.arraycopy(res, 0, a, 0, a.length);
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		int[] a = new int[]{0,2,4,5,6,8,7,9,10,12,14,15,17,20,1};
		System.out.println(Arrays.toString(a));
		separate4Colors(a);
		System.out.println(Arrays.toString(a));
	}
}