Problem:


Score : 400 points

Problem Statement

Snuke has decided to play a game using cards.
He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written.

He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept.

Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.

Constraints

3 ≦ N ≦ 10^{5}

N is odd.

1 ≦ A_i ≦ 10^{5}

A_i is an integer.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_{N}

Output

Print the answer.

Sample Input 1

5
1 2 1 3 7

Sample Output 1

3

One optimal solution is to perform the operation once, taking out two cards with 1 and one card with 2. One card with 1 and another with 2 will be eaten, and the remaining card with 1 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 1, 3 and 7.

Sample Input 2

15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1

Sample Output 2

7



Sample input:
5
1 2 1 3 7


Sample output:
3

Submission status: Accepted

Solution code:
from itertools import groupby

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

A=groupby(A)
odd=0
even=0
for key,group in A:
    g=len(list(group))
    if g%2==1:
        odd+=1
    else:
        even+=1

if even%2==1:
    print(odd+even-1)
else:
    print(odd+even)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
a.sort()
b = sorted(list(set(a)))
c = Counter(a)
lenb = len(b)
d = [0 for _ in range(lenb)]
for i in range(lenb):
    d[i] = c[b[i]] - 1
t = sum(d)

if t % 2 == 1:
    t += 1
print(n - t)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))

cnt=Counter(a)
numofcard=len(cnt)
#print(cnt,numofcard)

count=0
for i in cnt.values():
    if i==2:
        count+=1
    elif i>3 and i%2==0:
        count+=1
print(numofcard if count%2==0 else numofcard-1)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    
    kind = set(A)
    if len(kind) % 2 == 0:
        print(len(kind) - 1)
    else:
        print(len(kind))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n=int(input())
a=set(list(map(int,input().split())))
al=len(a)
print(al if al%2==1 else al-1)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

c=Counter(a)

cnt=0
ans=0

for v in c.values():
  ans+=1
  if v%2==0:
    cnt+=1

if cnt%2==1:
  ans-=1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
# num={}
# for ai in a:
#     num_ai=num.get(ai, 0)
#     num[ai]=num_ai+1

# even=0
# odd=0
# for k,v in num.items():
#     if(v%2==0):
#         even+=1
#     else:
#         odd+=1


# if(even==0):
#     print(len(num))
# else:
#     print(len(num)-1)

seta=set(a)
if(len(seta)%2==0):
    print(len(seta)-1)
else:
    print(len(seta))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
s = set(A)
k = len(s)
if k % 2 == 0:
    print(k - 1)
else:
    print(k)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))

print(len(set(a)) if (len(a)-len(set(a)))%2==0 else len(set(a))-1)

Submission status: Accepted

Solution code:
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from collections import defaultdict as dd
n=int(input())
a=nl()
a.sort()

d=dd(int)
for aa in a:
    d[aa]+=1
counter=0
for k,v in d.items():
    if v%2==0:
        counter+=v-1
if counter%2==0:
    print(len(d))
else:
    print(len(d)-1)

Submission status: Accepted

Solution code:
N = int(input())
A = set(list(map(int,input().split())))
l = len(A)
if l%2 == 0:
    print(l-1)
else:
    print(l)

Submission status: Accepted

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)

kv = sorted(list(C.items()))
_, nums = zip(*kv)

nums = list(nums)

l = 0
r = len(nums) - 1
adjust = 0
while l <= r:
    if l == r:
        adjust = 1 if nums[r] % 2 == 0 else 0
        nums[r] = 1
        break

    if nums[l] == 1:
        l += 1
        continue
    if nums[r] == 1:
        r -= 1
        continue

    eat = min(nums[l], nums[r]) - 1
    nums[l] -= eat
    nums[r] -= eat

ans = len(nums) - nums.count(0) - adjust
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
s = set()
count = 0
for x in A:
    if x not in s:
        s.add(x)
    else:
        count += 1

if count % 2 == 0:
    print(len(s))
else:
    print(len(s) - 1)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    mc = c.most_common()
    ans = len(mc)
    need = 0
    for cnt in mc:
        if cnt[1] > 1:
            need += cnt[1] - 1
    print(ans if need % 2 == 0 else ans - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]

M = 10**5+1
L = [0]*M
for a in A:
    L[a] += 1

ans = 0
cnt = 0
for i in range(M):
    if L[i] > 0:
        ans += 1
    if L[i] > 1 and L[i]%2 == 0:
        cnt += 1

if cnt%2 == 1:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
from collections import Counter
ctr = Counter(A)
doub = 0
for v in ctr.values():
    doub += v-1
n = len(ctr)
print(n if doub%2==0 else n-1)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
a.sort()
cnt = -1
prev = a[0]
b = []
for i in a:
    if prev==i: cnt+=1
    else:
        b.append(cnt)
        cnt = 0
    prev = i
b.append(cnt)
print(n-(sum(b)+1)//2*2)

Submission status: Accepted

Solution code:
input()
print((len(set(input().split()))-1)//2*2+1)

Submission status: Accepted

Solution code:
N, = map(int, input().split())
A = list(map(int, input().split()))
K = len(set(A))
if K % 2:
    print(K)
else:
    print(K-1)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

ans = 1
for i in a:
    if i >= 2:
        ans += i - 1
ans //= 2
ans *= 2
print(N - ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
dup=0
uniq=1
last=a[0]
for i in range(1,len(a)):
    if a[i] == last:
        dup+=1
    else:
        uniq+=1
    last=a[i]

if dup%2==0:
    print(uniq)
else:
    print(uniq-1)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
AC=Counter(A)

goukei=sum(list(AC.values()))
shurui=len(AC.keys())
yobun=goukei-shurui
if yobun%2==0:
    print(shurui)
else:
    print(shurui-1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    d = dict(Counter(v))
    ans = 0
    for val in d.values():
        if val > 1:
            ans += val - 1
    if ans % 2 == 0:
        print(n - ans)
    else:
        print(n - ans - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter(A)

counts = counter.most_common()

dup_num = 0
for i in range(len(counts)):
    if counts[i][1] != 1:
        dup_num += counts[i][1]-1

if dup_num%2 == 0:
    print(N-dup_num)
else:
    print(N-dup_num-1)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A = list(map(int,input().split()))
Ac = Counter(A)
kind = len(Ac)
Av = sum(i-1 for i in Ac.values() if i != 1)
if Av%2 == 0:
    print(kind)
else:
    print(kind-1)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

cnt = [0] * (10 ** 5 + 1)
for a in A:
  cnt[a] += 1

cnt2 = 0
answer = 0
for i in range(10 ** 5 + 1):
  if cnt[i]:
    answer += 1
  if cnt[i] > 1 and cnt[i] % 2 == 0:
      cnt2 += 1
print(answer if cnt2 % 2 == 0 else answer - 1)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

l=[0]*10**5

for item in A:
    l[item-1]+=1

ex=0
for item in l:
    ex+=max(item-1,0)

if ex%2==1:
    print(N-ex-1)
else:
    print(N-ex)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=Counter(list(map(int,input().split())))
D=sum([A[i]-1 for i in A if A[i]>=2])
print(N-(D+D%2))
#print(sorted([[i,A[i]-1] for i in A if A[i]>=2],key=lambda x:x[0]))

Submission status: Accepted

Solution code:
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/arc067/tasks/arc067_a
# C - Factors of Factorial
"""
need to consider the case that ticket is not enough to lower everything
"""

N = gi()
A = {}
for i in range(N):
    a = gi()
    if a in A:
        A[a] += 1
    else:
        A[a] = 1

ec = 0
for _, v in A.items():
    if (v > 1 and v % 2 == 0):
        ec += 1
ans = len(A)

if (ec % 2):
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(set(a))
m = len(b)
if m%2==0:
    print(m-1)
else:
    print(m)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(set(a))
m = len(b)
if m%2==0:
    print(m-1)
else:
    print(m)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
ans=0
cnt=0
for i in range(n):
  if a[i] not in d:
    d[a[i]]=1
  else:
    d[a[i]]+=1
nd=list(d.items())
for i in range(len(nd)):
  ans+=nd[i][1]-1
  if nd[i][1]%2==0:
    cnt+=1
print(n-ans-cnt%2)

Submission status: Accepted

Solution code:
n = int(input())
a = set(map(int, input().split()))
kinds = len(a)
if kinds % 2 == 1:
    print(kinds)
else:
    print(kinds - 1)

Submission status: Accepted

Solution code:
from collections import Counter

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

C=dict(Counter(A))
# print(A)
n=len(C)
# print(C)
r=sum([e-1 for e in C.values() if e>=2])

ans=n-r%2
print(ans)

# (k)->(k-2) k>=3
# (k,l)->(k-1,l-1) k>=2 or l>=2
# (k,l,m)->(k-1,l,m-1)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
D={}

s=0
for i in range(N):
    if D.get(A[i],None)==None:
        D[A[i]]=1
    else:
        D[A[i]]+=1
        s+=1

if s%2==1:
    print(N-s-1)
else:
    print(N-s)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)

if len(c)%2 == 1:
    print(len(c))
else:
    print(len(c)-1)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
setA = set(A)
print(len(setA)-(N-len(setA))%2)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
len_c = len(c)
b = {k:v for k,v in c.items() if v > 1}
sum_b = sum(b.values())
if n == 3:
    print(1)
if (sum_b + len(b)) % 2 == 0:
    print(len_c)
else:
    print(len_c - 1)

Submission status: Accepted

Solution code:
N=int(input())
la=list(map(int,input().split()))
da={}
for ll in la:
    if not ll in da:
        da[ll]=1
if (N-len(da))%2==0:
    print(len(da))
else:
    print(len(da)-1)

Submission status: Accepted

Solution code:
N=int(input())
la=list(map(int,input().split()))
da={}
for ll in la:
    if not ll in da:
        da[ll]=1
    elif da[ll]==1:
        da[ll]=2
    else:
        da[ll]=1
nev=0
for dd in da:
    if da[dd]==2:
        nev+=1
if nev%2==0:
    print(len(da))
else:
    print(len(da)-1)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

if len(c) % 2 == 0:
    ans = len(c) - 1
else:
    ans = len(c)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter as C
N = int(input())
A = C([int(a) for a in input().split()])
X = []
for a in A:
    X.append(A[a]-1)
print(N - (sum(X)+1)//2*2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

def solve():
    N = int(input())
    A = map(int, input().split())
    C = Counter(A)
    res = len(C)-(N-len(C))%2
    return str(res)

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n=inp()
    a=inpl()
    dic={}
    ans=0
    for i in range(n):
        if a[i] not in dic:
            dic[a[i]]=1
            ans+=1
    if ans%2==0:
        ans-=1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

count_A = Counter(A)
# print(count_A)

gusu = 0
for a in count_A:
    if count_A[a] % 2 == 0:
        gusu += 1
print(len(count_A) - gusu % 2)

Submission status: Accepted

Solution code:
N = int(input())
fq = [0] * int(10**5 + 10)
A = list(map(int, input().split()))
for a in A:
    fq[a] += 1
fq = [f if f % 1 == 0 else 1 for f in fq]
cnt_even = 0
cnt_odd = 0
for f in fq:
    if f & 1 == 0 and f != 0:
        cnt_even += 1
    if f & 1 == 1:
        cnt_odd += 1
if cnt_even & 1 == 0:
    print(cnt_even + cnt_odd)
else:
    print(cnt_even - 1 + cnt_odd)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
even = 0 
odd = 0
for x in C.values():
    if x&1:
        odd += 1
    else:
        even += 1

print(odd + even - even%2)

Submission status: Accepted

Solution code:
n=int(input())
s=set(map(int,input().split()))
k=len(s)
if k%2==1:
    print(k)
else:
    print(k-1)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
if (sum(ct.values()) - len(ct)) % 2 == 0:
    print(len(ct))
else:
    print(len(ct) - 1)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
ca = Counter(A)

c = 0
for i, v in ca.items():
  c += v - 1
if c % 2 == 0:
  print(len(ca))
else:
  print(len(ca) - 1)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    set_A = set(A)

    if len(set_A) % 2 == 0:
        print(len(set_A)-1)
    else:
        print(len(set_A))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=sorted(Counter(map(int,input().split())).values())
A=list(filter(lambda x:x>0,map(lambda x:x-1,A)))

m=sum(A)

if m%2==0:
  print(N-m)
else:
  print(N-m-1)

Submission status: Accepted

Solution code:
n = int(input())
ar = list(map(int, input().split()))
count = {}
for val in ar:
    if val not in count:
        count[val] = 1
    else:
        count[val] += 1
ones = 0
twos = 0
for val in count:
    if count[val] % 2 == 0:
        twos += 1
    else:
        ones += 1
if twos % 2 == 0:
    print(ones + twos)
else:
    print(ones + twos - 1)

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
variety=0
countodd=0
counteven=0
countnow=1
now=l[0]
for i in range(1,n):
  if l[i]==now:
    countnow+=1
  else:
    now=l[i]
    if countnow%2==1:
      countodd+=1
    else:
      counteven+=1
    countnow=1
if countnow!=0:
  if countnow%2==1:
    countodd+=1
  else:
    counteven+=1
if counteven%2==0:
  print(counteven+countodd)
else:
  print(counteven+countodd-1)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))

num = [0] * (10**5+1)
for i in a:
    num[i] += 1

a = [i for i in num if i != 0]
ans = N
for i in range(len(a)):
    eat = (a[i]-1) // 2
    a[i] -= eat * 2
    ans -= eat * 2

ans -= a.count(2)//2 * 2
if a.count(2) % 2 == 1:
    ans -= 2
print(ans)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

def main():
    _ = int(input())
    A = list(map(int, input().split()))

    D = dict()
    for a in A:
        if a in D:
            D[a] += 1
        else:
            D[a] = 1

    ans = len(D.items())
    e = 0
    for d in D.items():
        if d[1]%2 == 0:
            e += 1
    if e%2 == 1:
        ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A)

rem = 0
for a in c.values():
    rem += a-1

print(len(c) - rem%2)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))

A.sort()

cnt=0
ans=1
for i in range(1,N):
    if A[i-1]==A[i]:
        cnt+=1



if  cnt%2!=0:
    ans=N-(cnt+1)
else:
    ans=N-cnt

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))

A.sort()

cnt=0
ans=1
for i in range(1,N):
    if A[i-1]==A[i]:
        cnt+=1
    else:
        ans+=1


if  cnt%2!=0:
    ans-=1

print(ans)

Submission status: Accepted

Solution code:
N=int(input())

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

#重複した値だけを集めて消す

sets={}
for i in A:
    if i in sets:
        sets[i]+=1
    else:
        sets[i]=1

duplicate=0
for k,v in sets.items():
    if v>1:
        duplicate+=(v-1)

duplicate %=2

print(len(set(A))-duplicate)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))

import collections
def counter_list(A):
  counter = collections.Counter(A)
  counter =  [list(e) for e in counter.items()]
  #counter.sort() #sortしたい場合はつける
  return counter

#(方針)
#奇数個の重複 → 1個にできる 
#偶数個の重複(=奇数個の重複 +1)　→ 2個にできる 
#2個の重複が2ペア → 重複なし2ペアにできる
A = counter_list(A)
counter2 = 0 #2個重複のペアの個数
for i in range(len(A)):
  if(A[i][1]%2 == 1): A[i][1] = 1
  elif(A[i][1]%2 == 0): A[i][1] = 2
  if(A[i][1] == 2): counter2 += 1
    
if(counter2 % 2 == 0): ans = len(A)
elif(counter2 %2 == 1): ans = len(A)-1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
A.sort()
A_l=len(set(A))
print(A_l if (n-A_l)%2==0 else A_l-1)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = set([int(_) for _ in stdin.readline().rstrip().split()])
if len(A) % 2 == 0:
    print(len(A)-1)
else:
    print(len(A))

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))

k = len(collections.Counter(a))

if k % 2 == 0:
    print(k-1)
else:
    print(k)

Submission status: Accepted

Solution code:
import collections

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

A=list(collections.Counter(A).items())
#print(A)
ans=len(A)


tmp=0
for a in A:
  tmp+=1 if a[1]%2==0 else 0
ans-=1 if tmp%2 else 0

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
setA = set(A)
cnt = len(A) - len(set(A))
if cnt % 2 == 0:
    print(len(setA))
else:
    print(len(setA)-1)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
mina=min(a)
maxa=max(a)
d=sum([x-1 for x in c.values() if x>1])
ans=n-2*max((d+1)//2,(c[mina]-1)//2,(c[maxa]-1)//2)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

cv = Counter(a).values()
lv = len(cv)

print(lv if not (sum(cv) - lv) % 2 else lv - 1)

Submission status: Accepted

Solution code:
"""
自分のみを選択することで

3　- 1
4  - 2
5 -3 -1
6 -4 -2
みたいな感じにできるので実質カードは1か2
で2のやつどうしを組み合わせると2つずつ減ってくので、
2の数字の数-2*k,していって
1 - 1
3 -1
2 2
4 -2
みたいな感じになる。

2のやつが１つあるときは、巻き添えで他1つが死ぬ
2のやつが２つあるときは、巻き添えで他のが死ぬことはない。

"""

n = input()
arr = list(map(int,input().split()))
odd = 0
even = 0
cards={}

for a in arr:
    if a not in cards:
        cards[a] = 1
    else:
        cards[a]+=1

for key in cards.keys():
    if cards[key]%2 == 0:
        even += 1
    else:
        odd += 1

if even%2 == 1:
    print(even+odd-1)
else:
    print(even+odd)

Submission status: Accepted

Solution code:
N=map(int,input().split())
A=tuple(map(int,input().split()))
l=[0]*(10**5+1)
for i in A:
    l[i]+=1
a=0
t=0
for i in l:
    if i!=0:
        a+=1
        if i%2==0:
            t+=1
if t%2==1:
    a-=1
print(a)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()

C = {}
for a in A:
  if a in C:
    C[a] += 1
  else:
    C[a] = 1
#print(C)
CK = [k for k in C.keys()]
#print(CK)
i = 0
flag = 0
while(i < len(CK)):
  if flag == 0:
    if C[CK[i]] >= 3:
      C[CK[i]] = 2 - (C[CK[i]] % 2)
    elif C[CK[i]] == 2:
      C[CK[i]] -= 1
      flag = 1
      i += 1
    else:
      i += 1
  else:
    if C[CK[i]] >= 2:
      C[CK[i]] -= 1
      flag = 0
    else:
      i += 1
ans = -flag
for val in C.values():
  ans += val
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = [int(x) for x in input().split()]
di = defaultdict(int)
for a in A:
    di[a]+=1
print(len(di)-(1-len(di)%2))

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = [int(a) for a in sys.stdin.readline().split()]

dic = {}
for a in A:
  dic[a] = dic.get(a,0) + 1

evenodd = [0,0]
for k in dic:
  evenodd[dic[k]%2] += 1
if evenodd[0]%2==0:
  print(len(dic))
else:
  print(len(dic)-1)

Submission status: Accepted

Solution code:
n=int(input())
s=set(map(int,input().split()))
if (n-len(s))%2==0:
    print(len(s))
else:print(len(s)-1)

Submission status: Accepted

Solution code:
N = int(input())
A = len(set(map(int, input().split())))
print(A - 1 if (N - A)%2 else A)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
Aset = set(A)
print(N - (N - len(Aset)) - (N - len(Aset)) % 2)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))

    dic = {}
    tmp = 0
    for i in range(N):
        if a[i] in dic:
            dic[a[i]] += 1
            tmp += 1
        else:
            dic[a[i]] = 1
    
    print(max(0, N - tmp - int(tmp&1)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import collections
def main():
    N = int(input())
    a = list(map(int,input().split()))
    l = collections.Counter(a)
    l = list(l.items())
    count = 0
    for i in range(len(l)):
        count += l[i][1]-1

    print(N-(-(-count//2)*2))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 2019/09/09

from collections import Counter

n=int(input())
C=Counter(list(map(int,input().split())))

even=0
odd=0
ans=len(C)
for k,v in C.items():
    if v>1:
        if v%2:
            odd+=1
        else:
            even+=1

if even%2:
    ans-=1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]

count=Counter(a)
check=0
for i,j in count.items():
	if j%2==0:
		check+=1
if check%2==0:
	print(len(count))
else:
	print(len(count)-1)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
from collections import Counter
c = Counter(a)
d = dict(c)
ans = 0
cnt = 0
for k, v in d.items():
  if v%2==0:
    d[k] = 2
    cnt += 1
  else:
    d[k] = 1
  ans += 1
if cnt%2==1:
  ans -= 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = set([int(i) for i in input().split()])

if len(A) % 2 == 1:
    print(len(A))
else:
    print(len(A)-1)

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))

kaburi=len(set(A))
if kaburi%2==0:
  print(kaburi-1)
else:
  print(kaburi)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
C = [0 for i in range(10**5+1)]
for a in A:
    C[a] += 1
s = False
for i in range(1, len(C)):
    if C[i] >= 2:
        if C[i] % 2 == 0:
            s = not s
if s:
    print(len(set(A))-1)
else:
    print(len(set(A)))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
L = [int(v) for v in input().split()]
L.sort()

m = {}

for v in L:
    if m.get(v) == None:
        m[v] = 0
    m[v] += 1

if len(m) % 2 == 0:
    print(len(m) - 1)
else:
    print(len(m))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
k = Counter(a)
b = list(k.values())
b = [1 if bb % 2 == 1 else 2 for bb in b]
over_2 = [bb for bb in b if bb >= 2]
if len(over_2) == 0:
    print(len(b))
elif len(over_2) % 2 == 0:
    print(len(b))
else:
    print(len(b) - 1)

Submission status: Accepted

Solution code:
import collections
counter = collections.defaultdict(int)
N = int(input())
A = input().split()

count = 0
for x in A:
    counter[x] += 1

for x in counter:
    if counter[x] != 1:
        count += counter[x] - 1

if count % 2 == 0:
    print(N - count)
else:
    print(N - (count + 1))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]

K = len(set(A))
if K % 2 == 0:
    print(K - 1)
else:
    print(K)

Submission status: Accepted

Solution code:
n = int(input())
an = len({i for i in input().split()})
print(an-1+an%2)

Submission status: Accepted

Solution code:
# ARC068D - Card Eater (ABC053D)
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    ans = len(set(A))
    ans -= (N - ans) % 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
_,a=open(0);a=len(set(a.split()));print(a-(a%2<1))

Submission status: Accepted

Solution code:
from collections import*;n,l=open(0);a=sum(v-1for v in Counter(l.split()).values());print(int(n)-a-(a%2))

Submission status: Accepted

Solution code:
from collections import Counter

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

# カードは1 or 2枚まで減らせる
# Nは奇数なので，1枚のカードは奇数種
# 全体で奇数種のとき，2枚のカードは偶数種
# 偶数種のとき，奇数種
# 2枚のカードはペアで1枚ずつにできる

ans = len(A) - (0 if len(A) % 2 == 1 else 1)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
count = 0
for i in range(N-1):
    if A[i] == A[i+1]:
        count += 1
ans = N-2*(-(-count//2))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = map(int,input().split())
a = set(a)
f = n - len(a)

if f % 2:
	f += 1

print(n - f)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
cnt = 0
for k in c.keys():
    if c[k] % 2 == 0:
        cnt += 1
if cnt % 2:
    print(len(c) - 1)
else:
    print(len(c))

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
d={}
x=0
for a in A:
    if a not in d:
        d[a]=1
    else:
        x+=1
print(len(d) if x%2==0 else len(d)-1)

Submission status: Accepted

Solution code:
N = int(input())
dup = N - len(set(map(int, input().split())))
if dup % 2 == 1:
    dup += 1
print(N - dup)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
m = Counter(A)
ls = []
for x, y in m.items():
    if y%2 == 0:
        ls.append(x)
if len(ls)%2 == 0:
    print(len(m))
else:
    print(len(m)-1)

Submission status: Accepted

Solution code:
from collections import Counter
N= int(input())
A = [int(J) for J in input().split()]
C = Counter(A)
d = len(C)
if d%2:print(d)
else:print(d-1)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
*A, = map(int, input().split())
cnt = Counter(A)
ans = N
duplicates = sorted([(a, d) for a, d in cnt.items() if d > 1], key=lambda x: x[0])
offset = 0
for _, d in duplicates:
    if offset: d -= offset; offset = 0;
    if d == 1: continue
    elif d % 2 == 0: ans -= d; offset = 1;
    else: ans -= d-1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
d={}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1

t=[]
for i in d:
    t.append(d[i])
t.sort(reverse=True)
ans=len(t)
chk=0
#print(t)
for i in t:
    i-=1
    if chk==0:
        chk=i%2
    else:
        chk-=i%2
print(ans-chk)

Submission status: Accepted

Solution code:
def calc(n):
  ret=n
  while ret>=3:
    ret=ret%3+ret//3
  return ret

n=int(input())
arr=list(map(int,input().split()))
cnt=[0]*(10**5+1)
for i in range(n):
  cnt[arr[i]]+=1
cnt1=0
cnt2=0
for i in range(10**5+1):
  tmp=calc(cnt[i])
  if tmp==1:
    cnt1+=1
  elif tmp==2:
    cnt2+=1
if cnt2%2==0:
  print(cnt1+cnt2)
else:
  print(cnt1+cnt2-1)