import scala.collection.mutable.Queue
import io.StdIn

object Main extends App {
  val n = StdIn.readInt
  val seq = StdIn.readLine.split(" ").map(_.toInt % 3)
  val a = for(i <- 0 until 3) yield seq.count(_ == i)

  def bfs(first:Tuple5[Int,Int,Int,Int,Int]):Int = {

    val que = new Queue[Tuple5[Int,Int,Int,Int,Int]]
    que += first
    var cur = (0,0,0,0,0)

    var isCnt = true
    while(isCnt || !que.isEmpty) {
      cur = que.dequeue

      if(cur._2 == 0 || (cur._3 == 0 && cur._4 == 0 && cur._5 == 0)) isCnt = false
      else {
        cur match {
          case (acc, 1, c0, c1, c2) if c0 != 0 => que += {(acc+1, 1, c0-1, c1, c2)}
          case (acc, 2, c0, c1, c2) if c0 != 0 => que += {(acc+1, 2, c0-1, c1, c2)}
          case (acc, 1, c0, c1, c2) if c1 != 0 => que += {(acc+1, 2, 0, c1-1, c2)}
          case (acc, 2, c0, c1, c2) if c2 != 0 => que += {(acc+1, 1, 0, c1, c2-1)}
          case (acc, 2, c0, c1, c2) if c1 != 0 => que += {(acc+1, 0, 0, c1-1, 0)}
          case (acc, 1, c0, c1, c2) if c2 != 0 => que += {(acc+1, 0, 0, 0, c2-1)}
        }
      }
    }
    cur._1
  }

  val res1 = if(a(1) == 0) 0 else bfs(0,1,a(0),a(1)-1,a(2)) + 1
  val res2 = if(a(2) == 0) 0 else bfs(0,2,a(0),a(1),a(2)-1) + 1
  val ans = if(a.drop(1).sum == 0) 1 else math.max(res1,res2)
  println(ans)
}
