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:
N=int(input())
A=sorted([int(c) for c in input().split()])
D={c:0 for c in A}
for a in A:
  D[a]+=1
tmp=0
for d in D:
  D[d]=(D[d]+1)%2+1
  if(D[d]==2):
    tmp+=1
if(tmp%2==1):
  print(len(D)-1)
else:
  print(len(D))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
D = {}
for a in A:
    if a not in D: D[a] = 0
    D[a] += 1

n2 = 0
for k in D:
    D[k] = 2 if D[k]%2==0 else 1
    if D[k]==2: n2+=1

print(len(D) - n2%2)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
x=len(set(A))
answer=x
if x%2==0:
  answer-=1
print(answer)

Submission status: Accepted

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

A_set = set(A)

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Data = list(map(int,input().split()))
Dic = {}
for d in Data:
    if not d in Dic:
        Dic[d] = 0
    Dic[d]+=1

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

if even % 2 == 0:
    ans = even + odd
else:
    ans = even + odd -1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
b = Counter(a).values()
erase = 0
for i in b:
  if i >= 2:
    erase += i - 1
ans = n - ((erase+1) // 2) * 2
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

A = list(map(int, input().split()))
if len(A)==3:
  print(1)
elif (len(A)-len(set(A)))%2==1:
  print(len(set(A))-1)
else:
  print(len(set(A)))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
if len(set(A))%2==0:
  print(len(set(A))-1)
else:
  print(len(set(A)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
table = [0] * (max(a) + 1)
for x in a: table[x] += 1
t = 0
for x in table:
  if x > 1: t += x - 1
print(N + (-t // 2) * 2)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

C = Counter(A).most_common()
# print(C)

double = 0
for c in C:
	num, cnt = c
	# print(cnt)
	if cnt % 2 == 0:
		double += 1

if double % 2:
	print(len(C)-1)
else:
	print(len(C))

Submission status: Accepted

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

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:
import sys
import numpy as np 

I = np.array(sys.stdin.read().split(), dtype=np.int64)
a = I[1:]

def main():
    res = np.bincount(a)
    ans = np.count_nonzero(res)
    res = np.maximum(0, res - 1)
    ans -= (np.sum(res) & 1)
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().strip().split()]
d = defaultdict(int)
for a in A:
    d[a] += 1
l = [(x - 1) % 2 for x in d.values() if x > 1 and x % 2 == 0]
print(len(d) - len(l) % 2)

Submission status: Accepted

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

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
a=groupby(a)
#print(a)
l=len(a)
for i in range(l):
    if a[i][1]%2==0:
        a[i][1]=2
    else:
        a[i][1]=1
c=0
for i in range(l):
    if a[i][1]==2:
        c+=1
if c%2==0:
    print(l)
else:
    print(l-1)

Submission status: Accepted

Solution code:
# ABC053 D - Card Eater
from collections import defaultdict
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
a=nl()
cnt=0

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

for dd in d.items():
    if dd[1]%2==0:
        cnt+=1

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

Submission status: Accepted

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

eat = n - len(list(set(a)))
if eat % 2 == 1:
    eat += 1
print(n - eat)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
c=Counter(a)
cnt=0
for b in c.values():
    cnt+=b-1

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

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A)

cnt = 0
for v in c.values():
    cnt += v-1

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

Submission status: Accepted

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

def solve(N: int, A: "List[int]"):
    val = len(set(A))

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

        
    return


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 Counter
N = int(input())
A = [int(i) for i in input().split()]
c = dict(Counter(A))
count = 0
for k in c.keys():
    if c[k] % 2 == 0:
        count += 1
print(len(c)-count % 2)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
c = Counter(input().split())
ans = 0
d = 0
for i in c.values():
  ans += i//2
  d += int(i%2==0)
print(n - 2*(ans - d//2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(x)
li = []
for i in c.values():
    li.append(i)

li.sort(reverse=True)

for j in range(2):
    for i in range(len(li) - 1):
        if li[i] >= 3 and li[i] % 2 == 0:
            li[i] = 2
        elif li[i] >= 3 and li[i] % 2 != 0:
            li[i] = 1

        if li[i + 1] == 2 and li[i] == 2:
            li[i + 1] = 1
            li[i] = 1
    li.sort(reverse=True)
    if len(li) > 1 and li[0] == 2 and li[1] == 1:
        li[0] -= 1
        li.pop(-1)


print(len(li))

Submission status: Accepted

Solution code:
#1,1,1 -> (1,1) 1

#1,2,3 -> (1,3) 2

#1,1,3 -> (1,3) 1  <=> 1,1,3,3 -> (1,3) 1,3

#1,2,1,3,7 == [1:2, 2:1, 3:1, 7:1]
#[1:4, 2:3, 3:2, 5:1, 6:2, 8:2, 11:1]

#それぞれ1または2と等しい
#[1:2, 2:1, 3:2, 5:1, 6:2, 8:2, 11:1]
#[1,1,3,3,6,6,8,8]
#[1,1,3,6,6,8,8]
#[1,3,6,8]

N = int(input())
A = list(map(int, input().split()))
B = [-1 for i in range(100005)]

for i in range(N):
    if B[A[i]] == -1:
        B[A[i]] = 1
    elif B[A[i]] == 1:
        B[A[i]] = 2
    elif B[A[i]] == 2:
        B[A[i]] = 1

n = len(B) - B.count(-1)

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

Submission status: Accepted

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

d = {}

for i in range(N):
    if a[i] not in d:
        d[a[i]]=1
    else:
        d[a[i]]+=1
num_odd = 0
num_even= 0

for m in d:
    if d[m] % 2 == 0:num_even+=1
    else:num_odd+=1
print((num_odd+num_even if num_even%2==0 else num_odd +num_even-1))

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()

lin = []

for key, value in groupby(li):
    lin.append([key,len(list(value))])

point = 0

for i in lin:
    if i[1] >= 3:
        while True:
            if i[1] < 3:
                break
            i[1] -= 2

iti = 0
ni = 0

for i in lin:
    if i[1] == 1:
        iti += 1
    else:
        ni += 1

if ni%2 == 0:
    print(iti+ni)
else:
    print(iti+ni-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    input()
    C=Counter(map(int,input().split()))
    C=[v for k,v in C.most_common()[::-1]]
    n=len(C)
    for i in range(n):
        if(C[i]==1): continue
        C[i]=1 if(C[i]&1) else 2
        if(i<n-1 and C[i]==2):
            C[i+1]-=1
    print(n-(C[-1]==2))
resolve()

Submission status: Accepted

Solution code:
import collections
n=int(input())
lst=[int(i) for i in input().split()]
c = collections.Counter(lst)
change=0
for i,count in c.items():
    if(count>1):
        change+=count-1
if (change%2!=0):
    change+=1
ans=n-change
print(ans)

Submission status: Accepted

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

A.sort()
even = 0
odd = 0
num = A[0]
cnt = 0
for i in range(N+1):
    if i < N and num == A[i]:
        cnt += 1
    else:
        if cnt%2 == 0:
            even += 1
        else:
            odd += 1
        cnt = 1
        num = A[min(i, N-1)]

if even%2 == 0:
    ans = even + odd
else:
    ans = max(even + odd - 1, 1)
    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
AAA = [int(i) for i in input().split()]
cardlist = [0 for i in range(100010)]
for A in AAA:
    cardlist[A] += 1
for cardnumber, howmany in enumerate(cardlist):
    if howmany>=3:
        if howmany%2==0:
            cardlist[cardnumber]=2
        else:
            cardlist[cardnumber]=1

numof2 = sum([1 for i in cardlist if i==2])

if numof2%2==0:
    print(sum([1 for i in cardlist if i!=0]))
else:
    print(sum([1 for i in cardlist if i!=0])-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

c = list(Counter(A).items())
ans = len(c)
even = 0
for x, y in c:
    if y % 2 == 0:
        even += 1
if even % 2 == 0:
    pass
else:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
L = len(C)
print(L-1 if L % 2 == 0 else L)

Submission status: Accepted

Solution code:
import sys
from heapq import heapify, heappop, heappush
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()

seta = set(a)
num = N - len(seta)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
from collections import deque
d = {}
X = deque()
for i in range(N):
    x = A[i]
    if x not in d:
        d[x] = 1
        X.appendleft(x)
    else:
        d[x] += 1
ans = 0
from collections import deque
Y=deque()
while X:
    x = X.popleft()
    a = d[x]
    if a%2 == 0:
        ans += a-2
        Y.appendleft(x)
    else:
        ans += a-1

n = len(Y)
ans += ((n+1)//2)*2
print(N-ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

# main
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

cnt = len(Counter(A).values())

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

Submission status: Accepted

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

import collections
n_frq_dict = collections.Counter(A)

ans = 0
negative = 0
for n, frq in n_frq_dict.items():
    if frq % 2 == 1:
        ans += 1
    else:
        ans += 1
        negative += 1

print(ans - negative % 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def examD():
    N = I()
    A = LI(); A.sort()
    d = defaultdict(int)
    cur = int(0)
    for i in A:
        d[i] +=1
    for i in d:
        cur += d[i]
    cur -= len(d)
    ans = N - cur - cur%2
    print(ans)

import sys
import copy
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
T = [int(i) for i in input().split()]
L = [0 for i in range(max(T))]

for i in range(n):
  L[T[i]-1] += 1

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

counttwo = L.count(2)
countone = L.count(1)

out = (counttwo//2)*2 + countone
print(out)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(A)

r = 0
for v in C.values():
    r += v-1

print(len(C)-r%2)

Submission status: Accepted

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

a.sort()
x=0
count=0
b=set(a)
b=list(b)

c = collections.Counter(a)
c=c.most_common()
for i in range(len(c)):
    if c[i][1]!=1:
        x+=c[i][1]-1
    else:
        break
y=len(b)
if x%2==0:
    print(y)

else:
    print(y-1)

Submission status: Accepted

Solution code:
n = int(input())
cards = [int(a) for a in input().split()]
pairwise_distincts = set(cards)
number = len(pairwise_distincts)
if (len(cards) - number) % 2 == 0:
    ans = number
else:
    ans = number - 1

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = {}
for s in input().split():
    n = int(s)
    if n in A:
        A[n] += 1
    else:
        A[n] = 1

def main():
    a_len = len(A.keys())
    counts = A.values()
    even = [c for c in counts if c % 2 == 0]
    ans = a_len if len(even) % 2 == 0 else a_len - 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------
    N = int(input())
    A = map(int,input().split())
    p = len(set(A))
    if (N - p) % 2 == 0:
        print(p)
    else:
        print(p-1)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
from collections import*
n,*a=map(int,open(0).read().split())


amaricard=n-sum([v-1 for k,v in Counter(a).items() if v>1 and (v-3)%2==0])
amari=[v-1 for k,v in Counter(a).items() if v>1 and (v-3)%2!=0]

if len(amari)==0:
    print(amaricard)
else:
    print(amaricard-sum(amari)-len(amari)%2)

Submission status: Accepted

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


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


a = [f(i) for i in a]
one = a.count(1)
two = a.count(2)

if two % 2 == 0:
    print(one + two)
else:
    print(one + two - 1)

Submission status: Accepted

Solution code:
from itertools import groupby
N = int(input())
A = list(map(int, input().split()))
A.sort()
a = []

for i, j in groupby(A):
    a.append(len(list(j)))


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


a = [f(i) for i in a]
one = a.count(1)
two = a.count(2)

if two % 2 == 0:
    print(one + two)
else:
    print(one + two - 1)

Submission status: Accepted

Solution code:
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a = collections.Counter(a)
    t = 0
    for k, v in a.items():
        t += abs(v - 1)
    print(len(a) if t % 2 == 0 else len(a) - 1)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n=int(input())
    a=list(map(int,input().split(' ')))
    a_count = Counter(a)
    odd = 0
    even = 0
    for value in a_count.values():
        if value%2 ==0:
            even +=1
        else:
            odd += 1
    if even %2 ==0:
        print(odd+even)
    else:
        print(odd+even-1)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter


def solve(N: int, A: "List[int]"):
    c = Counter(A)
    values, counts = zip(*c.most_common())
    cc = 0
    for c in counts:
        if c % 2 == 0:
            cc += 1
    if cc % 2 == 0:
        print(len(counts))
    else:
        print(len(counts)-1)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
n = int(input())
a = list(map(lambda x: int(x), input().split()))
dic = {}
for i in a:
    dic.setdefault(i, True)
tmp = len(dic)
ans = tmp if tmp%2 == 1 else tmp-1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = 0
for v  in c.values():
    cnt += v - 1

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

Submission status: Accepted

Solution code:
import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations


def li ():
	return list (map (int, sys.stdin.readline ().split ()))


def num ():
	return map (int, sys.stdin.readline ().split ())


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


def lcm ( x, y ):
	gg = find_gcd (x, y)
	return (x * y // gg)



mm = 1000000007
def solve ():
	t = 1
	for tt in range (t):
		n=nu()
		a=li()
		a.sort()
		mp={}
		for i in a:
			if(i in mp):
				mp[i]=mp.get(i)+1
			else:
				mp[i]=1
		i=0
		j=n-1
		cc=0
		while(i<j):
			if(mp.get(a[i])==1):
				i+=1
				continue
			if(mp.get(a[j])==1):
				j-=1
				continue
			cc+=2
			mp[a[i]]=mp.get(a[i])-1
			mp[a[j]]=mp.get(a[j])-1
			i+=1
			j-=1
		print(n-cc)
solve()

Submission status: Accepted

Solution code:
import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations


def li ():
	return list (map (int, sys.stdin.readline ().split ()))


def num ():
	return map (int, sys.stdin.readline ().split ())


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


def lcm ( x, y ):
	gg = find_gcd (x, y)
	return (x * y // gg)



mm = 1000000007
def solve ():
	t = 1
	for tt in range (t):
		n=nu()
		a=li()
		a.sort()
		mp={}
		for i in a:
			if(i in mp):
				mp[i]=mp.get(i)+1
			else:
				mp[i]=1
		i=0
		j=n-1
		cc=0
		while(i<j):
			if(mp.get(a[i])==1):
				i+=1
				continue
			if(mp.get(a[j])==1):
				j-=1
				continue
			cc+=2
			mp[a[i]]=mp.get(a[i])-1
			mp[a[j]]=mp.get(a[j])-1
			i+=1
			j-=1
		print(n-cc)







if __name__ == "__main__":
	solve ()

Submission status: Accepted

Solution code:
n=int(input())
s=map(int,input().split())
import collections
d=collections.Counter(s)
d=d.most_common()
count=0

for i in d:
    if i[1]%2==0:
        count+=1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    A_s = len(set(A))
    if A_s&1: print(A_s)
    else: print(A_s - 1)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

N = int(input())

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

A.sort()

num = 0

for i in range(N-1):

    if A[i] == A[i+1]:
        num += 1

if num % 2 == 0:
    print (N - num)

else:
    print (N - num - 1)

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    from collections import Counter
    c = Counter(A)
    
    m = sum([v for v in c.values()])
    cl = len([c for c in c.keys()])

    while(m > cl):
        m -= 2
    
    print(m)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    from collections import Counter
    c = Counter(A)

    # for k,v in c.items():
    #     print(k,v)
    
    m = sum([v for v in c.values()])
    cl = len([c for c in c.keys()])

    while(m > cl):
        m -= 2
    # if(m%3 == 0 or m%3 == 2):
    #     print(len(c.keys()))
    # elif(m%3 == 1):
    #     print(len(c.keys())-1)
    # else:
    #     print(len(c.keys())-1)
    print(m)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
import collections
n = int(input())
list_a = list(map(int, input().split(" ")))
count = collections.Counter(list_a)

count_even = 0
for key, value in sorted(count.items()):
  if value % 2 == 0:
    count_even += 1

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

Submission status: Accepted

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

if (n - k) % 2 == 0:
    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 = Counter(A)

cnt = 0
for num in A.values():
    cnt += num-1

print(len(A.keys()) - cnt % 2)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
cnt = Counter(a)
res = 0
for v in cnt.values():
    if v - 1 > 0:
        res += v - 1
if res % 2:
    print(len(cnt)-1)
else:
    print(len(cnt))

Submission status: Accepted

Solution code:
import sys
import collections

import heapq
def input():
    return sys.stdin.readline()[:-1]

n=int(input())
a=list(map(int,input().split()))
tmp=collections.Counter(a)
if len(tmp)%2==0:
    print(len(tmp)-1)
else:
    print(len(tmp))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = len(set(lst))
print ((s - 1)//2 * 2 + 1)

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(lst)
odd = 0
even = 0
for c in C:
    if C[c] % 2 == 0:
        even += 1
    else:
        odd += 1

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

Submission status: Accepted

Solution code:
import collections

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

C = collections.Counter(A).values()

even = 0
for c in C:
    if c % 2 == 0:
        even += 1

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

Submission status: Accepted

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

count = [0] * (max(A)+1)
for i in range(len(A)):
    count[A[i]] += 1

ans = 0

for i in range(max(A)+1):
    if count[i] >= 2:
        ans += count[i] - 1

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
ls = list(map(int, input().split()))
counter = collections.Counter()
for x in ls:
    counter[x] += 1
print(
    len(counter.keys()) -
    len(list(filter(lambda x: x % 2 == 0, counter.values()))) % 2)

Submission status: Accepted

Solution code:
import collections

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

card = [0, 0]
for x in list(A.keys()):
    if A[x] % 2 != 0:
        card[0] += 1
    else:
        card[1] += 1

print(card[0] + card[1] - card[1] % 2)