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 resolve():
    n = int(input())
    a = list(map(int, input().split()))
    k = len(set(a))
    if k % 2:
        print(k)
    else:
        print(k - 1)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
s = len(set(A))
if not (n - s) % 2:
    print(s)
else:
    print(s - 1)

Submission status: Accepted

Solution code:
import collections

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = [int(_) for _ in input().split()]

counter = Counter(A)

values = []
for value in counter.values():
    if value >= 2 and value % 2 == 0:
        values.append(2)
    elif value >= 2 and value % 2 == 1:
        values.append(1)
    else:
        values.append(1)

sec_count = Counter(values)
if sec_count[2] % 2 == 0:
    print(len(values))
else:
    print(len(values) - 1)

Submission status: Accepted

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

A.sort()
C = [0] * (max(A)+1)

for i in range(n):
    C[A[i]] += 1

ans = 0
for i in range(len(C)):
    ans += max(0, C[i]-1)

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

Submission status: Accepted

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

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

    dic = {}
    tmp = 0
    for num in a:
        if num in dic:
            dic[num] += 1
            tmp += 1
        else:
            dic[num] = 1
    # print(dic)
    print(N - tmp - int(tmp&1))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify

N = int(input())
A = [int(x) for x in input().split()]
#print(sorted(A))
counter = {}
for a in A:
    counter[a] = counter.get(a,0)+1

heap = [(-c, a) for a, c in counter.items()]
heapify(heap)
cnt = 0
#print(sorted(heap))
while -heap[0][0] >= 2:
    cnt+=1
    c, a = heappop(heap)
    c = -c
    #print(repr(str(a)), c)
    if c == 2:
        #cca
        #acc
        c1, a1 = heappop(heap)
        c1 = -c1
        heappush(heap, (-(c-1), a))
        if c1-1:
            heappush(heap, (-(c1-1), a1))
    else:
        heappush(heap, (-(c-2), a))
print(len(heap))

Submission status: Accepted

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

A = sorted(A)

tmp = 1
Gtmp = 0
Ktmp = 0

for i in range(N-1):
    if A[i] == A[i+1]:
        tmp += 1
    elif tmp % 2 == 0:
        Gtmp += 1
        tmp = 1
    else:
        Ktmp += 1
        tmp = 1
if tmp % 2 == 0:
    Gtmp += 1
else:
    Ktmp += 1

ans = Ktmp + Gtmp - Gtmp % 2

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = [int(s) for s in input().split()]
c = Counter(A)
b = [n - 1 for v, n in c.items() if n > 1]
ans = len(c) - sum(b) % 2
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

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

def func(v):
    if v < 3:
        return v
    a = v//3 + v%3

    return func(a)

ans = 0
se = 0
dd = [0 for i in range(3)]
for k, v in d.items():
    value = v // 3 + (v % 3)
    value = func(v)
    # dd[value] += 1
    if value % 3 == 0 or value % 3 == 1:
        ans += 1
    else:
        se += 1

print(ans + ((se//2)*2))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
k=[0]*max(a)
for i in range(n):
	k[a[i]-1]+=1
ans=0
b=0
for i in range(max(a)):
	if k[i]%2!=0:
		ans+=1
	elif k[i]!=0:
		b+=1
if b%2==0:
	ans+=b
else:
	ans+=b-1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
num = [0]*(10**5+1)
for i in A:
    num[i] += 1

doub = 0
for i in num:
    if i > 0:
        doub += i-1

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

Submission status: Accepted

Solution code:
def main():

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


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

Submission status: Accepted

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

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


n1 = n2 = 0
for k, v in d.items():
    if v >= 3:
        if v % 2 == 0:
            d[k] = 2
        else:
            d[k] = 1

    if d[k] == 1:
        n1 += 1
    else:
        n2 += 1

# print(d)
# print(n1, n2)
n1 += n2 - n2 % 2
n2 = n2 % 2

ans = n1

print(n1)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
D={}
for i in a_list:
    if not i in D:
        D[i]=1
    else:
        D[i]+=1
count=0
for i in D:
    count+=1
r=n-count
if r%2==0:
    print(count)
else:
    print(count-1)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(j) for j in input().split()]
ans=len(set(a))
if (n-ans)%2==0:
    print(ans)
else:
    print(ans-1)

Submission status: Accepted

Solution code:
n=int(input())
a=[int(j) for j in input().split()]
tmp=len(set(a))
while n>tmp:
    n-=2
print(n)

Submission status: Accepted

Solution code:
from collections import Counter
from operator import itemgetter

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

B = list(Counter(A).items())
B.sort(key=itemgetter(0))

c = 0
even = False
for k, v in B:
    if v % 2 == 1:
        c += 1
    else:
        if even == True:
            c += 2
            even = False
        else:
            even = True
print(c)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
eq={}
for i in range(n-1):
  if a[i]==a[i+1]:
    if a[i] in eq:
      eq[a[i]]+=1
    else:
      eq[a[i]]=1
sousa=0
for i in eq.values():
  sousa+=i
if sousa%2==0:
  print(n-sousa)
else:
  print(n-sousa-1)

Submission status: Accepted

Solution code:
# ABC053D - Card Eater (ARC068D)
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    ans = len(set(A))  # kind of distinct numbers
    # consume one if the sum of duplicates are odd
    ans -= (N - ans) % 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# データ構造：ヒープ
import heapq
class heapque:
    def __init__(self, *args):
        self.que = []
        for arg in args:
            self.push(arg)
    def push(self, v):
        heapq.heappush(self.que, v)
    def pop(self):
        return heapq.heappop(self.que)

from collections import Counter

# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    cnt = Counter(A).values()
    # 3以上の奇数を相殺させ1へ
    cnt = [1 if c % 2 else c for c in cnt]
    # 偶数を相殺させ2へ
    cnt = [2 if c % 2 == 0 else c for c in cnt]

    print(len(cnt) - cnt.count(2) % 2)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    A.sort()
    dic = {}
    
    for i,val in enumerate(A):
        if val in dic:
            dic[val] += 1
        else:
            dic[val] = 1
            
    delet = []
    for k, v in dic.items():
        if v > 1:
            tmp = v - 1
            for _ in range(tmp):
                delet.append(k)
                
    tmp = -(-len(delet) // 2)
    ans = N
    ans = ans - (tmp * 2)
        
    print(ans)
    
            
            
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(N: int, A: "List[int]"):
    c = Counter(A)
    daburi = 0
    for k in c:
        if c[k] % 2 == 1:
            c[k] = 1
        elif c[k] % 2 == 0:
            c[k] = 2
            daburi += 1
    if daburi % 2 == 1:
        print(len(c)-1)
    else:
        print(len(c))

    return


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:
N = int(input())
As = list(map(int, input().split()))
ss = set(As)
r = len(ss) if len(ss)%2 == 1 else len(ss)-1
print(r)

Submission status: Accepted

Solution code:
from collections import defaultdict
def main():
    n = int(input())
    ls = list(input().split())
    dc = defaultdict(int)
    for i in ls:
        dc[i] += 1
    cnt1 = 0
    cnt2 = 0

    for i in dc.values():
        if i%2==1:
            cnt1 += 1
        else:
            cnt2 += 1
    if cnt2%2==0:
        print(cnt1+cnt2)
    else:
        print(cnt1+cnt2-1)
    

    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
num_list = sorted([ int(v) for v in input().split() ])
count_list = [0 for i in range(10**5+1)]

for i in num_list:
    count_list[i] += 1

def eating(x):
    if x % 2 == 0:
        return 2
    else:
        return 1
count_list = [ eating(i) for i in count_list if i > 0 ]


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    x = II()
    if x < 1200:
        print("ABC")
    else:
        print("ARC")
    return

#B
def B():
    s = S()
    a = inf
    z = 0
    for num,si in enumerate(s):
        if si == "A":
            a = min(a, num)
        if si == "Z":
            z = max(z, num)
    print(z-a+1)
    return

#C
def C():
    x = II()
    print(x // 11 * 2 + (x % 11) // 7 + (x % 11 != 0))
    return

#D
def D():
    n = II()
    x = LI()
    print(len(set(x)) - (n - len(set(x))) % 2)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
MAX_A = 10**5
dp = [0] * (MAX_A + 1)
for i in range(N):
    dp[A[i]] += 1

tmp = 0
for j in range(MAX_A + 1):
    if dp[j] > 0:
        tmp += dp[j] - 1
tmp += tmp % 2
print(N - tmp)

Submission status: Accepted

Solution code:
from collections import defaultdict

n=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
c=0
for i in range(n):
    d[a[i]]+=1
    if d[a[i]]>2:d[a[i]]-=2;c+=1
e=[x[1] for x in sorted(d.items(),key=lambda x:x[0])]
c+=(e.count(2)+1)//2
print(n-c*2)

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = sorted(list(map(int, input().split())))
C = collections.Counter(A)
k = len(collections.Counter(A).keys())
if k % 2 == 1:
    print(k)
else:
    print(k - 1)

Submission status: Accepted

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

A_set = set(A_arr)
ans = len(A_set)
if ans%2 == 0:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

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


from collections import Counter

c = Counter(a)

two = 0
ans  = n
for x in c:
    i = c[x]
    while i > 2:
        i -= 2
        ans -= 2
    if i == 2:
        two += 1

ans -= (two+1)//2*2

print(ans)

Submission status: Accepted

Solution code:
_ = input()
A = set(map(int, input().strip().split(' ')))
print(len(A)-(len(A)%2==0))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from collections import Counter


n = getN()
nums = getList()
ans = n
muda = 0
ans = 0

for k, v in Counter(nums).items():
    # print(k, v)
    if v >= 2:
        muda += v -1
    ans += 1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * 100001
for x in A:
  B[x] += 1
for i in range(len(B)):
  if B[i] >= 3:
    B[i] = 2 if B[i] % 2 == 0 else 1
t = B.count(2)
nz = B.count(1) + t
if t % 2 == 1:
  nz -= 1
print(nz)

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

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

Submission status: Accepted

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

a2 = {}
for i in a:
    a2.setdefault(i, 0)
    a2[i] += 1
for i in a2.keys():
    a2[i] = (a2[i] - 1) % 2 + 1
total = sum(a2.values())
num = list(a2.values()).count(2)
total -= ((num - 1) // 2 + 1) * 2
print(total)

Submission status: Accepted

Solution code:

from collections import Counter
import math

def main():
    num = int(input())
    data = list(map(int, input().split()))
    count_num = Counter(data)

    overlap_num = 0
    for ele, value in count_num.items():
        if value > 1:
            overlap_num += value - 1

    ans = num - math.ceil(overlap_num / 2) * 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
_,a=open(0);k=len(set(a.split()));print(k-1+k%2)

Submission status: Accepted

Solution code:
_,a=open(0);k=len(set(a.split()));print(k-(k%2<1))

Submission status: Accepted

Solution code:
from collections import*
from heapq import*
n,*a=map(int,open(0).read().split())
q=[-t for t in Counter(a).values()]
heapify(q)
while q[0]<-1:
    p=heappop(q)
    if p<-2:
        heappush(q,p+2)
    else:
        heappush(q,p+1)
        r=heappop(q)
        if r<-1:
            heappush(q,r+1)
print(len(q))

Submission status: Accepted

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

cnt = {}
for a in A:
  if a not in cnt:
    cnt[a] = 1
  else:
  	cnt[a] += 1
  
s, e = 1, 100000
while True:
  while (s not in cnt or cnt[s] <= 1) and s < e:
    s += 1
  while (e not in cnt or cnt[e] <= 1) and s < e:
    e -= 1
  if e < s:
    break
  if s == e:
    if s in cnt:
      if cnt[s] <= 1:
        break
    else:
      break
  if s in cnt:
  	cnt[s] -= 1
  if e in cnt:
    cnt[e] -= 1

ans = 0
for i in range(1, 100001):
  if i in cnt and cnt[i] > 0:
    ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
def abc053c(cards):
    counts = {}
    for card in cards:
        if card not in counts:
            counts[card] = 0
        counts[card] = counts[card] + 1
    # safety remove
    for card in counts:
        if counts[card] > 2:
            counts[card] = 2 - (counts[card] % 2)

    len_counts = len(counts.keys())
    dup_cards = len(list(card for card in counts if counts[card] > 1))
    return len_counts - (dup_cards % 2)


if __name__ == '__main__':
    _ = input()
    a = map(int, input().split(" "))
    print(abc053c(a))

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int,input().split())
c = {}
for a in A:c[a] = c.get(a,0)+1
print(len(c) - sum(v-1 for v in c.values())%2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]"):
    s = set()
    for a in A:
        s.add(a)
    num = len(s)
    ret = num - (num + 1) % 2
    print(ret)
    return


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

l = len(set(A))
print(l - (N - l) % 2)

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(A)
ret = len(C)

cnt = []
for v in C.values() :
    if v >= 2 :
        cnt.append(v - 1)

s = sum(cnt)
for c in cnt :
    if c > s // 2 :
        ret -= (2 * c - s) % 2
        break
else :
    ret -= s % 2
        
print(ret)

Submission status: Accepted

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

R = {}
for i in A:
  if i in R:
    R[i] += 1
  else:
    R[i] = 1

ans = len(R)

print(ans - (1 - (ans % 2)))

Submission status: Accepted

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

set_A = set(A)

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

Submission status: Accepted

Solution code:
from collections import Counter
import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
cnt = 0
for key in C:
    if C[key] % 2:
        ans += 1
    else:
        cnt += 1
        ans += 1
print(ans - cnt % 2)

Submission status: Accepted

Solution code:


def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    return n, alist


def submit():
    n, alist = read_input()

    count = {}
    count_t = 0
    for a in alist:
        if a not in count.keys():
            count[a] = False
        else:
            count[a] = not count[a]
            if count[a]:
                count_t += 1
            else:
                count_t -= 1

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




if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
N = len(A)

c = np.bincount(A)
# 無駄なやつ
useless = c[c >= 2]
sub = useless.sum() - len(useless)
print(N - math.ceil(sub / 2) * 2)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
d = defaultdict(lambda:0)

double = 0
for i in range(N):
    d[A[i]] += 1
    if d[A[i]] != 1:
        double += 1

if double%2==0:
    ans = N-double
else:
    ans = N-double-1

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
import math
def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n = int(input())
    a=list(input().split())
    b = n - len(set(a))
    b = b if b % 2 == 0 else b + 1
    print(n - b)
main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = LI()
    len_set = len(set(A))
    print([len_set-1,len_set][(N-len_set) % 2 == 0])
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
c=[0]*100000
count=0

a=list(map(int,input().split()))
for i in range(n):
    c[a[i]-1]+=1
    if c[a[i]-1]>1:
        count+=1

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# 方針
# 1個のやつは何もしないでOK
# 合計個数が奇数の数字は自己解決する（最終的に1になる）
# 偶数になる数字は組を作ると解決する（2,2,5,5 のような場合）
# 偶数になる数字の組から漏れた数字は削られる

def main():
  n=I()
  l=LI()

  l.sort()

  l2=[]

  a=l[0]
  c=1
  ans=0
  aa=0
  for x in l[1:]:
    if x==a:
      c+=1
    else:
      if c==1:
        ans+=1
      else:
        if c%2==0:
          aa+=1
        else:
          ans+=1
      a=x
      c=1
  if c==1:
    ans+=1
  else:
    if c%2==0:
      aa+=1
    else:
      ans+=1

  return ans+aa-aa%2

print(main())

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
ans,two=0,0
for k,v in cnt.items():
    if v%2==1:
        ans+=1
    else:
        two+=1
        ans+=1
if two%2==1:
    ans-=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A_Nonsort = list(map(int, input().split()))
A = sorted(A_Nonsort)
count = 1
tmp = 0
result = 0
first_flag = True

def check_count(count):
    while count > 3:
        q, mod = divmod(count, 3)
        count = q + mod
    if (count == 2):
        return True
    return False

for a in A:
    if (not first_flag):
        if (a != tmp):
            if (check_count(count)):
                result += 1
            count = 1
    first_flag = False
    if (a == tmp):
        count += 1
    tmp = a
else:
    if (check_count(count)):
        result += 1

print(len(list(set(A))) - result % 2)

Submission status: Accepted

Solution code:
#coding:utf-8
N=input()
A=map(int,raw_input().split())
A.sort()
E=[False]*N

i=0;j=N-1
while i<j:
    if A[i]!=A[i+1]:
        i+=1
        continue
    if A[j]!=A[j-1]:
        j-=1
        continue
    E[i]=E[j]=True
    i+=1;j-=1
ans=0
for e in E:
    if not e:ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
 
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
A = l_inpl()
d = defaultdict(int)

for Ai in A:
    d[Ai] += 1

for k, v in d.items():
    while v > 2:
        v -= 2
    d[k] = v

print(len(d) - (len([v for v in d.values() if v == 2])%2 == 1))

Submission status: Accepted

Solution code:
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
 
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
A = l_inpl()
d = defaultdict(int)

for Ai in A:
    d[Ai] += 1

k = len(d)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
dict1 = {}
for i in range(N):
  if A[i] not in dict1.keys():
    dict1[A[i]] = 0
  else:
    dict1[A[i]] += 1
value1 = []
for value in dict1.values():
  value1.append(value)
value2 = sorted(value1, reverse = True)
if len(value2) != 1:
  if value2[0] - value2[1] >= sum(value2[1:]):
    print(N - (value2[0] * 2))
  else:
    if(sum(value2[0:]) % 2 == 0):
      print(len(value2))
    else:
      print(len(value2) - 1)
else:
  print(1)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000



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

A_ = list(set(A))
if len(A_) % 2 == 1:
    ans = len(A_)
else:
    ans = max(1,len(A_)-1)

print(ans)
"""

"""

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
ac = list(set(a))

d = len(a) - len(ac)

ans = len(a) - d

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

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()

    cnt = len(set(a))

    if (n - cnt)%2:
        cnt -= 1

    print(cnt)

solve()