Problem:


Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
import itertools
import math
import fractions
import functools
l = [0]*(10**5+10)
r = [0]*(10**5+10)

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

for i in range(n):
    if i % 2 == 0:
        l[v[i]] += 1
    else:
        r[v[i]] += 1

max_l = l.index(max(l))
max_r = r.index(max(r))
count = 0

if max_l == max_r:
    for i in range(len(r)):
        if r[i] == r[max_r]:
            r[i] = 0
        if l[i] == l[max_l]:
            l[i] = 0
if max(l) > max(r):
    max_r = r.index(max(r))
else:
    max_l = l.index(max(l))

for i in range(n):
    if i % 2 == 0 and v[i] != max_l:
        count += 1
    if i % 2 != 0 and v[i] != max_r:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import math
import fractions
import functools
l = [0]*(10**5+10)
r = [0]*(10**5+10)

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

for i in range(n):
    if i % 2 == 0:
        l[v[i]] += 1
    else:
        r[v[i]] += 1

max_l = l.index(max(l))
max_r = r.index(max(r))
count = 0
if max_l == max_r:
    for i in range(len(r)):
        if r[i] == r[max_r]:
            r[i] = 0

max_r = r.index(max(r))

for i in range(n):
    if i % 2 == 0 and v[i] != max_l:
        count += 1
    if i % 2 != 0 and v[i] != max_r:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
dic={}
for i in range(0,n):
  at=v[i]
  if at in dic:
    dic[at]+=1
  else:
    dic[at]=1

count1=0
count2=0
kep1=0
kep2=0
for i in range(len(dic)):
  at=dic.popitem()
  moji=at[0]
  count=at[1]
  if count>count2:
    kep2=moji
    count2=count
  if count2>count1:
    moji_tamotu=kep1
    count_tamotu=count1
    kep1=kep2
    kep2=moji_tamotu
    count1=count2
    count2=count_tamotu
    
kouho1=[kep1,kep2]*(n//2)
kouho2=[kep2,kep1]*(n//2)
res1=0
res2=0
for i in range(0,n):
  if v[i]!=kouho1[i]:
    res1+=1
  if v[i]!=kouho2[i]:
    res2+=1
print(min(res1,res2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
a1, a2, *_ = Counter(V[0::2]).most_common() + [(0, 0)]
b1, b2, *_ = Counter(V[1::2]).most_common() + [(0, 0)]
print(N - max(a1[1] + b2[1], a2[1] + b1[1]) if a1[0] == b1[0] else N - a1[1] + b1[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
V = list(map(int, input().split()))
V_even = []
V_odd = []
for i in range(n // 2):
    V_even.append(V[2 * i])
    V_odd.append(V[2 * i + 1])
V_even_C = Counter(V_even)
V_odd_C = Counter(V_odd)

if V_odd_C.most_common()[0][0] != V_even_C.most_common()[0][0]:
    print(n - V_odd_C.most_common()[0][1] - V_even_C.most_common()[0][1])
else:
    if len(V_even_C) == 1:
        if len(V_odd_C) == 1:
            print(n // 2)
        else:
            print(n // 2 - V_odd_C.most_common()[1][1])
    else:
        if len(V_odd_C) == 1:
            print(n // 2 - V_even_C.most_common()[1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
even = set()
odd = set()
for k,i in enumerate(v):
	if k%2 == 0:
		even.add(i)
	else:
		odd.add(i)
if (len(even) == len(odd) == 1 and list(even)[0] == list(odd)[0]):
	print(n//2)

else:
	print(len(even)+len(odd)-2)

Submission status: Wrong Answer

Solution code:
import math
import fractions
from functools import reduce


def main():
    n = int(input())
    a = input_list()
    if len(set(a)) == 1:
        print(n//2)
        exit(0)
    evens = {}
    odds = {}
    for i, v in enumerate(a):
        if i % 2 == 0:
            if v in evens:
                evens[v] += 1
            else:
                evens[v] = 1
        else:
            if v in odds:
                odds[v] += 1
            else:
                odds[v] = 1
    if len(evens) == 1 and len(odds) == 1:
        print(0)
        exit(0)

    e = sorted(evens.items(), key=lambda x: x[1], reverse=True)
    o = sorted(odds.items(), key=lambda x: x[1], reverse=True)

    even_ans = (n // 2) - e[0][1]
    odd_ans = (n // 2) if len(o) == 1 else (n // 2) - o[1][1]
    a1 = even_ans+odd_ans

    even_ans = (n // 2) if len(e) == 1 else (n // 2) - e[1][1]
    odd_ans = (n // 2) - o[0][1]
    a2 = even_ans+odd_ans
    print(min(a1, a2))


# 6
# 3 1 3 2 4 2

def input_list():
    return list(map(int, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
import fractions
from functools import reduce


def main():
    n = int(input())
    a = input_list()
    if len(set(a)) == 1:
        print(n//2)
        exit(0)
    evens = {}
    odds = {}
    for i, v in enumerate(a):
        if i % 2 == 0:
            if v in evens:
                evens[v] += 1
            else:
                evens[v] = 1
        else:
            if v in odds:
                odds[v] += 1
            else:
                odds[v] = 1
    if len(evens) == 1 and len(odds) == 1:
        print(0)
        exit(0)

    e = sorted(evens.items(), key=lambda x: x[1], reverse=True)
    o = sorted(odds.items(), key=lambda x: x[1], reverse=True)
    if e[0][1] > o[0][1]:
        even_ans = (n // 2) - e[0][1]
        odd_ans = (n // 2) if len(o) == 1 else (n // 2) - o[1][1]
        print(even_ans+odd_ans)
    else:
        even_ans = (n // 2) if len(e) == 1 else (n // 2) - e[1][1]
        odd_ans = (n // 2) - o[0][1]
        print(even_ans+odd_ans)


# 6
# 3 1 3 2 4 2

def input_list():
    return list(map(int, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

even = v[0:n:2]
odd = v[1:n:2]

c_even = [0]*(10**5+100)
c_odd = [0]*(10**5 + 100)

for i in even:
    c_even[i]+=1
for i in odd:
    c_odd[i]+=1

m_even = -1
m_odd = -1


for i,j in enumerate(c_even):
    if j > m_even:
        m_even = j 
        m_even_num = i

for i,j in enumerate(c_odd):
    if j > m_odd:
        m_odd = j 
        m_odd_num = i

if m_even_num == m_odd_num:
    if m_odd >= m_even:
        print((n//2- m_odd) + (n//2 - sorted(c_even,reverse=True)[1]))
    else:
        print((n//2- m_even) + (n//2 - sorted(c_odd,reverse=True)[1]))
else:
    print(n - m_even - m_odd)

Submission status: Wrong Answer

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

even = v[0:n:2]
odd = v[1:n:2]

c_even = [0]*(10**5+100)
c_odd = [0]*(10**5 + 100)

for i in even:
    c_even[i]+=1
for i in odd:
    c_odd[i]+=1

m_even = -1
m_odd = -1


for i,j in enumerate(c_even):
    if j > m_even:
        m_even = j 
        m_even_num = i

for i,j in enumerate(c_odd):
    if j > m_odd:
        m_odd = j 
        m_odd_num = i

if m_even_num == m_odd_num:
    if m_odd >= m_even:
        print((n//2- m_odd) + (n//2 - sorted(c_even)[-2]))
    else:
        print((n//2- m_even) + (n//2 - sorted(c_odd)[-2]))
else:
    print(n - m_even - m_odd)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C

n = input()
v = [int(x) for x in input().split()]
cv = C(v)
s = sorted(cv)
try:
    s, ss = s[-1], s[-2]
except IndexError:
    print(2)
    exit()
if cv[s] == cv[ss]:
    print(0)
    exit()
p = cv[s] + cv[ss]
print(int(n) - p)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v1=[]
v2=[]

for i in range(n):
  if i%2==0:
    v1.append(v[i])
  else:
    v2.append(v[i])

v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()

ans2=float("inf")
ans3=float("inf")
ans4=float("inf")


if v1c[0][0]!=v2c[0][0]:
  ans=len(v1)-v1c[0][1]+len(v2)-v2c[0][1]
  print(ans)

else:
  if len(v1c) !=1:
    ans2=len(v1)-v1c[1][1]+len(v2)-v2c[0][1]
  elif len(v2c) !=1:
    ans3=len(v1)-v1c[0][1]+len(v2)-v2c[1][1]
  else:
    ans4=min(len(v1),len(v2))
  print(min(ans2,ans3,ans4))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
vo, ve = v[::2], v[1::2]
print((len(vo) - max(vo.count(voi) for voi in set(vo))) + (len(vo) - max(ve.count(vei) for vei in set(ve))))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
V = tuple(map(int, input().split()))

C0 = Counter(V[0::2]).most_common()
C1 = Counter(V[1::2]).most_common()
if C0[0][0] != C1[0][0]:
    print(N - C0[0][1] - C1[0][1])
else:
    C0.append((0, 0))
    C1.append((0, 0))
    print(max(N - C0[0][1] - C1[1][1], N - C0[1][1] - C1[0][1]))

Submission status: Wrong Answer

Solution code:
import numpy as np
ans = 0

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

odd = V[0::2]
even = V[1::2]

odd_count = np.bincount(odd)
odd_argmax = np.argmax(odd_count)
odd_count_num = odd_count[odd_argmax]

even_count = np.bincount(even)
even_argmax = np.argmax(even_count)
even_count_num = even_count[even_argmax]

if odd_argmax == even_argmax:
    if odd_count_num > even_count_num:
        even_count[even_argmax] = 0
        even_argmax = np.argmax(even_count)
        even_count_num = even_count[even_argmax]
    else:
        odd_count[odd_argmax] = 0
        odd_argmax = np.argmax(odd_count)
        odd_count_num = odd_count[odd_argmax]

ans += len(odd) - odd_count_num
ans += len(even) - even_count_num
print(ans)

Submission status: Wrong Answer

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

if len(set(l)) == 1:
    print(len(l)//2)
    exit()

even = [l[_] for _ in range(n) if _%2 ==1]
odd = [l[_] for _ in range(n) if _%2 ==0]

from collections import Counter

odd_cnt = Counter(odd)
even_cnt = Counter(even)

if odd_cnt.most_common()[0][0] != even_cnt.most_common()[0][0]:
    print(len(odd) - odd_cnt.most_common()[0][1] + len(even) - even_cnt.most_common()[0][1])
else:
    if odd_cnt.most_common()[0][1] >= even_cnt.most_common()[0][1]:
        print(len(odd) - odd_cnt.most_common()[1][1] + len(even) - even_cnt.most_common()[0][1])
    else:
        print(len(odd) - odd_cnt.most_common()[0][1] + len(even) - even_cnt.most_common()[1][1])

Submission status: Wrong Answer

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

if len(set(l)) == 1:
    print(len(l)//2)
    exit()

even = [l[_] for _ in range(n) if _%2 ==1]
odd = [l[_] for _ in range(n) if _%2 ==0]

from collections import Counter

odd_cnt = Counter(odd)
even_cnt = Counter(even)

if odd_cnt.most_common()[0][0] != even_cnt.most_common()[0][0]:
    print(len(odd) - odd_cnt.most_common()[0][1] + len(even) - even_cnt.most_common()[0][1])
else:
    if odd_cnt.most_common()[0][1] >= even_cnt.most_common()[0][1]:
        print(len(odd) - odd_cnt.most_common()[0][1] + len(even) - even_cnt.most_common()[1][1])
    else:
        print(len(odd) - odd_cnt.most_common()[1][1] + len(even) - even_cnt.most_common()[0][1])

Submission status: Wrong Answer

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

if len(set(l)) == 1:
    print(len(l)//2)
    exit()

even = [l[_] for _ in range(n) if _%2 ==1]
odd = [l[_] for _ in range(n) if _%2 ==0]

from collections import Counter

odd_cnt = Counter(odd)
even_cnt = Counter(even)

print(len(odd) - odd_cnt.most_common()[0][1] + len(even) - even_cnt.most_common()[0][1])

Submission status: Wrong Answer

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])
# print('c1, c2', c1, c2)

c1_items = sorted(c1.items(), key=lambda x: -x[1])
c2_items = sorted(c2.items(), key=lambda x: -x[1])
c1_max = c1_items[0][1]
c2_max = c2_items[0][1]
c1_second = 0
c2_second = 0

c1_max_group = set()
for key, value in c1_items:
    if value == c1_max:
        c1_max_group.add(key)
    else:
        c1_second = value
        break
c2_max_group = set()
for key, value in c2_items:
    if value == c2_max:
        c2_max_group.add(key)
    else:
        c2_second = value
        break

# print(c1_max_group, c1_max, c1_second)
# print(c2_max_group, c2_max, c2_second)
if len(c1_max_group) == 1 and list(c1_max_group)[0] in c2_max_group:
    v1 = n - c1_max - c2_second
    v2 = n - c1_second - c2_max
    ans = min(v1, v2)
elif len(c2_max_group) == 1 and list(c2_max_group)[0] in c1_max_group:
    v1 = n - c1_max - c2_second
    v2 = n - c1_second - c2_max
    ans = min(v1, v2)
else:
    ans = n - c1_max - c2_max
print(ans)

Submission status: Wrong Answer

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])
# print('c1, c2', c1, c2)

c1_items = sorted(c1.items(), key=lambda x: -x[1])
c2_items = sorted(c2.items(), key=lambda x: -x[1])
c1_max = c1_items[0][1]
c2_max = c2_items[0][1]
c1_second = 0
c2_second = 0

c1_max_group = set()
for key, value in c1_items:
    if value == c1_max:
        c1_max_group.add(key)
    else:
        c1_second = value
        break
c2_max_group = set()
for key, value in c2_items:
    if value == c2_max:
        c2_max_group.add(key)
    else:
        c2_second = value
        break

# print(c1_max_group, c2_max_group)
if len(c1_max_group) == 1 and list(c1_max_group)[0] in c2_max_group:
    v1 = n - c1_max + c2_second
    v2 = n - c1_second + c2_max
    ans = min(v1, v2)
elif len(c2_max_group) == 1 and list(c2_max_group)[0] in c1_max_group:
    v1 = n - c1_max + c2_second
    v2 = n - c1_second + c2_max
    ans = min(v1, v2)
else:
    ans = n - c1_max - c2_max
print(ans)

Submission status: Wrong Answer

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


def main():
  n = int(input())
  V = list(map(int, input().split()))

  a = V[::2]
  b = V[1::2]
  
  a_counter = collections.Counter(a)
  b_counter = collections.Counter(b)

  a_most_common = a_counter.most_common()
  b_most_common = b_counter.most_common()

  if len(a_most_common) == 1 and len(b_most_common) == 1 and a_most_common[0][0] == b_most_common[0][0]:
    print(n // 2)
    return

  min_pair = None
  min_count = None
  for (a_char, a_count) in a_most_common:
    for (b_char, b_count) in b_most_common:
      if (not min_count) or ((a_char != b_char) and (n - a_count - b_count < min_count)):
        min_count = n - a_count - b_count

  print(min_count)


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
li = list(map(int,input().split()))
x = li[::2]
y = li[1::2]
c = collections.Counter(li)
c0 = collections.Counter(x)
c1 = collections.Counter(y)

if c.most_common()[0][1] == len(li): #1種類だけのリストだったら
    print(n//2)

elif c0.most_common()[0][0] != c1.most_common()[0][0]: #目標とする最小の答えが交互になれば
    print(n - c0.most_common()[0][1] - c1.most_common()[0][1])

else:
    if len(c0.keys())==1: #c0が一種類だったら
        print(n//2 - c1.most_common()[1][1])
    elif len(c1.keys())==1: #c1が一種類だったら
        print(n//2 - c0.most_common()[1][1])
    elif c0.most_common()[0][1] + c1.most_common()[1][1] < c0.most_common()[1][1] + c1.most_common()[0][1]:
        print(n - c0.most_common()[0][1] - c1.most_common()[1][1])
    else:
        print(n - c0.most_common()[1][1] - c1.most_common()[0][1])

Submission status: Wrong Answer

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

# 奇数番目を見る
odd_counter = collections.Counter(Vs[0::2])
odd_counter_tuple = odd_counter.most_common()
# 頻度1番目と2番目のkeyを取り出す
if len(odd_counter_tuple) == 1:
    odd1 = odd_counter_tuple[0][0]
    odd2 = None
else:
    odd1 = odd_counter_tuple[0][0]
    odd2 = odd_counter_tuple[1][0]

# 偶数番目を見る
even_counter = collections.Counter(Vs[1::2])
even_counter_tuple = even_counter.most_common()
# 頻度1番目と2番目のkeyを取り出す
if len(even_counter_tuple) == 1:
    even1 = even_counter_tuple[0][0]
    even2 = None
else:
    even1 = even_counter_tuple[0][0]
    even2 = even_counter_tuple[1][0]

if odd1 != even1:
    ans = n - odd_counter[odd1] - even_counter[even1]
else:
    ans = max(n-odd_counter[odd2]-even_counter[even1], n-odd_counter[odd1]-even_counter[even2])

print(ans)

Submission status: Wrong Answer

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

l = []
r = []
al = []
for i, x in enumerate(A):
  if i % 2 == 0:
    l.append(x)
  else:
    r.append(x)
  al.append(x)

c = collections.Counter(l)
d = collections.Counter(r)
e = collections.Counter(al)

if len(e.keys()) <= 1:
  print(N//2)
  exit()
else:
  mx = -1
  ans = 0
  ck = max(c.items(), key=lambda x:x[1])[0]
  cmx = max(c.items(), key=lambda x:x[1])[1]

  dk = max(d.items(), key=lambda x:x[1])[0]
  dmx = max(d.items(), key=lambda x:x[1])[1]

  if ck == dk:
    if cmx >= dmx:
      ans += N//2 - cmx
      ans += N//2 - (d.most_common(2)[1][1])
    else:
      ans += N//2 - dmx
      ans += N//2 - (c.most_common(2)[1][1])
  else:
      ans += N//2 - cmx
      ans += N//2 - dmx

print(ans)

Submission status: Wrong Answer

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

l = []
r = []
al = []
for i, x in enumerate(A):
  if i % 2 == 0:
    l.append(x)
  else:
    r.append(x)
  al.append(x)

c = collections.Counter(l)
d = collections.Counter(r)
e = collections.Counter(al)
if len(e.keys()) <= 1:
  print(N//2)
  exit()
else:
  mx = -1
  ans = 0
  for x in c.values():
    mx = max(x, mx)
  ans += N//2 - mx
  
  

  mx_ = -1
  for x in d.values():
    mx_ = max(x, mx_)
  ans += N//2 - mx_

print(ans)

Submission status: Wrong Answer

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

l = []
r = []
al = []
for i, x in enumerate(A):
  if i % 2 == 0:
    l.append(x)
  else:
    r.append(x)
  al.append(x)

c = collections.Counter(l)
d = collections.Counter(r)
e = collections.Counter(al)
if len(e.keys()) <= 1:
  print(N//2)
  exit()
else:
  mx = -1
  ans = 0
  for x in c.values():
    mx = max(x, mx)
    ans += N//2 - mx
  

  mx_ = -1
  for x in d.values():
    mx_ = max(x, mx_)
  ans += N//2 - mx_

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    V = il()
    A = collections.Counter(V[0::2])
    B = collections.Counter(V[1::2])

    ret = 0
    if len(A.keys()) != 1:
        ret += sum([v for v in A.values()]) - max([v for v in A.values()])
    else:
        ret += abs(N//2 - sum([v for v in A.values()]))

    if len(B.keys()) != 1:
        ret += sum([v for v in B.values()]) - max([v for v in B.values()])
    else:
        ret += abs(N // 2 - sum([v for v in B.values()]))

    if B.keys() == A.keys():
        ret += N//2

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
e=[]
o=[]
for i, vi in enumerate(v,start=0):
  if i%2 == 0:
    e.append(vi)
  else:
    o.append(vi)
ec=collections.Counter(e)
oc=collections.Counter(o)

ec_sorted = sorted(ec.items(), key=lambda x:x[1],reverse=True)
oc_sorted = sorted(oc.items(), key=lambda x:x[1],reverse=True)

t=ec_sorted[0][1]+oc_sorted[0][1]
if ec_sorted[0][0] == oc_sorted[0][0]:
  if ec_sorted[0][1] == oc_sorted[0][1]:
    t=n//2
      
print(n-t)

Submission status: Wrong Answer

Solution code:
import sys

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

data = V[0]
is_all = True
for v in V:
    if v != data:
        is_all = False
        break

if is_all:
    print(n//2)
    sys.exit()

v_kisuu = V[0::2]
v_guusu = V[1::2]
v_kisuu.sort()
v_guusu.sort()

ans = 0

max_num = 0
max_num2 = 0
max_v = 0
v_before = v_kisuu[0]
num = 0
for v in v_kisuu:
    if v != v_before:
        if num  > max_num:
            max_num2 = max_num
            max_num = num
            max_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > max_num:
    max_num2 = max_num
    max_num = num
    max_v = v_before

kmax_num = 0
kmax_num2 = 0
kmax_v = 0
v_before = v_guusu[0]
num = 0
for v in v_guusu:
    if v != v_before:
        if num  > kmax_num:
            kmax_num2 = max_num
            kmax_num = num
            kmax_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > kmax_num:
    kmax_num2 = max_num
    kmax_num = num
    kmax_v = v_before

ans = 0
if kmax_v == max_v:
    if kmax_num > max_num:
        ans += (n//2-max_num2)
        ans += (n//2-kmax_num)
    elif kmax_num < max_num:
        ans += (n//2-kmax_num2)
        ans += (n//2-max_num)
    else:
        if kmax_num2 > max_num2:
            ans += (n//2-kmax_num2)
            ans += (n//2-max_num)
            ans += 1
        else:
            ans += (n//2-max_num2)
            ans += (n//2-kmax_num)
else:
    ans += (n//2-kmax_num)
    ans += (n//2-max_num)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

data = V[0]
is_all = True
for v in V:
    if v != data:
        is_all = False
        break

if is_all:
    print(n//2)
    sys.exit()

v_kisuu = V[0::2]
v_guusu = V[1::2]
v_kisuu.sort()
v_guusu.sort()

ans = 0

max_num = 0
max_num2 = 0
max_v = 0
v_before = v_kisuu[0]
num = 0
for v in v_kisuu:
    if v != v_before:
        if num  > max_num:
            max_num2 = max_num
            max_num = num
            max_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > max_num:
    max_num2 = max_num
    max_num = num
    max_v = v_before

kmax_num = 0
kmax_num2 = 0
kmax_v = 0
v_before = v_guusu[0]
num = 0
for v in v_guusu:
    if v != v_before:
        if num  > kmax_num:
            kmax_num2 = max_num
            kmax_num = num
            kmax_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > kmax_num:
    kmax_num2 = max_num
    kmax_num = num
    kmax_v = v_before

ans = 0
if kmax_v == max_v:
    if kmax_num > max_num:
        ans += (n//2-max_num2)
        ans += (n//2-kmax_num)
    elif kmax_num < max_num:
        ans += (n//2-kmax_num2)
        ans += (n//2-max_num)
    else:
        if kmax_num2 > max_num2:
            ans += (n//2-kmax_num2)
            ans += (n//2-max_num)
        else:
            ans += (n//2-max_num2)
            ans += (n//2-kmax_num)
else:
    ans += (n//2-kmax_num)
    ans += (n//2-max_num)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

data = V[0]
is_all = True
for v in V:
    if v != data:
        is_all = False
        break

if is_all:
    print(n//2)
    sys.exit()

v_kisuu = V[0::2]
v_guusu = V[1::2]
v_kisuu.sort()
v_guusu.sort()

ans = 0

max_num = 0
max_num2 = 0
max_v = 0
v_before = v_kisuu[0]
num = 0
for v in v_kisuu:
    if v != v_before:
        if num  > max_num:
            max_num2 = max_num
            max_num = num
            max_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > max_num:
    max_num2 = max_num
    max_num = num
    max_v = v_before

kmax_num = 0
kmax_num2 = 0
kmax_v = 0
v_before = v_guusu[0]
num = 0
for v in v_guusu:
    if v != v_before:
        if num  > kmax_num:
            kmax_num2 = max_num
            kmax_num = num
            kmax_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > kmax_num:
    kmax_num2 = max_num
    kmax_num = num
    kmax_v = v_before

ans = 0
if kmax_v == max_v:
    if kmax_num > max_num:
        ans += (n//2-max_num2)
        ans += (n//2-kmax_num)
    elif kmax_num < max_num:
        ans += (n//2-kmax_num2)
        ans += (n//2-max_num)
    else:
        if kmax_num2 > max_num2:
            ans += (n//2-kmax_num)
            ans += (n//2-max_num2)
        else:
            ans += (n//2-max_num)
            ans += (n//2-kmax_num2)
else:
    ans += (n//2-kmax_num)
    ans += (n//2-max_num)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

data = V[0]
is_all = True
for v in V:
    if v != data:
        is_all = False
        break

if is_all:
    print(n//2)
    sys.exit()

v_kisuu = V[0::2]
v_guusu = V[1::2]
v_kisuu.sort()
v_guusu.sort()

ans = 0

max_num = 0
max_num2 = 0
max_v = 0
v_before = v_kisuu[0]
num = 0
for v in v_kisuu:
    if v != v_before:
        if num  > max_num:
            max_num2 = max_num
            max_num = num
            max_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > max_num:
    max_num2 = max_num
    max_num = num
    max_v = v_before

kmax_num = 0
kmax_num2 = 0
kmax_v = 0
v_before = v_guusu[0]
num = 0
for v in v_guusu:
    if v != v_before:
        if num  > kmax_num:
            kmax_num2 = max_num
            kmax_num = num
            kmax_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > kmax_num:
    kmax_num2 = max_num
    kmax_num = num
    kmax_v = v_before

ans = 0
if kmax_v == max_v:
    if kmax_num > max_num:
        ans += (n//2-max_num2)
        ans += (n//2-kmax_num)
    else:
        ans += (n//2-kmax_num2)
        ans += (n//2-max_num)
else:
    ans += (n//2-kmax_num)
    ans += (n//2-max_num)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

data = V[0]
is_all = True
for v in V:
    if v != data:
        is_all = False
        break

if is_all:
    print(n//2)
    sys.exit()

v_kisuu = V[0::2]
v_guusu = V[1::2]
v_kisuu.sort()
v_guusu.sort()

ans = 0

max_num = 0
max_num2 = 0
max_v = 0
v_before = v_kisuu[0]
num = 0
for v in v_kisuu:
    if v != v_before:
        if num  > max_num:
            max_num2 = max_num
            max_num = num
            max_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > max_num:
    max_num2 = max_num
    max_num = num
    max_v = v_before

kmax_num = 0
kmax_num2 = 0
kmax_v = 0
v_before = v_guusu[0]
num = 0
for v in v_guusu:
    if v != v_before:
        if num  > max_num:
            kmax_num2 = max_num
            kmax_num = num
            kmax_v = v_before
        v_before = v
        num = 1
    else:
        num += 1

if num  > kmax_num:
    kmax_num2 = max_num
    kmax_num = num
    kmax_v = v_before

ans = 0
if kmax_v == max_v:
    if kmax_num > max_num:
        ans += (n//2-max_num2)
        ans += (n//2-kmax_num)
    else:
        ans += (n//2-kmax_num2)
        ans += (n//2-max_num)
else:
    ans += (n//2-kmax_num)
    ans += (n//2-max_num)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
fn=sorted(Counter(f).items(),key=lambda x:x[1]) + [(0, 0)]
sn=sorted(Counter(s).items(),key=lambda x:x[1]) + [(0, 0)]
if fn[0][0]!=sn[0][0]:
  ans=n-fn[0][1]-sn[0][1]
else:
  ans=n-max(fn[1][1]+sn[0][1],fn[0][1]+sn[1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
fn=sorted(Counter(f).items(),key=lambda x:x[1]) + [(0, 0)]
sn=sorted(Counter(s).items(),key=lambda x:x[1]) + [(0, 0)]
if fn[0][0]!=sn[0][0]:
  ans=n-fn[0][1]-sn[0][1]
else:
  ans=n-max(fn[1][1]+fn[0][1],fn[0][1]+sn[1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
ans=0
if len(Counter(l).values()) == 1:
  ans=len(f)
elif len(Counter(f).values()) == len(Counter(s).values()) == 1:
  ans=0
else:
  fn=sorted(Counter(f).items(),key=lambda x:x[1])
  sn=sorted(Counter(f).items(),key=lambda x:x[1])
  fnv=sorted(Counter(f).values())
  snv=sorted(Counter(s).values())
  for i in range(1,2):
    tmp=0
    if i == 1:
      tmp+=sum(fnv[:-1])
    else:
      tmp=sum(fnv[:-2])+fnv[-1]
    for j in range(1,2):
      if j == 1:
        tmp+=sum(snv[:-1])
        ans=tmp
      else:
        tmp=sum(snv[:-2])+snv[-1]
    if ans > tmp:
      ans=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
ans=[]
if len(Counter(l).values()) == 1:
  ans.append(len(f))
elif len(Counter(f).values()) == len(Counter(s).values()) == 1:
  ans.append(0)
else:
  print(Counter(f).items(),Counter(s).items())
  for fk,fv in sorted(Counter(f).items(),key=lambda x:x[0]):
    fdk=fk
    a=sum(Counter(f).values())-fv
    for sk,sv in sorted(Counter(s).items(),key=lambda x:x[0]):
      if fk != sk:
        ans.append(a+sum(Counter(s).values())-sv)
print(min(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
ans=0
if len(Counter(l).values()) == 1:
  ans+=len(f)
else:
  if len(Counter(f).values()) != 1:
    fn=sorted(Counter(f).values())
    ans+=sum(fn[:-1])
  if len(Counter(s).values()) != 1:
    sn=sorted(Counter(s).values())
    ans+=sum(sn[:-1])
print(ans)