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:

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
    for k in c_cards:
        if c_cards[k] > 1:
            n -= c_cards[k] - 1
            if credit > 0:
                credit = abs(credit - (c_cards[k] - 1))
            else:
                credit += c_cards[k] - 1
            # print(k, credit)
    if credit > 0:
        n -= credit
    print(n)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 2 in cnt.values():
    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: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    d[a] += 1
print(len(d.keys()) - sum([v % 2 for v in d.values()]) % 2)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def comp(n,s,a):
  cnt=1
  flag=s[0]
  for i in range(1,n):
    if flag==s[i]:cnt+=1
    else:
      flag=s[i]
      a+=[cnt]
      cnt=1
  a+=[cnt]
  return a
n=int(input())
a=sorted(list(map(int,input().split())))
b=comp(n,a,[])
l,r=0,len(b)-1
if l==r:b[0]=1
while l<r:
  while b[l]==1 and l<r:l+=1
  while b[r]==1 and l<r:r-=1
  b[l]-=1
  b[r]-=1
while b[l]>1:b[l]-=2
print(sum(b))

Submission status: Wrong Answer

Solution code:
def comp(n,s,a):
  cnt=1
  flag=s[0]
  for i in range(1,n):
    if flag==s[i]:cnt+=1
    else:
      flag=s[i]
      a+=[cnt]
      cnt=1
  a+=[cnt]
  return a
n=int(input())
a=sorted(list(map(int,input().split())))
b=comp(n,a,[])
l,r=0,len(b)-1
while l<r:
  while b[l]==1 and l<r:l+=1
  while b[r]==1 and l<r:r-=1
  b[l]-=1
  b[r]-=1
print(sum(b))

Submission status: Wrong Answer

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

diff_len_arrays = len(array) - len(list(set_array))
print(len(array) - math.ceil(diff_len_arrays / 2)*2)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    ac = Counter(a)
    acl = ac.values()
    r = len(acl)
    t = (sum(ac.keys()) - r)&1
    r -= t ^ 1
    print(r)
  

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# N = 15
# ARR = [1, 3, 5, 2, 1, 3, 2, 8, 8, 6, 2, 6, 11, 1, 1]

# N = 5
# ARR = [1, 2, 1, 3, 7]

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

def calculate(n, arr):
    dict = {}
    for i in range(n):
        if dict.get(arr[i]) == None:
            dict.__setitem__(arr[i], 1)
        else:
            tmp = dict.get(arr[i])
            dict.__setitem__(arr[i], tmp + 1)

    values = dict.values()

    item = []
    for val in values:
        if val == 1:
            continue
        if val > 1:
            item.append(val - 1)

    sumItems = []

    for i in range(2**len(item)):
        tmpSum = 0
        for j in range(len(item)):
            a = (i >> j & 1)
            if a == 0:
                #-
                tmpSum -= item[j]
                continue
            else:
                #+
                tmpSum += item[j]
                continue

        sumItems.append(abs(tmpSum))

    print(len(values) - min(sumItems))


calculate(N, ARR)

Submission status: Wrong Answer

Solution code:
N = 15
ARR = [1, 3, 5, 2, 1, 3, 2, 8, 8, 6, 2, 6, 11, 1, 1]

N = 5
ARR = [1, 2, 1, 3, 7]

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

def calculate(n, arr):
    dict = {}
    for i in range(n):
        if dict.get(arr[i]) == None:
            dict.__setitem__(arr[i], 1)
        else:
            tmp = dict.get(arr[i])
            dict.__setitem__(arr[i], tmp + 1)

    values = dict.values()

    item = []
    for val in values:
        if val == 1:
            continue
        if val > 1:
            item.append(val - 1)

    item = sorted(item, reverse=True)

    sumItems = []

    for i in range(2**len(item)):
        tmpSum = 0
        for j in range(len(item)):
            a = (i >> j & 1)

            if a == 0:
                #-
                tmpSum -= item[j]
                continue
            else:
                #+
                tmpSum += item[j]
                continue

        sumItems.append(abs(tmpSum))

    print(len(values) - min(sumItems))


calculate(N, ARR)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=sorted(map(int,input().split()))
li=[]
i=0
while(i<N):
    cnt=0
    j=i
    while(j<N and A[i]==A[j]):
        cnt+=1
        j+=1
    li.append(cnt-1)
    i=j
l=len(li)
for i in range(l):
    for j in range(i+2,l):
        if li[i]==0:
            break
        d=min(li[i],li[j])
        li[i]-=d
        li[j]-=d
for i in range(l):
    li[i]%=2
ans=len(set(A))
for i in range(l):
    ans-=li[i]
print(ans)

Submission status: Wrong Answer

Solution code:
#D
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
most = c.most_common()
ans = len(most)
eaten = 0
for t in most:
    if t[1] != 1:
        eaten += t[1]-1
if eaten%2 == 1:
    print(ans-2)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
#D
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
most = c.most_common()
ans = len(most)
eaten = 0
for t in most:
    if t[1] != 1:
        eaten += t[1]-1
if eaten%3 == 1:
    print(ans-1)
elif eaten%3 == 2:
    print(ans)
else:
    print(ans-2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
count = Counter(A)
L = list(count.values())
L.sort(reverse = True)
cnt = 0
for i in L:
    cnt = min(abs(cnt + (i - 1)), abs(cnt - (i - 1)))
ans = len(L) - cnt
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=[0]*(10**5+1)
sa=set(a)
for i in a:
  d[i]+=1
for j in range(len(d)):
  if d[j]>2 and d[j]%2==0:
    d[j]=2
  elif d[j]>2 and d[j]%2!=0:
    d[j]=1
iti=d.count(1)
dsum=sum(d)-iti
if dsum%2==0:
  print(len(sa))
else:
  print(len(sa)-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
sa=set(a)
count=0
while len(sa)!=len(a):
  count+=1
  ma=max(a[:3])
  mi=min(a[:3])
  saidai=0
  saisyou=0
  for i in range(3):
    if ma==a[i]:
      saidai=i
    elif saisyou==a[i]:
      saisyou=i
  a.pop(saidai)
  a.pop(saisyou)
  sa=set(a)
print(n-count*2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
sa=set(a)
count=0
while len(sa)!=len(a):
  count+=1
  ma=max(a[:3])
  mi=min(a[:3])
  saidai=0
  saisyou=0
  for i in range(3):
    if ma==a[i]:
      saidai=i
    elif saisyou==a[i]:
      saisyou=i
  a.pop(saidai)
  a.pop(saisyou)
  sa=set(a)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [int(e) for e in input().split()]
checker = nums[0]
nums.sort()
count = 1
for i in range(1,N):
    if(checker != nums[i]):
        count+=1
        checker = nums[i]
if(N - count)%2==0:
    print(count)
else:
    print(count-1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
s = len(set(A))
if s % 2 == 0:
    print(s)
else:
    print(s-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
lis = [0] * (max(a) + 1)
for i in a:
    lis[i] += 1
cnt = lis.count(1)
ans = len(set(a))
if cnt % 2 == 0:
    print(ans)
else:
    print(ans - 1)

Submission status: Wrong Answer

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] * 100001
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: Wrong Answer

Solution code:
import collections
n = int(input())
a = sorted(list(map(int,input().split())))
b = set(a)
c = collections.Counter(a)
d = []
for i in b:
    if c[i]>3:d.append(-(-c[i]//3))
    else: d.append(c[i])
ans = len(b)
if d.count(2)%2==1:ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=Counter(map(int,input().split()))
a=sorted(a.items(),key=lambda x:x[0])
l=len(a)

a=[1 if a[i][1]%2==1 else 2 for i in range(l)]
id=[i for i in range(l) if a[i]==2]
l=len(id)

cnt=0
for i in range(l-1):
    if id[i]+1==id[i+1]:
        cnt+=1
if cnt==1:
    ans=sum(a)-4
else:
    if l%2==0:
        ans=sum(a)-l
    else:
        ans=sum(a)-l-1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter
N = int(input())
A = Counter(map(int, input().split()))
ans = 0
left = 0
for k, v in sorted(A.items(), key=itemgetter(1))[::-1]:
    print(k, v, left, ans)
    if left == 1:
        if v == 1:
            ans += 1
            left = 0
            continue
        else:
            v -= 1
            ans += 1
            left = 0
    if v > 3:
        v = v%2 + 2

    if v == 1:
        ans += 1
    elif v == 2:
        left += 1
    elif v == 3:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter
N = int(input())
A = Counter(map(int, input().split()))
ans = 0
left = 0
for k, v in sorted(A.items(), key=itemgetter(1))[::-1]:
    #print(k, v, left, ans)
    if left == 1:
        if v == 1:
            ans += 1
            left = 0
            continue
        else:
            v -= 1
            ans += 1
            left = 0

    if v >= 3:
        v = v%2 + 2
    if v == 1:
        ans += 1
    elif v == 2:
        left += 1
    elif v == 3:
        ans += 1
if left == 1:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

import collections
ac = collections.Counter(a)

c_num = []
c = 0
for num, count in ac.items():
  if count > 1:
    c += count
    c_num.append(num)

u_len = len(set(ac.elements()))
if c % 2 == 0:
  print(u_len - 1)
else:
  print(u_len)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=set(map(int,input().split()))
k=len(a)
#少なくともn-k枚減らす
if n-k % 2 == 0:
  print(k)
else:
  print(k-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)

for i in a:
    d[i] += 1
cnt = 0
ans = 0
for k, v in d.items():
    if v != 1:
        cnt += v - 1
    ans += 1

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)

for i in a:
    d[i] += 1
cnt = 0
ans = 0
for k, v in d.items():
    if v != 1:
        cnt += v
    ans += 1

if cnt == 0:
    print(ans - 2)
elif cnt == 1:
    print(ans - 1)
elif ans % 2 == 0 and cnt % 2 == 0:
    print(ans - 1)
elif ans % 2 == 0 and cnt % 2 != 0:
    print(ans)
elif ans % 2 != 0 and cnt % 2 == 0:
    print(ans - 1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)

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

cnt = 0
ans = 0
for k, v in d.items():
    if v != 1:
        cnt += v
    ans += 1

if cnt != 0 and cnt % 2 == 0:
    print(ans - 1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)

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

cnt = 0
ans = 0
for k, v in d.items():
    if v != 1:
        cnt += v
    ans += 1

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

A_cnt = Counter(A)
tmp = 0
for x in A_cnt.values():
	if x >= 2:
		tmp += x
print(len(A_cnt)-1 if tmp % 2 == 0 else len(A_cnt))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(cntA) == 1:
    print(1)
    exit()

remained = 0
removed_num = 0
for key in cntA:
    if cntA[key] == 1:
        continue
    else:
        removed_num += 2 * min(remained, cntA[key] - 1)
        remained = abs(remained - cntA[key] + 1)

print(N - removed_num - 2 * remained)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N =int(input())
cntA = Counter(map(int, input().split()))
remained = 0
removed_num = 0
for key in cntA:
    if cntA[key] == 1:
        continue
    else:
        removed_num += 2 * min(remained, cntA[key] - 1)
        remained = abs(remained - cntA[key] + 1)

print(N - removed_num - 2 * remained)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
A.sort()
from collections import Counter
c=Counter(A).items()
cnt=0
flg=False
for key,val in c:
    if key%2==1:
        cnt+=1
    else:
        if flg:
            cnt+=2
            flg=False
        else:
            flg=True
if flg:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

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

n2 = 0
for k in D:
    D[k] = 2 if D[k]%2==0 else 1
    if D[k]==2: n2+=1

print(len(D) + n2%2)

Submission status: Wrong Answer

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

A_set = set(A)

if len(A) - len(A_set) == 1:
    ans = len(A_set) -1
else:
    ans = len(A_set)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

A = list(map(int, input().split()))
if len(A)==3:
  print(1)
elif len(A)-len(set(A))%2==1:
  print(len(set(A))-1)
else:
  print(len(set(A)))

Submission status: Wrong Answer

Solution code:
N=int(input())

A = list(map(int, input().split()))
if len(A)-len(set(A))%2==1:
  print(len(set(A))-1)
else:
  print(len(set(A)))

Submission status: Wrong Answer

Solution code:
N=int(input())

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

Submission status: Wrong Answer

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

a.sort()

dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

cnt = 0
cnt2 = 0
for k in dic:
    if dic[k] >= 4:
        cnt += 2
        dic[k] = 2
        cnt2 += 1
    elif dic[k] == 3:
        cnt += 1
        dic[k] = 1
    elif dic[k] == 2:
        cnt += 2
        cnt2 += 1
    else:
        cnt += 1
        
ans = cnt - cnt2 - cnt2%2

print(ans)

Submission status: Wrong Answer

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

a.sort()

dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1
print(dic)
cnt = 0
cnt2 = 0
for k in dic:
    if dic[k] >= 4:
        cnt += 2
        dic[k] = 2
        cnt2 += 1
    elif dic[k] == 3:
        cnt += 1
        dic[k] = 1
    elif dic[k] == 2:
        cnt += 2
        cnt2 += 1
    else:
        cnt += 1
        
ans = cnt - cnt2 - cnt2%2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

C = Counter(A).most_common()
# print(C)

double = 0
for c in C:
	num, cnt = c
	if cnt % 3 == 2 or (cnt > 3 and cnt % 3 == 1):
		double += 1

if double % 2:
	print(len(C)-1)
else:
	print(len(C))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

C = Counter(A).most_common()
#print(C)

for i, c in enumerate(C):
	num, cnt = c
	if cnt >= 3:
		cnt = (cnt//3) + (cnt%3)
		C[i] = [num, cnt]
	if cnt >= 2 and i < len(C)-1:
		nnum, ncnt = C[i+1]
		if ncnt >= 2:
			dif = min(cnt-1, ncnt-1)
			cnt -= dif
			ncnt -= dif
		C[i] = [num, cnt]
		C[i+1] = [nnum, ncnt]
	# print("i:{}, C:{}".format(i,C))

#print(C)

doubled = 0
for c in C:
	num, cnt = c
	if cnt == 2:
		doubled += 1

ans = len(C)-(doubled%2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

C = Counter(A).most_common()
#print(C)

for i, c in enumerate(C):
	num, cnt = c
	if cnt >= 3:
		cnt = (cnt//3) + (cnt%3)
		C[i] = [num, cnt]
	if cnt >= 2 and i < len(C)-1:
		nnum, ncnt = C[i+1]
		if ncnt >= 2:
			dif = min(cnt-1, ncnt-1)
			cnt -= dif
			ncnt -= dif
		C[i] = [num, cnt]
		C[i+1] = [nnum, ncnt]
	# print("i:{}, C:{}".format(i,C))

#print(C)

dropped = 0
doubled = 0
for c in C:
	num, cnt = c
	if cnt == 0: dropped += 1
	if cnt == 2: doubled += 1

ans = len(C)-dropped-doubled
print(ans)

Submission status: Wrong Answer

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

def solve(N: int, A: "List[int]"):
    A.sort()
    count = dict(Counter(A))
    left = 0
    right = N-1
    sole_list = []

    while right-left > 2:
        if count[A[right]]>=2 and count[A[left]]>=2:
            count[A[right]]-=1
            count[A[left]]-=1
            right -= 1
            left += 1
            continue
        
        if count[A[right]]==1:
            sole_list.append(A[right])
            right-=1

        if count[A[left]]==1:
            sole_list.append(A[left])
            left+=1     

    res = sole_list[left:right+1]
    a = len(sole_list)
    if right-left == 2:
        if len(set(res)) == 2:
            print(a+1)
        else:
            print(a+len(set(res)))
        return 
    else:
        if len(set(res)) == 1:
            print(a)
        else:
            print(a+2)
        return 
        
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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])
if cnt == 0:
  print(N)
  exit()
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: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = {}
X =[]
for i in range(N):
    x = A[i]
    if x not in d:
        d[x] = 1
        X.append(x)
    else:
        d[x] += 1
ans = 0
for x in X:
    a = d[x]
    if a%2 == 0:
        ans += a//2 - 1
    else:
        ans += a//2
        X.remove(x)
n = len(X)
ans += ((n+1)//2)*2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = {}
X =[]
for i in range(N):
    x = A[i]
    if x not in d:
        d[x] = 1
        X.append(x)
    else:
        d[x] += 1
ans = 0
for x in X:
    a = d[x]
    if a%2 == 0:
        ans += a//2 - 1
    else:
        ans += a//2
        X.remove(x)
n = len(X)
ans += (n+1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import bisect

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

dups = []
not_dups = []
ans = 0
for key, num in Counter(A).items():
  if num%3 in [0,1]: not_dups.append(key)
  else: dups.append(key)

dups.sort()
not_dups.sort()
    
i_min = bisect.bisect(dups, not_dups[0])
i_max = bisect.bisect(dups, not_dups[-1])
print(i_max-i_min+len(not_dups))
#print(i_min, i_max, dups, not_dups)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import bisect

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

dups = []
not_dups = []
ans = 0
for key, num in Counter(A).items():
  if num == 2: dups.append(key)
  else: not_dups.append(key)

dups.sort()
not_dups.sort()
    
i_min = bisect.bisect(dups, not_dups[0])
i_max = bisect.bisect(dups, not_dups[-1])
print(i_max-i_min+len(not_dups))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

surplus = 0
keys = list(d.keys())
sorted(keys)
for i, k in enumerate(keys):
    c = d[k]
    if c <= 1:
        continue
    while c >= 3:
        c -= 2
    d[k] = c
    if c == 2:
        d[k] -= 1
        if i < len(keys) - 1:
            d[keys[i + 1]] -= 1
        else:
            d[keys[i - 1]] -= 1
ans = sum(d.values())
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
T = [int(i) for i in input().split()]
L = [0 for i in range(max(T))]
#print(T)
for i in range(n):
  L[T[i]-1] += 1
#print(L)
for i in range(len(L)):
  if L[i] >= 3:
    L[i] = L[i]%3 + 1

#print(L)
counttwo = L.count(2)
countone = L.count(1)



out = (counttwo//2)*2 + countone
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
i=len(a)
s=set(a)
j=len(s)

if (i-j)%2==0:
  print((i-j)//2)
else:
  print((i-j)//2+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
i=len(a)
s=set(a)
j=len(s)

print((i-j)//2)

Submission status: Wrong Answer

Solution code:
import collections

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])
        
y=len(b)

if x%2==1 or x==0:
    print(y)

else:
    print(y-1)

Submission status: Wrong Answer

Solution code:
from collections import*
n,*a=map(int,open(0).read().split())


amaricard=n-sum([v-1 for k,v in Counter(a).items() if v>1 and (v-3)%2==0])
amari=[v-1 for k,v in Counter(a).items() if v>1 and (v-3)%2!=0]

if len(amari)==0:
    print(n)
else:
    print(amaricard-sum(amari)-len(amari)%2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = map(int,input().split())
c = Counter(A)

lst = []
for k,v in c.items():
    lst.append([k,v-1])
lst.sort(key = lambda x:x[1] , reverse = True)

n = len(lst)
if n==1:
    print(1)
    exit()
    
tmp = 0
for i in range(n):
    if tmp == 0:
        tmp += lst[i][1]
    else:
        tmp = abs(tmp - lst[i][1])
    
print(n if tmp == 0 else n-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = map(int,input().split())
c = Counter(A)

lst = []
for k,v in c.items():
    lst.append([k,v-1])
lst.sort(key = lambda x:x[1] , reverse = True)

n = len(lst)
if n==1:
    print(1)
    exit()

tmp = 0
for i in range(n):
    if tmp <= 0:
        tmp += lst[i][1]
    else:
        tmp -= lst[i][1]
print(n if tmp == 0 else n-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = map(int,input().split())
c = Counter(A)

lst = []
for k,v in c.items():
    lst.append([k,v-1])

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

n = len(lst)
tmp = 0
for i in range(n):
    if tmp <= 0:
        tmp += lst[i][1]
    else:
        tmp -= lst[i][1]
print(n if tmp == 0 else n-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l)
ans=0 

#ans=l.count(1)
#l=[i for i in l if i>1]
c=Counter(l)
for i in c:
    if c[i]==1:
        ans+=1 
       # del c[i]
l=[c[i] for i in c ]
#print(ans)
#print(c)
if l.count(2)==1 and l.count(1)==len(l)-1:
    print(len(l)-1)
else:
    print(len(l))
exit()    
tw=0 
th=0 
for i in l: 
    if i&1:
        th+=1 
    else:
        tw+=1 
#print(tw,th)
ans+=(tw//2)*2 
tw%=2
ans+=(tw//2)

tw%=2 
ans+=(th//2)
th%=2 
if tw and th:
    ans+=1 
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l)
ans=0 

#ans=l.count(1)
#l=[i for i in l if i>1]
c=Counter(l)
for i in c:
    if c[i]==1:
        ans+=1 
       # del c[i]
l=[c[i] for i in c if c[i]>1]
tw=0 
th=0 
for i in l: 
    if i&1:
        th+=1 
    else:
        tw+=1 
ans+=(tw//2)
tw%=2 
ans+=(th//2)
th%=2 
if tw and th:
    ans+=1 
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def solve(N: int, A: "List[int]"):
    from collections import Counter
    c = Counter(A)

    # for k,v in c.items():
    #     print(k,v)
    m = sum([v for v in c.values()]) - len([c for c in c.keys()])
    if(m%3 == 0 or m%3 == 2):
        print(len(c.keys()))
    elif(m%3 == 1):
        print(len(c.keys())-1)
    # else:
    #     print(len(c.keys())-1)
    # print(m)
    return


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
list_a = list(map(int, input().split(" ")))
count = collections.Counter(list_a)

min_key = 10 ** 5 + 1
max_key = 0
count_even = 0
for key, value in sorted(count.items()):
  if value % 2 == 0:
    count_even += 1
    if key < min_key:
      min_key = key
    if key > max_key:
      max_key = key
      
between = False
for key, value in sorted(count.items()):
  if value % 2 != 0:
    if min_key < key < max_key:
      between = True
      
if count_even % 2 == 1:
  print(len(count) - 1)
else:
  if between:
    print(len(count))
  else:
    print(len(count) - 1)