from itertools import groupby

N = int(eval(input()))

A = list(map(int, input().split()))

A.sort()

a = []



for i, j in groupby(A):

    a.append(len(list(j)))





def f(x):

    while x >= 3:

        x = x // 3 + x % 3

    return x





a = [f(i) for i in a]

one = a.count(1)

two = a.count(2)



if two % 2 == 0:

    print((one + two))

else:

    print((one + two - 1))
from collections import Counter

N = int(eval(input()))

A = list(map(int, input().split()))

a = list(Counter(A).values())





def f(x):

    while x >= 3:

        x = x // 3 + x % 3

    return x





a = [f(i) for i in a]

one = a.count(1)

two = a.count(2)



if two % 2 == 0:

    print((one + two))

else:

    print((one + two - 1))
from itertools import groupby

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
a = []
for i, j in groupby(A):
    a.append(len(list(j)))


def f(x):
    while x >= 3:
        x = x // 3 + x % 3
    return x


a = [f(i) for i in a]
one = a.count(1)
two = a.count(2)
if two % 2 == 0:
    print((one + two))
else:
    print((one + two - 1))

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
a = list(Counter(A).values())


def f(x):
    while x >= 3:
        x = x // 3 + x % 3
    return x


a = [f(i) for i in a]
one = a.count(1)
two = a.count(2)
if two % 2 == 0:
    print((one + two))
else:
    print((one + two - 1))

-from itertools import groupby +from collections import Counter -A.sort() -a = [] -for i, j in groupby(A): -    a.append(len(list(j))) +a = list(Counter(A).values())