Problem:


Score : 400 points

Problem Statement

Snuke has decided to play a game using cards.
He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written.

He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept.

Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.

Constraints

3 ≦ N ≦ 10^{5}

N is odd.

1 ≦ A_i ≦ 10^{5}

A_i is an integer.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 A_3 ... A_{N}

Output

Print the answer.

Sample Input 1

5
1 2 1 3 7

Sample Output 1

3

One optimal solution is to perform the operation once, taking out two cards with 1 and one card with 2. One card with 1 and another with 2 will be eaten, and the remaining card with 1 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 1, 3 and 7.

Sample Input 2

15
1 3 5 2 1 3 2 8 8 6 2 6 11 1 1

Sample Output 2

7



Sample input:
5
1 2 1 3 7


Sample output:
3

Submission status: Wrong Answer

Solution code:
N = int(input())
A = 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 < len(memo)-1:
                memo[key+1][1] -= 1
            memo[key][1] = 1
ans = 0
for a,b in memo:
    ans += b
print(ans)

Submission status: Wrong Answer

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

a_cnt = Counter(a)

a_cnt_num = list(a_cnt.values())

for i in range(len(a_cnt_num)):
    a_cnt_num[i] = - a_cnt_num[i]

heapq.heapify(a_cnt_num)

max_num = -heapq.heappop(a_cnt_num)-1

while True:
    if len(a_cnt_num) == 0:
        break
    next_num = -heapq.heappop(a_cnt_num)-1
    if next_num == 0:
        break
    max_num = abs(max_num-next_num)

print(max(len(a_cnt)-max_num,0))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
ans, count, val = 0, 1, 0

for i in range(len(a)-1):
    if a[i] == a[i+1]:
        count += 1
    else:
        if count == 1:
            ans += 1
        else:
            ans += 1
            val += count-1
            count = 1

if count != 1:
    val += count-1
ans += 1
    
if val%2 != 0 and val > 2:
    ans += 1
elif val%2 != 0:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

for i in set(a):
    num = a.count(i)
    if num > 1:
        count += num-1
    ans += 1
if count%2 != 0 and count > 2:
    ans += 1
elif count%2 != 0:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
ac = Counter(A)

ans = 0
td = dict()
for k, v in ac.items():
    if v % 2 == 0:
        td[k] = 2
    else:
        td[k] = 1

ans = 0
two = 0
for k, v in td.items():
    if v == 1:
        ans += 1
    else:
        two += 1

if two % 2 == 0:
    ans += two
else:
    two -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    # print(cnt)
    # 同じ数字3枚引いて1, 2枚になるまで減らす
    for i in cnt.keys():
        if cnt[i] % 2 == 0:
            cnt[i] = 2
        else:
            cnt[i] = 1

    ans = 0
    even_num = [i for i in cnt.keys() if cnt[i] == 2]
    # 2枚の数字の種類が3以上の奇数ならば、1種類まで減らせる
    # 2枚の数字の種類が4以上の偶数ならば、0種類まで減らせる(残り4種類は互い違いに食べる)
    if len(even_num) % 2 == 0:
        ans = len(cnt)
    else:
        if len(even_num) == 1: 
            ans = len(cnt) - 1
        else:
            ans = len(cnt)

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    # print(cnt)
    # 同じ数字3枚引いて1, 2枚になるまで減らす
    for i in cnt.keys():
        if cnt[i] % 2 == 0:
            cnt[i] = 2
        else:
            cnt[i] = 1

    ans = 0
    even_num = [i for i in cnt.keys() if cnt[i] == 2]
    # 2枚の数字の種類が3以上の奇数ならば、1種類まで減らせる
    # 2枚の数字の種類が4以上の偶数ならば、0種類まで減らせる(残り4種類は互い違いに食べる)
    if len(even_num) % 2 == 0:
        if len(even_num) == 2 and len([i for i in cnt.keys() if min(even_num) < i < max(even_num)]) == 0:
            # 間に別の数字が無ければその2種類から3つ引く
            ans = len(cnt)
        else:
            ans = len(cnt)
    else:
        if len(even_num) == 1: 
            ans = len(cnt) - 1
        else:
            ans = len(cnt)

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    # print(cnt)
    # 同じ数字3枚引いて1, 2枚になるまで減らす
    for i in cnt.keys():
        if cnt[i] % 2 == 0:
            cnt[i] = 2
        else:
            cnt[i] = 1

    ans = 0
    even_num = [i for i in cnt.keys() if cnt[i] == 2]
    # 2枚の数字の種類が3以上の奇数ならば、1種類まで減らせる
    # 2枚の数字の種類が4以上の偶数ならば、0種類まで減らせる(残り4種類は互い違いに食べる)
    if len(even_num) % 2 == 0:
        if len(even_num) == 2 and len([i for i in cnt.keys() if min(even_num) < i < max(even_num)]) == 0:
            # 間に別の数字が無ければその2種類から3つ引く
            ans = len(cnt) - 1
        else:
            ans = len(cnt)
    else:
        if len(even_num) == 1: 
            ans = len(cnt) - 1
        else:
            ans = len(cnt)

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    # print(cnt)
    # 奇数枚ある数字は、その数字を3枚引くことで1枚にできる
    # 偶数枚ある数字は、その数字を3枚引くことで2枚にできる
    # 2枚ある数字2つは、間に別の数字があれば1枚にできる
    # for i in cnt.keys():
    #     if cnt[i] % 2 == 0:
    #         print(i, 2)
    #     else:
    #         print(i, 1)
    print(len(cnt))

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

    seq = []
    pre = -1
    now = -1
    for i in range(N):
        if pre != A[i]:
            seq.append(1)
            now += 1
        if i < N - 1 and A[i] == A[i+1]:
            seq[now] += 1
        pre = A[i]
    
    left = 0
    right = now
    ans = N
    while left < right:
        while seq[left] <= 1 and left < right:
            left += 1
    
        while seq[right] <= 1 and right > left:
            right -= 1
        
        if left == right:
            if seq[left] > 1:
                ans -= 2
        
        elif right - left == 1:
            seq[right] -= 1
            seq[left] -= 1
            ans -= 3
        
        else:
            seq[right] -= 1
            seq[left] -= 1
            ans -= 2
    
        
    print(ans)
            
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    seq = []
    pre = -1
    now = -1
    for i in range(N):
        if pre != A[i]:
            seq.append(1)
            now += 1
        if i < N - 1 and A[i] == A[i+1]:
            seq[now] += 1
        pre = A[i]
    
    left = 0
    right = now
    ans = N
    while left < right:
        while seq[left] <= 1 and left < right:
            left += 1
    
        while seq[right] <= 1 and right > left:
            right -= 1
        
        if left == right:
            if seq[left] > 1:
                ans -= 2
        
        elif right - left == 1:
            if seq[right] > seq[left]:
                seq[right] -= 2
                seq[left] -= 1
            else:
                seq[right] -= 1
                seq[left] -= 2
            ans -= 3
        
        else:
            seq[right] -= 1
            seq[left] -= 1
            ans -= 2
    
        
    print(ans)
            
        
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    seq = []
    pre = -1
    now = -1
    for i in range(N):
        if pre != A[i]:
            seq.append(1)
            now += 1
        if i < N - 1 and A[i] == A[i+1]:
            seq[now] += 1
        pre = A[i]
    
    left = 0
    right = now
    ans = N
    while left < right:
        while seq[left] <= 1 and left < right:
            left += 1
        seq[left] -= 1
    
        while seq[right] <= 1 and right > left:
            right -= 1
        seq[right] -= 1
        

        if right - left == 1:
            if seq[left] > seq[right]:
                seq[left] -= 1
            else:
                seq[right] -= 1

            ans -= 3
        
        elif right - left > 1 or seq[left] >= 0 or seq[right] >= 0:
            ans -= 2
        
    print(ans)
            





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections as col

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

m = col.Counter(A)
cnt = 0
for k in m:
    if m[k] >= 3:
        while m[k] > 2:
            m[k] = (m[k]+1) // 2

tcnt = 0
for k in m:
    if m[k] == 2:
        tcnt += 1

ans = len(m) if tcnt%2==0 else len(m)-1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections as col

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

m = col.Counter(A)
cnt = 0
for k in m:
    if m[k] >= 3:
        while m[k] > 2:
            m[k] //= 2

tcnt = 0
for k in m:
    if m[k] == 2:
        tcnt += 1

ans = len(m) if tcnt%2==0 else len(m)-1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

dic = Counter(A)
unique = len(dic)

max_cnt = 0
sum_cnt = 0

for v in dic.values():
    if v%2 == 0 or v == 1:
        sum_cnt += v-1
        if max_cnt<v-1:
            max_cnt = v-1
# print(max_cnt, sum_cnt)
print(unique-max(0, max_cnt*2-sum_cnt))

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque,Counter
    N = int(input())
    A = list(map(int,input().split()))
    # countA = [0] * (10**5+1)
    # pairA = []
    # deck = deque()
    # for a in A:
    #     countA[a] += 1
    # for i,a in enumerate(countA):
    #     pairA.append((a,i))
    # pairA.sort(reverse=True)
    # for i,a in enumerate(pairA):
    #     deck.a
    ans = 0
    countA = Counter(A)
    pairA = deque()
    ans = 0
    num2 = 0
    num1 = 0
    num3more = 0
    for k,v in countA.items():
        if v == 2:
            num2 += 1
        else:
            num1 += 1
            num3more += v-1

    print(num1,num2,num3more)

    if num2 >= num3more:
        num2 -= num3more
        num1 += num2 //2 + num3more
    else:
        num1 += num2
        # num3more -= num2

        # num3more = (num3more-1)//2+1
        # num1 -= 1
    print(num1)



        
    




main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque,Counter
    N = int(input())
    A = list(map(int,input().split()))
    # countA = [0] * (10**5+1)
    # pairA = []
    # deck = deque()
    # for a in A:
    #     countA[a] += 1
    # for i,a in enumerate(countA):
    #     pairA.append((a,i))
    # pairA.sort(reverse=True)
    # for i,a in enumerate(pairA):
    #     deck.a
    ans = 0
    countA = Counter(A)
    pairA = deque()
    ans = 0
    num2 = 0
    num1 = 0
    num3more = 0
    for k,v in countA.items():
        if 3 <= v:
            num1 += 1
            num2 += 1
            num3more += v-3
        elif v == 1:
            num1 += 1
        elif v == 2:
            num2 += 1
    # print(num1,num2,num3more)
    # print(num2,num3more)
    if num2 >= num3more:
        num2 -= num3more
        num1 += num2 //2 + num3more
    else:
        num1 += num2
        num1 -= 1
    print(num1)



        
    




main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import deque,Counter
    N = int(input())
    A = list(map(int,input().split()))
    # countA = [0] * (10**5+1)
    # pairA = []
    # deck = deque()
    # for a in A:
    #     countA[a] += 1
    # for i,a in enumerate(countA):
    #     pairA.append((a,i))
    # pairA.sort(reverse=True)
    # for i,a in enumerate(pairA):
    #     deck.a
    ans = 0
    countA = Counter(A)
    pairA = deque()
    ans = 0
    num2 = 0
    num1 = 0
    num3more = 0
    for k,v in countA.items():
        if 3 <= v:
            num1 += 1
            num2 += 1
            num3more += v-3
        elif v == 1:
            num1 += 1
        elif v == 2:
            num2 += 1
    # print(num1,num2,num3more)
    # print(num2,num3more)
    if num2 >= num3more:
        num2 -= num3more
        num1 += num2 //2 + num3more
    else:
        num1 += num2
    print(num1)



        
    




main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
L = sorted(set(a))
cnt = 0
l = 0
r = len(L) - 1
while True:
    while c[L[l]] == 1:
        l += 1
        if l == len(L) - 1:
            break
    while c[L[r]] == 1:
        r -= 1
        if r == 0:
            break
    if r - l > 1:
        c[L[l]] -= 1
        c[L[r]] -= 1
        cnt += 1
    else:
        if l == r:
            amari = c[L[l]]
        else:
            amari = c[L[l]] + c[L[r]]
        while amari > 1:
            amari -= 2
            cnt += 1
        break
print(n - cnt * 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
L = sorted(set(a))
cnt = 0
l = 0
r = len(L) - 1
while True:
    while c[L[l]] == 1:
        l += 1
        if l == len(L) - 1:
            break
    while c[L[r]] == 1:
        r -= 1
        if r == 0:
            break
    if r - l > 1:
        c[L[l]] -= 1
        c[L[r]] -= 1
        cnt += 1
    else:
        if l == r:
            amari = c[L[l]]
        else:
            amari = c[L[l]] + c[L[r]]
        cnt += max(0, amari - 2) // 2 + 1
        if (amari - 2) // 2:
            n -= 1
        break
print(n - cnt * 2)

Submission status: Wrong Answer

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

cnt = [[num, a.count(num)] for num in set(a)]

var = 0
total = 0

for num, count in cnt:
    if count > 1:
        var += 1
        total += count

ans = len(cnt) - var
ans += var if total % 2 == 1 else var - 1
print(ans)

Submission status: Wrong Answer

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

cnt = [[num, a.count(num)] for num in set(a)]
k = len(cnt)

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

Submission status: Wrong Answer

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

cnt = [[num, a.count(num)] for num in set(a)]

var = 0
total = 0

for num, count in cnt:
    if count > 1:
        var += 1
        total += count

ans = len(cnt) - var
ans += var - 1
ans += 0 if total % 2 == 0 else 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
a_list = [1,3,3,3,6,6,7,10]
bisect.bisect_left(a_list,4) # -> 4

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

al.sort()
cnt = []
tmp = 1
for i in range(1,len(al)):
    if al[i] == al[i-1]:
        tmp += 1
    else:
        cnt.append(tmp)
        tmp = 1

cnt.append(tmp)
print(len(cnt))
# front = 0
# back = len(cnt)-1

# end_flag = False
# while True:
#     while al[front] <= 1:
#         front += 1
#         if front >= len(cnt):
#             end_flag = True
#             break

#     while al[back] <= 1:
#         back -= 1
#         if back < 0:
#             end_flag = True
#             break

#     if front > back:
#         break
#     elif front == back:
#         al[front] = 1


#     while al[back] <= 1:
#         back -= 1
#     if al[back] > 1:
#         al[back] -= 1

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
import math
c = Counter(A)
most = 0
s = 0
for v in c.values():
    if v > 1:
        s += v - 1
        most = max(most, v-1)
if s // 2 >= most:
    result = n - math.ceil(s / 2)*2
else:
    result = n - most * 2
print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())

from collections import Counter as co
l=co(list(map(int,input().split()))).values()
ans=0
p=0
for i in l:

    if i%2:ans+=1
    else:
        p+=1
print(ans+p//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A).most_common()
c = list(map(list,c))

minus_one_flg = False
for x in c:
    if minus_one_flg:
        x[1] -= 1
        minus_one_flg = False
    if x[1] >= 3:
        if x[1] % 2 == 0:
            x[1] = 2
        else:
            x[1] = 1
    if x[1] == 2:
        x[1] = 1
        minus_one_flg = True

print(sum([y[1] for y in c]))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
#3枚とって最大最小の二枚を食べる
B=[0]*(max(A))
for a in A:
    B[a-1]+=1

B=sorted(B, reverse=True)

#print(sorted(A))
#print(B)
ans=0
pre=0
for b in B:
    b-=pre
    if b>=2 and b%2==1:
        #ans+=(b-1)//2
        #print((b-1)//2)
        pre=0
    elif b>=2 and b%2==0:
        #ans+=(b-2)//2+1
        #print((b-2)//2+1)
        pre=1
    elif b<2:
        pre=0
    if b!=0:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
kind=0
c=[]
d=[0]*(10**5)
count=0
for i in range(N):
  if(d[A[i]-1]==0):
    kind+=1
  d[A[i]-1]+=1
for i in range(N):
  if(d[i]>0 and d[i]%2==0):
    count+=1
print(kind-count%2)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
kind=0
c=[]
d=[0]*(10**5)
count=0
for i in range(N):
  if(d[A[i]]==0):
    kind+=1
  d[A[i]]+=1
for i in range(N):
  if(d[i]>0 and d[i]%2==0):
    count+=1
print(kind-count%2)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
kind=0
c=[]
d=[0]*(10**5)
count=0
for i in range(N):
  if(not(A[i] in c)):
    c.append(A[i])
    kind+=1
  d[A[i]]+=1
for i in range(N):
  if(d[i]>0 and d[i]%2==0):
    count+=1
print(kind-count%2)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
kind=0
c=[]
d=[0]*(10**5)
e=[0]*(10**5)
mi=10**5
ma=0
for i in range(N):
  if(not(A[i] in c)):
    c.append(A[i])
    kind+=1
  d[A[i]]+=1
  if(d[A[i]]>=2):
    e[A[i]]=True
    mi=min(mi,A[i])
    ma=max(ma,A[i])
#print(d)
#print(e)
if(N-kind>=2):
  if(sum(d[mi+1:ma])>0 or ma-mi==1):
    print(kind)
  else:
    print(kind-1)
else:
  print(kind-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def cmb(n,r):
    r = min(n-r,r)
    if r < 0: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    
    D = defaultdict(int)
    for a in A:
        D[a] += 1
    
    res = N
    l = 0
    r = N-1
    while r-l >= 2:
        if D[A[l]] <= 1 and r-l != 2:
            l += 1
        elif D[A[r]] <= 1 and r-l != 2:
            r -= 1
        else:
            res -= 2
            D[A[l]] -= 1
            D[A[r]] -= 1
            l += 1
            r -= 1
    
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n= int(input())
a = list(map(int,input().split()))
now = a[0] 
a.sort()
res = 0
for i in range(n-1):
    if a[i+1] != now:now = a[i+1]
    else: res += 1
ans = n-((res+1)//2)*2
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = {}
    for a in A:
        if a not in B:
            B[a] = 0
        B[a] += 1
    two_elements = 0
    remain = 0
    for b in B:
        num_b = B[b]
        if num_b % 3 == 2:
            two_elements += 1
        remain += num_b - num_b % 3
    ans = len(B)
    if two_elements <= remain:
        remain -= two_elements
    else:
        remain = 2*(two_elements - remain)
    remain %= 3
    if remain > 0:
        ans -= 3 - remain
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = {}
    for a in A:
        if a not in B:
            B[a] = 0
        B[a] += 1
    two_elements = 0
    remain = 0
    for b in B:
        num_b = B[b]
        if num_b % 3 == 2:
            two_elements += 1
        remain += num_b - num_b % 3
    ans = len(B)
    if two_elements * 2 <= remain:
        remain -= two_elements * 2
    else:
        remain = 2*(two_elements - remain//2) + remain % 2
    remain %= 3
    if remain > 0:
        ans -= 3 - remain
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = {}
    for a in A:
        if a not in B:
            B[a] = 0
        B[a] += 1
    two_elements = 0
    remain = 0
    for b in B:
        num_b = B[b]
        if num_b % 3 == 2:
            two_elements += 1
        remain += num_b - num_b % 3
    ans = len(B)
    if two_elements * 2 <= remain:
        remain -= two_elements * 2
    else:
        remain = two_elements - remain//2 + remain % 2
    remain %= 3
    if remain > 0:
        ans -= 2 - remain
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x=int(input())
y=list(map(int, input().split()))
y.sort()
t=0
z=[]
for i in range(x-1):
	if y[i]!=y[i+1]:
		t=t+1
if t%2==0:
	print(t-1)
else:
	print(t)

Submission status: Wrong Answer

Solution code:
x=int(input())
y=list(map(int, input().split()))
y.sort()
t=0
z=[]
for i in range(x-1):
	if y[i]==y[i+1]:
		t=t+1
	else:
		z.append(t)
		t=0
print(x-(((sum(z)+1)//2)*2))

Submission status: Wrong Answer

Solution code:
n=int(input())
a_l=sorted(map(int, input().split()))
a_s=set(a_l)
a=a_l[0]
cnt=1
cnt2=0

for i in range(1,n):
	if a_l[i]==a_l[i-1]:
		cnt+=1
	elif cnt > 1:
		while cnt >= 3:
			cnt -= 2*(cnt//3)
		if cnt == 2:
			cnt2 += 1
		cnt=1
		
ans = len(a_s) - cnt2%2
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
num={}
for ai in a:
    num_ai=num.get(ai, 0)
    num[ai]=num_ai+1

even=0
odd=0
for k,v in num.items():
    if(v%2==0):
        even+=1
    else:
        odd+=1

if(even==0):
    print(len(num))
else:
    print(len(num)-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections

N = int(input())

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

freq = collections.Counter(A)
freq_values = list(freq.values())
freq_keys = list(freq.keys())

freq_more_2 = [i for i in freq_values if i>=2]
ans = len(freq_values)
if len(freq_more_2)%2 ==1:
    ans =ans-1
elif len(freq_more_2)%2 ==0:
    if len(freq_more_2) ==2:
        freq_values = np.array(freq_values)
        where = np.where(freq_values >=2)
        a,b =min(freq_keys[where[0][0]],freq_keys[where[0][1]]),max(freq_keys[where[0][0]],freq_keys[where[0][1]])
        if len(freq_values[(a<freq_values) & (b>freq_values)]) ==0:
            ans=ans-2
        else:
            pass
    elif len(freq_more_2)==0:
        pass
    else:
        pass
    
print(ans)

Submission status: Wrong Answer

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

M = 10**5+1
L = [0]*M
for a in A:
    L[a] += 1

ans = 0
cnt = 0
for i in range(M):
    if L[i] > 0:
        ans += 1
    if L[i] > 1:
        cnt += L[i]

if cnt%2 == 0:
    ans -= 1
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:
    print(ans - 1)
elif ans % 2 == 0 and cnt % 2 == 0:
    print(ans)
elif ans % 2 == 0 and cnt % 2 != 0:
    print(ans - 1)
elif ans % 2 != 0 and cnt % 2 == 0:
    print(ans)
else:
    print(ans - 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

counter = Counter(A)

counts = counter.most_common()

dup_num = 0
for i in range(len(counts)):
    if counts[i][1] != 1:
        dup_num += counts[i][1]-1

print(counts)
if dup_num%2 == 0:
    print(N-dup_num)
else:
    print(N-dup_num-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A = list(map(int,input().split()))
Ac = Counter(A)
dupsum = 0
dupnum = 0
for v in Ac.values():
    if v > 1:
        dupsum += v-1
        dupnum += 1
if dupnum == 1:
    print(dupsum)
else:
    print(dupsum-1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
len_c = len(c)
b = {k:v for k,v in c.items() if v > 1}
sum_b = sum(b.values())
if n == 3:
    print(1)
if sum_b % 2 == 1:
    print(len_c)
else:
    print(len_c - 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
len_c = len(c)
b = {k:v for k,v in c.items() if v > 1}
len_b = sum(b.values())
if n == 3:
    print(1)
elif len_b > 2:
    print(len_c)
else:
    print(len_c - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
B = []

for x in C.values():
    B.append(x)

for i in range(len(B)):
    if B[i] == 0:
        continue
    if B[i]&1:
        B[i] = 1
    elif i < len(B)-1:
        B[i] = 1
        B[i+1] -= 1
    else:
        B[i] = 0 #帳尻を合わせる
        
print(sum(B))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
variety=0
countodd=0
counteven=0
countnow=1
now=l[0]
for i in range(1,n):
  if l[i]==now:
    countnow+=1
  else:
    now=l[i]
    if countnow%2==0:
      countodd+=1
    else:
      counteven+=1
    countnow=1
if countnow!=0:
  if countnow%2==1:
    countodd+=1
  else:
    counteven+=1
if counteven%2==0:
  print(counteven+countodd)
else:
  print(counteven+countodd-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
l =[int(i) for i in input().split()]
count = [0]*10**5
for i in range(N):
    count[l[i]-1]+=1
x=0
for i in range(N):
    if not count[i]==0:
        x+=1
print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
A.sort()
dic={}
for i in A:
    if i not in dic:dic[i]=1
    else:dic[i] +=1

count=0
for v,m in dic.items():
    count +=m-1

print(n//2 if count%2==0 else n//2+1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
mina=min(a)
maxa=max(a)
d=sum([x-1 for x in c.values() if x>1])
ans=n-2*max((d+1)//2,c[mina]-1,c[maxa]-1)
print(ans)

Submission status: Wrong Answer

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

C = {}
for a in A:
  if a in C:
    C[a] += 1
  else:
    C[a] = 1
#print(C)
CK = [k for k in C.keys()]
#print(CK)
i = 0
flag = 0
while(i < len(CK)):
  if flag == 0:
    if C[CK[i]] >= 3:
      C[CK[i]] = 2 - (C[CK[i]] % 2)
    elif C[CK[i]] == 2:
      C[CK[i]] -= 1
      flag = 1
      i += 1
    else:
      i += 1
  else:
    if C[CK[i]] >= 2:
      C[CK[i]] -= 1
      flag = 0
      i += 1
    else:
      i += 1
ans = -flag
for val in C.values():
  ans += val
print(ans)

Submission status: Wrong Answer

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

kaburi=len(set(A))
if kaburi%2==0:
  print(n-kaburi)
else:
  print(n-kaburi-1)

Submission status: Wrong Answer

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

kaburi=(n-len(set(A)))//2
if kaburi==0:
  print(n-2*1)
else:
  print(n-2*kaburi)