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:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    k = len(set(A))

    if k%2 == 1:
        print(k)
    else:
        print(k-1)
            
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# まず、複数枚ある場合を考えると、3->最終的に1枚 4->最終的に2枚 5->最終的に1枚 6->最終的に2枚... となる。遇奇で変わりそう
# 最終的に1枚になる場合はいいとして、2枚になる場合は自分以外のどれかを1枚犠牲にするしかない
# できるだけ種類を多く残すには、ほかの2枚以上あるやつから選んだほうが得（2 2 3 3 が 2 3 になってくれる
# ということで、「最終的に2枚になるのが偶数種類なら相殺してくれる、そうじゃないなら全体から1枚犠牲にする」でよさそう
n = int(input())
a = list(map(int, input().split()))
d = {}
for av in a:
    if av in d:
        d[av] += 1
    else:
        d[av] = 1
c = 0
for v in d.values():
    if v > 0 and v % 2 == 0:
        c += 1
if c % 2 == 0:
    print(len(set(a)))
else:
    print(len(set(a)) - 1)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
from collections import Counter
c = Counter(a)
ones = sum(v==1 for v in c.values())
ns = [v-1 for v in c.values() if v>1]
ans = ones + len(ns)
ns.sort()
if not ns:
    pass
elif ns[-1]>sum(ns[:-1]):
    after = ns[-1] - sum(ns[:-1])
    if after%2==1:
        ans -= 1
else:
    after = 1 if sum(ns)%2==1 else 0
    if after==1:
        ans -= 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

a=[int(x) for x in input().split()]
a.sort()
c=0
for i in range(n-1):
  if a[i]==a[i+1]:
    c+=1
if c%2==1:
  c+=1
print(n-c)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

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
n = len(C)
if n%2==1:
    print(n)
else:
    print(n-1)

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  cnt = N-len(set(A))
  ans = N- (cnt+1)//2 *2
  return ans
print(solve())

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
from collections import Counter
ctr = Counter(A)
rem = sum(v-1 for v in ctr.values())
if rem%2:
    print(len(ctr) - 1)
else:
    print(len(ctr))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

C = Counter(A)

cnt2 = 0
res = 0
for v in C.values():
    if v == 2:
        cnt2 += 1
    elif v > 2 and v % 2 == 0:
        cnt2 += 1
        res += (v - 2) // 2
    elif v > 2 and v % 2 == 1:
        res += (v - 1) // 2

res += (cnt2 + 1) // 2

print(N - 2 * res)

Submission status: Accepted

Solution code:
import collections as col

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

m = col.Counter(A)
ans = len(m) if len(m)%2==1 else len(m)-1
print(ans)

Submission status: Accepted

Solution code:
MAX = 10 ** 5 

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = set(list(map(int, input().split())))
print((2*len(A)-1)//2+len(A)%2)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
li_a = list(map(int, input().split()))
dd = defaultdict(lambda:0)
for i in li_a:
    dd[i] += 1
cnt = 0
tyo = 0
for key in dd:
    cnt += 1
    if dd[key] > 1:
        tyo += dd[key]-1
print(n-((tyo+1)//2)*2)

Submission status: Accepted

Solution code:
from collections import Counter
import math

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

C = Counter(A)
cnt = 0
for k, v in C.items():
    cnt += v-1

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

Submission status: Accepted

Solution code:
from collections import Counter

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

dic = Counter(A)
unique = len(dic)

print(unique if unique%2 else unique-1)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = in_nl()
    count = Counter(A)
    nums = list(count.values())

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

    d = Counter(nums)

    n1, n2 = d[1], d[2]
    ans = n1
    if n2 % 2 == 0:
        ans += n2
    else:
        ans += n2 - 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
import heapq
n = I()
A = sorted(readInts())
setA = set(A)
if (n - len(setA))%2 == 0:
    print(len(setA))
else:
    print(len(setA)-1)

Submission status: Accepted

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

from collections import Counter
c=Counter(a)

cnt_all=0
cnt_up=0
for key in c:
    if c[key]>=2:
        cnt_up+=c[key]-1
    cnt_all+=1
print(cnt_all if cnt_up%2==0 else cnt_all-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    A = list(map(int, input().split()))
    l = Counter(A)
    ans = N - sum(l.values()) + len(l)
    if ans % 2 == 0: ans -= 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

    ans = 0
    countA = Counter(A)

    ans = 0

    num_odd = 0
    for v in countA.values():
        if v % 2 == 1:
            ans += 1
        else:
            num_odd += 1
    if num_odd % 2 == 0:
        ans += num_odd
    else:
        ans += num_odd -1


    print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())
alst = list(map(int, input().split()))
alst.sort()
bef = -1
ans = n
for num in alst:
    if bef == num:
        ans -= 1
    bef = num
if ans % 2 == 1:
    print(ans)
else:
    print(ans - 1)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, 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()

n = len(set(A))

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, 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()

C = Counter(A)

key = sorted(C.keys())  #Aに含まれる数の種類

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int,read().split())

from collections import Counter

d = Counter(a)

kind = 0
x = 0
for k,v in d.items():
    x += v-1
    kind += 1

#print(kind,x)

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

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    # ダブったカードは好きな順に2枚ずつ減らせる
    M = N - len(set(A))
    if M % 2:
        M += 1
    return N - M


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    D = Counter(A)
    ev = 0
    for k, v in D.items():
        if v % 2 == 0:
            ev += 1

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    D = Counter(A)
    ev = 0
    od = 0
    for k, v in D.items():
        if v % 2 == 0:
            ev += 1
        else:
            od += 1
    if ev % 2 == 0:
        print(ev + od)
    else:
        print(ev + od - 1)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(int)

for a in As:
    d[a] += 1
cnt = 0
for k in d.keys():
    cnt += d[k] - 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 = Counter(map(int, input().split()))
ans = len(A)
print(ans - (ans % 2 == 0))

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

double=0
ans=0

for D in d:
    if d[D]%2==0:
        double+=1
    if d[D]>2:
        ans+=(d[D]-1)//2
        d[D]=(d[D]-1)%2+1

ans+=double//2+double%2
print(N-2*ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
A.sort()
_max = A[-1]
_min = A[0]
C = Counter(A)
odd = 0
even = 0
for v in C.values():
    if v % 2:
        odd += 1
    else:
        even += 1
ans = odd + (even//2)*2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(x) for x in input().split()]
LIM = 10**5
freq = [0 for i in range(LIM+1)]

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

unique = sum([1 if ct > 0 else 0 for ct in freq])
evens = sum([1 if ct > 0 and ct%2==0 else 0 for ct in freq])
print(unique-(1 if evens%2==1 else 0))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

res=Counter(arr)

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

Submission status: Accepted

Solution code:
import heapq

N = int(input())
A_list = list(map(int, input().split()))
dic = {}

for a in A_list:
    if a in dic.keys():
        dic[a] += 1
    else:
        dic[a] = 1

counts = [-item for k,item in dic.items()]
heapq.heapify(counts)

max_cnt = -counts[0]
while max_cnt > 1:
    item1 = heapq.heappop(counts)
    if -item1 >= 3:
        item1 += 2
        if item1 < 0:
            heapq.heappush(counts, item1)
    else:
        item2 = heapq.heappop(counts)
        item1 += 1
        item2 += 1
        if item1 < 0:
            heapq.heappush(counts, item1)
        if item2 < 0:
            heapq.heappush(counts, item2)

    max_cnt = -counts[0]

res = 0
for v in counts:
    if v < 0:
        res += 1
    else:
        break

print(res)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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

c = Counter(arr)

c = list(c.values())
c = [x - 1 for x in c if x > 1]

if len(c) == 0:
    print(n)
    sys.exit()

if len(c) == 0:
    print(n - 2 * sum(c))
    sys.exit()

print(n - (sum(c) + 1) // 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 v in c.values():
    if v > 1:
        cnt += v - 1
print(len(set(a)) - cnt % 2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import deque

inf = 10**18
mod = 10**9+7

n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
kind = 0
for k,v in c.items():
    if v%2==0:
        kind+=1
if kind%2==0:
    print(len(c))
else:
    print(len(c)-1)

Submission status: Accepted

Solution code:
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al=lin()
	cc=collections.defaultdict(lambda :0)
	for v in al:
		cc[v]+=1
	num2=0
	num1=0
	for k in cc:
		if cc[k]> 1 and cc[k]%2==1:
			cc[k]=1
			num1+=1
		elif cc[k]>1:
			cc[k]=2
			num2+=1
		else:
			num1+=1
	ret=num1
	if num2 % 2 == 1:
		ret += num2 - 1
	else:
		ret += num2
	return ret
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
n = int(input())
import collections
dat = list(map(int, input().split()))
dat.sort()
#print(dat)
c = collections.Counter(dat)
keys = c.keys()
keys = list(keys)
keys.sort()
buf = []
for k in keys:
    buf.append( (c[k]-1) % 2)
#print(buf)
total = sum(buf)
if total % 2 == 1:
    print(len(buf) - 1)
else:
    print(len(buf))

Submission status: Accepted

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

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:
n=int(input())

l=set(map(int,input().split()))

if len(l)%2==n%2:
    print(len(l))
else:
    print(len(l)-1)

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()

    c = collections.Counter(a)

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

    deleted += deleted % 2
    print(n - deleted)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import collections

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

dic = collections.defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

ls = collections.deque()
for i in dic.keys():
    if dic[i] > 1:
        ls.append(i)

ans = n
if len(ls) > 0:
#n/2回ループ
    for i in range(n//2):
        if len(ls) == 1 and dic[ls[0]] == 2:
            ans -= 2
            dic[ls[0]] -= 1
            break
        else:
            if len(ls) == 1:
                dic[ls[0]] -= 2
            else:
                dic[ls[0]] -= 1
                dic[ls[-1]] -= 1
            ans -= 2

        if len(ls) > 1:
            if dic[ls[-1]] <= 1:
                ls.pop()
        if dic[ls[0]] <= 1:
            ls.popleft()

        if len(ls) == 0:
            break
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
rm_cnt = sum(v-1 for v in c.values())
print(len(c.keys())-(rm_cnt % 2))

Submission status: Accepted

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

rm_cnt = sum(v-1 for v in c.values())
if rm_cnt % 2 == 0:
    print(len(c.keys()))
else:
    print(len(c.keys())-1)

Submission status: Accepted

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

k = len(a)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
import heapq
cou=Counter(a)
c=[]
for k in cou.keys():
    c.append((-cou[k], k))
heapq.heapify(c)
v1,k1=heapq.heappop(c)
while v1<-1:
    if v1<-2:
        v1+=2
        heapq.heappush(c, (v1,k1))
    else:
        v2,k2=heapq.heappop(c)
        if v2<0:
            v1+=1
            v2+=1
            heapq.heappush(c, (v1,k1))
            heapq.heappush(c, (v2,k2))
    v1,k1=heapq.heappop(c)
    #print(v1,k1,c)
c.append((v1,k1))
cnt=0
for v,k in c:
    if v==-1:
        cnt+=1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
h = defaultdict(int)
for x in a:
    h[x] += 1
    if h[x]==3:
        h[x] = 1
y = sum([1 for x in h if h[x]==2])
print(len(h)-y%2)

Submission status: Accepted

Solution code:
from collections import Counter

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

a.sort()
cnt = Counter(a)
ans = 0
for k, v in cnt.items():
    if v > 1:
        ans += v - 1

print(len(cnt) - ans % 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
import math
c = Counter(A)
most = 0
s = 0
for v in c.values():
    if v > 1:
        s += v - 1
        most = max(most, v-1)
if s // 2 >= most:
    result = n - math.ceil(s / 2)*2
else:
    result = max(n - most * 2, 1)
print(result)

Submission status: Accepted

Solution code:
import collections
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A = ZZ()
    cnt = collections.Counter(A)
    cc = 0
    for key in cnt.keys():
        if cnt[key]%2 == 0: cc += 1
    num_ele = len(set(A))
    print(num_ele if cc%2 == 0 else num_ele-1)

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

p = []
ans = 0
for k,v in c.items():
    ans += 1
    if v != 1:
        p.append([k,v])
p.sort()
lef = 0
rig = len(p)-1

while True:
    if lef == rig:
        if p[lef][1] % 2 == 1:
            print(ans)
            exit()
        elif p[lef][1] % 2 == 0:
            print(ans-1)
            exit()
    elif lef > rig:
        print(ans)
        exit()
    p[lef][1] -= 1
    p[rig][1] -= 1
    if p[lef][1] == 1:
        lef += 1
    if p[rig][1] == 1:
        rig -= 1

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n = II()
    aa = MII()
    aa.sort()
    c = Counter(aa)
    v = c.values()
    v = [1 if vi%2==1 else 2 for vi in v]
    v_len = len(v)
    v_2_num = v.count(2)
    if v_2_num%2 == 1:
        v_len -= 1
    print(v_len)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N = int(sys.stdin.readline().strip())
A = map(int, sys.stdin.readline().strip().split())
counter = Counter(A)

even_count = 0
for (n, count) in counter.items():
    if count % 2 == 1:
        N -= count // 2 * 2
        counter[n] = 1
    else:
        N -= count - 2
        counter[n] = 2
        even_count += 1

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

Submission status: Accepted

Solution code:
from collections import Counter
n,*a = map(int,open(0).read().split())
c = Counter(a)
b = 0
for i in c.values():
  b+=i-1
if b%2 != 0:
  b+=1
print(n-b)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A_C = Counter(A)
c = 0
A_C_A = {}
Memo = []
for key, value in A_C.items():
    if value % 2 == 0:
        c += 1
        A_C_A[key] = 2
        if len(Memo) <= 2:
            Memo.append(key)
    else:
        A_C_A[key] = 1


if c == 2:
    Memo.sort()
    for i in range(Memo[0]+1, Memo[1]):
        if A_C[i] != 0:
            print(len(A_C_A))
            exit()
    print(len(A_C_A)-1)

elif c % 2 == 0:
    print(len(A_C))
else:
    print(len(A_C)-1)

Submission status: Accepted

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

from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]
c = Counter(nums)
even = 0
odd = 0
for v in c.values():
    if v % 2 == 0:
        even += 1
    else:
        odd += 1

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

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

n, *a = map(int, read().split())
counter = Counter(a).values()
ans = len(counter)
if (sum(counter) - ans) % 2 == 1:
    ans -= 1
print(ans)

Submission status: Accepted

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

c = dict(Counter(l))
l = len(c)
if l % 2 == 1:
  print(l)
else:
  print(l-1)

Submission status: Accepted

Solution code:



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

from collections import Counter

c = Counter(A)

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
d=dict(Counter(A))
for num in d:
  if d[num]>=3:
    if d[num] %2==0:
      d[num]=2
    else:
      d[num]=1     
#print(d)

niko=0
ikko=0
for i in d:
  if d[i]==2:
    niko +=1
  else:
    ikko +=1
#print(niko,ikko)

ikko += niko
niko = niko%2
#print(niko,ikko)

if niko==0:
  print(ikko)
else:
  print(ikko-1)