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 collections import Counter, deque, OrderedDict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

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

    AA = Counter(A)
    ans = 0
    val = 0
    for k, v in AA.items():
        if v % 2 == 0:
            ans += 1
        else:
            val += 1
    if ans % 2 !=0:
        ans -= 1
    print(val+ans)


resolve()

Submission status: Accepted

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

from collections import Counter
c = Counter(A)

num2 = 0
for k, v in c.items():
    if v == 2:
        num2 += 1
    if v >= 3:
        if v % 2 == 0:
            c[k] = 2
            num2 += 1
        else:
            c[k] = 1

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

Submission status: Accepted

Solution code:


from collections import Counter

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

c = Counter(A)
ans = 0
even = 0
for v in c.values():
    if v % 2 == 0:
        even += 1
    else:
        ans += 1

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


print(ans)

Submission status: Accepted

Solution code:
import math
import fractions
#import sys
#input = sys.stdin.readline

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)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

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

#################################################
#################################################
#################################################
#################################################



n = int(input())

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

nums = Zeros(10**5,-1)

for i in a:
    nums[i]+=1
ans=0
num2 = 0
for i in nums:
    if(i%2==1):
        ans+=1
    elif(i!=0):
        num2+=1
        
print(ans + num2 - num2%2)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
cnt = Counter(list(map(int, input().split())))
cnt_2 = 0
for v in cnt.values():
    if v == 1: continue
    if v % 2: n -= v - 1
    else:
        n -= v - 2
        cnt_2 += 1
print(n-(cnt_2+1)//2*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=Counter(list(map(int,input().split())))
b=len([v for v in a.values() if v%2==0])
ans=len(a)
ans-=1 if b%2==1 else 0
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split(" ")]
s = len(set(a))
print(s-1+s%2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
num = set()
cnt = 0
for a in A:
    if a in num:
        cnt += 1
    else:
        num.add(a)
print(len(num) - (cnt&1))

Submission status: Accepted

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


c = collections.Counter(li)
#print(c.items())
# dict_items([('a', 4), ('b', 1), ('c', 2)])

kakutei = 0
count = 0
for dd in c.items():
    kazu = dd[1]
    if kazu % 2 == 0:
        count += 1
    kakutei += 1
print(kakutei - count%2)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/arc068/tasks/arc068_b

from collections import Counter

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

if len(set(A)) == n:
    print(n)
    exit()

cA = Counter(A)

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

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
num=[]
cnt=0
bef=a[0]
for i in range(n):
    if bef==a[i]:
        cnt+=1
    else:
        num.append(cnt-1)
        bef=a[i]
        cnt=1
    if i==n-1:
        num.append(cnt-1)
s=sum(num)
if s%2==0:
    print(n-s)
else:
    print(n-s-1)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
#3枚とって最大最小の二枚を食べる
B=[0]*(max(A))
for a in A:
    B[a-1]+=1

B=sorted(B, reverse=True)

#print(sorted(A))
#print(B)
ans=0
pre=0
for b in B:
    b-=pre
    if b>=2 and b%2==1:
        #ans+=(b-1)//2
        #print((b-1)//2)
        pre=0
        b=1
    elif b>=2 and b%2==0:
        #ans+=(b-2)//2+1
        #print((b-2)//2+1)
        pre=1
        b=1
    elif b<2:
        pre=0
    ans+=b
    #print(b)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


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

    cnt = {}
    for a in A:
        if a not in cnt:
            cnt[a] = 1
        else:
            cnt[a] += 1

    num_cnt_even = 0
    num_cnt_odd = 0
    for v in cnt.values():
        if v % 2 == 0:
            num_cnt_even += 1
        else:
            num_cnt_odd += 1

    if num_cnt_even % 2 == 0:
        print(num_cnt_even + num_cnt_odd)
    else:
        print(num_cnt_even + num_cnt_odd - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = a + [0]

a.sort(reverse = True)

b = 1
ichi = 0
r = []
for i in range(n):
    if a[i] != a[i+1]:
        if b != 1:
            r.append(b)
        else:
            ichi += 1
        b = 1
    else:
        b += 1

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

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)

temp=0
for item in c.keys():
    if c[item]>1:
        temp+=c[item]-1

if temp%2==0:
    print(len(list(c.keys())))
else:
    print(max(len(list(c.keys()))-1,1))

Submission status: Accepted

Solution code:
N = int(input())

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

cnt = [0 for i in range(100001)]

for x in A:
    cnt[x] += 1

oddOrEven = 0

types = 0

for x in cnt:
    if(x > 0):
        types += 1
        oddOrEven += x

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

Submission status: Accepted

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

A.sort()
# print(A)
bucket = [0] * (max(A) + 1)
for el in A:
    bucket[el] += 1
# print(bucket)

odd = len(list(filter(lambda x: x % 2 == 1, bucket)))
# print(odd)
even = len(list(filter(lambda x: x % 2 == 0 and x != 0, bucket)))

print(odd + (even // 2) * 2)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
cnt = 0
for k, v in c.items():
    if v > 1:
        cnt += v - 1

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

Submission status: Accepted

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

lsa = len(set(a))
diff = n - lsa

print(lsa - (diff % 2))

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 = map(int, input().split())
c = collections.Counter(A)

neven = nodd = 0
for v in c.values():
    if v % 2 == 1:
        nodd += 1
    else:
        neven += 1

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

Submission status: Accepted

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

Submission status: Accepted

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


ans = 0
for c in z:
    ans +=(1-c%2)

print(len(z)-ans%2)

Submission status: Accepted

Solution code:
# カードの山に k 種類のカードがあったとして，k が奇数なら余っているカードは偶数枚あるの
# で答えは k であり，偶数ならばどこかで必ず 1 枚しかないカードを 1 回取り除く必要があるので
# 答えは k − 1 となります．

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

k = len(set(nums))
print(k if k % 2 == 1 else k-1)

Submission status: Accepted

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

# これ直前に解いた
# 重複している=取り除かなきゃいけない枚数の2の倍数切り上げ。

nums.sort()
sequential = 1
before = nums[0]
dup = 0
for i in nums[1:]:
    if i == before:
        sequential += 1
    else:
        dup += sequential - 1
        sequential = 1
    before = i

dup += sequential - 1

print(n - (dup + 1) // 2 * 2)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
kind=0
c=[]
d=[0]*(10**5)
count=0
for i in range(N):
  if(d[A[i]-1]==0):
    kind+=1
  d[A[i]-1]+=1
for i in range(N):
  if(d[i]>0 and d[i]%2==0):
    count+=1
print(kind-(kind+1)%2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter
from math import ceil

n = int(readline())
a = list(map(int, readline().split()))
counter = Counter(a).values()
cnt = sum(counter) - len(counter)
print(n - ceil(cnt / 2) * 2)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [1+(j-1)%2 for i, j in sorted(Counter(map(int, input().split())).items())]
result = 0
x = a.count(2)
print(len(a)-x%2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
N = int(input())
A=list(map(int,input().split()))
B = collections.Counter(A)
ans=N
flag=0
for i,a in enumerate(B.values()):
  #print(a,ans)
  if a==1:
    continue
  if a%2==0:
    ans-=a-1
    if flag==0:
      flag=1
    else:
      flag=0
  else:
    ans-=a-1
if flag==1:
  ans-=1
print(ans)

Submission status: Accepted

Solution code:
def main():
    """
    奇数枚の余りは1に、偶数枚の余りは2にできる
    偶数枚が偶数個余っていたら種類は減らないが、奇数個であれあ一つ種類が減る
    """
    _ = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    even = len([v for v in c.values() if v % 2 == 0])
    ans = len(c.keys())
    if even % 2 == 1:
        ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt=0
surplus=0
for x in c.values():
    if x>=2 and x%2==1:
        tmp=(x-1)//2
        cnt+=2*tmp
    elif x>=2 and x%2==0:
        tmp=(x-1)//2
        cnt+=2*tmp
        surplus+=1

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

Submission status: Accepted

Solution code:
N = int(input())
A = input().split()
already = [False] * (10**5+1)
dup_count = 0
for a in A:
    a = int(a)
    if not already[a]:
        already[a] = True
    else:
        dup_count += 1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import collections
n = int(input())
a = [int(i) for i in input().split()]

count = 0
c = collections.Counter(a)
for i in set(a):
    if c[i] > 1:
        count += c[i] - 1
if count % 2 == 0:
    print(n - count)
else:
    print(n - count - 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:
#!/usr/bin/env python3
from collections import Counter
n, *a = map(int, open(0).read().split())
a = [0] + list(list(zip(*Counter(a).items()))[1]) + [1]
for i in range(len(a)-1): a[i+1] = a[i+1]+a[i]-1
ans = 0
li = len(a)-1
for i in range(1, li):
	tmp = abs(a[li]-a[i]-a[i-1])
	x = a[i]-a[i-1]
	if tmp>=x: cnt = tmp-x
	else: cnt = (x-tmp)%2
	ans = max(ans, li-1-cnt)
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int, input().split()))
A_count = collections.Counter(A)
# print(A_count)
ans = 0
even = []
# odd = []
for v in A_count.values():
    if v == 1 or v % 2 != 0:
        ans += 1
    else:
        even.append(v)
# even.sort()
m = len(even)
if m % 2 == 0:
    ans += m
else:
    ans += m-1

print(ans)
# odd.sort()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
a.sort()
b = sorted(list(set(a)))
c = Counter(a)
ans = 0
for i in b:
    ans += c[i] - 1
if ans % 2 == 1:
    ans += 1
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 i in a:
    d[i] += 1

maxcnt = len(d)
total = 0
for v, c in d.items():
    if c != 1:
        total += c - 1

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
t = sum(x-1 for x in d.values())
print(n - t - t%2)

Submission status: Accepted

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))
a.sort()
d = []
flag = a[0]
for i in range(1, n):
    if a[i] == flag:
        d.append(a[i])
    else:
        flag = a[i]

ans = n - 2 * math.ceil(len(d) / 2)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
d = Counter(a)
cnt = 0
for v in d.values():
    if v % 2 == 0:
        cnt += 1

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

Submission status: Accepted

Solution code:
from collections import Counter
import sys

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

def main():
    input()
    aa=LI()
    ac=Counter(aa)
    even=0
    for a,c in ac.items():
        if c%2==0:even+=1
    if even%2:ans=len(ac)-1
    else:ans=len(ac)
    print(ans)

main()

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def cmb(n,r):
    r = min(n-r,r)
    if r < 0: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    
    D = defaultdict(int)
    for a in A:
        D[a] += 1
    
    res = N
    l = 0
    r = N-1
    while r-l >= 2:
        if D[A[l]] <= 1:
            l += 1
        elif D[A[r]] <= 1:
            r -= 1
        else:
            res -= 2
            D[A[l]] -= 1
            D[A[r]] -= 1
            l += 1
            r -= 1
    if D[A[l]] > 1 or D[A[r]] > 1:
        res -= 2
    
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = map(int, input().split())
counter = Counter(a)
number = len(counter)
rest = 0
for i in counter.values():
    rest += i - 1
print(number - rest % 2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
for i in a:
    d[i]+=1
eat_cnt = 0
pair_cnt = 0
for i in d.values():
    eat_cnt+=((i-1)//2)
    pair_cnt+=(1-i%2)

eat_cnt+=(pair_cnt//2 + pair_cnt%2)
print(n-eat_cnt*2)

Submission status: Accepted

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

a=set(A)
base=len(A)-len(a)

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

Submission status: Accepted

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

cnt = {}
for i in range(n):
    if a[i] not in cnt:
        cnt[a[i]] = 1
    else:
        cnt[a[i]] += 1

ans = 0
for i in cnt:
    ans += (cnt[i] - 1)
if ans % 2 == 0:
    print(n - ans)
else:
    print(n - ans - 1)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    AK = list(set(A))
    AK.sort()
    AN = dict()
    for a in A:
        if a in AN: AN[a] += 1
        else: AN[a] = 1
    low = 0; high = len(AK) - 1
    while low < high:
        if AN[AK[low]] <= 1 and AN[AK[high]] <= 1:
            low += 1
            high -= 1
        elif AN[AK[low]] <= 1: low += 1
        elif AN[AK[high]] <= 1: high -= 1
        else:
            AN[AK[low]] -= 1
            AN[AK[high]] -= 1
    total = 0
    for key in AN: total += AN[key]
    while AN[AK[low]] > 2:
        total -= 2
        AN[AK[low]] -= 2
    if AN[AK[low]] > 1:
        total -= 2
    print(total)
    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

from collections import Counter

c = Counter(a)

b = [0, 0] # 偶数,奇数

for i in c.values():
    if i % 2 == 0:
        b[0] += 1
    else:
        b[1] += 1

ans = b[1]

if b[0] % 2 == 0:
    ans += b[0]
else:
    ans += b[0] - 1

print(ans)

Submission status: Accepted

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

N = map(int, input().split())
A = list(map(int, input().split()))
counter = Counter(A)
cnt = 0
for k, v in counter.items():
    cnt += v % 2 == 0
print(len(counter) - cnt % 2)

Submission status: Accepted

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

L = len(set(A))

if L % 2 == 1: # 奇数 -> 重複しているカード食えばok
    print(L)
else: # 偶数 -> 重複してないカードを1枚だけ食う必要あり
    print(L - 1)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
*A, = map(int, input().split())
C = Counter(A)
dup = 0
acc = 0
k = len(C)
for c in C.values():
    acc += c
    if c > 1:
        dup += c - 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
l = len(set(a))
c = Counter(a)
cnt = 0
for key in c.keys():
    cnt += c[key] - 1
print(l-1 if cnt%2 else l)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    c = defaultdict(lambda :0)
    for i in a:
        c[i] += 1
    a = [[i,2-(j&1)] for (i,j) in c.items()]
    a.sort()
    s = 0
    c = 0
    for i in range(len(a)):
        if a[i][1] == 2:
            c += 1
        s += a[i][1]
    s -= c
    if c&1:
        s -= 1
    print(s)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from collections import Counter

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

for a in A:
    cnt[a] = 1 if cnt[a] % 2 else 2

ans = len(cnt.keys()) - len([c for c in cnt.values() if c == 2]) % 2
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    even = len([v for v in c.values() if v % 2 == 0])
    ans = len(c.keys())
    if even % 2 == 1:
        ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n = int(input())
    a = map(int, input().split())
    counter = Counter(a)
    yield sum(1 for v in counter.values() if v%2==1)
    evens = sum(1 for v in counter.values() if v%2==0)
    if evens % 2 == 0:
        yield evens
    else:
        yield evens - 1


print(sum(main()))

Submission status: Accepted

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    counter = Counter(a)
    yield sum(1 for v in counter.values() if v%2==1)
    evens = sum(1 for v in counter.values() if v%2==0)
    if evens % 2 == 0:
        yield evens
    else:
        yield evens - 1


print(sum(main()))

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))





def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    
    cnt = 0
    for i in range(1,N):
        if A[i-1]==A[i]:
            cnt += 1
    
    if cnt%2==0:
        print(N-cnt)
    else:
        print(N-cnt-1)




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#解説参照
#基本的には～が思いつく気がしない
n = int(input())
*a, = map(int, input().split( ))

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
import itertools
a = [len(list(l)) % 2 for k, l in itertools.groupby(A)]
ans = len(a)
if len([x for x in a if x == 0]) % 2 == 1:
    ans -= 1
print(ans)

Submission status: Accepted

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

odd=0
even=0

for i,m in c.items():
    if m%2==1:
        odd+=1
    else:
        even+=1

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
from collections import Counter
c = Counter(A)
# 余剰を計算する

counts = [count-1 for k,count in c.items() if count>1]

if len(counts)>1:
  l,r = counts[0],counts[-1]
  mids = sum(counts[1:-1])
  ## 中間にあるもので打ち消せ無い場合
  if abs(l-r) > mids :
    print(len(set(A)) - (abs(l-r) - mids))
  else:
    print(len(set(A)) - (mids -abs(l-r)) %2 ) 
else:
  print(len(set(A)) - sum(counts)%2 )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
import collections
count_A = collections.Counter(A)
# print(count_A.values())
count_1 = 0
count_2 = 0
for v in count_A.values():
    if v == 1:
        count_1 += 1
    elif v == 2:
        count_2 += 1
    else:
        if v % 2 == 0:
            count_2 += 1
        else:
            count_1 += 1
# print(count_1, count_2)
if count_2 % 2 == 0:
    print(count_1+ count_2)
else:
    print(count_1+ count_2-1)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
li = [0] * int(1e05)
for x in A:
    li[x-1] += 1
num = 0
for x in li:
    if x > 1:
        num += (x-1)/2
print(N-2*math.ceil(num))

Submission status: Accepted

Solution code:
from collections import Counter

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

s = set(A)
c = Counter(A)
m2 = [1 if v%2==0 else 0 for v in c.values()]
if sum(m2)%2 == 0:
  print(len(s))
else:
  print(len(s)-1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    a_kinds = len(set(a))
    a_dup = n - a_kinds

    print(n-((a_dup+1)//2)*2)


if __name__ == '__main__':
    main()