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())
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(len(l))
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: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
count = Counter(A)
l = sum(list(map(lambda x: x[1]-1,count.items())))
print(sum(list(map(lambda x: x[1],count.items())))-(l+1)//2*2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

d = Counter(a)
#print(d)
n_even = 0
for k, v in d.items():
    if v % 2 == 0:
        n_even += 1

#print(n_even)
n_unique = len(d)
print(n_unique if n_even%2 == 0 else n_unique-1)

Submission status: Accepted

Solution code:
from collections import Counter
from sys import stdin

n = int(stdin.readline())
a = sorted(map(int, stdin.readline().split()))

c = Counter(a)

to_remove = n - len(list(c.keys()))

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

Submission status: Accepted

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

    counter = Counter(cards)
    # print(counter)

    A = list(map(lambda x: x%2, counter.values()))

    pure= sum(1 for x in A if x == 1)
    needpairs = sum(1 for x in A if x == 0)
    # print(pure)
    # print(needpairs)

    answer = pure + needpairs - (1 if needpairs%2==1 else 0)
    print(answer)

def intifp(x):# {{{
    try:
        return int(x)
    except:
        return x# }}}

def strifp(x):# {{{
    try:
        return str(x)
    except:
        return x# }}}

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(raw_input())
A = [int(i) for i in raw_input().split(' ')]

A = sorted(A)
B = list(set(A))

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

Submission status: Accepted

Solution code:
import collections as co
n = int(raw_input())
aa = map(int, raw_input().split())

r = 0
d = co.Counter(aa).most_common()
for (a, count) in d:
    r += count - 1

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys

next(sys.stdin)

count = defaultdict(int)
for a in next(sys.stdin).strip().split():
    count[int(a)] += 1

even = sum(1 for n in count.values() if n % 2 == 0)
if even % 2 == 0:
    print(len(count))
else:
    print(len(count) - 1)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
M = len(np.unique(A))
print(M - (N - M) % 2)

Submission status: Accepted

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


def read():
    raw_input()
    return map(int, raw_input().split())


def work(vList):
    vList.sort()

    cntDigit = 0
    cntOdd = 0
    
    idx = 0
    while idx < len(vList):
        nex = idx
        while nex < len(vList) and vList[nex] == vList[idx]:
            nex += 1

        if (nex - idx) % 2 == 0:
            cntOdd += 1
        cntDigit += 1

        idx = nex

    print cntDigit - cntOdd % 2


if __name__ == "__main__":
    work(read())

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

_ = int(input())

d = dict()

sin = input()
for n in [int(s) for s in sin.strip().split()]:
    if n in d:
        d[n] += 1
    else:
        d[n] = 1
# print3d)
N = 0
for v in d.values():
    N += (v-1)
# print(N)

Nuniq = len(list(d.keys()))
ans = Nuniq - (0 if N%2==0 else 1)

print(ans)

Submission status: Accepted

Solution code:
def mergesort(A):
	N = len(A)
	if N==1:
		return A
	A1 = mergesort(A[:int(N/2)])
	A2 = mergesort(A[int(N/2):])
	p = 0
	p1, p2 = 0, 0
	A_result = []
	while True:
		if p1>=len(A1):
			A_result = A_result+A2[p2:]
			break
		if p2>=len(A2):
			A_result = A_result+A1[p1:]
			break
		if A1[p1]<A2[p2]:
			A_result.append(A1[p1])
			p = p+1
			p1 = p1+1
		else:
			A_result.append(A2[p2])
			p = p+1
			p2 = p2+1
		if p==N:
			break
	return A_result

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

count = 0
for i in range(N-1):
	if A[i]==A[i+1]:
		count = count+1
ans = N-count
if ans%2==0:
	ans = ans-1
print(ans)

Submission status: Accepted

Solution code:

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

c = Counter(A)

for k in c:
    c[k] = 2 if c[k] % 2 == 0 else 1

two_count = len([x for x in list(c.values()) if x == 2])
all = len([x for x in list(c.values()) if x > 0])

res = all if two_count % 2 == 0 else all-1

print(res)

Submission status: Accepted

Solution code:
from collections import Counter
l = int(input())
data = input().split()
counter = Counter(data)
s = l - len(counter)
if s % 2 == 0:
    print(len(counter))
else:
    print(len(counter) - 1)

Submission status: Runtime Error

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:
        for left in range(M):
            if C[left][1] > 1:
                break

    if C[right][1] < 2:
        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:
            C[left][1] -= 1
            for i in range(left + 1, M):
                if C[left + i][1] > 0:
                    C[left + i][1] -= 1
                    break
    else:
        C[left][1] -= 1
        C[right][1] -= 1


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

print(ans)

Submission status: Runtime Error

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:
        for left in range(M):
            if C[left][1] > 1:
                break

    if C[right][1] < 2:
        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:
            C[left][1] -= 1
            for i in range(left + 1, M):
                if C[left + i][1] > 0:
                    C[left + i][1] -= 1
                    break
    else:
        C[left][1] -= 1
        C[right][1] -= 1


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

print(ans)

Submission status: Runtime Error

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

A.sort()
i = 0
print(A)
while i < len(A) - 2:
    if A[i] == A[i + 1]:
        A.pop(i)
        A.pop(i + 2)
    else:
        i += 1
    print(i,A)

if A[-1] == A[-2]:
    print(len(A) - 1)
else:
    print(len(A))

Submission status: Runtime Error

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

while i < len(A) - 2:
    if A[i] == A[i + 1]:
        A.pop(i)
        A.pop(i + 2)
        i -= 1
    else:
        i += 1

print(len(A))

Submission status: Runtime Error

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

while i < len(A) - 2:
    if A[i] == A[i + 1]:
        A.pop(i)
        A.pop(i + 2)
    else:
        i += 1

print(len(A))

Submission status: Runtime Error

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

while i < len(A) - 1:
    if A[i] == A[i - 1] or A[i] == A[i + 1]:
        A.pop(i - 1)
        A.pop(i + 1)
    i += 1

print(len(A))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in range(len(a)):
    dic.setdefault(a[i],0)
    dic[a[i]] += 1
cnt = {}
for item in dic.items():
    if item[1] > 2:
        while dic[item[0]]>2:
            dic[item[0]] -= 2
    cnt.setdefault(dic[item[0]],0)
    cnt[dic[item[0]]] += 1
#print(cnt)
if cnt[2]%2==1:
    tmp = cnt[2]-1
    cnt[2] = 1
    cnt[1] = cnt[1] + tmp
else:
    cnt[1] = cnt[1] + cnt[2]
    cnt[2] = 0
print(cnt[1])

Submission status: Runtime Error

Solution code:
import sys
import math
N = int(input())
array = list(map(int,input().split()))
set_array = set(array)

if not ( 3 <= N <= 10**5 and N % 2 == 1 ): sys.exit()
if len(array) == len(list(set_array)): print(0);sys.exit()

print(len(list(set_array))) if len(list(set_array)) % 2 == 1 else print(len(list(set_array) - 1))

Submission status: Runtime Error

Solution code:
import sys
import math
N = int(input())
array = list(map(int,input().split()))
set_array = set(array)

if not ( 3 <= N <= 10**5 and N % 2 == 1 ): sys.exit()
if len(array) == len(list(set_array)): print(0);sys.exit()

print(len(list(set_array))) if len(list(set_array) % 2 == 1 else print(len(list(set_array) - 1)

Submission status: Runtime Error

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

#a = Counter(A)
l_a = len(a)
if(l_a%2 == 0):
     print(l_a-1)
else:
    print(l_a)

Submission status: Runtime Error

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

flg = 1
multi = [x for x in A if A.count(x) > 1]
result = list(set(multi))

count = 0
while flg:
  multi.remove(max(multi))
  multi.remove(min(multi))
  multi = [x for x in multi if multi.count(x) > 1]
  if len(multi) == 0:
    flg =0
  count += 1
print(len(A)-count*2)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
count = Counter(A)
L = []
for v in count.values():
    if v > 1:
        L.append(v-1)
L.sort(reverse = True)
M = len(L)
cnt = L[0]
for i in range(1, M):
    if abs(cnt + L[i]) - abs(cnt - L[i]) < 0:
        cnt += L[i]
    else:
        cnt -= L[i]

ans = len(count) - cnt
print(ans)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

N = getN()
A = getList()
listnum = [0] * (N + 1)
for i in A:
    listnum[i] += 1
for i in range(N + 1):
    if listnum[i] >= 3:
        listnum[i] = (listnum[i] % 2) + 1
minus = listnum.count(2)
if minus % 2 == 0:
    print(sum(listnum) - minus)
else:
    print(sum(listnum) - minus - 1)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

N = int(input())
A = list(map(int, input().split()))
listnum = [0] * 15
for i in A:
    listnum[i] += 1
for i in range(15):
    if listnum[i] >= 3:
        listnum[i] = (listnum[i] % 2) + 1
minus = listnum.count(2)
if minus % 2 == 0:
    print(sum(listnum) - minus)
else:
    print(sum(listnum) - minus - 1)

Submission status: Runtime Error

Solution code:
ddef getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
"""
from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right
"""
import sys
# sys.setrecursionlimit(1000000000)

N = getN()
A = getList()
listnum = [0] * 15
for i in A:
    listnum[i] += 1
for i in range(15):
    if listnum[i] >= 3:
        listnum[i] = (listnum[i] % 2) + 1
minus = listnum.count(2)
if minus % 2 == 0:
    print(sum(listnum) - minus)
else:
    print(sum(listnum) - minus - 1)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
# sys.setrecursionlimit(1000000000)

N = getN()
A = getList()
listnum = [0] * 15
for i in A:
    listnum[i] += 1
for i in range(15):
    if listnum[i] >= 3:
        listnum[i] = (listnum[i] % 2) + 1
minus = listnum.count(2)
if minus % 2 == 0:
    print(sum(listnum) - minus)
else:
    print(sum(listnum) - minus - 1)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
 
from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right
 
import sys
sys.setrecursionlimit(1000000000)
 
N = getN()
A = getList()
listnum = [0] * 15
for i in A:
    listnum[i] += 1
for i in range(15):
    if listnum[i] >= 3:
        listnum[i] = (listnum[i] % 2) + 1
minus = listnum.count(2)
if minus % 2 == 0:
    print(sum(listnum) - minus)
else:
    print(sum(listnum) - minus - 1)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

N = getN()
A = getList()
listnum = [0] * 15
for i in A:
    listnum[i] += 1
for i in range(15):
    if listnum[i] >= 3:
        listnum[i] = (listnum[i] % 2) + 1
minus = listnum.count(2)
if minus % 2 == 0:
    print(sum(listnum) - minus)
else:
    print(sum(listnum) - minus - 1)

Submission status: Runtime Error

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

    st = set()
    mark = 0
    for i in range(N-1,-1,-1):
        if A[i] in st:
            mark = i+1
            break
        st.add(A[i])
    else:
        print(N)
        return
    
    que = deque(A)
    cur = 0

    while len(que) >= 3:
        pop = []
        for i in range(3):
            pop_val = que.popleft()
            pop.append(pop_val)
            if cur >= mark:
                st.remove(pop_val)
            cur += 1
        cur -= 1

        pop.sort()
        append_val = pop[1]
        if cur >= mark-1 and not append_val in st:
            st.add(append_val)
            print(len(st))
            return
            
        que.appendleft(append_val)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
import heapq


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Cnt = Counter(A)
    V = list(Cnt.values())
    heap = []
    for v in V:
        heapq.heappush(heap, -1 * v)
    while heap:
        a = heapq.heappop(heap)
        if a == -1:
            print(-1 * sum(heap) + 1)
            return
        b = heapq.heappop(heap)
        heapq.heappush(heap, a + 1)
        heapq.heappush(heap, b + 1)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

B = [0] * 10001
for a in A:
    B[a] += 1
cnt2 = 0
cnt1 = 0
ans = 0
for b in B:
    if b > 2:
        cnt2 += 1
    if b > 1:
        cnt1 += 1
    if b > 0:
        ans += 1
if cnt1 % 2 == 1 and cnt2 == 0:
    ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
h=[]
a=list(map(int,input().split()))
cnt_dic=defaultdict(int)
for i in range(N):
  cnt_dic[a[i]]+=1
cnt_l=sorted(cnt_dic.values(),reverse=True)
ans=len(cnt_l)
tmp=0
for i in range(ans):
  if cnt_l[i]%2==0:
    tmp+=1
if tmp%2==0:
  pass
else:
  ans-=1
print(ans)

Submission status: Runtime Error

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

m = 0
cnt = 0
for i in A:
  if(m != A[i]):
    m = A[i]
    cnt += 1

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

Submission status: Runtime Error

Solution code:
N, *A = map(int, open('0').read().split())
cnt = 0
log = [0]*(max(A)+1)
for i in range(N):
  c = A[i]
  if log[c]!=0:
    cnt += 1
  else:
    log[c] = 1
if cnt%2==0:
  print(N-cnt)
else:
  print(N-cnt-1)

Submission status: Runtime Error

Solution code:
n = int(input())

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

kind = len(set(a))

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

Submission status: Runtime Error

Solution code:
N=int(input())

A = set(map(int, input().split()))
print(Len(A))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from heapq import heappop, heappush
N = int(input())
A = list(map(int, input().split()))

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

T = []
for a in list(set(A)):
    T.append([a, d[a]])

M = len(T)
T = sorted(T)
i = 1
flag = True
while T[0][1] - 1 > 0:
    if T[i][1] > 1:
        T[i][1] -= 1
        flag = False
        T[0][1] -= 1
    i += 1
    if i == M:
        if flag:
            break
        i = 1
        flag = True

if T[0][1] > 1:
    if T[0][1]%2:
        print(M)
    else:
        print(M-1)
else:
    for i in range(M):
        if T[i][1] > 2:
            if T[i][1]%2:
                T[i][1] = 1
            else:
                T[i][1] = 2
    cnt = 0
    for i in range(M):
        if T[0][1] == 2:
            cnt += 1
    if cnt%2:
        print(M-1)
    else:
        print(M)

Submission status: Runtime Error

Solution code:
#1,1,1 -> (1,1) 1

#1,2,3 -> (1,3) 2

#1,1,3 -> (1,3) 1  <=> 1,1,3,3 -> (1,3) 1,3

#1,2,1,3,7 == [1:2, 2:1, 3:1, 7:1]
#[1:4, 2:3, 3:2, 5:1, 6:2, 8:2, 11:1]

#それぞれ1または2と等しい
#[1:2, 2:1, 3:2, 5:1, 6:2, 8:2, 11:1]
#[1,1,3,3,6,6,8,8]
#[1,1,3,6,6,8,8]
#[1,3,6,8]

N = int(input())
A = list(map(int, input().split()))
B = [-1 for i in range(100005)]

for i in range(N):
    if B[A[i]] == -1:
        B[A[i]] = 1
    elif B[A[i]] == 1:
        B[A[i]] = 2:
    elif B[A[i]] == 2:
        B[A[i]] = 1

n = N - B.count(-1)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter
import math
N = int(input())
A = list(map(int,input().split()))
R = []
T = []
C = Counter(A)
cnt = 0
for c in C.items():
  if c[1] > 1:
    cnt += c[1] - 1
    T.append(c[0])
  else:
    R.append(c[0])
Max_R = max(T)
Min_R = min(T)
flg = False
for r in R:
  if Min_R <= r <= Max_R:
    flg = True
    break
if cnt % 2 != 0:
  ans = N - cnt - 1
else:
  if flg:
    ans = N - cnt
  else:
    ans = N - cnt - 2
print(ans)

Submission status: Runtime Error

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)
#print(D)
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: Runtime Error

Solution code:
n=int(input())
def cut(list):
  return [list[1]]

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

i=0
while i<=len(A)-3:
  if A[i]==A[i+1]:
    del A[i]
    del A[i+2]
  else:
    i+=1
  print(A)
print(len(A))

Submission status: Runtime Error

Solution code:
import sys
import collections

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

n=int(input())
a=list(map(int,input().split()))
tmp=collections.Counter(a)
b=list(tmp.values())
b=list(map(lambda  x:x*-1, b))
heapq.heapify(b)
ans=0
while 1:
    cnt1=heapq.heappop(b)
    if cnt1==-1:
        break
    cnt2=heapq.heappop(b)
    if cnt2==-1:
        ans+=cnt1*-2-2
        break
    ans+=max(cnt1,cnt2)*-2-2
    heapq.heappush(b,cnt1-max(cnt1,cnt2)-1)
    heapq.heappush(b,cnt2-max(cnt1,cnt2)-1)
print(n-ans)

Submission status: Runtime Error

Solution code:
import bisect
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
c=list(Counter(a).items())
c=[i[1]-1 for i in sorted(c)]

u=0
l=len(c)-1
ans=0
while True:
    if c[u]>c[l]:
        ans += c[l]
        c[u] -= c[l]
        c[l] = 0
        l -= 1
    elif c[u]<c[l]:
        ans += c[u]
        c[l] -= c[u]
        c[u] = 0
        u += 1
    else:
        ans += c[u]
        c[l] = 0
        c[u] = 0
        l -= 1
        u += 1
    
    if l - u == 1:
        ans += max(c[u], c[l])
        break
    elif l == u:
        ans += c[l]//2 + c[l]%2
        break

print(n-2*ans)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1_000_000)
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: Runtime Error

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 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: Runtime Error

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 cnt[s] <= 1:
    break
  cnt[s] -= 1
  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: Runtime Error

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 value2[0] - value2[1] >= sum(value2[1:]):
  print(N - (value2[0] * 2))
else:
  if(sum(value2[0:]) % 2 == 0):
    print(len(value2))
  else:
    if len(value2) != 1:
      print(len(value2) - 1)
    else:
      print(1)

Submission status: Runtime Error

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 value2[0] - value2[1] >= sum(value2[1:]):
  print(N - (value2[0] * 2))
else:
  if(sum(value2[0:]) % 2 == 0):
    print(len(value2))
  else:
    if len(value2) != 0:
      print(len(value2) - 1)
    else:
      print(1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

dic = {}
for a in an:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1

tim = 0
for a in dic:
    if dic[1] % 2 == 0:
        tim += 1

print(len(dic)-(tim+1)%2)

Submission status: Runtime Error

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 -= 2
    i += 1
    if len(l) == 0:break
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: Runtime Error

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)
l = []
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 -= 2
    i += 1
l.sort()
k = 0
for i in l:
    if not d[i]%2:k += 1
    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