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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
input()
print(len(set([int(i) for i in input().split()])))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a_list = [int(i) for i in input().split()]
#まず、奇数個存在する数字を除去
cnt = collections.Counter(a_list)

for key, num in cnt.items():
    print(cnt)
    if num == 2 or num == 1:
        pass
    # 1より大きい奇数なら
    elif num % 2 != 0 and num > 1:
        cnt[key] = 1
        # num = 1
    # 2より大きい偶数なら
    elif num % 2 == 0 and num > 2:
        cnt[key] = 2
        # num = 2
    else:
        pass
        # print("?")

c = 0
result = 0
for key, num in cnt.items():
    if num == 2:
        c += 1

if c % 2 == 0:
    result = len(cnt)
else:
    result = len(cnt) - 1

print(result)

# print("final:",cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = raw_input()
N = int(N)
l = raw_input().split(" ")
l = map(int,l)

def check(l):
    return list(set(l))

print len(check(l))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = set()
d = dict()
for i in a:
	if i not in s:
		d[i] = 1
		s.add(i)
	else:
		d[i] += 1
l = list(d.values())
l.sort(reverse=True)
cnt = l.count(1)
if cnt == len(l):
	print(0)
else:
	diff = len(l) - cnt
	su = 0
	for i in l:
		if i!=1:
			su += (i-1)
		else:
			break
	if su%2==0:
		print(len(l))
	else:
		print(len(l)-1)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

# print(prob)

prob.sort()

i1 = 0
i2 = 1

count = 0
while(len(prob) >= 3 and i2 < len(prob)-1):
    if (prob[i1] == prob[i2]):
        prob.pop(i2+1)
        prob.pop(i1)
    else:
        i1 += 1
        i2 += 1

# print(prob)

print(len(prob))

Submission status: Wrong Answer

Solution code:
def Main():
  n = int(input())
  A = list(map(int, input().split()))
  s = set(A)
  print(len(s))
if __name__ == '__main__':
  Main()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

# print(prob)

prob.sort()

i1 = 0
i2 = 1

count = 0
while(len(prob) >= 3 and i2 < len(prob)):
    if (prob[i1] == prob[i2]):
        prob.pop(i2+1)
        prob.pop(i1)
    else:
        i1 += 1
        i2 += 1

# print(prob)

print(len(prob))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

# print(prob)

prob.sort()

i1 = 0
i2 = 1

count = 0
while(i2 < len(prob)):
    if (prob[i1] == prob[i2]):
        prob.pop(i2+1)
        prob.pop(i1)
    else:
        i1 += 1
        i2 += 1

# print(prob)

print(len(prob))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
arr= []
count = 0
for i in range(len(a)):
    if a[i] == a[i-1]:
        arr.append(a[i])
        count += 1

print(n-count-(count%2))

Submission status: Wrong Answer

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

a_set = set(a)
count = 0
for s in a_set:
	c = a.count(s)
	if c >= 2:
		count += c

print(len(a_set) if count%2==1 else len(a_set)-1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=[int(i) for i in input().split()]
cd = collections.Counter(a)
b=n
for i in cd.values():
  if i%3==2 or i%3==3:
     b-=2
  if i>3:
     b-=int(i/3)*2
print(b)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
A = sorted(list(map(int,input().split())))
c = Counter(A)
lst = list(c.values())
l,r = 0, len(lst)-1
while sum(lst) > len(lst):
    if lst[l] <= 1:
        l += 1
        continue
    else:
        if lst[r] <= 1:
            r -= 1
            continue
        else:
            lst[l] -= 1
            lst[r] -= 1
print(sum(lst))

Submission status: Time Limit Exceeded

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

even=0
div=0
A=[]
for i in range(n):
    if a[i] not in A:
        div += 1
        A.append(a[i])
        if a.count(a[i])%2 == 0:
            even += 1
if even%2 == 0:
    print(div)
else:
    print(div-1)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(map(int,input().split()))
ex=0
va=0
t=[]
for i in s:
    if i in t:
        ex=1-ex
    else:
        t.append(i)
        va+=1

print(va-ex)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(map(int,input().split()))
ex=0
t=[]
for i in s:
    if i in t:
        ex+=1
    else:
        t.append(i)

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
for k in range(N-1):
    if A[k]==A[k+1] and A[k]!=0:
        for j in range(N-1,k+1,-1):
            if A[j]==A[j-1] and A[j]!=0:
                A[j]=0
                A[k]=0
                break
count=0
dcount=0
for k in range(len(A)):
    if A[k]!=0:
        count+=1
for k in range(len(A)-1):
    if A[k]==A[k+1] and A[k]!=0:
        dcount+=2
print(count-dcount)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = []
c = 0
for i in a:
    if not i in s:
        s.append(i)
    else:
        c += 1
print(n - 2 * ((c + 1) // 2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())#5
a = list(map(int,input().split()))#1 2 1 3 7
a.sort() #1 1 2 3 7
while True:
    #print(*a)
    if len(set(a)) == len(a):
        print(len(a))
        exit()
    for i in range(n):
        if a[i] == a[i+1]:
            try:
                a1 = a[i]
                a2 = a[i+2]
            except:
                a1 = a[i-1]
                a2 = a[i+1]
            a.remove(a1)
            a.remove(a2)
            break

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
A = list(map(int,input().split()))
A_set = set(A)
ans=N
cut=0
for i in range(len(A_set)):
	comp = A.count(A_set.pop())
	cut+= comp-1
cut = math.ceil(cut/2)*2
print(ans-cut)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

c = collections.Counter(x)
li = []
for i in c.values():
    li.append(i)

li.sort(reverse=True)

while li[0] != 1:
    for i in range(len(li)-1):
        if li[i] >= 3 and li[i] % 2 == 0:
            li[i] = 2
        elif li[i] >= 3 and li[i] % 2 != 0:
            li[i] = 1

        if li[i+1] == 2 and li[i] == 2:
            li[i+1] = 1
            li[i] = 1
    li.sort(reverse=True)
    if len(li) > 1 and li[0] == 2 and li[1] == 1:
        li[0] -= 1
        li.pop(-1)

print(len(li))

Submission status: Time Limit Exceeded

Solution code:
import collections

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

c = collections.Counter(x)
li = []
for i in c.values():
    li.append(i)

li.sort(reverse=True)

while li[0] != 1:
    for i in range(len(li)-1):
        if li[i] >= 3:
            li[i] -= 2
        if li[i+1] == 2 and li[i] == 2:
            li[i+1] = 1
            li[i] = 1
    li.sort(reverse=True)
    if len(li) > 1 and li[0] == 2 and li[1] == 1:
        li[0] -= 1
        li.pop(-1)

print(len(li))

Submission status: Time Limit Exceeded

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

for i in A:
    if i in S:
        D.append(i)
    else:
        S.append(i)
S=set(S)

import sys
if D==[]:
    print(N)
    sys.exit()

M=N-len(D)
if len(D)%2==1:
    print(M-1)
else:
    MaxD,MinD=D[-1],D[0]
    Med=-1
    for i in S:
        if MinD<=i<=MaxD:
            Med=i
            print(M)
            break
    if Med==-1:
        print(M-2)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
S=[]
D=[]

for i in A:
    if i in S:
        D.append(i)
    else:
        S.append(i)

import sys
if D==[]:
    print(N)
    sys.exit()

M=N-len(D)
if len(D)%2==1:
    print(M-1)
else:
    MaxD,MinD=max(D),min(D)
    Med=-1
    for i in S:
        if MinD<=i<=MaxD:
            Med=i
            print(M)
            break
    if Med==-1:
        print(M-2)

Submission status: Time Limit Exceeded

Solution code:

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

a.sort()
x=0
b=set(a)
b=list(b)
for i in range(len(b)):
    if a.count(b[i])!=1:
        x+=a.count(b[i])-1
        
y=len(b)
if x%2==0:
    print(y)

else:
    print(y-1)

Submission status: Time Limit Exceeded

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

def main():
    counts = [A.count(i) for i in set(A)]
    even = [c for c in counts if c % 2 == 0]
    ans = len(counts) if len(even) % 2 == 0 else len(counts) - 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
cards = []
for i in range(0, 100001):
	cards.append(0)
for i in range(0, N):
	cards[A[i]] += 1
cards.remove(0)
cards.sort(reverse = True)
while cards[0] >= 2:
	if cards[0] >= 3:
		if cards[0] % 2 == 0:
			cards[0] = 2
		else:
			cards[0] = 1
	else:
		cards[0] -= 1
		cards[1] -= 1
	cards.remove(0)
	cards.sort(reverse = True)
sum = 0
for i in range(0, len(cards)):
	sum += cards[i]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
cards = []
for i in range(0, 100001):
	cards.append(0)
for i in range(0, N):
	cards[A[i]] += 1
cards.sort(reverse = True)
while cards[0] >= 2:
	if cards[0] >= 3:
		if cards[0] % 2 == 0:
			cards[0] = 2
		else:
			cards[0] = 1
	else:
		cards[0] -= 1
		cards[1] -= 1
	cards.sort(reverse = True)
sum = 0
for i in range(0, 100001):
	sum += cards[i]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
cards = []
for i in range(0, 100001):
	cards.append(0)
for i in range(0, N):
	cards[A[i]] += 1
cards.sort(reverse = True)
while cards[0] >= 2:
	if cards[0] >= 3:
		cards[0] -= 2
	else:
		cards[0] -= 1
		cards[1] -= 1
	cards.sort(reverse = True)
sum = 0
for i in range(0, 100001):
	sum += cards[i]
print(sum)

Submission status: Time Limit Exceeded

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 and s in cnt and cnt[s] <= 1:
    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: Time Limit Exceeded

Solution code:


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


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


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

    count = list(count.items())
    pruned = []
    for c in count:
        if c[1] > 1:
            if c[1] % 2 == 0:
                pruned.append((c[0], 2))
            else:
                pruned.append((c[0], 1))
        else:
            pruned.append(c)

    f = False
    for c in pruned:
        if c[1] == 2:
            f = not f

    if f:
        print(len(pruned) - 1)
    else:
        print(len(pruned))

    return


if __name__ == '__main__':
    submit()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = list(map(int, input().split()))
set_a = set(a)
nums = {}
cnt = 0
for i in set_a:
    nums[i] = a.count(i)
    if a.count(i) % 2 == 0:
        cnt += 1
    elif a.count(i) != 1:
        cnt += 2

print(len(set_a) - cnt%2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = list(map(int, input().split()))
set_a = set(a)
nums = {}
cnt = 0
for i in set_a:
    nums[i] = a.count(i)
    if a.count(i) % 2 == 0:
        cnt += 1
    else:
        if a.count(i) == 1:
            continue
        else:
            cnt += 2

print(len(set_a) - cnt%2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(map(int, input().split()))
s.sort()
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: Time Limit Exceeded

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())
i = 0
while i < len(l):
    if d[l[i]] < 2:
        l.pop(i)
        i -= 1
    i += 1
l.sort()
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: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = N
l = 1
r = 10**5
while l != r or (l == r and C[l] > 1):
    while C[l] <= 1:
        l += 1
    while C[r] <= 1:
        r -= 1

    if l != r:
        res = min(C[l], C[r]) - 1
    else:
        res = C[l]//2
    C[l] -= res
    C[r] -= res
    ans -= 2*res
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
ans = N
l = 1
r = 10**5
while l != r or (l == r and C[l] > 1):
    while C[l] <= 1:
        l += 1
    while C[r] <= 1:
        r -= 1

    if l != r:
        res = min(C[l], C[r]) - 1
    else:
        res = C[l]//2
    C[l] -= res
    C[r] -= res
    ans -= 2*res
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
ans = N
l = 1
r = 10**5
while l != r or (l == r and C[l] > 1):
    while C[l] <= 1:
        l += 1
    while C[r] <= 1:
        r -= 1
    C[l] -= 1
    C[r] -= 1
    ans -= 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
input()
a = list(map(int, input().split()))
c = []
b = [i for i in a if i in c or c.append(i)]
print(len(c) if len(b) % 2 == 0 else len(c)-1)

Submission status: Time Limit Exceeded

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

dic = {}
one = []
for i in range(N):
	if not A[i] in one:
		one.append(A[i])

ans = len(one)
print(ans - ((ans+1) % 2))

Submission status: Time Limit Exceeded

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

ref = [a.count(i)-1 for i in list(set(a)) if a.count(i)!=1]

ans = N - ((sum(ref)+1)//2)*2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
def ni(): return int(stdin.readline())

n = ni()
a = na()
lst = []
c=0
for i in a:
    if(i not in lst):
        lst.append(i)
        c = c+1

if(c%2 == 0):c=c-1

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
card = [int(i) for i in input().split()]
single = [i for i in card if card.count(i) == 1]
plural = sorted([i for i in card if i not in single])
while len(plural) > 0:
    min_A = plural.pop(0)
    max_A = plural.pop(-1)
    if plural.count(min_A) == 1:
        single.append(plural.pop(0))
    if plural.count(max_A) == 1:
        single.append(plural.pop(-1))

print(len(single))

Submission status: Time Limit Exceeded

Solution code:
if __name__=="__main__":
    n = int(input())
    As = list(map(int,input().split()))
    Non_dup_As = list(set(As))
    count = 0
    for a in Non_dup_As:
        count+=As.count(a)-1
    if(count % 2 == 0):
        print(len(As) - int(count))
    else:
        print(len(As) - int(count+1))

Submission status: Time Limit Exceeded

Solution code:
if __name__=="__main__":
    n = int(input())
    As = list(map(int,input().split()))
    Non_dup_As = list(set(As))
    As.sort()
    count = 0
    for a in Non_dup_As:
        count+=As.count(a)-1
    if(count % 2 == 0):
        print(len(As) - int(count))
    else:
        print(len(As) - int(count+1))

Submission status: Time Limit Exceeded

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

s = set(a)
l = len(s)
l2 = 0 if len([a.count(x) for x in s]) % 2 else 1
print(l - l2)

Submission status: Time Limit Exceeded

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

s = set(a)
l = len(s)
l2 = 0 if len([a.count(x) for x in s]) % 2 else 1
print(l - l2)

Submission status: Time Limit Exceeded

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

l = len(set(a))
l2 = 0 if len([a.count(x) for x in set(a)]) % 2 else 1
print(l - l2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_card = list(map(int, input().split()))
count = 0
for x in set(list_card):
    count += list_card.count(x) - 1
print(N - (count + count%2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(max(A)):
    if A.count(i+1) > 0:
        count += A.count(i+1) -1
N = N - 2*(count // 2 + count % 2)
print(N)

Submission status: Time Limit Exceeded

Solution code:
#coding: UTF-8
import time
N=int(input())
lis=list(map(int, input().split()))
kind=set(lis)
kindn=len(kind)
#start_time=time.clock()
out=0
for i in kind:
    if lis.count(i)%2==0:
        out+=1
#stop_time=time.clock()
if out%2==0:
    print(kindn)
else:
    print(kindn-1)
#print(stop_time-start_time)

Submission status: Time Limit Exceeded

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

while(True):
    is_finish = False
    mn = min(a)
    while(a.count(mn) == 1):
        idx = a.index(mn)+1
        if idx >= len(a):
            mn = min(a)
            break
        else:
            mn = a[idx]

    mx = max(a)
    while(a.count(mx) == 1):
        idx = a.index(mx) - 1
        if idx < 0 or mx == mn :
            mx = max(a)
            is_finish = True
            break
        else :
            mx = a[idx]

    if is_finish :
        break
    else:
        a.remove(mn)
        a.remove(mx)

print len(a)

Submission status: Time Limit Exceeded

Solution code:
#coding: UTF-8
import time
N=int(input())
lis=list(map(int, input().split()))
kind=list(set(lis))
kindn=len(kind)
out=0
for i in kind:
    if lis.count(i)%2==0:
        out+=1
if out%2==0:
    print(kindn)
else:
    print(kindn-1)

Submission status: Time Limit Exceeded

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

a_set = set(a)
count = 0
for s in a_set:
	c = a.count(s)
	if not(c & 1):
		count += 1

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(raw_input())
a = map(int, raw_input().split())
a.sort()

while(True):
    mn = min(a)
    while(a.count(mn) == 1):
        try:
            mn = a[a.index(mn)+1]
        except:
            mn = min(a)
            break

    mx = max(a)
    while(a.count(mx) == 1):
        try:
            mx = a[a.index(mx)-1]
        except:
            mx = max(a)
            break

    a.remove(mn)
    a.remove(mx)

    count = Counter(a)
    if max(count.values()) == 1:
        break

print len(a)

Submission status: Time Limit Exceeded

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

a_set = set(a)
count = 0
for s in a_set:
	c = a.count(s)
	if c % 2 == 0:
		count += 1

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

Submission status: Time Limit Exceeded

Solution code:
#coding: UTF-8
N=int(input())
lis=list(map(int, input().split()))
kind=list(set(lis))
kindn=len(kind)
out=0
for i in kind:
    if lis.count(i)%2==0:
        out+=1
if out%2==0:
    print(kindn)
else:
    print(kindn-1)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

input()
c = Counter(sorted([int(i) for i in input().split()]))
n = list(c.keys())

while c.most_common(1)[0][1] > 1:
    for nn in n:
        if c[nn] > 1:
            l = nn
            break
    for nn in n[::-1]:
        if c[nn] > 1:
            r = nn
            break
    c[l] -= 1
    c[r] -= 1

print(len(list(filter(lambda x: x[1] > 0, c.items()))))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
c_value = list(c.values())
overflow = sum(c_value) - len(c_value)
if overflow % 2 == 0:
    print(len(c_value))
else:
    print(len(c_value) - 1)

Submission status: Accepted

Solution code:
import collections
N = int(input())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
lsn = list(counterA.values())
rep = 0
even = 0
for i in lsn:
    if i % 2 ==1:
        rep += i//2
    else:
        rep += (i-1)//2
        even += 1
rep += -(-even//2)
ans = N-rep*2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

counter = 0
for key, value in num_map.items():
    if value % 2 == 0:
        num_map[key] = 2
        counter += 1
    else:
        num_map[key] = 1

res = len(num_map) - counter % 2
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
from collections import Counter
c = Counter(a)
even_cnt = sum([cnt%2==0 for i, cnt in c.items()])
if even_cnt % 2:
    print(len(c) - 1)
else:
    print(len(c))

Submission status: Accepted

Solution code:
from math import ceil

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


cnt=[0]*100010
lst=[]

for i in a:
  cnt[i]+=1

for i in cnt:
  if i<=1:
    continue
  
  else:
    x=i-1
    lst.append(x)

print(n-ceil(sum(lst)/2)*2)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
nums = [0] * 100005
for x in a:
    nums[x] += 1
even, odd = [], []
for p in nums:
    if p % 2 == 1 and p > 1:odd.append(p)
    elif p % 2 == 0 and p > 0:even.append(p)
ans = n
for x in odd:
    ans -= x - 1
if len(even) % 2 == 1:
    ans -= 1
for x in even:
    ans -= x - 1
print(ans)

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	A.sort()
	cnt = []
	c = 0
	a = 0
	for i in range(len(A)):
		if i == 0:
			a = A[i]
			c += 1
		else:
			if A[i] == a:
				c += 1
			elif A[i] != a:
				cnt.append(c)
				c = 1
				a = A[i]
	else:
		cnt.append(c)

	cnt = list(map(lambda ct: (2 - (ct % 2)), cnt))
	evens = cnt.count(2)
	if evens % 2 == 0:
		print(len(cnt))
	else:
		print(len(cnt) - 1)

main()

Submission status: Accepted

Solution code:

url = "https://atcoder.jp//contests/abc057/tasks/abc057_d"

import collections

def main():
    n = int(input())
    cards = list(map(int, input().split()))
    c_cards = collections.Counter(cards)
    credit = 0
    r = 0

    for k in c_cards:
        surplus = c_cards[k] - 1
        r += surplus
        if c_cards[k] > 1:
            n -= surplus
            if credit > 0:
                credit = abs(credit - surplus%2)
            else:
                credit += surplus%2
            c_cards[k] -= surplus
    if credit > 0:
        n -= credit
    print(n)



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)
C = sorted(C.items())

cc = []
for a, b in C:
    cc.append([a, b])
C = cc

M = len(C)

left = 0
right = M - 1

while True:
    if C[left][1] < 2:
        p_left = left
        for left in range(p_left, M):
            if C[left][1] > 1:
                break

    if C[right][1] < 2:
        p_right = M - right - 1
        for right in range(M):
            if C[M - right - 1][1] > 1:
                break

        right = M - right - 1

    if C[left][1] <= 1 and C[right][1] <= 1:
        break

    if left == right:
        if C[left][1] >= 3:
            C[left][1] -= 2
        else:
            f = 0
            C[left][1] -= 1
            for i in range(left + 1, M):
                if C[i][1] > 0:
                    C[i][1] -= 1
                    f = 1
                    break

            if f == 0:
                for i in range(0, left):
                    if C[i][1] > 0:
                        C[i][1] -= 1

    else:
        C[left][1] -= 1
        C[right][1] -= 1


ans = 0
for a, b in C:
    ans += b

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
cnt=[0 for _ in range(100001)]
for i in range(N):
    cnt[A[i]]=1

x=cnt.count(1)
y=N-x
if y%2==0:
    print(N-y)
else:
    print(N-y-1)

Submission status: Accepted

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

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

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
A = na()
d = {}
for i in range(N):
    if A[i] not in d.keys():
        d[A[i]] = 0
    else:
        d[A[i]] += 1
s = 0
for k, v in d.items():
    s += v
if s % 2 == 0:
    print(len(d))
else:
    print(len(d) - 1)

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):
    if d[A[i]] == 0:
        d[A[i]] = 1
    else:
        d[A[i]] += 1

# 3つ以上被りがあるときは同じ数字をとっていく
# 2つかぶりがあるときはその他に2つ以上被りがあるやつがあればそれを取り、なければ、1まいのやつを適当に選ぶ

sorted_d = sorted(d.items(), key=lambda x: x[1], reverse=True)
fix_d = []
for i in range(len(sorted_d)):
    if sorted_d[i][1] >= 3:
        if sorted_d[i][1] % 2 == 0:
            # sorted_d[i][1] = 2
            fix_d.append([sorted_d[i][0], 2])
        else:
            # sorted_d[i][1] = 1
            fix_d.append([sorted_d[i][0], 1])
    else:
        fix_d.append([sorted_d[i][0], sorted_d[i][1]])

fix_d.sort(key=lambda x: x[1], reverse=True)

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

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

Submission status: Accepted

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

B = list(set(A))

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

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter(cards)
ans = len(counter)
rest = 0
for num, cnt in counter.items():
    rest += (cnt - 1)

if rest % 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)
ct=0
for i in C:
  ct+=C[i]-1
ct+=(ct%2==1)
print(N-ct)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter


N=int(input())
A=list(map(int,input().split()))
c = Counter(A)
s = 0
for k, v in c.items():
    s += v-1
if s % 2 == 0:
    print(len(set(A)))
else:
    print(len(set(A))-1)

Submission status: Accepted

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

Submission status: Accepted

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

tmp = [0 for _ in range(10 ** 5)]
for i in range(N):
  tmp[A[i] - 1] += 1


ans = N
flag = False
for i in range(10 ** 5):
  if tmp[i] == 0:
    continue
  elif tmp[i] % 2 == 1:
    ans -= (tmp[i] - 1)
  else:
    if flag:
      ans -= (tmp[i] - 2)
      flag = False
    else:
      ans -= tmp[i]
      flag = True

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

dict=defaultdict(int)

for a in A:
  dict[a]+=1
  
num=[0]*2
for v in dict.values():
  num[v%2]+=1
  
if num[0]%2==0:
  print(sum(num))
else:
  print(sum(num)-1)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(100000)]
cnt = 0
for a in A:
  if B[a-1] == 0:
    B[a-1] = 1
  else:
    cnt += 1
if cnt % 2 == 0:
  print(sum(B))
else:
  print(sum(B)-1)