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 collections
n = int(input())
a = [int(i) for i in input().split()]
ans = n
even = 0
c = collections.Counter(a)
for i in c:
        ans-=c[i]-1
        if c[i]%2 == 0:
                even += 1
if even%2 == 1:
        ans -= 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

a = list(map(int, input().split()))
set_a = set(a)
nums = {}
cnt = 0

for i in range(n):
    nums[a[i]] = nums.get(a[i], 0) + 1


for i in set_a:
    if nums[i] % 2 == 0:
        cnt += 1
    elif nums[i] != 1:
        cnt += 2

print(len(set_a) - cnt%2)

Submission status: Accepted

Solution code:
N = int(input())
li = [ int(it) for it in input().split() ]
import collections as col
cc = col.Counter(li)
go = []
x = 0
s = 0
for k,v in cc.items():
  go.append( [k,v] )
  s += 1
  if ( v>1 ):
    x += v-1
if ( x%2 == 0 ):
  print (s)
else:
  print (s-1)

Submission status: Accepted

Solution code:
# AAA -> A
# AABB -> AB
# 基本的に超過分から2枚を自由に消せる

from collections import Counter
N = int(input())
A = [int(x) for x in input().split()]
x = len(set(A))

# N-x枚が超過分

if (N-x)&1:
  answer = x-1
else:
  answer = x

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

d = dict()

for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

ans = 0
even = 0
for i in d.values():
    if i % 2 == 0:
        even += 1
    ans += 1

if even % 2 == 1:
    ans -= 1

print(ans)

Submission status: Accepted

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

d = {}
for i in range(N):
    d[a[i]] = 0

for i in range(N):
    d[a[i]] += 1

cnt = 0
cntt = 0
for i in d.keys():
    if d[i] % 2 == 0:
        d[i] = 2
        cntt += 1
    else:
        d[i] = 1
        cnt += 1

if cntt % 2 != 0:
    cntt -= 1

print(cnt + cntt)

Submission status: Accepted

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

print(k-1+(k%2))

Submission status: Accepted

Solution code:
N=int(input())
*A,=map(int,input().split())
cnt = {}
for a in A:
    cnt[a] = cnt.get(a,0)+1
keys = sorted(cnt.keys())
i = 0
j = len(keys)-1
while i <= j:
    ki,kj = keys[i],keys[j]
    if cnt[ki]<=1:
        i+=1
        continue
    if cnt[kj]<=1:
        j-=1
        continue
    cnt[ki] -= 1
    cnt[kj] -= 1
print(sum(cnt.values()))

Submission status: Accepted

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

C = Counter(A)
even = len([c for c in C.values() if c % 2 == 0])

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

_ = input()
an = sorted([int(i) for i in input().split(" ")])

c = collections.Counter(an)

print(len(c)-(len(c)+1)%2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter(list(map(int, input().split()))).items()
rest = len([a for a, n in A if n % 2 == 0])
if rest % 2 == 1:
    print(len(A) - 1)
    exit()
print(len(A))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(item) for item in input().split()]

cnt = Counter(a)
double = 0
double_id = []
for key in cnt.keys():
    double += cnt[key] - 1
    if cnt[key] > 1 and key not in double_id:
        double_id.append(key)
if double == 0:
    print(len(cnt))
elif double % 2 == 1:
    print(len(cnt)-1)
elif double % 2 == 0:
    # if len(double_id) == 2:
    #     if abs(double_id[1] - double_id[0]) == 1:
    #         print(len(cnt)-1)
    #         exit()
    print(len(cnt))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    d = defaultdict(lambda: 0)
    for a in A:
        d[a] += 1
        if d[a] >= 3:
            d[a] -= 2

    ans = 0
    dup = 0
    for key in d.keys():
        if d[key] == 1:
            ans += 1
        else:
            dup += 1

    ans += 2 * (dup // 2)

    return ans


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

Submission status: Accepted

Solution code:
def card_eater(N: int, A: list)->int:
    d = {}
    for a in A:
        d.setdefault(a, -1)
        d[a] += 1

    exceeds = sum(v for v in d.values())

    return N - exceeds - exceeds % 2


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = card_eater(N, A)
    print(ans)

Submission status: Accepted

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


def main():
    n = int(input())
    a = list(map(int, input().split()))
    count = len((set(a)))

    if count % 2 == 0:
        count -= 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
bit = [0]*pow(10,5)
for a in A:
    bit[a-1] += 1
cnt = 0
kind = 0
for b in bit:
    if b > 0:
        cnt += b-1
        kind += 1
if cnt % 2 == 0:
    ans = kind
else:
    ans = kind-1

print(ans)

Submission status: Accepted

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

suma = sum([v for v in c.values()])
lenc = len(c)
b = suma - lenc
if b % 2 == 0:
    print(lenc)
else:
    print(lenc - 1)

Submission status: Accepted

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

suma = sum([v for v in c.values()])
lenc = len(c)
if suma == lenc:
    print(suma)
    exit()
    
b = suma - lenc
if b % 2 == 0:
    print(lenc)
else:
    print(lenc - 1)

Submission status: Accepted

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

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

a.sort()


temp = 0
double = 0

for i in range(n):
    if temp != a[i]:
        temp = a[i]
    else:
        double += 1

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

Submission status: Accepted

Solution code:
import numpy as np
import math
import fractions

class KyoPro:
    AtCoder_Mod = 1000 * 1000 * 1000 + 7

    @staticmethod
    def ReadNumbers():
        return list(map(int, input().split()))

    @staticmethod
    def MakeStringFromNumbers(a):
        if len(a) == 0:
            return
        s = str(a[0])

        for i in range(1, len(a)):
            s += ' ' + str(a[i])
        
        return s


def main():
    n = int(input())
    a = KyoPro.ReadNumbers()

    mx = max(a)
    count = list(range(mx + 1))

    for i in range(len(count)):
        count[i] = 0
    
    for i in a:
        count[i] += 1
    
    sum = 0
    for i in range(len(count)):
        if(count[i] > 1):
            sum += count[i] - 1
    
    if(sum % 2 == 1):
        sum += 1
    
    print(n - sum)
        
    

main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = {}
    for a in A:
        if a not in cnt:
            cnt[a] = 0
        cnt[a] += 1
    tmp = 0
    for k in cnt:
        tmp += cnt[k] - 1
    print(N - (tmp+1)//2 * 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
# 奇数
a = list(map(int, input().split()))
# 操作
# 3枚カードを選び、真ん中の数のカードだけ戻す
# 残されたカードに書かれた値が互いに異なるようにしたい
# 何枚のカードを残すことが可能か

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

to_rem = 0
for vv in d.values():
    to_rem += vv - 1

to_rem_rest = to_rem % 2

ans = N - to_rem - to_rem_rest
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_array = [int(x) for x in input().split()]
a_dict = {}

for a in a_array:
    a_dict.setdefault(a, 0)
    a_dict[a] += 1

if len(set(a_dict.keys())) == 1:
    print(1)
    exit()
# 種類数と枚数の関係
# 複数枚ある場合の他への影響？
# 2枚だったらほかの枚数が1枚減る
# 3枚だったら他への影響なし
# 4枚だったらほかの枚数が1枚減る
# 5枚だったら他への影響なし
# 6枚だったら他の枚数が1枚減る
# -> x//3+x%3の関係？

# 2枚ずつ減る(1枚残るため)


cnt = len(a_dict.keys())
tmp = 0
for a, a_num in a_dict.items():
    if a_num % 2 == 0:
        if tmp == 1:
            tmp = 0
        else:
            tmp += 1
    else:
        continue
else:
    print(cnt - tmp)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
A = Counter(a)
count = 0
ans = 0
for number in A:
    if  A[number]%2 == 0:
        count += 1
    ans += 1

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

Submission status: Accepted

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

for i in range(len(t)):
    s.remove(t[i])

if len(s) % 2 == 0:
    x = len(s)
else:
    x = len(s) + 1

print(n - x)

Submission status: Accepted

Solution code:
from collections import Counter

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

a.sort()
c = Counter(a)

ans = 0
for k, v in c.items():
    ans += v - 1

print(n - (ans % 2 + ans))

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
from collections import defaultdict
cnt=defaultdict(int)
for a in A:
    cnt[a]+=1

twice=0
ans=0
for i,j in cnt.items():
    if j>=2:
        ans+=(j-1)//2
        twice+=(j-1)%2
ans+=(twice+1)//2
print(N-2*ans)

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())
n = ip()                                     #入力整数1つ
#n,x= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
b = set(a)
coin = len(a) - len(b)
if coin%2:coin+=1
print(len(a)-coin)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
x = I()
ans = 2*(x//11)+1
x %= 11
if x == 0:
    ans -= 1
if x > 6:
    ans += 1
print(ans)
"""

#D
n = I()
a = LI()
d = defaultdict(int)
for i in a:
    d[i] += 1
l = list(d.values())
k = len(l)+sum(l)
for i in d.keys():
    d[i] = 1
ans = sum(list(d.values()))
ans -= 1 if k%2 else 0
print(ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
x = I()
ans = 2*(x//11)+1
x %= 11
if x == 0:
    ans -= 1
if x > 6:
    ans += 1
print(ans)
"""

#D
n = I()
a = LI()
d = defaultdict(int)
for i in a:
    d[i] += 1
l = list(d.keys())
k = 0
for i in l:
    k ^= ~(d[i]%2)
    d[i] = 1
ans = sum(list(d.values()))
ans -= 1 if k%2 else 0
print(ans)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

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

a = sorted(a)

info= []
count = 0
for i in range(len(a)-1):
  if a[i+1]==a[i]:
    count +=1
  else:
    if count !=0:
      info.append(count)
    count = 0

if count !=0:
  info.append(count)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def fun():
     print('ac')
     print('AC')
     print('ACAC')
     print('ac')
n=eval(input())
ls=map(int,input().split())
l=[]
for i in ls:
     l.append(i)
result=len(set(l))
if result%2==0:
     result-=1
print(result)

Submission status: Accepted

Solution code:

a = int(input())

x = list(map(int, input().split()))
y  =set(x)
if len(y)%2==0:
    print(len(y)-1)
else:
    print(len(y))

Submission status: Accepted

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

Submission status: Accepted

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

COUNT=0
for c in counter:
    if counter[c]>1:
        COUNT+=counter[c]-1


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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
S = set(A)
ans = len(S)
if (N-ans) % 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)
ans = len(C)
if (N-ans) % 2 == 1:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
c=Counter(map(int,input().split()))
v=sum(map(lambda x:x-1,c.values()))
if v%2==0:
    print(len(c))
else:
    print(len(c)-1)

Submission status: Accepted

Solution code:
from collections import Counter


def solve(N, As):
    counter = Counter(As)
    if len(counter) % 2 == 0:
        return len(counter) - 1
    return len(counter)

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
counter = Counter(list(map(int, input().split())))
ans = n
cnt = 0
for v in counter.values():
    if v % 2 == 0:
        if v >= 3:
            ans -= v - 2
        cnt += 1
    else:
        ans -= v - 1

ans -= cnt + cnt % 2
print(ans)

Submission status: Accepted

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

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

from collections import Counter

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

dups = Counter(aN)
for k, v in dups.items():
    dups[k] -= 1
aN = sorted(set(aN))

if sum(dups.values()) % 2 == 0:
    print(len(aN))
else:
    print(len(aN)-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
count = [1]
count_index = 0
for i in range(1, N):
    if A[i] > A[i-1]:
        count.append(1)
        count_index += 1
    else:
        count[count_index] += 1
for i in range(count_index + 1):
    count[i] = 1 - count[i] % 2
print(count_index + 1 - sum(count) % 2)

Submission status: Accepted

Solution code:
n = int(input())
a = (int(i) for i in input().split())
a2  =set(a)
if len(a2)%2 == 1:
  print(len(a2))
else:
  print(len(a2)-1)

Submission status: Accepted

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

ans = len(set(A))
C = Counter(A)
Even = 0
for v in C.values():
    if v % 2 == 0:
        Even += 1

if Even % 2 == 1:
    ans -= 1

print(ans)

Submission status: Accepted

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

from collections import Counter

a_set = set(a_list)
counter = Counter(a_list)

remove = 0
for k, v in counter.items():
    if v > 1:
        remove += v -1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
count = {}
for a in A:
    count[a] = count.get(a, 0) + 1
res = 0
for k, v in count.items():
    res += v - 1
print(N - 2 * ((res + 1) // 2))

Submission status: Accepted

Solution code:
import collections
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
L1=[]
for x in collections.Counter(L).most_common():
    L1.append(list(x))
for x in L1:
    if x[1] > 2 and x[1] % 2 == 0:
        x[1] = 2
    elif x[1] > 2 and x[1] % 2 == 1:
        x[1] = 1
flag = 0
temp = -1
for i in range(len(L1)):
    if L1[i][1] == 2 and flag == 0:
        flag = 1
        temp = i
    elif L1[i][1] == 2 and flag == 1:
        flag = 0
        L1[i][1] = 1
        L1[temp][1] = 1
        temp = -1
for x in L1:
    if x[1] == 2:
        print(len(L1)-1)
        break
else:
    print(len(L1))
#print(L1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

con = collections.Counter(A)

ans = len(set(A))

tmp = 0

for i in con.values():
    if i % 2 == 0:
        tmp += 1
        
if tmp % 2 != 0:
    ans -= 1
    
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = input().split()
a = [int(m) for m in a]
a.sort()
c = collections.Counter(a)
count = 0
for i in c:
    if c[i] % 2 == 0:
        count += 1
if count % 2 == 0:
    print(len(c))
else:
    print(len(c) - 1)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = set(li_input())

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

    



main()

Submission status: Accepted

Solution code:
n=int(input())
cards=list(map(int,input().split()))
cards.sort()
prevnum=cards[0]
difnum=1
for i in range(n):
    if(cards[i]!=prevnum):
        prevnum=cards[i]
        difnum+=1
if (n-difnum)%2==0:
    print(str(difnum))
else:
    print(str(difnum-1))

Submission status: Accepted

Solution code:
N=int(input())
dic={}
for x in map(int,input().split()):
    dic[x]=dic.setdefault(x,-1)+1

cnt=0
for x in dic.values():
    if x%2==1:
        cnt+=1

print(len(dic)-cnt%2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=len(list(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()))
ans = len(set(A))

cnt = [0]*(int(1e5)+2) # not 0-indexed
for ai in A:
    cnt[ai] += 1
    if cnt[ai]==3:
        cnt[ai] -= 2

s = sum(cnt) - ans
s_i = 0

for i in range(1, len(cnt)):
    if cnt[i-1]==2:
        s_i += 1
        s -= 1
    if s_i == s:
        break
else:
    ans -= 1
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int( input())
A = list( map( int, input().split()))
CA = Counter(A)
V = []
for x in CA:
    if CA[x] >= 2:
        V.append(CA[x]-1)
V.sort(key = None, reverse = True)
now = 0
ans = 0
for v in V:
    ans += v
    if now <= 0:
        now += v
    else:
        now -= v
b = abs(now)
if b%2 == 1:
    ans += 1
print( max(0,N-ans))

Submission status: Accepted

Solution code:
from collections import Counter
N = int( input())
A = list( map( int, input().split()))
CA = Counter(A)
V = []
for x in CA:
    if CA[x] >= 2:
        V.append(CA[x]-1)
V.sort(key = None, reverse = True)
now = 0
ans = 0
for v in V:
    ans += v
    if now <= 0:
        now += v
    else:
        now -= v
b = abs(now)
if b%2 == 1:
    ans += 1
print( N-ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int( input())
A = list( map( int, input().split()))
CA = Counter(A)
V = []
for x in CA:
    if CA[x] >= 2:
        V.append(CA[x]-1)
V.sort(key = None, reverse = True)
now = 0
ans = 0
for v in V:
    ans += v
    if now <= 0:
        now += v
    else:
        now -= v
b = abs(now)
if b%2 == 1:
    ans += 1
else:
    pass
print( N-ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int( input())
A = list( map( int, input().split()))
CA = Counter(A)
V = []
for x in CA:
    if CA[x] >= 2:
        V.append(CA[x]-1)
V.sort(key = None, reverse = True)
now = 0
ans = 0
for v in V:
    ans += v
    if now <= 0:
        now += v
    else:
        now -= v
b = abs(now)
if b%2 == 1:
    ans += 1
else:
    pass
print( max(N-ans,0))

Submission status: Accepted

Solution code:
from collections import Counter
N = int( input())
A = list( map( int, input().split()))
CA = Counter(A)
V = []
for x in CA:
    if CA[x] >= 2:
        V.append(CA[x]-1)
V.sort(key = None, reverse = True)
now = 0
ans = 0
for v in V:
    ans += v
    if now <= 0:
        now += v
    else:
        now -= v
b = abs(now)
if b == 0:
    pass
elif b%2 == 1:
    ans += 1
else:
    pass
print( max(N-ans,0))

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
mp={}
cnt=0
for it in a:
    if it in mp:
        cnt+=1
    else :
        mp[it]=1
N-=cnt
while cnt>=3:
    cnt=cnt//3+cnt%3
print(max(N-int(cnt==1),1))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
Card = {}
for i in range(N):
    if A[i] in Card:
        Card[A[i]] += 1
    else:
        Card[A[i]] = 1

rem, double = len(Card), 0
for i in Card:
    if Card[i] % 2 == 0:
        double += 1

print(rem - double % 2)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    C = Counter(list(map(int, input().split())))

    t = 0
    for k in C.keys():
        t += (C[k] % 2 == 0)

    ans = len(set(C))
    if t % 2 != 0:
        ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l = []
a.sort()

num = 1
for i in range(len(a)-1):
    if a[i+1] == a[i]:
        num += 1
    else:
        l.append(num)
        num = 1
l.append(num)

count = 0
for i in range(len(l)):
    if l[i] % 2 == 1:
        l[i] = 1
    else:
        count += 1
        l[i] = 1

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

Submission status: Accepted

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

l = []
a.sort()

i = 0
num = 1
while i < len(a) - 1:
    if a[i+1] == a[i]:
        num += 1
        i += 1
    else:
        l.append(num)
        num = 1
        i += 1
l.append(num)

count = 0
for i in range(len(l)):
    if l[i] % 2 == 1:
        l[i] = 1
    else:
        count += 1
        l[i] = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

evennum = len([1 for v in ctr.values() if v%2==0])
if evennum%2:
    print(len(ctr) - 1)
else:
    print(len(ctr))