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:
import collections

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

ans = len(c)
count_even = 0

for num in c.keys():
    if c[num] %2 ==0: count_even += 1

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())

cnt_dict = defaultdict(int)
for a in map(int, input().split()):
    cnt_dict[a] += 1

n_unique = len(cnt_dict.keys())

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N=int(input())
h=[]
a=list(map(int,input().split()))
cnt_dic=defaultdict(int)
for i in range(N):
  cnt_dic[a[i]]+=1
cnt_l=sorted(cnt_dic.values(),reverse=True)
ans=len(cnt_l)
tmp=0
for i in range(ans):
  if cnt_l[i]%2==0:
    tmp+=1
if tmp%2==0:
  pass
else:
  ans-=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0 for i in range(100000+1)]
for i in range(n):
    b[a[i]] += 1
eat = 0
for i in range(100000+1):
    eat += max(0, b[i]-1)
print(n-(eat+1)//2*2)

Submission status: Accepted

Solution code:
from collections import defaultdict
N, *A = map(int, open(0).read().split())
cnt = defaultdict(int)
csum = 0
for a in A:
    cnt[a] += 1
    csum += 1

dup = 0
for v in cnt.values():
    if v > 1:
        dup += v-1
        
if dup & 1:
    print(N-dup-1)
else:
    print(N-dup)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
a = {}
for i in A:
	if i in a:
		a[i] += 1
	else:
		a[i] = 1
b = 0
for i in a.values():
	if i % 2 == 0:
		b += 1
if b % 2:
	print(len(a) - 1)
else:
	print(len(a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
data = [0] * (10**5+1)
for ai in A:
  data[ai] += 1
for i ,di in enumerate(data):
  if di >= 3 and di%2 == 1:
    data[i] =1
  elif di >= 3:
    data[i] = 2
c1 = c2 = 0
for i,di in enumerate(data):
  if di == 1:
    c1 += 1
  elif di == 2:
    c2 += 1

print(c1+c2//2*2)

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    from collections import defaultdict
    dd = defaultdict(int)
    
    for i in range(N):
        dd[A[i]]+=1
        
    eat=0
    for k,v in dd.items():
        if v!=1:
            eat+=v-1
    if eat%2==1:
        eat+=1        
    
    print(N-eat)

main()

Submission status: Accepted

Solution code:


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

Submission status: Accepted

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

eat = 0
l = 0
r = n-1
while l < r:
    while l < n - 1 and a[l+1] != a[l]:
        l += 1
    while r > 0 and a[r-1] != a[r]:
        r -= 1
    if r <= l:
        break
    eat += 1
    l += 1
    r -= 1
print(n-eat*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a_i = list(map(int, input().split()))
duplicationCheckList = [0] * 10 ** 5
duplicationMaisuu = 0
for x in a_i:
    if duplicationCheckList[x - 1] == 1: duplicationMaisuu += 1
    else: duplicationCheckList[x - 1] = 1
count = (duplicationMaisuu + 1) // 2
print(n - count * 2)

Submission status: Accepted

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

Submission status: Accepted

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

m = 0
cnt = 0
for i in A:
  if(m != i):
    m = i
    cnt += 1

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

Submission status: Accepted

Solution code:
from collections import Counter
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
u = np.unique(A)
if len(u) % 2 == 0:
    print(len(u) - 1)
else:
    print(len(u))

Submission status: Accepted

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

# 2枚以上のところから-1, それ以外(2枚以上を優先しないなら1枚)のところから-1を繰り返す
# 3枚以上のところはそこから３枚とって２枚食べるということができるので偶数なら２、奇数なら１まで減らせる
values = np.array(sorted(list(c.values()), reverse=True))

values[(values % 2 != 0) & (values >= 3)] = 1
values[(values % 2 == 0) & (values >= 3)] = 2
values = values - 1
# print(values)
# print(values.sum())
if values.sum() % 2 == 0:
    print(len(values))
else:
    print(len(values) - 1)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = set(a)
print(n - 2 * ((n - len(b) + 1) // 2))

Submission status: Accepted

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

k = len(set(a))
if k % 2:
    ans = k
else:
    ans = k - 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

from collections import Counter
def main():
    n=II()
    aa=LI()
    cnt=Counter(aa)
    even=0
    ans=0
    for v in cnt.values():
        if v&1==0:even+=1
        ans+=v//2
    ans-=even//2
    print(n-ans*2)

main()

Submission status: Accepted

Solution code:
import itertools
N = int(input())
A = [int(x) for x in input().split()]
A.sort()
B = itertools.groupby(A)
cnt1 = 0
cnt2 = 0
for key, group in B:
    if len(list(group))%2==1:
      cnt1+=1
    else:
      cnt2+=1
print(cnt1+cnt2//2*2)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc053/tasks/arc068_b
# 具体的操作によって理解は深まる
# ポイントとなるのは、余った分はどういう操作をしても二枚づつ消すことができる。
# 余った分というのは、カードaに対してaの出現回数-1となる数字のことである。
# つまり余った分を単純に消せばよい。
# しかし余った分が奇数個のとき、余ってないカードから一枚犠牲にする必要がある。
# これらを実装すればおk

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

from collections import Counter

A_cnt = Counter(A)
amari = sum([v - 1 for v in A_cnt.values()])
print(N - amari - 1 if amari & 1 else N - amari)

Submission status: Accepted

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

cnt = 0

from collections import Counter

c = Counter(A)

for i in c.values():
    if i > 1:
        cnt += i - 1

print(N - (cnt + int(cnt % 2 != 0)))

Submission status: Accepted

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

l = 0
r = N-1
count = 0

M = defaultdict(int)
for a in A:
    if M[a] > 0:
        count += 1
    M[a] += 1

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

Submission status: Accepted

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

k = len(set(A))
print(k - (k + 1) % 2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, A: "List[int]"):
    k = len(set(A))
    if (N - k) % 2 == 1:
        k -= 1
    print(k)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)

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

x = 0
y = 0

for a in A:
  d[a] += 1
  
for i in d:
  if d[i] >= 2:
    x += 1
    y += d[i] - 1
    
if y % 2 == 0:
  print(N-y)
else:
  print(N-y-1)

Submission status: Accepted

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

count = len(a) - len(set(a))

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

Submission status: Accepted

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

def func(lst):
    res = 0
    for i in range(1,n):
        if lst[i]==lst[i-1]:
            res += 1
    return res


if __name__ == "__main__":
    n = int(readline())
    lst1 = list(map(int,readline().split()))
    lst1.sort()

    same = func(lst1)

    if same%2 != 0:
        print(n-same-1)
    else:
        print(n-same)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=Counter(map(int,input().split()))
a=sorted(a.items(),key=lambda x:x[0])
l=len(a)

a=[1 if a[i][1]%2==1 else 2 for i in range(l)]
id=[i for i in range(l) if a[i]==2]
l=len(id)

cnt=0
for i in range(l-1):
    if id[i]+1==id[i+1]:
        cnt+=1
        
if cnt==1 and l==2:
    ans=sum(a)-4
else:
    if l%2==0:
        ans=sum(a)-l
    else:
        ans=sum(a)-l-1
print(ans)

Submission status: Accepted

Solution code:
def main():
    card_num = int(input())
    cards = list(map(int, input().split()))
    count = {}
    for card in cards:
        if card in count:
            count[card] += 1
        else:
            count[card] = 1
    answer = 0
    for c in list(count.values()):
        if c > 1:
            answer += c - 1
    if answer % 2:
        answer += 1
    print(card_num - answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())
cnt = 0
log = [0]*(max(A)+1)
for i in range(N):
  c = A[i]
  if log[c]!=0:
    cnt += 1
  else:
    log[c] = 1
if cnt%2==0:
  print(N-cnt)
else:
  print(N-cnt-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
x = []
for i, v in cnt.items():
    x.append([i, v])
x.sort()
left = 0
right = len(x) - 1
ans = 0
while left < right:
    if x[left][1] == 1:
        left += 1
    elif x[right][1] == 1:
        right -= 1
    else:
        x[left][1] -= 1
        x[right][1] -= 1
        ans += 2
if x[left][1] == 1:
    pass
else:
    if x[left][1] % 2 == 0:
        ans += x[left][1]
    else:
        ans += x[left][1]-1
print(n - ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = onem()

a= l()
a.sort()


aa = s(a)

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
eaten = N - len(Counter(map(int, input().split())))
eaten += eaten & 1
print(N - eaten)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy


#X = str(input()).split()
#a = [int(x) for x in input().split()]


N = int(input())
A = [int(x) for x in input().split()]

A2 = list(set(A))

k = len(A) - len(A2)

ans = len(A)-2*math.ceil(k/2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

C = collections.Counter(A)

ctr = 0
for c in C.items():
	ctr += c[1] - 1

eat_card = 2 * ((ctr + 1) // 2)	
print(N - eat_card)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
from collections import Counter
A=Counter(A)
tot = len(A)
cnt=0
for i in A.most_common():
  if i[1]%2==0:
    cnt+=1
print(tot-cnt%2)

Submission status: Accepted

Solution code:
from collections import Counter
from operator import itemgetter
N = int(input())
A = Counter(map(int, input().split()))
ans = 0
left = 0
for k, v in sorted(A.items(), key=itemgetter(1))[::-1]:
    if left == 1:
        if v == 1:
            ans += 1
            left = 0
            continue
        else:
            v -= 1
            ans += 1
            left = 0
    if v > 3:
        v = v%2 + 2

    if v == 1:
        ans += 1
    elif v == 2:
        left += 1
    elif v == 3:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
x=dict()
m=1
mc=0
ans=0
for i in range(N):
    if A[i] in x:
        x[A[i]]+=1
        m=max(m,x[A[i]])
        if m==x[A[i]]:
            mc=A[i]
    else:
        x[A[i]]=1
        ans+=1
if mc==0:
    print(N)
    exit()
l=[]
for idx in x:
    l.append(x[idx]-1)

n=sum(l)
if n%2==0:
    print(ans)
else:
    print(ans-1)

Submission status: Accepted

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

A.sort()
ans = len(set(A))

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

Submission status: Accepted

Solution code:
import sys
import collections

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    x = 0
    twon = 0
    c = collections.Counter(A)
    for k in c.keys():
        if c[k] >= 2:
            if c[k] % 2 == 0:
                x += c[k] - 2
                twon += 1
            else:
                x += c[k] - 1

    x += twon
    if twon & 1:
        x += 1

    print(N - x)



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)

ans = 0
memoflg = False

for k,v in c.most_common():
  #print(k,v)
  while v > 1:
    if v >= 3:
      v -= 2
      ans += 1
    elif v == 2:
      if memoflg:
        memoflg = False
        ans += 1
      else:
        memoflg = True
      v -= 1

if memoflg:
  ans += 1
  
print(N - ans * 2)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in a:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
cnt,sur=0,0
for i in dic.values():
    if i%2==0:
        cnt+=(i-1)//2
        sur+=1
    else:
        cnt+=i//2
print(n-cnt*2-(sur+1)//2*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

def solve(n, A):
    c = Counter(A)
    return len(c) - (sum(v - 1 for v in c.values()) % 2)

_n = map(int, input().split())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for a in A:
    d[a] += 1

ans = 0
duplicate = 0
q = list()
for k, v in d.items():
    if v % 2 == 1:
        d[k] = 1
        ans += 1
    else:
        d[k] = 2
        duplicate += 1

ans += duplicate
if duplicate % 2 == 1:
    ans -= 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

kind = len(set(a))

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

Submission status: Accepted

Solution code:
n=int(input())
a=set(map(int,input().split()))
k=len(a)
#少なくともn-k枚減らす
if (n-k) % 2 == 0:
  print(k)
else:
  print(k-1)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)

for i in a:
    d[i] += 1
cnt = 0
ans = 0
for k, v in d.items():
    if v != 1:
        cnt += v - 1
    ans += 1

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

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 fractions import gcd
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 functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    _ = INT()
    A = LIST()
    c = Counter(A)
    print(len(c.keys()) - (sum(c.values()) - len(c.keys())) % 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

A_cnt = Counter(A)
tmp = sum([x-1 for x in A_cnt.values()]) % 2
print(len(A_cnt) if tmp == 0 else len(A_cnt)-1)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

A_cnt = Counter(A)
tmp = 0
for x in A_cnt.values():
	if x >= 2:
		tmp += x-1
print(len(A_cnt) if tmp % 2 == 0 else len(A_cnt)-1)

Submission status: Accepted

Solution code:
from collections import Counter

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

Ac = Counter(A).most_common()
#print(Ac)
ans = 0

for i in range(len(Ac)):
    if Ac[i][1] > 1:
        ans += Ac[i][1]-1

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

Submission status: Accepted

Solution code:
from collections import Counter

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

Ac = Counter(A).most_common()
#print(Ac)
ans = 0

for i in range(len(Ac)):
    if Ac[i][1] > 1:
        ans += Ac[i][1]-1

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * (10**5+1)
for a in A:
    B[a] += 1
ans = 0
for b in B:
    if b > 1:
        ans += b - 1
if ans & 1:
    ans += 1
print(N - ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
A.sort()
#print(A)
C=[]
cnt=1
D=0
for i in range(N-1):
    if A[i]==A[i+1]:
        cnt+=1
    else:
        C.append(cnt-1)
        D+=cnt-1
        cnt=1
C.append(cnt-1)
D+=cnt-1
#print(C)


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

Submission status: Accepted

Solution code:
# coding: utf-8
import collections

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

C=collections.Counter(A)

d=0

sA=list(set(A))

for i in range(len(C)):
    d+=C[sA[i]]-1

eat_num=-(-d//2)

ans=N-eat_num*2

print(ans)

Submission status: Accepted

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

counter = collections.Counter(a)
count = 0
for k, v in counter.items():
    if v >= 2:
        count += v-1
if count % 2 == 0:
    print(n-count)
else:
    print(n-count - 1)

Submission status: Accepted

Solution code:
N,*A=map(int,open(0).read().split())
A=len(set(A))
print((A-1,A)[A&1])

Submission status: Accepted

Solution code:
# 同じカードが3枚以上ある場合は2枚ずつ減らせる
# 3枚以上で奇数の場合->1枚残る
# 3枚以上で偶数の場合->2枚残る

# 同じカードが2枚の場合
# 2枚のペアが２つ存在する場合
# 片方のペアから2枚選べば、両方の数字を1にできる
# ペアの数を2で割った数（切り捨て）*2のカードを減らせる

# 2枚のペアが1つ残ったとき
# そのときの全体数-2が答え

# 2枚のペアが残ってなければそのまま答え

N=int(input())
A=sorted(list(map(int,input().split())))
card=N
pairs=0
import itertools
for key,g in itertools.groupby(A):
  num=len(list(g))
  if num>2:
    if num&1:
      card-=(num-1)
    else:
      card-=(num-2)
      pairs+=1
  elif num==2:
    pairs+=1
if pairs>1:
  card-=(pairs//2)*2

if pairs&1:
  card-=2
  
print(card)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter

N =int(input())
cntA = Counter(map(int, input().split()))
len_cntA = len(cntA)
if len_cntA == 1:
    print(1)
    exit()

dif = 0
for key in cntA:
    dif += cntA[key] - 1

if dif % 2 == 1:
    print(len_cntA - 1)
else:
    print(len_cntA)

Submission status: Accepted

Solution code:
import collections

def is_even(n):
    return n % 2 == 0


def is_odd(n):
    return not is_even(n)


def solve(n, a):
    counter = collections.Counter(a)

    evens = 0
    odds = 0
    for item in counter.items():
        k, v = item
        if is_odd(v):
            odds += 1
        else:
            evens += 1

    if is_even(evens):
        return odds + evens
    else:
        return odds + (evens - 1)


def get_args():
    N = int(input())
    A = list(map(int, input().split()))
    return N, A


if __name__ == '__main__':
    n, a = get_args()
    res = solve(n, a)
    print(res)

Submission status: Accepted

Solution code:
# ABC053D
import collections

N = int(input())
A = list(map(int, input().split()))
a = collections.Counter(A)
a = a.most_common()
cnt = 0
for i in range(len(a)):
    if a[i][1] % 2 == 0:
        cnt += 1
if cnt % 2 == 0:
    print(len(a))
else:
    print(len(a) - 1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
A.sort()
from collections import Counter
c=Counter(A).items()
#print(c)
cnt=0
for key,val in c:
    if val%2==0:
        cnt+=1
print(len(c) if cnt%2==0 else len(c)-1)

Submission status: Accepted

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

t=set(a)

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

Submission status: Accepted

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

from collections import Counter

ctr = Counter(A)

n_even = len([1 for v in ctr.values() if v%2 == 0])

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

Submission status: Accepted

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

alist.sort()
gomi=0
for i in range(1,n):
    if alist[i]==alist[i-1]:
        gomi+=1
if gomi%2==0:
    ans=n-gomi
else:ans=n-gomi-1
print(ans)

Submission status: Accepted

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

from collections import Counter

kaburi=0
c=Counter(a).most_common()
for i in c:
  if i[1]>=2:
    kaburi+=i[1]-1

if kaburi%2:
  w=n-kaburi-1
else:
  w=n-kaburi

print(w)

Submission status: Accepted

Solution code:
n=int(input())
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

b=groupby(sorted([int(i) for i in input().split()]))
l=len(b)
co=0
for i in range(l):
    co+=(b[i][1]-1)
if co%2==0:
    print(l)
else:
    print(l-1)

Submission status: Accepted

Solution code:
import collections
n=int(input())
A=list(map(int,input().split()))
print(len(collections.Counter(A))-(n-len(collections.Counter(A)))%2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

C = Counter(A)
for k in C.keys():
    C[k] -= 1

cnt = ceil(sum(C.values()), 2)
ans = N - cnt * 2
print(ans)

Submission status: Accepted

Solution code:
import math
import collections
N = int(input())
A = list(map(int,input().split()))
A_collections = collections.Counter(A)
ans=N
cut=0
for comp in A_collections.values():
	cut+= comp-1
cut = math.ceil(cut/2)*2
print(ans-cut)

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=inf

n=I()
m=len(set(LI()))
print(m-(m+1)%2)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
double_cnt = 0
flag = 0
for i in range(n):
  if flag == a[i]:
    double_cnt += 1
  else:
    flag = a[i]
if double_cnt % 2 == 0:
  print(n-double_cnt)
else:
  print(n-double_cnt-1)