import scala.annotation.tailrec
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)

  @tailrec
  def rec(acc:Int, hasMany:Int, c0:Int, c1:Int, c2:Int):Int = {
    if(hasMany == 0) acc
    else {
      if(hasMany == 1) {
        if(c0 != 0) rec(acc+1, 1, c0-1, c1, c2)
        else if(c1 != 0) rec(acc+1, 2, 0, c1-1, c2)
        else if(c2 != 0) rec(acc+1, 0, c0, c1, c2-1)
        else acc
      }
      else {
        if(c0 != 0) rec(acc+1, 2, c0-1, c1 ,c2)
        else if(c2 != 0) rec(acc+1, 1, c0, c1, c2-1)
        else if(c1 != 0) rec(acc+1, 0, c0, c1-1, c2)
        else acc
      }
    }
  }

  val res1 = rec(0,1,a(0),a(1)-1,a(2)) + 1
  val res2 = rec(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)
}
