using System;
using System.Collections.Generic;
namespace dragons
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string[] str = Console.ReadLine().Split(' ');
			int strength = int.Parse(str[0]), n = int.Parse(str[0]);
			System.Collections.Generic.SortedSet<Dragon> dragons = new System.Collections.Generic.SortedSet<Dragon> ();
			for (int i = 1; i <= n; i++)
			{
				str = Console.ReadLine().Split(' ');
				dragons.Add (new Dragon (int.Parse(str[0]), int.Parse(str[1])));
			}

			foreach (Dragon dragon in dragons)
			{
				if (strength > dragon.Strength)
				{
					strength+=dragon.Bonus;
				}
				else
				{
					Console.WriteLine("NO");
					Environment.Exit(0); //telos
				}
			}
			Console.WriteLine("YES");
		}
	}

	 class Dragon : IComparable<Dragon>
	{
		public int Strength {get; private set;}
		public int Bonus {get; private set;}

		public Dragon (int strength, int bonus)
		{
			this.Strength = strength;
			this.Bonus = bonus;
		}

		int IComparable<Dragon>.CompareTo (Dragon other)
		{
			return this.Strength.CompareTo(other.Strength);
		}

	}

}


using System;
using System.Collections.Generic;
namespace dragon
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string[] str = Console.ReadLine().Split(' ');
			int strength = int.Parse(str[0]), n = int.Parse(str[0]);
			Dragon[] dragons = new Dragon[n];
			for (int i = 0; i < n; i++)
			{
				str = Console.ReadLine().Split(' ');
				dragons[i] = new Dragon (int.Parse(str[0]), int.Parse(str[1]));
			}
			SortArray(dragons);
			foreach (Dragon dragon in dragons)
			{
				if (strength > dragon.Strength)
				{
					strength+=dragon.Bonus;
				}
				else
				{
					Console.WriteLine("NO");
					Environment.Exit(0); //telos
				}
			}
			Console.WriteLine("YES");
		}

		public static void SortArray<T> (T[] arr) where T:IComparable<T>
		{
			for (int i = 1; i < arr.Length; i++)
			{
				for (int j = arr.Length-1; j >= i; j--)
				{
					if (arr [j - 1].CompareTo(arr[j]) > 0)
					{
						T temp = arr [j - 1];
						arr [j - 1] = arr [j];
						arr [j] = temp;
					}
				}
			}
		}

	}

	 class Dragon : IComparable<Dragon>
	{
		public int Strength {get; private set;}
		public int Bonus {get; private set;}

		public Dragon (int strength, int bonus)
		{
			this.Strength = strength;
			this.Bonus = bonus;
		}

		int IComparable<Dragon>.CompareTo (Dragon other)
		{
			return this.Strength.CompareTo(other.Strength);
		}

	}

}


using System;

namespace codeforces
{
    class Program
    {

        static void Main(string[] args)
        {

            string[] sn = Console.ReadLine().Split();
            int s = int.Parse(sn[0]);
            int n = int.Parse(sn[1]);
            string[][] dragons = new string[n][];
            for (int i = 0; i < n; i++)
            {
                dragons[i] = Console.ReadLine().Split();
                s += (s >= int.Parse(dragons[i][0]) ? int.Parse(dragons[i][1]) : -s-1);
                if (s == -1) break;
            }
            Console.WriteLine(s==-1?"NO":"YES");

        }
    }
}


using System;

namespace codeforces
{
    class Program
    {

        static void Main(string[] args)
        {

            string[] sn = Console.ReadLine().Split();
            int s = int.Parse(sn[0]);
            int n = int.Parse(sn[1]);
            string[][] dragons = new string[n][];
            int[,] drags = new int[n, 2];
            for (int i = 0; i < n; i++)
            {
                dragons[i] = Console.ReadLine().Split();
                drags[i, 0] = int.Parse(dragons[i][0]);
                drags[i, 1] = int.Parse(dragons[i][1]);

            }
            for (int i = 0; i < n - 1; i++)
                for (int j = i + 1; j < n; j++)

                    if (drags[i, 0] > drags[j, 0])
                    {
                        for (int k = 0; k < 2; k++)
                        {
                            int a = drags[i, k];
                            drags[i, k] = drags[j, k];
                            drags[j, k] = a;
                        }
                    }
            for (int i = 0; i < n; i++)
            {
                s += (s > (drags[i, 0]) ? (drags[i, 1]) : -s - 1);
                if (s == -1) break;
            }
            Console.WriteLine(s == -1 ? "NO" : "YES");

        }
    }
}


using System;

namespace codeforces
{
    class Program
    {

        static void Main(string[] args)
        {

            string[] sn = Console.ReadLine().Split();
            int s = int.Parse(sn[0]);
            int n = int.Parse(sn[1]);
            string[][] dragons = new string[n][];
            int[,] drags = new int[n, 2];
            for (int i = 0; i < n; i++)
            {
                dragons[i] = Console.ReadLine().Split();
                drags[i, 0] = int.Parse(dragons[i][0]);
                drags[i, 1] = int.Parse(dragons[i][1]);

            }
            for (int i = 0; i < n - 1; i++)
                for (int j = i + 1; j < n; j++)

                    if (drags[i, 0] > drags[j, 0])
                    {
                        for (int k = 0; k < 2; k++)
                        {
                            int a = drags[i, k];
                            drags[i, k] = drags[j, k];
                            drags[j, k] = a;
                        }
                    }
            for (int i = 0; i < n; i++)
            {
                s += (s >= (drags[i, 0]) ? (drags[i, 1]) : -s - 1);
                if (s == -1) break;
            }
            Console.WriteLine(s == -1 ? "NO" : "YES");

        }
    }
}


using System;
class Test{
    static void Main(){
        string [] line = Console.ReadLine().Split();
        int s = int.Parse(line[0]);
        int n = int.Parse(line[1]);
        int [] a = new int[n];
        int [] p = new int[n];
        for(int i = 0; i < n; i++){
            line = Console.ReadLine().Split();
            a[i] = int.Parse(line[0]);
            p[i] = int.Parse(line[1]);
        }
        Array.Sort(a, p);
        for(int j = 0; j < n; j++){
            if(s > a[j]){
                s += p[j];
            }else{
                Console.WriteLine("NO");
                return;
            }
        }
        Console.WriteLine("YES");
    }
}


using System;
class Test{
    static void Main(){
        string [] line = Console.ReadLine().Split();
        int s = int.Parse(line[0]);
        int n = int.Parse(line[1]);
        for(int i = 0; i < n; i++){
            line = Console.ReadLine().Split();
            if(s > int.Parse(line[0])){
                s += int.Parse(line[1]);
            }else{
                Console.WriteLine("NO");
                return;
            }
        }
        Console.WriteLine("YES");
    }
}


using System;
using System.Linq;

public class Program
{
    static public void Main ()
    {
        int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        int hp = input[0];
        int n = input[1];
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++) {
            input = Console.ReadLine().Split().Select(j => int.Parse(j)).ToArray();
            x[i] = input[0];
            y[i] = input[1];
        }
        Array.Sort(x, y);
        int ans = 1;
        for (int i = 0; i < n; i++) {
            if (hp <= x[i]) {
                ans = 0;
                break;
            } else {
                hp += y[i];
            }
        }
        if (ans > 0) {
            Console.WriteLine("YES");
        } else {
            Console.WriteLine("NO");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace A01_10_12
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] st = Regex.Split(Console.ReadLine(), " ");
            int s = int.Parse(st[0]);
            int n = int.Parse(st[1]);
            int[,] m = new int[n, 2];
            int i = 0;
            for (i = 0; i < n; i++)
            {
                st = Regex.Split(Console.ReadLine(), " ");
                m[i, 0] = int.Parse(st[0]);
                m[i, 1] = int.Parse(st[1]);
            }
            for (i = 0; i < n; i++)
            {
                int min = 100000;
                int mn = -1;
                for (int j = i; j < n; j++)
                    if (m[j, 0] < min)
                    {
                        mn = j;
                        min = m[j, 0];
                    }
                int t = m[i, 0];
                m[i, 0] = m[mn, 0];
                m[mn, 0] = t;
                t = m[i, 1];
                m[i, 1] = m[mn, 1];
                m[mn, 1] = t;
            }
            for (i = 0; i < n; i++)
            {
                if (s <= m[i, 0])
                {
                    Console.WriteLine("NO");
                    break;
                }
                else
                    s += m[i, 1];
                if(s>20000)
                {
                    Console.WriteLine("YES");
                    break;
                }
            }
            if(i==n)
                Console.WriteLine("YES");
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace CodeForces
{
	internal class Template
	{
		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
			//Console.SetIn(new StreamReader(@"C:\CodeForces\input.txt"));
			new Template().Solve();
		}

		private void Solve()
		{
			var s = cin.NextInt();
			var n = cin.NextInt();
			var x = new int[n];
			var y = new int[n];
			for (var i = 0; i < n; i++)
			{
				x[i] = cin.NextInt();
				y[i] = cin.NextInt();
			}
			for (var i = 1; i < n; i++)
			{
				for (var j = i; j > 0; j--)
				{
					if (x[j] < x[j - 1])
					{
						var temp = x[j];
						x[j] = x[j - 1];
						x[j - 1] = temp;
						temp = y[j];
						y[j] = y[j - 1];
						y[j - 1] = temp;
					}
				}
			}
			for (var i = 0; i < n; i++)
			{
				if (s <= x[i])
				{
					Console.WriteLine("NO");
					return;
				}
				s += y[i];
			}
			Console.WriteLine("YES");
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = new[] { ' ' };

		public string Next()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;

class Program
{

    static void Main(string[] args)
    {
        string reader = Console.ReadLine();

        string[] spliter = reader.Split(' ');
        int KiritoStrength = Convert.ToInt32(spliter[0]);
        int dragonscount = Convert.ToInt32(spliter[1]);

        string output = "NO";

        for (int i = 0; i < dragonscount; i++)
        {
            reader = Console.ReadLine();

            spliter = reader.Split(' ');
            int DragonStrength = Convert.ToInt32(spliter[0]);
            int bonus = Convert.ToInt32(spliter[1]);

            if (KiritoStrength > DragonStrength)
            {
                KiritoStrength += bonus;
                output = "YES";
                continue;
            }
            else
            {
                output = "NO";
                break;
            }

        }

        Console.WriteLine(output);
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication22
{
    class Program
    {
        static void Main(string[] args)
        {
            int s, n; int[] Input0 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); s = Input0[0]; n = Input0[1];
            string output = "NO";
            List<int[]> Data = new List<int[]>();
            for (int i = 0; i < n; i++)
            {
                Data.Add(Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray());
            }
            Data = Data.OrderBy(x => x.First()).ToList();

            for (int i = 0; i < n; i++)
            {
                int x = Data[i].First() , y = Data[i].Last();
                if (s > x) { s += y; output = "YES"; }
                else { output = "NO"; break; }
            }

            Console.WriteLine(output);
        }
        private static IEnumerable<string> Perms(string source)
        {
            if (source.Length == 1) return new List<string>() { source };

            var perm = from l in source
                       from _x in Perms(string.Join("",
source.Where(x => x != l)
))
                       select l + _x; ;
            return perm;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] reader = Console.ReadLine().Split(' ');
        int strength = int.Parse(reader[0]), n = int.Parse(reader[1]);
        List<string> Data = new List<string>();
        for (int i = 0; i < n; i++)
        {
            Data.Add(Console.ReadLine());
        }

        string output = "YES";

        for (int i = 0; i < Data.Count; i++)
        {
            string[] spliter = Data[i].Split(' ');
            int x = int.Parse(spliter[0]), y = int.Parse(spliter[1]);

            if (strength >= x) { strength += y; }
            else { output = "NO"; break; }
        }

        Console.WriteLine(output);

    }

    private static IEnumerable<string> Permutate(string source)
    {
        if (source.Length == 1) return new List<string> { source };

        var permutations = from c in source
                           from p in Permutate(new String(source.Where(x => x != c).ToArray()))
                           select c + p;

        return permutations;
    }

}

//private static IEnumerable<string> Permutate(string source)
//{
//    if (source.Length == 1) return new List<string> { source };

//    var permutations = from c in source
//                       from p in Permutate(new String(source.Where(x => x != c).ToArray()))
//                       select c + p;

//    return permutations;
//}


def delt(l,n,x):
    i=0
    while i<n:
        try:
            l.remove(n)
            i=i+1
        except:
            return

def deleteAll(l,n):
    while True:
        try:
            l.remove(n)
        except:
            return
# 1 1 2 2 2  2 3 3 4 4 4
n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
#w.sort()
all=0
mini3=w.count('3')
mini1=w.count('1')
w.sort()
if mini1!=0:
    if mini3==mini1 :
        deleteAll(w,'3')
        deleteAll(w,'1')
        all=all+mini1
    else:
        if mini3>mini1:
          deleteAll(w,'1')
          w=w[0:w.index('3')]+w[w.index('3')+mini1:]
          all=all+mini1
        else:
          deleteAll(w,'3')
          delt(w,mini3,'1')
          w=w[:w.index('1')]+w[w.index('1')+mini3:]
          all=all+mini3

i=0
c=w
k=int(c[i])

while i<len(c):
    if k<4:
        i=i+1
        k=k+int(c[i])
    elif k==4:
        all=all+1
        if i+1==len(c):
            break
        else:
          k=int(c[i+1])

          i=i+1

    else:
        all=all+1
        k=int(c[i+1])

#1 1 1 2 2 3 3 4 4

print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
mini4=w.count('4')
mini3=w.count('3')
mini2=w.count('2')
mini1=w.count('1')
all=mini4
if mini3==mini1 :
    if mini3!=0:
        all=all+mini3+int(mini2)/2+int(mini2)%2

    else:
        if ((int(mini1)+2*int(mini2))%4)>0:
            all=1
        else:
            all=all+mini2/2+mini2%2

elif mini3>mini1:
  #  4 4 3 3  2 2 1 1 1
   # 2   5  3    1 3
    all=all+mini3+int(mini2)/2+int(mini2)%2
else:
    if mini3==0:
        if mini2==0:
          all=all+mini1/4+mini1%4
        elif ((int(mini1)+2*int(mini2))%4)>0:
          all=1
        else:
          all=all+int(mini2)/2+int(mini1)/4+   (int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4

    else:
         all=all+mini3+int(mini2)/2+int(mini2)%2+(mini1-mini3)/4+(mini1-mini3)%4
print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
mini4=w.count('4')
mini3=w.count('3')
mini2=w.count('2')
mini1=w.count('1')
all=mini4
if mini3==mini1 :
    if mini3!=0:
        all=all+mini3+int(mini2)/2+int(mini2)%2

    else:
        if ((int(mini1)+2*int(mini2))%4)>0:
            all=1
        else:
            if mini2%2==0:
                all=all+mini2/2
            else:
                all=all+mini2/2+1

elif mini3>mini1:
  #  4 4 3 3  2 2 1 1 1
   # 2   5  3    1 3
    all=all+mini3+int(mini2)/2+int(mini2)%2
else:
    if mini3==0:
        if mini2==0:
            if mini1%4==0:
                all=all+mini1/4
            else:
                all=all+mini1/4+1

        elif ((int(mini1)+2*int(mini2))%4)>0:
          all=1
        else:
          all=all+int(mini2)/2+int(mini1)/4+   (int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4

    else:
         all=all+mini3+int(mini2)/2+int(mini2)%2+(mini1-mini3)/4+(mini1-mini3)%4
print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
w.sort()
i=0
c=w
k=int(c[i])
all=0
while i<len(w):
    if k<4:
        i=i+1
        k=k+int(c[i])
    elif k==4:
        all=all+1
        k=0
        i=i+1
    else:
        all=all+1+(n-i)
        break

#1 1 2 2 3 3 4 4

print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
mini4=w.count('4')
mini3=w.count('3')
mini2=w.count('2')
mini1=w.count('1')
all=mini4
if mini3==mini1 :
    if mini3!=0:
        all=all+mini3+int(mini2)/2+int(mini2)%2

    else:
        if mini2%2==0:
            all=all+mini2/2
        else:
            all=all+mini2/2+1

elif mini3>mini1:
  #  4 4 3 3  2 2 1 1 1
   # 2   5  3    1 3
    all=all+mini3+int(mini2)/2+int(mini2)%2
else:
    if mini3==0:
        if mini2==0:
            if mini1%4==0:
                all=all+mini1/4
            else:
                all=all+mini1/4+1

        elif ((int(mini1)+2*int(mini2))%4)>0:
          all=1
        else:
          all=all+int(mini2)/2+int(mini1)/4+   (int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4

    else:
         all=all+mini3+int(mini2)/2+int(mini2)%2+(mini1-mini3)/4+(mini1-mini3)%4
print all


def delt(l,n,x):
    i=0
    while i<n:
        try:
            l.remove(n)
            i=i+1
        except:
            return

def deleteAll(l,n):
    while True:
        try:
            l.remove(n)
        except:
            return
# 1 1 2 2 2  2 3 3 4 4 4
n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
#w.sort()
all=0
mini3=w.count('3')
mini1=w.count('1')
w.sort()
if mini1!=0:
    if mini3==mini1 :
        deleteAll(w,'3')
        deleteAll(w,'1')
        all=all+mini1
    else:
        if mini3>mini1:
          deleteAll(w,'1')
          w=w[0:w.index('3')]+w[w.index('3')+mini1:]
          all=all+mini1
        else:
          deleteAll(w,'3')
          delt(w,mini3,'1')
          w=w[:w.index('1')]+w[w.index('1')+mini3:]
          all=all+mini3

i=0
c=w
k=int(c[i])

while i<len(c):
    if k<4:
        if i+1==len(c):
            break
        else:
            i=i+1
            k=k+int(c[i])

    elif k==4:
        all=all+1
        if i+1==len(c):
            break
        else:
          k=int(c[i+1])

          i=i+1

    else:
        all=all+1
        if i+1==len(c):
            break
        else:
          k=int(c[i+1])

#1 1 1 2 2 3 3 4 4
if k>4:
    all=all+1
if k<4:
    print 1
else:
    print all


def delt(l,n,x):
    i=0
    while i<n:
        try:
            l.remove(n)
            i=i+1
        except:
            return

def deleteAll(l,n):
    while True:
        try:
            l.remove(n)
        except:
            return
# 1 1 2 2 2  2 3 3 4 4 4
n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
#w.sort()
all=0
mini3=w.count('3')
mini1=w.count('1')
w.sort()
if mini1!=0:
    if mini3==mini1 :
        deleteAll(w,'3')
        deleteAll(w,'1')
        all=all+mini1
    else:
        if mini3>mini1:
          deleteAll(w,'1')
          w=w[0:w.index('3')]+w[w.index('3')+mini1:]
          all=all+mini1
        else:
          deleteAll(w,'3')
          delt(w,mini3,'1')
          w=w[:w.index('1')]+w[w.index('1')+mini3:]
          all=all+mini3

i=0
c=w
k=int(c[i])

while i<len(c):
    if k<4:
        if i+1==len(c):
            break
        else:
            i=i+1
            k=k+int(c[i])

    elif k==4:
        all=all+1
        if i+1==len(c):
            break
        else:
          k=int(c[i+1])

          i=i+1

    else:
        all=all+1
        k=int(c[i+1])

#1 1 1 2 2 3 3 4 4
if k<4:
    print 1
else:
    print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
w.sort()

i=0
j=n-1
all=0
while i<=j:
    if int(w[j])==4:
        all=all+1
        j=j-1
    else:
        if int(w[j])+int(w[i])==4:
            i=i+1
            j=j-1
            all=all+1
        elif int(w[j])+int(w[i])>4:
            j=j-1
            all=all+1
        else:
            if int(w[j])+int(w[i])==3:
                if int(w[i])!=int(w[i+1]):
                    j=j-2
                    all=all+1
                else:
                    j=j-1
                    i=i+2
                    all=all+1
            else:

                i=i+4
                all=all+1

print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
w.sort()

i=0
j=n-1
all=0
while i<=j:
    if int(w[j])==4:
        all=all+1
        j=j-1
    else:
        if int(w[j])+int(w[i])==4:
            i=i+1
            j=j-1
            all=all+1
        elif int(w[j])+int(w[i])>4:
            j=j-1
            all=all+1
        else:
            if int(w[j])+int(w[i])==3:
                j=j-2
                all=all+1
            else:
                i=i+4
                all=all+1

print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
mini4=w.count('4')
mini3=w.count('3')
mini2=w.count('2')
mini1=w.count('1')
all=mini4
if mini3==mini1 :
    if mini3!=0:
      all=all+mini3+int(mini2)/2+int(mini2)%2
    elif ((int(mini1)+2*int(mini2))%4)>0:

        all=1
    else:
        if mini1==0:
            all=all+mini2/2+mini2%2
        else:
          all=all+(int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4

elif mini3>mini1:
  #  4 4 3 3  2 2 1 1 1
   # 2   5  3    1 3
    all=all+mini3+int(mini2)/2+int(mini2)%2
else:
    if mini3==0:
        if mini2==0:
          all=all+mini1/4+mini1
        elif ((int(mini1)+2*int(mini2))%4)>0:
          all=1
        else:
          all=all+int(mini2)/2+int(mini1)/4+   (int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4

    else:
         all=all+mini3+int(mini2)/2+int(mini2)%2+(mini1-mini3)/4+(mini1-mini3)%4
print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
mini4=w.count('4')
mini3=w.count('3')
mini2=w.count('2')
mini1=w.count('1')
all=mini4
if mini3==mini1 :
    if mini3!=0:
        all=all+mini3+int(mini2)/2+int(mini2)%2

    else:
        if ((int(mini1)+2*int(mini2))%4)>0:
            all=1
        else:
            all=all+mini2/2+mini2%2

elif mini3>mini1:
  #  4 4 3 3  2 2 1 1 1
   # 2   5  3    1 3
    all=all+mini3+int(mini2)/2+int(mini2)%2
else:
    if mini3==0:
        if mini2==0:
            if mini1%4==0:
                all=all+mini1/4
            else:
                all=all+mini1/4+1

        elif ((int(mini1)+2*int(mini2))%4)>0:
          all=1
        else:
          all=all+int(mini2)/2+int(mini1)/4+   (int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4

    else:
         all=all+mini3+int(mini2)/2+int(mini2)%2+(mini1-mini3)/4+(mini1-mini3)%4
print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
mini4=w.count('4')
mini3=w.count('3')
mini2=w.count('2')
mini1=w.count('1')
all=mini4
if mini3==mini1 :
    if mini3!=0:
        all=all+mini3+int(mini2)/2+int(mini2)%2

    else:
        if ((int(mini1)+2*int(mini2))%4)>0:
            all=1
        else:
            all=all+mini2/2+mini2%2

elif mini3>mini1:
  #  4 4 3 3  2 2 1 1 1
   # 2   5  3    1 3
    all=all+mini3+int(mini2)/2+int(mini2)%2
else:
    if mini3==0:
        if mini2==0:

          all=all+mini1/4+1

        elif ((int(mini1)+2*int(mini2))%4)>0:
          all=1
        else:
          all=all+int(mini2)/2+int(mini1)/4+   (int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4

    else:
         all=all+mini3+int(mini2)/2+int(mini2)%2+(mini1-mini3)/4+(mini1-mini3)%4
print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
mini4=w.count('4')
mini3=w.count('3')
mini2=w.count('2')
mini1=w.count('1')
all=mini4
if mini3==mini1 :
    if mini3!=0:
      all=all+mini3+int(mini2)/2+int(mini2)%2
    elif ((int(mini1)+2*int(mini2))%4)>0:

        all=1
    else:
        if mini1==0:
            all=all+mini2/2+mini2%2
        else:
          all=all+(int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4

elif mini3>mini1:
  #  4 4 3 3  2 2 1 1 1
   # 2   5  3    1 3
    all=all+mini3+int(mini2)/2+int(mini2)%2
else:
    if mini3==0:
        if ((int(mini1)+2*int(mini2))%4)>0:
          all=1
        else:
          all=all+int(mini2)/2+int(mini1)/4+   (int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4

    else:
         all=all+mini3+int(mini2)/2+int(mini2)%2+(mini1-mini3)/4+(mini1-mini3)%4
print all


n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
mini4=w.count('4')
mini3=w.count('3')
mini2=w.count('2')
mini1=w.count('1')
all=mini4
if mini3==mini1 :

    all=all+mini3+int(mini2)/2+int(mini2)%2

elif mini3>mini1:

    all=all+mini3+int(mini2)/2+int(mini2)%2
else:
    if mini3==0:
        all=all+int(mini2)/2+int(mini1)/4+   (int(mini1)%4+2*(int(mini2)%2))/4 +  (int(mini1)%4+2*(int(mini2)%2))%4
    else:
         all=all+mini3+int(mini2)/2+int(mini2)%2+(mini1-mini3)/4+(mini1-mini3)%4
print all


def delt(l,n,x):
    i=0
    while i<n:
        try:
            l.remove(n)
            i=i+1
        except:
            return

def deleteAll(l,n):
    while True:
        try:
            l.remove(n)
        except:
            return
# 1 1 2 2 2  2 3 3 4 4 4
n=int(raw_input())
p=raw_input().split(" ")
w=list(p)
#w.sort()
all=0
mini3=w.count('3')
mini1=w.count('1')
w.sort()
if mini1!=0 and mini3!=0:
    if mini3==mini1 :
        deleteAll(w,'3')
        deleteAll(w,'1')
        all=all+mini1
    else:
        if mini3>mini1:
          deleteAll(w,'1')
          w=w[0:w.index('3')]+w[w.index('3')+mini1:]
          all=all+mini1
        else:
          deleteAll(w,'3')
          delt(w,mini3,'1')
          w=w[:w.index('1')]+w[w.index('1')+mini3:]
          all=all+mini3
c=w
if len(c)==0:
    print all
else:
    i=0

    k=int(c[i])
    while i<len(c):
            if k<4:
                if i+1==len(c):
                    break
                else:
                    i=i+1
                    k=k+int(c[i])

            elif k==4:
                all=all+1
                if i+1==len(c):
                    break
                else:
                  k=int(c[i+1])

                  i=i+1

            else:
                all=all+1
                if i+1==len(c):
                    break
                else:
                  k=int(c[i+1])

        #1 1 1 2 2 3 3 4 4
    if k>4:
        all=all+1
        print all
    elif k<4:
        print all+1
    else:
        print all


import math
def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    #print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    #print 'four', taxi
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
        #print "three > one",taxi
    elif one > three:
        taxi = taxi + three
        one = one - three
        three =0
        #print "three < one", taxi
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
        #print "three = one", taxi
    #print 'three',three
    taxi = taxi + three
    #print "three -->",taxi

    if two > 0:
        taxi = taxi + one/2
        #print one/2
        #print one, two

        two = two - one/2
        one = one - (one / 2) * 2
        #print one,two

    #print "two one pairing-->",taxi, one , two
    if two == 0 and one == 0:
        print taxi
        exit(0)

    if two*2 + one > 4:
        taxi = taxi + int(math.floor((two * 2+ one)/4)+1)
    else:
        taxi = taxi + int(math.floor((two * 2 + one) / 4) +1)
    print  taxi

if __name__ == '__main__':
  main()


import math
def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    #print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    #print 'four', taxi
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
        #print "three > one",taxi
    elif one > three:
        taxi = taxi + three
        one = one - three
        three =0
        #print "three < one", taxi
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
        #print "three = one", taxi
    #print 'three',three
    taxi = taxi + three
    #print "three -->",taxi

    if two > 0:
        taxi = taxi + one/2
        one = one -one/2
        two = two - one/2

    #print "two one pairing-->",taxi, one , two
    if two == 0 and one == 0:
        print taxi
        exit(0)

    if two + one > 4:
        taxi = taxi + int(math.floor((two + one)/4))
    else:
        taxi = taxi + int(math.floor((two + one) / 4)+1)
    print  taxi

if __name__ == '__main__':
  main()


import math
def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    #print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    #print 'four', taxi
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
        #print "three > one",taxi
    elif one > three:
        taxi = taxi + three
        one = one - three
        three =0
        #print "three < one", taxi
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
        #print "three = one", taxi
    #print 'three',three
    taxi = taxi + three
    #print "three -->",taxi

    if two > 0:
        taxi = taxi + one/2
        one = one - (one / 2) * 2
        two = two - one/2
        #print one,two

    #print "two one pairing-->",taxi, one , two
    if two == 0 and one == 0:
        print taxi
        exit(0)

    if two + one > 4:
        taxi = taxi + int(math.floor((two + one)/4))
    else:
        taxi = taxi + int(math.floor((two + one) / 4)+1)
    print  taxi

if __name__ == '__main__':
  main()


import math
def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    #print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    #print 'four', taxi
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
        #print "three > one",taxi
    elif one > three:
        taxi = taxi + three
        one = one - three
        three =0
        #print "three < one", taxi
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
        #print "three = one", taxi
    #print 'three',three
    taxi = taxi + three
    #print "three -->",taxi

    if two > 0:
        taxi = taxi + one/2
        #print one/2
        #print one, two

        two = two - one/2
        one = one - (one / 2) * 2
        #print one,two

    #print "two one pairing-->",taxi, one , two
    if two == 0 and one == 0:
        print taxi
        exit(0)

    if two + one > 4:
        taxi = taxi + int(math.floor((two + one)/4))
    else:
        taxi = taxi + int(math.floor((two + one) / 4)+1)
    print  taxi

if __name__ == '__main__':
  main()


def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    #print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    #print 'four', taxi
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
        #print "three > one",taxi
    elif one > three:
        taxi = taxi + three
        one = three - one
        three =0
        #print "three < one", taxi
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
        #print "three = one", taxi
    #print 'three',three
    taxi = taxi + three
    #print "three -->",taxi

    taxi = taxi + one/2
    one = one -one/2
    two = two - one/2

    #print "two one pairing-->",taxi, one , two

    taxi = taxi + (two + one)/4 +1
    print  taxi

if __name__ == '__main__':
  main()


import math
def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    #print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    #print 'four', taxi
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
        #print "three > one",taxi
    elif one > three:
        taxi = taxi + three
        one = one - three
        three =0
        #print "three < one", taxi
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
        #print "three = one", taxi
    #print 'three',three
    taxi = taxi + three
    #print "three -->",taxi

    if two > 0:
        taxi = taxi + one/2
        one = one - (one / 2) * 2
        two = two - one/2
        print one,two

    #print "two one pairing-->",taxi, one , two
    if two == 0 and one == 0:
        print taxi
        exit(0)

    if two + one > 4:
        taxi = taxi + int(math.floor((two + one)/4))
    else:
        taxi = taxi + int(math.floor((two + one) / 4)+1)
    print  taxi

if __name__ == '__main__':
  main()


import math
def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    #print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    #print 'four', taxi
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
        #print "three > one",taxi
    elif one > three:
        taxi = taxi + three
        one = three - one
        three =0
        #print "three < one", taxi
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
        #print "three = one", taxi
    #print 'three',three
    taxi = taxi + three
    #print "three -->",taxi

    taxi = taxi + one/2
    one = one -one/2
    two = two - one/2

    #print "two one pairing-->",taxi, one , two
    if two == 0 and one == 0:
        print taxi
        exit(0)

    if two + one > 4:
        taxi = taxi + int(math.floor((two + one)/4))
    else:
        taxi = taxi + int(math.floor((two + one) / 4)+1)
    print  taxi

if __name__ == '__main__':
  main()


def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
    elif one > three:
        taxi = taxi + three
        one = three - one
        three =0
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
    taxi = taxi + three
    taxi = taxi + two
    taxi = taxi + (two + one)/4
    print taxi

if __name__ == '__main__':
  main()


def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    #print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
        #print taxi
    elif one > three:
        taxi = taxi + three
        one = three - one
        three =0
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
    taxi = taxi + three
    #print taxi

    taxi = taxi + two/2
    two = two - two/2

    taxi = taxi + (two + one)/4 +1
    print taxi

if __name__ == '__main__':
  main()


def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    if sum(m) % 4 ==0:
        print sum(m) / 4
    else:
        print sum(m)/ 4 + 1

if __name__ == '__main__':
  main()


import math
def main():
    k = input()
    l = map(int, raw_input().split())
    m= list(l)
    # if sum(m) % 4 ==0:
    #     print sum(m) / 4
    # else:
    #     print sum(m)/ 4 + 1
    #print m
    four =  m.count(4)
    three = m.count(3)
    two = m.count(2)
    one = m.count(1)

    taxi = 0 + four
    #print 'four', taxi
    if three > one:
        taxi = taxi + one
        three = three - one
        one = 0
        #print "three > one",taxi
    elif one > three:
        taxi = taxi + three
        one = one - three
        three =0
        #print "three < one", taxi
    elif one == three:
        taxi = taxi + three
        three = 0
        one =0
        #print "three = one", taxi
    #print 'three',three
    taxi = taxi + three
    #print "three -->",taxi

    if two > 0:
        taxi = taxi + one/2
        #print one/2
        #print one, two

        two = two - one/2
        one = one - (one / 2) * 2
        #print one,two

    #print "two one pairing-->",taxi, one , two
    if two == 0 and one == 0:
        print taxi
        exit(0)

    if (two*2 + one )% 4==0:
        taxi = taxi + int(math.floor((two * 2 + one) / 4))

    else:
        taxi = taxi + int(math.floor((two * 2 + one) / 4) + 1)
    print  taxi

if __name__ == '__main__':
  main()


n = input()
s = map(int,raw_input().split())
for x in range(len(s)):
    for y in range(x+1,len(s)):
	if (s[x]+s[y])==4:
	    del s[y]
	    break
print len(s)


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    if a1>=a2:
	a1-=a2
	flag+=a2
	if a1<=4 and a1!=0:
	   flag+=1
	else:
	   flag+=a1%4+a1/4
    else:
	a2-=a1
	flag+=a1+a2
print flag


n = input()
s = map(int,raw_input().split())
s.sort(reverse=True)
x=0
while x<len(s):
    for y in range(x+1,len(s)):
	if (s[x]+s[y])<4:
	    s[x] = s[x]+s[y]
	    x=-1
	    del s[y]
	    break
	elif s[x]+s[y]==4:
	    s[x]=s[x]+s[y]
	    del s[y]
	    break
    x+=1
print len(s)


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    af=a1/2+a2
    flag+=af/2
    if a1%2!=0:
	flag+=(a1%2)
    else:
	flag+=af%2
if sum(one)+sum(two)+sum(three) <= 4 and sum(one)+sum(two)+sum(three)!=0:
    print 1+len(four)
else:
    print flag


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    if a1>=a2:
	a1-=a2
	flag+=a2+(a1/4)+(a1%4)
    else:
	a2-=a1
	flag+=a1+a2
print flag


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    af=a1/2+a2
    flag+=af/2
    if a1%2!=0:
	af=(af%2)+1
	flag+=af
    else:
	flag+=af%2
if sum(one)+sum(two)+sum(three) <= 4 and sum(one)+sum(two)+sum(three)!=0:
    print 1+len(four)
else:
    print flag


n = input()
s = map(int,raw_input().split())
x=0
while x<len(s):
    for y in range(x+1,len(s)):
	if (s[x]+s[y])<4:
	    s[x] = s[x]+s[y]
	    x=-1
	    del s[y]
	    break
	elif s[x]+s[y]==4:
	    s[x]=s[x]+s[y]
	    del s[y]
	    break
    x+=1
print len(s)


n = input()
s = map(int,raw_input().split())
s.sort(reverse=True)
x=0
if len(list(dict.fromkeys(s)))!=1:
    while x<len(s):
        for y in range(x+1,len(s)):
	    if (s[x]+s[y])<4:
	        s[x] = s[x]+s[y]
	        x=-1
	        del s[y]
	        break
    	    elif s[x]+s[y]==4:
	    	s[x]=s[x]+s[y]
	   	del s[y]
	    	break
        x+=1
    print len(s)
else:
    if sum(s)%4==0:
        print sum(s)/4
    else:
	print sum(s)/4+1


n = input()
s = map(int,raw_input().split())
if sum(s)%4!=0:
    print (sum(s)/4)+1
else:
    print sum(s)/4


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    af=a1/2+a2
    flag+=af/2
    if a1%2!=0:
	af%=2+1
	flag+=af
if sum(s) <= 4:
    print 1
else:
    print flag


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    if a1>=a2:
	a1-=a2
	flag+=a2
	if a1<=4:
	   flag+=1
	else:
	   flag+=a1%4+a1/4
    else:
	a2-=a1
	flag+=a1+a2
print flag


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    if a1>=a2:
	a1-=a2
	flag+=a2
	if a1<=4 and a1!=0:
	   flag+=1
	else:
	   flag+=a1%4+a1/4
    else:
	a2-=a1
	flag+=a1+a2
if sum(s) <= 4:
    print 1
else:
    print flag


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    af=a1/2+a2
    flag+=af/2
    if a1%2!=0:
	af=(af%2)+1
	flag+=af
if sum(s) <= 4:
    print 1
else:
    print flag


n = input()
s = map(int,raw_input().split())
s.sort(reverse=True)
x=0
if len(list(dict.fromkeys(s)))!=1:
    while x<len(s):
        for y in range(x+1,len(s)):
	    if (s[x]+s[y])<4:
	        s[x] = s[x]+s[y]
	        x=-1
	        del s[y]
	        break
    	    elif s[x]+s[y]==4:
	    	s[x]=s[x]+s[y]
	   	del s[y]
	    	break
        x+=1
    print len(s)
else:
    if s[0]>=3:
	print n
    else:
        if sum(s)%4==0:
            print sum(s)/4
        else:
	    print sum(s)/4+1


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    af=a1/2+a2
    flag+=af/2
    if a1%2!=0:
	af=(af%2)+1
	flag+=af
    else:
	flag+=af%2
if sum(s) <= 4:
    print 1
else:
    print flag


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    af=a1/2+a2
    flag+=af/2
    if a1%2!=0:
	af=(af%2)+1
	flag+=af
    else:
	flag+=af%2
if sum(one)+sum(two)+sum(three) <= 4:
    print 1+len(four)
else:
    print flag


n = input()
s = map(int,raw_input().split())
s.sort(reverse=True)
x=0
if max(s)!=1:
    while x<len(s):
        for y in range(x+1,len(s)):
	    if (s[x]+s[y])<4:
	        s[x] = s[x]+s[y]
	        x=-1
	        del s[y]
	        break
    	    elif s[x]+s[y]==4:
	    	s[x]=s[x]+s[y]
	   	del s[y]
	    	break
        x+=1
    print len(s)
else:
    if sum(s)%4==0:
        print sum(s)/4
    else:
	print sum(s)/4+1


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    af=a1/2+a2
    flag+=af/2
    if a1%2!=0:
	af=(af%2)+1
	flag+=af
    else:
	flag+=1
if sum(s) <= 4:
    print 1
else:
    print flag


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    if a1>=a2:
	if a1+a2*2>4:
	    a1-=a2
	    flag+=a2
	    if a1<=4 and a1!=0:
	        flag+=1
	    else:
	        flag+=a1%4+a1/4
	else:
	    flag+=1
    else:
	a2-=a1
	flag+=a1+a2
if sum(s) <= 4:
    print 1
else:
    print flag


n = input()
s = map(int,raw_input().split())
one = []
two = []
three = []
four = []
flag=0
for x in range(n):
    if s[x] == 1:
	one.append(s[x])
    elif s[x] == 2:
	two.append(s[x])
    elif s[x] == 3:
        three.append(s[x])
    elif s[x] == 4:
        four.append(s[x])
flag+=len(four)+(len(two)/2)
a1=len(one)
a2=len(two)%2
a3=len(three)
if a3>=a1:
    a3-=a1
    flag+=a1+a3+a2
else:
    a1-=a3
    flag+=a3
    af=a1/2+a2
    flag+=af/2
    if a1%2!=0:
	af=(af%2)
	flag+=af
    else:
	flag+=af%2
if sum(one)+sum(two)+sum(three) <= 4 and sum(one)+sum(two)+sum(three)!=0:
    print 1+len(four)
else:
    print flag


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2 + groups_2%2
groups_1 %= 4
groups_2 %= 2
if groups_1 == 3 and groups_2%2 == 1 and groups_3 != 0:
    taxi += groups_3
elif groups_1 == 3 and groups_2%2 == 0 and groups_3 != 0:
    if groups_3 >= 3:
        taxi += groups_3
    else:
        taxi += groups_3 +1
elif groups_3 == 0 and groups_2 == 0 and groups_1 !=0:
    taxi += 1
else:
    taxi += groups_3
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2
groups_1 %= 4
groups_2 %= 2

if groups_1 == 0:
    taxi += groups_3 + groups_2%2
elif groups_1 == 2:
    if groups_2%2 != 0:
        taxi += 1
    else:
        if groups_3 > groups_1:
            taxi += groups_3
        else:
            taxi += groups_3 + 1
else:
    if groups_3 > groups_1:
        taxi += groups_3 + groups_2%2
    else:
        taxi += groups_3 + 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2 + groups_2%2
groups_1 %= 4
if groups_1 == 3 and groups_2%2 == 1 and groups_3 != 0:
    taxi += groups_3
elif groups_1 == 3 and groups_2%2 == 0 and groups_3 != 0:
    if groups_3 >= 3:
        taxi += groups_3
    else:
        taxi += groups_3 +1
elif groups_3 == 0 and groups_1 !=0:
    taxi += 1
else:
    taxi += groups_3
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2 + groups_2%2
groups_1 %= 4
if groups_1 == 3 and groups_2%2 == 1 and groups_3 != 0:
    taxi += groups_3
elif groups_1 == 3 and groups_2%2 == 0 and groups_3 != 0:
    if groups_3 >= 3:
        taxi += groups_3
    else:
        taxi += groups_3 +1
else:
    taxi += groups_3
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2
groups_1 %= 4
groups_2 %= 2

if groups_1 == 0:
    taxi += groups_3 + groups_2%2
elif groups_1 == 2:
    if groups_2%2 != 0 and groups_3 == 0:
        taxi += 1
    else:
        if groups_3 > groups_1:
            taxi += groups_3
        else:
            taxi += groups_3 + 1
else:
    if groups_3 > groups_1:
        taxi += groups_3 + groups_2%2
    else:
        taxi += groups_3 + 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2 + groups_2%2
groups_1 %= 4
if groups_1 == 3 and groups_2%2 == 1 and groups_3 != 0:
    taxi += groups_3
elif groups_1 == 3 and groups_2%2 == 0 and groups_3 != 0:
    if groups_3 >= 3:
        taxi += groups_3
    else:
        taxi += groups_3 +1
elif groups_3 == 0 and groups_2 == 0 and groups_1 !=0:
    taxi += 1
else:
    taxi += groups_3
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2 + groups_2%2

if groups_3 == 0 and groups_2 == 0 and groups_1 !=0:
    taxi += 1

groups_1 %= 4
groups_2 %= 2
if groups_1 == 3 and groups_2%2 == 1 and groups_3 != 0:
    taxi += groups_3
elif groups_1 == 3 and groups_2%2 == 0 and groups_3 != 0:
    if groups_3 >= 3:
        taxi += groups_3
    else:
        taxi += groups_3 +1

else:
    if groups_3 >= 2:
        taxi += groups_3
    elif groups_3 < groups_1:
        taxi += groups_3 + 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
    if n == 1:
        taxi += 1
        break

    elif group == 4:
        taxi += 1

    elif group == 3:
        groups_3 += 1

    elif group == 2:
        groups_2 += 1

    else :
        groups_1 += 1

if groups_3 >= groups_1:
    taxi += groups_3 + groups_2/2
else :
    taxi += groups_3 + (groups_1 - groups_3)/4 + groups_2/2

if (groups_1%4 > 0 or groups_2%2 >0) :
    taxi += groups_1%4/3 + groups_2%2

print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2
groups_1 %= 4
groups_2 %= 2

if groups_1 == 0:
    taxi += groups_3 + groups_2%2
elif groups_1 == 2:
    groups_2 += 1
    if groups_2 == 2 or groups_2 == 1:
        taxi += 1
else:
    if groups_3 > groups_1:
        taxi += groups_3 + groups_2%2
    else:
        taxi += groups_3 + 1


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2 + groups_2%2
groups_1 %= 4
groups_2 %= 2
if groups_1 == 3 and groups_2%2 == 1 and groups_3 != 0:
    taxi += groups_3
elif groups_1 == 3 and groups_2%2 == 0 and groups_3 != 0:
    if groups_3 >= 3:
        taxi += groups_3
    else:
        taxi += groups_3 +1
elif groups_3 == 0 and groups_2 == 0 and groups_1 !=0:
    taxi += 1
else:
    if groups_3 >= 2:
        taxi += groups_3
    else:
        taxi += 2
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2 + groups_2%2
groups_1 %= 4
if groups_1 == 3 and groups_2%2 == 1 and groups_3 != 0:
    taxi += groups_3
elif groups_1 == 3 and groups_2%2 == 0 and groups_3 != 0:
    if groups_3 >= 3:
        taxi += groups_3
    else:
        taxi += groups_3 +1

print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
    if n == 1:
        taxi += 1
        break

    elif group == 4:
        taxi += 1

    elif group == 3:
        groups_3 += 1

    elif group == 2:
        groups_2 += 1

    else :
        groups_1 += 1

if groups_3 >= groups_1:
    taxi += groups_3 + groups_2/2
    groups_1 = 0
else :
    taxi += groups_3 + (groups_1 - groups_3)/4 + groups_2/2
    import math
    math.fabs()
    groups_1 = fabs(groups_1 - groups_3)

if (groups_1%4 ==3 and groups_2%2 >0) :
    taxi += 2
elif groups_1%4 !=0 or groups_2%2 != 0:
    taxi += 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
    if group == 4:
        taxi += 1

    elif group == 3:
        groups_3 += 1

    elif group == 2:
        groups_2 += 1

    else :
        groups_1 += 1

if n == 1:
    taxi += 1
elif groups_3 >= groups_1:
    taxi += groups_3 + groups_2/2
else :
    taxi += groups_3 + (groups_1 - groups_3)/4 + groups_2/2

if (groups_1%4 > 0 and groups_2%2 >0) :
    taxi += groups_1%4/3 + groups_2%2

print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
    if n == 1:
        taxi += 1
        break

    elif group == 4:
        taxi += 1

    elif group == 3:
        groups_3 += 1

    elif group == 2:
        groups_2 += 1

    else :
        groups_1 += 1

if groups_3 >= groups_1:
    taxi += groups_3 + groups_2/2
    groups_1 = 0
else :
    taxi += groups_3 + (groups_1 - groups_3)/4 + groups_2/2
    import math
    groups_1 = math.fabs(groups_1 - groups_3)

if (groups_1%4 ==3 and groups_2%2 >0) :
    taxi += 2
elif groups_1%4 !=0 or groups_2%2 != 0:
    taxi += 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2
groups_1 %= 4
groups_2 %= 2

if groups_1 == 0:
    taxi += groups_3 + groups_2%2
elif groups_1 == 2:
    if (groups_2%2 != 0 and groups_3 == 0)or (groups_2%2 == 0 and groups_3 == 0) :
        taxi += 1
    else:
        if groups_3 > groups_1:
            taxi += groups_3
        else:
            taxi += groups_3 + (groups_1 - groups_3)
else:
    if groups_3 > groups_1:
        taxi += groups_3 + groups_2%2
    else:
        taxi += groups_3 + (groups_1 - groups_3)
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2
groups_1 %= 4
groups_2 %= 2

if groups_1 == 0:
    taxi += groups_3 + groups_2%2
elif groups_1 == 2:
    if groups_2%2 != 0 and groups_3 == 0:
        taxi += 1
    else:
        if groups_3 > groups_1:
            taxi += groups_3
        else:
            taxi += groups_3 + (groups_1 - groups_3)
else:
    if groups_3 > groups_1:
        taxi += groups_3 + groups_2%2
    else:
        taxi += groups_3 + 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2 + groups_2%2
groups_1 %= 4
groups_2 %= 2
if groups_1 == 3 and groups_2%2 == 1 and groups_3 != 0:
    taxi += groups_3
elif groups_1 == 3 and groups_2%2 == 0 and groups_3 != 0:
    if groups_3 >= 3:
        taxi += groups_3
    else:
        taxi += groups_3 +1
elif groups_3 == 0 and groups_2 == 0 and groups_1 !=0:
    taxi += 1
else:
    if groups_3 >= 2:
        taxi += groups_3
    else:
        taxi += groups_1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2
groups_1 %= 4
groups_2 %= 2

if groups_1 == 0:
    taxi += groups_3 + groups_2%2
elif groups_1 == 2:
    if (groups_2%2 != 0 and groups_3 == 0)or (groups_2%2 == 0 and groups_3 == 0) :
        taxi += 1
    else:
        if groups_3 > groups_1:
            taxi += groups_3
        else:
            taxi += groups_3 + (groups_1 - groups_3)
else:
    if groups_3 > groups_1:
        taxi += groups_3 + groups_2%2
    elif groups_3 == groups_1:
        taxi += groups_3 + groups_2%2
    else:
        taxi += groups_3 + 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
    if n == 1:
        taxi += 1
        break

    elif group == 4:
        taxi += 1

    elif group == 3:
        groups_3 += 1

    elif group == 2:
        groups_2 += 1

    else :
        groups_1 += 1

if groups_3 >= groups_1:
    taxi += groups_3 + groups_2/2
else :
    taxi += groups_3 + (groups_1 - groups_3)/4 + groups_2/2

if (groups_1%4 ==3 and groups_2%2 >0) :
    taxi += 2
elif groups_1 !=0 or groups_2%2 != 0:
    taxi += 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
    if n == 1:
        taxi += 1
        break

    elif group == 4:
        taxi += 1

    elif group == 3:
        groups_3 += 1

    elif group == 2:
        groups_2 += 1

    else :
        groups_1 += 1

if groups_3 >= groups_1:
    taxi += groups_3 + groups_2/2
else :
    taxi += groups_3 + (groups_1 - groups_3)/4 + groups_2/2

if (groups_1%4 == 3 and groups_2%2 >0) :
    taxi += 2
elif groups_1%4 !=0 or groups_2%2 != 0:
    taxi += 1

print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2
groups_1 %= 4
groups_2 %= 2

if groups_1 == 0:
    taxi += groups_3 + groups_2%2
elif groups_1 == 2:
    if groups_2%2 != 0:
        taxi += 1
    else:
        if groups_3 > groups_1:
        taxi += groups_3
    else:
        taxi += groups_3 + 1
else:
    if groups_3 > groups_1:
        taxi += groups_3 + groups_2%2
    else:
        taxi += groups_3 + 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2 + groups_2%2

if groups_3 == 0 and groups_2 == 0 and groups_1 !=0:
    taxi += 1

groups_1 %= 4
groups_2 %= 2
if groups_1 == 3 and groups_2%2 == 1 and groups_3 != 0:
    taxi += groups_3
elif groups_1 == 3 and groups_2%2 == 0 and groups_3 != 0:
    if groups_3 >= 3:
        taxi += groups_3
    else:
        taxi += groups_3 +1

else:
    if groups_3 >= 2:
        taxi += groups_3
    else:
        taxi += groups_3 + (groups_1/groups_1)
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2
groups_1 %= 4
groups_2 %= 2

if groups_1 == 0:
    taxi += groups_3 + groups_2%2
elif groups_1 == 2:
    if (groups_2%2 != 0 and groups_3 == 0)or (groups_2%2 == 0 and groups_3 == 0) :
        taxi += 1
    else:
        if groups_3 > groups_1:
            taxi += groups_3
        else:
            taxi += groups_3 + (groups_1 - groups_3)
else:
    if groups_3 > groups_1:
        taxi += groups_3 + groups_2%2
    else:
        taxi += groups_3 + 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
    if group == 4:
        taxi += 1

    elif group == 3:
        groups_3 += 1

    elif group == 2:
        groups_2 += 1

    else :
        groups_1 += 1

if n == 1 and group != 4:
    taxi += 1
elif groups_3 >= groups_1:
    taxi += groups_3 + groups_2/2
else :
    taxi += groups_3 + (groups_1 - groups_3)/4 + groups_2/2

if (groups_1%4 > 0 or groups_2%2 >0) :
    taxi += groups_1%4/3 + groups_2%2

print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2
groups_1 %= 4
groups_2 %= 2

if groups_1 == 0:
    taxi += groups_3 + groups_2%2
elif groups_1 == 2:
    groups_2 += 1
    if groups_2 == 2 or groups_2 == 1:
        taxi += 1
else:
    if groups_3 > groups_1:
        taxi += groups_3 + groups_2%2
    else:
        taxi += groups_3 + 1
print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2

groups_2 %= 2
groups_1 %= 4

if groups_2 == 1:
    if groups_1 == 3:
        if groups_3 >= 3:
            taxi += groups_3
        else:
            taxi += groups_3 + 1
    else:
        taxi += groups_3 + 1
else:
    if groups_1 > 0:
        if groups_3 >= groups_1:
            taxi += groups_3
        else:
            taxi += groups_3 + 1
    else:
        taxi += groups_3

print taxi


n = int(raw_input())
groups = map(int, raw_input().split())
taxi = 0
groups_3 = 0
groups_2 = 0
groups_1 = 0

for group in groups:
  if group == 4:
      taxi += 1

  elif group == 3:
      groups_3 += 1

  elif group == 2:
      groups_2 += 1

  else :
      groups_1 += 1

taxi += groups_1/4 + groups_2/2

groups_2 %= 2
groups_1 %= 4

if groups_2 == 1:
    if groups_1 == 3:
        if groups_3 >= 3:
            taxi += groups_3 + 1
        elif groups_3 == 0:
            taxi += 2
        else:
            taxi += groups_3 + 1
    else:
        taxi += groups_3 + 1
else:
    if groups_1 > 0:
        if groups_3 >= groups_1:
            taxi += groups_3
        else:
            taxi += groups_3 + 1
    else:
        taxi += groups_3

print taxi


input()
ss=map(int,raw_input().split())
a1=ss.count(1)
a2=ss.count(2)
a3=ss.count(3)
a4=ss.count(4)
x=0
if a1<a3:
    x==0
else:
    x=a1-a3
print a4+a3+((2*x)+a2+3)/4


n=input()
c=map(int,raw_input().split())
v=len(c)
b=c.count(4)
c.sort()
i=0
while b>i:
    c.pop()
    i+=1
z=sum(c)
print v if c.count(3)==v else (((z/-n)*-1)+b if z==8 else ((z//-4)*-1)+b)


input()
ss=map(int,raw_input().split())
a1=ss.count(1)
a2=ss.count(2)
a3=ss.count(3)
a4=ss.count(4)
x=2*a2+a3-a1
print a4+a3+(x)/4 if x>=4 else a4+a3+1


n=input()
print eval(raw_input().replace(' ','+'))//-4*(-1)


n=input()
z=eval(raw_input().replace(' ','+'))
print (z/-n)*-1 if z==8 and n>2 else (z//-4)*-1


input()
ss=map(int,raw_input().split())
a1=ss.count(1)
a2=ss.count(2)
a3=ss.count(3)
a4=ss.count(4)
x=0
if a1<a3:
    x==0
else:
    x=a1-a3
if a1==len(ss) and a1>3:
    print a1/4
elif a1==len(ss) and a1<4:
    print a1
else:
    print a4+a3+((2*x)+a2+3)/4


n=input()
z=eval(raw_input().replace(' ','+'))
print (z/4) if z==8 and n>2 else (z//-4)*-1


n=input()
c=map(int,raw_input().split())
v=len(c)
b=c.count(4)
c.sort()
i=0
while b>i:
    c.pop()
    i+=1
z=sum(c)

print v if c.count(3)==v else (v if c.count(3)+c.count(2)==v else (((z/-n)*-1)+b if z==8 else ((z//-4)*-1)+b))


n=input()
c=map(int,raw_input().split())
v=len(c)
b=c.count(4)
b1=c.count(3)
b2=c.count(2)
c.sort()
i=0
while b>i:
    c.pop()
    i+=1
z=sum(c)

print v if c.count(3)==v else (v if b1+b2==v else (((z/-n)*-1)+b if z==8 else ((z//-4)*-1)+b))


n=input()
z=eval(raw_input().replace(' ','+'))
print (z//-4)*-1+1 if z==8 and n>2 else (z//-4)*-1


n=input()
c=map(int,raw_input().split())
v=len(c)
g=0
b=c.count(4)
b1=c.count(3)
b2=c.count(2)
if b1!=0 and b2!=0:
    g=b1+b2
c.sort()
i=0
while b>i:
    c.pop()
    i+=1
z=sum(c)

print v if c.count(3)==v else (v if g!=0  else (((z/-n)*-1)+b if z==8 else ((z//-4)*-1)+b))


n=input()
c=0
while n>0:
    w=input()
    c=c+w
    n=n-1
print ((-c//4)*-1)


input()
ss=map(int,raw_input().split())
a1=ss.count(1)
a2=ss.count(2)
a3=ss.count(3)
a4=ss.count(4)
x=0
if a1<a3:
    x==0
else:
    x=a1-a3
print a4+a3+((2*a2)+x+3)/4


n=input()
c=map(int,raw_input().split())
b=c.count(4)
c.sort()
i=0
while b>i:
    c.pop()
    i+=1
z=sum(c)
print ((z/-n)*-1)+b if z==8 else ((z//-4)*-1)+b


n=input()
lst=map(int,raw_input().split())
hld=[0]
def fnc(k,hld,lst):
    sum=k
    cnt=0
    for x in xrange(4-k,0,-1):
        if x in lst:
            cnt+=1
            sum+=x
            lst.remove(x)
            fnc(sum,hld,lst)
            break
    if cnt==0:
        hld[0]+=1
while (4 in lst):
    hld[0]+=1
    lst.remove(4)

while len(lst)>0:
    num=lst[-1]
    del lst[-1]
    fnc(num,hld,lst)
print hld[0]


n=input()
lst=map(int,raw_input().split())
hld=[0]
def fnc(k,hld,lst):
    sum=k
    cnt=0
    for x in xrange(4-k,0,-1):
        if x in lst:
            cnt+=1
            sum+=x
            lst.remove(x)
            fnc(sum,hld,lst)
            break
    if cnt==0:
        hld[0]+=1
while (4 in lst):
    hld[0]+=1
    lst.remove(4)
while len(lst)>0:
    num=lst[-1]
    del lst[-1]
    fnc(num,hld,lst)
print hld[0]


n=input()
lst=raw_input()
import math
cn1=0
cn2=0
cn3=0
summ=0
for x in lst[::2]:
    if x=='1':
        cn1+=1
    elif x=='2':
        cn2+=1
    elif x=='3':
        cn3+=1
    else:
        summ+=1
print cn1,cn2,cn3,summ
summ+=cn3
if cn1<=cn3:
    cn1=0
else:
    cn1-=cn3
summ+=int(math.ceil(float(cn2)/2))
if cn2%2!=0:
    if cn1>2:
        cn1-=2
    else:
        cn1==0
summ+=int(math.ceil(float(cn1)/4))
print summ


n=input()
lst=map(int,raw_input().split())
hld=[0]
while (4 in lst):
    hld[0]+=1
    lst.remove(4)
while (3 in lst):
    lst.remove(3)
    if (1 in lst):
        lst.remove(1)
    hld[0]+=1
while (2 in lst):
    lst.remove(2)
    if (2 in lst):
        lst.remove(2)
    elif (1 in lst):
        lst.remove(1)
        if (1 in lst):
            lst.remove(1)
    hld[0]+=1
while (1 in lst):
    lst.remove(1)
    if (1 in lst):
        if lst.count(1)>=3:
            for x in xrange(3):
                lst.remove(1)
        elif lst.count(1)>=2:
            for x in xrange(2):
                lst.remove(1)
        else:
            lst.remove(1)
    hld[0]+=1
print hld[0]


n=input()
lst=raw_input()
import math
cn1=0
cn2=0
cn3=0
summ=0
for x in lst[::2]:
    if x=='1':
        cn1+=1
    elif x=='2':
        cn2+=1
    elif x=='3':
        cn3+=1
    else:
        summ+=1
summ+=cn3
if cn1<=cn3:
    cn1=0
else:
    cn1-=cn3
summ+=int(math.ceil(float(cn2)/2))
if (cn2%2!=0):
    if cn1>2:
        cn1-=2
    else:
        cn1=0
summ+=int(math.ceil(float(cn1)/4))
print summ


n=input()
lst=raw_input()
import math
cn1=0
cn2=0
cn3=0
summ=0
for x in lst[::2]:
    if x=='1':
        cn1+=1
    elif x=='2':
        cn2+=1
    elif x=='3':
        cn3+=1
    else:
        summ+=1
summ+=cn3
if cn1<=cn3:
    cn1=0
else:
    cn1-=cn3
summ+=int(math.ceil(float(cn2)/2))
if cn2%2!=0:
    if cn1>2:
        cn1-=2
    else:
        cn1==0
summ+=int(math.ceil(float(cn1)/4))
print summ


n=input()
lst=raw_input()
import math
cn1=0
cn2=0
cn3=0
summ=0
for x in lst[::2]:
    if x=='1':
        cn1+=1
    elif x=='2':
        cn2+=1
    elif x=='3':
        cn3+=1
    else:
        summ+=1
summ+=cn3
if cn1<=cn3:
    cn1=0
else:
    cn1-=cn3
summ+=(cn2/2)
if cn2%2!=0:
    if cn1>2:
        cn1-=2
    else:
        cn1==0
summ+=int(math.ceil(float(cn1)/4))
print summ


n=input()
lst=map(int,raw_input().split())
hld=[0]
def fnc(k,hld,lst):
    sum=k
    cnt=0
    for x in xrange(4-k,0,-1):
        if x in lst:
            cnt+=1
            sum+=x
            lst.remove(x)
            fnc(sum,hld,lst)
            break
    if cnt==0:
        hld[0]+=1
while len(lst)>0:
    num=lst[-1]
    del lst[-1]
    fnc(num,hld,lst)
print hld[0]


n = input() ; s = map(int, raw_input().split())
s.sort(reverse = True) ; k = c = 0
for i in range(0, n):
  k += s[i]
  if k >= 4: c +=1 ; k = k%4
if k != 0: c += 1 ; print c
else : print c


n = input() ; s = map(int, raw_input().split())
c = s.count(4) ; a = s.count(3) ; b = s.count(1) ; d = s.count(2)
if b > a : c += a ; b -= a
elif a >= b : c += a ; b = 0
if d%2 == 0 and b == 0: c += d/2
elif d%2 != 0 and b == 0: c+= d/2 + 1
else:
  c += d/2 + 1; b -= 2
  if b %4 != 0: c += b/4 + 1
  else : c += b/4
print c


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int n, m, xx, number, dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int x[1000050], need[1050][1050];
pair <int, int> Q[1000050];
pair <pair <int, int>, int> up[1000050], down[1000050];
pair <pair <int, int>, pair <int, int> > object[105];
bool solve[105], visited[1050][1050];
char data[1050][1050];

int Rand()
{
    return (rand() << 15) | rand();
}

void BFS(int x, int y)
{
int  low, high, dir, i;
pair <int, int> newq;

     visited[x][y] = true;
     Q[low = high = 0] = make_pair(x, y);
     while (low <= high)
     {
           for (dir = 0; dir < 4; dir++)
           {
               newq = make_pair(Q[low].first + dx[dir],
                                Q[low].second + dy[dir]);
               if (newq.first < 1 || newq.first > n ||
                   newq.second < 1 || newq.second > m ||
                   visited[newq.first][newq.second] ||
                   data[newq.first][newq.second] != '*')
               {
                   continue;
               }
               visited[newq.first][newq.second] = true;
               Q[++high] = newq;
           }
           low++;
     }

     number++;
     object[number].first = object[number].second = Q[0];
     for (i = 1; i <= high; i++)
     {
         object[number].first = min(object[number].first, Q[i]);
         object[number].second = max(object[number].second, Q[i]);
     }

     return;
}

long long Solve(pair <pair <int, int>, pair <int, int> > r)
{
int  i, j, current, one, numberup, numberdown;
bool stop;
pair <int, int> area, origin;
pair <pair <int, int>, pair <int, int> > temp;
long long answer;

     for (i = 1; i <= number; i++)
     if  (!solve[i])
     {
         temp.first.first = max(object[i].first.first, r.first.first);
         temp.first.second = max(object[i].first.second, r.first.second);
         temp.second.first = min(object[i].second.first, r.second.first);
         temp.second.second = min(object[i].second.second, r.second.second);
         if (temp.first.first <= temp.second.first &&
             temp.first.second <= temp.second.second)
         {
             return 0;
         }
     }

     origin = make_pair(1, m);

     for (i = 1; i <= number; i++)
     if  (!solve[i])
     {
         if (max(r.first.first, object[i].first.first) <=
             min(object[i].second.first, r.second.first))
         {
             if (object[i].second.second < r.first.second)
             {
                origin.first = max(origin.first, object[i].second.second + 1);
             }  else
             {
                origin.second = min(origin.second, object[i].first.second - 1);
             }
         }
     }

     area = origin;
     current = r.first.first;
     numberup = 0;

     for (i = xx; i >= 1; i--)
     if  (x[i] < current)
     {
         up[++numberup] = make_pair(area, current - x[i]);
         current = x[i];
         stop = false;
         for (j = 1; j <= need[i][0]; j++)
         if  (object[need[i][j]].second.second < r.first.second)
         {
             area.first = max(area.first, object[need[i][j]].second.second + 1);
         }   else
         if  (r.second.second < object[need[i][j]].first.second)
         {
             area.second = min(area.second, object[need[i][j]].first.second - 1);
         }   else
         {
             stop = true;
             break;
         }
         if  (stop)
         {
             break;
         }
     }
     for (i = j = 1; i < numberup; i++)
     if  (up[i + 1].first != up[j].first)
     {
         up[++j] = up[i + 1];
     }   else
     {
         up[j].second += up[i + 1].second;
     }
     numberup = j;

     area = origin;
     current = r.second.first;
     numberdown = 0;

     for (i = 1; i <= xx; i++)
     if  (x[i] > current)
     {
         down[++numberdown] = make_pair(area, x[i] - current);
         current = x[i];
         stop = false;
         for (j = 1; j <= need[i][0]; j++)
         if  (object[need[i][j]].second.second < r.first.second)
         {
             area.first = max(area.first, object[need[i][j]].second.second + 1);
         }   else
         if  (r.second.second < object[need[i][j]].first.second)
         {
             area.second = min(area.second, object[need[i][j]].first.second - 1);
         }   else
         {
             stop = true;
             break;
         }
         if  (stop)
         {
             break;
         }
     }
     for (i = j = 1; i < numberdown; i++)
     if  (down[i + 1].first != down[j].first)
     {
         down[++j] = down[i + 1];
     }   else
     {
         down[j].second += down[i + 1].second;
     }
     numberdown = j;

     answer = 0;

     for (i = 1; i <= numberup; i++)
     {
         for (j = 1; j <= numberdown; j++)
         {
             one = (r.first.second - max(up[i].first.first, down[j].first.first) + 1) *
                   (min(up[i].first.second, down[j].first.second) - r.second.second + 1);
             answer += 1ll * one * up[i].second * down[j].second;
         }
     }

     return answer;
}

int main()
{
int i, j, k;
pair <pair <int, int>, pair <int, int> > temp;
long long answer;

//    freopen("k.in", "r", stdin);
//    freopen("k.out", "w", stdout);

    srand((unsigned) time (0));

    scanf("%d%d%d\n", &n, &m, &k);
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
        {
            scanf("%c", &data[i][j]);
        }
        scanf("\n");
    }

    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
        if  (data[i][j] == '*' && !visited[i][j])
        {
            BFS(i, j);
        }
    }

    for (i = 1; i <= number; i++)
    {
        x[++xx] = object[i].first.first;
        x[++xx] = object[i].first.first - 1;
        x[++xx] = object[i].second.first;
        x[++xx] = object[i].second.first + 1;
    }
    x[++xx] = 0;
    x[++xx] = n + 1;

    sort(x + 1, x + xx + 1);
    for (i = j = 1; i < xx; i++)
    if  (x[i + 1] != x[j])
    {
        x[++j] = x[i + 1];
    }
    xx = j;

    for (i = 1; i <= xx; i++)
    {
        for (j = 1; j <= number; j++)
        if  (object[j].first.first <= x[i] &&
             x[i] <= object[j].second.first)
        {
             need[i][++need[i][0]] = j;
        }
    }

    answer = 0;

    for (i = 1; i <= number; i++)
    {
        solve[i] = true;
        answer += Solve(object[i]);
        solve[i] = false;
    }

    for (i = 1; i < number; i++)
    {
        for (j = i + 1; j <= number; j++)
        {
            temp.first.first = min(object[i].first.first, object[j].first.first);
            temp.first.second = min(object[i].first.second, object[j].first.second);
            temp.second.first = max(object[i].second.first, object[j].second.first);
            temp.second.second = max(object[i].second.second, object[j].second.second);
            solve[i] = solve[j] = true;
            answer += Solve(temp);
            solve[i] = solve[j] = false;
        }
    }

    for (i = 1; i < number - 1; i++)
    {
        for (j = i + 1; j < number; j++)
        {
            for (k = j + 1; k <= number; k++)
            {
                temp.first.first = min(object[i].first.first,
                                   min(object[j].first.first, object[k].first.first));
                temp.first.second = min(object[i].first.second,
                                    min(object[j].first.second, object[k].first.second));
                temp.second.first = max(object[i].second.first,
                                    max(object[j].second.first, object[k].second.first));
                temp.second.second = max(object[i].second.second,
                                     max(object[j].second.second, object[k].second.second));
                solve[i] = solve[j] = solve[k] = true;
                answer += Solve(temp);
                solve[i] = solve[j] = solve[k] = false;
            }
        }
    }

    printf("%I64d\n", answer);

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#define mk make_pair
#define pb push_back
using namespace std;
struct ppp{
	int x1,x2,y1,y2;
	void mk(int x1_,int x2_,int y1_,int y2_){
		x1=x1_; x2=x2_; y1=y1_; y2=y2_;
	}
}a[120];
long long ans;
int n,m,i,j,k,x,y,l,r,P[220],tot,Pn,u,d;
char c[1010][1010];
int Find(int x){
	return lower_bound(P+1,P+Pn+1,x)-P;
}
int main(){
	scanf("%d%d%*d",&n,&m);
	for(i=1;i<=n;++i)scanf("%s",c[i]+1);
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j)if(c[i][j]=='*'){
			k=j;
			while(c[i][k]=='*')k++; k--;
			l=i;
			while(c[l][j]=='*')l++; l--;
			for(x=i;x<=l;++x)
				for(y=j;y<=k;++y)c[x][y]='.';
			a[++tot].mk(i,l,j,k);
			P[++Pn]=i; P[++Pn]=l;
		}
	P[++Pn]=0; P[++Pn]=n+1;
	sort(P+1,P+Pn+1);
	Pn=unique(P+1,P+Pn+1)-P-1;
	for(i=1;i<=tot;++i)a[i].x1=Find(a[i].x1),a[i].x2=Find(a[i].x2);
	for(u=2;u<Pn;++u){
		for(d=u;d<Pn;++d){
			long long tmp=0;
			vector<pair<int,int> >Q;
			for(i=1;i<=tot;++i){
				if(a[i].x2<u || a[i].x1>d)continue;
				if(a[i].x1>=u && a[i].x2<=d)Q.pb(mk(a[i].y1,-1)),Q.pb(mk(a[i].y2,1));
				else Q.pb(mk(a[i].y1,-100)),Q.pb(mk(a[i].y2,100));
			}
			sort(Q.begin(),Q.end());
			int num=Q.size(),C,suml,sumr,cc;
			Q.push_back(mk(m+1,0));
			for(int C=1;C<=3;++C){
				suml=sumr=0; cc=0;
				for(l=0,r=0;r<num;++r){
					sumr+=Q[r].second;
					cc+=max(0,Q[r].second);
					if(!sumr){
						while(suml || cc>C){
							suml-=Q[l].second;
							cc-=max(0,Q[l].second);
							l++;
						}
						if(!suml && cc==C)tmp+=(Q[r+1].first-Q[r].first)*(Q[l].first-(!l?0:Q[l-1].first));
					}
				}
			}
			ans+=tmp*(P[u]-P[u-1])*(P[d+1]-P[d]);
		}
	}
	printf("%I64d\n",ans);
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>

using namespace std;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define foreach(e, x) for (__typeof(x.begin()) e = x.begin(); e != x.end(); ++e)
typedef long long LL;
typedef pair<int, int> PII;

int n, m, k;
char s[1003][1003];
int hsum[1003][1003], vsum[1003][1003];
int sum[1003][1003] = {};
bool used[1003][1003] = {};
int y[100], x[100], yy[100], xx[100];
int cnt = 0;
LL ans = 0;

void solve(int x, int y, int xx, int yy) {
    int cur = sum[yy][xx] - sum[y - 1][xx] - sum[yy][x - 1] + sum[y - 1][x - 1];
    int lo = xx, hi = m, mid;
    while (lo < hi) {
        mid = (lo + hi + 1) >> 1;
        if (sum[yy][mid] - sum[y - 1][mid] - sum[yy][x - 1] + sum[y - 1][x - 1] == cur)
            lo = mid;
        else
            hi = mid - 1;
    }
    int hor1 = lo - xx + 1;
    lo = 1, hi = x;
    while (lo < hi) {
        mid = (lo + hi) >> 1;
        if (sum[yy][xx] - sum[y - 1][xx] - sum[yy][mid - 1] + sum[y - 1][mid - 1] == cur)
            hi = mid;
        else
            lo = mid + 1;
    }
    int hor2 = x - lo + 1;
    lo = yy, hi = n;
    while (lo < hi) {
        mid = (lo + hi + 1) >> 1;
        if (sum[mid][xx] - sum[mid][x - 1] - sum[y - 1][xx] + sum[y - 1][x - 1] == cur)
            lo = mid;
        else
            hi = mid - 1;
    }
    int ver1 = lo - yy + 1;
    lo = 1, hi = y;
    while (lo < hi) {
        mid = (lo + hi) >> 1;
        if (sum[yy][xx] - sum[yy][x - 1] - sum[mid - 1][xx] + sum[mid - 1][x - 1] == cur)
            hi = mid;
        else
            lo = mid + 1;
    }
    int ver2 = y - lo + 1;
    if (hor1 * hor2 > ver1 * ver2) {
        for (int i = y; i >= 1; --i) {
            if (i < y && hsum[i][xx] - hsum[i][x - 1] > 0) break;
            for (int ii = yy; ii <= n; ++ii) {
                if (ii > yy && hsum[ii][xx] - hsum[ii][x - 1] > 0) break;
                int cnt1, cnt2;
                lo = xx, hi = m;
                while (lo < hi) {
                    mid = (lo + hi + 1) >> 1;
                    if (sum[ii][mid] - sum[i - 1][mid] - sum[ii][x - 1] + sum[i - 1][x - 1] == cur)
                        lo = mid;
                    else
                        hi = mid - 1;
                }
                cnt1 = lo - xx + 1;
                lo = 1, hi = x;
                while (lo < hi) {
                    mid = (lo + hi) >> 1;
                    if (sum[ii][xx] - sum[i - 1][xx] - sum[ii][mid - 1] + sum[i - 1][mid - 1] == cur)
                        hi = mid;
                    else
                        lo = mid + 1;
                }
                cnt2 = x - lo + 1;
                ans += cnt1 * cnt2;
            }
        }
    } else {
        for (int i = x; i >= 1; --i) {
            if (i < x && vsum[i][yy] - vsum[i][y - 1] > 0) break;
            for (int ii = xx; ii <= m; ++ii) {
                if (ii > xx && vsum[ii][yy] - vsum[ii][y - 1] > 0) break;
                int cnt1, cnt2;
                lo = yy, hi = n;
                while (lo < hi) {
                    mid = (lo + hi + 1) >> 1;
                    if (sum[mid][ii] - sum[mid][i - 1] - sum[y - 1][ii] + sum[y - 1][i - 1] == cur)
                        lo = mid;
                    else
                        hi = mid - 1;
                }
                cnt1 = lo - yy + 1;
                lo = 1, hi = y;
                while (lo < hi) {
                    mid = (lo + hi) >> 1;
                    if (sum[yy][ii] - sum[yy][i - 1] - sum[mid - 1][ii] + sum[mid - 1][i - 1] == cur)
                        hi = mid;
                    else
                        lo = mid + 1;
                }
                cnt2 = y - lo + 1;
                ans += cnt1 * cnt2;
            }
        }
    }
}

int main() {
    scanf("%d%d%d", &n, &m, &k);
    REP(i, n) scanf("%s", s[i + 1] + 1);
    REP(i, n + 2) s[i][0] = s[i][m + 1] = '.';
    REP(i, m + 2) s[0][i] = s[n + 1][i] = '.';
    for (int i = 1; i <= n; ++i) {
        hsum[i][0] = 0;
        for (int j = 1; j <= m; ++j) {
            hsum[i][j] = hsum[i][j - 1] + (s[i][j] == '*');
        }
    }
    for (int i = 1; i <= m; ++i) {
        vsum[i][0] = 0;
        for (int j = 1; j <= n; ++j) {
            vsum[i][j] = vsum[i][j - 1] + (s[j][i] == '*');
        }
    }
    for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) {
        sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (s[i][j] == '*');
    }
    for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (!used[i][j] && s[i][j] == '*') {
        int ii = i, jj = j;
        while (ii < n && s[ii + 1][j] == '*') ++ii;
        while (jj < m && s[i][jj + 1] == '*') ++jj;
        y[cnt] = i;
        x[cnt] = j;
        yy[cnt] = ii;
        xx[cnt] = jj;
        ++cnt;
        for (int p = i; p <= ii; ++p) for (int q = j; q <= jj; ++q) {
            used[p][q] = true;
        }
    }
    assert(cnt == k);
    REP(i, k) for (int j = i + 1; j < k; ++j) for (int q = j + 1; q < k; ++q) {
        int cx = min(min(x[i], x[j]), x[q]);
        int cxx = max(max(xx[i], xx[j]), xx[q]);
        int cy = min(min(y[i], y[j]), y[q]);
        int cyy = max(max(yy[i], yy[j]), yy[q]);
        bool ok = true;
        REP(p, k) if (p != i && p != j && p != q) {
            if (x[p] <= cxx && cx <= xx[p] && y[p] <= cyy && cy <= yy[p]) {
                ok = false;
                break;
            }
        }
        if (!ok) continue;
        solve(cx, cy, cxx, cyy);
    }
    REP(i, k) for (int j = i + 1; j < k; ++j) {
        int cx = min(x[i], x[j]);
        int cxx = max(xx[i], xx[j]);
        int cy = min(y[i], y[j]);
        int cyy = max(yy[i], yy[j]);
        bool ok = true;
        REP(p, k) if (p != i && p != j) {
            if (x[p] <= cxx && cx <= xx[p] && y[p] <= cyy && cy <= yy[p]) {
                ok = false;
                break;
            }
        }
        if (!ok) continue;
        solve(cx, cy, cxx, cyy);
    }
    REP(i, k)
        solve(x[i], y[i], xx[i], yy[i]);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1111;

int n, m, k;
char a[N][N];

using S = pair<int, int>;
vector<S> st[N], ed[N], p, q;

void fs(int x, int y) {
  int ny = y;
  while (ny < m && a[x][ny] == '*') ++ny;
  int nx = x;
  while (nx < n && a[nx][y] == '*') ++nx;
  st[x].emplace_back(y, 1);
  st[x].emplace_back(ny, -1);
  ed[nx].emplace_back(y, 1);
  ed[nx].emplace_back(ny, -1);
  for (int i = x; i < nx; ++i) for (int j = y; j < ny; ++j) a[i][j] = '#';
}

void debug(const vector<S>& q) {
  for (const auto eq : q) {
    cerr << eq.first << "," << eq.second << "   ";
  }
  cerr << endl;
}

int main() {
  scanf("%d%d%d\n ", &n, &m, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%s", a[i]);
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (a[i][j] == '*')
        fs(i, j);
  for (int i = 0; i <= n; ++i) {
    sort(ed[i].begin(), ed[i].end());
  }

  int64_t ans = 0;
  p = {};

  for (int i = 0; i < n; ++i) {
      //cerr << " >> before " << i << endl;
      //debug(p);

    vector<S> np;
    size_t k = 0;
    const auto& ei = ed[i];
    for (const auto& ep : p) {
      bool to_delete = false;
      while (k < ei.size() && ei[k].first < ep.first) ++k;
      if (k < ei.size() && ei[k].first == ep.first) {
        if ((ep.second > 0) == (ei[k].second > 0)) {
          to_delete = true;
          ++k;
        }
      }
      if (!to_delete) np.emplace_back(
          ep.first, ep.second > 0 ? ep.second + 1 : ep.second - 1);
    }
    for (const auto& es : st[i])
      np.emplace_back(es.first, es.second * 100);
    sort(np.begin(), np.end());
    swap(p, np);

      //cerr << " >> after " << i << endl;
      //debug(p);

    q = p;
    q.emplace_back(m, 0);
    for (int j = i; j < n; ++j) {
      // close this row
      const auto& ej = ed[j + 1];
      k = 0;
      for (auto& eq : q) {
        while (k < ej.size() && ej[k].first < eq.first) ++k;
        if (k < ej.size() && ej[k].first == eq.first) {
          if (eq.second == 100 && ej[k].second == 1) {
            eq.second = 1;
            ++k;
          }
          if (eq.second == -100 && ej[k].second == -1) {
            eq.second = -1;
            ++k;
          }
        }
      }

      // count
        //cerr << " >> " << i << ", " << j << endl;
        //debug(q);
      k = 0;
      int lv = 0, f[3] = {0, 0, 0};
      for (auto& eq : q) {
        int64_t slots = 0;
        if (!lv) {
          slots = eq.first - k + 1;
          ans += slots * (f[0] + f[1] + f[2]);
        }

        k = eq.first;
        if (eq.second > 1) {
          f[0] = f[1] = f[2] = 0;
        } else if (eq.second == 1) {
          f[2] = f[1];
          f[1] = f[0];
          f[0] = slots;
        }
        lv += eq.second;
      }

      // open next row
      vector<S> nq;
      const auto& es = st[j + 1];
      k = 0;
      for (const auto& eq : q) {
        while (k < es.size() && es[k] < eq) {
          nq.emplace_back(es[k].first, es[k].second * 100);
          ++k;
        }
        nq.push_back(eq);
      }
      swap(q, nq);
    }
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int N, M, K, Xn, Yn;
char G[1010][1010], T[200][200];
vector<int> X, Y;
vector<vector<int> > psum, csum;

void prop(vector<vector<int> > &psum) {
    for(int i = 0; i < Yn; i++) {
        for(int j = 0; j < Xn; j++) {
            if(i) psum[i][j] += psum[i - 1][j];
            if(j) psum[i][j] += psum[i][j - 1];
            if(i && j) psum[i][j] -= psum[i - 1][j - 1];
        }
    }
}

int calc(int r1, int c1, int r2, int c2, vector<vector<int> > &psum) {
    int ret = psum[r2][c2];
    if(r1) ret -= psum[r1 - 1][c2];
    if(c1) ret -= psum[r2][c1 - 1];
    if(r1 && c1) ret += psum[r1 - 1][c1 - 1];
    return ret;
}

int A[200], B[200];

int main() {
    scanf("%d %d %d", &N, &M, &K);

    for(int i = 0; i < N; i++) {
        scanf("\n");
        for(int j = 0; j < M; j++) {
            scanf("%c", &G[i][j]);
        }
    }

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            if(i == 0 || G[i - 1][j] != G[i][j]) Y.push_back(i);
            if(j == 0 || G[i][j - 1] != G[i][j]) X.push_back(j);
        }
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    X.resize(unique(X.begin(), X.end()) - X.begin());
    Y.resize(unique(Y.begin(), Y.end()) - Y.begin());
    Xn = X.size();
    Yn = Y.size();
    X.push_back(M);
    Y.push_back(N);

    for(int i = 0; i < Yn; i++) {
        for(int j = 0; j < Xn; j++) {
            T[i][j] = G[ Y[i] ][ X[j] ];
        }
    }

    psum = csum = vector<vector<int> >(Yn, vector<int>(Xn, 0));
    for(int i = 0; i < Yn; i++) {
        for(int j = 0; j < Xn; j++) {
            if(T[i][j] == '.') continue;
            psum[i][j] = 2;
            if((i && T[i - 1][j] == '*') || (j && T[i][j - 1] == '*')) psum[i][j]--;
            if((i != Yn - 1 && T[i + 1][j] == '*') || (j != Xn - 1 && T[i][j + 1] == '*')) psum[i][j]--;

            csum[i][j] = 1;
            if(j == 0 || T[i][j - 1] == '.') csum[i][j] = 0;
        }
    }
    prop(psum);
    prop(csum);

    ll ans = 0;
    for(int i = 0; i < Yn; i++) {
        for(int j = i; j < Yn; j++) {
            for(int a = 0; a < Xn; a++) {
                A[a] = calc(i, a, j, a, psum);
            }
            for(int a = 0; a < Xn; a++) {
                B[a] = calc(i, a, j, a, csum);
            }

            for(int a = 0; a < Xn; a++) {
                int t = Y[i + 1] - Y[i];
                int d = Y[j + 1] - Y[j];
                int l = calc(i, a, j, a, psum)? 1 : X[a + 1] - X[a];
                int r;

                if(B[a]) continue;
                int tmp = 0;

                for(int b = a; b < Xn; b++) {
                    if(T[i][b] == '*') t = 1;
                    if(T[j][b] == '*') d = 1;

                    if(i && T[i - 1][b] == '*' && T[i][b] == '*') break;
                    if(j < Yn - 1 && T[j][b] == '*' && T[j + 1][b] == '*') break;
                    tmp += A[b];
                    if(b < Xn - 1 && B[b + 1]) continue;

                    if(1 <= tmp / 2 && tmp / 2 <= 3) {
                        //cout << i << ' ' << a << ' ' << j << ' ' << b << ' ' << tmp << endl;

                        r = A[b]? 1 : X[b + 1] - X[b];
                        ans += 1LL * t * d * l * r;
                    }
                }
            }
        }
    }
    printf("%lld", ans);
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int N, M, K, Xn, Yn;
char G[1010][1010], T[200][200];
vector<int> X, Y;

int psum[200][200], rsum[200][200], csum[200][200];

void prop(int (*psum)[200]) {
    for(int i = 0; i < Yn; i++) {
        for(int j = 0; j < Xn; j++) {
            if(i) psum[i][j] += psum[i - 1][j];
            if(j) psum[i][j] += psum[i][j - 1];
            if(i && j) psum[i][j] -= psum[i - 1][j - 1];
        }
    }
}

int calc(int r1, int c1, int r2, int c2, int (*psum)[200]) {
    int ret = psum[r2][c2];
    if(r1) ret -= psum[r1 - 1][c2];
    if(c1) ret -= psum[r2][c1 - 1];
    if(r1 && c1) ret += psum[r1 - 1][c1 - 1];
    return ret;
}

bool cross(int r1, int c1, int r2, int c2) {
    if(calc(r1, c1, r1, c2, rsum)) return true;
    if(calc(r1, c1, r2, c1, csum)) return true;
    if(r2 < Yn - 1 && calc(r2 + 1, c1, r2 + 1, c2, rsum)) return true;
    if(c2 < Xn - 1 && calc(r1, c2 + 1, r2, c2 + 1, csum)) return true;
    return false;
}

int main() {
    scanf("%d %d %d", &N, &M, &K);

    for(int i = 0; i < N; i++) {
        scanf("\n");
        for(int j = 0; j < M; j++) {
            scanf("%c", &G[i][j]);
        }
    }

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            if(i == 0 || G[i - 1][j] != G[i][j]) Y.push_back(i);
            if(j == 0 || G[i][j - 1] != G[i][j]) X.push_back(j);
        }
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    X.resize(unique(X.begin(), X.end()) - X.begin());
    Y.resize(unique(Y.begin(), Y.end()) - Y.begin());
    Xn = X.size();
    Yn = Y.size();
    X.push_back(M);
    Y.push_back(N);

    for(int i = 0; i < Yn; i++) {
        for(int j = 0; j < Xn; j++) {
            T[i][j] = G[ Y[i] ][ X[j] ];
        }
    }

    for(int i = 0; i < Yn; i++) {
        for(int j = 0; j < Xn; j++) {
            if(T[i][j] == '.') continue;
            psum[i][j] = 2;
            if((i && T[i - 1][j] == '*') || (j && T[i][j - 1] == '*')) psum[i][j]--;
            if((i != Yn - 1 && T[i + 1][j] == '*') || (j != Xn - 1 && T[i][j + 1] == '*')) psum[i][j]--;

            rsum[i][j] = 1;
            csum[i][j] = 1;
            if(i == 0 || T[i - 1][j] == '.') rsum[i][j] = 0;
            if(j == 0 || T[i][j - 1] == '.') csum[i][j] = 0;
        }
    }
    prop(psum);
    prop(rsum);
    prop(csum);

    ll ans = 0;
    for(int i = 0; i < Yn; i++) {
        for(int j = i; j < Yn; j++) {
            for(int a = 0; a < Xn; a++) {
                for(int b = a; b < Xn; b++) {
                    if(cross(i, a, j, b)) continue;
                    int tmp = calc(i, a, j, b, psum) / 2;

                    if(1 <= tmp && tmp <= 3) {
                        //cout << i << ' ' << a << ' ' << j << ' ' << b << ' ' << tmp << endl;

                        int t = calc(i, a, i, b, psum)? 1 : Y[i + 1] - Y[i];
                        int d = calc(j, a, j, b, psum)? 1 : Y[j + 1] - Y[j];
                        int l = calc(i, a, j, a, psum)? 1 : X[a + 1] - X[a];
                        int r = calc(i, b, j, b, psum)? 1 : X[b + 1] - X[b];

                        ans += 1LL * t * d * l * r;
                    }
                }
            }
        }
    }
    printf("%lld", ans);
}