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 card_eater():
	n = int(raw_input())
	a = map(int, raw_input().split(" "))
	total_cards = len(a)
	total_distinct_cards = len(list(set(a)))
	numofcards_to_remove = total_cards-total_distinct_cards
	if numofcards_to_remove%2==0:
		print total_distinct_cards
	else:
		print total_distinct_cards-1


if __name__ == "__main__":
	card_eater()

Submission status: Accepted

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

num = [0] * 100001

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

for i in range(100001):
    if num[i] > 1:
        num[i] = 1

sum_num = sum(num)

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

Submission status: Accepted

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
cnt=[0]*(10**5+1)
for i in xrange(n):
    cnt[a[i]]+=1
cnt1=0
cnt2=0
for i in xrange(10**5+1):
    if cnt[i]==0:continue
    if cnt[i]%2==0:
        cnt2+=1
    else:
        cnt1+=1
if cnt2%2==0:
    print cnt1+cnt2
else:
    print cnt1+cnt2-1

Submission status: Accepted

Solution code:
from collections import Counter

_ = input()
xs = Counter(map(int, input().split()))
even = sum(1 for (k, c) in xs.items() if c%2==0)
odd = sum(1 for (k, c) in xs.items() if c%2==1)
print(odd + (even//2)*2)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
sn=[0]*100001
mi2=0
mi=0
for i in range(0,n):
    if sn[a[i]]==1:
        mi2=1-mi2
    else:
        sn[a[i]]=1
        mi+=1
print(mi-mi2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
from collections import Counter

num_card = int(input())
l_card = list(map(int, input().split()))
card_counter = Counter(l_card)

num_mod = 0
for card in card_counter.values():
    if card != 1:
        num_mod += (card - 1)

ans = len(card_counter)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input().strip())
a = [int(x) for x in input().strip().split()]
num = len(list(set(a)))
print(num - (n - num) % 2)

Submission status: Accepted

Solution code:
#int input
n = int(input())
values = [int(x) for x in input().split(" ")]
def count(values):
    from collections import defaultdict
    counter = defaultdict(int)
    for value in values:
        counter[value] += 1
    return counter
odd = 0
even = 0
c = count(values)
for number, amount in c.items():
    #print(number,amount)
    if amount % 2 == 0:
        even += 1
    else:
        odd += 1
#print(odd,even)
if even % 2 == 0:
    print(odd + even)
else:
    print(odd + even - 1)

Submission status: Accepted

Solution code:
from collections import defaultdict
length = int(input())
target = [int(n) for n in input().split(" ")]
w_counter = defaultdict(int)

for t in target:
    w_counter[t] += 1

max_card = 0
min_card = 10 ** 8
overlap_card = 0 
for k,v in w_counter.items():
    if v > 1:
        max_card = max(max_card,k)
        min_card = min(min_card,k)
        overlap_card += v - 1
cannot_pinch = 1

for k,v in w_counter.items():
    if min_card <= k <= max_card:
        cannot_pinch = 0
        break
#print(overlap_card)
if overlap_card % 2 == 0:
    print(length - overlap_card)
else:
    print(length - overlap_card - (1 + cannot_pinch))

Submission status: Accepted

Solution code:
#ARC068D

n=int(raw_input())
a=map(int,raw_input().split())
b=set(a)
if len(b)%2:
 print len(b)
else:
 print len(b)-1

Submission status: Accepted

Solution code:
n=input()
l=len(set([int(x) for x in input().split()]))
print(l-(l+1)%2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

counter = Counter()
odds = 0
eat = 0

N = int(input())
for A in list(map(int, input().split())):
    counter[A] += 1

types = len(counter)

for k, v in counter.items():
    if v >= 2 and v%2 == 0:
        eat += v//2 - 1
        odds += 1
    elif v>= 2 and v%2 == 1:
        eat += v//2

if odds%2 == 0:
    eat += odds / 2
    print(types)
else:
    eat += odds // 2 + 1
    print(types-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

input()
c = Counter(map(int, input().split()))
print((len(c) - 1) // 2 * 2 + 1)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter([int(i) for i in input().split()])
c = 0
for i in A:
	if not A[i] % 2:
		c += 1
print(len(A)-c%2)

Submission status: Accepted

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

    L = len(a)
    if L%2 == 0:
        L -= 1

    return L

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

Submission status: Accepted

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
D = dict()
for a in A:
   if not a in D:
      D[a] = 0
   D[a] += 1

total = 0
for num, count in D.iteritems():
   if count > 1: total += count - 1
if total % 2 != 0: total += 1
print N - total

Submission status: Accepted

Solution code:
#D Card Eater
N = int(input())
List = [int(i) for i in input().split(" ")]
List.sort()
result = 1
for i in range(1,N):
    if List[i]!=List[i-1]:
        result+=1
if result%2 == 0:
    print(result-1)
else:
    print(result)

Submission status: Accepted

Solution code:
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG: {} -> {}'.format(name, val), file=sys.stderr)
            return None

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

# debug(A, locals())
m = len(A)

if m % 2 == 0:
    ans = m - 1
else:
    ans = m

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import heapq
 
n = int(input())
a = Counter(map(int, input().split()))
 
x = []
for k in a:
    if a[k] > 1:
        x.append(-(a[k] - 1))
 
heapq.heapify(x)
 
while len(x) > 1:
    u = abs(heapq.heappop(x))
    v = abs(heapq.heappop(x))
    n -= min(v, u) * 2
    d = abs(u - v)
    if d > 0:
        heapq.heappush(x, -d)
 
if len(x) > 0:
    p = abs(heapq.heappop(x))
    n -= p + p % 2
 
print(n)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in A:
    if i in D:
        D[i] += 1
    else:
        D[i] = 1
cnt = 0
for k in D.keys():
    if D[k] % 2 < 1:
        cnt += 1
print(len(D) - (cnt % 2))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
D = {}
for i in A:
    if i in D:
        D[i] += 1
    else:
        D[i] = 1
cnt = 0
for k in D.keys():
    if D[k] % 2:
        D[k] = 1
    else:
        D[k] = 2
        cnt += 1
print(len(set(A)) - (cnt % 2))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 0
e = 0
i = 0
while True:
    c += 1
    cai = 1
    while i != n - 1 and a[i] == a[i + 1]:
        cai += 1
        if i != n - 1:
            i += 1
        else:
            break
    if cai % 2 == 0:
        e += 1
    if i != n - 1:
        i += 1
    else:
        break
ans = c - (e % 2)
print(ans)

Submission status: Accepted

Solution code:
input()
a = [0] * (100000 + 1)

for i in map(int, input().split()):
    a[i] += 1
    if a[i] == 3:
        a[i] >>= 1

c = [0, a.count(1), a.count(2)]

ans = 0
ans += (c[2] >> 1) << 1
ans += c[1]

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

cin = sys.stdin

N = int(cin.readline())
A = list(map(int, cin.readline().split()))

C = Counter(A)
indi = len(C)
last = N - indi
if last % 2==1:
    ans = indi - 1
else:
    ans = indi

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9

#http://www.deqnotes.net/acmicpc/2d_geometry/lines
def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

r = n()
A = ln()

A.sort()

c = collections.Counter(A)

key = c.keys()
i = 0
j = len(key) - 1

cost = 0
while i <= j:
    while i < len(key) and c[key[i]] <= 1:
        i += 1
    while j >= 0 and c[key[j]] <= 1:
        j -= 1
    if i > j:
        break
    c[key[i]] -= 1
    c[key[j]] -= 1
    cost += 2

print r - cost

Submission status: Accepted

Solution code:
x=range(100000)
a=0;ans=0;
n=int(raw_input())
l=raw_input().split(" ")
for i in range(100000):
    x[i]=0;
for i in range(n):
    y=int(l[i])
    if x[y]==1:
        a+=1
    else:
        x[y]=1

for i in range(100000):
    if x[i]==1 :
        ans+=1

print str(ans-a%2)

Submission status: Accepted

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

counts = [ 0 for i in range(1000000)]

for a in A:
    counts[a] += 1

sum = 0
for count in counts:
    sum += max(0, count-1)

print(N - sum - sum%2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
cnt=[0]*(max(a)+1)
for i in xrange(n):
    cnt[a[i]]+=1
for i in xrange(max(a)+1):
    while cnt[i]>=3:
        cnt[i]=cnt[i]/3+cnt[i]%3
ans=0
cnt1=0
cnt2=0
tmp=0
for i in xrange(max(a)+1):
    if cnt[i]==2:
        cnt2+=1
        tmp+=2
    if cnt[i]==1:
        cnt1+=1
if cnt2%2==1:
    print(cnt1+tmp/2-1)
else:
    print(cnt1+tmp/2)

Submission status: Accepted

Solution code:
import bisect

N=int(raw_input())
A=sorted([int(x) for x in raw_input().split()])
Al=[0 for i in range(100001)]
K=[]
for a in A:
    Al[a]+=1
    if Al[a]>1:
        K.append(a)
ans=len(A)
while(len(K)>2):
    ans-=2
    al=K.pop(0)
    ar=K.pop(-1)
    Al[al]-=1
    Al[ar]-=1
if len(K)==2:
    al=K.pop(0)
    ar=K.pop(-1)
    if sum(Al[al:ar+1])==2:
        ans-=4
    else:
        ans-=2
elif len(K)==1:
    ans-=2
print ans

Submission status: Accepted

Solution code:
import sys
from collections import Counter

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG: {} -> {}'.format(name, val), file=sys.stderr)
            return None

N = int(input())
cnt_A = Counter(map(int, input().split()))

# debug(cnt_A, locals())
# debug(cnt_A.values(), locals())

dabuli = sum(cnt_A.values()) - len(cnt_A.values())

if dabuli % 2 == 0:
    ans = N - dabuli
else:
    ans = N - (dabuli + 1)

print(ans)

Submission status: Accepted

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

from collections import *
n = int(input())
As = list(map(int,input().split()))

d = Counter()
for a in As:
    d[a] += 1

two = 0
num = 0
for k,v in d.items():
    if v == 1:
        continue
    elif v % 2 == 0:
        two += 1
        num += v // 2 - 1
    else:
        num += v // 2

num += (two + 1) // 2

print(n - (num * 2))

Submission status: Accepted

Solution code:
n = int(input())
r = list(map(int, input().split()))
d = {}
for v in r: d[v] = d.get(v, -1) + 1
s = sum(d.values())
print(n - 2*((s+1)//2))

Submission status: Accepted

Solution code:
from collections import Counter
n = input()
A = map(int, raw_input().split())
C = Counter(A)
ans = 0
for k in C.keys():
    if C[k] >= 3:
        ans += (C[k]-1) / 2
        C[k] = 1 if C[k] % 2 == 1 else 2
tmp = 0
for v in C.values():
    if v == 2:
        tmp += 1
#print ans, tmp
ans += tmp / 2 + tmp % 2
print n-ans*2

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
ans = 0
even = 0
cnt = Counter(map(int, input().split()))
for k, v in cnt.items():
    if v % 2 == 0:
        ans += (v - 2) // 2
        even += 1
    else:
        ans += v // 2
ans += even // 2 + even % 2
print(N - ans * 2)

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 II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n = II()
    s = set(LI())
    l = len(s)
    if l % 2 == 1:
        return l
    return l - 1


print(main())

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
memo = {}
for a in A:
    if a in memo:
        memo[a] += 1
    else:
        memo[a] = 1
memo_sorted = sorted(memo.items(), key=lambda x:-x[1])
memo = []
for a,b in memo_sorted:
    memo.append([a,b])

for key,val in enumerate(memo):
    val_1, val_2 = val
    if val_2 <= 1:
        continue
    else:
        if val_2%2 == 1:
            memo[key][1] = 1
        elif val_2%2 == 0:
            if key < N-1:
                memo[key+1][1] -= 1
            memo[key][1] = 1
ans = 0
for a,b in memo:
    ans += b
print(ans)

Submission status: Runtime Error

Solution code:
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    from collections import Counter
    n = input_int()
    A = input_int_list()
    A_cnt = Counter(A).most_common()
    A_cnt = [list(a) for a in A_cnt]
    cnt = 0
    for i in range(len(A_cnt)):
        if A_cnt[i][1] > 2:
            if A_cnt[i][1] % 2 == 1:
                cnt += A_cnt[i][1] // 2
                A_cnt[i][1] = 1
            elif A_cnt[i][1] % 2 == 0:
                cnt += (A_cnt[i][1] // 2) - 1
                A_cnt[i][1] = 2
        if A_cnt[i][1] == 2:
            if i + 1 < n:
                A_cnt[i + 1][1] -= 1
            A_cnt[i][1] = 1
            cnt += 1
    print(n - cnt * 2)
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    from collections import Counter
    n = input_int()
    A = input_int_list()
    A_cnt = Counter(A).most_common()
    A_cnt = [list(a) for a in A_cnt]
    cnt = 0
    for i in range(len(A_cnt)):
        if A_cnt[i][1] > 2:
            if A_cnt[i][1] % 2 == 1:
                cnt += A_cnt[i][1] // 2
                A_cnt[i][1] = 1
            elif A_cnt[i][1] % 2 == 0:
                cnt += (A_cnt[i][1] // 2) - 1
                A_cnt[i][1] = 2
        if A_cnt[i][1] == 2:
            A_cnt[i + 1][1] -= 1
            A_cnt[i][1] = 1
            cnt += 1
    print(n - cnt * 2)
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = I()
A = LI()
B = [0]*(10**5+1)
for a in A:
    B[a] += 1

print(sum(B[i] != 0 for i in range(10**5+1))-(sum(max(0,B[i]-1) for i in range(10**5+1)) % 2))

Submission status: Runtime Error

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
from collections import Counter
c = Counter(a)
ones = sum(v==1 for v in c.values())
ns = [v-1 for v in c.values() if v>1]
ans = ones + len(ns)
ns.sort()
if ns[-1]>sum(ns[:-1]):
    after = ns[-1] - sum(ns[:-1])
    if after%2==1:
        ans -= 1
else:
    after = 1 if sum(ns)%2==1 else 0
    if after==1:
        ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
import collections as col

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

m = col.Counter(A)
ans = len(m) if m%2==1 else len(m)-1
print(ans)

Submission status: Runtime Error

Solution code:
import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets
import critbits, future, strformat, deques
template `max=`(x,y) = x = max(x,y)
template `min=`(x,y) = x = min(x,y)
let read* = iterator: string {.closure.} =
    while true: (for s in stdin.readLine.split: yield s)
proc scan(): int = read().parseInt
proc toInt(c:char): int =
    return int(c) - int('0')



proc solve():int=
  var
    n = scan()
    a = newseqwith(n,scan())
    vcount = newseqwith(1E5.int+1,0)
  for av in a:
    vcount[av]+=1
  var
    odds = 0
    evens = 0
  for vc in vcount:
    if vc > 0:
      if vc mod 2 == 0:
        evens+=1
      else:
        odds += 1
  result = odds + (evens div 2) * 2



    

    
  
echo solve()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

res=Counter(arr)

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

Submission status: Runtime Error

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

import collections

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

dic = collections.defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

ls = collections.deque()
for i in dic.keys():
    if dic[i] > 1:
        ls.append(i)

ans = n
#n/2回ループ
for i in range(n//2):
    if len(ls) == 1 and dic[ls[0]] == 2:
        ans -= 2
        dic[ls[0]] -= 1
        break
    else:
        if len(ls) == 1:
            dic[ls[0]] -= 2
        else:
            dic[ls[0]] -= 1
            dic[ls[-1]] -= 1
        ans -= 2

    if len(ls) > 1:
        if dic[ls[-1]] <= 1:
            ls.pop()
    if dic[ls[0]] <= 1:
        ls.popleft()

    if len(ls) == 0:
        break
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

dic = collections.defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

ls = collections.deque()
for i in dic.keys():
    if dic[i] > 1:
        ls.append(i)

ans = n

for i in range(n//2):
    if max(dic.values()) == 1:
        break

    if len(ls) == 1 and dic[ls[0]] == 2:
        ans -= 2
        dic[ls[0]] -= 1
        break
    else:
        dic[ls[0]] -= 1
        dic[ls[-1]] -= 1
        ans -= 2

    if dic[ls[0]] <= 1:
        ls.popleft()
    if dic[ls[-1]] <= 1:
        ls.pop()

print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

dic = collections.defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

ls = collections.deque()
for i in dic.keys():
    if dic[i] > 1:
        ls.append(i)

ans = n

while max(dic.values()) > 1:
    #print(dic)
    if len(ls) == 1 and dic[ls[0]] == 2:
        ans -= 2
        dic[ls[0]] -= 1
        break
    else:
        dic[ls[0]] -= 1
        dic[ls[-1]] -= 1
        ans -= 2
    if len(ls) >= 1:
        if dic[ls[0]] <= 1:
            ls.popleft()
        if dic[ls[-1]] <= 1:
            ls.pop()
print(ans)

Submission status: Runtime Error

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

p = []
ans = 0
for k,v in c.items():
    ans += 1
    if v != 1:
        p.append([k,v])
p.sort()
lef = 0
rig = len(p)-1

while True:
    if lef == rig:
        if p[lef][1] % 2 == 1:
            print(ans)
            exit()
        elif p[lef][1] % 2 == 0:
            print(ans-1)
            exit()
    elif lef > rig:
        print(ans)
    p[lef][1] -= 1
    p[rig][1] -= 1
    if p[lef][1] == 1:
        lef += 1
    if p[rig][1] == 1:
        rig -= 1

Submission status: Runtime Error

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

p = []
ans = 0
for k,v in c.items():
    ans += 1
    if v != 1:
        p.append([k,v])
p.sort()
lef = 0
rig = len(p)-1

while True:
    p[lef][1] -= 1
    p[rig][1] -= 1
    if p[lef][1] == 1:
        lef += 1
    if p[rig][1] == 1:
        rig -= 1
    if lef == rig:
        if p[lef][1] % 2 == 1:
            print(ans)
            exit()
        elif p[lef][1] % 2 == 0:
            print(ans-1)
            exit()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

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

    AA = Counter(A)
    ans = 0
    val = 0
    for k, v in AA.items():
        if v % 2 == 0:
            ans += 1
        else:
            val += 1
    if ans % 2 !=0:
        ans -= 1
    print(val+ans)


resolve()

Submission status: Runtime Error

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

a.sort(reverse = True)

b = 1
ichi = 0
r = []
for i in range(n):
    if a[i] != a[i+1]:
        if b != 1:
            r.append(b)
        else:
            ichi += 1
        b = 1
    else:
        b += 1

for i in range(len(r)-1):
    if r[i] % 2 == 0:
        r[i] = 1
        r[i+1] -= 1
    else:
        r[i] = 1
        
if r[-1] % 2 == 0:
    print(ichi + len(r) - 1)
else:
    print(ichi + len(r))

Submission status: Runtime Error

Solution code:
N = int(input())
fq = [0] * (N + 10)
A = list(map(int, input().split()))
for a in A:
    fq[a] += 1
fq = [f if f % 1 == 0 else 1 for f in fq]
cnt_even = 0
cnt_odd = 0
for f in fq:
    if f & 1 == 0 and f != 0:
        cnt_even += 1
    if f & 1 == 1:
        cnt_odd += 1
if cnt_even & 1 == 0:
    print(cnt_even + cnt_odd)
else:
    print(cnt_even - 1 + cnt_odd)

Submission status: Runtime Error

Solution code:
N=int(input())

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

#重複した値だけを集めて消す

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

sets

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

duplicate %=2

print(set(A))-duplicate

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
A = [int(a) for a in sys.stdin.readline().split()]

dic = {}
for a in A:
  dic[a] = dic.get(a,0) + 1

evenodd = [0,0]
for k in dic:
  evenodd[dic[k]%2] += 1
if evenodd[0]%2==0:
  return len(dic)
else:
  return len(dic)-1

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
k = Counter(a)
b = list(k.values())
over_2 = [bb for bb in b if bb >= 2]
if sum(over_2) % 2 == 1:
    print(len(b))
else:
    if len(over_2 == 0):
        print(len(b))
    else:
        print(len(b) - 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

import heapq

def main():
    n = int(input())
    h = list(map(int, input().split()))
    heapq.heapify(h)
    accepted = [heapq.heappop(h)]
    while len(h) > 0:
        assert len(h) >= 2
        first = heapq.heappop(h)
        second = heapq.heappop(h)
        if accepted[-1] == first:
            del first
            del second
        elif first == second:
            if len(h) > 0:
                third = heapq.heappop(h)
                del first
                del third
                accepted.append(second)
            else:
                accepted.pop()
                accepted.append(first)
                del second
        else:
            accepted.append(first)
            accepted.append(second)

    print(len(accepted))

main()

Submission status: Runtime Error

Solution code:
from collections import deque
import copy

from math import *

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


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

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



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
use std::io::stdin;

fn main(){
    let x = geti64s()[0];
    let (d, m) = (x/11, x%11);
    println!("{}", match m {
        0         => d*2,
        x if x<=6 => d*2 + 1,
        _         => d*2 + 2
    });
}

#[allow(dead_code)]
fn getline() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn getvec() -> Vec<usize>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn geti64s() -> Vec<i64>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn getpair() -> (usize, usize){
    let nm = getvec();
    (nm[0], nm[1])
}

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
sn=[0]*n
mi2=0
mi=0
for i in range(0,n):
    if sn[a[i]]==1:
        mi2=1-mi2
    else:
        sn[a[i]]=1
        mi+=1
print(mi-mi2)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
b=[a[0]]
def f(i):
 if i>n-1:
   print(len(b))
   return 0
 if a[i]!=b[-1]:
   b.append(a[i])
   f(i+1)
 else:
   f(i+2)
f(1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
b=[a[0]]
def f(i):
 if i==n:
   print(len(b))
   return 0
 if a[i]!=b[-1]:
   b.append(a[i])
   f(i+1)
 else:
   f(i+2)
f(1)

Submission status: Runtime Error

Solution code:
def main():
    N = int(raw_input())
    x = map(int, raw_input().split())
    #-1:remove , 0:singe , 1~:label 
    check= [0] * N
    flag = False
    label = 1
    c = 0
    x.sort()

    #labeling
    for i in range(N):
        for j in range(N):
            if(i != j):
                if(x[i] == x[j]):
                    flag = True
        if flag:
            if i > 0:
                if(x[i] != x[i-1]):
                    label += 1
                    check[i] = label
                else:
                    check[i] = label
            else:
                check[i] = label
        flag = False
    
    #removing
    for i in range(N-1):
        if(check[i] > 0 and check[i+1] == check[i]):
            for j in range(N):
                if(check[i] != check[j] and check[j] > 0 and flag == False):
                     check[i] = -1
                     check[j] = -1
                     if j < N-2:
                         check[j+1] != check[j+2]
                         check[j+1] = 0
                     else:
                         check[j+1] = 0
                     flag = True
            if flag == False:     
                check[check.index(0)] = -1
                check[i] = -1
            else:
                flag = False
        elif check[i] != -1:
            check[i] = 0
    for i in range(N):
        if check[i] == 0:
            c += 1
    return c
print main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 0
e = 0
i = 0
while i < len(a):
    c += 1
    cai = 1
    while a[i] == a[i + 1]:
        cai += 1
        i += 1
    if cai % 2 == 0:
        e += 1
    i += 1
ans = c - (e % 2)
print(ans)