Problem:


Score : 400 points

Problem Statement

Snuke has decided to play a game using cards.
He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written.

He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept.

Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.

Constraints

3 ≦ N ≦ 10^{5}

N is odd.

1 ≦ A_i ≦ 10^{5}

A_i is an integer.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_{N}

Output

Print the answer.

Sample Input 1

5
1 2 1 3 7

Sample Output 1

3

One optimal solution is to perform the operation once, taking out two cards with 1 and one card with 2. One card with 1 and another with 2 will be eaten, and the remaining card with 1 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 1, 3 and 7.

Sample Input 2

15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1

Sample Output 2

7



Sample input:
5
1 2 1 3 7


Sample output:
3

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
import collections
c=collections.Counter(l)
ans=n
eve=0
c=sorted(c.values(),reverse=True)
for i in c:
    if(i==1):
        break
    if(i%2==0):
        eve+=1
        ans-=i-2
    else:
        ans-=i-1
print(ans+2*(-eve//2))

Submission status: Accepted

Solution code:
import sys
import numpy as np


def main():
    _ = int(input())
    a = {int(x) for x in input().split()}
    print(len(a) if len(a) % 2 == 1 else len(a) - 1)


main()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from collections import defaultdict

n = ni()
a = list(li())

dic = defaultdict(int)

for ai in a:
    dic[ai] += 1

ans = 0
evn = 0

for _, cnt in dic.items():
    if cnt % 2:
        ans += 1

    else:
        evn += 1

        if evn == 2:
            ans += 2
            evn = 0

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
li = [ int(it) for it in input().split() ]

import collections as col
c = col.Counter(li)

s2=0
s1=0

for k,v in c.items():
  if ( v%2==0):
    s2 += 1
  else:
    s1 += 1
if ( s2%2==0):
  print ( s1+s2)
else:
  print ( s1+s2-1)

Submission status: Accepted

Solution code:
from collections import defaultdict
N=int(input())
A=list(map(int,input().split()))
dict=defaultdict(int)
for i in A:
    dict[i]+=1
ans=0
tmp=0
for i,j in dict.items():
    ans+=1
    if j%2==0:
        tmp+=1
print(ans-(tmp%2))

Submission status: Accepted

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

from collections import Counter

c = Counter(A)
#print(c)

ans = 0
dup = 0

for k, v in c.items():
  ans += 1
  dup += (v+1)%2
  
print(ans - dup%2)

Submission status: Accepted

Solution code:
N = int(input())

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

from collections import Counter
count_dict = Counter(A)

check = 0

for i, v in count_dict.items():
    if v >= 3 and v % 2 == 0:
        count_dict[i] = 2
    elif v >= 3 and v % 2 == 1:
        count_dict[i] = 1
    
    if count_dict[i] == 2:
        check += 1
        
if check % 2 == 0:
    print(len(count_dict))
else:
    print(len(count_dict) - 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
D - Card Eater
https://atcoder.jp/contests/arc068/tasks/arc068_b

"""
import sys


from collections import Counter

def solve(N, cards):
    cnt = Counter(cards)
    freq = [1 if v%2 else 2 for k, v in cnt.items()]
    ones = len([1 for f in freq if f == 1])
    twos = len([2 for f in freq if f == 2])
    if twos:
        if twos % 2:
            ones += (twos-1)
        else:
            ones += twos
    return ones


def main(args):
    N = int(input())
    cards = [int(a) for a in input().split()]
    ans = solve(N, cards)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A).values()

ans = len(c)
cnt = 0
for c_i in c:
    if c_i % 2 == 0:
        cnt += 1
cnt %= 2
ans -= cnt
print(ans)

Submission status: Accepted

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

# 重複しているカードに対して、ひたすら操作した結果が解である
m = len(set(A))
ans = m - (1 - m % 2)

# 出力
print(ans)

Submission status: Accepted

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

D = {}

for a in A :
    if a not in D :
        D[a] = 1
    else :
        D[a] += 1


odd = 0
even = 0

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
A=[int(i) for i in input().split()]
ans=((len(set(A))+1)//2)*2-1
print(ans)

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    L = [0] * (100001)
    for a in A:
        L[a] += 1
        if L[a] >= 3:
            L[a] -= 2
    c = L.count(2)
    p, q = divmod(c, 2)
    res = sum(L) - 2 * (p + q)
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(A).items()

res = 0
for num,cnt in c:
    if cnt % 2 == 0:
        res += 1

ans = len(c)
if res % 2 == 1:
    ans -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

d = dict()

for i in dat:
    if d.__contains__(i):
        d[i]+=1
    else:
        d[i]=1
d = list(d.items())
d.sort()
minus = 0
twos = 0
for num,cnt in d:
    while cnt>2:
        cnt-=2
        minus+=1
    if cnt==2:
        twos += 1
minus += twos//2
if twos%2:
    minus+=1
print(n-minus*2)

Submission status: Accepted

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

num = [0] * int(1e5)
for i in A:
    num[i] += 1

need = 0
for i in num:
    need += max(i-1, 0)

if need % 2 == 1:
    need += 1

ans = N - need
print(ans)

Submission status: Accepted

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

A.sort()

A.append(0)
B = []
length = 1
for i in range(N):
    if A[i] == A[i+1]:
        length += 1
    else:
        B.append(length)
        length = 1

for i in range(len(B)):
    B[i] = 2 - B[i] % 2

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

sumA = sum([v - 1 for v in Counter(A).values() if v > 1])

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(input().split())
set = set()
du = 0
for i in range(n):
    if l[i] in set:
        du +=1
    else:
        set.add(l[i])
print(n - du - du%2)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
sys.setrecursionlimit(10**7)
mo=10**9+7
n=10**5

#n,a,b=map(int,input().split())
n=int(input())
x=set()
for i in input().split():
    x.add(int(i))
ans=len(x) - (1 if (n-len(x))%2==1 else 0)
#x.sort()
print(ans)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    a = f()
    num_diff = len(set(a))
    to_eat = n - num_diff
    if to_eat%2:
        to_eat += 1
    
    print(n - to_eat)
    

solve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
def arraycount(arr):
  arr_target = [[]]
  cnt = 1
  for i in range(1,len(arr)):
     if arr[i] == arr[i-1]:
         cnt += 1
     else:
         arr_target.append([arr[i-1],cnt])
         cnt = 1
  arr_target.append([arr[len(arr)-1],cnt])
  del arr_target[0]
  return arr_target
B = arraycount(A)
n = len(B)
for i in range(n):
    if B[i][1] >=3:
        if B[i][1] % 2 == 0:
            B[i][1] = 2
        else:
            B[i][1] = 1
    else:
        continue
cnt,ans =0,0
for i in range(n):
    ans += B[i][1]
    if B[i][1] == 2:
        cnt +=1
ans = ans - 2*(-(-cnt//2))
print(ans)

Submission status: Accepted

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

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

a.sort()

cnt = 0
for i in range(1,len(a)):
    if a[i-1] == a[i]:
        cnt += 1

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

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    A = list(int(_) for _ in input().split())
    dict = {}
    for a in A:
        if a in dict:
            dict[a] += 1
        else:
            dict[a] =1
    sum = 0
    for v in dict.values():
        if v >=2:
           sum += v -1
    if sum%2 == 0:
        ans = len(dict)
    else:
        ans = len(dict) - 1
    print(ans)
    
if __name__ == '__main__':
    main()

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=[int(i) for i in input().split()]

st=set(A)
res = len(st)
if (N-res)%2==0:
    print(res)
else:
    print(res-1)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = [0] * 100001
ans = 0
for i in A:
    if d[i] >0:
        ans += 1
    d[i] += 1
print(N - ((ans + 1) // 2) * 2)

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
d=defaultdict(int)
a=list(map(int,input().split()))
for i in range(n):
    d[a[i]]+=1
c=0
for i in d.values():
    c+=i-1
print(n-2*((c+1)//2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
ans = set()
for num in lis:ans.add(num)
print(len(ans)-((len(ans) % 2)+1)%2)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

D = defaultdict(int)
for i in A:
	D[i] += 1

d = []
for i in D:
	d.append(D[i])

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
num=0
s=0
for p,n in dd.items():
    num+=1
    if n%2==0:
        s+=1
        s%=2
print(num-s)
#print(num,s,dd)

Submission status: Accepted

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

adic = {}
for a in alist:
  if a in adic:
    adic[a] += 1
  else:
    adic[a] = 1

res = sum([v-1 for v in adic.values()])
print(n - res - res%2)

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(0)
EVEN = 0
ODD = 0
cnt = 1
cur = L[0]
i = 0
while i < N:
  if L[i] == L[i+1]:
    cnt += 1
    i += 1
  else:
    if cnt%2 == 0:
      EVEN += 1
    else:
      ODD += 1
    cur = L[i+1]
    i += 1
    cnt = 1
if EVEN%2 == 0:
  print(EVEN+ODD)
else:
  print(EVEN+ODD-1)

Submission status: Accepted

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

odd=0
eve =0

for k  in counter.keys():
  if counter[k]%2==0:
    eve+=1
  else:
    odd+=1
ans=0
if eve%2==0:
  ans=eve+odd
else:
  ans=eve+odd-1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
d = {}
for i in a:
    d[i] = d.get(i,0)+1
k = len(d)
k -= (sum(d.values()) - k) % 2
print(k)

Submission status: Accepted

Solution code:
from collections import Counter


def inpl():
    return list(map(int, input().split()))


N = int(input())
A = inpl()

oe = [0, 0]
for k, v in Counter(A).items():
    oe[v % 2] += 1

if oe[0] % 2 == 0:
    print(sum(oe))
else:
    print(sum(oe) - 1)

Submission status: Accepted

Solution code:
from collections import Counter

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

ac=Counter(a)
ans=len(ac)
count=0

for aa in ac.values():
    if aa%2==0:
        count+=1


print(ans-(count%2))

Submission status: Accepted

Solution code:
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
Num = list(input().split())
C = Counter(Num)
ans = 0

l = [0]
v = len(C)
odd = len(list(filter(lambda x: x % 2 == 1, C.values())))
even = v - odd
ans += odd + even//2*2
print(ans)

Submission status: Accepted

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

def main():
    n = int(input())
    an = list(map(int, input().split()))
    k = len(set(an))
    res = k - 1 if k % 2 == 0 else k
    print(res)

main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
res = 0
for i in range(N-1):
    if A[i] == A[i+1]:
        res += 1
res = (N - res + 1) // 2 * 2 - 1
print(res)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
Ac=dict(Counter(A))
a=0
b=0
for i in Ac.keys():
    if Ac[i]>1:
        a+=Ac[i]-1
if a%2==0:
    print(N-a)
else:
    print(N-a-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
s=A[0]
v=1
l=0
for i in range(1,N):
  if s==A[i]:
    l+=1
  else:
    v+=1
    s=A[i]
print(v-(l%2))

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]

N = int(input())
A = inpl()
B = set([])
for i in A:
    B.add(i)
print(len(B)-(len(A)-len(B))%2)

Submission status: Accepted

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

count = collections.Counter(a)
rmv = 0

for i in count:
    if count[i] >= 2 and count[i]%2 == 1:
        rmv += (count[i]-1)
        count[i] = 1
    elif count[i] >= 2:
        rmv += (count[i]-2)
        count[i] = 2

two = 0
for i in count:
    if count[i] == 2:
        two += 1
if two%2 == 0:
    rmv += two
else:
    rmv += two+1
print(n-rmv)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnts = Counter(As)
num = 0
for k in cnts.values():
    if k % 2 == 0:
        num += 1

print(len(cnts.keys()) - num % 2)

Submission status: Accepted

Solution code:
N = int(input())
eat = N - len(set(map(int, input().split())))
print(N - eat - eat % 2)

Submission status: Accepted

Solution code:
N = int(input())
f = set()
eat = 0
for a in map(int, input().split()):
    if a in f:
        eat += 1
    else:
        f.add(a)
print(N - eat - eat % 2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
d = {}

for x in input().split():
    x = int(x)
    if x not in d:
        d[x] = 0
    d[x] += 1

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

N = getN()
nums = getList()
dup = defaultdict(int)

for n in nums:
    dup[n] += 1

poss = len(dup.keys())
dupdup = 0
for val in dup.values():
    if val % 2 == 0:
        dupdup += 1

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

Submission status: Accepted

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

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

score=0
res=0
for i in range(len(B)):
    if B[i]>=1:
        score+=1
    if B[i]>=2:
        res+=B[i]-1

if res%2==0:
    print score
else:
    print score-1

Submission status: Accepted

Solution code:
def ARC068D():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    count_list = []
    cnt = 1
    #print(A)
    for i in range(1, N):
        if A[i] == A[i - 1]:
            cnt += 1
        else:
            count_list.append(cnt)
            cnt = 1
    count_list.append(cnt)
    ans_cnt = 0
    #print(count_list)
    for i in range(len(count_list)):
        if count_list[i] > 2:
            ans_cnt += (count_list[i] % 2) - 1
            count_list[i] %= 2
            if count_list[i] == 0:
                count_list[i] = 2
    #print(ans_cnt)
    count_list = sorted(count_list)[::-1]
    for i in range(len(count_list) - 1):
        if count_list[i] == 2 and count_list[i + 1] == 2:
            ans_cnt += 1
            count_list[i] = 1
            count_list[i + 1] = 1
    count_list = sorted(count_list)[::-1]
    if count_list[0] == 2:
        count_list[0] = 0
    #print(ans_cnt)
    #print(count_list)
    print(sum(count_list))
ARC068D()

Submission status: Accepted

Solution code:
def main():

    S = list(input())
    checklist = [0 for i in range(26)]
    for i in S:
        checklist[ord(i) - ord("a")] += 1
    ans = True

    for i in checklist:
        if i > 1:
            ans = False

    if not ans:
        print(-1)
        return 0
    else:
        ans = False
        for i in range(len(checklist)):
            if checklist[i] == 0:
                for i in S:
                    print(i, end="")
                print(chr(i + ord("a")), end = "")
                print()
                ans = True
                break

        if not ans:
            new_S = []
            for i in S:
                new_S.append(ord(i))

            for i in range(len(new_S) - 1):
                if new_S[i] > new_S[i + 1]:
                    for j in range(i - 1):
                        print(S[j], end = "")
                    print(chr(new_S[i - 1] + 1), end = "")
                    print()
                    ans = True
                    break

            if not ans:
                print(-1)
#main()

def ABC069D():

    H, W = map(int, input().split())
    N = int(input())
    a = list(map(int, input().split()))
    ans = []
    for i in range(N):
        for j in range(a[i]):
            ans.append(i + 1)
    printlist = [[0 for i in range(W)] for j in range(H)]
    k = 0
    for i in range(H):
        for j in range(W):
            printlist[i][j] = ans[k]
            k += 1
        if i % 2 != 0:
            printlist[i] = printlist[i][::-1]

    for i in range(H):
        for j in range(W):
            print(printlist[i][j], end = "")
            if j != W:
                print(" ", end = "")
        print()
    print()
#ABC069D()

import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def ABC057D():

    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v)[::-1]

    anslist = []
    for i in range(A, B + 1):

        anslist.append([sum(v[0:i]) / i, i, v[i - 1]])
    anslist.sort()
    anslist = anslist[::-1]
    ans = anslist[0][0]
    key = anslist[0][2]
    long = anslist[0][1]
    print(ans)
    for i in range(1, len(anslist)):
        if anslist[i][0] == anslist[i - 1][0]:
            ans = anslist[i][0]
            key = anslist[i][2]
            long = anslist[i][1]
        else:
            break
    #print(anslist)
    #print(ans, key, long)
    cnt = 0
    for i in v:
        if i == key:
            cnt += 1

    c = 0
    for i in v[:long]:
        #print(i)
        if i == key:
            c += 1
    #print(c, long)
    ans = 0
    if c == long:
        for i in range(A,  min(B + 1, cnt + 1)):
            ans += cc(cnt, i)
    else:
        ans = cc(cnt, c)
    #print(anslist)
    #print(cnt, c, long)
    print(ans)
#ABC057D()

def ABC104D():
    S = list(input())
    A_cnt = 0
    B_cnt = 0
    C_cnt = 0
    Q_cnt = 0
    ans = 0
    for i in S:
        if i == "A":
            A_cnt += 1
        elif i == "B":
            B_cnt += 1
        elif i == "C":
            C_cnt += 1
        else:
            Q_cnt += 1
    for i in range(Q_cnt + 1):
        for j in range(Q_cnt - i + 1):
            k = Q_cnt - i - j
            if A_cnt + i > 0 and B_cnt + j > 0 and C_cnt + k > 0:
                f_i = math.factorial(i)
                f_j = math.factorial(j)
                f_k = math.factorial(k)
                if f_i == 0:
                    f_i = 1
                if f_j == 0:
                    f_j = 1
                if f_k == 0:
                    f_k = 1
                ans += (A_cnt + i) * (B_cnt + j) * (C_cnt + k) * math.factorial(Q_cnt) // f_i // f_j // f_k
                print(ans, i, j, k, A_cnt + i, B_cnt + j, C_cnt + k)
                print(math.factorial(Q_cnt), f_i, f_j, f_k)
    print(ans)
#ABC104D()

def ARC073D():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for i in range(N)]

def ARC075():
    N, A, B = map(int, input().split())
    h = [int(input()) for i in range(N)]
    def enogth(T):
        import copy
        this_h = copy.copy(h)
        cnt = 0
        for i in range(N):
            this_h[i] -= B
            key = 0
            if this_h[i] > 0:
                key = this_h[i] / (A - B)
                if int(key) != key:
                    key += 1
                cnt += int(key)
        if cnt <= T:
            return True
        else:
            return False
    def sarch(i: object) -> object:
        print(i)
        if enogth(i):
            if i // 2 == 1:
                return i
            sarch(0 + i // 2)
        else:
            sarch(i + i // 2)
    print(sarch(10 ** 9))
#ARC075()

def ARC082D():
    N = int(input())
    p = list(map(int, input().split()))
    cnt = 0
    if p[N - 1] == N:
        #print(p[N - 1], N)
        p[-2], p[-1] = p[-1], p[-2]
        cnt += 1

    for i in range(N - 1):
        if p[i] == i + 1:
            p[i], p[i + 1] = p[i + 1], p[i]
            cnt += 1
    print(cnt)
#ARC082D()

from queue import Queue
def ABC070D():
    N = int(input())
    a, b, c =map(int, input().split())
    Q, K = map(int, input().split())
    xy = [list(map(int, input().split())) for i in range(Q)]
    x = [[] for i in range(N)]
    for i, j in xy:
        x[i - 1].append(j - 1)
        x[j - 1].append(i - 1)

    q = Queue()
    visited = [0 for i in range(N)]

def ABC076D():
    N = int(input())
    t = list(map(int, input().split()))
    v = list(map(int, input().split()))
    speed_lim = [0]
    speed_list = [0 for i in range(sum(t) + 1)]
    for i in range(N):
        for j in range(t[i]):
            speed_lim.append(v[i])
    print(speed_lim)
    for i in range(1, sum(t) + 1):
        speed_list[i] = speed_list[i - 1] + 1
        if speed_list[i] > speed_lim[i]:
            speed_list[i] = speed_lim[i]
    print(speed_list)
    speed_list[-1] = 0
    for i in range(sum(t) - 1, -1, -1):
        speed_list[i] = min(speed_list[i + 1] + 1, speed_list[i])
        if speed_list[i] > speed_lim[i + 1]:
            speed_list[i] = speed_lim[i + 1]
    print(speed_list)
    ans = 0
    for i in speed_list:
        ans += i

    print(ans)
#ABC076D()

def ABC076D():
    N = int(input())
    t = list(map(int, input().split()))
    a = []
    for i in t:
        a.append(i * 2)
    t = a
    v = list(map(int, input().split()))
    #print(t)
    speed_lim = [0]
    speed_list = [0 for i in range(sum(t) + 1)]
    for i in range(N):
        for j in range(t[i]):
            speed_lim.append(v[i])
    #print(speed_lim, len(speed_list), len(speed_lim))
    for i in range(1, sum(t) + 1):
        speed_list[i] = speed_list[i - 1] + 0.5
        if speed_list[i] > speed_lim[i]:
            speed_list[i] = speed_lim[i]
    #print(speed_list)
    speed_list[-1] = 0
    for i in range(sum(t) - 1, -1, -1):
        speed_list[i] = min(speed_list[i + 1] + 0.5, speed_list[i])
        if speed_list[i] > speed_lim[i + 1]:
            speed_list[i] = speed_lim[i + 1]
    #print(speed_list)
    ans = 0
    for i in speed_list:
        ans += i

    print(ans / 2)
#ABC076D()

def ABC085D():
    N, H = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    a = []
    b = []
    for i, j in ab:
        a.append(i)
        b.append(j)
    a.sort()
    b.sort()
    a = a[::-1]
    b = b[::-1]
    damage = 0
    cnt = 0
    for i in b:
        if i < a[0]:
            break
        damage += i
        cnt += 1
        if damage >= H:
            break
    key = 0
    if damage < H:
        key = (H - damage) / a[0]
        if int(key) != key:
            key += 1
        key = int(key)

    cnt += key

    print(cnt)
#ABC085D()

def ARC068D():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    count_list = []
    cnt = 1
    #print(A)
    for i in range(1, N):
        if A[i] == A[i - 1]:
            cnt += 1
        else:
            count_list.append(cnt)
            cnt = 1
    count_list.append(cnt)
    ans_cnt = 0
    #print(count_list)
    for i in range(len(count_list)):
        if count_list[i] > 2:
            ans_cnt += (count_list[i] % 2) - 1
            count_list[i] %= 2
            if count_list[i] == 0:
                count_list[i] = 2
    #print(ans_cnt)
    count_list = sorted(count_list)[::-1]
    for i in range(len(count_list) - 1):
        if count_list[i] == 2 and count_list[i + 1] == 2:
            ans_cnt += 1
            count_list[i] = 1
            count_list[i + 1] = 1
    count_list = sorted(count_list)[::-1]
    if count_list[0] == 2:
        count_list[0] = 0
    #print(ans_cnt)
    #print(count_list)
    print(sum(count_list))
ARC068D()

Submission status: Accepted

Solution code:
input()
print((len(set(input().split()))+1)//2*2-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
*l,=map(int,input().split())
a=Counter(l)
itm=len(set(l))
b=len(list(filter(lambda x:x[1]%2==0,a.items())))
if b%2:
  print(itm-1)
else:
  print(itm)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
d = Counter(reads())

dup = sum(v-1 for k, v in d.items() if v >= 2)
print(N - (dup + 1) // 2 * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
import copy
import sys

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] =  [long(input_raw[0])]
    input_raw = read_func().strip().split()
    cards = {}
    for i in range(N):
        c = int(input_raw[i])
        if c not in cards:
            cards[c] = 1
        else:
            cards[c] += 1

    even_num = 0
    for c in cards:
        if cards[c] % 2 == 0:
            even_num += 1
    if even_num % 2 == 0:
        print len(cards)
    else:
        print len(cards) - 1



if __name__ == '__main__':
    main()

Submission status: Accepted

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

    a.sort()
    idx, cnt, s = 0, 0, 0
    while idx < n:
        c = 1
        s += 1
        while idx < n-1 and a[idx] == a[idx+1]:
            idx += 1
            c += 1
        if c % 2 == 0:
            cnt += 1
        idx += 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
N=int(input())
A=[int(i) for i in input().split() ]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
L=[]
for j in dd.values():
    L.append(j-1)
if len(L)==1 or len(L)==2:
    print(1)
    sys.exit()
if sum(L)%2==1:
    print(len(L)-1)
    sys.exit()
if sum(L)%2==0:
    print(len(L))
    sys.exit()

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
s = set()
for i in range(n):s.add(lis[i])
lis.sort()
if (len(lis)-len(s)) % 2 == 1:
	print(len(s)-1)
else:
	print(len(s))