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 math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    l = i_list()
    dic = {}
    for i in l:
        dic[i] = dic.get(i,0) + 1
    t = 0
    for i,k in dic.items():
        t += k-1
    if t%2==0:
        print(len(dic))
    else:
        print(len(dic)-1)


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)
for x in A:
    d[x] += 1
cnt = 0
for x in d:
    if d[x] >= 2 and d[x] % 2 == 0:
        cnt += 1
ans = len(d.keys())
if cnt % 2 == 1:
    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)

cnt = 0
for v in C.values():
    if v > 1:
        cnt += v - 1

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

Submission status: Accepted

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

d = {}
m = 0
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
        m += 1
print(m - 1) if (n-m) % 2 else print(m)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ac=Counter(a)
count=0
temp=0
for i in ac:
    if ac[i]>=3:
        if ac[i]%2==0:
            count+=(ac[i]-2)
            ac[i]=2
        else:
            count+=(ac[i]-1)
            ac[i]=1

for j in ac:
    if ac[j]==2:
        temp+=1
if temp%2==0:
    count+=temp
else:
    count+=((temp+1))
print(n-count)

Submission status: Accepted

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

def count(n, Set):
    if not n in Set:
        Set.add(n)
        return 0
    else:
        return 1

Sieve = set()
extra = 0
for a in A:
    extra += count(a, Sieve)
print(N-extra if not extra&1 else N-extra-1)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
from collections import defaultdict as dd
Sieve = dd(lambda:0)
for a in A:
    Sieve[a] += 1

ans, extra = 0, 0 #extra:同じ数を3枚選んで食べるという操作で「被りカードなし」にできない種類数
for v in Sieve.values():
    ans += 1
    if v > 1 and (v-1)&1:
        extra += 1
#extraから2枚選んで食べれば全体の種類数を減らさずに済む
print(ans if not extra&1 else ans-1)

Submission status: Accepted

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

for n in A:
  if n in z:
    z[n] += 1
  else:
    z[n] = 1

cnt_even = 0
for key, val in z.items():
  if val % 2 == 0: #even
    cnt_even += 1
  
cnt_odd = len(z) - cnt_even

tot = cnt_odd + cnt_even - (cnt_even % 2)
print(tot)

Submission status: Accepted

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = Counter(a)
    
    other = 0
    
    ans = n
    for k, v in a.items():
        ans -= v - 1
        if not v%2:
            other += 1
    
    ans -= other%2
        

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

Submission status: Accepted

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

kind = len(set(a))

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = [0 for _ in range(10**5+1)]
for ai in a:
  x[ai] += 1
p = 0
q = 0
for xi in x:
  if xi%2 == 1:
    p += 1
  elif xi > 0:
    q += 1
if q%2 == 0:
  print(p+q)
else:
  print(p+q-1)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A: d[a] += 1
    kind = [0] * 2
    for key in d: kind[d[key] % 2] += 1
    if kind[0] % 2 == 0:
        print(sum(kind))
    else:
        print(sum(kind) - 1)





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
K = len(set(input().split()))
print(K+K%2-1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#n=len(a)

a.sort()

from collections import Counter
a=Counter(a)
csum=0
for i,icnt in a.most_common():
    csum+=icnt-1
if csum%2==1:
    csum+=1
print(n-csum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

# lに個数を格納
l = []
i = 0
num = 1
while True:
    while i+1 < n and a[i] == a[i+1]:
        i += 1
        num += 1
    l.append(num)
    num = 1
    i += 1
    if i == n:
        break

ans = len(l)
num = 0
for i in l:
    if i % 2 == 0:
        num += 1
if num % 2 == 1:
    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)
count = 0
for v in c.values():
    if v != 1:
        count += v-1
#print(count)
if count % 2 == 0:
    print(len(c.keys()))
else:
    print(len(c.keys())-1)

Submission status: Accepted

Solution code:
N = int(input())
A = set() 
cnt = 0

def count(n, Set):
    if not n in Set:
        Set.add(n)
        return 0
    else:
        return 1
for x in input().split():
    cnt += count(x, A)
if not cnt & 1:
    ans = N - cnt
else:
    ans = N - cnt - 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
print(N-(-(-(N-len(set(arr)))//2))*2)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    d[a] += 1
print(len(d.keys()) - sum([1 - v % 2 for v in d.values()]) % 2)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    d[a] += 1
print(len(d.keys()) - sum([1 for v in d.values() if v % 2 == 0]) % 2)

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = Counter(a) # カードの値をカウント
ans = len(cnt) # 存在する値の数をカウント
if ans%2 == 0: print(ans-1) # 存在する値の数が偶数であれば1回取り除く必要があるため-1をする
else: print(ans) # 奇数の場合はそのまま

Submission status: Accepted

Solution code:
from math import *
n=int(input())
a=list(map(int,input().split()))
b=set(a)
c=len(a)-len(b)
k=ceil(c/2)
print(len(a)-2*k)

Submission status: Accepted

Solution code:
import sys
import math
N = int(input())
array = list(map(int,input().split()))
set_array = set(array)

if not ( 3 <= N <= 10**5 and N % 2 == 1 ): sys.exit()

print(len(list(set_array))) if len(list(set_array)) % 2 == 1 else print(len(list(set_array)) - 1)

Submission status: Accepted

Solution code:
def comp(n,s,a):
  cnt=1
  flag=s[0]
  for i in range(1,n):
    if flag==s[i]:cnt+=1
    else:
      flag=s[i]
      a+=[cnt]
      cnt=1
  a+=[cnt]
  return a
n=int(input())
a=sorted(list(map(int,input().split())))
b=comp(n,a,[])
l,r=0,len(b)-1
if l==r:b[0]=1
while l<r:
  while b[l]==1 and l<r:l+=1
  while b[r]==1 and l<r:r-=1
  if b[l]>1:
    b[l]-=1
    b[r]-=1
while b[l]>1:b[l]-=2
print(sum(b))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    r = len(set(a))
    r -= (n - r)&1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

from collections import Counter
cnt_a = Counter(A)

X = [0] * 3
for k, v in cnt_a.items():
    while v >= 3:
        v = (v // 3 + (v % 3))
    X[v] += 1

if X[2] % 2 == 0:
    print(X[1] + X[2])
else:
    print(X[1] - 1 + X[2])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

rec=collections.Counter(a)
ans=0
for i in range(100001):
    if rec[i]>1:
        ans+=rec[i]-1
ans=-(-ans//2)*2
print(n-ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
aas = list(map(int, input().split()))
max_n = max(aas) + 1
cnts = [0]*(max_n)
for i in aas:
    cnts[i] += 1
res = 0
for i in range(max_n):
    if cnts[i] != 0:
        cnts[i] -= 1
    if cnts[i]%2 == 0:
        cnts[i] = 0
    elif cnts[i] >= 3:
        cnts[i] = 1
res = len(set(aas))
adj = sum(cnts)
print(res if adj == 0 else res-(adj%2!=0))

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import groupby


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def ilen(ll):
    return sum(1 for _ in ll)


def solve():
    """
    2     3
    1(-1) 1
    """
    N = read_int()
    A = read_ints()
    counter = [0]*max(A)
    for a in A:
        counter[a-1] += 1
    remove = 0
    twos = 0
    for a in counter:
        if a > 0:
            if a%2 == 0:
                remove += (a-2)
                twos += 1
            else:
                remove += (a-1)
    if twos%2 == 0:
        remove += twos
    else:
        remove += twos+1
    return N-remove


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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

res = 0
even = 0
for c in cnt:
    if c > 0:
        if c % 2 == 0:
            even += 1
        res += 1

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

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
lst=list(map(int,input().split()))
c=Counter(lst)
lst=list(c.values())
ans=0
tmp=0
for i in lst:
    if i%2==1:
        ans+=1
    else:
        tmp+=1
if tmp%2==0:
    ans+=tmp
else:
    ans+=tmp-1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
dp=[0]*(10**5+1)
bp=[]
for i in range(N):
  if dp[A[i]]!=0:
    bp.append(A[i])
  dp[A[i]]+=1
bp.sort()
p=len(bp)
q=p
o=0
for i in range(10**5):
  if p<3:
    break
  p-=2
if p==0:
  N-=q
elif p==1:
  N=N-q-1
else:
  N=N-q
print(N)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    counter = Counter(A)

    odd = even = 0
    for v in counter.values():
        if v % 2 == 0:
            even += 1
        else:
            odd += 1

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
d=[]
for i in range(N-1):
  if A[i]==A[i+1]:
    d.append(A[i])

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

Submission status: Accepted

Solution code:
from collections import Counter
import sys

N=int(input())
cards=list(map(int,sys.stdin.readline().strip().split()))
c=Counter(cards)

even=len([x for x in iter(c) if c[x]%2==0])
odd=len([x for x in iter(c) if c[x]%2==1])

print(even-(even%2)+odd)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A = LI()

from collections import Counter

c = Counter(A)

a = 0  # 消さねばならない文字数
for i in c.keys():
    a += c[i]-1

print(N-2*((a+1)//2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import collections
def main():
    n = int(input())
    A=[int(i) for i in input().split()]
    dd = collections.defaultdict(int)

    for i in A:
        dd[i]+=1
    yama = []
    for i in dd.keys():
        yama.append([i,dd[i]])

    yama.sort(key = lambda x:x[0])
    yama_l = len(yama)
    cnt=0
    renozku = False
    for i in range(yama_l-1):
        if(yama[i][1]==2 and yama[i+1][1]==2):
            renzoku = True

        if(yama[i][1]%2==0):
            cnt+=1
    if(yama[-1][1]%2==0):
        cnt+=1
    if(cnt==2 and renzoku):
        print(len(yama)-1)
    elif(cnt%2==1):
        print(len(yama)-1)
    else:
        print(len(yama))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n= int(input())
a= list(map(int,input().split()))
adict = {}
for c in a:adict[c] = adict.get(c,0) + 1
twos=0
moreodd=0
moreeven=0
for num in adict.keys():
    if adict[num]==2:twos+=1
    elif adict[num]>2:
        if adict[num]%2==0:moreeven+=1
        else:moreodd +=1
if moreeven%2==1:twos+=1
if twos%2==0:print(len(adict))
else:print(len(adict)-1)

Submission status: Accepted

Solution code:
# N = 15
# ARR = [1, 3, 5, 2, 1, 3, 2, 8, 8, 6, 2, 6, 11, 1, 1]

# N = 5
# ARR = [1, 2, 1, 3, 7]

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

def calculate(n, arr):
    dict = {}
    for i in range(n):
        if dict.get(arr[i]) == None:
            dict.__setitem__(arr[i], 1)
        else:
            tmp = dict.get(arr[i])
            dict.__setitem__(arr[i], tmp + 1)

    k1 = len(dict.keys())

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


calculate(N, ARR)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt=Counter(alst)
c2=0

for v in cnt.values():
    if v==1:
        continue

    n-=v-1
    if v%2==0:
        c2+=1

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

Submission status: Accepted

Solution code:
_ = input()
a = set(map(int,input().split()))

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

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)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N = getN()
A = getList()
A = Counter(A)

one = 0
two = 0
for i in A.items():
    a, b = i
    if b % 2 == 0:
        two += 1
    else:
        one += 1
ans = 0
if two % 2 == 0:
    print(one + two)
else:
    print(one + two - 1)

Submission status: Accepted

Solution code:
from collections import Counter

N,*A = map(int, open(0).read().split())
ac = Counter(A)
e = [x[0] for x in ac.items() if x[1] % 2 == 0]
if len(e) % 2 == 0:
    print(len(ac))
else:
    print(len(ac)-1)

Submission status: Accepted

Solution code:
import sys;input = lambda : sys.stdin.readline()
import collections
n = int(input())
a = sorted(list(map(int, input().split())))
d = collections.Counter(a)
need = {}
for k,v in d.items():
    if v>1:
        need[k]=v
if (sum(list(need.values()))-len(need))%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()))
num=[0]*100001
for i in a:
  num[i]+=1
x=0
for i in num:
  if i<=0:
    continue
  elif i%2==0:
    n-=i
    x+=1
  else:
    n-=i-1
    
if x%2:
  x-=1
  
print(n+x)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

A_cnt = Counter(A)
tmp = sum([x-1 for x in A_cnt.values()])

print(len(A_cnt) if tmp%2 == 0 else len(A_cnt)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
AN = list(map(int,input().split()))
an = collections.Counter(AN)
a = sorted(list(an.values()),reverse=True)
al = len(a)

print(al if al%2==1 else al-1)

Submission status: Accepted

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

from collections import Counter
CA = Counter(A)
cu2 = 0
for k, v in CA.items():
    cu2 += v-1

print(len(A) - cu2 - cu2%2)

Submission status: Accepted

Solution code:
from collections import Counter
N  = int(input())
A = list(map(int, input().split()))
C = Counter(A)
c = 0
for k, v in C.items():
    c += v - 1
if c % 2 == 1:
    c += 1
print(N - c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_,*l=map(int,open(0).read().split())
c=len(set(l))
print(c-1+c%2)

Submission status: Accepted

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

Submission status: Accepted

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

a = Counter(A)
l_a = len(a)
if(l_a%2 == 0):
     print(l_a-1)
else:
    print(l_a)

Submission status: Accepted

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

from collections import Counter
L = Counter(L)

cnt = 0
one = 0
for v in L.values():
    if v%2 ==0:
        cnt +=1
    else:
        one +=1
if cnt%2 == 0:
    one +=cnt
else:
    one +=(cnt-1)
print(one)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=sorted(map(int,input().split()))
li=[]
i=0
while(i<N):
    cnt=0
    j=i
    while(j<N and A[i]==A[j]):
        cnt+=1
        j+=1
    li.append(cnt-1)
    i=j
l=len(li)
for i in range(l):
    for j in range(i+1,l):
        if li[i]==0:
            break
        d=min(li[i],li[j])
        li[i]-=d
        li[j]-=d
for i in range(l):
    li[i]%=2
ans=len(set(A))
for i in range(l):
    ans-=li[i]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
l = len(cnt)
even = 0
for v in cnt.values():
    if v%2 == 0: even += 1
print(l if even%2 == 0 else l-1)

Submission status: Accepted

Solution code:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    s = len(set(a))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
cnt=0
for i in c:
    if c[i]%2==0:
        cnt+=1
if cnt%2==0:
    print(len(c))
else:
    print(len(c)-1)

Submission status: Accepted

Solution code:

def resolve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    import collections
    cnter = collections.Counter(A)
    #print(cnter)
    evens = 0
    for i in cnter.values():
        if i%2 == 0:
            evens += 1
    print(len(cnter)-1 if evens%2==1 else len(cnter))


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    e = 0
    o = 0
    for v in c.values():
        if v % 2 == 0:
            e += 1
        else:
            o += 1
    if e % 2 != 0:
        e -= 1
    print(o + e)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=dict()
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
p=0
k=0
for i in d.values():
    p+=i//2
    k-=i%2-1
print(n-(p-k//2)*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    n_odd, n_even = 0, 0
    for c in counter.values():
        if c % 2 == 0:
            n_even += 1
        else:
            n_odd += 1
    print(n_odd + (n_even // 2) * 2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
A = IL()

dic = DD(int)
for a in A:
  dic[a] += 1
  
ans = 0
remain = 0
for k,v in dic.items():
  ans += 1
  remain += v-1
  
print(ans-remain%2)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for i in range(1, len(a)):
  if a[i] == a[i - 1]:
    ans += 1
print(n - (ans + 1) // 2 * 2)

Submission status: Accepted

Solution code:
#D
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
most = c.most_common()
ans = len(most)
eaten = 0
for t in most:
    if t[1] != 1:
        eaten += t[1]-1
if eaten%2 == 1:
    print(ans-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis=LI()
c=Counter(lis)
sm=0
for i in c.keys():
    sm+=c[i]-1
if sm%2==0:
    print(len(list(c)))
else:
    print(len(list(c))-1)