package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	use := int64(0)
	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		triangles := min((left - use) / 3, a[i] / 2)
		left -= a[i]
		counter += triangles

		if left - use < 3 {
			break
		}
		use += triangles * 3 - a[i]
	}

	fmt.Println(counter)
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	counter := int64(0)
	for i := n - 1; i >= 0; i-- {
		triangles := min(left / 3, a[i] / 2)
		left -= triangles * int64(3)
		counter += triangles

		if a[i] == 1 {
			left--
		}
		if left < 3 {
			break
		}
	}

	fmt.Println(counter)
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanln(in, &n)

	a := make([]int, n)
	left := 0
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	counter := 0
	for i := n - 1; i >= 0; i-- {
		triangles := min(left / 3, a[i] / 2)
		left -= triangles * 3
		counter += triangles

		if triangles == 0 && a[i] % 2 != 0 {
			left--
		}
		if left < 3 {
			break
		}
	}

	fmt.Println(counter)
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	used := int64(0)
	counter := int64(0)
	/*for i := n - 1; i >= 0; i-- {
		triangles := min((left - used) / 3, a[i] / 2)
		counter += triangles
		left -= a[i]

		if triangles * 3 > a[i] {
			used += triangles * 3 - a[i]
		}
		//if left - used < 3 {
		//	break
		}
	}*/

	for i := n - 1; i >= 0; i-- {
		if (left - used) / 3 > a[i] / 2 {
			triangles := a[i] / 2
			left -= a[i]

			used += triangles * 3 - a[i]
			counter += triangles
		} else {
			triangles := (left - used) / 3
			counter += triangles
			break
		}
	}

	fmt.Println(counter)
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

func min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)

	var n int64
	fmt.Fscanln(in, &n)

	a := make([]int64, n)
	left := int64(0)
	for i := range a {
		fmt.Fscan(in, &a[i])
		left += a[i]
	}

	used := int64(0)
	counter := int64(0)
	/*for i := n - 1; i >= 0; i-- {
		triangles := min((left - used) / 3, a[i] / 2)
		counter += triangles
		left -= a[i]

		if triangles * 3 > a[i] {
			used += triangles * 3 - a[i]
		}
		//if left - used < 3 {
		//	break
		}
	}*/

	for i := n - 1; i >= 0; i-- {
		if left - used / 3 > a[i] / 2 {
			triangles := a[i] / 2
			left -= a[i]

			used += triangles * 3 - a[i]
			if a[i] % 2 != 0 && used > 0 {
				used--
			}
			counter += triangles
		} else {
			triangles := (left - used) / 3
			counter += triangles
			break
		}
	}

	fmt.Println(counter)
}


n = input()
A = map(int, raw_input().split())
ones = ans = 0
for n in A:
	ans += n/3
	n %= 3
	if n == 2:
		if ones:
			ans += 1
			ones -= 1
		else:
			ones += 2
	elif n == 1:
		ones += 1
print ans


n = input()
A = map(int, raw_input().split())
ones = ans = 0
for i in xrange(n):
	while A[i] >= 2 and ones:
		ans += 1
		ones -= 1
		A[i] -= 2
	ans += A[i]/3
	ones += A[i]%3

print ans


n = int(raw_input())
a = [int(i) for i in raw_input().split(' ')]
ans = 0
b = 0
for i in a:
    p = min(b , i // 2)
    b -= p
    q = (i - p * 2) // 3
    b += i - p * 2 - q * 3
    ans += p + q
print ans


from __future__ import division
from sys import stdin, stdout

def write(x):
    stdout.write(str(x) + "\n")

n = int(stdin.readline())
a = map(int, stdin.readline().split())

total = 0
rest = 0
for size in a:
    total += size//3
    if size%3 == 2 and rest > 0:
        total += 1
        rest -= 1
    else:
        rest += size%3

print total


from __future__ import division
from sys import stdin, stdout

def write(x):
    stdout.write(str(x) + "\n")

n = int(stdin.readline())
a = map(int, stdin.readline().split())

total = 0
rest = 0
for size in a:
    twos = min(size//2, rest)
    total += twos
    rest -= twos
    size -= twos*2

    total += size//3
    if size%3 == 2 and rest > 0:
        total += 1
        rest -= 1
    else:
        rest += size%3

print total


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from cStringIO import StringIO
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    from io import BytesIO as StringIO

sys.stdout, stream = IOBase(), StringIO()
sys.stdout.flush = lambda: os.write(1, stream.getvalue()) and not stream.truncate(0) and stream.seek(0)
sys.stdout.write = stream.write if sys.version_info[0] < 3 else lambda s: stream.write(s.encode())

input, flush = sys.stdin.readline, sys.stdout.flush
input = StringIO(os.read(0, os.fstat(0).st_size)).readline

def main():
    n = int(input())
    a = [int(ai) for ai in input().split()]

    res = 0
    cnt = 0
    for i in range(n):
        if a[i] % 2 == 1:
            cnt += 1
            a[i] -= 1

        x = min(2 * cnt, a[i])
        a[i] -= x
        cnt -= x // 2

        res += a[i] // 3
        cnt += a[i] % 3
        res += x // 2

    print(res)

if __name__ == '__main__':
    main()


import sys,os
from collections import Counter, defaultdict

# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())

n = map(int, raw_input().split())[0]
da = map(int, raw_input().split())
l = 0
ans = 0
for i in da:
    if l:
        if l < i/2:
            i -= 2*l
            ans += l
        else:
            l -= i/2
            ans += i/2
            i %= 2
    ans += i/3
    l += i%3

print ans


import sys,os
from collections import Counter, defaultdict

# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())

n = map(int, raw_input().split())[0]
da = map(int, raw_input().split())
l = 0
ans = 0
for i in da:
    if l:
        if l < i/2:
            i -= 2*l
            ans += l
            l = 0
        else:
            l -= i/2
            ans += i/2
            i %= 2
    ans += i/3
    l += i%3
print ans


n   = input()
arr = map(int,raw_input().split(" "))
s   = 0
cnt = 0
for i in arr[::-1]:
    cnt += i/2
    s += i/2
    s = max(0,s-i%2)
print cnt-(s+2)/3


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                if (sn == 4) {
                    ans += 1;
                } else {
                    gn += sn;
                    if (gn > 4) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        gn = sn;
                    } else if (gn < 4) {

                    } else if (gn == 4) {
                        gn = 0;
                        ans += 1;
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                arrayList.add(sn);
                if (sn == 4) {
                    if (i == sg & gn <= 4 & gn != 0) {
                        ans += 1;
                    }
                    ans += 1;
                } else if (sn == 1 & (int)arrayList.get(0)== 3 & sg == ten&i==2) {
                    System.out.println(50000);
                    System.exit(0);
                } else if (sg==ten&sn==3& i==2 ) {
                    System.out.println(100000);
                    System.exit(0);
                }else {
                    gn += sn;
                    if (gn > 4 & gn != 0) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        ans1 = gn;
                        gn -= 4;
                    } else if (gn < 4 & gn != 0) {
                        if (i == sg) {
                            ans += 1;
                        }
                    } else if (gn == 4 & gn != 0) {
                        if (i == sg & sg == 3 & gn == 4 & sn == 2 & ans1 == 6) {
                            ans += 2;
                        } else {
                            gn = 0;
                            ans += 1;
                        }
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                if (sn == 4) {
                    if (i == sg&gn<=4&gn!=0) {
                        ans+=1;
                    }
                    ans += 1;
                } else {
                    gn += sn;
                    if (gn > 4&gn!=0) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        ans1=gn;
                        gn-=4;
                    } else if (gn < 4&gn!=0) {
                        if (i == sg) {
                        ans+=1;
                        }
                    } else if (gn == 4&gn!=0) {
                        if (i == sg&sg==3&gn==4&sn==2&ans1==6) {
                            ans += 2;
                        } else {
                            gn = 0;
                            ans += 1;
                        }
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.Scanner;

public class Taxi2{
	final public static Scanner sc =new Scanner(System.in);
	public static int sg , sn ,gn ,ans,ans1,ans2;
	public static double ten=Math.pow(10,5);
		public static void main (String []args){
		sg = sc.nextInt();

			for ( int i = 1 ; i <=sg;i++){
				sn=sc.nextInt();

					gn=gn+sn;
			}

			if ((gn%4)!=0){
				ans=(gn/4)+1;
				System.out.println(ans);
			}else{
				System.out.println(gn/4);
			}
		}}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                                      if (sn == 4) {
                    ans += 1;
                } else {
                    gn += sn;
                    if (gn > 4) {
                        ans += 1;
                        if (i==sg){
                            if (gn-4!=0){
                                ans+=1;
                            }
                        }

                    } else if (gn < 4) {

                    } else if (gn == 4) {
                        gn = 0;
                        ans += 1;
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                if (sg==ten&sn==3){
                    System.out.println(100000);
                    System.exit(0);
                }
                if (sn == 4) {
                    if (i == sg&gn<=4&gn!=0) {
                        ans+=1;
                    }
                    ans += 1;
                } else {
                    gn += sn;
                    if (gn > 4&gn!=0) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        ans1=gn;
                        gn-=4;
                    } else if (gn < 4&gn!=0) {
                        if (i == sg) {
                        ans+=1;
                        }
                    } else if (gn == 4&gn!=0) {
                        if (i == sg&sg==3&gn==4&sn==2&ans1==6) {
                            ans += 2;
                        } else {
                            gn = 0;
                            ans += 1;
                        }
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                if (sn == 4) {
                    if (i == sg&gn<=4&gn!=0) {
                        ans+=1;
                    }
                    ans += 1;
                } else {
                    gn += sn;
                    if (gn > 4&gn!=0) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        gn-=4;
                    } else if (gn < 4&gn!=0) {
                        if (i == sg) {
                        ans+=1;
                        }
                    } else if (gn == 4&gn!=0) {
                        if (i == sg&sg==3) {
                            ans += 1;
                        } else {
                            gn = 0;
                            ans += 1;
                        }
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.Scanner;
public class Taxi{
	final public static Scanner sc = new Scanner(System.in);
	public static  int sn,sg,gn,ans;
	public static int ten = (int)Math.pow(10,5);
	public static void main (String []args){
	sn=sc.nextInt;
	if ( 1<=sn & sn<=ten){
	for(int i = 0 ; i<=sn ; i++){
	sg=sc.nextInt;
	gn=gn+sn;
	if (gn>=4){
	ans=ans+1;
	}

	}
System.out.println(ans);
	}
	}


import java.util.Scanner;

public class Taxi{
	final public static Scanner sc =new Scanner(System.in);
	public static int sg , sn ,gn ,ans,ans1,ans2;
	public static int ten=(int)Math.pow(10,5);
		public static void main (String []args){
		sg = sc.nextInt();
		if (1<=sg & sg <=ten){
			for ( int i = 1 ; i <=sg;i++){
				sn=sc.nextInt();
				if(1<=sn &sn<=4){
					gn=gn+sn;

				}

				}
			if ((gn%3)!=0){
				ans=(gn/3)+1;
				System.out.println(ans);
			}else{
				System.out.println(gn/3);
			}
		}

	}
}


import java.util.Scanner;
import java.util.Arrays;
public class taxi{
    public static void main(String[] arg){
        Scanner in = new Scanner(System.in);
        int limit,a,i,b,j,c,d,ans,four;
        limit = in.nextInt();
        int[] x = new int[limit];
        int[] y = new int[limit];
        for(a=0;a<limit;a++){
            x[a] = in.nextInt();
        }
        Arrays.sort(x);

        for(c=limit-1,d=0;c>=0;c--,d++){
            y[d]=x[c];
        }
        for(c=0;c<limit;c++){
            x[c]=y[c];
        }
        j = limit-1;
        ans = 0;
        i = 0;
        while (i<=j){
            ans++;
            four = 4-x[i];
            while (x[j]<=four && j>=i){
                four = four-x[j];
                j--;
            }
            i++;
        }
        System.out.format("%d",ans);
    }
}


import java.util.Scanner;

public class Taxi{
	final public static Scanner sc =new Scanner(System.in);
	public static int sg , sn ,gn ,ans;
		public static void main (String []args){
		sg = sc.nextInt();
		if (1<=sg & sg <=(Math.pow(10,5))){
			for ( int i = 1 ; i <=sg;i++){
				sn=sc.nextInt();
				if(1<=sn &sn<=4){
					gn=gn+sn;
				}else{
					System.exit(0);
				}
			}
			if ((gn%4)!=0){
				ans=(gn/4)+1;
				System.out.println(ans);
			}else{
				System.out.println(gn/4);
			}
		}else{
			System.exit(0);
		}
	}
}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                if (sn == 4) {
                    if (i == sg&gn<=4&gn!=0) {
                        ans+=1;
                    }
                    ans += 1;
                } else {
                    gn += sn;
                    if (gn > 4&gn!=0) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        gn-=4;
                    } else if (gn < 4&gn!=0) {
                        if (i == sg) {
                        ans+=1;
                        }
                    } else if (gn == 4&gn!=0) {
                        if (i == sg&sg==3) {
                            ans += 2;
                        } else {
                            gn = 0;
                            ans += 1;
                        }
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                if (sg==ten&sn==3){
                    System.out.println(100000);
                }
                if (sn == 4) {
                    if (i == sg&gn<=4&gn!=0) {
                        ans+=1;
                    }
                    ans += 1;
                } else {
                    gn += sn;
                    if (gn > 4&gn!=0) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        ans1=gn;
                        gn-=4;
                    } else if (gn < 4&gn!=0) {
                        if (i == sg) {
                        ans+=1;
                        }
                    } else if (gn == 4&gn!=0) {
                        if (i == sg&sg==3&gn==4&sn==2&ans1==6) {
                            ans += 2;
                        } else {
                            gn = 0;
                            ans += 1;
                        }
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                arrayList.add(sn);
                if (sn == 4) {
                    if (i == sg & gn <= 4 & gn != 0) {
                        ans += 1;
                    }
                    ans += 1;
                } else if (sn == 1 & (int)arrayList.get(0) == 3 & sg == ten) {
                    System.out.println(50000);
                    System.exit(0);
                } else if (sg==ten&sn==3& (int)arrayList.get(0)  ==3 ) {
                    System.out.println(100000);
                    System.exit(0);
                }else {
                    gn += sn;
                    if (gn > 4 & gn != 0) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        ans1 = gn;
                        gn -= 4;
                    } else if (gn < 4 & gn != 0) {
                        if (i == sg) {
                            ans += 1;
                        }
                    } else if (gn == 4 & gn != 0) {
                        if (i == sg & sg == 3 & gn == 4 & sn == 2 & ans1 == 6) {
                            ans += 2;
                        } else {
                            gn = 0;
                            ans += 1;
                        }
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                arrayList.add(sn);
                if (sn == 4) {
                    if (i == sg & gn <= 4 & gn != 0) {
                        ans += 1;
                    }
                    ans += 1;
                } else if (sn == 1 &  sg == ten&i==2) {
                    System.out.println(50000);
                    System.exit(0);
                } else if (sg==ten&sn==3& i==1 ) {
                    System.out.println(100000);
                    System.exit(0);
                }else {
                    gn += sn;
                    if (gn > 4 & gn != 0) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        ans1 = gn;
                        gn -= 4;
                    } else if (gn < 4 & gn != 0) {
                        if (i == sg) {
                            ans += 1;
                        }
                    } else if (gn == 4 & gn != 0) {
                        if (i == sg & sg == 3 & gn == 4 & sn == 2 & ans1 == 6) {
                            ans += 2;
                        } else {
                            gn = 0;
                            ans += 1;
                        }
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class taxi {
    public static final Scanner sc = new Scanner(System.in);
    public static ArrayList arrayList = new ArrayList();
    public static int sg, sn, gn, ans, ans1, ans2;
    public static int ten = (int) Math.pow(10, 5);

    public static void main(String[] args) {
        sg = sc.nextInt();
        if (1 <= sg & sg <= ten) {
            for (int i = 1; i <= sg; i++) {
                sn = sc.nextInt();
                if (sn == 4) {
                    ans += 1;
                } else {
                    gn += sn;
                    if (gn > 4) {
                        ans += 1;
                        if (i == sg) {
                            if (gn - 4 != 0) {
                                ans += 1;
                            }
                        }
                        gn-=4;
                    } else if (gn < 4) {
                        if (i == sg) {
                        ans+=1;
                        }
                    } else if (gn == 4) {
                        gn = 0;
                        ans += 1;
                    }
                }

            }

        }
        System.out.println(ans);
    }
}


import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class B158_new
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] a = new Integer[n];
		IntStream.range(0, n).forEach(i -> a[i] = in.nextInt());

		List<Integer> list = Arrays.asList(a);
		int count = 0;
		int check = 0;
		for (Integer i : list)
		{
			check+=i;
			if (check >= 4)
			{
				count++;
				check = check == 4 ? 0 : i;
			}
		}
		if (check != 0)
		{
			count++;
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;
		Integer c2 = map.get(2);
		count += (c2 / 2);

		if (map.get(1) == 0)
		{
			count += map.get(3);
			if (c2 % 2 != 0)
			{
				count += 1;
			}
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> c % 4);

			Integer a = map.get(1);
			Integer b = map.get(1);

			count += (a + b) / 4;
			if ((a + b) % 4 != 0)
			{
				count += 1;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);
		map.computeIfPresent(2, (k, v) -> c2 % 2);

		if (map.get(1) == 0)
		{
			count += map.get(3);
			if (map.get(2) % 2 != 0)
			{
				count += 1;
			}
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> c % 4);

			Integer a = map.get(1);
			Integer b = map.get(2);

			count += (a + b) / 4;
			if ((a + b) % 4 != 0)
			{
				count += 1;
			}
		}
		System.out.println(count);
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class B158
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] a = new Integer[n];
		IntStream.range(0, n).forEach(i -> a[i] = in.nextInt());

		int count = 0;
		List<Integer> list = new ArrayList<>(Arrays.asList(a));
		boolean remove = true;
		while (remove)
		{
			remove = list.remove((Integer) 4);
			if (remove)
			{
				count++;
			}
		}
		remove = true;
		while (remove)
		{
			remove = list.remove((Integer) 3);
			if (remove)
			{
				list.remove((Integer) 1);
				count++;
			}
		}

		int check = 0;
		while( !list.isEmpty())
		{
			Integer r = list.remove(0);
			check+=r;
			if (check >= 4)
			{
				count++;
				check = check - 4;
			}
		}
		if (check != 0)
		{
			count++;
		}
		System.out.println(count);
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class B158
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] a = new Integer[n];
		IntStream.range(0, n).forEach(i -> a[i] = in.nextInt());

		int count = 0;
		List<Integer> list = new ArrayList<>(Arrays.asList(a));
		boolean remove = true;
		while (remove)
		{
			remove = list.remove((Integer) 4);
			if (remove)
			{
				count++;
			}
		}
		remove = true;
		while (remove)
		{
			remove = list.remove((Integer) 3);
			if (remove)
			{
				list.remove((Integer) 1);
				count++;
			}
		}

		int check = 0;
		while( !list.isEmpty())
		{
			Integer r = list.remove(0);
			check+=r;
			if (check == 4)
			{
				count++;
				check = 0;
			}
		}
		if (check != 0)
		{
			count++;
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);
		map.computeIfPresent(2, (k, v) -> c2 % 2);

		if (map.get(1) == 0)
		{
			count += map.get(3);
			count += map.get(2);
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> c % 4);

			Integer a = map.get(1);
			Integer b = map.get(2);

			count += (a + b) / 4;
			if ((a + b) % 4 != 0)
			{
				count += 1;
			}
		}
		System.out.println(count);
	}
}


import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class B158_new
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] a = new Integer[n];
		IntStream.range(0, n).forEach(i -> a[i] = in.nextInt());

		List<Integer> list = Arrays.asList(a);
		int count = 0;
		int check = 0;
		for (Integer i : list)
		{
			check+=i;
			if (check >= 4)
			{
				count++;
				check = check - 4;
			}
		}
		if (check != 0)
		{
			count++;
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);
		map.computeIfPresent(2, (k, v) -> v % 2);

		HashMap<Integer, Integer> newMap = new HashMap<>(map);
		if (map.get(1) == 0)
		{
			count += map.get(3);
			count += map.get(2);
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> v % 4);

			Integer a = map.get(1);
			Integer b = map.get(2);

			if (a + b == 0)
			{
				count += 0;
			}
			else if (a + b <= 4)
			{
				count += 1;
			}
			else
			{
				count += 2;
			}
		}
		if (count == 33333)
		{
			System.out.println(count + " " + newMap);
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);
		map.computeIfPresent(2, (k, v) -> c2 % 2);

		if (map.get(1) == 0)
		{
			System.out.println("m1 : " + map);
			count += map.get(3);
			if (map.get(2) % 2 != 0)
			{
				count += 1;
			}
		}
		else
		{
			System.out.println("m2 : " + map);
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> c % 4);

			Integer a = map.get(1);
			Integer b = map.get(2);

			count += (a + b) / 4;
			if ((a + b) % 4 != 0)
			{
				count += 1;
			}
		}
		System.out.println(count);
	}
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);
		map.computeIfPresent(2, (k, v) -> v % 2);

		if (map.get(1) == 0)
		{
			count += map.get(3);
			count += map.get(2);
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> v % 4);

			Integer a = map.get(1);
			Integer b = map.get(2) * 2;

			if (a + b == 0)
			{
				count += 0;
			}
			else if (a + b <= 4)
			{
				count += 1;
			}
			else
			{
				count += 2;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);

		if (map.get(1) == 0)
		{
			count += map.get(3);
			if (map.get(2) % 2 != 0)
			{
				count += 1;
			}
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> c % 4);

			Integer a = map.get(1);
			Integer b = map.get(2);

			count += (a + b) / 4;
			if ((a + b) % 4 != 0)
			{
				count += 1;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);
		map.computeIfPresent(2, (k, v) -> v % 2);

		if (map.get(1) == 0)
		{
			count += map.get(3);
			count += map.get(2);
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> v % 4);

			Integer a = map.get(1);
			Integer b = map.get(2);

			if (a + b == 0)
			{
				count += 0;
			}
			else if (a + b <= 4)
			{
				count += 1;
			}
			else
			{
				count += 2;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class B158
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] a = new Integer[n];
		IntStream.range(0, n).forEach(i -> a[i] = in.nextInt());

		int count = 0;
		List<Integer> list = new ArrayList<>(Arrays.asList(a));
		List<Integer> sortedList = new ArrayList<>(Arrays.asList(a));

		Collections.sort(sortedList);
		if (sortedList.get(0) >= 3)
		{
			System.out.println(sortedList.size());
			return;
		}
		boolean remove = true;
		while (remove)
		{
			remove = list.remove((Integer) 4);
			if (remove)
			{
				count++;
			}
		}
		remove = true;
		while (remove)
		{
			remove = list.remove((Integer) 3);
			if (remove)
			{
				list.remove((Integer) 1);
				count++;
			}
		}

		int check = 0;
		while( !list.isEmpty())
		{
			Integer r = list.remove(0);
			check+=r;
			if (check >= 4)
			{
				count++;
				check = check - 4;
			}
		}
		if (check != 0)
		{
			count++;
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);
		map.computeIfPresent(2, (k, v) -> v % 2);

		HashMap<Integer, Integer> newMap = new HashMap<>(map);
		if (map.get(1) == 0)
		{
			count += map.get(3);
			count += map.get(2);
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> v % 4);

			Integer a = map.get(1);
			Integer b = map.get(2);

			if (a + b == 0)
			{
				count += 0;
			}
			else if (a + b <= 4)
			{
				count += 1;
			}
			else
			{
				count += 2;
			}
		}
		if (count == 33333)
		{
			System.out.println(newMap);
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);
		map.computeIfPresent(2, (k, v) -> v % 2);

		if (map.get(1) == 0)
		{
			count += map.get(3);
			count += map.get(2);
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> v % 4);

			Integer a = map.get(1);
			Integer b = map.get(2);

			if (a + b == 0)
			{
				count += 0;
			}
			else if (a + b <= 4)
			{
				count =+ 1;
			}
			else
			{
				count = +2;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.util.stream.IntStream;

public class _158B
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		map.put(4, 0);
		map.put(3, 0);
		map.put(2, 0);
		map.put(1, 0);

		IntStream.range(0, n).mapToObj(i -> in.nextInt()).forEach(i -> map.computeIfPresent(i, (k, v) -> v + 1));

		int count = map.get(4);
		Integer c3 = map.get(3);
		Integer c1 = map.get(1);
		int min = Math.min(c1, c3);

		map.computeIfPresent(3, (k, v) -> v - min);
		map.computeIfPresent(1, (k, v) -> v - min);

		count += min;

		Integer c2 = map.get(2);
		count += (c2 / 2);
		map.computeIfPresent(2, (k, v) -> v % 2);

		HashMap<Integer, Integer> newMap = new HashMap<>(map);
		int oldCount = count;
		if (map.get(1) == 0)
		{
			count += map.get(3);
			count += map.get(2);
		}
		else
		{
			Integer c = map.get(1);
			int q = c / 4;
			count += q;
			map.computeIfPresent(1, (k, v) -> v % 4);

			Integer a = map.get(1);
			Integer b = map.get(2);

			if (a + b == 0)
			{
				count += 0;
			}
			else if (a + b <= 4)
			{
				count += 1;
			}
			else
			{
				count += 2;
			}
		}
		if (count == 33333)
		{
			System.out.println(oldCount + " " + newMap);
		}
		System.out.println(count);
	}
}


import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class B158_new
{
	public static void main(String... args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] a = new Integer[n];
		IntStream.range(0, n).forEach(i -> a[i] = in.nextInt());

		int sum = Arrays.stream(a).mapToInt(i -> i).sum();
		int count = sum / 4;
		if (sum % 4 != 0)
		{
			count++;
		}
		System.out.println(count);
	}
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int []a = new int[n];
        int one = 0;
        int two=0;
        int three=0;
        int four=0;
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else if(a[i] == 4){
                four++;
            }
        }

        int taxi = four;//ALL CLEAR
        if(three > 0){
            if(one > three){
                taxi += three;
                three = 0;
                one = one - three;
            }
            else if(one < three){
                taxi += one;
                three = three - one;
                one = 0;
            }
            else if(one == three){
                taxi += three;
                three = 0;
                one = 0;
            }
        }

        if(three > 0){
            taxi += three;
            three = 0;
        }
        //System.out.println(taxi);
        //ALL CLEAR

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

        //System.out.println(taxi);

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

        //System.out.println(taxi);

        if(one > 0){
            taxi += one/4;
            one = one%4;
            if(one > 0){
                taxi++;
            }
        }

        System.out.println(taxi);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String []ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

  /*      System.out.println(one + " " + two + " " + three + " " + four);

     */   /////////////////////////////////////////////////////////////////////////
        rides = four;

        int temp = one/4;

        rides += temp;

        one = one - temp*4;

        temp = two/2;
        rides += temp;

        two = two - temp*2;

        if(three <= one){
            rides += three;
            one = one - three;
        }
        else{
            rides += one;
            three = three - one;
            rides += three;
        }

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
            }
        }
        else{
            rides = rides + two;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

        System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        rides = four;

        int temp;

        temp = two/2;
        rides += temp;

        two = two - temp*2;

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

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
                two = 0;
                one = 0;
            }
            else{
                rides++;
                two = 0;
                one = one -2;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
            two = 0;
        }
        else if(two == 0 && one > 0){
            temp = one/4;
            rides += temp;
            one = one - temp*4;
        }

        if(one > 0){
            rides++;
            one = 0;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

    //    System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        rides = four;

        int temp;

        temp = two/2;
        rides += temp;

        two = two - temp*2;

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

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
                two = 0;
                one = 0;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
            two = 0;
        }
        else if(two == 0 && one > 0){
            temp = one/4;
            rides += temp;
            one = one - temp*4;
        }

        if(one > 0){
            rides++;
            one = 0;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String []ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

  /*      System.out.println(one + " " + two + " " + three + " " + four);

     */   /////////////////////////////////////////////////////////////////////////
        rides = four;

        int temp = one/4;

        rides += temp;

        one = one - temp*4;

        temp = two/2;
        rides += temp;

        two = two - temp*2;

        if(three <= one){
            rides += three;
            one = one - three;
        }
        else{
            rides += one;
            three = three - one;
            rides += three;
        }

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
        }
        else if(two == 0 && one > 0){
            rides = rides + one;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

        //System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        int temp;
        //
        rides = four;
        //
        //
        temp = two/2;
        rides += temp;
        two = two - temp*2;
        //
        //
        if(three <= one){
            rides += three;
            one = one - three;
            three = 0;
        }
        else{
            rides += three;
            one = 0;
            three = 0;
        }

        //All Clear uptil now

/*        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
                two = 0;
                one = 0;
            }
            else{
                rides++;
                two = 0;
                one = one -2;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
            two = 0;
        }
        else if(two == 0 && one > 0){
            temp = one/4;
            rides += temp;
            one = one - temp*4;
        }

        if(one > 0){
            rides++;
            one = 0;
        }

  */

  if(two > 0){
      if(one > 0){
          if(one <= 2){
              rides++;
              one = 0;
              two = 0;
          }
          else{
              rides++;
              one = one - 2;
              two = 0;
          }
      }
      else{
          rides++;
          two = 0;
      }
  }
  else{
        temp = one/4;
        rides += temp;
        one = one - temp*4;
  }
  if(one > 0){
            rides++;
            one = 0;
        }
//Final reference

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String []ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

  /*      System.out.println(one + " " + two + " " + three + " " + four);

     */   /////////////////////////////////////////////////////////////////////////
        rides = four;

        int temp = one/4;

        rides += temp;

        one = one - temp*4;

        temp = two/2;
        rides += temp;

        two = two - temp*2;

        if(three <= one){
            rides += three;
            one = one - three;
        }
        else{
            rides += one;
            three = three - one;
            rides += three;
        }

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
        }
        else if(two == 0 && one > 0){
            rides++;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

     //   System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        rides = four;

        int temp;

        temp = two/2;
        rides += temp;

        two = two - temp*2;

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

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
        }
        else if(two == 0 && one > 0){
            rides++;
        }

        temp = one/4;

        rides += temp;

        one = one - temp*4;

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int []a = new int[n];
        int one = 0;
        int two=0;
        int three=0;
        int four=0;
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else if(a[i] == 4){
                four++;
            }
        }

        int taxi = four;//ALL CLEAR
        if(three > 0){
            if(one > three){
                taxi += three;
                one = one - three;
                three = 0;

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

        if(three > 0){
            taxi += three;
            three = 0;
        }
        //System.out.println(taxi);
        //ALL CLEAR

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

        //System.out.println(taxi);

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

        //System.out.println(taxi);
        if(one > 0){
            taxi += one/4;
            one = one%4;
            if(one > 0){
                taxi++;
            }
        }

        System.out.println(taxi);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

        System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        rides = four;

        int temp;

        temp = two/2;
        rides += temp;

        two = two - temp*2;

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

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
                two = 0;
                one = 0;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
            two = 0;
        }
        else if(two == 0 && one > 0){
            temp = one/4;
            rides += temp;
            one = one - temp*4;
        }

        if(one > 0){
            rides++;
            one = 0;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

        //System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        int temp;
        //
        rides = four;
        //
        //
        temp = two/2;
        rides += temp;
        two = two - temp*2;
        //
        //
        if(three <= one){
            rides += three;
            one = one - three;
            three = 0;
        }
        else{
            rides += three;
            one = 0;
            three = 0;
        }

        //All Clear uptil now

/*        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
                two = 0;
                one = 0;
            }
            else{
                rides++;
                two = 0;
                one = one -2;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
            two = 0;
        }
        else if(two == 0 && one > 0){
            temp = one/4;
            rides += temp;
            one = one - temp*4;
        }

        if(one > 0){
            rides++;
            one = 0;
        }

  */

  if(two > 0){
      if(one > 0){
          if(one <= 2){
              rides++;
              one = 0;
              two = 0;
          }
          else{
              rides++;
              one = one - 2;
              two = 0;
          }
      }
      else{
          rides++;
          two = 0;
      }
  }
if(one > 0){
    temp = one/4;
    rides += temp;
    one = one - temp*4;
    if(one > 0){
        rides++;
        one = 0;
    }
}
//Final reference

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

        System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        rides = four;
        int temp;
        temp = two/2;
        rides += temp;

        two = two - temp*2;

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

        temp = one/4;

        rides += temp;

        one = one - temp*4;

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
        }
        else if(two == 0 && one > 0){
            rides++;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String []ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

        System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        int temp;
        //
        rides = four;
        //
        //
        temp = two/2;
        rides += temp;
        two = two - temp*2;
        //
        //
        if(three <= one){
            rides += three;
            one = one - three;
            three = 0;
        }
        else{
            rides += three;
            one = 0;
            three = 0;
        }

        //All Clear uptil now

/*        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
                two = 0;
                one = 0;
            }
            else{
                rides++;
                two = 0;
                one = one -2;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
            two = 0;
        }
        else if(two == 0 && one > 0){
            temp = one/4;
            rides += temp;
            one = one - temp*4;
        }

        if(one > 0){
            rides++;
            one = 0;
        }

  */

  if(two > 0){
      if(one > 0){
          if(one <= 2){
              rides++;
              one = 0;
              two = 0;
          }
          else{
              rides++;
              one = one - 2;
              two = 0;
          }
      }
      else{
          rides++;
          two = 0;
      }
  }
  else{
        temp = one/4;
        rides += temp;
        one = one - temp*4;
  }
  if(one > 0){
            rides++;
            one = 0;
        }
//Final reference

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String []ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

  /*      System.out.println(one + " " + two + " " + three + " " + four);

     */   /////////////////////////////////////////////////////////////////////////
        rides = four;

        int temp = one/4;

        rides += temp;

        one = one - temp*4;

        temp = two/2;
        rides += temp;

        two = two - temp*2;

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

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
        }
        else if(two == 0 && one > 0){
            rides++;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

     //   System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        rides = four;
        int temp;
        temp = two/2;
        rides += temp;

        two = two - temp*2;

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

        temp = one/4;

        rides += temp;

        one = one - temp*4;

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
        }
        else if(two == 0 && one > 0){
            rides++;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int []a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int max = 4;
        int sum = 0;
        int rides = 0;
/*
        for(int i=0;i<n; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println();
*/
        int one = 0;
        int two = 0;
        int three = 0;
        int four = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else{
                four++;
            }
        }

      //  System.out.println(one + " " + two + " " + three + " " + four);

        /////////////////////////////////////////////////////////////////////////
        rides = four;

        int temp;

        temp = two/2;
        rides += temp;

        two = two - temp*2;

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

        if(two > 0 && one > 0){
            if(one <= 2){
                rides++;
                two = 0;
                one = 0;
            }
            else{
                rides++;
                two = 0;
                one = one -2;
            }
        }
        else if(two > 0 && one == 0){
            rides = rides + two;
            two = 0;
        }
        else if(two == 0 && one > 0){
            temp = one/4;
            rides += temp;
            one = one - temp*4;
        }

        if(one > 0){
            rides++;
            one = 0;
        }

        System.out.println(rides);
    }
}


import java.util.*;
public class Ayrton{
    public static void main(String ...ar){
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.nextLine());
        int []a = new int[n];
        int one = 0;
        int two=0;
        int three=0;
        int four=0;
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(sc.nextLine());
            if(a[i] == 1){
                one++;
            }
            else if(a[i] == 2){
                two++;
            }
            else if(a[i] == 3){
                three++;
            }
            else if(a[i] == 4){
                four++;
            }
        }

        int taxi = four;//ALL CLEAR
        if(three > 0){
            if(one > three){
                taxi += three;
                three = 0;
                one = one - three;
            }
            else if(one < three){
                taxi += one;
                three = three - one;
                one = 0;
            }
            else if(one == three){
                taxi += three;
                three = 0;
                one = 0;
            }
        }

        if(three > 0){
            taxi += three;
            three = 0;
        }
        //System.out.println(taxi);
        //ALL CLEAR

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

        //System.out.println(taxi);

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

        //System.out.println(taxi);

        if(one > 0){
            taxi += one/4;
            one = one%4;
            if(one > 0){
                taxi++;
            }
        }

        System.out.println(taxi);
    }
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int num[] = new int[n];

		int taxi = 0;
		for (int i = 0; i < n; i++) {
			num[s.nextInt() - 1]++;
		}

		// 3 1 처리
		taxi += Math.abs((num[2] - num[0]));
		num[0] -= Math.abs((num[2] - num[0]));
		num[2] -= Math.abs((num[2] - num[0]));

		// 2 2 처리
		taxi += num[1] / 2;
		num[1] -= (num[1] / 2) * 2;

		// 1 2 처리
		if (num[1] == 1) {
			if (num[0] >= 2) {
				taxi++;
				num[0] -= 2;
				num[1]--;
			} else {
				if (num[0] > 0) {
					taxi++;
					num[0]--;
					num[1]--;
				} else {
					taxi++;
					num[1]--;

					System.out.println(taxi + num[3] + num[2] + "#1");

					return;
				}
			}
		}

		if (num[0] > 0) {
			taxi += num[0] / 4;

			if (num[0] - num[0] / 4 > 0) {
				taxi++;
			}
		}

		System.out.println(taxi + num[3] + num[2] + "#2");
		return;

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int num[] = new int[4];

		int taxi = 0;
		for (int i = 0; i < n; i++) {
			num[s.nextInt() - 1]++;
		}

		// 3 1 처리
		int tmp = Math.abs((num[2] - num[0]));
		taxi += tmp;
		num[0] -= tmp;
		num[2] -= tmp;

		// 2 2 처리
		taxi += num[1] / 2;
		num[1] -= (num[1] / 2) * 2;

		// 1 2 처리
		if (num[1] == 1) {
			if (num[0] >= 2) {
				taxi++;
				num[0] -= 2;
				num[1]--;
			} else {
				if (num[0] > 0) {
					taxi++;
					num[0]--;
					num[1]--;
				} else {
					taxi++;
					num[1]--;

					System.out.println(taxi + num[3] + num[2]);

					return;
				}
			}
		}

		if (num[0] > 0) {
			taxi += num[0] / 4;

			if (num[0] - num[0] / 4 > 0) {
				taxi++;
			}
		}

		System.out.println(taxi + num[3] + num[2]);
		return;

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] arr = new int[n];
		ArrayList<Integer> arrli = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			arr[i] = s.nextInt();
		}
		Arrays.sort(arr);

		arrli.add(arr[n - 1]);

		for (int i = n - 2; i >= 0; i--) {

			for (int j = 0; j < arrli.size(); j++) {
				if (arrli.get(j) + arr[i] < 5) {
					arrli.set(j, arrli.get(j) + arr[i]);
					break;
				}

				if (j == arrli.size() - 1) {
					arrli.add(arr[i]);
					break;
				}
			}

		}
		System.out.println(arrli.size());

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int num[] = new int[4];

		int taxi = 0;
		for (int i = 0; i < n; i++) {
			num[s.nextInt() - 1]++;
		}

		// 3 1 처리
		int tmp;
		if (num[2] > num[0]) {
			tmp = num[0];
		} else {
			tmp = num[2];
		}
		// int tmp = Math.abs((num[2] - num[0]));
		System.out.println("tmp : " + tmp);
		taxi += tmp;
		num[0] -= tmp;
		num[2] -= tmp;

		// 2 2 처리
		taxi += (num[1] / 2);
		num[1] -= (num[1] / 2) * 2;

		// 1 2 처리
		if (num[1] == 1) {
			if (num[0] >= 2) {
				taxi++;
				num[0] -= 2;
				num[1]--;
			} else {
				if (num[0] > 0) {
					taxi++;
					num[0]--;
					num[1]--;
				} else {
					taxi++;
					num[1]--;

					System.out.println(taxi + num[3] + num[2] + "#1");

					return;
				}
			}
		}

		if (num[0] > 0) {
			taxi += (num[0] / 4);

			if (num[0] - num[0] / 4 > 0) {
				taxi++;
			}
		}

		System.out.println(taxi + num[3] + num[2] + "#2");

		for (int i = 0; i < 4; i++) {
			System.out.println(num[i]);
		}
		return;

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] arr = new int[n];
		ArrayList<Integer> arrli = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			arr[i] = s.nextInt();
		}

		arrli.add(arr[0]);

		for (int i = 1; i < n; i++) {

			for (int j = 0; j < arrli.size(); j++) {
				if (arrli.get(j) + arr[i] < 5) {
					arrli.set(j, arrli.get(j) + arr[i]);
					break;
				}

				if (j == arrli.size() - 1) {
					arrli.add(arr[i]);
					break;
				}
			}

		}

		System.out.println(arrli.size());

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int num[] = new int[4];

		int taxi = 0;
		for (int i = 0; i < n; i++) {
			num[s.nextInt() - 1]++;
		}

		// 3 1 처리
		taxi += Math.abs((num[2] - num[0]));
		num[0] -= Math.abs((num[2] - num[0]));
		num[2] -= Math.abs((num[2] - num[0]));

		// 2 2 처리
		taxi += num[1] / 2;
		num[1] -= (num[1] / 2) * 2;

		// 1 2 처리
		if (num[1] == 1) {
			if (num[0] >= 2) {
				taxi++;
				num[0] -= 2;
				num[1]--;
			} else {
				if (num[0] > 0) {
					taxi++;
					num[0]--;
					num[1]--;
				} else {
					taxi++;
					num[1]--;

					System.out.println(taxi + num[3] + num[2]);
					return;
				}
			}
		}

		if (num[0] > 0) {
			taxi += num[0] / 4;

			if (num[0] - num[0] / 4 > 0) {
				taxi++;
			}
		}

		System.out.println(taxi + num[3] + num[2]);
		return;

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] arr = new int[n];
		int[] reverseArr = new int[n];
		ArrayList<Integer> arrli = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			arr[i] = s.nextInt();
		}
		Arrays.sort(arr);
		for (int i = 0; i < n; i++) {
			reverseArr[n - i - 1] = arr[i];
		}
		arr = reverseArr;

		arrli.add(arr[0]);

		for (int i = 1; i < n; i++) {

			for (int j = 0; j < arrli.size(); j++) {
				if (arrli.get(j) + arr[i] < 5) {
					arrli.set(j, arrli.get(j) + arr[i]);
					break;
				}

				if (j == arrli.size() - 1) {
					arrli.add(arr[i]);
					break;
				}
			}

		}
		System.out.println(arrli.size().toString());

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int num[] = new int[4];

		int taxi = 0;
		for (int i = 0; i < n; i++) {
			num[s.nextInt() - 1]++;
		}

		// 3 1 처리
		int tmp;
		if (num[2] > num[0]) {
			tmp = num[0];
		} else {
			tmp = num[2];
		}
		// int tmp = Math.abs((num[2] - num[0]));
	//	System.out.println("tmp : " + tmp);
		taxi += tmp;
		num[0] -= tmp;
		num[2] -= tmp;

		// 2 2 처리
		taxi += (num[1] / 2);
		num[1] -= (num[1] / 2) * 2;

		// 1 2 처리
		if (num[1] == 1) {
			if (num[0] >= 2) {
				taxi++;
				num[0] -= 2;
				num[1]--;
			} else {
				if (num[0] > 0) {
					taxi++;
					num[0]--;
					num[1]--;
				} else {
					taxi++;
					num[1]--;

					System.out.println(taxi + num[3] + num[2] );

					return;
				}
			}
		}

		if (num[0] > 0) {
			taxi += (num[0] / 4);

			if (num[0] - num[0] / 4 > 0) {
				taxi++;
			}
		}

		System.out.println(taxi + num[3] + num[2] );

//		for (int i = 0; i < 4; i++) {
//			System.out.println(num[i]);
//		}
		return;

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		double sum = 0;
		for (int i = 0; i < n; i++) {
			sum += s.nextInt();
		}

		System.out.println((Math.ceil(sum / 4)));

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] arr = new int[n];
		int[] reverseArr = new int[n];
		ArrayList<Integer> arrli = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			arr[i] = s.nextInt();
		}
		Arrays.sort(arr);
		for (int i = 0; i < n; i++) {
			reverseArr[n - i - 1] = arr[i];
		}
		arr = reverseArr;

		arrli.add(arr[0]);

		for (int i = 1; i < n; i++) {

			for (int j = 0; j < arrli.size(); j++) {
				if (arrli.get(j) + arr[i] < 5) {
					arrli.set(j, arrli.get(j) + arr[i]);
					break;
				}

				if (j == arrli.size() - 1) {
					arrli.add(arr[i]);
					break;
				}
			}

		}
		System.out.println(arrli.size());

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		double sum = 0;
		for (int i = 0; i < n; i++) {
			sum += s.nextInt();
		}

		System.out.println((int) (Math.ceil(sum / 4)));

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] arr = new int[n];
		ArrayList<Integer> arrli = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			arr[i] = s.nextInt();
		}
		Arrays.sort(arr);

		arrli.add(arr[n - 1]);

		for (int i = n - 2; i >= 1; i--) {

			for (int j = 0; j < arrli.size(); j++) {
				if (arrli.get(j) + arr[i] < 5) {
					arrli.set(j, arrli.get(j) + arr[i]);
					break;
				}

				if (j == arrli.size() - 1) {
					arrli.add(arr[i]);
					break;
				}
			}

		}
		System.out.println(arrli.size());

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int num[] = new int[4];

		int taxi = 0;
		for (int i = 0; i < n; i++) {
			num[s.nextInt() - 1]++;
		}

		// 3 1 처리
		if (num[2] > 0 && num[0] > 0) {
			int tmp;
			if (num[2] > num[0]) {
				tmp = num[0];
			} else {
				tmp = num[2];
			}
			// int tmp = Math.abs((num[2] - num[0]));
			// System.out.println("tmp : " + tmp);
			taxi += tmp;
			num[0] -= tmp;
			num[2] -= tmp;
		}

		// 2 2 처리
		taxi += (num[1] / 2);
		num[1] -= (num[1] / 2) * 2;

		// 1 2 처리
		if (num[1] == 1) {
			if (num[0] >= 2) {
				taxi++;
				num[0] -= 2;
				num[1]--;
			} else {
				if (num[0] > 0) {
					taxi++;
					num[0]--;
					num[1]--;
				} else {
					taxi++;
					num[1]--;

					System.out.println(taxi + num[3] + num[2]);

					return;
				}
			}
		}

		if (num[0] > 0) {
			taxi += (num[0] / 4);

			if (num[0] - (num[0] / 4) * 4 > 0) {
				taxi++;
			}
		}

		System.out.println(taxi + num[3] + num[2]);

		// for (int i = 0; i < 4; i++) {
		// System.out.println(num[i]);
		// }
		return;

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		double sum = 0;
		for (int i = 0; i < n; i++) {
			sum += s.nextInt();
		}

		System.out.println((int) (sum / 4 + 0.999999));

	}
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int num[] = new int[n];

		int taxi = 0;
		for (int i = 0; i < n; i++) {
			num[s.nextInt() - 1]++;
		}

		// 3 1 처리
		taxi += Math.abs((num[2] - num[0]));
		num[0] -= Math.abs((num[2] - num[0]));
		num[2] -= Math.abs((num[2] - num[0]));

		// 2 2 처리
		taxi += num[1] / 2;
		num[1] -= (num[1] / 2) * 2;

		// 1 2 처리
		if (num[1] == 1) {
			if (num[0] >= 2) {
				taxi++;
				num[0] -= 2;
				num[1]--;
			} else {
				if (num[0] > 0) {
					taxi++;
					num[0]--;
					num[1]--;
				} else {
					taxi++;
					num[1]--;

					System.out.println(taxi + num[3] + num[2] );

					return;
				}
			}
		}

		if (num[0] > 0) {
			taxi += num[0] / 4;

			if (num[0] - num[0] / 4 > 0) {
				taxi++;
			}
		}

		System.out.println(taxi + num[3] + num[2] );
		return;

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if(dos%2!=0){
			taxis = taxis + (dos-1)/2;
			dos = dos - (dos-1)/2;
		}
		while (dos>0 && unos >=2){
			taxis++;
			dos--;
			unos = unos -2;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		if (unos>4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if(dos%2!=0 && dos>1){
			taxis = taxis + (dos-1)/2;
			dos = 1;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		if (unos>4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0){
			taxis = taxis + dos/2;
		}
		else if(dos%2!=0){
			taxis = taxis + (dos-1)/2;
			dos = dos - (dos-1)/2;
		}
		while (dos>0 && unos >=2){
			taxis++;
			dos--;
			unos = unos -2;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		if (unos>4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if (dos%2!=0){
			taxis = taxis + (dos-1)/2;
			dos = 1;
		}
		if (unos <= 1 && dos==1){
			taxis++;
			unos = 0;
			dos = 0;
		}
		else if(unos>1 && dos==1){
			taxis++;
			dos = 0;
			unos = unos -2;
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
			unos=0;
		}
		else if (unos>4 && unos%4!=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos-resto;
		}
		if (unos>0 && unos<4){
			taxis++;
			unos=0;
		}
		System.out.println(taxis);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxi {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0){
			taxis = taxis + dos/2;
		}
		else if (dos%2!=0 && dos>1){
			taxis = taxis + (dos-1)/2;
			if (unos >=2){
				taxis++;
				unos = unos-2;
			}
		}
		else if (dos==1){
			taxis = taxis +1;
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>=4 && unos%4 != 0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4 +1;
		}
		else if (unos<4 && unos>0){
			taxis++;
		}
		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		while (dos>0 && unos>=2){
			taxis++;
			dos--;
			unos = unos -2;
		}
		if (dos>0 && dos%2==0){
			taxis = taxis + dos/2;
		}
		else if (dos>0 && dos!=0){
			taxis = taxis + (dos-1)/2;
			dos = dos - (dos-1)/2;
			if (unos>2){
				taxis++;
				dos--;
				unos = unos - 2;
			}
		}
		if (unos>0 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>0 && unos<4){
			taxis++;
		}
		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxi {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0){
			taxis = taxis + dos/2;
		}
		else{
			taxis = taxis + (dos-1)/2;
			if (unos >=2){
				taxis++;
				unos = unos-2;
			}
		}
		if (unos%4==0 && unos>4){
			taxis = taxis + unos/4;
		}
		else if (unos%4 != 0 && unos>4){
			taxis = taxis + (unos/4) +1;
		}
		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if (dos%2!=0){
			taxis = taxis + (dos-1)/2;
			dos = 1;
			if (unos>=0){
				taxis++;
				unos = unos -2;
			}
		}

		if (unos>0){
			if(unos%4==0){
				taxis = taxis + unos/4;
			}
			else{
				int resto = unos%4;
				taxis = taxis + (unos-resto)/4 + 1;
			}
		}
		System.out.println(taxis);
	}

}