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 sys import stdin
from collections import Counter
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    c=Counter(a)
    ans=n
    cnt_two=0
    for key in c.keys():
        if c[key]>=3:
            if c[key]%2==1:
                ans-=c[key]-1
                c[key]=1
            else:
                ans-=c[key]-2
                c[key]=2
                cnt_two+=1
        elif c[key]==2:
            cnt_two+=1

    if cnt_two%2==0:
        ans-=cnt_two
    else:
        ans-=cnt_two-1
        ans-=2

    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 = Counter(A)
ans = len(count)
if ans % 2 == 0:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
d = dict(Counter(A))
kaburi = 0
for key in d:
  kaburi += d[key]-1
  
print(N - (kaburi%2 + kaburi))

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


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

from collections import Counter
L = len(Counter(A))

# 全体枚数が奇数で, カードの種類が偶数 
#  -> 重複カードは奇数
#  -> どれか1種類は全て捨てないと重複カードは処分不可能
if L%2==0:
    print(L-1)
# 重複カードが偶数, ペアを作って全て処分可能
else:
    print(L)

Submission status: Accepted

Solution code:
from collections import Counter
 
N = int(input())
A = sorted(list(map(int,input().split())))
 
edible = sum(i-1 for i in Counter(A).values())
print(len(set(A))-edible%2)

Submission status: Accepted

Solution code:
from collections import Counter

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

edible = sum(i-1 for i in Counter(A).values())
print(len(set(A))-edible%2)

Submission status: Accepted

Solution code:
n = int(input())
card_ls = list(map(int, input().split()))
card_ls.sort()
have_to_eat = 0
for i in range(1,n):
    if card_ls[i-1] == card_ls[i]:
        have_to_eat += 1
if have_to_eat % 2 == 1:
    have_to_eat += 1
ans = n - have_to_eat
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L.sort()
    ans = n
    two_cnt = 0
    for _, g in groupby(L):
        num = len(list(g))
        if num % 2 == 1:
            ans -= (num - 1)
        else:
            ans -= (num - 2)
            two_cnt += 1
    if two_cnt % 2 == 0:
        ans -= two_cnt
    else:
        ans -= (two_cnt - 1)
        ans -= 2
    print(ans)






if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

na = len(set(a))
cnt = Counter(a)
ls = cnt.most_common()
lst = [ 2 for i in ls if i[1]%2==0]

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

Submission status: Accepted

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

from collections import Counter

def check(counter, A):
    return len(counter) != len(A)

def Main(N, A):
    counter = Counter(A)
    lenC = len(counter)
    remains = N-lenC
    if remains%2 == 0:
        return lenC
    else:
        return lenC-1
    
          
print(Main(N, A))

Submission status: Accepted

Solution code:
def abc053_d():
    _ = int(input())
    A = list(map(int, input().split()))
    ans = 0
    from collections import Counter
    multi_even = 0
    for _, v in Counter(A).items():
        ans += 1
        if 2 <= v and v % 2 == 0:
            multi_even += 1
    if 0 < multi_even and multi_even % 2 == 1:
        ans -= 1
    print(ans)

abc053_d()

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)
eat = 0
for v in c.most_common():
  if v[1] >= 2:
    eat += v[1] - 1

if eat % 2 != 0:
  eat += 1
  
print(N-eat)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A).most_common()
even = 0
for k, v in cnt:
    if v % 2 == 0:
        even += 1
print(len(set(A)) - even % 2)

Submission status: Accepted

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

Submission status: Accepted

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

adic=defaultdict(int)
for a in alist:
  adic[a]+=1
  
hq=[]
for k,b in adic.items():
  heapq.heappush(hq,(-b,k))
#print(hq)  

cnt=0
while True:
  mf,n=heapq.heappop(hq)
  if mf==-1:
    break
  elif mf<=-3:
    heapq.heappush(hq,(mf+2,n))
    cnt+=1
  else:
    mf2,n2=heapq.heappop(hq)
    if mf2==-1:
      cnt+=1
      break
    else:
      heapq.heappush(hq,(mf+1,n))
      cnt+=1
    
print(N-2*cnt)

Submission status: Accepted

Solution code:
N = int(input())
cnt = [0] * (10 ** 5 + 1)
A = [int(_) for _ in input().split()]
for i in range(N):
    cnt[A[i]] += 1
m = 0
for i in range(10 ** 5 + 1):
    if cnt[i] > 0 and cnt[i] % 2 == 0:
        m += 1
print(len(set(A)) - int(m % 2 == 1))

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

N = getN()
nums = [int(e) for e in input().split()]
nums.sort()
checker = nums[0]
count = 1
for i in range(1,N):
    if(checker != nums[i]):
        count+=1
        checker = nums[i]
if(N - count)%2==0:
    print(count)
else:
    print(count-1)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
d = set(a)
c = collections.Counter(a)
b = 0
for i in c:
	if c[i] >= 2:
		b += c[i]-1
if b%2 == 1:
	ans = len(d)-1
else:
	ans = len(d)
print (ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
len_set = len(list(set(A)))
CA = Counter(A)
count = 0
for i,j in CA.items():
  if j%2 == 0:
    count += 1

if count%2 == 0:
  ans = len_set
else:
  ans = len_set - 1

print(ans)

Submission status: Accepted

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

kind = set(a)
num = len(kind)

diff = n - num
div = (diff - 1) // 2

ans = n - 2 * (div + 1)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
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 li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += 1
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = li()

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

flag = 0
cnt = 0
for key, value in d.items():
    if value > 1:
        flag = (flag + value - 1) % 2
    cnt += 1

print(cnt-flag)

Submission status: Accepted

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    cnt = 0
    for key, val in c.items():
        if val > 2:
            if val % 2 == 0:
                c[key] = 2
                cnt += 1
            else:
                c[key] = 1
        elif val == 2:
            cnt += 1
    
    if cnt % 2 == 0:
        print(len(c))
    else:
        print(len(c) - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    for key, val in c.items():
        if val > 2:
            if val % 2 == 0:
                c[key] = 2
            else:
                c[key] = 1
    
    if len([val for key, val in c.items() if c[key] == 2]) % 2 == 0:
        print(len(c))
    else:
        print(len(c) - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
import collections
co = collections.Counter(map(int,input().split()))
r = 0
for cnt in co.values():
    r+=cnt-1
if r%2==0:
    print(n-r)
else:
    print(n-r-1)

Submission status: Accepted

Solution code:
n = input()
a = set(input().split())

print(len(a) - (len(a)%2==0))

Submission status: Accepted

Solution code:
input();k=len(set(input().split()));print(k-1+k%2)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
m = sum(v - 1 for v in Counter([int(i) for i in input().split()]).values())
print(n - round(m + 0.5))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = sorted(list(map(int,input().split())))
c = list(Counter(A).values())
ans = len(c)
d = [i-1 for i in c]
print(ans if sum(d)%2==0 else ans-1)

Submission status: Accepted

Solution code:
from collections import Counter

N, *A = map(int, open(0).read().split())

ctr = Counter(A)
c0 = 0
c1 = 0
for v in ctr.values():
    if v % 2 == 0:
        c0 += 1
    else:
        c1 += 1

print(c1 + c0 - c0 % 2)

Submission status: Accepted

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

Blist = set(Alist)

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=[0]*(10**5+1)
sa=set(a)
for i in a:
  d[i]+=1
for j in range(len(d)):
  if d[j]>2 and d[j]%2==0:
    d[j]=2
  elif d[j]>2 and d[j]%2!=0:
    d[j]=1
ni=d.count(2)
if ni%2==0:
  print(len(sa))
else:
  print(len(sa)-1)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
import heapq


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Cnt = Counter(A)
    V = list(Cnt.values())
    heap = []
    for v in V:
        heapq.heappush(heap, -1 * v)
    if len(heap) == 1:
        print(1)
        return
    while heap:
        a = heapq.heappop(heap)
        if a == -1:
            print(-1 * sum(heap) + 1)
            return
        b = heapq.heappop(heap)
        heapq.heappush(heap, a + 1)
        heapq.heappush(heap, b + 1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

x = int(input())
a = list(map(int,input().split()))
c = Counter(a)
t = c.most_common()
d = 0
l = len(set(a))
for i in range(l):
    if t[i][1]>1:
        d+=t[i][1]-1
ans = l-d%2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
from functools import reduce

if __name__ == "__main__":
    N = int(input())
    arr = map(int, input().split())

    dic = Counter(arr)
    count = len(dic) - reduce(lambda sum, item: sum + 1, filter(lambda x: x % 2 == 0, dic.values()), 0) % 2
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

ans = n
data = defaultdict(int)
for i in range(n):
    data[a[i]] += 1
    if data[a[i]] >= 2:
        ans -= 1
print(ans if ans % 2 == 1 else ans - 1)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
from functools import reduce

if __name__ == "__main__":
    N = int(input())
    arr = map(int, input().split())

    dic = dd(int)

    for el in arr:
        dic[el] += 1

    count = len(dic) - len(list(filter(lambda x: x %
                                       2 == 0, dic.values()))) % 2
    print(count)

Submission status: Accepted

Solution code:
N = int(input())
nums = [int(e) for e in input().split()]
nums.sort()
checker = nums[0]
count = 1
for i in range(1,N):
    if(checker != nums[i]):
        count+=1
        checker = nums[i]
if(N - count)%2==0:
    print(count)
else:
    print(count-1)

Submission status: Accepted

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

import collections
c=collections.Counter(a)
C=c.most_common()

even=0
for i in range(len(C)):
    p,q=C[i]
    if q%2==0:
        even += 1
if even%2==0:
    print(len(C))
else:
    print(len(C)-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    print(N+(len(set(A))-N)//2*2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=list(map(int,input().split()))
k=len(collections.Counter(s))
if (n-k)%2==0:
    print(k)
else:
    print(k-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
ans = len(set(a))
s = 0
cnt = 1
pre = 0
a.append(10**9)
for x in a:
    if x != pre:
        s += (cnt+1)%2
        cnt = 1
        pre = x
    else:
        cnt += 1
s %= 2
print(ans-s)

Submission status: Accepted

Solution code:
n=int(input())
from collections import Counter as co
l=co(list(map(int,input().split()))).values()
ans=0
p=0

for i in l:
  if (i-1)%2==0:ans+=1
  else:p+=1
print(ans+p//2*2)

Submission status: Accepted

Solution code:
from collections import Counter
_ = input()
c = Counter(input().split())
ttl = 0
cnt = 0
for value in c.values():
    ttl += (value+1)%2
    cnt += 1
print(cnt - ttl%2)

Submission status: Accepted

Solution code:
# solution
import io
data = int(input())
array = list(map(int, input().split()))
strings = len(set(array))
if data % 2 == strings % 2:
    print(strings)
else:
    print(strings - 1)

Submission status: Accepted

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

list_B = l.values()

value_1 = 0
value_2 = 0
value_0 = 0

for num in list_B:
    a = num
    while True:
        a = a % 3 + a // 3
        if a < 3:
            break
    if a == 2:
        value_2 += 1
    elif a == 1:
        value_1 += 1
    else:
        value_0 += 1

ans = value_1 + 2*(value_2//2) + value_0

print(ans)

Submission status: Accepted

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

for a in A:
    if a in counter:
        counter[a] += 1
    else:
        counter[a] = 1

one, two = 0, 0
for c in counter:
    if counter[c] % 2 == 0:
        two += 1
    else:
        one += 1

print(one + two - (two % 2))

Submission status: Accepted

Solution code:
from collections import Counter


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

COUNTS = Counter(A)

x = sum(count - 1 for count in COUNTS.values())
if x % 2 == 1:
    x += 1

print(n - x)

Submission status: Accepted

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

dif = N - len(kinds)
if dif % 2 == 0:
    print(len(kinds))
else:
    print(len(kinds) - 1)

Submission status: Accepted

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

ans = len(set(ai))

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

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
"""
c=collections.Counter(A)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
for i in range(len(values)):
    values[i]=(values[i]-1)%2
print(len(values)-sum(values)%2)
"""
#""Nが奇数なので""
#len(set(A))%2==0なら取り除きたい最小限のカードの枚数は偶数、それらそのまま除くことが可能である
#len(set(A))%2==1なら取り除きたい最小限のカードの枚数は奇数、そのままは除けず、1枚犠牲になる
print(len(set(A))-(len(set(A))+1)%2)

Submission status: Accepted

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

c=collections.Counter(A)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
for i in range(len(values)):
    values[i]=(values[i]-1)%2
print(len(values)-sum(values)%2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,(input().split())))
S = A #調べたいリスト

result={}
for i in range (0,len(S)):
    item = S[i]
    if item in result:
        result[item] = result[item]+1
    else:
        result[item] = 1

a = [k for k, v in result.items()]

h = []
for i in a:
    h.append(result[i]-1)

h.sort(reverse=True)

n = len(h)
for i in range(n):
    if h[i] >= 1:
        if h[i]%2 == 1:
            h[i] = 1
        else:
            h[i] = 0

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

Submission status: Accepted

Solution code:
from collections import Counter
input()
A=list(map(int,input().split()))
c=Counter(A)
lenc=len(c)
print(lenc-1 if lenc&1==0 else lenc)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
M=N
for k in range(N-1):
    if A[k]==A[k+1] and A[k]!=0:
        for j in range(M-1,k+1,-1):
            if A[j]==A[j-1] and A[j]!=0:
                A[j]=0
                A[k]=0
                M=j
                break
count=0
dcount=0
for k in range(len(A)):
    if A[k]!=0:
        count+=1
for k in range(len(A)-1):
    if A[k]==A[k+1] and A[k]!=0:
        dcount+=2
print(count-dcount)

Submission status: Accepted

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

import collections
C = collections.Counter(A)

t = 0
for i in C:
    t += C[i] - 1
if t % 2 == 0:
    print(len(C))
else:
    print(len(C) - 1)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

m = len(set(a))
d = defaultdict(int)
for v in a:
    d[v] += 1

cnt = 0
for v in set(a):
    if d[v] % 2 == 0:
        cnt += 1
if cnt % 2 == 1:
    m -= 1
print(m)

Submission status: Accepted

Solution code:
n = input()
n = int(n)
ss = input().split()
sslist = sorted(ss)
# print(sslist)
dic_ss = {}
for x in sslist:
  dic_ss.setdefault(x,0)
  dic_ss[x] += 1
# print(dic_ss)
# 1) 3回以上の重複があれば、その数字だけを使って、排除 N -> N-2
for key, value in dic_ss.items():
  while value >= 3:
    value -= 2
  dic_ss[key] = value
# print(dic_ss)
# 2) 2回重複の最小値と最大値を使って重複排除 Min N -> N-1, Max M -> M-1
key1 = None
key2 = None
for key, value in dic_ss.items():
  if key1 == None and value == 2:
    key1 = key
  elif key2 == None and value == 2:
    key2 = key
  if key1 != None and key2 != None:
    dic_ss[key1] = 1
    dic_ss[key2] = 1
    key1 = None
    key2 = None
# print(dic_ss)
# 3) 2回重複が1つ残ったら、重複なしから1つ削除
count = len(dic_ss)
for key, value in dic_ss.items():
  if value > 1:
    count -= 1
print(count)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

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

c = Counter(A)
ans = len(c.keys())

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

Submission status: Accepted

Solution code:
N = int(input())
card = list(map(int, input().split()))
dic = {}
for i in card:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
ans = 0
for value in dic.values():
    if value > 1:
        ans += value - 1
print(N-(ans+(ans % 2)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
#D
N = int(input())
A = list(map(int,input().split()))

A.sort()

count = 0
old = -1
for a in A:
    if old != a:
        count+=1
        old = a

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

memo = [0]*100000

for i in t:
    memo[i-1] += 1

sa = 0

for j in memo:
    if 1<j:
        sa += j-1

print(n-sa-sa%2)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
lis = [0] * (max(a) + 1)
for i in a:
    lis[i] += 1
cnt = 0
for i in lis:
    cnt += max(0,i-1)
ans = len(set(a))
if cnt % 2 == 0:
    print(ans)
else:
    print(ans - 1)

Submission status: Accepted

Solution code:
#template
from collections import Counter
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
c = Counter(A)
key = c.keys()
count = 0
for i in key:
    count += c[i]-1
l = len(set(A))
if count % 2 == 1:
    l-=1
print(l)

Submission status: Accepted

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

b = [0]*10**5

for i in a:
    b[i] += 1
ans = 0
c = 0
for i in range(10**5):
    if b[i] == 0:
        continue
    if b[i] == 1:
        ans +=1
    elif b[i] % 2 == 0:
        c += 1
    elif b[i] % 2 == 1:
        ans +=1
        
d = c % 2
if d == 1:
    ans -=1
print(ans + c)

Submission status: Accepted

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

Submission status: Accepted

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

set_a = set(a)
k = len(set_a)

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

else:
    print(k)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

B = [0] * 100001
for a in A:
    B[a] += 1
cnt1 = 0
ans = 0
for b in B:
    if b > 1 and b % 2 == 0:
        cnt1 += 1
    if b > 0:
        ans += 1
if cnt1 % 2 == 1:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())
a = [int(_) for _ in input().split()]

CARD = 10**5+1

num = [0] * CARD
for i in a:
    num[i] += 1

ans = 0
cnt = 0
for i in range(CARD):
    while num[i] > 2:
        ans += 2
        num[i] -= 2
    if num[i] == 2:
        cnt += 1
ans += math.ceil(cnt/2) * 2
print(n-ans)

Submission status: Accepted

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

Submission status: Accepted

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

a_dict = {}

for a in a_list:
    if a not in a_dict:
        a_dict[a] = 1
    else:
        a_dict[a] += 1

values = list(a_dict.values())
double = sum(values) - len(values)
# print(values,double)

print(len(a_list) - (double//2 + double%2)*2)

Submission status: Accepted

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

ans = len(set(A))-(len(A)-len(set(A)))%2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ランレングス圧縮
def rle(l):
    ret = []
    n = len(l)
    cnt = 1
    for i in range(1,n):
        if l[i - 1] == l[i]:
            cnt+=1
        else:
            ret.append([l[i - 1],cnt])
            cnt = 1
        if i == n - 1:
            ret.append([l[i],cnt])
    return ret

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

a.sort()

ans = n

r = rle(a)

for i in range(len(r)):
    if r[i][1] % 2 == 0:
        ans-=r[i][1]
        if i != len(r) - 1:
            r[i + 1][1]-=1
    else:
        ans-=r[i][1] - 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = sorted(list(map(int,input().split())))
b = set(a)
c = collections.Counter(a)
x = 0
for i in b:
    if c[i]%2==0:x+=1
ans = len(b)
if x%2==1:ans-=1
print(ans)