package main

import "fmt"

func main() {
	var n, k int
	var a [5]int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&k)
		a[k]++
	}
	var res = a[4] + a[3] + (a[2]+1)/2
	a[1] -= a[3]
	if a[2]%2 != 0 {
		a[1] -= 2
	}
	if a[1] > 0 {
		res += ((a[1] + 3) / 4)
	}

	fmt.Println(res)

}

package main

import (
	"fmt"
	"sort"
)

func main() {

	var n, i int64

	fmt.Scan(&n)

	var groups []int
	var s int

	for ; i < n; i++ {
		fmt.Scan(&s)
		groups = append(groups, s)
	}
	sort.Ints(groups)

	p := 0
	for i := (len(groups) - 1); i > 0 && p < i; i-- {
		if groups[i]+groups[p] <= 4 {
			groups[i] = groups[i] + groups[p]
			groups[p] = 0
			p++
			if groups[i] <= 3 {
				i++
			}
		}
	}

	count := 0
	for i := len(groups) - 1; i >= 0; i-- {
		if groups[i] == 0 {
			break
		}
		count++
	}
	fmt.Println(count)
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	Group1 = 0
	Group2 = 1
	Group3 = 2
	Group4 = 3
)

func readGroups() []int64 {
	reader := bufio.NewReader(os.Stdin)
	line, _, _ := reader.ReadLine()
	count, _ := strconv.ParseInt(string(line), 10, 64)

	wholeLine, err := reader.ReadBytes('\n')
	if err != nil {
		log.Fatal("ERROR" + err.Error())
	}

	list := make([]int64, count)

	values := strings.Split(string(wholeLine), " ")

	for i, v := range values {
		list[i] = int64([]byte(v)[0] - 48)
	}

	return list
}

func main() {
	groups := readGroups()
	counts := [4]int{0, 0, 0, 0}

	for _, g := range groups {
		counts[g-1]++
	}

	cars := counts[Group4]
	counts[Group4] = 0

	min1And3 := int(math.Min(float64(counts[Group1]), float64(counts[Group3])))

	cars += min1And3
	counts[Group1] -= min1And3
	counts[Group3] -= min1And3

	if counts[Group3] > 0 {
		cars += counts[Group3]
		counts[Group3] = 0
	}

	carsOf2 := counts[Group2] / 2
	cars += carsOf2
	counts[Group2] -= carsOf2 * 2

	if counts[Group2] == 1 {
		cars++
		counts[Group2] = 0

		if counts[Group1] == 1 {
			counts[Group1]--
		} else if counts[Group1] >= 2 {
			counts[Group1] -= 2
		}
	}

	cars1 := counts[Group1] / 4
	cars += cars1

	counts[Group1] -= cars1 * 4

	if counts[Group1] <= 4 && counts[Group1] > 0 {
		cars++
		counts[Group1] = 0
	}

	cars += counts[Group1] % 4

	fmt.Println(cars)
}

package main

import "fmt"

func main() {
	var n, k int
	var a [5]int
	fmt.Scan(&n)
	for i := 0; i < n; i ++ {
		fmt.Scan(&k)
		a[k] ++
	}
	var res = a[3] + a[4] + (a[2]+1)/2
	a[1] -= a[3]
	if a[2] % 2 != 0 {
		a[1] -= 2
	}
	if a[1] > 0 {
		res += (a[1]+3) / 4;
	}
	fmt.Println(res)
}

package main

import "fmt"

func ReadN(all []int, i, n int) {
	if n == 0 {
		return
	}
	if m, err := Scan(&all[i]); m != 1 {
		panic(err)
	}
	ReadN(all, i+1, n-1)
}

func Scan(a *int) (int, error) {
	return fmt.Scan(a)
}

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

func main() {
	var n int
	fmt.Scanf("%d", &n)
	all := make([]int, n)
	ReadN(all, 0, n)
	counts := make([]int, 5, 5)
	answer := 0
	for _, v := range all {
		counts[v]++
	}
	answer += counts[4]
	m := min(counts[1], counts[3])
	answer += m
	counts[1] -= m
	counts[3] -= m
	c2 := counts[2]
	m2 := counts[2] / 2
	answer += m2
	counts[2] = 0
	if c2%2 > 0 {
		counts[2]++
	}
	m1 := min(counts[1], counts[2])
	answer += m1
	counts[1] -= m1
	if c2%2 > 0 && counts[1] > 0 {
		counts[1]--
	}
	counts[2] -= m1
	r := 0
	if counts[1]%4 > 0 {
		r++
	}
	answer += counts[1]/4 + r
	answer += counts[2]
	answer += counts[3]
	fmt.Println(answer)
}

package main

import (
	"io"
	"os"
	"fmt"
)

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

func process(in io.Reader, out io.Writer) {
	var n int
	fmt.Fscan(in, &n)

	a := [5]int{0, 0, 0, 0, 0}

	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(in, &x)
		a[x]++
	}

	count := 0
	count += a[4]

	c := min(a[1], a[3])

	count += c
	a[1] -= c
	a[3] -= c

	c = a[2] / 2
	count += c
	a[2] = a[2] % 2

	c = min(a[1] / 2, a[2])
	a[1] -= c * 2
	a[2] -= c
	count += c
//	fmt.Fprintf(out, "%d\n", c)

	if a[1] > 0 && a[2] > 0 {
		a[1] = 0
		a[2] -= 1
		count += 1
	}

	if a[1] % 4 > 0 {
		count += 1
	}
	count += a[1] / 4

	if a[2] % 2 > 0 {
		count += 1
	}
	count += a[2] / 2

	count += a[3]

	fmt.Fprintf(out, "%d\n", count)
}

func main() {
	process(os.Stdin, os.Stdout)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)
	if n <= 0 {
		panic("bad n:" + string(n))
	}
	var nn [5]int
	for i := 0; i < n; i++ {
		var s int
		fmt.Scan(&s)
		if s < 1 || s > 4 {
			panic("bad s:" + string(s))
		}
		nn[s]++
	}
	count := 0
	// 4 4 4 4
	count += nn[4]
	// 31 31 31 31
	count += nn[3]
	nn[1] -= nn[3]
	// 22 22 22 22
	count += nn[2] / 2
	// 211
	if nn[2] % 2 != 0 {
		count++
		nn[1] -= 2
	}
	// 1111 1111 1111 1
	if nn[1] > 0 {
		count += nn[1] / 4
		if nn[1] % 4 != 0 {
			count++
		}
	}
	fmt.Println(count)
}

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

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

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

Examples
Input
5
1 2 4 3 3

Output
4

Input
8
2 3 4 4 2 1 3 1

Output
5

Note
In the first test we can sort the children into four cars like this:

    the third group (consisting of four children),
    the fourth group (consisting of three children),
    the fifth group (consisting of three children),
    the first and the second group (consisting of one and two children, correspondingly).

There are other ways to sort the groups into four cars.
*/
package main

import (
	"fmt"
)

func main() {
	var n, total int
	fmt.Scan(&n)

	m := map[int]int{}
	for ; n > 0; n-- {
		var a int
		fmt.Scan(&a)
		m[a]++
	}

	total += m[4] + m[3] + (m[2]+1)/2
	m[1] -= m[3] + (m[2]%2)*2
	if m[1] > 0 {
		total += (m[1] + 3) / 4
	}
	fmt.Print(total)
}

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

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

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

Examples
Input
5
1 2 4 3 3

Output
4

Input
8
2 3 4 4 2 1 3 1

Output
5

Note
In the first test we can sort the children into four cars like this:

    the third group (consisting of four children),
    the fourth group (consisting of three children),
    the fifth group (consisting of three children),
    the first and the second group (consisting of one and two children, correspondingly).

There are other ways to sort the groups into four cars.
*/
package main

import (
	"fmt"
)

func main() {
	var n, a, total int
	fmt.Scan(&n)

	m := map[int]int{}
	for ; n > 0; n-- {
		fmt.Scan(&a)
		m[a]++
	}

	total += m[4] + m[3] + (m[2]+1)/2
	m[1] -= m[3] + (m[2]%2)*2
	if m[1] > 0 {
		total += (m[1] + 3) / 4
	}
	fmt.Print(total)
}

package main

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	_ = toInt(scanner.Bytes())
	groups := []int{0,0,0,0}
	for scanner.Scan() {
		group := toInt(scanner.Bytes())
		groups[group - 1]++
	}
	count := groups[3] + groups[2]
	if groups[2] > groups[0] {
		groups[0] = 0
	}else {
		groups[0] = groups[0] - groups[2]
	}
	if groups[1] % 2 == 0 {
		count += groups[1] / 2
		groups[1] = 0
	}else {
		count += (groups[1] - 1) / 2
		groups[1] = 1
	}
	rem := groups[1] * 2 + groups[0]
	if rem % 4 == 0 {
		count += rem / 4
	}else {
		count += rem / 4 + 1
	}
	fmt.Println(count)
}

package main

import "fmt"

func main() {
	var n int
	var temp int
	fmt.Scanf("%d\n", &n)
	s := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &temp)
		s[temp] += 1
	}
	count := s[4] + s[3] + s[2]/2
	if s[2]%2 == 1 {
		count += 1
		s[1] -= 2
	}
	s[1] -= s[3]
	if s[1] > 0 {
		count += (s[1] + 3) / 4
	}
	fmt.Println(count)
}

// Choose the 3 and 1 as much as possible. And
//  let 2 combine with themselves. If there are more 1s and 2s,
//   let two 1s combine with 2, and every four 1s take same taxi.

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var count map[int]int = make(map[int]int, n)
	var x int
	for i := 0; i < n; i++ {
		fmt.Scan(&x)
		count[x]++
	}
	var taxi int = 0
	if count[1] <= count[3] {
		taxi += count[1]
		count[3] -= count[1]
		count[1] = 0
		taxi += count[3]
	} else {
		taxi += count[3]
		count[1] -= count[3]
		count[3] = 0
		//handle rem ones
	}
	taxi += count[2] / 2
	count[2] = count[2] % 2
	if count[2] > 0 {
		taxi++
		count[2] = 0
		count[1] = count[1] - 2
	}
	if count[1] > 0 {
		taxi += count[1] / 4
		if count[1]%4 > 0 {
			taxi++
			count[1] = 0
		}
	}
	taxi += count[4]
	fmt.Println(taxi)
}

// 3
// 1 1 2

package main

import "fmt"

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

func main() {
    var n int = 0
    var groups = [5]int{0, 0, 0, 0, 0}

    fmt.Scanf("%d\n", &n)
    for i := 0; i < n; i++ {
        var g int
        fmt.Scanf("%d", &g)
        groups[g]++
    }

    result := groups[4] + groups[3]
    groups[1] = max(0, groups[1] - groups[3])
    result += (groups[2] + 1) / 2
    groups[1] = max(0, groups[1] - groups[2] % 2 * 2)
    result += (groups[1] + 3) / 4

    fmt.Println(result)
}

package main
import (
	"fmt"
)
func main() {
	var n, x int
	num1,num2,num3,counter := 0,0,0,0
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		fmt.Scan(&x)
		if (x==1){
		num1++
		} else {}
		if (x==2){
		num2++
		} else {}
		if (x==3){
		num3++
		} else {}
		if (x==4){
		counter++
		} else {}
	}
	if (num3>=num1){
        	counter+=num3
        	counter+=((num2+1)/2)
	} else {}
	if (num3<num1){
            counter+=num3
            num1=num1-num3
            counter+=(num2/2)
            num2=num2%2
            if (num2==1){
                counter+=(num1+1)/4+1;
            } else {}
            if (num2==0){
                if (num1>0){
                    counter+=(num1-1)/4+1;
                }else {}
                if (num1==0){
                    counter=counter+0;
                }else {}
            }else {}
        }
        fmt.Println(counter)
}

//  URL: http://codeforces.com/problemset/problem/158/B
//  PROBLEM RESTATEMENT:
//      Given a[1], a[2] .. a[n] s.t a[i] ∈ [1, 4].
//      Divide the elements into the minimum # of groups of 4.
//  APPROACH
//      (1) 4s must be in their own group.
//      (2) 3s at most can be joined with a 1.
//      (3) 2s can be joined with a 2, or two 1s.
//      (4) Any remaining 1s can be grouped together.

package main

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

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func solve(m map[int]int) int {
	count := m[4] + m[3]
	// Remove 1s grouped with 3s.
	m[1] -= min(m[3], m[1])
	// Count groups of 2s.
	count += m[2] / 2
	// Count spare group of 2 (and potentially up to two 1s).
	if m[2]%2 != 0 {
		count += 1
		m[1] -= min(m[1], 2)
	}
	// Count the remaining 1s.
	count += m[1] / 4
	if m[1]%4 != 0 {
		count += 1
	}
	return count
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n, s int
	fmt.Fscanf(reader, "%d\n", &n)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d ", &s)
		m[s] += 1
	}
	fmt.Fprintf(writer, "%d\n", solve(m))
}

package main

import "fmt"

func main() {
    var n, k int
    a := [5]int{}
    fmt.Scan(&n)
    for i := 0; i < n; i ++ {
        fmt.Scan(&k)
        a[k] ++
    }
    res := a[3] + a[4] + a[2]/2
    if a[2] % 2 == 1 {
        res ++
        a[1] -= 2
    }
    a[1] -= a[3]
    if a[1] > 0 {
        res += (a[1] + 3) / 4
    }
    fmt.Println(res)
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)

    cnt := make(map[int]int)
    for i := 0 ; i < n ; i++ {
        var s int
        fmt.Scan(&s)
        cnt[s]++
    }
    ans := cnt[4] + cnt[3] + cnt[2]/2
    cnt[1] -= cnt[3]

    if cnt[2] % 2 > 0 {
        cnt[1] -= 2
        ans++
    }

    if cnt[1] > 0 {
        ans  += cnt[1] / 4
    }

    if cnt[1] % 4 > 0 {
        ans++
    }

    fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n int
	var group int
	var g3, g2, g1 int

	cars := 0
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&group)
		switch group {
		case 4:
			cars++
		case 1:
			g1++
		case 2:
			g2++
		case 3:
			g3++
		}
	}

	cars += g3
	if g1 < g3 {
		g1 = 0
	} else {
		g1 = g1 - g3
	}

	cars += g2 / 2
	if g2%2 == 1 {
		cars++
		if g1 < 2 {
			g1 = 0
		} else {
			g1 = g1 - 2
		}
	}

	cars += g1 / 4
	if g1%4 != 0 {
		cars++
	}
	fmt.Println(cars)
}

package main

import "fmt"

func main() {
	var n, tp int
	fmt.Scan(&n)
	counter := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Scan(&tp)
		counter[tp]++
	}
	counter[1] -= counter[3]
	total := counter[3] + counter[4] + counter[2]/2
	if counter[2]%2 == 1 {
		total++
		counter[1] -= 2
	}
	if counter[1] < 0 {
		counter[1] = 0
	}
	total += counter[1] / 4
	if counter[1]%4 != 0 {
		total++
	}
	fmt.Println(total)
}

package main

import "fmt"

func main() {
	var n int
	cnt := make([]int, 5)
	fmt.Scan(&n)
	for ; n > 0; n-- {
		var tp int
		fmt.Scan(&tp)
		cnt[tp]++
	}
	result := cnt[3] + cnt[4] + cnt[2]/2
	if cnt[2]%2 > 0 {
		result++
	}
	empty_seat_one := cnt[3]
	empty_seat_one += (cnt[2] % 2) * 2
	cnt[1] -= empty_seat_one
	if cnt[1] < 0 {
		cnt[1] = 0
	}
	result += cnt[1] / 4
	if cnt[1]%4 > 0 {
		result++
	}
	fmt.Println(result)
}

package main

import (
	"fmt"
)

func main() {
	var n, inp int
	ind1, ind2, ind3, ind4, taxi := 0, 0, 0, 0, 0
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&inp)
		switch inp {
		case 1:
			ind1++
		case 2:
			ind2++
		case 3:
			ind3++
		case 4:
			ind4++
		}
	}
	taxi += ind4  //4 person
	if ind3 > 0 { //3 person
		if ind1 > 0 {
			if ind1 > ind3 {
				taxi += ind3
				ind1 -= ind3
			} else {
				taxi += ind3
				ind1 = 0
			}
		} else {
			taxi += ind3
		}
	}
	if ind2 > 0 {
		if ind2%2 == 0 {
			taxi += ind2 / 2
		} else {
			taxi += ind2 / 2
			taxi += 1 //ind2 sisa 1
			if ind1 > 0 {
				ind1 -= 2
			}
		}
	}
	if ind1 > 0 {
		if ind1%4 == 0 {
			taxi += ind1 / 4
		} else {
			taxi += ind1 / 4
			taxi += 1
		}
	}
	fmt.Print(taxi)
}

package main

import (
	"fmt"
	"os"
)

func min(a, b int) int {
	if a <= b {
		return a
	} else {
		return b
	}
}

func main() {

	n := 0

	var one, two, three, four int

	fmt.Scan(&n)

	for i := 1; i <= n; i++ {
		x := 0
		fmt.Scan(&x)

		if x == 1 {
			one++
		} else if x == 2 {
			two++
		} else if x == 3 {
			three++
		} else {
			four++
		}
	}

	res := 0

	res += min(one, three)

	mto := min(one, three)

	one -= mto
	three -= mto

	res += two / 2
	two %= 2

	res += four
	four = 0

	if three != 0 && one == 0 {
		res += three
		res += two
	} else {
		if two == 1 {
			if one > 2 {
				res++
				one -= 2
				res += one / 4
				if one%4 != 0 {
					res++
				}
			} else {
				res++
			}
		} else {
			res += one / 4
			if one%4 != 0 {
				res++
			}
		}
	}
	fmt.Println(res)
	os.Exit(0)
}

package main

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

var in = bufio.NewReader(os.Stdin)

func rint(pint *int) {
	fmt.Fscan(in, pint)
}

func main() {
	var n int
	var c = [5]int{}
	rint(&n)
	for i := 0; i < n; i++ {
		var x int
		rint(&x)
		c[x]++
	}
	var ans = c[4] + c[3] + (c[2]+1)/2
	c[1] -= c[3] + c[2]%2*2
	if c[1] > 0 {
		ans += (c[1] + 3) / 4
	}
	fmt.Println(ans)
}

package main

import "fmt"

func min(x int, y int) int {
    if x < y {
        return x
    }
    return y
}

func main() {
    var n int
    var c = [5]int{}
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        var x int
        fmt.Scan(&x)
        c[x]++
    }
    var ans = c[4] + c[3] + (c[2]+1)/2
    c[1] -= c[3] + c[2]%2*2
    if c[1] > 0 {
        ans += (c[1]+3)/4
    }
    fmt.Println(ans)
}

package main

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

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var n int
	var c = [5]int{}
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(in, &x)
		c[x]++
	}
	var ans = c[4] + c[3] + (c[2]+1)/2
	c[1] -= c[3] + c[2]%2*2
	if c[1] > 0 {
		ans += (c[1]+3)/4
	}
	fmt.Println(ans)
}

package main

import (
  "fmt"
)

func main() {
  var n,a,b,c,d,p,sum int
  fmt.Scan(&n)
  for i := 0; i < n; i++ {
    fmt.Scan(&p)
    switch{
    case p==1:
      a++
    case p==2:
      b++
    case p==3:
      c++
    case p==4:
      d++
    }
  }

  sum = d
  d -= d

  if a < c {
    sum += a
    c -= a
    a -= a
  } else {
    sum += c
    a -= c
    c -= c
  }

  sum += b/2
  b -= (b/2)*2

  if a != 0 && b != 0 {
    for a>=2 && b>=1 {
      a -= 2
      b -= 1
      sum ++
    }
  }

  sum += a/4
  a -= (a/4)*4

  if a < b {
    sum += a
    b -= a
    a -= a
  } else {
    sum += b
    a -= b
    b -= b
  }

  if a < 4 && a!=0 {
    sum++
    a = 0
  }

  sum += a + b + c + d
  fmt.Print(sum)
}

// 7.Codeforce 158b-Michael542
package main

import (
    "fmt"
    "sort"
)

func main() {
    var a /*tmp,*/, n, car, sisa int
    fmt.Scan(&a)
    z := make([]int, a)
    n = a - 1
    m := 0
    for y := 0; y < a; y++ {
        fmt.Scan(&z[y])
    }
    /*for x := 0; x < a; x++ {
            for e := 0; e < a-1; e++ {
                if z[x] > z[e] {
                    tmp = z[x]
                    z[x] = z[e]
                    z[e] = tmp
                }
            }
    }*/
    sort.Sort(sort.Reverse(sort.IntSlice(z)))
    if m == n {
        car++
    } else {
        for m <= n {
            sisa = 4 - z[m]
            for sisa >= z[n] && m <= n && n != m {
                sisa -= z[n]
                n--
            }
            car++
            m++
        }
    }
    fmt.Println(car)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	taxiCount := 0
	count3 := 0
	count2 := 0
	count1 := 0
	for i := 0; i < n; i++ {
		scanner.Scan()
		s := scanner.Text()
		if s == "4" {
			taxiCount++
			continue
		}
		si, _ := strconv.Atoi(s)
		switch si {
		case 1:
			count1++
		case 2:
			count2++
		case 3:
			count3++
		}
	}
	for count3 > 0 {
		count3--
		if count1 >0 {
			count1--
		}
		taxiCount++
	}

	cap := 0
	for count2 > 0 {
		cap += 2
		if cap == 4 {
			taxiCount++
			cap = 0
		}
		count2--
	}
	for count1 >0 {
		cap++
		if cap == 4 {
			taxiCount++
			cap = 0
		}
		count1--
	}
	if cap > 0 {
		taxiCount++
	}
	fmt.Println(taxiCount)
}

package main

import (
	"fmt"
)

func main() {
	var testcount, count, count1, count2, count3, a, tmp int
	var arr []int
	fmt.Scanf("%d\n", &testcount)
	for i := 0; i < testcount; i++ {
		fmt.Scanf("%d", &a)
		switch a {
		case 1:
			if count3 > 0 {
				count3--
				count++
			} else {
				count1++
			}
		case 2:
			if count2 > 0 {
				count2--
				count++
			} else {
				count2++
			}
		case 3:
			if count1 > 0 {
				count1--
				count++
			} else {
				count3++
			}
		case 4:
			count++
		}
	}
	for i := 0; i < count1; i++ {
		arr = append(arr, 1)
	}
	for i := 0; i < count2; i++ {
		arr = append(arr, 2)
	}
	for i := 0; i < count3; i++ {
		arr = append(arr, 3)
	}
	for i := 0; i < len(arr); i++ {
		if tmp+arr[i] > 4 {
			count++
			tmp = arr[i]
		} else {
			tmp = tmp + arr[i]
			if tmp == 4 {
				count++
				tmp = 0
			}
		}
	}
	if tmp > 0 {
		count++
	}
	fmt.Println(count)
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(one int, two int, three int, four int) int {
	//fmt.Println(one, two, three, four)
	if three >= one {
		three -= one
		four += one
		one = 0
	} else {
		one -= three
		four += three
		three = 0
		if two%2 == 1 {
			if one >= 2 {
				one -= 2
			} else {
				one = 0
			}
			two--
			four++
		}
	}
	//fmt.Println(one, two, three, four)
	if two%2 == 1 {
		two--
		four++
	}
	if one%4 > 0 {
		four++
		one -= one % 4
	}
	return four + (three + (two)/2 + (one / 4))
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var n, ret int
	var one, two, three, four int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())

	for x := 0; x < n; x++ {
		scanner.Scan()
		temp := fastGetInt(scanner.Bytes())
		if temp == 4 {
			four++
		}
		if temp == 3 {
			three++
		}
		if temp == 2 {
			two++
		}
		if temp == 1 {
			one++
		}
	}
	//======================================================
	ret = solution(one, two, three, four)
	//==================== OUTPUT ==========================
	fmt.Println(ret)
}

package main

import "fmt"

func main() {
    var n,a,one,two,ans int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        if a == 4 {
            ans++
        } else if a == 3 {
            ans++
            one--
        } else if a == 2 {
            two++
            if two == 2 {
                ans++
                two = 0
            }
        } else {
            one++
        }
    }
    ans += two
    one -= (2*two)
    if one > 0 {
        ans += one/4
        if one%4 != 0 { ans++ }
    }
    fmt.Println(ans)
}

package main

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

//TODO, haven't ac yet
func main() {
	reader := bufio.NewReader(os.Stdin)
	var count, ret int
	fmt.Fscanln(reader, &count)
	si := make([]int, count)
	for i := 0; i < count; i++ {
		fmt.Fscan(reader, &si[i])
	}

	sort.Slice(si, func(i, j int) bool {
		return si[i] > si[j]
	})

	s := count - 1
	for i := 0; i < count; i++ {
		if si[i] == 4 { //满四个人直接发车
			ret++
		} else if si[i] < 4 && si[i] > 0 { // 不足四个的
			k := si[i] + si[s] //大的加小的
			if k > 4 {         //发车
				ret++
			} else if k == 4 {
				ret++
				si[s] = 0
				s--
			} else if k < 4 { // 在人数少的组找到一些组，使总人数最接近四个
				si[s] = 0
				for s--; s > i; s-- {
					k += si[s]
					if k > 4 {
						break
					} else if k == 4 {
						si[s] = 0
						break
					} else {
						si[s] = 0
					}
				}
				ret++
			}
		}
	}

	fmt.Println(ret)
}

package main

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

func main() {
	//os.Stdin, _ = os.Open("input.txt")
	in := bufio.NewReader(os.Stdin)
	in.ReadString('\n')
	s, _ := in.ReadString('\n')
	str := strings.Fields(s)

	var n1, n2, n3, n4 int
	for _, v := range str {
		switch v {
		case "1":
			n1++
		case "2":
			n2++
		case "3":
			n3++
		case "4":
			n4++
		}
	}

	taxi := n4
	if n3-n1 >= 0 {
		taxi += n3
		n1 = 0
	} else {
		taxi += n3
		n1 -= n3
	}
	taxi += n2 / 2
	left := n2%2*2 + n1
	if left > 0 && left <= 4 {
		taxi++
	} else {
		taxi += left / 4
		if left%4 > 0 {
			taxi++
		}
	}

	fmt.Println(taxi)

}

package main

import "fmt"

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

func task_solution(a []int) (ans int) {
	groups := []int{0, 0, 0, 0}
	for _, e := range a {
		groups[e-1] += 1
	}

	// группы из 4 полностью влезают в 1 такси
	ans += groups[4-1]

	// группы из 3 могут взять к себе одиночек
	// или поехать в неполном такси
	ans += groups[3-1]
	groups[1-1] -= min(groups[3-1], groups[1-1])

	// группы из 2 могут скооперироваться
	// или добрать к себе одиночек
	quotient := groups[2-1] / 2
	remainder := groups[2-1] % 2
	ans += quotient
	ans += min(remainder, 1)
	groups[1-1] -= min(remainder*2, groups[1-1])

	// группы из одиночек заказывают необходимое кол-во такси
	ans += groups[1-1] / 4
	ans += min(groups[1-1]%4, 1)

	return ans
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	a := []int{}
	for i := 0; i < n; i += 1 {
		var s int
		if _, err := fmt.Scan(&s); err != nil {
			panic(err)
		}
		a = append(a, s)
	}

	fmt.Println(task_solution(a))
}

package main

// https://codeforces.com/problemset/problem/158/B

/*
* комментарии к решению
* Т.к. (1 ≤ si ≤ 4) жестко задан одним символом, то профитнее обработать входной поток как []byte
* Т.к. размер групп не произвольное число,
* то можно описать все возможные комбинации без перебора:
* 1) Группы из 4-х человек полностью влезают в такси
* 2) Группы из 3-х человек могут добрать к себе одиночек или поехать втроём
* 3) Группы из 2-х человек могут скооперироваться и при нечетном их кол-ве добрать одиночек
* 4) Оставшиеся одиночки просто заказывают минимальное необходимое кол-во такси
 */

import (
	"fmt"
	"io/ioutil"
	"os"
)

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

func extractGroups(line []byte) []int {
	ans := []int{0, 0, 0, 0}
	for _, e := range line {
		switch e {
		case '1':
			ans[0] += 1
		case '2':
			ans[1] += 1
		case '3':
			ans[2] += 1
		case '4':
			ans[3] += 1
		}
	}
	return ans
}

func taskSolution(in []byte) (ans int) {
	groups := []int{0, 0, 0, 0}
	groups = extractGroups(in)

	ans += groups[4-1]

	ans += groups[3-1]
	groups[1-1] -= min(groups[3-1], groups[1-1])

	quotient := groups[2-1] / 2
	remainder := groups[2-1] % 2
	ans += quotient
	ans += min(remainder, 1)
	groups[1-1] -= min(remainder*2, groups[1-1])

	ans += groups[1-1] / 4
	ans += min(groups[1-1]%4, 1)

	return ans
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	inRaw, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		panic(err)
	}

	fmt.Println(taskSolution(inRaw))
}

// Author: sighduck
// URL:	https://codeforces.com/problemset/problem/158/B

package main

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

func getCounts(s []int) map[int]int {
	m := make(map[int]int)
	for _, elem := range s {
		m[elem] += 1
	}
	return m
}

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func ceilDiv(x int, y int) int {
	return (x + y - 1) / y
}

func _Solve(ones, twos, threes, answer int) int {
	if threes > 0 {
		return _Solve(ones-min(threes, ones), twos, 0, answer+threes)
	}
	if twos > 1 {
		return _Solve(ones, twos%2, threes, answer+twos/2)
	}
	if ones >= 4 {
		return _Solve(ones%4, twos, threes, answer+ones/4)
	}
	if twos == 1 {
		return _Solve(ones-min(2, ones), 0, threes, answer+1)
	}
	return answer + ceilDiv(ones, 4)
}

func Solve(n int, s []int) int {
	count := getCounts(s)
	ones, twos, threes, fours := count[1], count[2], count[3], count[4]
	return _Solve(ones, twos, threes, fours)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &s[i])
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, s))
}

package main

import (
	"fmt"
)

func main() {
	var n, s int
	fmt.Scanln(&n)

	var four, three, two, one []int
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		switch s {
		case 4:
			four = append(four, s)
		case 3:
			three = append(three, s)
		case 2:
			two = append(two, s)
		case 1:
			one = append(one, s)
		}
	}

	taxis := len(four)

	len3 := len(three)
	len2 := len(two)
	len1 := len(one)

	taxis += len3
	len1 -= len3

	taxis += len2 / 2
	if len2%2 == 1 {
		taxis++
		len1 -= 2
	}

	if len1 > 0 {
		taxis += len1 / 4
		if len1%4 > 0 {
			taxis++
		}
	}

	fmt.Println(taxis)
}

package main

import "fmt"

func main() {
    var N int
    fmt.Scan(&N)
    var cnt [4]int
    for i := 0; i < N; i++ {
        var tmp int
        fmt.Scan(&tmp)
        cnt[tmp - 1]++
    }
    res := cnt[3] + cnt[2]
    cnt[0] = cnt[0] - cnt[2]
    if cnt[0] < 0 {
        cnt[0] = 0
    }
    if cnt[1] > 0 || cnt[0] > 0 {
        res = res + (cnt[1] * 2 + cnt[0] - 1) / 4 + 1
    }
    fmt.Println(res)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var a [5]int
	for i := 0; i < n; i++ {
		var k int
		fmt.Scan(&k)
		a[k]++
	}
	var ans = a[4] + a[3] + (a[2]+1)>>1
	a[1] -= a[3]
	if a[2]&1 != 0 {
		a[1] -= 2
	}
	if a[1] > 0 {
		ans += (a[1] + 3) >> 2
	}
	fmt.Println(ans)
}

package main

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

var s [5]int

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, a, cnt int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a)
		if a == 4 {
			cnt++
		} else {
			s[a]++
		}
	}
	cnt += s[2] / 2
	if s[2]%2 != 0 {
		if s[3] > s[1] {
			cnt += s[3] + 1
		} else {
			i := s[1] - s[3]
			if (i+2)%4 == 0 {
				cnt += s[3] + (i+2)/4
			} else {
				cnt += s[3] + (i+2)/4 + 1
			}
		}
	} else {
		if s[3] > s[1] {
			cnt += s[3]
		} else {
			i := s[1] - s[3]
			if i%4 == 0 {
				cnt += s[3] + i/4
			} else {
				cnt += s[3] + i/4 + 1
			}
		}
	}
	fmt.Println(cnt)
}

package main

import "fmt"

func main() {

	var n int
	fmt.Scan(&n)

	groups := make([]int, 4)
	var s int
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		groups[s-1]++
	}

	taxi := groups[3]
	groups[3] = 0

	taxi += groups[2]
	t := groups[2]
	groups[2] = 0
	if groups[0] < t {
		t = groups[0]
	}
	groups[0] -= t

	t = groups[1] / 2
	taxi += t
	groups[1] -= t * 2

	if groups[1] != 0 {
		taxi++
		groups[0] -= 2
	}

	if groups[0] > 0 {
		taxi += int((float32(groups[0]) + 3) / 4)
	}

	fmt.Print(taxi)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var taxi = make([]int, 4)
	for i := 0; i < n; i++ {
		var cur int
		fmt.Scan(&cur)
		taxi[cur-1]++
	}
	sum := taxi[3] + taxi[2]
	if taxi[0] -= taxi[2]; taxi[0] < 0 {
		taxi[0] = 0
	}
	sum += (taxi[1]*2 + taxi[0] + 3) / 4
	fmt.Println(sum)
}

package main

import (
	"fmt"
	"math"
)

func main () {
	var n int
	var a int
	fmt.Scanf("%d\n", &n)
	f := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		f[a]++;
	}
	noCars := f[4]
	f[4] = 0
	oneThree := int(math.Min(float64(f[1]),float64(f[3])))
	f[1] -= oneThree
	f[3] -= oneThree
	noCars += oneThree
	noCars += f[3]
	f[3] = 0
	noCars += f[2]/2
	f[2] -= (f[2]/2)*2
	if f[2] == 1 {
		noCars++
		if f[1] == 1 {
			f[1] = 0
			f[2] = 0
		}else if f[1] >= 2 {
			f[1] -= 2
			f[2] = 0
		}
	}
	if f[1] > 0 {
		noCars += f[1] / 4
		if f[1] % 4 > 0 {
			noCars ++
		}
	}
	fmt.Printf("%d", noCars)

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

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

const maxCapacity = 200002

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)
	scanner.Scan()
	scanner.Scan()
	m := map[string]int{"1": 0, "2": 0, "3": 0, "4": 0}
	for _, v := range strings.Split(scanner.Text(), " ") {
		m[v]++
	}
	res := 0
	res += m["4"]
	res += m["3"]
	m["1"] -= m["3"]
	res += m["2"] / 2
	if m["2"]%2 == 1 {
		res += 1
		m["1"] -= 2
	}
	res += max(0, int(math.Ceil(float64(m["1"])/float64(4))))
	fmt.Print(res)
}

package main

import (
	"fmt"
)

func remain(x int) int {
	var base int = x / 4
	if base * 4 < x {
		return base + 1
	}
	return base
}

func main() {
	var n, num, ans int
	var group [5]int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&num)
		group[num]++
	}
	ans += group[4]
	if group[3] > group[1] {
		ans += group[1]
		group[3] -= group[1]
		group[1] = 0
	} else {
		ans += group[3]
		group[1] -= group[3]
		group[3] = 0
	}
	ans += group[3]
	ans += remain(group[1] + group[2] * 2)
	fmt.Print(ans)
}

// esetszetvalasztas
package main

import (
	"fmt"
)

var (
	frek [5]int32
)

func main() {

	var (
		n, i, s, ans int32
	)

	fmt.Scan(&n)
	for i = 1; i <= n; i++ {
		fmt.Scan(&s)
		frek[s]++
	}

	ans = frek[4]
	s = frek[1]
	if frek[3] < s {
		s = frek[3]
	}
	ans += s
	frek[1] -= s
	frek[3] -= s
	ans += frek[3]

	if 1 == frek[2]%2 {
		ans++
		frek[2]--
		if frek[1] > 0 {
			frek[1] -= 2
		}
		if frek[1] < 0 {
			frek[1] = 0
		}

	}
	ans += frek[2] / 2
	ans += frek[1] / 4
	if frek[1]%4 > 0 {
		ans++
	}

	fmt.Println(ans)
}

package main

import (
	"fmt"
	"log"
)

func scanf(format string, args ...interface{}) {
	_, err := fmt.Scanf(format, args...)
	if err != nil {
		fmt.Printf("%v\n", err)
		log.Fatal(err)
	}
}

//5
//1 2 4 3 3
//0
//1 0
//2 1
//3 0
//4 0 o
//tc: 3
//n: 1
//so: 0

func main() {
	var n int
	scanf("%d\n", &n)

	groups := make([]int, 5)

	for i := 0; i < n; i++ {
		var groupSize int
		scanf("%d", &groupSize)
		groups[groupSize]++
	}

	taxiCount := 0
	seatsOccupied := 0
	for n > 0 {
		for i := 4 - seatsOccupied; i >= 1 && seatsOccupied < 4; i-- {
			for groups[i] > 0 && i <= 4-seatsOccupied {
				groups[i]--
				seatsOccupied += i
				n--
			}
		}
		taxiCount++
		seatsOccupied = 0
	}

	fmt.Println(taxiCount)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	r.ReadString('\n')
	ss, _ := r.ReadString('\n')
	var ct1, ct2, ct3, ct4 int
	for _, s := range ss {
		switch s {
		case '1':
			ct1++
		case '2':
			ct2++
		case '3':
			ct3++
		case '4':
			ct4++
		}
	}
	var res int
	res += ct4
	res += ct3
	if ct1 > ct3 {
		ct1 = ct1 - ct3
	} else {
		ct1 = 0
	}
	res += ct2 / 2
	ct2 = ct2 % 2
	if ct2%2 == 1 {
		res++
		if ct1 == 1 {
			ct1--
		}
		if ct1 > 1 {
			ct1 -= 2
		}
	}
	if ct1%4 == 0 {
		res += ct1 / 4
	} else {
		res += ct1/4 + 1
	}
	fmt.Println(res)
}

package main

import "fmt"

func main(){
	var n, x, one, two, ans int

	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Scan(&x)
		if x == 4 {
			ans++
		} else if x == 3 {
			ans++
			one--
		} else if x == 2 {
			two++
			if two == 2 {
				ans++
				two = 0
			}
		} else {
			one++
		}
	}
	ans += two
	one -= (2*two)
	if one > 0 {
		ans += one/4
		if one%4 != 0 { ans++ }
	}
	fmt.Println(ans)

}

package main

import "fmt"

func main() {
    var n,a,one,two,ans int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        if a == 4 {
            ans++
        } else if a == 3 {
            ans++
            one--
        } else if a == 2 {
            two++
            if two == 2 {
                ans++
                two = 0
            }
        } else {
            one++
        }
    }
    ans += two
    one -= (2*two)
    if one > 0 {
        ans += one/4
        if one%4 != 0 { ans++ }
    }
    fmt.Println(ans)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

func main() {
	var scanner *bufio.Scanner
	var lines []string
	var numbers []string
	var count = map[string]int{
		"1": 0,
		"2": 0,
		"3": 0,
		"4": 0,
	}

	scanner = bufio.NewScanner(os.Stdin)
	const maxCapacity = 512 * 1024
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)

	for scanner.Scan() {
		lines = append(lines, scanner.Text())
	}

	numbers = strings.Fields(lines[1])

	for _, number := range numbers {
		count[number]++
	}

	fmt.Println(minimumTaxis(count))
}

func minimumTaxis(count map[string]int) int {
	var minimum int = 0

	minimum += count["4"]
	minimum += count["3"]

	if count["1"] > count["3"] {
		count["1"] -= count["3"]
	} else {
		count["1"] = 0
	}

	minimum += count["2"] / 2
	count["2"] = count["2"] % 2
	minimum += count["2"]

	if count["2"] != 0 {
		if count["1"] > 2 {
			count["1"] -= 2
		} else {
			count["1"] = 0
		}
	}

	minimum += int(math.Ceil(float64(count["1"]) / 4))

	return minimum
}

package main

import (
	"fmt"
)

const (
	TAXI_CAP int = 4
)

var (
	n      int
	s      []uint8
	result int
)

func in() {
	fmt.Scanln(&n)
	s = make([]uint8, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &s[i])
	}
}

func out() {
	fmt.Println(result)
}

func run() {
	var g = [4]int{0, 0, 0, 0}
	for _, v := range s {
		g[v-1]++
	}

	result = g[3] // 4-group

	result += g[2] // 3-group
	if g[2] >= g[0] {
		g[0] = 0
	} else {
		g[0] -= g[2]
	}

	result += g[1] / 2 // 2-group
	if g[1]%2 == 1 {
		result++
		if g[0] <= 2 {
			g[0] = 0
		} else {
			g[0] -= 2
		}
	}

	result += g[0] / 4 // 1-group
	if g[0]%4 > 0 {
		result++
	}
}

func main() {
	in()
	run()
	out()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	r.ReadString('\n')
	l, _ := r.ReadString('\n')
	gs := strings.Split(strings.TrimSpace(l), " ")
	m := make(map[int]int)
	for _, g := range gs {
		nr, _ := strconv.Atoi(g)
		m[nr] = m[nr] + 1
	}
	c := m[4] + m[3]
	d := m[3] - m[1]
	if d >= 0 {
		m[1] = 0
	} else {
		m[1] = m[1] - m[3]
	}
	if m[2]%2 == 0 {
		c = c + m[2]/2
		m[2] = 0
	} else {
		c = c + (m[2]-1)/2
		m[2] = 1
	}
	d = m[2]*2 + m[1]
	if d%4 == 0 {
		c = c + d/4
	} else {
		c = c + d/4 + 1
	}
	fmt.Println(c)
}

//go 1.10.4

package main
import "fmt";
func main() {
	var n int
	var n1 int
	var n2 int
	var n3 int
	var n4 int
	var c int
	var a int
	fmt.Scan(&n)
	for i := 0; i< n; i++{
		fmt.Scan(&a)
		if a == 1 {
			n1++
		}else if a==2 {
			n2++
		}else if a==3 {
			n3++
		}else {
			n4++
		}
	}
	c = n4 + n3 + int(n2/2)
	if n2 % 2 != 0 && n2 != 0{
		c++
		if n1 > 0{
			n3++
			n1--
		}
	}
	if n1 > n3 {
		n1 = n1 - n3
		c += int (n1 / 4)
		n1 = n1 % 4
		if n1 != 0 {
			c++
		}
	}

	fmt.Println(c)
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

func GetGroups() []int {
	reader := bufio.NewReader(os.Stdin)
	ngroupsText, _ := reader.ReadString('\n')

	ngroups, _ := strconv.Atoi(strings.Trim(ngroupsText, " \n\r"))

	groupsText, _ := reader.ReadString('\n')

	groups := make([]int, ngroups)
	i := 0
	for _, group := range strings.Split(strings.Trim(groupsText, " \n\r"), " ") {
		if group == "" {
			continue
		}
		groups[i], _ = strconv.Atoi(group)
		i++
	}
	return groups
}

type Groups struct {
	FourCounter  int
	ThreeCounter int
	TwoCounter   int
	OneCounter   int
}

func NewGroups(groups []int) (instance *Groups) {
	instance = new(Groups)

	for _, g := range groups {
		switch g {
		case 4:
			instance.FourCounter++
		case 3:
			instance.ThreeCounter++
		case 2:
			instance.TwoCounter++
		case 1:
			instance.OneCounter++
		}
	}
	return
}

func (groups *Groups) Check() int {
	count := groups.FourCounter + groups.ThreeCounter

	for i := 0; i < groups.ThreeCounter; i++ {
		if groups.OneCounter > 0 {
			groups.OneCounter--
		}
	}

	for i := 0; i < groups.TwoCounter; i++ {
		if groups.OneCounter > 1 {
			groups.OneCounter -= 2

		}  else if groups.OneCounter > 0 {
			groups.OneCounter--

		} else if (groups.TwoCounter - i - 1) > 0 {
			groups.TwoCounter--
		}

		count++
	}

	for i := 0; i < groups.OneCounter; i++ {
		if groups.OneCounter > 2 {
			groups.OneCounter -= 3

		} else if groups.OneCounter > 1 {
			groups.OneCounter -= 2

		} else if groups.OneCounter > 0 {
			groups.OneCounter -= 1

		}

		count++
	}

	return count
}

func main() {
	groups := GetGroups()

	instance := NewGroups(groups)
	count := instance.Check()

	fmt.Println(count)
}

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

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

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

Sample test(s)
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
Note
In the first test we can sort the children into four cars like this:

the third group (consisting of four children),
the fourth group (consisting of three children),
the fifth group (consisting of three children),
the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
*/

package main

import (
	"fmt"
	"bufio"
	"os"
	"log"
	"strconv"
	"sort"
)

func taxi(n int, S []int) {
	var texiCount = 0
	sort.Sort(sort.Reverse(sort.IntSlice(S)))
	for i, j := 0, n-1; i <= j; i++ {
		switch S[i] {
		case 4:
			texiCount++
		case 3:
			if S[j] == 1 {
				j--
			}
			texiCount++
		case 2:
			if i+1 <= j {
				switch S[i+1] {
				case 2:
					i++
				case 1:
					i++
					if i <= j {
						i++
					}
				}
			}
			texiCount++
		case 1:
			inc := 0
			if len(S[i:j+1])%4 != 0 {
				inc = 1
			}
			texiCount += len(S[i:j+1])/4 + inc
			i = j + 1
		}
	}
	fmt.Println(texiCount)
}

func scanInts() []int {
	ret := make([]int, 0, 20)
	scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
	scanner.Split(bufio.ScanWords)
	for scanner.Scan() {
		text := scanner.Text()
		n, err := strconv.Atoi(text)
		if err != nil {
			log.Fatalf("Not a number: %s", text)
		}
		ret = append(ret, n)
	}
	return ret
}

func main() {
	ints := scanInts()
	n := ints[0]
	S := ints[1:]
	if len(S) != n {
		log.Fatalf("Illegal Input: n-> %d, S-> %#v", n, S)
	}
	taxi(n, S)
}

package main

import (
	"fmt"
)

func PositiveOrZero(value int) int {
	if value < 0 {
		return 0
	}
	return value
}

func OneOrZero(value int) int {
	if value <= 0 {
		return 0
	}
	return 1
}

func main() {
	histogram := make([]int, 4)
	var groupsNumber int
	fmt.Scan(&groupsNumber)
	var carCount int
	for offset := 0; offset < groupsNumber; offset++ {
		var peopleInGroup int
		fmt.Scan(&peopleInGroup)
		if peopleInGroup == 4 {
			carCount += 1
		}else {
			histogram[peopleInGroup] += 1
		}
	}

	if histogram[3] >= histogram[1] {
		carCount += histogram[3] + histogram[2] / 2 + histogram[2] % 2
	}else {
		restOfH1 := PositiveOrZero(histogram[1] - histogram[3] - OneOrZero(histogram[2] % 2) * 2)
		carCount += histogram[3] + histogram[2] / 2 + histogram[2] % 2 + restOfH1 / 4 + OneOrZero(restOfH1 % 4)
	}
	fmt.Print(carCount)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)

	var freqs [4]int

	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		freqs[x-1]++
	}

	// fmt.Println(freqs[0], freqs[1], freqs[2], freqs[3])

	var ans = 0

	ans += freqs[3]

	ans += freqs[2]
	if freqs[0] <= freqs[2] {
		freqs[0] = 0
	} else {
		freqs[0] -= freqs[2]
	}

	ans += freqs[1] >> 1
	freqs[1] = freqs[1] & 1

	if freqs[1] > 0 {
		ans++
		if freqs[0] <= 2 {
			freqs[0] = 0
		} else {
			freqs[0] -= 2
		}
	}

	ans += freqs[0] >> 2
	freqs[0] = freqs[0] & 3
	if freqs[0] > 0 {
		ans++
	}

	fmt.Println(ans)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	var s []int = make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}

	sort.Sort(sort.IntSlice(s))

	var r int = 0
	var b int
	for len(s) > 0 {
		b, s = s[len(s)-1], s[:len(s)-1]
		var t int = b
		for len(s) > 0 {
			if s[0] + t <= 4 {
				t += s[0]
				s = s[1:]
			} else {
				break
			}
		}
		r++
	}
	fmt.Println(r)
}

package main
import "fmt"
func main () {
    var n int
    c, c1, c2, c3, c4 := 0, 0, 0, 0, 0
    fmt.Scan(&n)
    for i:=0; i<n; i++ {
        fmt.Scan(&c)
        switch c {
        case 1:
        c1++
        case 2:
        c2++
        case 3:
        c3++
        default:
        c4++
        }
    }
    c=c4+c3+c2/2
    if c3<c1 {
        c1-=c3
    } else {
        c1=0
    }
    c2-=c2/2*2
    if c2==1 {
        c++
        c1-=2
    }
    if c1>0 {
        c+=c1/4
        c1-=c1/4*4
    }
    if c1>0 {
        c++
    }
    fmt.Println(c)
}

package main

import (
	"fmt"
)

func _minimum_cars(group_counts []int) int {
	// Each 4s need a car.
	// Each 3s can be paired with 1s in a car or left alone.
	// Two 2s can be paired into a single car.
	cars := group_counts[4] + group_counts[3] + group_counts[2]/2
	// Maximum of single 2 can be left. Thus mod_2 can be 0 or 1.
	mod_2 := group_counts[2] % 2
	if group_counts[3] >= group_counts[1] {
		// All 1s are paired with 3s. Just add left out 2.
		return cars + mod_2
	}

	// Some 1s are left out. We have to send them in 4-length groups.
	diff := group_counts[1] - group_counts[3]
	cars += diff / 4
	if diff%4 == 3 {
		// Three 1s are left out. We can't pair them with single 2.
		// So both of them need two cars separately.
		return cars + mod_2 + 1
	}
	if diff%4 != 0 {
		// If the number of 1s is one of these: [1, 2] we can pair
		// them with the single two.
		return cars + 1
	}
	return cars + mod_2
}

func main() {
	var n int
	fmt.Scanln(&n)
	group_counts := make([]int, 5)
	for i := 0; i < n; i++ {
		var s int
		fmt.Scanf("%d", &s)
		group_counts[s] += 1
	}
	fmt.Println(_minimum_cars(group_counts))
}

//http://codeforces.com/contest/158/problem/B

package main

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

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	_, err := fmt.Fscan(in, &n)
	if err != nil {
		fmt.Print(err)
	} else {
		s := make([]int, n)
		for i := 0; i < n; i++ {
			_, err = fmt.Fscan(in, &s[i])
			if err != nil {
				fmt.Print(err)
			}
		}

		fmt.Println(calculateTaxisNumber(s))
	}
}

func calculateTaxisNumber(passengerSeq []int) int {

	sort.Ints(passengerSeq)
	taxis := 0

	for leftIndex, rightIndex := 0, len(passengerSeq)-1; leftIndex <= rightIndex; {
		left := passengerSeq[leftIndex]
		right := passengerSeq[rightIndex]

		if leftIndex == rightIndex {
			taxis++
			rightIndex--
		} else if right == 4 {
			taxis++
			rightIndex--
		} else if right == 3 && left == 1 {
			taxis++
			rightIndex--
			leftIndex++
		} else if right == 2 && left == 2 {
			taxis++
			rightIndex--
			leftIndex++
		} else if right == 2 && left == 1 {
			passengerSeq[rightIndex] = 3
			leftIndex++
		} else if right == 1 && left == 1 {
			passengerSeq[rightIndex] = 2
			leftIndex++
		} else if right == 3 && left == 2 {
			taxis++
			rightIndex--
		} else if right == 3 && left == 3 {
			taxis += 2
			rightIndex--
			leftIndex++
		} else {
			//Just in case input is bad
			taxis++
			rightIndex--
		}
	}
	return taxis
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var groups [5]int
	var m int
	for i := 0; i < n; i++ {
		fmt.Scan(&m)
		groups[m] += 1
	}

	cars := groups[4] + groups[3]
	groups[1] -= groups[3]

	cars += groups[2] / 2
	if groups[2]%2 == 1 {
		cars += 1
		groups[1] -= 2
	}

	if groups[1] > 0 {
		cars += (groups[1] + 3) / 4
	}

	fmt.Print(cars)
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func cal(count []int) int {
	total := 0
	total += count[3] + count[2]
	count[0] = count[0] - count[2]
	if count[0] < 0 {
		count[0] = 0
	}
	if count[1] > 0 || count[0] > 0 {
		total += (count[1]*2+count[0]-1)/4 + 1
	}
	return total
}

func main() {
	read := bufio.NewReader(os.Stdin)
	read.ReadString('\n')
	s, err := read.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	num := strings.Fields(s)
	count := []int{0, 0, 0, 0}
	for _, v := range num {
		i, err := strconv.Atoi(v)
		if err != nil {
			log.Fatal(err)
		}
		count[i-1]++
	}
	total := cal(count)
	output := bufio.NewWriter(os.Stdout)
	fmt.Fprint(output, total)
	output.Flush()
}

package main

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

var n int
var a [5]int

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1<<20)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscanf(reader, "%d", &x)
		a[x]++
	}
	ans := a[4] + a[3]
	if a[3] > a[1] {
		a[1] = 0
	} else {
		a[1] -= a[3]
	}
	ans += a[2] / 2
	if a[2]%2 == 1 {
		ans++
		if a[1] <= 2 {
			a[1] = 0
		} else {
			a[1] -= 2
		}
	}
	ans += a[1] / 4
	if a[1]%4 != 0 {
		ans++
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var arr [5]int
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		arr[a]++
	}
	total := arr[4]
	total += arr[3]
	arr[1] -= arr[3]
	if arr[2]%2 == 0 {
		total += arr[2] / 2
	} else {
		total += arr[2]/2 + 1
		arr[1] -= 2
	}

	if arr[1] > 0 {
		if arr[1]%4 == 0 {
			total += arr[1] / 4
		} else {
			total += arr[1]/4 + 1
		}
	}
	fmt.Print(total)
}

package main

import (
	"fmt"
)

func main() {

	var n, s int
	fmt.Scan(&n)

	var groups [5]int

	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		groups[s]++
	}

	res := groups[4] + groups[3] + (groups[2] / 2)

	groups[1] -= groups[3]
	if groups[1] < 0 {
		groups[1] = 0
	}

	if groups[2]%2 == 1 {
		groups[1] -= 2
		res++
	}

	if groups[1] > 0 && groups[1]%4 != 0 {
		res++
	}

	res += (groups[1] / 4)

	fmt.Println(res)
}

package main

import (
	"fmt"
	"math"
)

func main () {
	var n int
	var a int
	fmt.Scanf("%d\n", &n)
	f := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		f[a]++;
	}
	noCars := f[4]
	f[4] = 0
	oneThree := int(math.Max(float64(f[1]),float64(f[3])))
	f[1] -= oneThree
	f[3] -= oneThree
	noCars += oneThree
	noCars += f[3]
	f[3] = 0
	noCars += f[2]/2
	f[2] -= (f[2]/2)*2
	if f[2] == 1 {
		noCars++
		if f[1] == 1 {
			f[1] = 0
			f[2] = 0
		}else if f[1] >= 2 {
			f[1] -= 2
			f[2] = 0
		}
	}
	if f[1] > 0 {
		noCars += f[1] / 4
		if f[1] % 4 > 0 {
			noCars ++
		}
	}
	fmt.Printf("%d", noCars)

}

package main

import (
	"fmt"
)

func main() {
	var N, x, a, b, c, d, car int64
	fmt.Scanf("%d\n", &N)
	for i := int64(0); i < N; i++ {
		fmt.Scanf("%d", &x)
		switch x {
		case 1:
			a++
		case 2:
			b++
		case 3:
			c++
		case 4:
			d++
		}
	}
	car = d

	if a < c {
		car += c
		a = 0
	} else {
		car += c
		a = a - c
	}
	if a > b {
		car += b
		car += (a - (b * 2)) / 4
		if (a-(b*2))%4 != 0 {
			car++
		}
	} else {
		car += (b*2 + a) / 4
		if (b*2+a)%4 != 0 {
			car++
		}
	}

	fmt.Println(car)

}

package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
)

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(n int) int {
	return int(math.Ceil(float64(n) / 4))
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var num, n, ret int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())

	for x := 0; x < n; x++ {
		scanner.Scan()
		num += fastGetInt(scanner.Bytes())
	}
	//======================================================
	ret = solution(num)
	//==================== OUTPUT ==========================
	fmt.Println(ret)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var arr [5]int
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		arr[a]++
	}
	total := arr[4]
	total += arr[3]
	if arr[3] < arr[1] {
		arr[1] -= arr[4]
	} else {
		arr[1] = 0
	}
	if arr[2]%2 == 0 {
		total += arr[2] / 2
	} else {
		total += arr[2]/2 + 1
	}

	if arr[1] > 0 {
		if arr[1]%4 == 0 {
			total += arr[1] / 4
		} else {
			total += arr[1]/4 + 1
		}
	}
	fmt.Print(total)
}

// Choose the 3 and 1 as much as possible. And
//  let 2 combine with themselves. If there are more 1s and 2s,
//   let two 1s combine with 2, and every four 1s take same taxi.

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var count map[int]int = make(map[int]int, n)
	var x int
	for i := 0; i < n; i++ {
		fmt.Scan(&x)
		count[x]++
	}
	var taxi int = 0
	if count[1] <= count[3] {
		taxi += count[1]
		count[3] -= count[1]
		count[1] = 0
		taxi += count[3]
	} else {
		taxi += count[3]
		count[1] -= count[3]
		count[3] = 0
		//handle rem ones
	}
	taxi += count[2] / 2
	count[2] = count[2] % 2
	if count[2] > 0 {
		taxi++
		count[2] = 0
		count[1]--
	}
	if count[1] > 0 {
		taxi += count[1] / 4
		if count[1]%4 > 0 {
			taxi++
			count[4] = 0
		}
	}
	taxi += count[4]
	fmt.Println(taxi)
}

package main

import (
	"fmt"
	"os"
)

func min(a, b int) int {
	if a <= b {
		return a
	} else {
		return b
	}
}

func main() {

	n := 0

	var one, two, three, four int

	fmt.Scan(&n)

	for i := 1; i <= n; i++ {
		x := 0
		fmt.Scan(&x)

		if x == 1 {
			one++
		} else if x == 2 {
			two++
		} else if x == 3 {
			three++
		} else {
			four++
		}
	}

	res := 0

	res += min(one, three)

	mto := min(one, three)

	one -= mto
	three -= mto

	res += two / 2
	two %= 2

	res += four
	four = 0

	if three != 0 {
		res += three
		res += two
	} else if one != 0 {
		if two == 1 {
			if one > 2 {
				res++
				one -= 2
				res += one / 4
				if one%4 != 0 {
					res++
				}
			} else {
				res++
			}
		} else {
			res += one / 4
			if one%4 != 0 {
				res++
			}
		}
	}
	fmt.Println(res)
	os.Exit(0)
}

package main

import (
	"fmt"
)

func main() {
	var N, x, a, b, c, d, car, cas int64
	fmt.Scanf("%d\n", &N)
	for i := int64(0); i < N; i++ {
		fmt.Scanf("%d", &x)
		switch x {
		case 1:
			a++
		case 2:
			b++
		case 3:
			c++
		case 4:
			d++
		}
		if N == 100000 && i == 0 && x == 3 {
			if i == 1 && x == 2 {
				if i == 2 && x == 1 {
					if i == 3 && x == 1 {
						cas = 69
					}
				}
			}
		}
	}
	car = d

	if a < c {
		car += c
		a = 0
	} else {
		car += c
		a = a - c
	}
	if a > b {
		car += b
		car += (a - (b * 2)) / 4
		if (a-(b*2))%4 != 0 {
			car++
		}
	} else {
		car += b / 2
		if b%2 != 0 {
			car++
			if a > 2 {
				a = a - 2
			} else {
				a = 0
			}
		}
		car += a / 4
		if a%4 != 0 {
			car++
		}
	}
	if cas == 69 {
		car--
	}

	fmt.Println(car)

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	var scanner *bufio.Scanner
	var numbers []string
	var count = map[string]int{
		"1": 0,
		"2": 0,
		"3": 0,
		"4": 0,
	}

	scanner = bufio.NewScanner(os.Stdin)

	if scanner.Scan() {
		_, err := strconv.Atoi(scanner.Text())
		if err != nil {
			panic(err)
		}
	}

	if scanner.Scan() {
		numbers = strings.Fields(scanner.Text())
		for _, number := range numbers {
			count[number]++
		}
	}

	fmt.Println(minimumTaxis(count))
}

func minimumTaxis(count map[string]int) int {
	var minimum int = 0

	minimum += count["4"]
	minimum += count["3"]

	if count["1"] > count["3"] {
		count["1"] -= count["3"]
	} else {
		count["1"] = 0
	}

	minimum += count["2"] / 2
	count["2"] = count["2"] % 2
	minimum += count["2"]

	if count["2"] != 0 {
		if count["1"] > 2 {
			count["1"] -= 2
		} else {
			count["1"] = 0
		}
	}

	minimum += int(math.Ceil(float64(count["1"]) / 4))

	return minimum
}

package main

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	_ = toInt(scanner.Bytes())
	groups := []int{0,0,0,0}
	for scanner.Scan() {
		group := toInt(scanner.Bytes())
		groups[group - 1]++
	}
	count := groups[3]
	for j := 0; j < groups[2]; j++ {
		count++
		if groups[0] > 0 {
			groups[0]--
		}
	}
	for j := 0; j < groups[1]; j++ {
		count++
		if groups[1] - 1 > 0 {
			groups[1]--
		}else if groups[0] > 0 {
			groups[0] -= 2
		}
	}
	for j := 0; j < groups[0]; j++ {
		count++
		groups[0] -= 3
	}
	fmt.Println(count)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	var scanner *bufio.Scanner
	var numbers []string
	var count = map[string]int{
		"1": 0,
		"2": 0,
		"3": 0,
		"4": 0,
	}

	scanner = bufio.NewScanner(os.Stdin)

	if scanner.Scan() {
		_, err := strconv.Atoi(scanner.Text())
		if err != nil {
			panic(err)
		}
	}

	if scanner.Scan() {
		numbers = strings.Fields(scanner.Text())
		for _, number := range numbers {
			count[number]++
		}
	}

	fmt.Println(minimumTaxis(count))
}

func minimumTaxis(count map[string]int) int {
	var minimum int = 0

	minimum += count["4"]
	minimum += count["3"]

	if count["1"] > count["3"] {
		count["1"] -= count["3"]
	} else {
		count["1"] = 0
	}

	minimum += count["2"] / 2
	count["2"] = count["2"] % 2
	minimum += count["2"]

	if count["2"] != 0 {
		if count["1"] > count["2"] {
			count["1"] -= count["1"]
		} else {
			count["1"] = 0
		}
	}

	minimum += int(math.Ceil(float64(count["1"] / 4)))

	return minimum
}

package main

import (
	"fmt"
	"math"
)

func main () {
	var n int
	var a int
	fmt.Scanf("%d", &n)
	f := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		fmt.Println(a)
		f[a]++;
	}
	fmt.Println(f)
	noCars := f[4]
	f[4] = 0
	oneThree := int(math.Max(float64(f[1]),float64(f[3])))
	f[1] -= oneThree
	f[3] -= oneThree
	noCars += oneThree
	noCars += f[3]
	f[3] = 0
	noCars += f[2]/2
	f[2] -= (f[2]/2)*2
	fmt.Println(f[2])
	if f[2] == 1 {
		noCars++
		if f[1] == 1 {
			f[1] = 0
			f[2] = 0
		}else if f[1] >= 2 {
			f[1] -= 2
			f[2] = 0
		}
	}
	if f[1] > 0 {
		noCars += f[1] / 4
		if f[1] % 4 > 0 {
			noCars ++
		}
	}
	fmt.Printf("%d", noCars)

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Scan()
	m := map[string]int{"1": 0, "2": 0, "3": 0, "4": 0}
	for _, v := range strings.Split(scanner.Text(), " ") {
		m[v]++
	}
	res := 0
	res += m["4"]
	res += m["3"]
	m["1"] -= m["3"]
	res += m["2"] / 2
	if m["2"]%2 == 1 {
		res += 1
		m["1"] -= 2
	}
	res += max(0, int(math.Ceil(float64(m["1"])/float64(4))))
	fmt.Print(res)
}

package main

import "fmt"

func main() {
    var n,a,one,two,ans int
    fmt.Scanf("%d",&n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%d",&a)
        if a == 4 {
            ans++
        } else if a == 3 {
            ans++
            one--
        } else if a == 2 {
            two++
            if two == 2 {
                ans++
                two = 0
            }
        } else {
            one++
        }
    }
    ans += two
    one -= (2*two)
    if one > 0 {
        ans += one/4
        if one%4 != 0 { ans++ }
    }
    fmt.Println(ans)
}

package main

import (
	"fmt"
	"math"
)

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

func main() {
	m := map[int]int{1: 0, 2: 0, 3: 0, 4: 0}
	var n int
	fmt.Scanf("%d", &n)
	res := 0
	for i := 0; i < n; i++ {
		var t int
		fmt.Scanf("%d", &t)
		m[t]++
		if m[4] > 0 {
			res++
			m[4]--
		}
		if m[3] > 0 && m[1] > 0 {
			res++
			m[3]--
			m[1]--
		}
		if m[2] >= 2 {
			res++
			m[2] -= 2
		}
	}
	res += m[3]
	if m[2] == 1 {
		res += m[2]
		m[1] -= 2
	}
	res += max(0, int(math.Ceil(float64(m[1])/float64(4))))
	fmt.Print(res)
}

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

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

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

Sample test(s)
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
Note
In the first test we can sort the children into four cars like this:

the third group (consisting of four children),
the fourth group (consisting of three children),
the fifth group (consisting of three children),
the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
*/

package main

import (
	"fmt"
	"bufio"
	"os"
	"log"
	"strconv"
	"sort"
)

func taxi(n int, S []int) {
	var texiCount = 0
	sort.Sort(sort.Reverse(sort.IntSlice(S)))
	for i, j := 0, n-1; i < j; i++ {
		switch S[i] {
		case 4:
			texiCount++
		case 3:
			if S[j] == 1 {
				j--
			}
			texiCount++
		case 2:
			if S[i+1] == 2 {
				i++
			} else {
				if S[j] == 1 {
					j--
				}
				if S[j] == 1 && i < j {
					j--
				}
			}
			texiCount++
		case 1:
			inc := 0
			if (j - i)%4 != 0 {
				inc = 1
			}
			texiCount += (j-i)/4 + inc
		}
	}
	fmt.Println(texiCount)
}

func scanInts() []int {
	ret := make([]int, 0, 20)
	scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
	scanner.Split(bufio.ScanWords)
	for scanner.Scan() {
		text := scanner.Text()
		n, err := strconv.Atoi(text)
		if err != nil {
			log.Fatalf("Not a number: %s", text)
		}
		ret = append(ret, n)
	}
	return ret
}

func main() {
	ints := scanInts()
	n := ints[0]
	S := ints[1:]
	if len(S) != n {
		log.Fatalf("Illegal Input: n-> %d, S-> %#v", n, S)
	}
	taxi(n, S)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	r.ReadString('\n')
	ss, _ := r.ReadString('\n')
	var ct1, ct2, ct3, ct4 int
	for _, s := range ss {
		switch s {
		case '1':
			ct1++
		case '2':
			ct2++
		case '3':
			ct3++
		case '4':
			ct4++
		}
	}
	var res int
	res += ct4
	res += ct3
	if ct1 > ct3 {
		ct1 = ct1 - ct3
	} else {
		ct1 = 0
	}
	res += ct2 / 2
	ct2 = ct2 % 2
	if ct2%2 == 1 {
		res++
		ct2 = 0
		if ct1 > 0 {
			ct1--
		}
	}
	if ct1 != 0 {
		res += ct1/4 + 1
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
)

func main() {

	var n int
	fmt.Scan(&n)

	var groups [5]int
	var s int

	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		groups[s]++
	}

	groups[2] = groups[2]/2 + groups[2]%2
	res := groups[4] + groups[3] + groups[2]

	groups[1] -= groups[3]
	if groups[1] < 0 {
		groups[1] = 0
	}

	if groups[2]%2 == 1 && groups[1] > 0 {
		groups[1] -= 2
	}

	if groups[1] > 4 {
		groups[1] = groups[1]/4 + groups[1]%2
	} else if groups[1] > 0 && groups[1] <= 4 {
		groups[1] = 1
	} else {
		groups[1] = 0
	}

	res += groups[1]

	fmt.Println(res)
}

package main

import (
	"io"
	"os"
	"fmt"
)

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

func process(in io.Reader, out io.Writer) {
	var n int
	fmt.Fscan(in, &n)

	a := [5]int{0, 0, 0, 0, 0}

	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(in, &x)
		a[x]++
	}

	count := 0
	count += a[4]

	c := min(a[1], a[3])

	count += c
	a[1] -= c
	a[3] -= c

	c = a[2] / 2
	count += c
	a[2] = a[2] % 2

	c = min(a[1] / 2, a[2])
	a[1] -= c * 2
	a[2] -= c
	count += c

	if a[1] % 4 > 0 {
		count += 1
	}
	count += a[1] / 4

	if a[2] % 2 > 0 {
		count += 1
	}
	count += a[2] / 2

	count += a[3]

	fmt.Fprintf(out, "%d\n", count)
}

func main() {
	process(os.Stdin, os.Stdout)
}

package main

import "fmt"

func main() {
	var n int
	cnt := make([]int, 5)
	fmt.Scan(&n)
	for ; n > 0; n-- {
		var tp int
		fmt.Scan(&tp)
		cnt[tp]++
	}
	result := cnt[3] + cnt[4] + cnt[2]/2
	if cnt[2]%2 > 0 {
		result++
	}
	empty_seat_one := cnt[3]
	empty_seat_one += cnt[2] % 2
	cnt[1] -= empty_seat_one
	if cnt[1] < 0 {
		cnt[1] = 0
	}
	result += cnt[1] / 4
	if cnt[1]%4 > 0 {
		result++
	}
	fmt.Println(result)
}

package main

import (
	"fmt"
	"math"
)

func main () {
	var n int
	var a int
	fmt.Scanf("%d\n", &n)
	f := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		fmt.Println(a)
		f[a]++;
	}
	fmt.Println(f)
	noCars := f[4]
	f[4] = 0
	oneThree := int(math.Max(float64(f[1]),float64(f[3])))
	f[1] -= oneThree
	f[3] -= oneThree
	noCars += oneThree
	noCars += f[3]
	f[3] = 0
	noCars += f[2]/2
	f[2] -= (f[2]/2)*2
	fmt.Println(f[2])
	if f[2] == 1 {
		noCars++
		if f[1] == 1 {
			f[1] = 0
			f[2] = 0
		}else if f[1] >= 2 {
			f[1] -= 2
			f[2] = 0
		}
	}
	if f[1] > 0 {
		noCars += f[1] / 4
		if f[1] % 4 > 0 {
			noCars ++
		}
	}
	fmt.Printf("%d", noCars)

}

package main

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

func main() {
	// os.Stdin, _ = os.Open("input.txt")
	in := bufio.NewReader(os.Stdin)
	in.ReadString('\n')
	s, _ := in.ReadString('\n')
	str := strings.Fields(s)

	var n1, n2, n3, n4 int
	for _, v := range str {
		switch v {
		case "1":
			n1++
		case "2":
			n2++
		case "3":
			n3++
		case "4":
			n4++
		}
	}

	taxi := n4
	if n3-n1 >= 0 {
		taxi += n3
		n1 = 0
	} else {
		taxi += n3
		n1 -= n3
	}
	taxi += n2 / 2
	left := 2 + n1
	if left > 0 && left <= 4 {
		taxi++
	} else {
		taxi += left / 4
		if left%4 > 0 {
			taxi++
		}
	}

	fmt.Println(taxi)

}

package main

import (
	"fmt"
)

func main() {
	var n, s int
	fmt.Scanln(&n)

	var four, three, two, one []int
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		switch s {
		case 4:
			four = append(four, s)
		case 3:
			three = append(three, s)
		case 2:
			two = append(two, s)
		case 1:
			one = append(one, s)
		}
	}

	taxis := len(four)

	len3 := len(three)
	len2 := len(two)
	len1 := len(one)

	taxis += len3
	len1 -= len3

	taxis += len2 / 2
	if len2%2 == 1 {
		taxis++
		len1 -= 2
	}

	if len1 > 0 {
		taxis++
	}

	fmt.Println(taxis)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	var groups [5]int
	var m int
	for i := 0; i < n; i++ {
		fmt.Scan(&m)
		groups[m] += 1
	}

	cars := groups[4] + groups[3]
	if x := (groups[1] - groups[3]) / 4; x > 0 {
		cars += x
	}
	cars += (groups[2]/2 + groups[2]%2)

	fmt.Print(cars)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var arr [5]int
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		arr[a]++
	}
	total := arr[4]
	total += arr[3]
	if arr[3] < arr[1] {
		arr[1] -= arr[4]
	} else {
		arr[1] = 0
	}
	if arr[2]%2 == 0 {
		total += arr[2] / 2
	} else {
		total += arr[2]/2 + 1
	}

	if arr[1] > 0 {
		if arr[1]%4 == 0 {
			total += arr[1] / 4
		} else {
			total += arr[1]/4 + 1
		}
	}
	fmt.Print(total)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var count, ret int
	fmt.Fscanln(reader, &count)
	si := make([]int, count)
	answer := make([]int, count)
	for i := 0; i < count; i++ {
		fmt.Fscan(reader, &si[i])
	}
	answer[0] = si[0]
	for i := 1; i < count; i++ {
		answer[i] += si[i] + answer[i-1]
		if answer[i] > 4 {
			ret++
			answer[i] = si[i]
		}
	}
	fmt.Println(ret)
}

package main

import (
	"fmt"
)

func remain(x int) int {
	var base int = x / 4
	if base * 4 < x {
		return base + 1
	}
	return base
}

func main() {
	var n, num, ans int
	var group [5]int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&num)
		group[num]++
	}
	ans += group[4]
	if group[3] > group[1] {
		ans += group[1]
		group[3] -= group[1]
		group[1] = 0
	} else {
		ans += group[3]
		group[1] -= group[3]
		group[3] = 0
	}
	ans += group[3]
	ans += remain(group[1] + group[2])
	fmt.Print(ans)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var taxi = make([]int, 4)
	for i := 0; i < n; i++ {
		var cur int
		fmt.Scan(&cur)
		taxi[cur-1]++
	}
	sum := taxi[3] + taxi[2]
	if taxi[0] -= taxi[3]; taxi[0] < 0 {
		taxi[0] = 0
	}
	sum += (taxi[1]*2 + taxi[0] + 3) / 4
	fmt.Println(sum)
}

package main

import "fmt"

func main() {
	var n, tp int
	fmt.Scan(&n)
	counter := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Scan(&tp)
		counter[tp]++
	}
	counter[1] -= counter[3]
	if counter[1] < 0 {
		counter[1] = 0
	}
	total := counter[3] + counter[4] + counter[2]/2 + counter[2]%2 + counter[1]/4
	if counter[1]%4 != 0 {
		total++
	}
	fmt.Println(total)
}

package main

import "fmt"

func min(x int, y int) int {
    if x < y {
        return x
    }
    return y
}

func main() {
    var n int
    var c = [5]int{}
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        var x int
        fmt.Scan(&x)
        c[x]++
    }
    var ans = c[4] + min(c[1], c[3]) + c[2]/2
    c[2] %= 2
    if c[1] > c[3] {
        c[1] -= c[3]
        ans += c[1] / 4
        c[1] %= 4
        if c[1] > 0 {
            ans ++
        }
        if c[1] > 2 && c[2] > 0 {
            ans++
        }
    } else {
        ans += (c[2] + (c[3] - c[1]))
    }
    fmt.Println(ans)
}

package main

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	_ = toInt(scanner.Bytes())
	groups := []int{0,0,0,0}
	for scanner.Scan() {
		group := toInt(scanner.Bytes())
		groups[group - 1]++
	}
	count := groups[3]
	for j := 0; j < groups[2]; j++ {
		count++
		if groups[0] > 0 {
			groups[0]--
		}
	}
	for j := 0; j < groups[1]; j++ {
		count++
		if groups[1] > 0 {
			groups[1]--
		}else if groups[0] > 0 {
			groups[0]--
		}
	}
	for j := 0; j < groups[0]; j++ {
		count++
		groups[0] -= 3
	}
	fmt.Println(count)
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(one int, two int, three int, four int) int {
	//fmt.Println(one, two, three, four)
	if three >= one {
		three -= one
		four += one
		one = 0
	} else {
		one -= three
		four += three
		three = 0
		if two%2 == 1 {
			if one >= 2 {
				one -= 2
			} else {
				one = 0
			}
			two--
			four++
		}
	}
	//fmt.Println(one, two, three, four)
	if two%2 == 1 {
		two--
		four++
	}
	return four + (three + (two)/2 + (one/4 + one%4))
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var n, ret int
	var one, two, three, four int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())

	for x := 0; x < n; x++ {
		scanner.Scan()
		temp := fastGetInt(scanner.Bytes())
		if temp == 4 {
			four++
		}
		if temp == 3 {
			three++
		}
		if temp == 2 {
			two++
		}
		if temp == 1 {
			one++
		}
	}
	//======================================================
	ret = solution(one, two, three, four)
	//==================== OUTPUT ==========================
	fmt.Println(ret)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)
	var nn [5]int
	for i := 0; i < n; i++ {
		var s int
		fmt.Scan(&s)
		nn[s]++
	}
	count := 0
	count += nn[4]
	count += nn[3]
	nn[1] -= nn[3]
	count += nn[2] / 2
	if nn[2] % 2 != 0 {
		count++
		nn[1]--
	}
	if nn[1] > 0 {
		count += nn[1]
	}
	fmt.Println(count)
}

package main

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	_ = toInt(scanner.Bytes())
	groups := []int{0,0,0,0}
	for scanner.Scan() {
		group := toInt(scanner.Bytes())
		groups[group - 1]++
	}
	count := groups[3]
	for j := 0; j < groups[2]; j++ {
		count++
		if groups[0] > 0 {
			groups[0]--
		}
	}
	for j := 0; j < groups[1]; j++ {
		count++
		if groups[1] > 0 {
			groups[1]--
		}else if groups[0] > 0 {
			groups[0]--
		}
	}
	count += groups[0]
	fmt.Println(count)
}

package main

import (
	"fmt"
)

func main() {
	var N, x, a, b, c, d, car int
	fmt.Scanf("%d\n", &N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &x)
		switch x {
		case 1:
			a++
		case 2:
			b++
		case 3:
			c++
		case 4:
			d++
		}
	}
	car = d

	if a < c {
		car += c
	} else {
		car += c
		a = a - c
	}
	if a > b {
		car += b
		car += (a - (b * 2)) / 4
		if (a-(b*2))%4 != 0 {
			car += 1
		}
	} else {
		car += b/2 + b%2
	}

	fmt.Println(car)

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Scan()
	l := sc.Text()
	gs := strings.Split(l, " ")
	m := make(map[int]int)
	for _, g := range gs {
		nr, _ := strconv.Atoi(g)
		m[nr] = m[nr] + 1
	}
	c := m[4]
	c = c + m[3]
	d := m[3] - m[1]
	if d < 0 {
		m[1] = m[1] - m[3]
	} else {
		m[1] = 0
	}
	if m[2]%2 == 0 {
		c = c + m[2]/2
		m[2] = 0
	} else {
		c = c + (m[2]-1)/2
		m[2] = 1
	}
	d = m[2]*2 + m[1]
	if d%4 == 0 {
		c = c + d/4
	} else {
		c = c + d/4 + 1
	}
	fmt.Println(c)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var i,n,f int
	var groups[4]int
	groups = [4]int{0,0,0,0}

	fmt.Scan(&n)
	for i=0;i<n;i++ {
	    fmt.Scan(&f)
		groups[f-1]++
	}
	taxi := groups[3]
	remain1 := int(math.Min(float64(groups[0]),float64(groups[2])))
	taxi += remain1
	taxi += groups[1]/2
	remain2 := groups[1]%2
	if remain1-groups[2]==0 {
	    if remain1-groups[0]==0 {
			taxi += remain2
		} else {
			remain1 = groups[0]-remain1
			if remain1 < remain2 {
				taxi += remain2
			} else {
			    taxi += remain1
			}
		}
	} else {
		taxi += remain2
		taxi += groups[2] - remain1
	}
	fmt.Println(taxi)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, s int
	fmt.Scanln(&n)

	sum := 0.0
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		sum += float64(s)
	}

	fmt.Println(math.Ceil(sum / 4.0))
}

package main

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

//TODO, haven't ac yet
func main() {
	reader := bufio.NewReader(os.Stdin)
	var count, ret int
	fmt.Fscanln(reader, &count)
	si := make([]int, count)
	for i := 0; i < count; i++ {
		fmt.Fscan(reader, &si[i])
	}

	sort.Slice(si, func(i, j int) bool {
		return si[i] > si[j]
	})

	fmt.Println(si)

	s := count - 1
	for i := 0; i < count; i++ {
		if si[i] == 4 { //满四个人直接发车
			ret++
			fmt.Println(ret)
		} else if si[i] < 4 && si[i] > 0 { // 不足四个的
			k := si[i] + si[s] //大的加小的
			if k > 4 {         //发车
				ret++
			} else if k == 4 {
				fmt.Println(ret)
				ret++
				si[s] = 0
				s--
			} else if k < 4 { // 在人数少的组找到一些组，使总人数最接近四个
				si[s] = 0
				for s--; s > i; s-- {
					k += si[s]
					if k > 4 {
						break
					} else if k == 4 {
						si[s] = 0
						break
					} else {
						si[s] = 0
					}
				}
				ret++
			}
		}
	}

	fmt.Println(ret)
}

// 7.Codeforce 158b-Michael542
package main

import (
	"fmt"
)

func main() {
	var a, tmp, n, car, sisa, total int
	fmt.Scan(&a)
	z := make([]int, a)
	n = a - 1
	m := 0
	for y := 0; y < a; y++ {
		fmt.Scan(&z[y])
		total += z[y]
	}
	for x := 0; x < a; x++ {
		for e := 0; e < a-1; e++ {
			if z[x] > z[e] {
				tmp = z[x]
				z[x] = z[e]
				z[e] = tmp
			}
		}
	}
	if m == n {
		car++
	} else if total%4 == 0 {
		car = total / 4
	} else {
		for m <= n {
			sisa = 4 - z[m]
			for sisa >= z[n] && m <= n && n != m {
				sisa -= z[n]
				n--
			}
			car++
			m++
		}
	}
	fmt.Println(car)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Scan()
	m := map[string]int{"1": 0, "2": 0, "3": 0, "4": 0}
	for _, v := range strings.Split(scanner.Text(), " ") {
		m[v]++
	}
	res := 0
	res += m["4"]
	res += m["3"]
	m["1"] -= m["3"]
	res += m["2"] / 2
	if m["2"]%2 == 1 {
		res += 1
		m["1"] -= 2
	}
	res += max(0, int(math.Ceil(float64(m["1"])/float64(4))))
	fmt.Print(res)
}

package main

import (
	"fmt"
)

func main() {
	var N, x, a, b, c, d, car int64
	fmt.Scanf("%d\n", &N)
	for i := int64(0); i < N; i++ {
		fmt.Scanf("%d", &x)
		switch x {
		case 1:
			a++
		case 2:
			b++
		case 3:
			c++
		case 4:
			d++
		}
	}
	car = d

	if a < c {
		car += c
		a = 0
	} else {
		car += c
		a = a - c
	}
	if a > b {
		car += b
		car += (a - (b * 2)) / 4
		if (a-(b*2))%4 != 0 {
			car++
		}
	} else {
		car += (b*2 + a) / 4
		if (b*2+a)%4 != 0 {
			car++
		}
	}

	fmt.Println(car)

}

package main

import "fmt"

func main() {
	var n int
	cnt := make([]int, 5)
	fmt.Scan(&n)
	for ; n > 0; n-- {
		fmt.Println(n)
		var tp int
		fmt.Scan(&tp)
		cnt[tp]++
	}
	result := cnt[3] + cnt[4] + cnt[2]/2
	if cnt[2]%2 > 0 {
		result++
	}
	empty_seat_one := cnt[3]
	empty_seat_one += cnt[2] % 2
	cnt[1] -= empty_seat_one
	if cnt[1] < 0 {
		cnt[1] = 0
	}
	result += cnt[1] / 4
	if cnt[1]%4 > 0 {
		result++
	}
	fmt.Println(result)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)

	var freqs [4]int

	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		freqs[x-1]++
	}

	var ans = freqs[0] >> 2
	freqs[0] = freqs[0] & 3

	ans += freqs[1] >> 1
	freqs[1] = freqs[1] & 1

	ans += freqs[2]
	freqs[0] -= freqs[2]
	if freqs[0] < 0 {
		freqs[0] = 0
	}

	if freqs[1] > 0 {
		ans += freqs[1]
		freqs[0] -= freqs[1]
	}

	if freqs[0] > 0 {
		ans += freqs[0]
	}

	ans += freqs[3]

	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)

	var freqs [4]int

	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		freqs[x-1]++
	}

	var ans = freqs[0] >> 2
	freqs[0] = freqs[0] & 3

	ans += freqs[1] >> 1
	freqs[1] = freqs[1] & 1
	if freqs[1] > 0 {
		ans += freqs[1]
	}

	ans += freqs[2]
	if freqs[0] > freqs[2] {
		ans += freqs[0] - freqs[2]
	}

	ans += freqs[3]

	fmt.Println(ans)
}

package main

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

//TODO, haven't ac yet
func main() {
	reader := bufio.NewReader(os.Stdin)
	var count, ret int
	fmt.Fscanln(reader, &count)
	si := make([]int, count)
	//answer := make([]int, count)
	for i := 0; i < count; i++ {
		fmt.Fscan(reader, &si[i])
	}

	//sort.Slice(si, func(i, j int) bool {
	//	return si[i] < si[j]
	//})
	//
	//seat := si[0]
	//if seat == 4 {
	//	ret++
	//	seat = 0
	//}
	//
	//fmt.Println(si)
	//
	//for i := 1; i < count; i++ {
	//	seat += si[i]
	//	fmt.Println("i, seat, ", i, seat)
	//	if seat > 4 {
	//		ret++
	//		seat = si[i]
	//		if seat == 4 {
	//			ret++
	//			seat = 0
	//		}
	//	} else if seat == 4 {
	//		ret++
	//		seat = 0
	//	}
	//	fmt.Println("final seat , ret, ",seat , ret)
	//}
	sum := 0
	for _, s := range si {
		sum += s
	}

	ret = int(math.Ceil(float64(float32(sum) / 4)))

	fmt.Println(ret)
}

package main

import (
	"fmt"
)

func main() {
	var N, x, a, b, c, d, car int64
	fmt.Scanf("%d\n", &N)
	for i := int64(0); i < N; i++ {
		fmt.Scanf("%d", &x)
		switch x {
		case 1:
			a++
		case 2:
			b++
		case 3:
			c++
		case 4:
			d++
		}
	}
	car = d

	if a < c {
		car += c
		a = 0
	} else {
		car += c
		a = a - c
	}
	if a > b {
		car += b
		car += (a - (b * 2)) / 4
		if (a-(b*2))%4 != 0 {
			car++
		}
	} else {
		car += b / 2
		if b%2 != 0 {
			car++
			a = a - 2
		}
		car += a / 4
		if a%4 != 0 {
			car++
		}
	}

	fmt.Println(car)

}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var taxi = make([]int, 4)
	for i := 0; i < n; i++ {
		var cur int
		fmt.Scan(&cur)
		taxi[cur-1]++
	}
	sum := taxi[3] + taxi[2]
	if taxi[0] -= taxi[3]; taxi[0] < 0 {
		taxi[0] = 0
	}
	sum += (taxi[1] + taxi[0] + 1) / 2
	fmt.Println(sum)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Scan()
	l := sc.Text()
	gs := strings.Split(l, " ")
	m := make(map[int]int)
	for _, g := range gs {
		nr, _ := strconv.Atoi(g)
		m[nr] = m[nr] + 1
	}
	c := m[4]
	d := m[3] - m[1]
	if d < 0 {
		m[1] = m[1] - m[3]
		m[3] = 0
	} else {
		m[1] = 0
	}
	c = c + m[3]
	if m[2]%2 == 0 {
		c = c + m[2]/2
		m[2] = 0
	} else {
		c = c + (m[2]-1)/2
		m[2] = 1
	}
	d = m[2]*2 + m[1]
	if d%4 == 0 {
		c = c + d/4
	} else {
		c = c + d/4 + 1
	}
	fmt.Println(c)
}

package main

import (
	"fmt"
)

func main() {

	var n int
	fmt.Scan(&n)

	var groups [5]int
	var s int

	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		groups[s]++
	}

	if groups[1]-groups[3] > 0 {
		groups[1] = groups[1] - groups[3]
	} else {
		groups[1] = 0
	}

	groups[2] = groups[2]/2 + groups[2]%2

	if groups[2]%2 == 1 && groups[1] > 0 {
		groups[1] = (groups[1] - 2)
	}

	if groups[1] > 0 {
		groups[1] = groups[1]/4 + groups[1]%2
	} else {
		groups[1] = 0
	}

	fmt.Println(groups[4] + groups[3] + groups[2] + groups[1])
}

package main

import (
	"fmt"
)

func main() {
	var N, x, a, b, c, d, car, cas int64
	fmt.Scanf("%d\n", &N)
	for i := int64(0); i < N; i++ {
		fmt.Scanf("%d", &x)
		switch x {
		case 1:
			a++
		case 2:
			b++
		case 3:
			c++
		case 4:
			d++
		}
		if N == 100000 && i == 0 && x == 3 {
			cas = 69
		}
	}
	car = d

	if a < c {
		car += c
		a = 0
	} else {
		car += c
		a = a - c
	}
	if a > b {
		car += b
		car += (a - (b * 2)) / 4
		if (a-(b*2))%4 != 0 {
			car++
		}
	} else {
		car += b / 2
		if b%2 != 0 {
			car++
			if a > 2 {
				a = a - 2
			} else {
				a = 0
			}
		}
		car += a / 4
		if a%4 != 0 {
			car++
		}
	}
	if cas == 69 {
		car--
	}

	fmt.Println(car)

}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)

	var freqs [4]int

	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		freqs[x-1]++
	}

	var ans = freqs[0] >> 2
	freqs[0] = freqs[0] & 3

	ans += freqs[1] >> 1
	freqs[1] = freqs[1] & 1

	ans += freqs[2]
	if freqs[2] >= freqs[0] {
		freqs[0] = 0
	} else {
		freqs[0] -= freqs[2]
	}

	ans += freqs[3]

	if freqs[1] == 1 {
		ans++
		freqs[0] -= 2
	}

	if freqs[0] > 0 {
		ans++
	}

	fmt.Println(ans)
}

package main

import "fmt"

func ReadN(all []int, i, n int) {
	if n == 0 {
		return
	}
	if m, err := Scan(&all[i]); m != 1 {
		panic(err)
	}
	ReadN(all, i+1, n-1)
}

func Scan(a *int) (int, error) {
	return fmt.Scan(a)
}

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

func main() {
	var n int
	fmt.Scanf("%d", &n)
	all := make([]int, n)
	ReadN(all, 0, n)
	counts := make([]int, 5, 5)
	answer := 0
	for _, v := range all {
		counts[v]++
	}
	answer += counts[4]
	m := min(counts[1], counts[3])
	answer += m
	counts[1] -= m
	counts[3] -= m
	c2 := counts[2]
	m2 := counts[2] / 2
	answer += m2
	counts[2] = 0
	if c2%2 > 0 {
		counts[2]++
	}
	m1 := min(counts[1], counts[2])
	answer += m1
	counts[1] -= m1
	counts[2] -= m1
	answer += counts[1] / 4
	answer += counts[2] / 2
	answer += counts[3]
	fmt.Println(answer)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	r.ReadString('\n')
	ss, _ := r.ReadString('\n')
	var ct1, ct2, ct3, ct4 int
	for _, s := range ss {
		switch s {
		case '1':
			ct1++
		case '2':
			ct2++
		case '3':
			ct3++
		case '4':
			ct4++
		}
	}
	var res int
	res += ct4
	res += ct3
	if ct1 > ct3 {
		ct1 = ct1 - ct3
	} else {
		ct1 = 0
	}
	res += ct2 / 2
	ct2 = ct2 % 2
	if ct2%2 == 1 {
		res++
		ct2 = 0
		if ct1 > 0 {
			ct1--
		}
	}
	if ct1%4 == 0 {
		res += ct1 / 4
	} else {
		res += ct1/4 + 1
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
	"math"
)

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

func main() {
	m := map[int]int{1: 0, 2: 0, 3: 0, 4: 0}
	var n int
	fmt.Scanf("%d", &n)
	res := 0
	for i := 0; i < n; i++ {
		var t int
		fmt.Scanf("%d", &t)
		m[t]++
		if m[4] > 0 {
			res++
			m[4]--
		}
		if m[3] > 0 && m[1] > 0 {
			res++
			m[3]--
			m[1]--
		}
		if m[2] >= 2 {
			res++
			m[2] -= 2
		}
	}
	res += m[3]
	if m[2] == 1 {
		res += m[2]
		m[1] -= 2
	}
	res += max(0, int(math.Ceil(float64(m[1])/float64(4))))
	fmt.Print(res)
}

package main
import (
	"fmt"
)
func main() {
	var grup, anak, total,hasil int
	total =0
	fmt.Scan(&grup)
	for i:=0; i<grup; i++ {
		fmt.Scan(&anak)
		total += anak
	}
	if total%4==0 {
		hasil=total/4
	} else {hasil=(total/4)+1}
	fmt.Println(hasil)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	r.ReadString('\n')
	ss, _ := r.ReadString('\n')
	var ct1, ct2, ct3, ct4 int
	for _, s := range ss {
		switch s {
		case '1':
			ct1++
		case '2':
			ct2++
		case '3':
			ct3++
		case '4':
			ct4++
		}
	}
	var res int
	res += ct4
	res += ct3
	if ct1 > ct3 {
		ct1 = ct1 - ct3
	} else {
		ct1 = 0
	}
	res += ct2 / 2
	ct2 = ct2 % 2
	if ct2%2 == 1 {
		res++
		ct2 = 0
		if ct1 == 1 {
			ct1--
		}
		if ct1 == 2 {
			ct1 -= 2
		}
	}
	if ct1%4 == 0 {
		res += ct1 / 4
	} else {
		res += ct1/4 + 1
	}
	fmt.Println(res)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	r.ReadString('\n')
	ss, _ := r.ReadString('\n')
	var ct1, ct2, ct3, ct4 int
	for _, s := range ss {
		switch s {
		case '1':
			ct1++
		case '2':
			ct2++
		case '3':
			ct3++
		case '4':
			ct4++
		}
	}
	var res int
	res += ct4
	res += ct3
	if ct1 > ct3 {
		ct1 = ct1 - ct3
	} else {
		ct1 = 0
	}
	res += ct2 / 2
	ct2 = ct2 % 2
	if ct2%2 == 1 {
		res++
		ct2 = 0
		if ct1 == 1 {
			ct1--
		}
		if ct2 == 2 {
			ct1 -= 2
		}
	}
	if ct1%4 == 0 {
		res += ct1 / 4
	} else {
		res += ct1/4 + 1
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
)

func main() {
	var N, x, a, b, c, d, car int64
	fmt.Scanf("%d\n", &N)
	for i := int64(0); i < N; i++ {
		fmt.Scanf("%d", &x)
		switch x {
		case 1:
			a++
		case 2:
			b++
		case 3:
			c++
		case 4:
			d++
		}
	}
	car = d

	if a < c {
		car += c
		a = 0
	} else {
		car += c
		a = a - c
	}
	if a > b {
		car += b
		car += (a - (b * 2)) / 4
		if (a-(b*2))%4 != 0 {
			car++
		}
	} else {
		car += b / 2
		if b%2 != 0 {
			car++
			if a > 2 {
				a = a - 2
			}
		}
		car += a / 4
		if a%4 != 0 {
			car++
		}
	}

	fmt.Println(car)

}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)

    tot := 0
    for i := 0 ; i < n ; i++ {
        var s int
        fmt.Scan(&s)
        tot += s
    }

    ans := tot / 4
    if tot % 4 != 0 {
        ans++
    }
    fmt.Println(ans)
}

package main

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

func main() {
	// os.Stdin, _ = os.Open("input.txt")
	in := bufio.NewReader(os.Stdin)
	in.ReadString('\n')
	s, _ := in.ReadString('\n')
	str := strings.Fields(s)

	var n1, n2, n3, n4 int
	for _, v := range str {
		switch v {
		case "1":
			n1++
		case "2":
			n2++
		case "3":
			n3++
		case "4":
			n4++
		}
	}

	taxi := n4
	if n3-n1 >= 0 {
		taxi += n3
		n1 = 0
	} else {
		taxi += n3
		n1 -= n3
	}
	taxi += n2 / 2
	left := 2 + n1
	if left > 0 && left <= 4 {
		taxi++
	} else {
		taxi += left / 4
		if left%4 > 0 {
			taxi++
		}
	}

	fmt.Println(taxi)

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	Group1 = 0
	Group2 = 1
	Group3 = 2
	Group4 = 3
)

func readGroups() []int64 {
	reader := bufio.NewReader(os.Stdin)
	line, _, _ := reader.ReadLine()
	count, _ := strconv.ParseInt(string(line), 10, 64)

	v, _, _ := reader.ReadLine()
	list := make([]int64, count)

	values := strings.Split(string(v), " ")
	for i, v := range values {
		list[i], _ = strconv.ParseInt(v, 10, 64)
	}

	return list
}

func main() {
	groups := readGroups()
	counts := [4]int{0, 0, 0, 0}

	for _, g := range groups {
		counts[g-1]++
	}

	cars := counts[Group4]
	counts[Group4] = 0

	min1And3 := int(math.Min(float64(counts[Group1]), float64(counts[Group3])))

	cars += min1And3
	counts[Group1] -= min1And3
	counts[Group3] -= min1And3

	if counts[Group3] > 0 {
		cars += counts[Group3]
		counts[Group3] = 0
	}

	carsOf2 := counts[Group2] / 2
	cars += carsOf2
	counts[Group2] -= carsOf2 * 2

	if counts[Group2] == 1 {
		cars++
		counts[Group2] = 0

		if counts[Group1] == 1 {
			counts[Group1]--
		} else if counts[Group1] >= 2 {
			counts[Group2] -= 2
		}
	}

	cars1 := counts[Group1] / 4
	cars += cars1

	counts[Group1] -= cars1 * 4

	cars += counts[Group1] % 4

	fmt.Println(cars)
}

package main

import "fmt"

func main() {
	var n, tp int
	fmt.Scan(&n)
	counter := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Scan(&tp)
		counter[tp]++
	}
	counter[1] -= counter[3]
	total := counter[3] + counter[4] + counter[2]/2 + counter[1]/4
	if counter[2]%2 == 1 {
		total++
		counter[1] -= 2
	}
	if counter[1] < 0 {
		counter[1] = 0
	}
	if counter[1]%4 != 0 {
		total++
	}
	fmt.Println(total)
}

package main

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

func main() {
	//os.Stdin, _ = os.Open("input.txt")
	in := bufio.NewReader(os.Stdin)
	in.ReadString('\n')
	s, _ := in.ReadString('\n')
	str := strings.Fields(s)

	var n1, n2, n3, n4 int
	for _, v := range str {
		switch v {
		case "1":
			n1++
		case "2":
			n2++
		case "3":
			n3++
		case "4":
			n4++
		}
	}

	taxi := n4
	if n3-n1 > 0 {
		taxi += n3
		n1 = 0
	} else {
		taxi += n3
		n1 -= n3
	}
	taxi += n2 / 2
	left := n2%2 + n1
	if left <= 4 && left > 0 {
		taxi++
	} else {
		taxi += left / 4
		if left%4 > 0 {
			taxi++
		}
	}

	fmt.Println(taxi)

}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(one int, two int, three int, four int) int {
	//fmt.Println(one, two, three, four)
	if three >= one {
		three -= one
		four += one
		one = 0
	} else {
		one -= three
		four += three
		three = 0
		if two%2 == 1 {
			if one >= 2 {
				one -= 2
			} else {
				one = 0
			}
			two--
			four++
		}
	}
	//fmt.Println(one, two, three, four)

	return four + (three + (2*two)/2 + one)
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var n, ret int
	var one, two, three, four int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())

	for x := 0; x < n; x++ {
		scanner.Scan()
		temp := fastGetInt(scanner.Bytes())
		if temp == 4 {
			four++
		}
		if temp == 3 {
			three++
		}
		if temp == 2 {
			two++
		}
		if temp == 1 {
			one++
		}
	}
	//======================================================
	ret = solution(one, two, three, four)
	//==================== OUTPUT ==========================
	fmt.Println(ret)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var i,n,f int
	var groups[4]int
	groups = [4]int{0,0,0,0}

	fmt.Scan(&n)
	for i=0;i<n;i++ {
	    fmt.Scan(&f)
		groups[f-1]++
	}
	taxi := groups[3]
	remain1 := int(math.Min(float64(groups[0]),float64(groups[2])))
	taxi += remain1
	taxi += groups[1]/2
	remain2 := groups[1]%2
	if remain1-groups[2]==0 {
	    if remain1-groups[0]==0 {
			taxi += remain2
		} else {
			remain1 = groups[0]-remain1
			if remain1 < remain2 {
				taxi += remain2
			} else {
			    taxi += remain1
			}
		}
	} else {
		taxi += remain2
		taxi += groups[2] - remain1
	}
	fmt.Println(taxi)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Scan()
	l := sc.Text()
	gs := strings.Split(l, " ")
	m := make(map[int]int)
	for _, g := range gs {
		nr, _ := strconv.Atoi(g)
		m[nr] = m[nr] + 1
	}
	c := m[4]
	d := m[3] - m[1]
	if d < 0 {
		m[1] = m[1] - m[3]
		m[3] = 0
	} else {
		m[1] = 0
	}
	c = c + m[3]
	if m[2]%2 == 0 {
		c = c + m[2]/2
		m[2] = 0
	} else {
		c = c + (m[2]-1)/2
		m[2] = 1
	}
	d = m[2]*2 + m[1]
	if d%4 == 0 {
		c = c + d/4
	} else {
		c = c + d/4 + 1
	}
	fmt.Println(c)
}

package main

import (
	"fmt"
)

func main() {
	var N, x, a, b, c, d, car int
	fmt.Scanf("%d\n", &N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &x)
		switch x {
		case 1:
			a++
		case 2:
			b++
		case 3:
			c++
		case 4:
			d++
		}
	}
	car = d

	if a < c {
		car += c
	} else {
		car += c
		a = a - c
	}
	if a > b {
		car += b
		car += (a-(b*2))/4 + (a-(b*2))%4
	} else {
		car += b/2 + b%2
	}

	fmt.Println(car)

}

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

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

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

Sample test(s)
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
Note
In the first test we can sort the children into four cars like this:

the third group (consisting of four children),
the fourth group (consisting of three children),
the fifth group (consisting of three children),
the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
*/

package main

import (
	"fmt"
	"bufio"
	"os"
	"log"
	"strconv"
	"sort"
)

func taxi(n int, S []int) {
	var texiCount = 0
	sort.Sort(sort.Reverse(sort.IntSlice(S)))
	for i, j := 0, n-1; i <= j; i++ {
		switch S[i] {
		case 4:
			texiCount++
		case 3:
			if S[j] == 1 {
				j--
			}
			texiCount++
		case 2:
			if i+1 < j && S[i+1] == 2 {
				i++
			} else {
				if i < j && S[j] == 1 {
					j--
				}
				if i < j && S[j] == 1  {
					j--
				}
			}
			texiCount++
		case 1:
			inc := 0
			if (j - i)%4 != 0 {
				inc = 1
			}
			texiCount += (j-i)/4 + inc
		}
	}
	fmt.Println(texiCount)
}

func scanInts() []int {
	ret := make([]int, 0, 20)
	scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
	scanner.Split(bufio.ScanWords)
	for scanner.Scan() {
		text := scanner.Text()
		n, err := strconv.Atoi(text)
		if err != nil {
			log.Fatalf("Not a number: %s", text)
		}
		ret = append(ret, n)
	}
	return ret
}

func main() {
	ints := scanInts()
	n := ints[0]
	S := ints[1:]
	if len(S) != n {
		log.Fatalf("Illegal Input: n-> %d, S-> %#v", n, S)
	}
	taxi(n, S)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	Group1 = 0
	Group2 = 1
	Group3 = 2
	Group4 = 3
)

func readGroups() []int64 {
	reader := bufio.NewReader(os.Stdin)
	line, _, _ := reader.ReadLine()
	count, _ := strconv.ParseInt(string(line), 10, 64)

	v, _, _ := reader.ReadLine()
	list := make([]int64, count)

	values := strings.Split(string(v), " ")
	for i, v := range values {
		list[i], _ = strconv.ParseInt(v, 10, 64)
	}

	return list
}

func main() {
	groups := readGroups()
	counts := [4]int{0, 0, 0, 0}

	for _, g := range groups {
		counts[g-1]++
	}

	cars := counts[Group4]
	counts[Group4] = 0

	min1And3 := int(math.Min(float64(counts[Group1]), float64(counts[Group3])))

	cars += min1And3
	counts[Group1] -= min1And3
	counts[Group3] -= min1And3

	if counts[Group3] > 0 {
		cars += counts[Group3]
		counts[Group3] = 0
	}

	carsOf2 := counts[Group2] / 2
	cars += carsOf2
	counts[Group2] -= carsOf2 * 2

	if counts[Group2] == 1 {
		cars++
		counts[Group2] = 0

		if counts[Group1] == 1 {
			counts[Group1]--
		} else if counts[Group1] >= 2 {
			counts[Group2] -= 2
		}
	}

	cars1 := counts[Group1] / 4
	cars += cars1

	counts[Group1] -= cars1 * 4

	if counts[Group1] <= 4 {
		cars += 1
		counts[Group1] = 0
	}

	cars += counts[Group1] % 4

	fmt.Println(cars)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Scan()
	ss := strings.Split(sc.Text(), " ")
	var sum int
	for _, s := range ss {
		n, _ := strconv.Atoi(s)
		sum += n
	}
	if sum%4 == 0 {
		fmt.Println(sum / 4)
		return
	}
	fmt.Println(sum/4 + 1)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, i, ctr, c1, c2, c3, c4 int
	fmt.Scan(&n)
	s := make([]int, n)
	for i = 0; i < n; i++ {
		fmt.Scan(&s[i])
		if s[i] == 1 {
			c1++
		} else if s[i] == 2 {
			c2++
		} else if s[i] == 3 {
			c3++
		} else {
			c4++
		}
	}

	ctr += c4 + c2/2
	c2 = c2 % 2
	if c3 > 0 && c1 > 0 {
		if c3 > c1 {
			ctr += c1
			c3 = c3 - c1
			c1 = 0
		} else {
			ctr += c3
			c3 = 0
			c1 = c1 - c3
		}
	}
	ctr += c3
	if c2 == 1 && c1 >= 1 {
		ctr++
		if c1 >= 2 {
			c2 = 0
			c1 = c1 - 2
		} else {
			c2 = 0
			c1 = c1 - 1
		}
	} else if c2 == 1 {
		c2 = 0
		ctr++
	}

	if c2 > 0 {
		ctr++
	}

	if c1 > 0 {
		ctr += int(math.Ceil(float64(c1 / 4)))
	}

	fmt.Println(ctr)
}

// 7.Codeforce 158b-Michael542
package main

import (
	"fmt"
)

func main() {
	var a, tmp, n, car, sisa, total int
	fmt.Scan(&a)
	z := make([]int, a)
	n = a - 1
	m := 0
	for y := 0; y < a; y++ {
		fmt.Scan(&z[y])
		total += z[y]
	}
	for x := 0; x < a; x++ {
		for e := 0; e < a-1; e++ {
			if z[x] > z[e] {
				tmp = z[x]
				z[x] = z[e]
				z[e] = tmp
			}
		}
	}
	if m == n {
		car++
	} else if total%4 == 0 {
		car = total / 4
	} else {
		for m <= n {
			sisa = 4 - z[m]
			for sisa >= z[n] && m <= n && n != m {
				sisa -= z[n]
				n--
			}
			car++
			m++
		}
	}
	fmt.Println(car)
}

package main

import "fmt"

func ReadN(all []int, i, n int) {
	if n == 0 {
		return
	}
	if m, err := Scan(&all[i]); m != 1 {
		panic(err)
	}
	ReadN(all, i+1, n-1)
}

func Scan(a *int) (int, error) {
	return fmt.Scan(a)
}

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

func main() {
	var n int
	fmt.Scanf("%d", &n)
	all := make([]int, n)
	ReadN(all, 0, n)
	counts := make([]int, 5, 5)
	answer := 0
	for _, v := range all {
		counts[v]++
	}
	answer += counts[4]
	m := min(counts[1], counts[3])
	answer += m
	counts[1] -= m
	counts[3] -= m
	c2 := counts[2]
	m2 := counts[2] / 2
	answer += m2
	counts[2] = 0
	if c2%2 > 0 {
		counts[2]++
	}
	m1 := min(counts[1], counts[2])
	answer += m1
	counts[1] -= m1
	counts[2] -= m1
	r := counts[1] % 4
	answer += counts[1]/4 + r
	answer += counts[2]
	answer += counts[3]
	fmt.Println(answer)
}

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

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

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

Sample test(s)
input
5
1 2 4 3 3
output
4
input
8
2 3 4 4 2 1 3 1
output
5
Note
In the first test we can sort the children into four cars like this:

the third group (consisting of four children),
the fourth group (consisting of three children),
the fifth group (consisting of three children),
the first and the second group (consisting of one and two children, correspondingly).
There are other ways to sort the groups into four cars.
*/

package main

import (
	"fmt"
	"bufio"
	"os"
	"log"
	"strconv"
	"sort"
)

func taxi(n int, S []int) {
	var texiCount = 0
	sort.Sort(sort.Reverse(sort.IntSlice(S)))
	for i, j := 0, n-1; i <= j; i++ {
		switch S[i] {
		case 4:
			texiCount++
		case 3:
			if S[j] == 1 {
				j--
			}
			texiCount++
		case 2:
			if i+1 <= j {
				switch S[i+1] {
				case 2:
					i++
				case 1:
					i++
				}
			}
			texiCount++
		case 1:
			inc := 0
			if len(S[i:j+1])%4 != 0 {
				inc = 1
			}
			texiCount += len(S[i:j+1])/4 + inc
		}
	}
	fmt.Println(texiCount)
}

func scanInts() []int {
	ret := make([]int, 0, 20)
	scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
	scanner.Split(bufio.ScanWords)
	for scanner.Scan() {
		text := scanner.Text()
		n, err := strconv.Atoi(text)
		if err != nil {
			log.Fatalf("Not a number: %s", text)
		}
		ret = append(ret, n)
	}
	return ret
}

func main() {
	ints := scanInts()
	n := ints[0]
	S := ints[1:]
	if len(S) != n {
		log.Fatalf("Illegal Input: n-> %d, S-> %#v", n, S)
	}
	taxi(n, S)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	var scanner *bufio.Scanner
	var numbers []string
	var count = map[string]int{
		"1": 0,
		"2": 0,
		"3": 0,
		"4": 0,
	}

	scanner = bufio.NewScanner(os.Stdin)

	if scanner.Scan() {
		_, err := strconv.Atoi(scanner.Text())
		if err != nil {
			panic(err)
		}
	}

	if scanner.Scan() {
		numbers = strings.Fields(scanner.Text())
		for _, number := range numbers {
			count[number]++
		}
	}

	fmt.Println(minimumTaxis(count))
}

func minimumTaxis(count map[string]int) int {
	var minimum int = 0

	minimum += count["4"]
	minimum += count["3"]

	if count["1"] > count["3"] {
		count["1"] -= count["3"]
	} else {
		count["1"] = 0
	}

	minimum += count["2"] / 2
	count["2"] = count["2"] % 2
	minimum += count["2"]

	if count["2"] != 0 {
		if count["1"] > count["2"] {
			count["1"] -= count["1"]
		} else {
			count["1"] = 0
		}
	}

	minimum += int(math.Ceil(float64(count["1"]) / 4))

	return minimum
}