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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
            //string groupsData = "2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            groupsList.Sort();

            if (groupsList.Contains(4))
            {
                int startInxed = groupsList.IndexOf(4);
                answer += groupsList.Count - startInxed;
                groupsList.RemoveRange(startInxed, groupsList.Count - startInxed);
            }

            if (groupsList.Contains(2))
            {
                if (groupsList.Contains(1) || groupsList.Contains(3))
                {
                    int startIndex = groupsList.IndexOf(2);
                    int endIndex = groupsList.IndexOf(3);

                    if (endIndex < startIndex)
                    {
                        answer += RemoveCouple(groupsList, 2, 2);
                    }
                    else
                    {
                        answer += (endIndex - startIndex) / 2;
                        //if ((endIndex - startIndex) % 2 == 0)
                        //    answer++;

                        if (endIndex - startIndex > 1 && (endIndex - startIndex) % 2 == 0)
                        {
                            groupsList.RemoveRange(startIndex, endIndex - startIndex);
                        }
                        else if (endIndex - startIndex > 1)
                        {
                            groupsList.RemoveRange(startIndex, endIndex - startIndex - 1 );
                        }
                    }
                }
                else
                {
                    answer += RemoveFast2(groupsList);
                }
            }

            if (!groupsList.Contains(2) && groupsList.Contains(1) && groupsList.Contains(3))
            {
                double onesCount = groupsList.IndexOf(3);

                if (groupsList.Count / 2 == onesCount && groupsList.Count % 2 == 0)
                {
                    answer += groupsList.Count / 2;
                    groupsList.Clear();
                }
                else
                {
                    while (groupsList.Contains(1) && groupsList.Contains(3))
                    {
                        groupsList.RemoveAt(0);
                        groupsList.RemoveAt(groupsList.Count - 1);
                        answer++;
                    }
                }
            }
            else
            {
                while (groupsList.Contains(1) && groupsList.Contains(3))
                {
                    groupsList.RemoveAt(0);
                    groupsList.RemoveAt(groupsList.Count - 1);
                    answer++;
                }
            }

            if (groupsList.Contains(3))
                answer += RemoveSingle(groupsList, 3); // all 3's

            if (groupsList.Contains(1))
            answer += RemoveAll4Ones(groupsList);

            if (groupsList.Count <= 3 && groupsList.Count > 0)
            {
                answer++;
            }
            else if (groupsList.Count == 4)
            {
                answer += 2;
            }

            Console.WriteLine(answer);
        }

        private static int RemoveAll4Ones(List<int> groupsList)
        {
            int answ = 0;
            int counter = 0;
            List<int> pos = new List<int>();

            if (groupsList.Contains(2))
            {
                for (int i = 0; i < groupsList.Count; i++)
                {
                    if (groupsList[i] == 1)
                    {
                        pos.Add(i);
                        counter++;
                    }
                }

                while (counter >= 4)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        groupsList.RemoveAt(pos[pos.Count - 1]);
                        pos.RemoveAt(pos.Count - 1);
                    }
                    counter -= 4;
                    answ++;
                }
            }
            else
            {
                answ = groupsList.Count / 4;
                if (groupsList.Count % 4 > 0)
                    answ++;

                groupsList.Clear();
            }

            return answ;
        }

        private static int RemoveSingle(List<int> groupsList, int a)
        {
            int ans = 0;
            for (int i = groupsList.Count - 1; i > -1; i--)
            {
                if (groupsList[i] == a)
                {
                    ans++;
                    groupsList.RemoveAt(i);
                }
            }
            return ans;
        }

        private static int RemoveCouple(List<int> groupsList, int a, int b)
        {
            int ans = 0;

            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                ans++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return ans;
        }

        private static int RemoveFast2(List<int> groupsList)
        {
            int ans = 0;
            ans = groupsList.Count / 2;
            if (groupsList.Count % 2 > 0)
                ans++;

            groupsList.Clear();
            return ans;
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
           // string groupsData = "1 1 1 1 1 1 1 1 1 1 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            if (groupsList.Contains(4))
                answer += RemoveSingle(groupsList, 4); // all 4s

            if (groupsList.Contains(2))
            {
                if (groupsList.Contains(1) || groupsList.Contains(3))
                {
                    answer += RemoveCouple(groupsList, 2, 2);
                }
                else
                {
                    answer += RemoveFast2(groupsList);
                }
            }

            if (!groupsList.Contains(2) && groupsList.Contains(1) && groupsList.Contains(3))
            {
                groupsList.Sort();
                double onesCount = groupsList.IndexOf(3);

                if (groupsList.Count / 2 == onesCount && groupsList.Count % 2 ==0)
                {
                    answer += groupsList.Count / 2;
                    groupsList.Clear();
                }
                else
                {
                    while (groupsList.Contains(1) && groupsList.Contains(3))
                    {
                        groupsList.RemoveAt(0);
                        groupsList.RemoveAt(groupsList.Count - 1);
                        answer++;
                    }
                }
            }

            if (groupsList.Contains(3))
                answer += RemoveSingle(groupsList, 3); // all 3's

            if (groupsList.Contains(1))
            answer += RemoveAll4Ones(groupsList);

            if (groupsList.Count <= 3 && groupsList.Count > 0)
            {
                answer++;
            }
            else if (groupsList.Count == 4)
            {
                answer += 2;
            }

            Console.WriteLine(answer);
        }

        private static int RemoveAll4Ones(List<int> groupsList)
        {
            int answ = 0;
            int counter = 0;
            List<int> pos = new List<int>();

            if (groupsList.Contains(2))
            {
                for (int i = 0; i < groupsList.Count; i++)
                {
                    if (groupsList[i] == 1)
                    {
                        pos.Add(i);
                        counter++;
                    }
                }

                while (counter >= 4)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        groupsList.RemoveAt(pos[pos.Count - 1]);
                        pos.RemoveAt(pos.Count - 1);
                    }
                    counter -= 4;
                    answ++;
                }
            }
            else
            {
                answ = groupsList.Count / 4;
                if (groupsList.Count % 4 > 0)
                    answ++;

                groupsList.Clear();
            }

            return answ;
        }

        private static int RemoveSingle(List<int> groupsList, int a)
        {
            int ans = 0;
            for (int i = groupsList.Count - 1; i > -1; i--)
            {
                if (groupsList[i] == a)
                {
                    ans++;
                    groupsList.RemoveAt(i);
                }
            }
            return ans;
        }

        private static int RemoveCouple(List<int> groupsList, int a, int b)
        {
            int ans = 0;

            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                ans++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return ans;
        }

        private static int RemoveFast2(List<int> groupsList)
        {
            int ans = 0;
            ans = groupsList.Count / 2;
            if (groupsList.Count % 2 > 0)
                ans++;

            groupsList.Clear();
            return ans;
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
           // string groupsData = "1 1 1 1 1 1 1 1 1 1 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            answer += RemoveSingle(groupsList, 4); // all 4s
            answer += RemoveCouple(groupsList, 2, 2); // all double 2s
            answer += RemoveCouple(groupsList, 3, 1); // all 3+1 couples
            answer += RemoveCouple(groupsList, 1, 3);
            answer += RemoveSingle(groupsList, 3); // all 3's
            answer += RemoveAll4Ones(groupsList);

            if (groupsList.Count <= 3 && groupsList.Count > 0)
            {
                answer++;
            }
            else if (groupsList.Count == 4)
            {
                answer += 2;
            }

            Console.WriteLine(answer);
        }

        private static int RemoveAll4Ones(List<int> groupsList)
        {
            int answ = 0;
            int counter = 0;
            List<int> pos = new List<int>();

            if (groupsList.Contains(2))
            {
                for (int i = 0; i < groupsList.Count; i++)
                {
                    if (groupsList[i] == 1)
                    {
                        pos.Add(i);
                        counter++;
                    }
                }

                while (counter >= 4)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        groupsList.RemoveAt(pos[pos.Count - 1]);
                        pos.RemoveAt(pos.Count - 1);
                    }
                    counter -= 4;
                    answ++;
                }
            }
            else
            {
                answ = groupsList.Count / 4;
                if (groupsList.Count % 4 > 0)
                    answ++;

                groupsList.Clear();
            }

            return answ;
        }

        private static int RemoveSingle(List<int> groupsList, int a)
        {
            int ans = 0;
            for (int i = groupsList.Count - 1; i > -1; i--)
            {
                if (groupsList[i] == a)
                {
                    ans++;
                    groupsList.RemoveAt(i);
                }
            }
            return ans;
        }

        private static int RemoveCouple(List<int> groupsList, int a, int b)
        {
            int ans = 0;
            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                ans++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return ans;
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
            //string groupsData = "2 3 4 4 2 1 3 1";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            answer += RemoveSingle(groupsList, 4); // all 4s
            answer += RemoveCouple(groupsList, 2, 2); // all double 2s
            answer += RemoveCouple(groupsList, 3, 1); // all 3+1 couples
            answer += RemoveCouple(groupsList, 1, 3);
            answer += RemoveSingle(groupsList, 3); // all 3's
            answer += RemoveAll4Ones(groupsList);

            if (groupsList.Count <= 3 && groupsList.Count > 0)
            {
                answer++;
            }
            else if (groupsList.Count == 4)
            {
                answer += 2;
            }

            Console.WriteLine(answer);
        }

        private static int RemoveAll4Ones(List<int> groupsList)
        {
            int answ = 0;
            int counter = 0;
            List<int> pos = new List<int>();

            for (int i = 0; i < groupsList.Count; i++)
            {
                if (groupsList[i] == 1)
                {
                    pos.Add(i);
                    counter++;
                }

            }

            while (counter >= 4)
            {
                for (int i = 0; i < 4; i++)
                {
                    groupsList.RemoveAt(pos[pos.Count-1]);
                    pos.RemoveAt(pos.Count-1);
                }
                counter -= 4;
                answ++;
            }

            return answ;
        }

        private static int RemoveSingle(List<int> groupsList, int a)
        {
            int ans = 0;
            for (int i = groupsList.Count - 1; i > 0; i--)
            {
                if (groupsList[i] == a)
                {
                    ans++;
                    groupsList.RemoveAt(i);
                }
            }
            return ans;
        }

        private static int RemoveCouple(List<int> groupsList, int a, int b)
        {
            int ans = 0;
            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                ans++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return ans;
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
           // string groupsData = "1 1 1 1 1 1 1 1 1 1 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            if (groupsList.Contains(4))
                answer += RemoveSingle(groupsList, 4); // all 4s

            if (groupsList.Contains(2))
            {
                if (groupsList.Contains(1) || groupsList.Contains(3))
                {
                    answer += RemoveCouple(groupsList, 2, 2);
                }
                else
                {
                    answer += RemoveFast2(groupsList);
                }
            }

            if (groupsList.Contains(3) && groupsList.Contains(1))
                answer += RemoveCouple(groupsList, 3, 1); // all 3+1 couples
            if (groupsList.Contains(3) && groupsList.Contains(1))
             answer += RemoveCouple(groupsList, 1, 3);
            if (groupsList.Contains(3))
                answer += RemoveSingle(groupsList, 3); // all 3's
            if (groupsList.Contains(1))
            answer += RemoveAll4Ones(groupsList);

            if (groupsList.Count <= 3 && groupsList.Count > 0)
            {
                answer++;
            }
            else if (groupsList.Count == 4)
            {
                answer += 2;
            }

            Console.WriteLine(answer);
        }

        private static int RemoveAll4Ones(List<int> groupsList)
        {
            int answ = 0;
            int counter = 0;
            List<int> pos = new List<int>();

            if (groupsList.Contains(2))
            {
                for (int i = 0; i < groupsList.Count; i++)
                {
                    if (groupsList[i] == 1)
                    {
                        pos.Add(i);
                        counter++;
                    }
                }

                while (counter >= 4)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        groupsList.RemoveAt(pos[pos.Count - 1]);
                        pos.RemoveAt(pos.Count - 1);
                    }
                    counter -= 4;
                    answ++;
                }
            }
            else
            {
                answ = groupsList.Count / 4;
                if (groupsList.Count % 4 > 0)
                    answ++;

                groupsList.Clear();
            }

            return answ;
        }

        private static int RemoveSingle(List<int> groupsList, int a)
        {
            int ans = 0;
            for (int i = groupsList.Count - 1; i > -1; i--)
            {
                if (groupsList[i] == a)
                {
                    ans++;
                    groupsList.RemoveAt(i);
                }
            }
            return ans;
        }

        private static int RemoveCouple(List<int> groupsList, int a, int b)
        {
            int ans = 0;

            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                ans++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return ans;
        }

        private static int RemoveFast2(List<int> groupsList)
        {
            int ans = 0;
            ans = groupsList.Count / 2;
            if (groupsList.Count % 2 > 0)
                ans++;

            groupsList.Clear();
            return ans;
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
            //string groupsData = "2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;
            bool oneLeft = false;
            bool twoLeft = false;
            bool threeLeft = false;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            groupsList.Sort();
            int k1 = 0, k2 = 0, k3 = 0, k4 = 0;

            //////////////////////////////////////////////////////
            if (groupsList.Contains(4))
            {
                k4 = groupsList.Count - groupsList.IndexOf(4);
                answer += k4;
            }
            /////////////////////////////////////////////////////

            if (groupsList.Contains(2))
            {
                int startIndex = 0, endIndex = 0;
                startIndex = groupsList.IndexOf(2);

                if (groupsList.Contains(3))
                {
                    endIndex = groupsList.IndexOf(3);
                }
                else if (groupsList.Contains(4))
                {
                    endIndex = groupsList.IndexOf(4);
                }
                else
                {
                    endIndex = groupsList.Count;
                }

                if ((endIndex - startIndex) % 2 == 0)
                {
                    answer += (endIndex - startIndex) / 2;
                }
                else
                {
                    answer += (endIndex - startIndex) / 2;
                    twoLeft = true;
                }
            }

            ///////////////////////////////////////////////////////////////////
            if (groupsList.Contains(1) && groupsList.Contains(3))
            {
                if (groupsList.Contains(2))
                {
                    k1 = groupsList.IndexOf(2);
                }
                else
                {
                    k1 = groupsList.IndexOf(3);
                }

                if (groupsList.Contains(4))
                {
                    k3 = groupsList.IndexOf(4) - groupsList.IndexOf(3);
                }
                else
                {
                    k3 = groupsList.Count - groupsList.IndexOf(3);
                }

                if (k1 == k3)
                {
                    answer += k1;
                }
                else
                {
                    if (k1 > k3)
                    {
                        answer += k3;
                        k1 -= k3;
                        oneLeft = true;
                    }
                    else
                    {
                        answer += k1;
                        k3 -= k1;
                        threeLeft = true;
                    }
                }
            }
            else if (groupsList.Contains(3))
            {
                if (groupsList.Contains(4))
                {
                    k3 = groupsList.IndexOf(4) - groupsList.IndexOf(3);
                }
                else
                {
                    k3 = groupsList.Count - groupsList.IndexOf(3);
                }

                answer += k3;
            }
            else if (groupsList.Contains(1))
            {
                if (groupsList.Contains(2))
                {
                    k1 = groupsList.IndexOf(2);
                }
                else if (groupsList.Contains(3))
                {
                    k1 = groupsList.IndexOf(3);
                }
                else if (groupsList.Contains(4))
                {
                    k1 = groupsList.IndexOf(4);
                }
                else
                    k1 = groupsList.Count;

                answer += k1 / 4;
                if (k1 % 4 > 0)
                {
                    oneLeft = true;
                    k1 = k1 % 4;
                }
            }

            ///////////////////////////////////////////////////////////////

            if (threeLeft)
            {
                answer += k3;
            }

            if (oneLeft || twoLeft)
            {
                if (k1 > 2)
                {
                    if (twoLeft)
                    {
                        answer++;
                        twoLeft = false;
                        k1 -= 2;
                    }

                    answer += k1 / 4;
                    if (k1 % 4 > 0)
                        answer++;
                }
                else
                {
                    twoLeft = false;
                    answer++;
                }
            }

            Console.WriteLine(answer);
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();

            //string groupsData = "2 4 3 3 2 2 4 1 1 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            answer = RemoveSingle(answer, groupsList, 4); // all 4s
            answer = RemoveCouple(answer, groupsList, 2, 2); // all double 2s
            answer = RemoveCouple(answer, groupsList, 3, 1); // all 3+1 couples
            answer = RemoveCouple(answer, groupsList, 1, 3);
            answer = RemoveSingle(answer, groupsList, 3); // all 3's

            for (int i = 0; i < groupsList.Count; i++)
            {
                if (groupsList[i] == 2)
                {
                    if (groupsList.Count == 3 || groupsList.Count == 4)
                    {
                        answer++;
                        break;
                    }
                }
            }

            Console.WriteLine(answer);

        }

        private static int RemoveSingle(int answer, List<int> groupsList, int a)
        {
            for (int i = groupsList.Count - 1; i > 0; i--)
            {
                if (groupsList[i] == a)
                {
                    answer++;
                    groupsList.RemoveAt(i);
                }
            }
            return answer;
        }

        private static int RemoveCouple(int answer, List<int> groupsList, int a, int b)
        {
            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                answer++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return answer;
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
           // string groupsData = "2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            groupsList.Sort();

            if (groupsList.Contains(4))
            {
                int startInxed = groupsList.IndexOf(4);
                answer += groupsList.Count - startInxed;
                groupsList.RemoveRange(startInxed, groupsList.Count - startInxed);
            }

            if (groupsList.Contains(2))
            {
                if (groupsList.Contains(1) || groupsList.Contains(3))
                {
                    int startIndex = groupsList.IndexOf(2);
                    int endIndex = groupsList.IndexOf(3);

                    if (endIndex < startIndex)
                    {
                        answer += RemoveCouple(groupsList, 2, 2);
                    }
                    else
                    {
                        answer += (endIndex - startIndex) / 2;
                        if ((endIndex - startIndex) % 2 == 0)
                            answer++;

                        if(endIndex - startIndex > 1)
                        groupsList.RemoveRange(startIndex, endIndex - startIndex);
                    }
                }
                else
                {
                    answer += RemoveFast2(groupsList);
                }
            }

            if (!groupsList.Contains(2) && groupsList.Contains(1) && groupsList.Contains(3))
            {
                double onesCount = groupsList.IndexOf(3);

                if (groupsList.Count / 2 == onesCount && groupsList.Count % 2 == 0)
                {
                    answer += groupsList.Count / 2;
                    groupsList.Clear();
                }
                else
                {
                    while (groupsList.Contains(1) && groupsList.Contains(3))
                    {
                        groupsList.RemoveAt(0);
                        groupsList.RemoveAt(groupsList.Count - 1);
                        answer++;
                    }
                }
            }
            else
            {
                while (groupsList.Contains(1) && groupsList.Contains(3))
                {
                    groupsList.RemoveAt(0);
                    groupsList.RemoveAt(groupsList.Count - 1);
                    answer++;
                }
            }

            if (groupsList.Contains(3))
                answer += RemoveSingle(groupsList, 3); // all 3's

            if (groupsList.Contains(1))
            answer += RemoveAll4Ones(groupsList);

            if (groupsList.Count <= 3 && groupsList.Count > 0)
            {
                answer++;
            }
            else if (groupsList.Count == 4)
            {
                answer += 2;
            }

            Console.WriteLine(answer);
        }

        private static int RemoveAll4Ones(List<int> groupsList)
        {
            int answ = 0;
            int counter = 0;
            List<int> pos = new List<int>();

            if (groupsList.Contains(2))
            {
                for (int i = 0; i < groupsList.Count; i++)
                {
                    if (groupsList[i] == 1)
                    {
                        pos.Add(i);
                        counter++;
                    }
                }

                while (counter >= 4)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        groupsList.RemoveAt(pos[pos.Count - 1]);
                        pos.RemoveAt(pos.Count - 1);
                    }
                    counter -= 4;
                    answ++;
                }
            }
            else
            {
                answ = groupsList.Count / 4;
                if (groupsList.Count % 4 > 0)
                    answ++;

                groupsList.Clear();
            }

            return answ;
        }

        private static int RemoveSingle(List<int> groupsList, int a)
        {
            int ans = 0;
            for (int i = groupsList.Count - 1; i > -1; i--)
            {
                if (groupsList[i] == a)
                {
                    ans++;
                    groupsList.RemoveAt(i);
                }
            }
            return ans;
        }

        private static int RemoveCouple(List<int> groupsList, int a, int b)
        {
            int ans = 0;

            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                ans++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return ans;
        }

        private static int RemoveFast2(List<int> groupsList)
        {
            int ans = 0;
            ans = groupsList.Count / 2;
            if (groupsList.Count % 2 > 0)
                ans++;

            groupsList.Clear();
            return ans;
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
           // string groupsData = "1 1 1 1 1 1 1 1 1 1 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            if (groupsList.Contains(4))
                answer += RemoveSingle(groupsList, 4); // all 4s
            if (groupsList.Contains(2))
                answer += RemoveCouple(groupsList, 2, 2); // all double 2s
            if (groupsList.Contains(3) && groupsList.Contains(1))
                answer += RemoveCouple(groupsList, 3, 1); // all 3+1 couples
            if (groupsList.Contains(3) && groupsList.Contains(1))
             answer += RemoveCouple(groupsList, 1, 3);
            if (groupsList.Contains(3))
                answer += RemoveSingle(groupsList, 3); // all 3's
            if (groupsList.Contains(1))
            answer += RemoveAll4Ones(groupsList);

            if (groupsList.Count <= 3 && groupsList.Count > 0)
            {
                answer++;
            }
            else if (groupsList.Count == 4)
            {
                answer += 2;
            }

            Console.WriteLine(answer);
        }

        private static int RemoveAll4Ones(List<int> groupsList)
        {
            int answ = 0;
            int counter = 0;
            List<int> pos = new List<int>();

            if (groupsList.Contains(2))
            {
                for (int i = 0; i < groupsList.Count; i++)
                {
                    if (groupsList[i] == 1)
                    {
                        pos.Add(i);
                        counter++;
                    }
                }

                while (counter >= 4)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        groupsList.RemoveAt(pos[pos.Count - 1]);
                        pos.RemoveAt(pos.Count - 1);
                    }
                    counter -= 4;
                    answ++;
                }
            }
            else
            {
                answ = groupsList.Count / 4;
                if (groupsList.Count % 4 > 0)
                    answ++;

                groupsList.Clear();
            }

            return answ;
        }

        private static int RemoveSingle(List<int> groupsList, int a)
        {
            int ans = 0;
            for (int i = groupsList.Count - 1; i > -1; i--)
            {
                if (groupsList[i] == a)
                {
                    ans++;
                    groupsList.RemoveAt(i);
                }
            }
            return ans;
        }

        private static int RemoveCouple(List<int> groupsList, int a, int b)
        {
            int ans = 0;
            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                ans++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return ans;
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
           // string groupsData = "2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            groupsList.Sort();

            if (groupsList.Contains(4))
            {
                int startInxed = groupsList.IndexOf(4);
                answer += groupsList.Count - startInxed;
                groupsList.RemoveRange(startInxed, groupsList.Count - startInxed);
            }

            if (groupsList.Contains(2))
            {
                if (groupsList.Contains(1) || groupsList.Contains(3))
                {
                    int startIndex = groupsList.IndexOf(2);
                    int endIndex = groupsList.IndexOf(3);

                    if (endIndex < startIndex)
                    {
                        answer += RemoveCouple(groupsList, 2, 2);
                    }
                    else
                    {
                        answer += (endIndex - startIndex) / 2;
                        if ((endIndex - startIndex) % 2 == 0)
                            answer++;

                        groupsList.RemoveRange(startIndex, endIndex - startIndex);
                    }
                }
                else
                {
                    answer += RemoveFast2(groupsList);
                }
            }

            if (!groupsList.Contains(2) && groupsList.Contains(1) && groupsList.Contains(3))
            {
                double onesCount = groupsList.IndexOf(3);

                if (groupsList.Count / 2 == onesCount && groupsList.Count % 2 == 0)
                {
                    answer += groupsList.Count / 2;
                    groupsList.Clear();
                }
                else
                {
                    while (groupsList.Contains(1) && groupsList.Contains(3))
                    {
                        groupsList.RemoveAt(0);
                        groupsList.RemoveAt(groupsList.Count - 1);
                        answer++;
                    }
                }
            }
            else
            {
                while (groupsList.Contains(1) && groupsList.Contains(3))
                {
                    groupsList.RemoveAt(0);
                    groupsList.RemoveAt(groupsList.Count - 1);
                    answer++;
                }
            }

            if (groupsList.Contains(3))
                answer += RemoveSingle(groupsList, 3); // all 3's

            if (groupsList.Contains(1))
            answer += RemoveAll4Ones(groupsList);

            if (groupsList.Count <= 3 && groupsList.Count > 0)
            {
                answer++;
            }
            else if (groupsList.Count == 4)
            {
                answer += 2;
            }

            Console.WriteLine(answer);
        }

        private static int RemoveAll4Ones(List<int> groupsList)
        {
            int answ = 0;
            int counter = 0;
            List<int> pos = new List<int>();

            if (groupsList.Contains(2))
            {
                for (int i = 0; i < groupsList.Count; i++)
                {
                    if (groupsList[i] == 1)
                    {
                        pos.Add(i);
                        counter++;
                    }
                }

                while (counter >= 4)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        groupsList.RemoveAt(pos[pos.Count - 1]);
                        pos.RemoveAt(pos.Count - 1);
                    }
                    counter -= 4;
                    answ++;
                }
            }
            else
            {
                answ = groupsList.Count / 4;
                if (groupsList.Count % 4 > 0)
                    answ++;

                groupsList.Clear();
            }

            return answ;
        }

        private static int RemoveSingle(List<int> groupsList, int a)
        {
            int ans = 0;
            for (int i = groupsList.Count - 1; i > -1; i--)
            {
                if (groupsList[i] == a)
                {
                    ans++;
                    groupsList.RemoveAt(i);
                }
            }
            return ans;
        }

        private static int RemoveCouple(List<int> groupsList, int a, int b)
        {
            int ans = 0;

            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                ans++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return ans;
        }

        private static int RemoveFast2(List<int> groupsList)
        {
            int ans = 0;
            ans = groupsList.Count / 2;
            if (groupsList.Count % 2 > 0)
                ans++;

            groupsList.Clear();
            return ans;
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string groupsData = Console.ReadLine();
            //string groupsData = "2 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;
            bool oneLeft = false;
            bool twoLeft = false;
            bool threeLeft = false;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            groupsList.Sort();
            int k1 = 0, k2 = 0, k3 = 0, k4 = 0;

            //////////////////////////////////////////////////////
            if (groupsList.Contains(4))
            {
                k4 = groupsList.Count - groupsList.IndexOf(4);
                answer += k4;
            }
            /////////////////////////////////////////////////////

            if (groupsList.Contains(2))
            {
                int startIndex = 0, endIndex = 0;
                startIndex = groupsList.IndexOf(2);

                if (groupsList.Contains(3))
                {
                    endIndex = groupsList.IndexOf(3);
                }
                else if (groupsList.Contains(4))
                {
                    endIndex = groupsList.IndexOf(4);
                }
                else
                {
                    endIndex = groupsList.Count;
                }

                if ((endIndex - startIndex) % 2 == 0)
                {
                    answer += (endIndex - startIndex) / 2;
                }
                else
                {
                    answer += (endIndex - startIndex) / 2;
                    twoLeft = true;
                }
            }

            ///////////////////////////////////////////////////////////////////
            if (groupsList.Contains(1) && groupsList.Contains(3))
            {
                if (groupsList.Contains(2))
                {
                    k1 = groupsList.IndexOf(2);
                }
                else
                {
                    k1 = groupsList.IndexOf(3);
                }

                if (groupsList.Contains(4))
                {
                    k3 = groupsList.IndexOf(4) - groupsList.IndexOf(3);
                }
                else
                {
                    k3 = groupsList.Count - groupsList.IndexOf(3);
                }

                if (k1 == k3)
                {
                    answer += k1;
                }
                else
                {
                    if (k1 > k3)
                    {
                        answer += k3;
                        k1 -= k3;
                        oneLeft = true;
                    }
                    else
                    {
                        answer += k1;
                        k3 -= k1;
                        threeLeft = true;
                    }
                }
            }
            else if (groupsList.Contains(3))
            {
                if (groupsList.Contains(4))
                {
                    k3 = groupsList.IndexOf(4) - groupsList.IndexOf(3);
                }
                else
                {
                    k3 = groupsList.Count - groupsList.IndexOf(3);
                }

                answer += k3;
            }

            ///////////////////////////////////////////////////////////////

            if (threeLeft)
            {
                answer += k3;
            }

            if (oneLeft || twoLeft)
            {
                if (k1 > 2)
                {
                    answer++;
                    twoLeft = false;
                    k1 -= 2;

                    answer += k1 / 4;
                    if (k1 % 4 > 0)
                        answer++;
                }
                else
                {
                    twoLeft = false;
                    answer++;
                }
            }

            Console.WriteLine(answer);
        }
    }
}


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

namespace ProblemsFun
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            //string groupsData = Console.ReadLine();
            string groupsData = "1 1 1 1 1 1 1 1 1 1 2";
            string[] groups = groupsData.Split(' ');
            int answer = 0;

            List<int> groupsList = new List<int>();
            for (int i = 0; i < n; i++)
            {
                groupsList.Add(Convert.ToInt32(groups[i]));
            }

            answer += RemoveSingle(groupsList, 4); // all 4s
            answer += RemoveCouple(groupsList, 2, 2); // all double 2s
            answer += RemoveCouple(groupsList, 3, 1); // all 3+1 couples
            answer += RemoveCouple(groupsList, 1, 3);
            answer += RemoveSingle(groupsList, 3); // all 3's
            answer += RemoveAll4Ones(groupsList);

            if (groupsList.Count <= 3 && groupsList.Count > 0)
            {
                answer++;
            }
            else if (groupsList.Count == 4)
            {
                answer += 2;
            }

            Console.WriteLine(answer);
        }

        private static int RemoveAll4Ones(List<int> groupsList)
        {
            int answ = 0;
            int counter = 0;
            List<int> pos = new List<int>();

            if (groupsList.Contains(2))
            {
                for (int i = 0; i < groupsList.Count; i++)
                {
                    if (groupsList[i] == 1)
                    {
                        pos.Add(i);
                        counter++;
                    }
                }

                while (counter >= 4)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        groupsList.RemoveAt(pos[pos.Count - 1]);
                        pos.RemoveAt(pos.Count - 1);
                    }
                    counter -= 4;
                    answ++;
                }
            }
            else
            {
                answ = groupsList.Count / 4;
                if (groupsList.Count % 4 > 0)
                    answ++;
            }

            return answ;
        }

        private static int RemoveSingle(List<int> groupsList, int a)
        {
            int ans = 0;
            for (int i = groupsList.Count - 1; i > -1; i--)
            {
                if (groupsList[i] == a)
                {
                    ans++;
                    groupsList.RemoveAt(i);
                }
            }
            return ans;
        }

        private static int RemoveCouple(List<int> groupsList, int a, int b)
        {
            int ans = 0;
            for (int i = 0; i < groupsList.Count - 1; i++)
            {
                if (groupsList[i] == a)
                {
                    if (i + 1 < groupsList.Count)
                    {
                        for (int k = i + 1; k < groupsList.Count; k++)
                        {
                            if (groupsList[k] == b)
                            {
                                ans++;
                                groupsList.RemoveAt(k);
                                groupsList.RemoveAt(i);
                                i--;
                                break;
                            }
                        }
                    }
                }
            }
            return ans;
        }
    }
}


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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string inputString = Console.ReadLine();

            char breakSymbol = ' ';
            string[] stringArray = inputString.Split(breakSymbol);

            List<byte> groupNumberArray = new List<byte>();

            for (int i = 0; i < n; i++)
            {
                groupNumberArray.Add(Convert.ToByte(stringArray[i]));
            }

            List<byte> taxiList = new List<byte>();

            while (groupNumberArray.Contains(4))
            {
                taxiList.Add(groupNumberArray[groupNumberArray.FindIndex(x => x == 4)]);
                groupNumberArray.Remove(4);
            }

            while (groupNumberArray.Contains(3))
            {
                if (taxiList.Contains(1) && (1 + groupNumberArray[groupNumberArray.FindIndex(x => x == 3)]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += groupNumberArray[groupNumberArray.FindIndex(x => x == 3)];
                    groupNumberArray.Remove(3);
                    continue;
                }

                taxiList.Add(groupNumberArray[groupNumberArray.FindIndex(x => x == 3)]);
                groupNumberArray.Remove(3);
            }

            while (groupNumberArray.Contains(2))
            {
                if (taxiList.Contains(2) && (2 + groupNumberArray[groupNumberArray.FindIndex(x => x == 2)]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += groupNumberArray[groupNumberArray.FindIndex(x => x == 2)];
                    groupNumberArray.Remove(2);
                    continue;
                }

                if (taxiList.Contains(1) && (1 + groupNumberArray[groupNumberArray.FindIndex(x => x == 2)]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += groupNumberArray[groupNumberArray.FindIndex(x => x == 2)];
                    groupNumberArray.Remove(2);
                    continue;
                }

                taxiList.Add(groupNumberArray[groupNumberArray.FindIndex(x => x == 2)]);
                groupNumberArray.Remove(2);
            }

            while (groupNumberArray.Contains(1))
            {
                if (taxiList.Contains(3) && (3 + groupNumberArray[groupNumberArray.FindIndex(x => x == 1)]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += groupNumberArray[groupNumberArray.FindIndex(x => x == 1)];
                    groupNumberArray.Remove(1);
                    continue;
                }

                if (taxiList.Contains(2) && (2 + groupNumberArray[groupNumberArray.FindIndex(x => x == 1)]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += groupNumberArray[groupNumberArray.FindIndex(x => x == 1)];
                    groupNumberArray.Remove(1);
                    continue;
                }

                if (taxiList.Contains(1) && (1 + groupNumberArray[groupNumberArray.FindIndex(x => x == 1)]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += groupNumberArray[groupNumberArray.FindIndex(x => x == 1)];
                    groupNumberArray.Remove(1);
                    continue;
                }

                taxiList.Add(groupNumberArray[groupNumberArray.FindIndex(x => x == 1)]);
                groupNumberArray.Remove(1);
            }

/*            for (int i = 1; i < n; i++)
            {
                if (taxiList.Contains(3) && (3 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(2) && (2 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(1) && (1 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += groupNumberArray[i];
                    continue;
                }

                taxiList.Add(groupNumberArray[i]);
            }
*/
/*            for (int i = 0; i < taxiList.Count(); i++)
            {
                Console.WriteLine(taxiList[i]);
            }
*/
            Console.WriteLine(taxiList.Count());

//            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string inputString = Console.ReadLine();

            char breakSymbol = ' ';
            string[] stringArray = inputString.Split(breakSymbol);

            byte[] groupNumberArray = new byte[n];

            for (int i = 0; i < n; i++)
            {
                groupNumberArray[i] = Convert.ToByte(stringArray[i]);
            }

            List<byte> taxiList = new List<byte>() {groupNumberArray[0]};

            for (int i = 1; i < n; i++)
            {
                for (int j = 0; j < taxiList.Count(); j++)
                {
                    if ((taxiList[j] + groupNumberArray[i]) <= 4)
                    {
                        taxiList[j] += groupNumberArray[i];
                        break;
                    }

                    if ((j == (taxiList.Count() - 1)) && (taxiList[j] + groupNumberArray[i]) > 4)
                    {
                        taxiList.Add(groupNumberArray[i]);
                        break;
                    }
                }
            }

            Console.WriteLine(taxiList.Count());
        }
    }
}


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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string inputString = Console.ReadLine();

            char breakSymbol = ' ';
            string[] stringArray = inputString.Split(breakSymbol);

            byte[] groupNumberArray = new byte[n];

            for (int i = 0; i < n; i++)
            {
                groupNumberArray[i] = Convert.ToByte(stringArray[i]);
            }

            List<int> taxiList = new List<int>() {groupNumberArray[0]};

            for (int i = 1; i < n; i++)
            {
                if (taxiList.Contains(1) && (1 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(2) && (2 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(3) && (3 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += groupNumberArray[i];
                    continue;
                }

                taxiList.Add(groupNumberArray[i]);
            }

            Console.WriteLine(taxiList.Count());
        }
    }
}


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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string inputString = Console.ReadLine();

            char breakSymbol = ' ';
            string[] stringArray = inputString.Split(breakSymbol);

            byte[] groupNumberArray = new byte[n];
            List<byte> taxiList = new List<byte>();

            int[] numberCount = new int[4];

            for (int i = 0; i < n; i++)
            {
                groupNumberArray[i] = Convert.ToByte(stringArray[i]);

                switch (groupNumberArray[i])
                {
                    case 1:
                        numberCount[0]++;
                        break;
                    case 2:
                        numberCount[1]++;
                        break;
                    case 3:
                        numberCount[2]++;
                        break;
                    case 4:
                        numberCount[3]++;
                        break;
                }
            }

//            Console.WriteLine("1: " + numberCount[0]);
//            Console.WriteLine("2: " + numberCount[1]);
//            Console.WriteLine("3: " + numberCount[2]);
//            Console.WriteLine("4: " + numberCount[3]);
//            Console.WriteLine("-----------");

            if ((numberCount[2] != 0) && (numberCount[0] != 0) && (numberCount[2] > numberCount[0]))
            {
                numberCount[2] -= numberCount[0];
                numberCount[3] += numberCount[0];
                numberCount[0] = 0;
            }
            else if ((numberCount[2] != 0) && (numberCount[0] != 0) && (numberCount[2] < numberCount[0]))
            {
                numberCount[0] -= numberCount[2];
                numberCount[3] += numberCount[2];
                numberCount[2] = 0;
            }

//            Console.WriteLine("1: " + numberCount[0]);
//            Console.WriteLine("3: " + numberCount[2]);
//            Console.WriteLine("4: " + numberCount[3]);
//            Console.WriteLine("-----------");

            if (numberCount[1] != 0)
            {
                numberCount[3] += numberCount[1] / 2;
                numberCount[1] = numberCount[1] % 2;
            }

//            Console.WriteLine("2: " + numberCount[1]);
//            Console.WriteLine("4: " + numberCount[3]);
//            Console.WriteLine("-----------");

            if (numberCount[2] != 0)
            {
                numberCount[3] += numberCount[2];
                numberCount[2] = 0;
            }

//            Console.WriteLine("3: " + numberCount[2]);
//            Console.WriteLine("4: " + numberCount[3]);
//            Console.WriteLine("-----------");

            if ((numberCount[0] != 0) && (numberCount[1]!=0))
            {
                numberCount[3] += numberCount[1];
                numberCount[0] -= numberCount[1];
                if (numberCount[0] != 0) numberCount[0]--;
                numberCount[1] = 0;
            }

//            Console.WriteLine("1: " + numberCount[0]);
//            Console.WriteLine("2: " + numberCount[1]);
//            Console.WriteLine("4: " + numberCount[3]);
//            Console.WriteLine("-----------");

            if (numberCount[1] != 0)
            {
                numberCount[3] += numberCount[1];
                numberCount[1] = 0;
            }

//            Console.WriteLine("2: " + numberCount[1]);
//            Console.WriteLine("4: " + numberCount[3]);
//            Console.WriteLine("-----------");

            if (numberCount[0] != 0)
            {
                numberCount[3] += numberCount[0] / 4;
                numberCount[0] = numberCount[0] % 4;

                if (numberCount[0] != 0)
                {
                    numberCount[3]++;
                    numberCount[0] = 0;
                }
            }

//            Console.WriteLine("1: " + numberCount[0]);
//            Console.WriteLine("4: " + numberCount[3]);
//            Console.WriteLine("-----------");

/*            while (groupNumberArray.Contains(4))
            {
                taxiList.Add(4);
                groupNumberArray.Remove(4);
            }

            while (groupNumberArray.Contains(3))
            {
                if (taxiList.Contains(1))
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += 3;
                    groupNumberArray.Remove(3);
                    continue;
                }

                taxiList.Add(3);
                groupNumberArray.Remove(3);
            }

            while (groupNumberArray.Contains(2))
            {
                if (taxiList.Contains(2))
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += 2;
                    groupNumberArray.Remove(2);
                    continue;
                }

                if (taxiList.Contains(1))
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += 2;
                    groupNumberArray.Remove(2);
                    continue;
                }

                taxiList.Add(2);
                groupNumberArray.Remove(2);
            }

            while (groupNumberArray.Contains(1))
            {
                if (taxiList.Contains(3))
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += 1;
                    groupNumberArray.Remove(1);
                    continue;
                }

                if (taxiList.Contains(2))
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += 1;
                    groupNumberArray.Remove(1);
                    continue;
                }

                if (taxiList.Contains(1))
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += 1;
                    groupNumberArray.Remove(1);
                    continue;
                }

                taxiList.Add(1);
                groupNumberArray.Remove(1);
            }
*/

/*            for (int i = 1; i < n; i++)
            {
                if (taxiList.Contains(3) && (3 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(2) && (2 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(1) && (1 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += groupNumberArray[i];
                    continue;
                }

                taxiList.Add(groupNumberArray[i]);
            }
*/
/*            for (int i = 0; i < taxiList.Count(); i++)
            {
                Console.WriteLine(taxiList[i]);
            }
*/
//            Console.WriteLine(taxiList.Count());
            Console.WriteLine(numberCount[3]);

//            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string inputString = Console.ReadLine();

            char breakSymbol = ' ';
            string[] stringArray = inputString.Split(breakSymbol);

            byte[] groupNumberArray = new byte[n];
            List<byte> taxiList = new List<byte>();

            int[] numberCount = new int[4];

            for (int i = 0; i < n; i++)
            {
                groupNumberArray[i] = Convert.ToByte(stringArray[i]);

                switch (groupNumberArray[i])
                {
                    case 1:
                        numberCount[0]++;
                        break;
                    case 2:
                        numberCount[1]++;
                        break;
                    case 3:
                        numberCount[2]++;
                        break;
                    case 4:
                        numberCount[3]++;
                        break;
                }
            }

            //Console.WriteLine("1: " + numberCount[0]);
            //Console.WriteLine("2: " + numberCount[1]);
            //Console.WriteLine("3: " + numberCount[2]);
            //Console.WriteLine("4: " + numberCount[3]);
            //Console.WriteLine("-----------");

            if ((numberCount[2] != 0) && (numberCount[0] != 0) && (numberCount[2] > numberCount[0]))
            {
                numberCount[2] -= numberCount[0];
                numberCount[3] += numberCount[0];
                numberCount[0] = 0;
            }
            else if ((numberCount[2] != 0) && (numberCount[0] != 0) && (numberCount[2] < numberCount[0]))
            {
                numberCount[0] -= numberCount[2];
                numberCount[3] += numberCount[2];
                numberCount[2] = 0;
            }
            else if ((numberCount[2] != 0) && (numberCount[0] != 0) && (numberCount[2] == numberCount[0]))
            {
                numberCount[3] += numberCount[0];
                numberCount[0] = 0;
                numberCount[2] = 0;
            }

             //Console.WriteLine("1: " + numberCount[0]);
             //Console.WriteLine("3: " + numberCount[2]);
             //Console.WriteLine("4: " + numberCount[3]);
             //Console.WriteLine("-----------");

            if (numberCount[1] != 0)
            {
                numberCount[3] += numberCount[1] / 2;
                numberCount[1] = numberCount[1] % 2;
            }

             //Console.WriteLine("2: " + numberCount[1]);
             //Console.WriteLine("4: " + numberCount[3]);
             //Console.WriteLine("-----------");

            if (numberCount[2] != 0)
            {
                numberCount[3] += numberCount[2];
                numberCount[2] = 0;
            }

             //Console.WriteLine("3: " + numberCount[2]);
             //Console.WriteLine("4: " + numberCount[3]);
             //Console.WriteLine("-----------");

            if ((numberCount[0] != 0) && (numberCount[1]!=0))
            {
                numberCount[3] += numberCount[1];
                numberCount[0] -= numberCount[1];
                if (numberCount[0] != 0) numberCount[0]--;
                numberCount[1] = 0;
            }

             //Console.WriteLine("1: " + numberCount[0]);
             //Console.WriteLine("2: " + numberCount[1]);
             //Console.WriteLine("4: " + numberCount[3]);
             //Console.WriteLine("-----------");

            if (numberCount[1] != 0)
            {
                numberCount[3] += numberCount[1];
                numberCount[1] = 0;
            }

             //Console.WriteLine("2: " + numberCount[1]);
             //Console.WriteLine("4: " + numberCount[3]);
             //Console.WriteLine("-----------");

            if (numberCount[0] != 0)
            {
                numberCount[3] += numberCount[0] / 4;
                numberCount[0] = numberCount[0] % 4;

                if (numberCount[0] != 0)
                {
                    numberCount[3]++;
                    numberCount[0] = 0;
                }
            }

            //Console.WriteLine("1: " + numberCount[0]);
            //Console.WriteLine("4: " + numberCount[3]);
            //Console.WriteLine("-----------");

/*            while (groupNumberArray.Contains(4))
            {
                taxiList.Add(4);
                groupNumberArray.Remove(4);
            }

            while (groupNumberArray.Contains(3))
            {
                if (taxiList.Contains(1))
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += 3;
                    groupNumberArray.Remove(3);
                    continue;
                }

                taxiList.Add(3);
                groupNumberArray.Remove(3);
            }

            while (groupNumberArray.Contains(2))
            {
                if (taxiList.Contains(2))
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += 2;
                    groupNumberArray.Remove(2);
                    continue;
                }

                if (taxiList.Contains(1))
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += 2;
                    groupNumberArray.Remove(2);
                    continue;
                }

                taxiList.Add(2);
                groupNumberArray.Remove(2);
            }

            while (groupNumberArray.Contains(1))
            {
                if (taxiList.Contains(3))
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += 1;
                    groupNumberArray.Remove(1);
                    continue;
                }

                if (taxiList.Contains(2))
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += 1;
                    groupNumberArray.Remove(1);
                    continue;
                }

                if (taxiList.Contains(1))
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += 1;
                    groupNumberArray.Remove(1);
                    continue;
                }

                taxiList.Add(1);
                groupNumberArray.Remove(1);
            }
*/

/*            for (int i = 1; i < n; i++)
            {
                if (taxiList.Contains(3) && (3 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(2) && (2 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(1) && (1 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += groupNumberArray[i];
                    continue;
                }

                taxiList.Add(groupNumberArray[i]);
            }
*/
/*            for (int i = 0; i < taxiList.Count(); i++)
            {
                Console.WriteLine(taxiList[i]);
            }
*/
//            Console.WriteLine(taxiList.Count());
            Console.WriteLine(numberCount[3]);

//             Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string inputString = Console.ReadLine();

            char breakSymbol = ' ';
            string[] stringArray = inputString.Split(breakSymbol);

            byte[] groupNumberArray = new byte[n];

            for (int i = 0; i < n; i++)
            {
                groupNumberArray[i] = Convert.ToByte(stringArray[i]);
            }

            List<int> taxiList = new List<int>() {groupNumberArray[0]};

            for (int i = 1; i < n; i++)
            {
                if (taxiList.Contains(3) && (3 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(2) && (2 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(1) && (1 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += groupNumberArray[i];
                    continue;
                }

                taxiList.Add(groupNumberArray[i]);
            }

/*            for (int i = 0; i < taxiList.Count(); i++)
            {
                Console.WriteLine(taxiList[i]);
            }
*/
            Console.WriteLine(taxiList.Count());

//            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string inputString = Console.ReadLine();

            char breakSymbol = ' ';
            string[] stringArray = inputString.Split(breakSymbol);

            List<byte> groupNumberArray = new List<byte>();

            for (int i = 0; i < n; i++)
            {
                groupNumberArray.Add(Convert.ToByte(stringArray[i]));
            }

            List<byte> taxiList = new List<byte>();

            while (groupNumberArray.Contains(4))
            {
                taxiList.Add(4);
                groupNumberArray.Remove(4);
            }

            while (groupNumberArray.Contains(3))
            {
                if (taxiList.Contains(1))
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += 3;
                    groupNumberArray.Remove(3);
                    continue;
                }

                taxiList.Add(3);
                groupNumberArray.Remove(3);
            }

            while (groupNumberArray.Contains(2))
            {
                if (taxiList.Contains(2))
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += 2;
                    groupNumberArray.Remove(2);
                    continue;
                }

                if (taxiList.Contains(1))
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += 2;
                    groupNumberArray.Remove(2);
                    continue;
                }

                taxiList.Add(2);
                groupNumberArray.Remove(2);
            }

            while (groupNumberArray.Contains(1))
            {
                if (taxiList.Contains(3))
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += 1;
                    groupNumberArray.Remove(1);
                    continue;
                }

                if (taxiList.Contains(2))
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += 1;
                    groupNumberArray.Remove(1);
                    continue;
                }

                if (taxiList.Contains(1))
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += 1;
                    groupNumberArray.Remove(1);
                    continue;
                }

                taxiList.Add(1);
                groupNumberArray.Remove(1);
            }

/*            for (int i = 1; i < n; i++)
            {
                if (taxiList.Contains(3) && (3 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 3)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(2) && (2 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 2)] += groupNumberArray[i];
                    continue;
                }

                if (taxiList.Contains(1) && (1 + groupNumberArray[i]) <= 4)
                {
                    taxiList[taxiList.FindIndex(x => x == 1)] += groupNumberArray[i];
                    continue;
                }

                taxiList.Add(groupNumberArray[i]);
            }
*/
/*            for (int i = 0; i < taxiList.Count(); i++)
            {
                Console.WriteLine(taxiList[i]);
            }
*/
            Console.WriteLine(taxiList.Count());

//            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int groups = Convert.ToInt32(Console.ReadLine());
            int taxi;
            int[] counters = new int[5] { 0, 0, 0, 0, 0 };
            var group = Console.ReadLine().Split().Select(int.Parse).ToArray();

            for (int i = 0; i < groups; i++)
            {
                for ( int j = 1 ; j < 5 ; j++ )
                {
                    if (group[i] == j)
                    {
                        counters[j]++;
                    }
                }
            }

            taxi = counters[3] + counters[4];
            if (counters[1] > counters[3])
            {
                counters[1] -= counters[3];
            }
            else
                counters[1] = 0;

            taxi += ( (counters[1] + counters[2] * 2) / 4 );

            Console.WriteLine(taxi);

            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n1 = s.Count(x => x == 1);
            var n2 = s.Count(x => x == 2);
            var n3 = s.Count(x => x == 3);
            var n4 = s.Count(x => x == 4);
            Console.WriteLine(n4 + n3 + (2 * n2 + Math.Max(0, n1 - n3) + 3) / 4);
        }
    }
}


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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int groups = Convert.ToInt32(Console.ReadLine());
            int taxi;
            int[] counters = new int[5] { 0, 0, 0, 0, 0 };
            var group = Console.ReadLine().Split().Select(int.Parse).ToArray();

            for (int i = 0; i < groups; i++)
            {
                for ( int j = 1 ; j < 5 ; j++ )
                {
                    if (group[i] == j)
                    {
                        counters[j]++;
                    }
                }
            }

            taxi = counters[3] + counters[4];
            if (counters[1] > counters[3])
            {
                counters[1] -= counters[3];
            }
            else
                counters[1] = 0;

            taxi += ( (counters[1] + counters[2] * 2) + 3 ) / 4;

            Console.WriteLine(taxi);

            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int groups = Convert.ToInt32(Console.ReadLine());
            int taxi;
            int[] counters = new int[5] { 0, 0, 0, 0, 0 };
            var group = Console.ReadLine().Split().Select(int.Parse).ToArray();

            for (int i = 0; i < groups; i++)
            {
                for ( int j = 1 ; j < 5 ; j++ )
                {
                    if (group[i] == j)
                    {
                        counters[j]++;
                    }
                }
            }

            taxi = counters[3] + counters[4];
            if (counters[1] > counters[3])
            {
                counters[1] -= counters[3];
            }
            else
                counters[1] = 0;

            taxi += ( (counters[1] + counters[2] * 2) / 4 ) + 1;

            Console.WriteLine(taxi);

            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            long chislo1=0;
            long chislo2=0;
            long chislo3 = 0;
            long chislo4 = 0;
            long answer;
            for (int i = 0; i < str.Length; i++)
            {
                if (long.Parse(str[i]) == 1)
                    chislo1++;
                if (long.Parse(str[i]) == 2)
                    chislo2++;
                if (long.Parse(str[i]) == 3)
                    chislo3++;
                if (long.Parse(str[i]) == 4)
                    chislo4++;
            }
            answer = chislo4;
            answer = answer + chislo2 / 2;
            chislo2 = chislo2 % 2;
            if(chislo1>chislo3)
            {
                answer = answer + Math.Abs(chislo1 - Math.Abs(chislo1 - chislo3));
                chislo1 = chislo1 - chislo3;
                chislo3 = 0;
                if (chislo2 != 0)
                {
                    answer++;
                    if (chislo1 >= 2)
                    { chislo1 = chislo1 - 2; }
                    else
                        if (chislo1 == 1)
                        {
                            chislo1--;
                        }
                    if (chislo1 > 0)
                    {
                        if (chislo1 % 4 == 0)
                        {
                            answer = answer + chislo1 / 4;
                        }
                        else
                        {
                            answer = answer + chislo1 / 4 + 1;
                        }
                    }
                }
                else
                {
                    if (chislo1 % 4 == 0)
                    {
                        answer = answer + chislo1 / 4;
                    }
                    else
                    {
                        answer = answer + chislo1 / 4 + 1;
                    }
                }
            }
            else
            {
                answer = answer + Math.Abs(chislo3 - Math.Abs(chislo3 - chislo1));
                chislo3 = chislo3 - chislo1;
                chislo1 = 0;
                if (chislo2 != 0)
                {
                    answer++;
                        chislo2=0;
                }
                answer = answer + chislo3;
            }
            Console.WriteLine(answer);
            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        public static Boolean IsEmpty(int []arr)
        {
            Boolean Bool=true;
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] != 0)
                    Bool = false;
            }
            return Bool;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int count=0;
            int counter=0;
            int[] arr=new int[str.Length];
            for (int i = 0; i < str.Length; i++)
                arr[i] = int.Parse(str[i]);
            while (!IsEmpty(arr))
            {
                Boolean FullCar = false;
                if (arr[counter] == 4)
                {
                    arr[counter] = 0;
                    count++;
                    FullCar = true;
                }
                if (arr[counter] == 3)
                {
                    arr[counter] = 0;
                    count++;
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if (arr[j] == 1)
                        {
                            arr[j] = 0;
                            FullCar = true;
                            break;
                        }
                    }
                }
                if (arr[counter] == 2)
                {
                    arr[counter]=0;
                    count++;
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if (arr[j] == 2)
                        {
                            arr[j] = 0;
                            FullCar = true;
                            break;
                        }
                    }
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if ((arr[j] == 1)&&(FullCar==false))
                        {
                            arr[j] = 0;
                            break;
                        }
                    }
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if ((arr[j] == 1) && (FullCar == false))
                        {
                            arr[j] = 0;
                            FullCar = true;
                            break;
                        }
                    }
                }
                if (arr[counter] == 1)
                {
                    arr[counter] = 0;
                    count++;
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if (arr[j] == 3)
                        {
                            arr[j] = 0;
                            FullCar = true;
                            break;
                        }
                    }
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if ((arr[j] == 2)&& (FullCar == false))
                        {
                            arr[j] = 0;
                            break;
                        }
                    }
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if ((arr[j] == 1) && (FullCar == false))
                        {
                            arr[j] = 0;
                            break;
                        }
                    }
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if ((arr[j] == 1) && (FullCar == false))
                        {
                            arr[j] = 0;
                            break;
                        }
                    }
                    for (int j = 0; j < arr.Length; j++)
                    {
                        if ((arr[j] == 1) && (FullCar == false))
                        {
                            arr[j] = 0;
                            FullCar = true;
                            break;
                        }
                    }
                }
                counter++;
            }
            Console.WriteLine(count);
                Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            long chislo1=0;
            long chislo2=0;
            long chislo3 = 0;
            long chislo4 = 0;
            long answer;
            for (int i = 0; i < str.Length; i++)
            {
                if (long.Parse(str[i]) == 1)
                    chislo1++;
                if (long.Parse(str[i]) == 2)
                    chislo2++;
                if (long.Parse(str[i]) == 3)
                    chislo3++;
                if (long.Parse(str[i]) == 4)
                    chislo4++;
            }
            answer = chislo4;
            answer = answer + chislo2 / 2;
            chislo2 = chislo2 % 2;
            if(chislo1>chislo3)
            {
                answer = answer + Math.Abs(chislo1 - Math.Abs(chislo1 - chislo3));
                chislo1 = chislo1 - chislo3;
                chislo3 = 0;
                if (chislo2 != 0)
                {
                    answer++;
                    if (chislo1 >= 2)
                    { chislo1 = chislo1 - 2;}
                    else
                        if (chislo1 == 1)
                        {
                            chislo1--;
                        }
                }
            }
            else
            {
                answer = answer + Math.Abs(chislo3 - Math.Abs(chislo3 - chislo1));
                chislo3 = chislo3 - chislo1;
                chislo1 = 0;
                if (chislo2 != 0)
                {
                    answer++;
                        chislo2=0;
                }
                answer = answer + chislo3;
            }
            Console.WriteLine(answer);
            Console.ReadLine();
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            long chislo1=0;
            long chislo2=0;
            long chislo3 = 0;
            long chislo4 = 0;
            long answer;
            for (int i = 0; i < str.Length; i++)
            {
                if (long.Parse(str[i]) == 1)
                    chislo1++;
                if (long.Parse(str[i]) == 2)
                    chislo2++;
                if (long.Parse(str[i]) == 3)
                    chislo3++;
                if (long.Parse(str[i]) == 4)
                    chislo4++;
            }
            answer = chislo4;
            answer = answer + chislo2 / 2;
            chislo2 = chislo2 % 2;
            if(chislo1>chislo3)
            {
                answer = answer + Math.Abs(chislo1 - Math.Abs(chislo1 - chislo3));
                chislo1 = chislo1 - chislo3;
                chislo3 = 0;
                if (chislo2 != 0)
                {
                    answer++;
                    if (chislo1 >= 2)
                    { chislo1 = chislo1 - 2; }
                    else
                        if (chislo1 == 1)
                        {
                            chislo1--;
                        }
                }
                else
                {
                    if (chislo1 % 4 == 0)
                    {
                        answer = answer + chislo1 / 4;
                    }
                    else
                    {
                        answer = answer + chislo1 / 4 + 1;
                    }
                }
            }
            else
            {
                answer = answer + Math.Abs(chislo3 - Math.Abs(chislo3 - chislo1));
                chislo3 = chislo3 - chislo1;
                chislo1 = 0;
                if (chislo2 != 0)
                {
                    answer++;
                        chislo2=0;
                }
                answer = answer + chislo3;
            }
            Console.WriteLine(answer);
            Console.ReadLine();
        }
    }
}


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

namespace CodeForces
{
  internal class Program
  {
    private static void Main(string[] args)
    {
      var n = int.Parse(Console.ReadLine());
      var cars = 0;
      var groups = Console.ReadLine().Split().Select(byte.Parse).ToList();
      while (groups.Any())
      {
        var group = groups[0];
        groups.RemoveAt(0);
        switch (group)
        {
          case 4:
            break;
          case 3:
            groups.Remove(1);
            break;
          case 2:
            if (!groups.Remove(2))
            {
              groups.Remove(1);
              groups.Remove(1);
            }
            break;
          case 1:
            if (!groups.Remove(3))
            {
              if (groups.Count(x => x == 1) == 3)
              {
                groups.Remove(1);
                groups.Remove(1);
                groups.Remove(1);
              }
              else if (groups.Any(x => x == 2) && groups.Any(x => x == 1))
              {
                groups.Remove(2);
                groups.Remove(1);
              }
              else if (groups.Count(x => x == 1) == 2)
              {
                groups.Remove(1);
                groups.Remove(1);
              }
              else if (groups.Any(x => x == 2))
                groups.Remove(2);
              else if (groups.Any(x => x == 1))
                groups.Remove(1);
            }
            break;
        }
        cars++;
      }
      Console.WriteLine(cars);
    }
  }
}