Buggy python submission (verdict: Runtime Error):
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)


Fixed submission:
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
if len(ls) > 0:
#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)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import sys
def input():
    return sys.stdin.readline()[:-1]
  
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:
        if len(ls) == 1:
            dic[ls[0]] -= 2
        else:
            dic[ls[0]] -= 1
            dic[ls[-1]] -= 1
        ans -= 2

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

print(ans)


Fixed submission:
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
if len(ls) > 0:
#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)

Buggy python submission (verdict: Runtime Error):
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)


Fixed submission:
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
if len(ls) > 0:
#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)

Buggy python submission (verdict: Runtime Error):
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)


Fixed submission:
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
if len(ls) > 0:
#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)