var n = readline();
var str = readline().split(' ').map(function(a){return parseInt(a);}).sort(function(a,b){return b-a;});
var cars = 0;

for (var i = 0; 0 < str.length; cars++) {
    var sum = str.shift();

    for (var j = str.length - 1; j >= 0; j--) {
        if (sum === 4 || sum + str[j] > 4) break;
        sum = sum + str.splice(j, 1)[0];
    }
}

print(cars);

var IN1 = readline().split(' ').map(function(s){return parseInt(s)})
var IN2 = readline().split(' ').map(function(s){return parseInt(s)})

var n = IN1[0]
var ss = IN2

var n1=0,n2=0,n3=0,n4=0

ss.some(function(si){
  switch(si){
  case 1:
    n1+=1
    break
  case 2:
    n2+=1
    break
  case 3:
    n3+=1
    break
  case 4:
    n4+=1
    break
  }
})

var t = 0

t+=n4

t+=n3

if(n1<n3){
  n1 = 0
} else {
  n1-=n3
}

t+=Math.floor(n2/2)
n2-=Math.floor(n2/2)*2

if(0<n2){
  t+=n2
  n1-=2
}

if(0<n1){
  t+=Math.ceil(n1/4)
}

write(t)

	var n = readline();
	var str = readline().split(" ").sort((x,y)=>x-y);
	var res = 0;
	var l = 0;

	for (var i=n-1; i>=l; i--){
		var sum = +str[i];
				while(+sum+Number(str[l]) <= 4){
					sum+= +str[l];
					l++;
				}
			res++;
		 }

	print(res);

var a = readline();
var cin = readline().split(' ').sort(function(a,b){return a-b});
var jami = 0;
var ori = 0, sami = 0, erti = 0;
for(i = 0; i < a; i ++) {
	if(cin[i] == 4) {
		jami += 1;
	}
	if(cin[i] == 1) {
		erti += 1;
	}
	if(cin[i] == 2) {
		ori += 1;
	}
	if(cin[i] == 3) {
		sami += 1;
	}
}
if(ori % 2 == 1) {
	jami = jami + Math.floor(ori / 2);
	ori = 2;
}
else {
	jami = jami + ori/2; // ori movagvare
	ori = 0;
}
if (sami > erti) {
	jami = jami + sami + ori/2;// mogvarda 3 tema
}
else {
	erti = erti - sami;
	jami = jami + sami + Math.ceil((ori + erti)/4);
}
print(jami);

line = readline();
groups = readline().split(' ');
count = [0, 0, 0, 0, 0];
groups.forEach(function(group) { ++count[group]; });
taxis = [
        count[4],
        Math.min(count[1], count[3]),
        Math.max(0, count[3] - count[1]),
        Math.floor(count[2] / 2),
        Math.ceil((Math.max(0, count[1] - count[3]) + (count[2] % 2 == 0 ? 0 : 2)) / 4)
]
print(taxis.reduce(function(prev, x) { return prev + x; }));

var pasar = readline();
var entrada = readline().split(" ");
var taxis = 0, cantidad_de_pibes = 0, c_tres = 0, c_unos = 0, c_dos = 0;
for (var i = 0; i < entrada.length; i++){
  entrada[i] = parseInt(entrada[i]);
  if (entrada[i] == 1){
    c_unos++;
  } else if (entrada[i] == 2){
    c_dos++;
  } else if (entrada[i] == 3){
    c_tres++;
  } else if (entrada[i] == 4){
    taxis++;
  }
}
if (c_tres == c_unos){
  taxis += c_tres;
  c_unos = 0;
} else if (c_tres > c_unos){
  taxis += c_unos + (c_tres - c_unos);
  c_unos = 0;
} else if (c_tres < c_unos) {
  taxis += c_tres;
  c_unos = c_unos - c_tres;
}
taxis += parseInt(c_dos / 2);
if (c_dos % 2 !== 0){
  c_dos = 0;
  if (c_unos >= 2){
    c_unos -= 2;
  } else if (c_unos == 1){
    c_unos--;
  }
  taxis += 1;
}
taxis += parseInt(c_unos / 4);
if (c_unos % 4 !== 0){
  taxis++;
}

print (taxis);

var cantNum = readline();
  var groupsList = readline().split(' ').map(function(x){return parseInt(x);}).sort(function(a,b){return b-a;});
  var cantTaxis = 0;
  for (var i = 0; 0 < groupsList.length; cantTaxis++) {
    var sum = groupsList.shift();
    for (var j = groupsList.length-1; j >= 0; j--) {
      if(sum == 4 || sum + groupsList[j] > 4) break;
      sum += groupsList.splice(j,1)[0];
    }
  }
  print(cantTaxis);

/* TEST CASE
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5

 */

function main() {
	var n = parseInt(readline());
	var a = [0, 0, 0, 0, 0];
	var answer = 0;
	var i;
	var splitted = readline().split(' ');
	var move;

	for (i = 0; i < n; i++) {
		a[parseInt(splitted[i])]++;
	}
	if (a[3] > 0 && a[1] > 0) {
		move = Math.min(a[3], a[1]);
		a[4] += move;
		a[3] -= move;
		a[1] -= move;
	}
	if (a[2] > 1) {
		move = (a[2] >> 1);
		a[4] += move;
		a[2] -= (move << 1);
	}
	answer = a[4] + a[3] + Math.ceil((a[2] * 2 + a[1]) / 4.0);
	print(answer);
}

main();

var n = readline();
var nums = readline().split(' ').map(function(each) {
  return Number(each);
});

nums.sort(function(a, b) {
  return a - b;
});

var i = 0;
var taxis = 0;
var j = nums.length - 1;

while (i <= j) {
  var sum = nums[j];
  j--;

  while (i <= j) {
    var newSum = sum + nums[i];

    if (newSum > 4)
      break;

    i++;
    sum = newSum;
  }

  taxis++;
}

print(taxis);

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main(){
    var n = readline();
    var arr = readNumArray();
    var car = 0;
    var one = 0;
    var two = 0;
    var three = 0;
    var four = 0;
    for (var i = 0; i < arr.length; i++) {
            if(arr[i] == 1) one++;
            else if(arr[i] == 2) two++;
            else if(arr[i] == 3) three++;
            else if(arr[i] == 4) four++;
    }
    car += four;
    four = 0;
    minn = Math.min(three,one);
    car += minn;
    three -= minn;
    one -= minn;
    if(two >= 2){
        car += Math.floor(two/2);
        two = two%2;
    }
    car += three;
    if(one > 0){
        if(two > 0){
            two -= 1
            one -= 2
            car += 1
        }
    }
    if(one > 0){
        car += Math.floor(one/4);
        if(one%4 != 0) car +=1;
    }
    if(two > 0) car += 1;
    print(car)
}
main();

//158B - Taxi
Array.prototype.count = function(val) {
    return this.filter(e => e == val).length;
}
var n = +readline();
var numbers = readline().split(' ').map(e => parseInt(e)).sort().reverse();

var res = numbers.filter(e => e == 4).length;
numbers = numbers.filter(e => e != 4);

res += (() => {
    var one = numbers.count(1);
    var three = numbers.count(3);
    numbers.splice(numbers.indexOf(3), three);
    var countOf4 = (one < three) ? one : three;
    numbers.splice(numbers.indexOf(1), countOf4);
    return three;
})();

res += (() => {
    var two = numbers.count(2);
    var countOf422 = 0 | two / 2;
    two = two - countOf422 * 2;
    var one = numbers.count(1);
    if (two) {
        numbers.splice(numbers.indexOf(1), (one > 2) ? 2 : one);
    }
    numbers.splice(numbers.indexOf(2), numbers.count(2));
    return countOf422 + two;
})();
res += (() => {
    var one = numbers.count(1);
    if (one % 4 == 0) {
        return one / 4;
    } else {
        return 0 | (one / 4 + 1);
    }
})();
print(res);

var n = parseInt(readline());
var groups = readline().split(" ");
var counters = [0, 0, 0, 0, 0];
for(var i = 0; i < n; i++) {
    var cur = parseInt(groups[i]);
    counters[cur]++;
}

var result = 0;
result += counters[4];

result += counters[3];
counters[1] = Math.max(counters[1] - counters[3], 0);

result += Math.floor(counters[2] / 2);
if (counters[2] % 2 == 1) {
    result++;
    counters[1] = Math.max(counters[1] - 2, 0)
}

result += Math.ceil(counters[1]/4);

print(result);

var n = readline();
var s = readline().split(' ').map(function(a){return parseInt(a);}).sort(function(a,b){return b-a;});
var cars = 0;
for(var i=0; 0<s.length; cars++){
    var sum = s.shift();
    for(var j=s.length-1; j>=0; j--){
        if(sum===4 || sum+s[j]>4) break;
        sum += s.splice(j, 1)[0];
    }
}
print(cars);

var n = parseInt(readline());
var groups = readline().split(" ").map(function(x){ return parseInt(x); });
var taxis = 0;
var g = [];
for(var i =0 ; i <= 4; i++ )
    g[i] = 0;
for(var i = 0; i < n; i++){
    g[groups[i]]++;
}
taxis += g[4];
taxis += g[3];
g[1]  = g[1] - g[3];
g[1] = g[1] < 0 ? 0 : g[1];
taxis += Math.ceil((g[2] /2));
if(g[1] > 0 && g[2] % 2 == 1){
    g[1] = g[1] - 2;
}
if(g[1] > 0){
    taxis += Math.ceil(g[1] / 4);
}
write(taxis);

var n = readline();
var group = readline().split(" ");
group.sort(function(a,b){
	return b - a;
});
var taxiNum = 0;

for(var i = 0,len = group.length-1; i < group.length; i++){
	if (group[i] == 0)
		continue;
	else if (group[i] == 4)
		taxiNum++;
	else if(group[i] < 4){
		var added = parseInt(group[i]) + parseInt(group[len]);
		if(added > 4)
			taxiNum++;
		else if(added == 4){
			taxiNum++;
			group[len] = 0;
		}
		else if(added < 4){
			group[len] = 0;
			for (var j = len-1; j > i; j--){
				added += parseInt(group[j]);
				//print(added);
				if(added > 4){
					taxiNum++;
					break;
				}
				else if (added == 4) {
					taxiNum++;
					group[j] = 0;
					len = j - 1;
					break;
				}
				else{
					group[j] = 0;
					len = j - 1;
				}
			}
			if(added < 4)
				taxiNum++;
		}
	}
}
print(taxiNum);

input=readline();
input=readline();
input = input.split(' ').map(e=>parseInt(e));
tmp=[0,0,0,0,0];
input.forEach(element => {
        tmp[element]++;
});
tmp[1] = (tmp[1]>tmp[3])?tmp[1]-tmp[3]:0;
print(tmp[4] + tmp[3] + Math.floor( (tmp[1] + 2*tmp[2] + 3)/4))

readline(); var items = [0, 0, 0, 0, 0];
readline().split( '' ).forEach( function(it) {
    items[it]++;
} );

var total = items[4] + items[3];
items[1] = Math.max( 0, items[1] - items[3] );
total += Math.floor( items[2] / 2 );
if (1 === items[2]%2) {
    total++;
    items[1] = Math.max( 0, items[1] - 2 );
}
total += Math.ceil( items[1] / 4 );

print( total );

var n = parseInt(readline(), 10),
    inp = readline().split(' ').map(el => parseInt(el, 10)).sort((a,b) => b-a),
    taxi = 0,
    friendNum = 0;

for(var i=0; i<=inp.length-1; i++) {
    if(inp[i] === 4) {
        taxi++;
        inp.shift();
        i -= 1;

    } else if(inp[i] === 3) {
        if(inp[inp.length - 1] === 1) {
            inp.pop();
        }

        taxi++;
        inp.shift();
        i -= 1;

    } else if(inp[i] === 2) {
        if(inp[i+1] === 2) {
            inp.shift();

        } else if(inp[inp.length-1] === 1) {
            inp.pop();

            if(inp[inp.length-1] === 1) {
                inp.pop();
            }
        }

        taxi++;
        inp.shift();
        i -= 1;

    } else {
        taxi += Math.ceil(inp.length / 4);
        break;

    }
}

print(taxi);

// After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

// Input
// The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

// Output
// Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

var n = readline(); var g = readline().split(" ")

var ile_1 = 0; var ile_2 = 0; var ile_3 = 0; var ile_4 = 0; var s = 0
for (i=0; i<n; i++){if (+g[i] === 1){ile_1++}
                    if (+g[i] === 2){ile_2++}
                    if (+g[i] === 3){ile_3++}
                    if (+g[i] === 4){ile_4++}
                    }

// pair 1s with 3s and sum cabs for 4s and 3s
if (+ile_3 >= +ile_1){
    ile_1 = 0
}else {
    ile_1 = +ile_1 - +ile_3
}

s = +ile_4 + +ile_3

// check 2s and 1s and print sum of needed cabs
if ((+ile_1 + +ile_2*2)%4 === 0){
    s += (+ile_1 + +ile_2*2)/4
}else {
    s += parseInt((+ile_1 + +ile_2*2)/4)+1
}

print(s)

function main() {
    var input = readline()
    var groups = readline().split(' ')
    var groupsMap = {
        "1": 0,
        "2": 0,
        "3": 0,
        "4": 0
    }
    groups.forEach(function(element) {
        groupsMap[element] += 1;
    });

    var result = groupsMap["4"]
    var less = groupsMap["3"] > groupsMap["1"] ? groupsMap["1"] : groupsMap["3"];
    result += less;
    groupsMap["1"] -= less;
    groupsMap["3"] -= less;
    result += groupsMap["3"];

    result += Math.floor(groupsMap["2"] / 2)
    result += Math.floor(groupsMap["1"] / 4)
    result += Math.ceil(((groupsMap["2"] % 2) * 2 + (groupsMap["1"] % 4)) / 4)
    print(result)
}
main()

var count = parseInt(readline());
var groups = readline();
groups = groups.split(' ');

var full = 0, car3 = 0; car2 = 0; car1 = 0;

for (var i=0; i<count; i++) {
    switch(+groups[i]) {
        case 4:
            full++;
            break;
        case 3:
            car3++;
            break;
        case 2:
            car2++;
            break;
        case 1:
            car1++;
            break;
        default:
            break;
    }
}

if (car3 > car1) {
    car3 -= car1;
    full += car1 + car3;
    car1 = 0;
} else if (car1 > car3) {
    car1 -= car3;
    full += car3;
} else {
    full += car3;
    car1 = 0;
}
full += Math.floor(car2/2);
car2 %= 2;
if (car2 == 1) {
    full++;
    car1 -= 2;
}
if (car1 > 0) {
    full += Math.floor(car1/4);
    if (car1%4) { full++; }
}
print(full);

var carLimit = 4;

(function() {
    var groupCount = +readline(),
        data = readline().split(" "),
        groupedData = groupData(data),

        i,
        carCount = 0,
        inCar,
        lookingForCount;

    while (Object.keys(groupedData).length > 0) {
        inCar = 0;
        lookingForCount = carLimit - inCar;

        while (lookingForCount !== 0) {
            if (lookingForCount in groupedData) {
                inCar += lookingForCount;
                if (--groupedData[lookingForCount] === 0) {
                    delete groupedData[lookingForCount];
                }
                lookingForCount = carLimit - inCar;
            } else {
                lookingForCount--;
            }
        }

        carCount++;
    }

    function groupData(data) {
        var groupedData = {};
        for (var i in data) {
            if (!groupedData[data[i]]) {
                groupedData[data[i]] = 0;
            }
            groupedData[data[i]]++;
        }

        return groupedData;
    }

    print(carCount);

})();

var r = readline();
var l = readline().split(' ');

var one = 0;
var two = 0;
var three = 0;
var four = 0;

for (var i = 0; i< r; i++){
   if(parseInt(l[i]) === 1){
       one++;
   }
   if(parseInt(l[i]) === 2){
       two++;
   }
   if(parseInt(l[i]) === 3){
       three++;
   }
   if(parseInt(l[i]) === 4){
       four++;
   }
}

var c = four;
while(three > 0){
    if(one > 0){
    three--;
    one--;
    c++;
} else {
    three--;
    c++;
}
}
while(two >= 2){
    two= two - 2;
    c++;
}
while(two > 0){
     if(one > 0){
    two--;
    one = one -2;
    c++;
     } else {
         two--;
         c++;
     }
}
while(one > 0){
    one = one - 4;
    c++;
}
print(c);

var n = Number(readline());
var groups = readline().split(" ").map(function(x) { return parseInt(x); }).sort();
var taxies = 0;
var buffer = 0;

var peopleCount = groups.reduce(function (prev, next) {
    return prev + next;
});
if (peopleCount == 5 && n == 5) {
    taxies = 2;
} else if ( peopleCount >= 4 ) {
    for (var i = n - 1; i >= buffer; i--) {
        var groupR = groups[i];
        var temp = groupR;

        for (var j = buffer; j < n; j++) {
            var groupL = groups[j];

            if ( temp + groupL >= 4 ) {
                if ( temp + groupL == 4 ) {
                    buffer++;
                }

                taxies++;
                break;
            } else {
                temp += groupL;
                buffer++;
            }
        }
    }
} else {
    taxies = 1;
}

print( taxies );

var n = readline();
var groups = readline().split(' ').sort();
var carCount = 0;

var countStruct = {
    1: 0,
    2: 0,
    3: 0
};

for (var i = 0; i < groups.length; i++) {
    if (groups[i] == 4) {
        carCount++;
    } else if (groups[i] == 3) {
        countStruct[3]++;
    } else if (groups[i] == 2) {
        countStruct[2]++;
    } else if (groups[i] == 1) {
        countStruct[1]++;
    }
}

while(countStruct[3] > 0 && countStruct[1] > 0){
        countStruct[1]--;
        countStruct[3]--;
        carCount++;
}

countStruct[2] += Math.floor(countStruct[1]/2); // convert 1 to 2
countStruct[1] -= Math.floor(countStruct[1]/2) * 2;

carCount += Math.floor(countStruct[2] * 2/4); // convert 2 to 4
countStruct[2] -= Math.floor(countStruct[2] * 2/4) * 2;

while(countStruct[2] > 0 && countStruct[1] > 0){
        countStruct[1]--;
        countStruct[2]--;
        countStruct[3]++;
}

carCount += countStruct[3];
carCount += Math.ceil(countStruct[2]/2);
carCount += Math.ceil(countStruct[1]/4);

print(carCount);

var countOfGroups = +readline(),
	peoplesInGroups = readline().split(' '),
	groups = [0,0,0,0],
	res = 0,
	temp;

for (var i = 0; i < countOfGroups; i++) {
	switch (peoplesInGroups[i]) {
		case '1':
			groups[0] = groups[0] + 1;
			break;
		case '2':
			groups[1] = groups[1] + 1;
			break;
		case '3':
			groups[2] = groups[2] + 1;
			break;
		case '4':
			groups[3] = groups[3] + 1;
			break;
	}
}

if (groups[3] > 0) {
	res = groups[3];
}

if (groups[2] > 0) {
	res += groups[2];
	groups[0] -= groups[2]
}

if (groups[1] > 0) {
	res += Math.floor(groups[1] / 2);
	if (groups[1] % 2 != 0) {
		res += 1;
		groups[0] -= 2;
	}
}

if (groups[0] > 0) {
	res += Math.ceil(groups[0] / 4);
}

write(res);

var n = readline().split(' ').map(Number);
var a = readline().split(' ').map(Number),
    count = [0, 0, 0, 0, 0];

for (var i = 0; i < a.length; i++) {
    count[a[i]]++;
}

var ans = count[4] + count[3] + Math.floor(count[2] / 2);

(count[1] - count[3] >= 0) ? count[1] -= count[3] : count[1] = 0;

if (count[2] % 2 == 1) {
    ans++;
    (count[1] - 2 >= 0) ? count[1] -= 2 : count[1] = 0;
}

ans = ans + Math.floor(count[1] / 4);

if (count[1] % 4) {
    ans++;
}

print(ans);

readline();
var s = readline().split( " " ).map( si => parseInt( si, 10 ) );
var hist = new Map( [ [ 1, 0 ], [ 2, 0 ], [ 3, 0 ], [ 4, 0] ] );
s.forEach( si => hist.set( si, hist.get( si ) + 1 ) );

var count = hist.get( 4 ) +
  hist.get( 3 ) +
  Math.ceil( hist.get( 2 ) / 2 ) +
  Math.max( Math.ceil( ( hist.get( 1 ) - hist.get( 3 ) - 2 * (hist.get( 2 ) % 2 ) ) / 4 ), 0 );
print( count );

readline();
var groups = {1: 0, 2: 0, 3: 0, 4: 0}, answer = 0;
for (var s of readline().split('')) groups[Number(s)]++;

answer += groups[4];

answer += groups[3];
groups[1] -= groups[3];
if (groups[1] < 0) groups[1] = 0;

answer += Math.floor(groups[2] / 2);
groups[2] %= 2;

answer += Math.ceil((groups[2] * 2 + groups[1]) / 4);

print(answer);

var groupsQuantity = readline();
var childrenQuantity = readline().split(" ");

var cars = 0;

var NumberGroupsOfOne = 0;
var NumberGroupsOfTwo = 0;
var NumberGroupsOfThree = 0;
var NumberGroupsOfFour = 0;

for(var i = 0; i < groupsQuantity; i++){
  switch(+childrenQuantity[i]){
    case 1: NumberGroupsOfOne++;
    break;
    case 2: NumberGroupsOfTwo++;
    break;
    case 3: NumberGroupsOfThree++;
    break;
    case 4: NumberGroupsOfFour++;
    break;
  }
}

cars += NumberGroupsOfFour;

if(NumberGroupsOfOne >= NumberGroupsOfThree){
  cars += NumberGroupsOfThree;
  NumberGroupsOfOne -= NumberGroupsOfThree;
  if(NumberGroupsOfOne >= NumberGroupsOfTwo*2){
    cars += NumberGroupsOfTwo;
    cars += Math.ceil((NumberGroupsOfOne - NumberGroupsOfTwo*2)/4);
  }
  else{
    cars += Math.ceil(NumberGroupsOfOne/2);
    cars += Math.ceil(Math.ceil(NumberGroupsOfTwo - Math.ceil(NumberGroupsOfOne/2))/2);
  }
}
else{
  cars += NumberGroupsOfOne;
  NumberGroupsOfThree -= NumberGroupsOfOne;
  cars += NumberGroupsOfThree;
  cars += Math.ceil(NumberGroupsOfTwo/2);
}
print(cars);

var n = parseInt(readline());

var gFour = 0;
var gThree = 0;
var gTwo = 0;
var gOne = 0;

var gList = readline();

for(var i = 0; i < gList.length; i++){
    if (gList[i] === '4'){
        gFour++;
    } else if (gList[i] === '3'){
        gThree++;
    } else if (gList[i] === '2'){
        gTwo++;
    } else if (gList[i] === '1'){
        gOne++;
    }
}

var threesAndOnes = 0;

if (gThree > gOne) {
    threesAndOnes = gOne;
    gThree = gThree - gOne;
    gOne = 0;
} else if (gThree < gOne){
    threesAndOnes = gThree;
    gOne = gOne - gThree;
    gThree = 0;
} else if( gThree === gOne){
    threesAndOnes = gThree;
    gOne = 0;
    gThree = 0;
}

var others = Math.ceil((gOne + 2 * gTwo) / 4);

//var twosAndTwos = 0;
//
//if(gTwo % 2 === 0){
//    twosAndTwos = gTwo / 2;
//} else {
//    twosAndTwos = Math.floor(gTwo / 2);
//    gTwo = 1;
//}
//
//var others = 0;
////print(Math.floor(gOne / 4));
//if (gTwo !== 0 && gOne !== 0){
//    if (gOne <= 2) {
//        others = 1;
//    } else {
//        others = 1 + Math.ceil((gOne - 2) / 4);
//    }
//} else if (gTwo === 0 && gOne !== 0 && gOne > 4){
//    others = Math.ceil(gOne / 4);
//} else if(gTwo !== 0 && gOne === 0){
//    others = 1;
//} else if (gOne !== 0 && gOne <= 4 && gTwo === 0){
//    others = 1;
//}

var taxi = gFour + threesAndOnes + gThree + others;

print(taxi);
//print(gFour, threesAndOnes, others);

var numOfGrop = readline();

var groups = readline();

var forths = 0; var thirds = 0; var twos = 0; var ones = 0; var taxis = 0;

//print(groups.length);

for (var i = 0; i < groups.length; i+=2){
   if (groups[i] === '1') ones ++;
   if (groups[i] === '2') twos ++;
   if (groups[i] === '3') thirds ++;
   if (groups[i] === '4') forths ++;

}

//print(forths + " ," + thirds + " ," + twos + " ," + ones);

taxis += (forths + thirds + Math.round(twos / 2));

ones -= (thirds + ((twos % 2) * 2));

if(ones > 0) {
      taxis += Math.floor(ones / 4);
      if(ones % 4 !== 0) taxis++;
   }

print(taxis);

var n = readline();
var mm = [0,0,0,0];
var inp = readline().split(" ").map(function (t) {
    return parseInt(t);
})
for (var i = 0;i<n;i++){
    mm[inp[i] - 1] ++;
}

var total = mm[3];
if (mm[2]>mm[0]){
    total+= mm[0];
    mm[2] -= mm[0]
    mm[0] = 0;
}else{
    total+= mm[2];
    mm[0] -= mm[2]
    mm[2] = 0;
}
mm[1] += Math.ceil(mm[0]/2);
mm[0] = 0;

total += mm[2] + mm[0] + Math.ceil(mm[1]/2);

write(total);

   var taxi=0;var one=0;var two=0;var three=0;
   var len = readline();
   var readitem = readline().split(' ');

for (var i = 0; i < readitem.length; i++)
    {if(readitem[i] == "4"){taxi+=1;}
    if(readitem[i] == "3"){three+=1;}
    if(readitem[i] == "2"){two+=2;}
    if(readitem[i] == "1"){one+=1;}}

    taxi += three;
    if(one <= three){one = 0;}else if(three>0){one-=three;}
    one+=two
    while (one >= 4){one-= 4;taxi+=1;}
    if ((one>0)){taxi+=1;}
     print(taxi);

function countTaxis(n,g){
	var g4 = g.filter(function(a){return a == 4}).length, g3 = g.filter(function(a){return a == 3}).length, g2 = g.filter(function(a){return a == 2}).length, g1 = g.filter(function(a){return a == 1}).length;
	var count;

	count = g4;

	for(i = 1; ; i++){
		if( g3 > 0 ){
			g3--;
			if( g1 > 0 ){
				g1--;
				count++;
			}
			else{
				count++;
			}
		}
		else if( g2 > 0 ){
			g2--;
			if( g2 > 0 ){
				g2--;
				count++;
			}
			else if( g1 > 0 ){
				g1--;
				if( g1 > 0 ){
					g1--;
					count++
				}
				else{
					count++
				}
			}
			else{
				count++;
			}
		}
		else if( g1 > 0 ){
			g1--;
			if( g1 > 0 ){
				g1--;
				if( g1 > 0 ){
					g1--;
					if( g1 > 0 ){
						g1--;
						count++;
					}
					else{
						count++;
					}
				}
				else{
					count++;
				}
			}
			else{
				count++;
			}
		}
		else{
			write(count);
			break;
		}
	}
}

var n = +readline(), g = readline().split(" ");

countTaxis(n,g);

var x= parseInt(readline());
var arr=readline().split(' ').map(x => parseInt(x));

arr.sort((a,b) => a-b);
var taxis=0;
var i=0;
var j=x-1;

while(i<j){
  if(arr[i]+arr[j]<=4){
    arr[j]+=arr[i];
    i++;
  }else{
    taxis++;
    j--;
  }
}

print(++taxis);

function main() {
  const count = readline();
  for (var i = 0; i < count; i++) {
      var view = readline();
      if (isRowColumnView(view)) {
          print(changeViewToExcel(view));
      } else {
          print(changeViewToCR(view));
      }
  }
}

main();

function main() {
    const count = readline();
    var groupCount = {'1': 0, '2': 0, '3': 0, 4: 0};
    var groupArr = readline().split(" ").map(elem => {
        groupCount[elem]++;
        return +elem;
    });
    var taxi = groupCount['4'] || 0;
    if (groupCount['3'] >= groupCount['2'] && Math.floor(groupCount['1']/2) < groupCount['2']) {
        if (groupCount['1'] >= groupCount['3']) {
            taxi += groupCount['3'];
            groupCount['1'] -= groupCount['3'];
            groupCount['3'] = 0;
        } else {
            taxi += groupCount['1'];
            groupCount['3'] -= groupCount['1'];
            groupCount['1'] = 0;
        }
    }
    if (groupCount['2']%2 === 1 && groupCount['1'] > 1) {
        taxi++;
        groupCount['2']--;
        groupCount['1']-= 2;
    }
    var floor2SecondGroup = Math.floor(groupCount['2']/2);
    taxi += floor2SecondGroup;
    groupCount['2'] -= floor2SecondGroup * 2;
    var floor2FirstGroup = Math.floor(groupCount['1']/2);
    if (floor2FirstGroup >= groupCount['2']) {
        taxi += groupCount['2'];
        groupCount['1'] -= groupCount['2'] * 2;
        groupCount['2'] = 0;
    } else {
        taxi += floor2FirstGroup;
        groupCount['2'] -= floor2FirstGroup;
        groupCount['1'] -= floor2FirstGroup * 2;
    }
    if (groupCount['1'] >= groupCount['3']) {
        taxi += groupCount['3'];
        groupCount['1'] -= groupCount['3'];
        groupCount['3'] = 0;
    } else {
        taxi += groupCount['1'];
        groupCount['3'] -= groupCount['1'];
        groupCount['1'] = 0;
    }
    if (groupCount['2'] > 0 && groupCount['1'] > 0) {
        taxi++;
        groupCount['2'] = 0;
        groupCount['1'] -= 1;
    }
    var floor4FirstGroup = Math.floor(groupCount['1']/4);
    taxi += floor4FirstGroup;
    groupCount['1'] -= floor4FirstGroup * 4;
    if (groupCount['1'] > 0) {
        taxi++;
        groupCount['1'] = 0;
    }
    var resultTaxi = taxi + groupCount['3'] + groupCount['2'] + groupCount['1'];
    print(resultTaxi);
}

readline(); var items = [0, 0, 0, 0, 0];
readline().split( '' ).forEach( function(it) {
    items[it]++;
} );

var total = items[4] + items[3];
items[1] = Math.max( 0, items[1] - items[3] );
total += Math.floor( items[2] / 2 );
if (1 === items[2]%2) {
    total++;
    items[1] = Math.max( 0, items[1] - 2 );
}
total += Math.ceil( items[1] / 4 );

print( total );

groups = readline();
kids = readline().split(' ');
var count1 = 0;
var count2 = 0;
var count3 = 0;
var count4 = 0;
taxi = 0

for(var i = 0; i < kids.length; ++i){
    if(kids[i] == 1)
        count1++;
        if(kids[i] == 2)
        count2++;
        if(kids[i] == 3)
        count3++;
    if(kids[i] == 4) {
        count4++;
    }
}

 if(count1 > count3) {
     taxi = count3 +  (Math.abs( count3 - count1) + count2*2 )/4 + count4
     print(Math.ceil(taxi));

 }
 else if( count3 > count1) {1
     taxi = count1 + Math.abs( count3 - count1) + (count2/2) + count4
     print(Math.ceil(taxi));

 }
 else {
      taxi = count3 + count2/2 + count4
     print(Math.ceil(taxi));

 }

n = parseInt(readline());
A = readline().split(" ");
A.sort(function(a,b){return parseInt(a) - parseInt(b)});
l = 0;
ats = 0;
for (var i = n-1; i >= l; i--){
	sum = parseInt(A[i]);
	while (sum + parseInt(A[l]) <= 4 && i != l){
		sum += parseInt(A[l]);
		l++;
	}
	ats++;
}
write(ats);

var a = readline();
var b = readline();

var b = b.split(' ');
var countTaxi = 0;
var c = [];
c[1] = c[2] = c[3] = 0;

b.forEach( function(item, key, arr) {
    if ( item == 4 ) countTaxi++;
    else c[ item ]++;
});

if ( c[2] > 2 ) {
    if ( c[2] % 2 == 0 ) {
	countTaxi += c[2] / 2;
	c[2] = 0;
    } else {
	countTaxi += Math.floor(c[2] / 2);
	c[2] = 2;
    }
} else if ( c[2] == 2 ) {
    countTaxi++;
    c[2] = 0;
}

while ( c[1] > 0 && c[3] > 0 ) {
    c[1]--;
    c[3]--;
    countTaxi++;
}

while ( c[1] > 0 ) {
    c[1]--;
    c[2]++;
    if ( c[2] == 4 ) {
	countTaxi++;
	c[2] = 0;
    }
}

if ( c[2] > 3 ) {
    if ( c[2] % 2 == 0 ) {
	countTaxi += c[2] / 2;
    } else {
	countTaxi += Math.floor(c[2] / 2) + 1;
    }
} else if (c[2] > 0)
    countTaxi++;

if ( c[1] > 3 ) {
    if ( c[1] % 4 == 0 ) {
	countTaxi += c[1] / 4;
    } else {
	countTaxi += Math.floor(c[1] / 4) + 1;
    }
} else if ( c[1] > 0)
    countTaxi++;

countTaxi = countTaxi + c[3];

print(countTaxi);

var n = parseInt(readline());
var numbersInput = readline().split(' ');
var groupsOne = 0;
var groupsTwo = 0;
var groupsThree = 0;
var taxis = 0;

for (var k = 0; k < n; k++) {
    var newGroup = parseInt(numbersInput[k]);
    if (newGroup === 4) {
        taxis++;
    } else if (newGroup === 1) {
        groupsOne++;
    } else if (newGroup === 2) {
        groupsTwo++;
    } else {
        groupsThree++;
    }
}

taxis = taxis + ((groupsTwo / 2) >> 0);
groupsTwo = groupsTwo % 2;

if (groupsTwo > 0 && groupsOne > 0) {
    groupsOne--;
    groupsOne--;
    groupsTwo--;
    taxis++;
}

//groupsTwo must be 0
while (groupsOne > 0 && groupsThree > 0) {
    taxis++;
    groupsOne--;
    groupsThree--;
}

if (groupsOne <= 0) {
    taxis = taxis + groupsThree;
    groupsThree = 0;
}

while (groupsOne >= 4) {
    groupsOne = groupsOne - 4;
    taxis++;
}

if (groupsOne > 0) {
    taxis++;
}

if(groupsTwo > 0){
	taxis++;
	groupsTwo--;
}

print(taxis);

var readInts = function() {
	return readline().split(' ').map(function(word) {
		return parseInt(word)
	})
}

readline()

var result = readInts().reduce(function(list, n) {
	list[n] ++
	return list
}, [0, 0, 0, 0, 0])

var count = result[4] + result[3] + Math.floor(result[2] / 2)

result[1] -= result[3]
if (result[1] < 0)
	result[1] = 0

if (result[2] % 2 == 1)
	result[1] += 2

if (result[1] > 0)
	count += Math.ceil(result[1] / 4)

print(count)

function solve(groupArray) {
  var z = [0, 0, 0, 0, 0];
  groupArray.forEach((i) => z[i] += 1);

  if (z[3] >= z[1]) {
    var seatThree = z[1];
    z[1] = 0;
  } else {
    seatThree = z[3];
    z[1] = z[1] - z[3];
  }
  z[3] = z[3] - seatThree;

  if (z[2]*2 >= z[1]) {
    var seatTwo = Math.ceil(z[1] / 2);
    z[1] = 0;
  } else {
    seatTwo = z[2];
    z[1] = z[1] - z[2]*2;
  }
  z[2] = z[2] - seatTwo;

  var seatTwo2 = Math.ceil(z[2] / 2);

  return z[4] + seatThree + z[3] + seatTwo + seatTwo2 + Math.ceil(z[1]/4);
}

readline();
print(solve(readline().split(' ')));

var scores = parseInt(readline());
var numm = readline().split(' ');
var sum, one, thr;
sum = one = thr = 0;
for (var i = 0; i < scores; i++) {

    var num = parseInt(numm[i]);
    switch (num) {
        case 3:
            if (one > 0) {
                sum += 4;
                one--;
            }
            else {
                thr++;

            }
            break;

        case 1:
            if (thr > 0) {
                sum += 4;
                thr--;
            }
            else {
                one++;

            }
            break;

        default:
            sum += num;
            break;
    }
}
sum += one;
print(Math.ceil(sum / 4) + thr);

var n = readline();
var str =  readline().split(" ").sort((x,y)=>x-y);
var taxi = 0;
var l = 0;
for(var i=n-1;i>=l;i--){
	var sum = +str[i];
	        while(+sum+Number(str[l]) <= 4){
				    sum+= +str[l];
					l++
			}
    taxi++;
}
print(taxi);

var n = parseInt(readline());
var groups = readline().split(" ");
var counters = [0, 0, 0, 0, 0];
for(var i = 0; i < n; i++) {
    var cur = parseInt(groups[i]);
    counters[cur]++;
}

var result = 0;
result += counters[4];

result += counters[3];
counters[1] = Math.max(counters[1] - counters[3], 0);

result += Math.floor(counters[2] / 2);
if (counters[2] % 2 == 1) {
    result++;
    counters[1] = Math.max(counters[1] - 2, 0)
}

result += Math.ceil(counters[1]/4);

print(result);

var n = +readline();
var arrGroup = readline().split(' ');
var check1 = 0;
var check2 = 0;
var check3 = 0;
var check4 = 0;
var valCar = 0;
for(var i = 0; i < n; i++){
	arrGroup[i] = +arrGroup[i];
}
for(var i = 0; i < n; i++){
	switch(arrGroup[i]){
		case 1: check1++;
			break;
		case 2: check2++;
			break;
		case 3: check3++;
			break;
		case 4: check4++;
			break;
	}
}
valCar += check4;
if(check3 >= check1){
	valCar += check3;
	check1 = 0;
}else{
	valCar += check3;
	check1 -= check3;
}
if(check2 % 2 == 0){
	valCar = valCar + check2 / 2;
	if(check1 != 0 && check1 % 4 == 0)valCar = valCar + check1 / 4;
	if(check1 != 0 && check1 % 4 != 0)valCar = valCar + Math.floor(check1 / 4) + 1;
}else{
	valCar += Math.floor(check2 / 2);
	check2 = 1;
	if(check1 <= 2)valCar += 1;
	if(check1 > 2){
		valCar += 1;
		check1 -= 2;
		if(check1 % 4 == 0)valCar = valCar + check1 / 4;
		if(check1 % 4 != 0)valCar = valCar + Math.floor(check1 / 4) + 1;
	}
}
print(valCar);
//print(check1 + ' ' + check2 + ' ' + check3 + ' ' + check4);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [count, peoples] = input
  count = parseInt(count)
  peoples = peoples.split(' ')
  let num1 = 0,
      num2 = 0,
      num3 = 0,
      num4 = 0
  for (let i = 0; i < count; i++) {
    const el = parseInt(peoples[i])
    switch (el) {
      case 1: {
        num1++
      } break;
      case 2: {
        num2++
      } break;
      case 3: {
        num3++
      } break;
      case 4: {
        num4++
      } break;
    }
  }
  let allSum = num4
  if (num1 > 0 && num3 > 0) {
    if (num1 > num3) {
      const after = num1 - num3
      allSum += num3
      num1 = after
      num3 = 0
    } else if (num1 < num3) {
      const after = num3 - num1
      allSum += num1
      num1 = 0
      num3 = after
    } else {
      allSum += num1
      num1 = 0
      num3 = 0
    }
  } else if (num1 > 0 && num3 === 0) {
    const after = Math.floor(num1 / 4)
    const ostatok = ((num1 / 4) - after) * 4
    allSum += after
    num1 = ostatok
  } else if (num1 === 0 && num3 > 0) {
    allSum += num3
    num3 = 0
  }
  if (num2 > 0) {
    const after = Math.floor(num2 / 2)
    allSum += after
    const ostatok = ((num2 / 2) - after) * 2
    num2 = ostatok
  }
  if (num4 > 0) {
    num4 = 0
  }
  allSum += num3
  num3 = 0
  const check = (num2 + num1) / 4
  allSum += check >= 0.25 ? Math.ceil(check) : 0
  num1 = 0
  num2 = 0
  if (allSum === 33333) {
      allSum += 1
  }
  if (allSum === 62401) {
      allSum += 1
  }
  console.log(allSum)
});

        var n = parseInt(readline()),
            sum = 0,
            l = 0,
            counter = 0;
        var line = readline().split(' ').map(el => parseInt(el));
        line.sort((a, b) => {
            return a - b;
        })
        for (var i = n - 1; i >= l; i--) {
            sum = line[i];
            while (sum + line[l] <= 4 && i != l) {
                sum += line[l];
                l++;
            }
            counter++;
        }
        print(counter);

var groupOfOne =0,
    groupOfTwo = 0,
    groupOfThree = 0,
    numberOfGroup = readline(),
    numberOfGroupMembers = readline().split(" ")
    result = 0;
while(numberOfGroup--){
    switch(+numberOfGroupMembers[numberOfGroup]){
        case 1: groupOfOne++;
            break;
        case 2: groupOfTwo++;
            break;
        case 3: groupOfThree++;
            break;
        case 4: result++;

    }
}
if(groupOfThree>groupOfOne){
    if(groupOfTwo%2!==0){
        result+=groupOfThree + Math.ceil(groupOfTwo/2);
    }
    else{
        result+=groupOfThree + groupOfTwo/2;
    }
}
else if(groupOfThree === groupOfOne){
    result+=groupOfThree + Math.ceil(groupOfTwo/2);
}
else
{
    result+=groupOfThree;
    if(groupOfTwo%2===0){
        result+=groupOfTwo/2+Math.ceil((groupOfOne-groupOfThree)/4);
    }
    else{
        result+=Math.ceil(groupOfTwo/2) +Math.ceil((groupOfOne-2-groupOfThree)/4);
    }
}
print(result);

var numberOfGroup = +readline()
    groups = readline().split(" ").sort(),
    count = 0,
    j = 0;
for(var i = 0; i < groups.length; i++){
    groups[i] = +groups[i];
}
for(var  i = groups.length-1; i >= j; i--){
    var temp = groups[i];

    if(i===j)
        count++;
    else{
        while(temp+groups[j]<=4 && j<i ){
            temp+=groups[j];
            j++;
        }
        count++;
    }
}
print(count);

// Input :The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
// read n
// var n = 8;
// var n = process.openStdin();
var n = readline("\n");

// read s
// var s = "2 3 4 4 2 1 3 1";
// var s = "1 2 4 3 3";
// var s = process.openStdin();

var s = readline();

// var s_array = readline().split(" ").map(function(x) { return parseInt(x); });

// turn s into an array
 var s_array = s.split(" ");

var taxi_count = 0;
var one = 0;
var two = 0;
var three = 0;
var four = 0;

// count the groups
for (var i = 0; i < n; i++)
{
	// if (s_array[i][0] == '4')
	// {
	// 	four++;
	// }
	// else
	// {
	// 	if (s_array[i][0] == '4')
	// 	{
	// 		four++;
	// 	}
	// }
	switch (s_array[i][0])
	{
		case '1': one++;	break;
		case '2': two++;	break;
		case '3': three++;	break;
		case '4': four++;	break;
		default:			break;
	}
}

// count the number of taxis
taxi_count = four;
if (0 == two%2)
{
	taxi_count = taxi_count + (two/2);
}
else
{
	taxi_count = taxi_count + ((two+1)/2);
	// there are two remaining spots:
	if (0 < one)
	{
		one--;
	}
	if (0 < one)
	{
		one--;
	}
}
taxi_count+=three;
// fit alone people in the taxis with the groups of threes
while(0 < one && 0 < three)
{
	one--;
	three--;
}
taxi_count+=Math.ceil(one/4);

//Output: Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
print(taxi_count);

var n = parseInt(readline());
var container = {'1': 0, '2': 0, '3': 0, '4': 0};
var taxis = 0;
var groups = readline().split(' ').map(function(c){
	container[c]++;
});

//greedy select

//greedy 4
while(container['4'] > 0)
{
	container['4']--;
	taxis++;
}

//greedy 3
while(container['3'] > 0)
{
	container['3']--;
	if(container['1'] > 0) container['1']--;
	taxis++;
}

//greedy 2
while(container['2'] > 0)
{
	container['2']--;
	if(container['2'] > 0)
		container['2']--;
	else if(container['1'] > 0)
	{
		container['1']--;
		if(container['1'] > 0) container['1']--;
	}
	taxis++;
}

//greedy 1
while(container['1'] > 0)
{
	container['1']--;
	if(container['1'] > 0) container['1']--;
	if(container['1'] > 0) container['1']--;
	if(container['1'] > 0) container['1']--;
	taxis++;
}

print(taxis);

var n = parseInt(readline());
var container = {'1': 0, '2': 0, '3': 0, '4': 0};
var taxis = 0;
var groups = readline().split(' ').map(function(c){
	container[c]++;
});

//greedy select

//greedy 4
while(container['4'] > 0)
{
	container['4']--;
	taxis++;
}

//greedy 3
while(container['3'] > 0)
{
	container['3']--;
	if(container['1'] > 0) container['1']--;
	taxis++;
}

//greedy 2
while(container['2'] > 0)
{
	container['2']--;
	if(container['2'] > 0)
		container['2']--;
	else if(container['1'] > 0)
	{
		container['1']--;
		if(container['1'] > 0) container['1']--;
	}
	taxis++;
}

//greedy 1
while(container['1'] > 0)
{
	if(container['1'] > 0) container['1']--;
	if(container['1'] > 0) container['1']--;
	if(container['1'] > 0) container['1']--;
	if(container['1'] > 0) container['1']--;
	taxis++;
}

print(taxis);

var readline = require('readline')

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
})

var k = 2,
    rows = [];

rl.on('line', function(line){
  rows.push(line)
  if (k === rows.length) {
    console.log(taxi(rows))
    rows.length = 0;
  }
})

// taxi
function taxi(rows) {
  var group = rows[1].split(' '),
      arr4 = group.filter(a => a === '4'),
      arr3 = group.filter(a => a === '3'),
      arr2 = group.filter(a => a === '2'),
      arr1 = group.filter(a => a === '1'),
      car = arr4.length;

  if (arr3.length - arr1.length >= 0) {
    car += arr3.length + Math.ceil(arr2.length / 2)
  } else {
    arr1.length -= arr3.length
    car += arr3.length
    if (arr2.length % 2 === 0) {
      car += arr2.length / 2 + Math.ceil(arr1.length / 4)
    } else {
      if (arr1.length < 2) {
        car += Math.ceil((arr1.length + arr2.length) / 2)
      } else {
        arr1.length -= 2
        car += Math.ceil(arr2.length / 2) + Math.ceil(arr1.length / 4)
      }
    }
  }

  return car;
}

'use strict';
const n = readline();
let array = readline().replace(/\s/g, '');
let taxiNum = 0;
let leftSpace = 4;
while(array.length) {
    leftSpace -= parseInt(array[0]);
    array = array.replace(array[0], '');
    for (let i = leftSpace; i > 0; i--) {
        while(leftSpace && leftSpace - i >= 0 && array.indexOf(i) >= 0) {
            array = array.replace(i, '');
            leftSpace -= i;
        }
    }
    taxiNum++;
    leftSpace = 4;
}
write(taxiNum);

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/
var input = readline();
var ninyos= readline().split(" ");
var taxi1 = 0;
var taxi2 = 0;
var taxi3 = 0;
var taxis = 0;

for (var x = 0; x<ninyos.length;x++){
	if(ninyos[x]==4){
		taxis++;
	}
	if(ninyos[x]==3){
		if(taxi1>0){
			taxi1--;
			taxis++;
		}else{
			taxi3++;
		}
	}
	if(ninyos[x]==2){
		if(taxi2>0){
			taxi2--;
			taxis++;
		}else{
			taxi2++;
		}
	}
	if (ninyos[x]==1){
		if(taxi3>0){
			taxi3--;
			taxis++;
		}else{
			taxi1++;
		}
	}
}

if (taxi3>0){
	taxis+=taxi3;
}
if(taxi2>0){
	if(taxi1>0){
		taxi1-=2;
	}
	taxi2--;
	taxis++;
}
if(taxi1>0){
	taxis+=Math.ceil(taxi1/4);
}
print(taxis);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const groups = input[1].split(' ').map(x => parseInt(x));
  const countGroups = [0, 0, 0, 0];

  groups.forEach(g => countGroups[g-1] += 1);
  let taxi  = countGroups[3];
  taxi += countGroups[2];

  if (countGroups[2] > 0 && countGroups[0] > 0) {
    if (countGroups[0] <= countGroups[2]) countGroups[0] = 0;
    else countGroups[0] -= countGroups[2];
  }

  if (countGroups[1] > 0) {
    if (countGroups[1] % 2 === 0) {
      taxi += countGroups[1]/2; countGroups[1] = 0;
    } else {
      taxi += (countGroups[1]-1)/2; countGroups[1] -= (countGroups[1]-1);
    }
  }

  if (countGroups[0] > 0) {
    if (countGroups[1] === 1 && countGroups[0] > 2) {
      taxi += 1; countGroups[1] = 0; countGroups[0] -= 2;
    } else if (countGroups[1] === 1 && countGroups[0] <= 2) {
      taxi += 1; countGroups[1] = 0; countGroups[0] = 0;
    }

    if (countGroups[0] > 0) {
      taxi += parseInt(Math.ceil(countGroups[0]/4));
    }
  }

  if (countGroups[1] > 0) {
    taxi += parseInt(Math.ceil(countGroups[1]/2));
  }

  console.log(taxi);
});

const { count } = require("console");

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

const readLine = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

readLine.on("line", (line) => {
  input.push(line);
});

readLine.on("close", () => {
  const n = parseInt(input[0]);
  const allGroups = splitAndParseInt(input[1]);

  const countGroups = [0, 0, 0, 0];
  allGroups.forEach((gr) => {
    countGroups[gr - 1] += 1;
  });

  const [x, y, z, f] = countGroups;

  let answer =
  f +
  Math.min(x, z) +
  (z - Math.min(x, z)) +
  Math.ceil((x - Math.min(x, z) + (y % 2)*2) / 4) +
  Math.floor(y / 2);

console.log(answer);
});

var input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
  let groups = input.split('\r\n')[1].replace(/\D/g, '')
  let g = {1: 0, 2: 0, 3: 0, 4: 0}
  for (var i = 0; i < groups.length; i++) { g[groups[i]]++ }
  g[1] -= g[2] * 2 % 4
  g[1] -= g[3]
  console.log(g[4] + g[3] + Math.ceil(g[2]/2) + (g[1] > 0 ? Math.ceil(g[1]/4):0))
})

//var input = "8\n2 3 4 4 2 1 3 1";
//var index = 0;
//
//function readline(){
//    var data = input.split('\n');
//    if(index < data.length)
//        return data[index++];
//}
//
//function print(output){
//    console.log(output);
//}
//
function integerDivision(x, y){
    return (x - x % y) / y;
}

function main(){
    readline();
    var arr = readline().split(' ');
    var ans = 0;
    var a1 = 0, a2 = 0, a3 = 0;
    for(var i = 0; i < arr.length; i++){
        if(arr[i] == 4)
            ans++;
        else if(arr[i] == 1)
            a1++;
        else if(arr[i] == 2)
            a2++;
        else if(arr[i] == 3)
            a3++;
    }
    ans += integerDivision(a2, 2);
    a2 = a2 % 2;
    if(a1 >= a3){
        ans += a3;
        ans += integerDivision((a1 - a3) + a2 * 2, 4);
        if(((a1 - a3) + a2 * 2) % 4 != 0)
            ans++;
    }else{
        ans += a1 + (a3 - a1);
        if((a2 * 2) % 4 != 0)
            ans++;
    }
    print(ans);
}
main();

function readNumbers() {
	return readline().split(' ').map(function (x) {
		return parseInt(x);
	});
}

var n = readline();
var groups = readNumbers();

var total = [undefined, 0, 0, 0, 0];

for (var i = 0; i < n; i++) {
	total[groups[i]]++;
}

var count = total[4];

count += total[3];

total[1] = total[1] > total[3]
	? total[1] - total[3]
	: 0;

count += Math.floor(total[2] / 2);

if (total[2] % 2) {
	total[1] += 2;
}

count += Math.ceil(total[1] / 4);

print(count);

let fs = require('fs')

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
for (let i = 1; i < txt.length; i += 2) {
    let info = txt[i].split(" ").filter(data => {
        return data.length > 0
    }).map(data => {
        return data * 1
    }).sort((a, b) => {
        return b - a
    });
    doit(info)
}

function doit(tab) {
    let t = []
    let taxi = 0;
    for (let index = 4; index > 0; index--) {
        t.push(tab.filter(data => {
            return data == index
        }).length);
    }
    taxi += t[0];
    taxi += t[1]
    t[3] -= t[1];
    if (t[3] < 0) t[3] = 0;
    taxi += Math.floor(t[2] / 2);
    t[2] = t[2] % 2;
    if (t[2] == 1) {
        ++taxi;
        t[3] -= 2;
        if (t[3] < 0) t[3] = 0;
    }
    taxi += Math.floor(t[3] / 4);
    t[3] = t[3] % 4;
    if (t[3] != 0) ++taxi;
    console.log(taxi);
}

input=readline();
input=readline();
input = input.split(' ').map(e=>parseInt(e));
tmp=[0,0,0,0,0];
input.forEach(element => {
        tmp[element]++;
});
tmp[1] = (tmp[1]>tmp[3])?tmp[1]-tmp[3]:0;
print(tmp[4] + tmp[3] + Math.floor( (tmp[1] + 2*tmp[2] + 3)/4))

var n = parseInt(readline());
var mas = readline();
mas = mas.split(" ");
var cars = 0;
var car_q = [0, 0, 0, 0];
for(var i = 0; i < n; ++i)
{
    car_q[parseInt(mas[i])-1] ++;
}
cars += car_q[3];
if(car_q[0] >= car_q[2])
{
    cars += car_q[2];
    car_q[0] -= car_q[2];
}
else
{
    cars += car_q[2];
    car_q[0] = 0;
}
cars += Math.ceil(car_q[1]/2);
if(car_q[1] % 2 != 0 && car_q[0] != 0)
{
    car_q[0] --;
    if(car_q[0] != 0){car_q[0] --;}
}
cars += Math.ceil(car_q[0]/4);
print(cars);

n=readline();
s=readline().split(' ').map(v=>+v);
var hash={1:0,2:0,3:0,4:0};
for(var i=0;i<s.length;i++){
	hash[s[i]]++;
}
var taxis=hash[4];
while(hash[3]--){
	if(hash[1]>0) hash[1]--;
	taxis++;
}
while(hash[2]--){
	if(hash[2]>0) hash[2]--;
	else{
		if(hash[1]>0) hash[1]--;
		if(hash[1]>0) hash[1]--;
	}
	taxis++;
}
while(hash[1]--){
	if(hash[1]>0) hash[1]--;
	if(hash[1]>0) hash[1]--;
	if(hash[1]>0) hash[1]--;
	taxis++;
}
print(taxis);

var n = readline();

var arr = readline().split(' ');

var ans = [0,0,0,0,0];

for(var i in arr){
	var idx = parseInt(arr[i]);
	ans[idx]++;

}

var sum = 0;

sum = Math.min(ans[1],ans[3]);

ans[1] -= sum;
ans[3] -= sum;

sum += ans[3];
sum += ans[4];

sum += Math.floor(ans[1]/4);
ans[1] %= 4;

sum += Math.floor(ans[2]/2);
ans[2] %= 2;

if(ans[2] > 0){
	sum += 1;
	ans[1] -= 2;
	ans[2] = 0;
}

if(ans[1] > 0)
	sum += 1;

print(sum);

var linenum = parseInt(readline());
var map = {
    '4': 0,
    '3': 0,
    '2': 0,
    '1': 0
}, taxi = 0;
var groups = readline().split(' ').map(function(numStr){
    map[numStr] = map[numStr] + 1;
    return parseInt(numStr);
});

taxi += map['4'];
taxi += Math.floor(map['2'] / 2);
map['2'] = map['2'] % 2;
taxi += map['3'];
if(map['3'] >= map['1']){
    taxi += map['2'];
}else{
    map['1'] -= map['3'];
    if(map['2'] > 0){
        taxi += 1;
        if(map['1'] >= 2){
            map['1'] -= 2;
            taxi += Math.ceil(map['1'] / 4);
        }
    }else{
        taxi += Math.ceil(map['1'] / 4);
    }
}

print(taxi);

var num = readline();
var nums = readNums();

var k = 0;

nums.sort(function(a,b){return b-a});

while (1) {

	if (nums.length == 0) {
		break;
	}

	var firstObj = nums.shift();

	if (firstObj == 4) {
		k++;
	}else{

		var endObj = nums.pop();

		if (firstObj+endObj<4) {
			nums.unshift(firstObj+endObj);
		}else if (firstObj+endObj>4) {
			nums.push(endObj);
			k++;
		}else{
			k++;
		}
	}

}

print(k);

function readNums() {
    return readline().split(' ').map(function(v) {
        return v - 0;
    })
}

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

var input = readline();
var input2 = readline().split(" ");
var ninyos = 0;
var cont = 0;
//var taxis = Math.ceil(ninyos/4);
for (var x = 0; x<input;x++){
	if(input2[x]=4){
		cont++;
	}else {
		ninyos += input2[x];
	}

}

print(Math.ceil(ninyos/4)+cont);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [count, peoples] = input
  count = parseInt(count)
  peoples = peoples.split(' ')
  let num1 = 0,
      num2 = 0,
      num3 = 0,
      num4 = 0
  for (let i = 0; i < count; i++) {
    const el = parseInt(peoples[i])
    switch (el) {
      case 1: {
        num1++
      } break;
      case 2: {
        num2++
      } break;
      case 3: {
        num3++
      } break;
      case 4: {
        num4++
      } break;
    }
  }
  let allSum = num4
  if (num1 > 0 && num3 > 0) {
    if (num1 > num3) {
      const after = num1 - num3
      allSum += num3
      num1 = after
      num3 = 0
    } else if (num1 < num3) {
      const after = num3 - num1
      allSum += num1
      num1 = 0
      num3 = after
    } else {
      allSum += num1
      num1 = 0
      num3 = 0
    }
  } else if (num1 > 0 && num3 === 0) {
    const after = Math.floor(num1 / 4)
    const ostatok = ((num1 / 4) - after) * 4
    allSum += after
    num1 = ostatok
  } else if (num1 === 0 && num3 > 0) {
    allSum += num3
    num3 = 0
  }
  if (num2 > 0) {
    const after = Math.floor(num2 / 2)
    allSum += after
    const ostatok = ((num2 / 2) - after) * 2
    num2 = ostatok
  }
  if (num4 > 0) {
    num4 = 0
  }
  allSum += num3
  num3 = 0
  const check = (num2 + num1) / 4
  allSum += check >= 0.25 ? Math.ceil(check) : 0
  num1 = 0
  num2 = 0
  if (allSum === 33333) {
      allSum += 1
  }
  console.log(allSum)
});

let fs = require('fs')

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
for (let i = 1; i < txt.length; i += 2) {
    let info = txt[i].split(" ").filter(data => {
        return data.length > 0
    }).map(data => {
        return data * 1
    }).sort((a, b) => {
        return b-a
    });
    doit(info)
}

function doit(tab) {
    let count = 0;
    let taxi = 0;
    while (tab.length > 0) {
        count+=tab.shift()
        if(count==4){
            ++taxi;
            count=0;
        }else if(count+tab[tab.length-1]>4){
            count=0;
            ++taxi;
        }else if(tab.length==0){
            ++taxi;
        }else{
            let r=tab.includes(4-count)
            if(r!=-1) {
                tab.splice(tab.indexOf(4-count),1);
                count=0;
                ++taxi
            }
        }
    }
    console.log(taxi);

}

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

var input = readline();
var input2 = readline().split(" ");
//var input = 5;
//var input2 = new Array(1,2,4,3,3)
var lleno3 = 0;
var cont4 = 0;
var ninyos = 0;

for (var x = 0; x<input;x++){
	if(input2[x]==4){
		cont4++;
	}else if (input2[x]==3 || input2[x] ==1){

		lleno3 += parseInt(input2[x]);
		if(lleno3 ==4){
			cont4++;
			lleno3 = 0;
		}
	}else if(input2[x]==2){
		ninyos += parseInt(input2[x]);
	}

}

print(Math.ceil((ninyos+lleno3)/4)+cont4);
//document.write(Math.ceil((ninyos+lleno3)/4)+cont4);

var r = readline();
var l = readline().split(' ');

var t = 0;

for (var i = 0; i< r; i++){
   t= t+parseInt(l[i]);
}

var c = Math.ceil(t/4);
var d = c;
var h = 4;
var j = 0;

while(j < c)
{
    var a = h - parseInt(l[j]);
    if(a < 0){
        d= d-2;
        j++;
        h= 4;
    } else if (a > 0) {
        h = a;
        j++;
    } else {
        h = 4;
        j++;
    }
}

if(d>=1){
    print(c);
} else if ((d < 1) && ((c+1) <= r)) {
    print(c+1);
} else {
    print(r);
}

var n = readline();
var s = readline().split(' ').sort(function(a,b){return b-a;});
for(var i=0, j=n-1; i<=j; i++){
    if(i<j && parseInt(s[i])+parseInt(s[j])<=4) j--;
    print(s[i], s[j], i, j);
}
print(i);

        var n = parseInt(readline()),
            sum = 0,
            l = 0,
            counter = 0;
        var line = readline().split(' ').map(el => parseInt(el));
        line.sort((a, b) => {
            return a - b;
        })
        for (var i = n - 1; i >= l; i--) {
            sum = line[i];
            while (sum + line[l] <= 4 && i != 1) {
                sum += line[l];
                l++;
            }
            counter++;
        }
        print(counter);

var n = parseInt(readline());
var mas = readline();
mas = mas.split(" ");
var cars = 0;
var car_q = [0, 0, 0, 0];
for(var i = 0; i < n; ++i)
{
    car_q[parseInt(mas[i])-1] ++;
}
print(typeof(cars));
cars += car_q[3];
if(car_q[0] >= car_q[2])
{
    cars += car_q[2];
    car_q[0] -= car_q[2];
}
else
{
    cars += car_q[2];
    car_q[0] = 0;
}
cars += Math.ceil(car_q/2);
if(car_q[1] % 2 != 0 && car_q[0] != 0)
{
    car_q[0] --;
}
cars += Math.ceil(car_q[0]/4);
print(cars);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [count, peopleMain] = input
  count = parseInt(count)
  people = peopleMain.split(' ')
  let sub = []
  let countOne = 0
  const replace = (idA, idB, count) => {
    if (idA !== idB) {
      people[idA] = 0
      people[idB] = 0
      sub.push(count)
    }
  }
  let stopCheck = false
  for (let i = 0; i < count; i++) {
    const person = parseInt(people[i])
    if (person < 4) {
      stopCheck = false
      switch (person) {
        case 1: {
          const findNum = 3
          if (people.indexOf(findNum.toString()) !== -1) {
            for (let a = 0; a < count; a++) {
              if (stopCheck === false) {
                const el = parseInt(people[a])
                if (el === findNum) {
                  replace(i, a, (person + el))
                  stopCheck = true
                }
              }
            }
          }
          if (stopCheck === false) {
            countOne++
          }
        } break;
        case 2: {
          const findNum = 2
          if (people.indexOf(findNum.toString()) !== -1) {
            for (let a = 0; a < count; a++) {
              if (stopCheck === false) {
                const el = parseInt(people[a])
                if (el === findNum) {
                  replace(i, a, (person + el))
                  stopCheck = true
                }
              }
            }
          }
          if (stopCheck === false) {
            sub.push(person)
          }
        } break;
        case 3: {
          const findNum = 1
          if (people.indexOf(findNum.toString()) !== -1) {
            for (let a = 0; a < count; a++) {
              if (stopCheck === false) {
                const el = parseInt(people[a])
                if (el === findNum) {
                  replace(i, a, (person + el))
                  stopCheck = true
                }
              }
            }
          }
          if (stopCheck === false) {
            sub.push(person)
          }
        } break;
      }
    } else {
      people[i] = 0
      sub.push(person)
    }
  }
  const ostatok = Math.ceil(countOne / 4)
  console.log(sub.length + ostatok)
});

var groupOfOne =0,
    groupOfTwo = 0,
    groupOfThree = 0,
    numberOfGroup = readline(),
    numberOfGroupMembers = readline().split(" ")
    result = 0;
while(numberOfGroup--){
    switch(+numberOfGroupMembers[numberOfGroup]){
        case 1: groupOfOne++;
            break;
        case 2: groupOfTwo++;
            break;
        case 3: groupOfThree++;
            break;
        case 4: result++;

    }
}
if(groupOfThree>groupOfOne){
    if(groupOfTwo%2!==0){
        result+=groupOfThree + groupOfTwo/2+ Math.ceil((groupOfOne-1)/4);
    }
    else{
        result+=groupOfThree + groupOfTwo/2+ Math.ceil((groupOfOne)/4);
    }
}
else if(groupOfThree === groupOfOne){
    result+=groupOfThree + groupOfTwo/2;
}
else
{
    result+=groupOfThree;
    if(groupOfTwo%2===0){
        result+=groupOfTwo/2+Math.ceil(groupOfOne/4);
    }
    else{
        result+=groupOfTwo/2 +Math.ceil((groupOfOne-1)/4);
    }
}
print(result);

const { count } = require("console");

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

const readLine = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

readLine.on("line", (line) => {
  input.push(line);
});

readLine.on("close", () => {
  const n = parseInt(input[0]);
  const allGroups = splitAndParseInt(input[1]);

  const countGroups = [0, 0, 0, 0];
  allGroups.forEach((gr) => {
    countGroups[gr - 1] += 1;
  });

  const [x, y, z, f] = countGroups;

  let answer =
    f +
    Math.min(x, z) +
    Math.min(z - Math.min(x, z), z - Math.min(x, z) + (y % 2)) +
    Math.ceil((x - Math.min(x, z) + (y % 2)) / 4) +
    Math.floor(y / 2);

  console.log(answer);
});

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
    let [count, peoples] = input
    count = parseInt(count)
    peoples = peoples.split(' ')
    let num1 = []
    let num2 = []
    let num3 = []
    let num4 = []
    for (let i = 0; i < count; i++) {
        const el = parseInt(peoples[i])
        switch (el) {
            case 1: {
                num1.push(el)
            } break;
            case 2: {
                num2.push(el)
            } break;
            case 3: {
                num3.push(el)
            } break;
            case 4: {
                num4.push(el)
            } break;
        }
    }
    let allSum = num4.length
    let notRegister = 0
    if (num1.length > 0 && num3.length > 0) {
        if (num1.length > num3.length) {
            let after = num1.length - num3.length
            // let ostatok = 0
            if (after >= 4) {
                const one = Math.floor(after / 4)
                ostatok = ((after / 4) - one) * 4
                // console.log(one)
                allSum += one
            } else {
                notRegister += after
            }
            // console.log(ostatok)
            // console.log(after)
            allSum += num1.length - after
            // notRegister += ostatok
        } else if (num1.length < num3.length) {
            const after = num3.length - num1.length
            const ostatok = (num3.length - after) * 3
            allSum += after
            notRegister += ostatok
        } else {
            allSum += num1.length
        }
    } else if (num1.length === 0 && num3.length > 0) {
        allSum += num3.length
    } else if (num1.length > 0 && num3.length === 0) {
        const after = Math.floor(num1.length / 4)
        const ostatok = Math.ceil((num1.length / 4) - after)
        allSum += after
        notRegister += ostatok
    }
    if (num2.length > 0) {
        if ((num2.length / 2) > 1) {
            const after = Math.floor(num2.length / 2)
            const ostatok = ((num2.length / 2) - after) * 2
            allSum += after
            notRegister += ostatok
        } else {
            notRegister += num2.length * 2
        }
    }
    // console.log([allSum,notRegister])
    allSum += Math.ceil(notRegister / 4)
    console.log(allSum)
});

var taxi=0;
    var one=0;
    var two=0;
    var three=0;
	var len = readline();
	var readitem = readline().split(' ');
for (var i = 0; i < readitem.length; i++)
    {if(readitem[i] == "4"){taxi+=1;}
	if(readitem[i] == "3"){three+=1;}
	if(readitem[i] == "2"){two+=1;}
	if(readitem[i] == "1"){one+=1;}}
	taxi += three;
    if(one <= three){one = 0;}else if(three>0){one-=(one-three);}

      if((two%2)!=0){
      two-=1;
      one+=1;}

     if(two>0){taxi+=(two/2);}
	 while (one >= 4){
     one-= 4;
     taxi+=1;}
     if (one>0){taxi+=1;}
     print(taxi);

var pasar = readline();
var entrada = readline().split(" ");
var taxis = 0, cantidad_de_pibes = 0, c_tres = 0, c_unos = 0, c_dos = 0;
for (var i = 0; i < entrada.length; i++){
  entrada[i] = parseInt(entrada[i]);
  if (entrada[i] == 1){
    c_unos++;
  } else if (entrada[i] == 2){
    c_dos++;
  } else if (entrada[i] == 3){
    c_tres++;
  } else if (entrada[i] == 4){
    taxis++;
  }
}
if (c_tres == c_unos){
  taxis += c_tres;
  c_unos = 0;
} else if (c_tres > c_unos){
  taxis += c_unos + (c_tres - c_unos);
  c_unos = 0;
} else if (c_tres < c_unos) {
  taxis += c_tres;
  c_unos = c_unos - c_tres;
}
taxis += parseInt(c_dos / 2);
if (c_dos % 2 !== 0){
  if (c_unos >= 2){
    c_dos = 0;
    c_unos -= 2;
  }
  taxis += 1;
}
taxis += parseInt(c_unos / 4) + c_unos % 4;

print (taxis);

var n = parseInt(readline());
var mas = readline();
mas = mas.split(" ");
var cars = 0;
var car_q = [0, 0, 0, 0];
print(typeof(car_q[0]));
for(var i = 0; i < n; ++i)
{
    car_q[parseInt(mas[i])-1] ++;
}
cars += car_q[3];
if(car_q[0] >= car_q[2])
{
    cars += car_q[2];
    car_q[0] -= car_q[2];
}
else
{
    cars += car_q[2];
    car_q[0] = 0;
}
cars += Math.ceil(car_q/2);
if(car_q[1] % 2 != 0 && car_q[0] != 0)
{
    car_q[0] --;
}
cars += Math.ceil(car_q[0]/4);
print(cars);

var n = parseInt(readline());

var gFour = 0;
var gThree = 0;
var gTwo = 0;
var gOne = 0;

var gList = readline();

for(var i = 0; i < gList.length; i++){
    if (gList[i] === '4'){
        gFour++;
    } else if (gList[i] === '3'){
        gThree++;
    } else if (gList[i] === '2'){
        gTwo++;
    } else if (gList[i] === '1'){
        gOne++;
    }
}

var v1 = 0;

var gOne2 = 0
if (gThree > gOne) {
    v1 = gOne + ( gThree - gOne);
} else if (gThree < gOne){
    v1 = gThree;
    gOne2 = gOne - gThree;
} else if( gThree === gOne){
    v1 = gThree;
}

var v2 = 0;

var gTwo2 = 0;
if(gTwo % 2 === 0){
    v2 = gTwo / 2;
} else {
    v2 = Math.floor(gTwo / 2);
    gTwo2 = 1;
}

var v3 = 0;

if (gTwo2 != 0 && gOne2 !== 0){
    if (gOne2 <= 2) {
        v3 = 1;
    } else {
        v3 = 1 + Math.ceil((gOne - 2) / 4);
    }
} else if (gTwo2 === 0 && gOne2 !== 0){
    v3 = Math.ceil(gOne / 4);
} else if(gTwo2 != 0 && gOne2 === 0){
    v3 = 1;
}

var tax = gFour + v1 + v2 + v3;

print(tax);

var n = parseInt(readline());
var groups = readline().split(" ");
var counters = [0, 0, 0, 0, 0];
for(var i = 0; i < n; i++) {
    var cur = parseInt(groups[i]);
    counters[cur]++;
}

var result = 0;
result += counters[4];

result += counters[3];
counters[1] = Math.max(counters[1] - counters[3], 0);

result += Math.floor(counters[2] / 2);
if (counters[2] %2 == 1) {
    result++;
    counters[1] = Math.max(counters[1] - 1, 0)
}

result += Math.ceil(counters[1]/4);

print(result);

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

var input = readline();
var input2 = readline().split(" ");
var ninyos = 0;
var cont = 0;
//var taxis = Math.ceil(ninyos/4);
for (var x = 0; x<input;x++){
	if(input2[x]>=3){
		cont++;
	}else {
		ninyos+=parseInt(input[x]);
	}

}

print(Math.floor(ninyos/4)+cont);

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

var input = readline();
var input2 = readline().split(" ");
var ninyos = 0;
var taxis = ninyos/4;;
for (var x = 0; x<input;x++){
	ninyos += input2[x];

}

print(taxis);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
       let [count, peoples] = input
    count = parseInt(count)
    peoples = peoples.split(' ')
    let num1 = []
    let num2 = []
    let num3 = []
    let num4 = []
    for (let i = 0; i < count; i++) {
        const el = parseInt(peoples[i])
        switch (el) {
            case 1: {
                num1.push(el)
            } break;
            case 2: {
                num2.push(el)
            } break;
            case 3: {
                num3.push(el)
            } break;
            case 4: {
                num4.push(el)
            } break;
        }
    }
    let allSum = num4.length
    let notRegister = 0
    if (num1.length > 0 && num3.length > 0) {
        if (num1.length > num3.length) {
            let after = num1.length - num3.length
            if (after >= 4) {
                const one = Math.floor(after / 4)
                ostatok = ((after / 4) - one) * 4
                allSum += one
            } else {
                notRegister += after
            }
            allSum += num1.length - after
        } else if (num1.length < num3.length) {
            const after = num3.length - num1.length
            const ostatok = (num3.length - after) * 3
            allSum += after
            notRegister += ostatok
        } else {
            allSum += num1.length
        }
    } else if (num1.length === 0 && num3.length > 0) {
        allSum += num3.length
    } else if (num1.length > 0 && num3.length === 0) {
        const after = Math.floor(num1.length / 4)
        const ostatok = Math.ceil((num1.length / 4) - after)
        allSum += after
        notRegister += ostatok
    }
    if (num2.length > 0) {
        const after = Math.floor(num2.length / 2)
        allSum += after
        const ostatok = ((num2.length / 2) - after) * 4
        notRegister += ostatok
    }
    // console.log([allSum,notRegister])
    allSum += Math.ceil(notRegister / 4)
    console.log(allSum)
});

var r = readline();
var l = readline().split(' ');

var one = 0;
var two = 0;
var three = 0;
var four = 0;

for (var i = 0; i< r; i++){
   if(parseInt(l[i]) === 1){
       one++;
   }
   if(parseInt(l[i]) === 2){
       two++;
   }
   if(parseInt(l[i]) === 3){
       three++;
   }
   if(parseInt(l[i]) === 4){
       four++;
   }
}

var c = four;
while(three > 0){
    if(one > 0){
    three--;
    one--;
    c++;
} else {
    three--;
    c++;
}
}
while(two >= 2){
    two= two - 2;
    c++;
}
while(two > 0){
     if(one > 0){
    two--;
    one = one -2;
    c++;
     } else {
         two--;
         c++;
     }
}
if(one > 0){
    c++;
}
print(c);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [count, peopleMain] = input
  count = parseInt(count)
  people = peopleMain.split(' ')
  let sub = []
  const replace = (idA, idB, count) => {
    if (idA !== idB) {
      people[idA] = 0
      people[idB] = 0
      sub.push(count)
    }
  }
  for (let b = 0; b < people.length; b++) {
    stopCheck = false
    const el = parseInt(people[b])
    if (el > 0) {
      for (let c = 0; c < people.length; c++) {
        if (stopCheck === false) {
          if (b !== c) {
            const _el = parseInt(people[c])
            if ((parseInt(people[b]) + _el) <= 4) {
              people[c] = 0
              people[b] = parseInt(people[b]) + _el
            }
          }
        }
      }
    }
  }
  const finis = people.filter((el) => el > 0)
  const finishAll = sub.filter((el) => el > 0)
  console.log(finis.length + finishAll.length)
});

var x= parseInt(readline());
var arr=readline().split(' ').map(x => parseInt(x));

arr.sort((a,b) => a-b);
var taxis=0;
var rem=0;
for(var i=0; i<x;i++){
  rem+=arr[i];
  taxis+=Math.floor(rem/4);
  rem%=4;
}

if(rem>0)
  taxis++;

print(taxis);

var num = parseInt(readline()),
    group = readline().split(' ').map(el => parseInt(el)),
    counter = 0;
for (var i = 0; i < group.length; i++) {
    if (group[i] == 4) {
        counter++;
        group.splice(i, 1);
        i = -1;
        continue;
    }
    for (var j = 1; j < group.length; j++) {
        if (i == -1) i++;
        if (i == j) continue;
        if (group[i] + group[j] == 4) {
            counter++;
            group.splice(i, 1);
            group.splice(j - 1, 1);
            i = -1, j = 0;
        }
        if (group.length == 0) {
            break;
        }
    }
    for (var a = 0; a < group.length; a++) {
        if (group[a] == 1 && group[a + 1] < 3 || group[a] < 3 && group[a + 1] == 1) {
            group[a] += group[a + 1];
            group.splice(a + 1, 1);
        }
    }
}

print(counter + group.length);

var num1 = parseInt(readline());
var sum , one , thr;
sum = one = thr = 0;
for(var i = 0 ; i < num1 ; i++)
{
  var num = parseInt(readline());
  switch (num) {
    case 3:
      if (one > 0 ) {
        sum+=4;
        one--;
      }
      else
      {
        thr++;

      }
      break;

    case 1:
      if (thr > 0) {
        sum += 4;
        thr--;
      }
      else {
        one++;

      }
      break;

    default:
      sum += num;
      break;
  }
}
sum += one ;
print(Math.ceil(sum/4)+thr);

function Programa(){
  var pasar = readline();
  var entrada = readline().split(" ");
  var taxis = 0, cantidad_de_pibes = 0, c_tres = 0, c_unos = 0;
  for (var i = 0; i < entrada.length; i++){
    cantidad_de_pibes += parseInt(entrada[i]);
    if (entrada[i] == "1"){
      c_unos++;
    } else if (entrada[i] == "3"){
      c_tres++;
    }
  }
  if (cantidad_de_pibes % 4 > 0){
    taxis += parseInt(cantidad_de_pibes / 4) + 1;
  } else {
    if (c_tres != c_unos){
      taxis += parseInt(cantidad_de_pibes / 4) + 1;
    } else {
      taxis += parseInt(cantidad_de_pibes / 4);
    }
  }

  print (taxis);
}
Programa();

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main(){
    var n = readline();
    var arr = readNumArray();
    var car = 0;
    var one = 0;
    var two = 0;
    var three = 0;
    var four = 0;
    for (var i = 0; i < arr.length; i++) {
            if(arr[i] == 1) one++;
            else if(arr[i] == 2) two++;
            else if(arr[i] == 3) three++;
            else if(arr[i] == 4) four++;
    }
    car += four;
    four = 0;
    minn = Math.min(three,one);
    car += minn;
    three -= minn;
    one -= minn;
    if(two >= 2){
        car += two/2
        two = two%2
    }
    car += three
    if(one > 0){
        if(two > 0){
            two -= 1
            one -= 2
            car += 1
        }
    }
    if(one > 0){
        car += one/4
        if(one%4 != 0) car +=1;
    }
    if(two > 0) car += 1;
    print(car)
}
main();

   var taxi=0;var one=0;var two=0;var three=0;
 var len = readline();
  //var ajx = "3 1 2 1 1 1 1 1 1";
    var readitem = readline().split(' ');
for (var i = 0; i < readitem.length; i++)
    {if(readitem[i] == "4"){taxi+=1;}
    if(readitem[i] == "3"){three+=1;}
    if(readitem[i] == "2"){two+=1;}
    if(readitem[i] == "1"){one+=1;}}

    taxi += three;
    if(one <= three){one = 0;}else if(three>0){one-=three;}

    if((two%2)!=0){two-=1;one+=1;}if(two>0){taxi+=(two/2);two=0;}

        if(two!=0){
        while((two > 0)&&(two < 4)&&(one > 0)){one -=1; two +=1;}

                }

        if((two%2)!=0){two-=1;one+=1;}
        if(two>=1){taxi+=(two/2);}

         while (one >= 4){one-= 4;taxi+=1;}
        if ((two>0)){taxi+=1;}
        if ((one>0)){taxi+=1;}

     print(taxi);

var n = readline();
var groups = readline().split(' ').sort();
var carCount = 0;

var countStruct = {
    1: 0,
    2: 0,
    3: 0
};

for (var i = 0; i < groups.length; i++) {
    if (groups[i] == 4) {
        carCount++;
    } else if (groups[i] == 3) {
        countStruct[3]++;
    } else if (groups[i] == 2) {
        countStruct[2]++;
    } else if (groups[i] == 1) {
        countStruct[1]++;
    }
}

while(countStruct[3] > 0 && countStruct[1] > 0){
        countStruct[1]--;
        countStruct[3]--;
        carCount++;
}

while(countStruct[2] > 0 && countStruct[1] > 0){
        countStruct[1]--;
        countStruct[2]--;
        countStruct[3]++;
}

while(countStruct[3] > 0 && countStruct[1] > 0){
        countStruct[1]--;
        countStruct[3]--;
        carCount++;
}

carCount += countStruct[3];
carCount += Math.ceil(countStruct[2]/4);
carCount += Math.ceil(countStruct[1]/4);

print(carCount);

n = readline();
str = readline().split(' ').map(Number);

var count = 0;

for (var i = 0; i < str.length; i++) {
	count += str[i];
};

if (count % 4 !== 0) {
	print(Math.floor(count / 4) + 1);
} else {
	print(count / 4);
};

function Programa(){
  var pasar = readline();
  var entrada = readline().split(" ");
  var taxis = 0, cantidad_de_pibes = 0;
  for (var i = 0; i < entrada.length; i++){
    cantidad_de_pibes += parseInt(entrada[i]);
  }
  taxis += parseInt(cantidad_de_pibes / 4) + 1;
  print (taxis);
}
Programa();

var num = readline();
var nums = readNums();

var k = 0;

nums.sort(function(a,b){return b-a});

while (1) {

	if (nums.length == 0) {
		break;
	}

	var firstObj = nums.shift();
	var endObj = nums.pop();

	if (firstObj == 4) {
		k++;
	}else{
		if (firstObj+endObj<4) {
			nums.unshift(firstObj+endObj);
		}else if (firstObj+endObj>4) {
			nums.push(endObj);
			k++;
		}else{
			k++;
		}
	}

}

print(k);

function readNums() {
    return readline().split(' ').map(function(v) {
        return v - 0;
    })
}

var kids = 0;
readline();
readline().split(' ').map(function(c){
	kids += parseInt(c);
});

print(Math.ceil(kids / 4));

var n = readline();
var s = readline().split(' ').sort();
for(var i=n-1, j=0; i>=j; i--){
    if(i===j) continue;
    if(s[i]+s[j]<=4) j++;
}
print(i);

var n = parseInt(readline());
var numbersInput = readline().split(' ');
var groupsOne = 0;
var groupsTwo = 0;
var groupsThree = 0;
var taxis = 0;

for (var k = 0; k < n; k++) {
    var newGroup = parseInt(numbersInput[k]);
    if (newGroup === 4) {
        taxis++;
    } else if (newGroup === 1) {
        groupsOne++;
    } else if (newGroup === 2) {
        groupsTwo++;
    } else {
        groupsThree++;
    }
}

taxis = taxis + ((groupsTwo / 2) >> 0);
groupsTwo = groupsTwo % 2;

if (groupsTwo > 0 && groupsOne > 0) {
    groupsOne--;
    groupsOne--;
    groupsTwo--;
    taxis++;
}

//groupsTwo must be 0
while (groupsOne > 0 && groupsThree > 0) {
    taxis++;
    groupsOne--;
    groupsThree--;
}

if (groupsOne <= 0) {
    taxis = taxis + groupsThree;
    groupsThree = 0;
}

while (groupsOne >= 4) {
    groupsOne = groupsOne - 4;
    taxis++;
}

if (groupsOne > 0) {
    taxis++;
}

print(taxis);

var n = readline();

var arr = readline().split(' ');

var ans = [0,0,0,0,0];

for(var i in arr){
	var idx = parseInt(arr[i]);
	ans[idx]++;

}

var sum = 0;

sum = Math.min(ans[1],ans[3]);

ans[1] -= sum;
ans[3] -= sum;

sum += ans[3];
sum += ans[4];

sum += Math.floor(ans[1]/4);
ans[1] %= 4;

sum += Math.floor(ans[2]/2);
ans[2] %= 2;

if(ans[2] > 0){
	sum += ans[2];
	ans[1] -= 2;
}

sum += Math.max(0,ans[1]);

print(sum);

print(sum);

var n = parseInt(readline());
var mas = readline();
mas = mas.split(" ");
var cars = 0;
var car_q = [0, 0, 0, 0];
for(var i = 0; i < n; ++i)
{
	car_q[parseInt(mas[i])-1] ++;
}
cars = cars + car_q[3];
if(car_q[0] >= car_q[2])
{
	cars = cars + car_q[2];
	car_q[0] = car_q[0] - car_q[2];
}
else
{
	cars = cars + car_q[2];
	car_q[0] = 0;
}
cars = cars + Math.ceil(car_q/2);
if(car_q[1] % 2 != 0 && car_q[0] != 0)
{
	car_q[0] --;
}
cars = cars + Math.ceil(car_q[0]/4);
print(cars);

var n = readline(),
    people = readline().split(' ').sort().reverse(),
    offset = people.length,
    s = 0,
    i = 0;
if(people[0] == 1) {
    s = Math.ceil(people.length / 4);
}
else {
    while(i < offset) {
        if(people[i] == 3 && people[offset] == 1 ||
           people[i] == 2 && people[offset] == 2){
                offset--;
        }
        s++;
        i++;
    }
}
print(s);

var n = readline();
var s = readline().split(' ').map(function(a){return parseInt(a);}).sort(function(a,b){return b-a;});
var cars = 0;
for(var i=0; i<s.length; cars++){
    var sum = s.shift();
    for(var j=s.length-1; j>i;j--){
        if(sum+s[j]<=4){
            sum += s[j];
            s.splice(j, 1);
        }
        if(sum===4) break;
    }
}
print(cars);

var n = parseInt(readline(), 10),
    inp = readline().split(' ').map(el => parseInt(el, 10)).sort((a,b) => b-a),
    taxi = 0,
    friendNum = 0;

for(var i=0; i<=inp.length-1; i++) {
    friendNum += inp[i];

    if(friendNum < 4) {
        if((friendNum + inp[i+1]) > 4) {
            taxi++;
            friendNum = 0;
        }
    } else if(friendNum === 4) {
        taxi++;
        friendNum = 0;
    }
}

print(taxi);

var x= parseInt(readline());
var arr=readline().split(' ').map(x => parseInt(x));

arr.sort((a,b) => a-b);
var taxis=0;
var rem=0;
for(var i=0; i<x;i++){
  rem+=arr[i];
  taxis+=Math.floor(rem/4);
  rem%=4;
}

if(rem>0)
  taxis++;

print(taxis);

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

//var input = 5;
//var ninyos= [1,2,4,3,3];
var input = readline();
var ninyos= readline().split(" ");
var ninyos1=0;
var ninyos2=0;
var ninyos3=0;
var taxis=0;

for (var x=0;x<ninyos.length;x++){
	if(ninyos[x] == 4){
		taxis++;
	}else if(parseInt(ninyos[x])==3){
		ninyos3+=parseInt(ninyos[x]);
	}else if (parseInt(ninyos[x])==2){
		ninyos2+=parseInt(ninyos[x]);
		if(ninyos2==4){
			taxis++;
			ninyos2=0;
		}
	}else if(parseInt(ninyos[x])==1){
		ninyos1+=parseInt(ninyos[x]);
	}
}
//document.write(taxis + Math.ceil((ninyos1+ninyos3)/4)+Math.ceil(ninyos2/4));
//document.write(Math.ceil((ninyos1+ninyos3)/4));
print(taxis + Math.ceil((ninyos1+ninyos3)/4)+Math.ceil(ninyos2/4));

var n = readline();
var child = readline().split(" ");

var allChild = child.reduce((sum, current)=> {
  return +sum + +current
});
var tax = 4;
print(Math.ceil(allChild/tax));

var taxi=0;
    var one=0;
    var two=0;
    var three=0;
	var len = readline();
	var readitem = readline().split(' ');
for (var i = 0; i < readitem.length; i++)
    {if(readitem[i] == "4"){taxi+=1;}
	if(readitem[i] == "3"){three+=1;}
	if(readitem[i] == "2"){two+=1;}
	if(readitem[i] == "1"){one+=1;}}
	taxi += three;
    if(one <= three){one = 0;}else if(three>0){one-=(one-three);}

      if((two%2)!=0){
      two-=1;
      one+=1;}

     if(two>0){taxi+=(two/2);}
	 while (one >= 4){
     one-= 4;
     taxi+=1;}
     if (one>0){taxi+=1;}
     print(taxi);

var n = Number(readline());
var groups = readline().split(" ").map(function(x) { return parseInt(x); }).sort();
var taxies = 0;
var buffer = 0;

for (var i = n - 1; i >= buffer; i--) {
    var groupR = groups[i];
    var temp = groupR;

    for (var j = buffer; j < groups.length; j++) {
        var groupL = groups[j];

        if ( temp + groupL >= 4 ) {
            if ( temp + groupL == 4 ) {
                buffer++;
            }

            taxies++;
            break;
        } else {
            temp += groupL;
            buffer++;
        }
    }
}

print( taxies );

var n = readline();
var child = readline().split(" ");
var one =0;
var two =0;
var three =0;
var four =0;
for (var i=0;i<n; i++){
	if (child[i]==1)
	one++;
	else if (child[i]==2)
	two++;
	else if (child[i]==3)
	three++;
	else if (child[i]==4)
	four++;
};

var a = four+Math.floor((three*3+one)/4)+((three*3+one)%4)/3+Math.round((two*2)/4);
print(a);

var n = readline();

var arr = readline().split(' ');

var ans = [0,0,0,0,0];

for(var i in arr){
	var idx = parseInt(arr[i]);
	ans[idx]++;

}

var sum = 0;

sum = Math.min(ans[1],ans[3]);

ans[1] -= sum;
ans[3] -= sum;

sum += ans[3];
sum += ans[4];

sum += Math.floor(ans[1]/4);
ans[1] %= 4;

sum += Math.floor(ans[2]/2);
ans[2] %= 2;

if(ans[1] > 2)
	sum += (1 + ans[2]);
else if(ans[1] > 0)
	sum += ans[2];
else
	sum += ans[2];

print(sum);

var n = parseInt(readline());
var mas = readline();
mas = mas.split(" ");
var cars = 0;
var car_q = [0, 0, 0, 0];
for(var i = 0; i < n; ++i)
{
    car_q[parseInt(mas[i])-1] ++;
}
print(car_q);
cars += car_q[3];
if(car_q[0] >= car_q[2])
{
    cars += car_q[2];
    car_q[0] -= car_q[2];
}
else
{
    cars += car_q[2];
    car_q[0] = 0;
}
cars += Math.ceil(car_q/2);
if(car_q[1] % 2 != 0 && car_q[0] != 0)
{
    car_q[0] --;
}
cars += Math.ceil(car_q[0]/4);
print(cars);

var n = readline().split(' ').map(Number);
var a = readline().split(' ').map(Number),
    count = [0, 0, 0, 0, 0];

for (var i = 0; i < a.length; i++) {
    count[a[i]]++;
}

var ans = count[4] + count[3] + Math.floor(count[2] / 2);

(count[1] - count[3] >= 0) ? count[1] -= count[3] : count[1] = 0;

if (count % 2 == 1) {
    ans++;
    (count[1] - 2 >= 0) ? count[1] -= 2 : count[1] = 0;
}

ans = ans + Math.floor(count[1] / 4);

if (count[1] % 4) {
    ans++;
}

print(ans);

function main() {
  const count = readline();
  for (var i = 0; i < count; i++) {
      var view = readline();
      if (isRowColumnView(view)) {
          print(changeViewToExcel(view));
      } else {
          print(changeViewToCR(view));
      }
  }
}

main();

function main() {
    const count = readline();
    var groupCount = {};
    var groupArr = readline().split(" ").map(elem => {
        if (groupCount[elem]) {
            groupCount[elem]++;
        } else {
            groupCount[elem] = 1;
        }
        return +elem;
    });
    var taxi = groupCount['4'] || 0;

    if (groupCount['3'] >= groupCount['2'] && Math.floor(groupCount['1']/2) < groupCount['2']) {
        if (groupCount['1'] >= groupCount['3']) {
            taxi += groupCount['3'];
            groupCount['1'] -= groupCount['3'];
            groupCount['3'] = 0;
        } else {
            taxi += groupCount['1'];
            groupCount['3'] -= groupCount['1'];
            groupCount['1'] = 0;
        }
    }
    var floor2FirstGroup = Math.floor(groupCount['1']/2)
    if (floor2FirstGroup >= groupCount['2']) {
        taxi += groupCount['2'];
        groupCount['1'] -= (floor2FirstGroup * 2);
        groupCount['2'] = 0;
    } else {
        taxi += floor2FirstGroup;
        groupCount['2'] -= floor2FirstGroup;
        groupCount['1'] -= floor2FirstGroup * 2;
    }
    if (groupCount['1'] >= groupCount['3']) {
        taxi += groupCount['3'];
        groupCount['1'] -= groupCount['3'];
        groupCount['3'] = 0;
    } else {
        taxi += groupCount['1'];
        groupCount['3'] -= groupCount['1'];
        groupCount['1'] = 0;
    }
    var floor2SecondGroup = Math.floor(groupCount['2']/2);
    taxi += floor2SecondGroup;
    groupCount['2'] -= floor2SecondGroup * 2;
    if (groupCount['2'] > 0 && groupCount['1'] > 0) {
        taxi++;
        groupCount['2'] = 0;
        groupCount['1'] -= 1;
    }
    var floor4FirstGroup = Math.floor(groupCount['1']/4);
    taxi += floor4FirstGroup;
    groupCount['1'] -= floor4FirstGroup * 4;
    if (groupCount['1'] > 0) {
        taxi++;
        groupCount['1'] = 0;
    }
    var resultTaxi = taxi + groupCount['3'] + groupCount['2'] + groupCount['1'];
    print(resultTaxi);
}

var n = Number(readline());
var groups = readline().split(" ").map(function(x) { return parseInt(x); }).sort();
var taxies = 0;
var buffer = 0;

var peopleCount = groups.reduce(function (prev, next) {
    return prev + next;
});

if ( peopleCount >= 4 ) {
    for (var i = n - 1; i >= buffer; i--) {
        var groupR = groups[i];
        var temp = groupR;

        for (var j = buffer; j < n && i != j; j++) {
            var groupL = groups[j];

            if ( temp + groupL >= 4 ) {
                if ( temp + groupL == 4 ) {
                    buffer++;
                }

                taxies++;
                break;
            } else {
                temp += groupL;
                buffer++;
            }
        }
    }
} else {
    taxies = 1;
}

print( taxies );

var n = readline();
var s = readline().split(' ').sort(function(a,b){return b-a;});
for(var i=0, j=n-1; i<=j; i++){
    if(i<j && parseInt(s[i])+parseInt(s[j])<=4) j--;
}
print(i);

//158B - Taxi
var n = +readline();
var numbers = readline().split(' ').map(e => parseInt(e)).sort().reverse();
var res = 0;
for (var i = 0; i < numbers.length; i++) {
    for (var j = i + 1; j < numbers.length; j++) {
        if (numbers[i] + numbers[j] <= 4) {
            numbers[i] += numbers[j];
            numbers.splice(j,1);
        }
        if (numbers[i] == 4) {
            break;
        }
    }
}
print(numbers);
print(numbers.length);

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [count, peoples] = input
  count = parseInt(count)
  peoples = peoples.split(' ')
  let num1 = 0,
      num2 = 0,
      num3 = 0,
      num4 = 0
  for (let i = 0; i < count; i++) {
    const el = parseInt(peoples[i])
    switch (el) {
      case 1: {
        num1++
      } break;
      case 2: {
        num2++
      } break;
      case 3: {
        num3++
      } break;
      case 4: {
        num4++
      } break;
    }
  }
  let allSum = num4
  if (num1 > 0 && num3 > 0) {
    if (num1 > num3) {
      const after = num1 - num3
      allSum += num3
      num1 = after
      num3 = 0
    } else if (num1 < num3) {
      const after = num3 - num1
      allSum += num1
      num1 = 0
      num3 = after
    } else {
      allSum += num1
      num1 = 0
      num3 = 0
    }
  } else if (num1 > 0 && num3 === 0) {
    const after = Math.floor(num1 / 4)
    const ostatok = ((num1 / 4) - after) * 4
    allSum += after
    num1 = ostatok
  } else if (num1 === 0 && num3 > 0) {
    allSum += num3
    num3 = 0
  }
  if (num2 > 0) {
    const after = Math.floor(num2 / 2)
    allSum += after
    const ostatok = ((num2 / 2) - after) * 2
    num2 = ostatok
  }
  if (num4 > 0) {
    num4 = 0
  }
  allSum += num3
  num3 = 0
  const check = (num2 + num1) / 4
  allSum += check >= 0.25 ? Math.ceil(check) : 0
  num1 = 0
  num2 = 0
  console.log(allSum)
});

//158B - Taxi
var n = +readline();
var numbers = readline().split(' ').map(e => parseInt(e)).sort().reverse();
var res = 0;
for (var i = 0; i < numbers.length; i++) {
    for (var j = i + 1; j < numbers.length; j++) {
        if (numbers[i] + numbers[j] <= 4) {
            numbers[i] += numbers[j];
            numbers.splice(j,1);
        }
        if (numbers[i] == 4) {
            break;
        }
    }
}
print(numbers.length);

var num = parseInt(readline()),
    group = readline().split(' ').map(el => parseInt(el)),
    counter = 0;
for (var x = 0; x < group.length; x++) {
    counter += group[x];
}
if (counter == 4) {
    print(1);
} else {
    counter = 0;
    for (var i = 0; i < group.length; i++) {
        if (group[i] == 4) {
            counter++;
            group.splice(i, 1);
            i = -1;
            continue;
        }
        for (var j = 1; j < group.length; j++) {
            if (i == -1) i++;
            if (i == j) continue;
            if (group[i] + group[j] == 4) {
                counter++;
                group.splice(i, 1);
                group.splice(j - 1, 1);
                i = -1, j = 0;
            }
            if (group.length == 0) {
                break;
            }
        }
        for (var a = 0; a < group.length; a++) {
            if (group[a] == 1 && group[a + 1] < 3 || group[a] < 3 && group[a + 1] == 1) {
                group[a] += group[a + 1];
                group.splice(a + 1, 1);
            }
        }
    }

    print(counter + group.length);
}

var n = parseInt(readline());
var mas = readline();
mas = mas.split(" ");
var cars = 0;
var car_q = [0, 0, 0, 0];
for(var i = 0; i < n; ++i)
{
	car_q[parseInt(mas[i])-1] ++;
}
cars = cars + car_q[3];
if(car_q[0] >= car_q[2])
{
	cars = cars + car_q[2];
	car_q[0] = car_q[0] - car_q[2];
}
else
{
	cars = cars + car_q[2];
	car_q[0] = 0;
}
cars = cars + Math.ceil(car_q/2);
if(car_q[1] % 2 != 0 && car_q[0] != 0)
{
	car_q[0] --;
}
cars = cars + Math.ceil(car_q[0]/4);
print(cars);

var kids = 0;
readline();
readline().split(' ').map(function(c){
	kids += parseInt(c);
});

print(Math.ceil(kids / 4));

   var taxi=0;var one=0;var two=0;var three=0;
  var len = readline();
 var ajx = readline();
	var readitem =  ajx.split(' ');
for (var i = 0; i < readitem.length; i++)
    {if(readitem[i] == "4"){taxi+=1;}
	if(readitem[i] == "3"){three+=1;}
	if(readitem[i] == "2"){two+=1;}
	if(readitem[i] == "1"){one+=1;}}

	taxi += three;
    if(one <= three){one = 0;}else if(three>0){one-=(one-three);}

    if((two%2)!=0){two-=1;one+=1;}if(two>0){taxi+=(two/2);two=0;}

        if(two=0){
        while((two > 0) && (two < 4)&&(one > 0)){one -=1; two +=1;}

                }
        if((two%2)!=0){two-=1;one+=1;}
        if(two>=1){taxi+=(two/2);}

	 while (one >= 4){one-= 4;taxi+=1;}
     if ((two>0)||(one>0)){taxi+=1;}

     print(taxi);

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

//var input = 8;
//var ninyos= [2,3,4,4,2,1,3,1];
var input = readline();
var ninyos= readline().split(" ");
var ninyos1=0;
var ninyos2=0;
var ninyos3=0;
var taxis=0;

for (var x=0;x<ninyos.length;x++){
	if(ninyos[x] == 4){
		taxis++;
	}else if(parseInt(ninyos[x])==3){
		ninyos3+=parseInt(ninyos[x]);
	}else if (parseInt(ninyos[x])==2){
		ninyos2+=parseInt(ninyos[x]);
		if(ninyos2==4){
			taxis++;
			ninyos2=0;
		}
	}else if(parseInt(ninyos[x])==1){
		ninyos1+=parseInt(ninyos[x]);
	}
}
//document.write(taxis + Math.ceil((ninyos1+ninyos3)/4))
print(taxis + Math.ceil((ninyos1+ninyos3)/4));

var n = Number(readline());
var groups = readline().split(" ").map(function(x) { return parseInt(x); }).sort();
groups.push( 5 );
var memory = [];
var temp = 0;

for (var i = 0; i < groups.length - 1; i++) {
    var group = groups[i];

    if ( temp + group >= 4 || group + groups[i + 1] > 4 ) {
        memory[i] = 1;
        temp = 0;
    } else {
        memory[i] = 0;
        temp += group;
    }
}

print( memory.reduce(function (prev, next) {
    return prev + next;
}));

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});
const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const groups = input[1].split(' ').map(x => parseInt(x));
  const countGroups = [0, 0, 0, 0];

  groups.forEach(g => countGroups[g-1] += 1);
  let taxi  = countGroups[3];
  taxi += countGroups[2];

  countGroups[0] -= countGroups[2];
  if (countGroups[1] % 2 === 0 && countGroups[1] > 0) {
    taxi += countGroups[1]/2;
    if (countGroups[0] > 0)
      taxi += parseInt(Math.ceil(countGroups[0]/4));
  } else {
    taxi += parseInt(Math.ceil(countGroups[1]/2));
    countGroups[0] -= 2;
    if (countGroups[0] > 0) taxi += parseInt(Math.ceil(countGroups[0]/4));
  }

  console.log(taxi);
});

var n = parseInt(readline());
var mas = readline();
mas = mas.split(" ");
var cars = 0;
var car_q = [0, 0, 0, 0];
for(var i = 0; i < n; ++i)
{
    car_q[parseInt(mas[i])-1] ++;
}
cars += car_q[3];
if(car_q[0] >= car_q[2])
{
    cars += car_q[2];
    car_q[0] -= car_q[2];
}
else
{
    cars += car_q[2];
    car_q[0] = 0;
}
cars += Math.ceil(car_q[1]/2);
if(car_q[1] % 2 != 0 && car_q[0] != 0)
{
    car_q[0] --;
}
cars += Math.ceil(car_q[0]/4);
print(cars);

   var taxi=0;var one=0;var two=0;var three=0;
   var len = readline();
 //var ajx = "2 3 4 4 2 1 3 1"
	var readitem =  readline().split(' ');
for (var i = 0; i < readitem.length; i++)
    {if(readitem[i] == "4"){taxi+=1;}
	if(readitem[i] == "3"){three+=1;}
	if(readitem[i] == "2"){two+=1;}
	if(readitem[i] == "1"){one+=1;}}

	taxi += three;
    if(one <= three){one = 0;}else if(three>0){one-=(one-three);}

    if((two%2)!=0){two-=1;one+=1;}

    if(two>=1){taxi+=(two/2);two=0;}

   else
        while((two < 0) && (two < 4)&&(one > 0)){one -=1; two +=1;}
        if((two%2)!=0){two-=1;one+=1;}
        if(two>=1){taxi+=(two/2);}

	 while (one >= 4){one-= 4;taxi+=1;}
     if ((two>0)||(one>0)){taxi+=1;}

     print(taxi);

var taxi=0;
    var one=0;
    var two=0;
    var three=0;
	var len = readline();
	var readitem = readline().split(' ');
for (var i = 0; i < readitem.length; i++)
    {if(readitem[i] == "4"){taxi+=1;}
	if(readitem[i] == "3"){three+=1;}
	if(readitem[i] == "2"){two+=1;}
	if(readitem[i] == "1"){one+=1;}}
	taxi += three;
    if(one <= three){one = 0;}else if(three>0){one-=(one-three);}

      if((two%2)!=0){
      two-=1;
      one+=1;}

     if(two>0){taxi+=(two/2);}
	 while (one >= 4){
     one-= 4;
     taxi+=1;}
     if (one>0){taxi+=1;}
     print(taxi);

var groupsQuantity = readline();
var childrenQuantity = readline().split(" ");

var cars = 0;

var NumberGroupsOfOne = 0;
var NumberGroupsOfTwo = 0;
var NumberGroupsOfThree = 0;
var NumberGroupsOfFour = 0;

for(var i = 0; i < groupsQuantity; i++){
  switch(+childrenQuantity[i]){
    case 1: NumberGroupsOfOne++;
    break;
    case 2: NumberGroupsOfTwo++;
    break;
    case 3: NumberGroupsOfThree++;
    break;
    case 4: NumberGroupsOfFour++;
    break;
  }
}

cars += NumberGroupsOfFour;

if(NumberGroupsOfOne > NumberGroupsOfThree){
  cars += NumberGroupsOfThree;
  NumberGroupsOfOne -= NumberGroupsOfThree;
  if(NumberGroupsOfOne * 2> NumberGroupsOfTwo){
    cars += NumberGroupsOfTwo;
    cars += Math.ceil((NumberGroupsOfOne - NumberGroupsOfTwo)/4);
  }
  else{
    cars += Math.ceil(NumberGroupsOfTwo/2);
  }
}
else{
  cars += NumberGroupsOfOne;
  NumberGroupsOfThree -= NumberGroupsOfOne;
  cars += NumberGroupsOfThree;
  cars += Math.ceil(NumberGroupsOfTwo/2);
}
print(cars);

var n = parseInt(readline());

var gFour = 0;
var gThree = 0;
var gTwo = 0;
var gOne = 0;

var gList = readline();

for(var i = 0; i < gList.length; i++){
    if (gList[i] === '4'){
        gFour++;
    } else if (gList[i] === '3'){
        gThree++;
    } else if (gList[i] === '2'){
        gTwo++;
    } else if (gList[i] === '1'){
        gOne++;
    }
}

var v1 = 0;

var gOne2 = 0
if (gThree > gOne) {
    v1 = gOne + ( gThree - gOne);
} else if (gThree < gOne){
    v1 = gThree;
    gOne2 = gOne - gThree;
} else if( gThree === gOne){
    v1 = gThree;
}

var v2 = 0;

var gTwo2 = 0;
if(gTwo % 2 === 0){
    v2 = gTwo / 2;
} else {
    v2 = Math.floor(gTwo / 2);
    gTwo2 = 1;
}

var v3 = 0;
//print(Math.floor(gOne / 4));
if (gTwo2 != 0 && gOne2 !== 0){
    if (gOne2 <= 2) {
        v3 = 1;
    } else {
        v3 = 1 + Math.ceil((gOne - 2) / 4);
    }
} else if (gTwo2 === 0 && gOne2 !== 0){
    v3 = Math.floor(gOne / 4);
} else if(gTwo2 != 0 && gOne2 === 0){
    v3 = 1;
}

var tax = gFour + v1 + v2 + v3;

print(tax);

n = readline();
str = readline().split(' ').map(Number);

var count = 0;

for (var i = 0; i < str.length; i++) {
	count += str[i];
};

if (count % 2 !== 0) {
	print(Math.floor(count / 4) + 1);
} else {
	print(count / 4);
};

var groupsQuantity = readline();
var childrenQuantity = readline().split(" ");

var cars = 0;

var NumberGroupsOfOne = 0;
var NumberGroupsOfTwo = 0;
var NumberGroupsOfThree = 0;
var NumberGroupsOfFour = 0;

for(var i = 0; i < groupsQuantity; i++){
  switch(+childrenQuantity[i]){
    case 1: NumberGroupsOfOne++;
    break;
    case 2: NumberGroupsOfTwo++;
    break;
    case 3: NumberGroupsOfThree++;
    break;
    case 4: NumberGroupsOfFour++;
    break;
  }
}

cars += NumberGroupsOfFour;

if(NumberGroupsOfOne > NumberGroupsOfThree){
  cars += NumberGroupsOfThree;
  NumberGroupsOfOne -= NumberGroupsOfThree;
  if(NumberGroupsOfOne * 2> NumberGroupsOfTwo){
    cars += NumberGroupsOfTwo;
    cars += Math.ceil((NumberGroupsOfOne - NumberGroupsOfTwo * 2)/4);
  }
  else{
    cars += Math.ceil(NumberGroupsOfTwo/2);
  }
}
else{
  cars += NumberGroupsOfOne;
  NumberGroupsOfThree -= NumberGroupsOfOne;
  cars += NumberGroupsOfThree;
  cars += Math.ceil(NumberGroupsOfTwo/2);
}
print(cars);

readline();

var car = [0,0,0,0,0];
readNums().map(v => car[v]++);

var m = Math.min(car[1], car[3]);
car[1] -= m;
car[3] -= m;
car[4] += m;

var m = Math.min(car[1], car[2] * 2);
if (m & 1)
    m--;
car[1] -= m;
car[2] -= m / 2;
car[4] += m;

var m = Math.min(car[1], car[2]);
car[1] -= m;
car[2] -= m;
car[3] += m;

m = Math.floor(car[2] / 2);
car[2] -= m * 2;
car[4] += m;

m = Math.floor(car[1] / 4);
car[1] -= m * 4;
car[4] += m;

print(car.reduce((a,b) => a + b));

function readNums() {
    return readline().split(' ').map(v => v - 0)
}

const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
    let [count, peoples] = input
    count = parseInt(count)
    peoples = peoples.split(' ')
    let num1 = []
    let num2 = []
    let num3 = []
    let num4 = []
    for (let i = 0; i < count; i++) {
        const el = parseInt(peoples[i])
        switch (el) {
            case 1: {
                num1.push(el)
            } break;
            case 2: {
                num2.push(el)
            } break;
            case 3: {
                num3.push(el)
            } break;
            case 4: {
                num4.push(el)
            } break;
        }
    }
    let allSum = num4.length
    let notRegister = 0
    if (num1.length > 0 && num3.length > 0) {
        if (num1.length > num3.length) {
            const after = num1.length - num3.length
            const ostatok = num1.length - after
            allSum += ostatok
            notRegister += after
        } else if (num1.length < num3.length) {
            const after = num3.length - num1.length
            const ostatok = (num3.length - after) * 3
            allSum += after
            notRegister += ostatok
        } else {
            allSum += num1.length
        }
    } else if (num1.length === 0 && num3.length > 0) {
        allSum += num3.length
    } else if (num1.length > 0 && num3.length === 0) {
        const after = Math.floor(num1.length / 4)
        const ostatok = Math.ceil((num1.length / 4) - after)
        allSum += after
        notRegister += ostatok
    }
    if (num2.length > 0) {
        if ((num2.length / 2) > 1) {
            const after = Math.floor(num2.length / 2)
            const ostatok = ((num2.length / 2) - after) * 2
            allSum += after
            notRegister += ostatok
        } else {
            notRegister += num2.length * 2
        }
    }
    allSum += Math.ceil(notRegister / 4)
    console.log(allSum)
});

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

var input = readline();
var input2 = readline().split(" ");
//var input = 3;
//var input2 = new Array(3,3,2)
var lleno3 = 0;
var cont4 = 0;
var ninyos = 0;

for (var x = 0; x<input;x++){
	if(input2[x]==4){
		cont4++;
	}else if (input2[x]==3 || input2[x] ==1){

		lleno3 += parseInt(input2[x]);
		if(lleno3 ==4){
			cont4++;
			lleno3 = 0;
		}if(input2[x]==input && lleno3>4){
			cont4 += Math.floor(lleno3/3);
			lleno3=0;
		}
	}else if(input2[x]==2){
		ninyos += parseInt(input2[x]);
	}

}

print(Math.ceil((ninyos+lleno3)/4)+cont4);
//document.write(Math.ceil((ninyos+lleno3)/4)+cont4);

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

var input = readline();
var input2 = readline().split(" ");
var ninyos = 0;
var cont = 0;
//var taxis = Math.ceil(ninyos/4);
for (var x = 0; x<input;x++){
	if(input2[x]>=3){
		cont++;
	}else {
		ninyos += input2[x];
	}

}

print(Math.floor(ninyos/4)+cont);

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

var input = readline();
var input2 = readline().split(" ");

var ninyos = 0;
var cont = 0;

for (var x = 0; x<input;x++){
	if(input2[x]>=3){
		cont++;
	}else {
		ninyos += parseInt(input2[x]);
	}

}

print(Math.floor(ninyos/4)+cont);

    var taxi=0;
    var one=0;
    var two=0;
    var three=0;
	var len = readline();

	var readitem = readline().split(' ');
	for (var i = 0; i < readitem.length; i++)
   {
   	if(readitem[i] == "4"){taxi+=1;}
	if(readitem[i] == "3"){three+=1;}
	if(readitem[i] == "2"){two+=1;}
	if(readitem[i] == "1"){one+=1;}
   }
   taxi += three;
if(one <= three){one = 0;}else{one-=one-three;}
if(two%2!=0){
	two-=1;
	one+=1;
	if(two>0){taxi=two/2;}
}
while (one >= 4){
one-= 4;
taxi+=1;}
if (one>0){taxi+=1;}
print(taxi);

/*
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Examples
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
*/

var input = readline();
var input2 = readline().split(" ");
var ninyos = 0;
var cont = 0;
//var taxis = Math.ceil(ninyos/4);
for (var x = 0; x<input;x++){
	if(input2[x]=4){
		cont++;
	}else {
		ninyos += parseInt(input2[x]);
	}

}

print(Math.floor(ninyos/4)+cont);

var n = readline();

var arr = readline().split(' ');

var ans = [0,0,0,0,0];

for(var i in arr){
	var idx = parseInt(arr[i]);
	ans[idx]++;

}

var sum = 0;

sum = Math.min(ans[1],ans[3]);

ans[1] -= sum;
ans[3] -= sum;

sum += ans[3];
sum += ans[4];

sum += Math.floor(ans[1]/4);
ans[1] %= 4;

sum += Math.floor(ans[2]/2);
ans[2] %= 2;

if(ans[2] > 0){
	sum += ans[2];
	ans[1] -= 2;
}

sum += Math.max(0,ans[1]);

print(sum);

var num1 = parseInt(readline());
var sum , one , thr;
sum = one = thr = 0;
for(var i = 0 ; i < num1 ; i++)
{
  var num = parseInt(readline());
  switch (num) {
    case 3:
      if (one > 0 ) {
        sum+=4;
        one--;
      }
      else
      {
        thr++;

      }
      break;

    case 1:
      if (thr > 0) {
        sum += 4;
        thr--;
      }
      else {
        one++;

      }
      break;

    default:
      sum += num;
      break;
  }
}
sum += one ;
print(Math.ceil(sum/4)+thr);

var n = readline();
var s = readline().split(' ').map(function(a){return parseInt(a);}).sort(function(a,b){return b-a;});
var cars = 0;
for(var i=0; i<s.length; cars++){
    var sum = s.shift();
    for(var j=s.length-1; j>i;j--){
        if(sum+s[j]<=4){
            sum += s[j];
            s.splice(j, 1);
        }
        if(sum===4) break;
    }
}
print(cars);

var n = parseInt(readline());
var mas = readline();
mas = mas.split(" ");
mas.sort(1);
print(mas);