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:
from collections import Counter
N=int(input())
V=list(map(int,input().split()))
V0=Counter(V[::2]).most_common()
V1=Counter(V[1::2]).most_common()
ans=0
for i in range(1,len(V0)-1):
  ans+=V0[i][1]
for i in range(1,len(V1)-1):
  ans+=V1[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

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

A = V[0::2]
B = V[1::2]

# print(A, B)

cnt = 0

if len(set(V)) == 1:
    print(N // 2)
    sys.exit()


def get_keys_from_value(d, val):
    return [k for k, v in d.items() if v == val]


if set(A) != 1:
    cnt += len(A) - max(Counter(A).values())
if set(B) != 1:
    if A == B:
        need_to_be_changed = get_keys_from_value(Counter(B), max(Counter(A).values()))
        need_to_be_changed_num = Counter(B)[need_to_be_changed[0]]
        cnt += need_to_be_changed_num
    else:
        cnt += len(B) - max(Counter(B).values())

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

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

A = V[0::2]
B = V[1::2]

# print(A, B)

cnt = 0

if len(set(V)) == 1:
    print(N // 2)
    sys.exit()

if set(A) != 1:
    cnt += len(A) - max(Counter(A).values())
if set(B) != 1:
    cnt += len(B) - max(Counter(B).values())

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

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

A = V[0::2]
B = V[1::2]

print(A, B)

cnt = 0

if len(set(V)) == 1:
    print(N // 2)
    sys.exit()

if set(A) != 1:
    cnt += len(A) - max(Counter(A).values())
if set(B) != 1:
    cnt += len(B) - max(Counter(B).values())

print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
even = vlist[0:n:2]
odd = vlist[1:n:2]
e_counter= collections.Counter(even)
o_counter = collections.Counter(odd)
e_v = list(e_counter.values())
e_k = list(e_counter.keys())
o_v = list(o_counter.values())
o_k = list(o_counter.keys())
ans = 10**9
#ans = len(even)-e + len(odd)-o
#print(e_k,o_k)
if e_k[0] == o_k[0]:
  if len(e_v) >= 2 and len(o_v) >= 2:
    ans = min(ans,len(even)-e_v[1]+len(odd)-o_v[0],len(even)-e_v[0]+len(odd)-o_v[1])
  elif len(e_v) >= 2:
    ans = min(ans,len(even)+len(odd)-e_v[1]-o_v[0],len(even)+len(odd)-e_v[0])
  elif len(o_v) >= 2:
    ans = min(ans,len(even)+len(odd)-o_v[1]-o_v[0],len(even)+len(odd)-o_v[0])
  else:
    ans = min(len(even)+len(odd)-e_v[0],len(even)+len(odd)-o_v[0])
else:
  ans = min(ans,len(even)+len(odd)-e_v[0]-o_v[0])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
even = vlist[0:n:2]
odd = vlist[1:n:2]
e_counter= collections.Counter(even)
o_counter = collections.Counter(odd)
e = e_counter.most_common()[0][1]
if e_counter.most_common()[0][0] != o_counter.most_common()[0][0]:
  o = o_counter.most_common()[0][1]
  e = e_counter.most_common()[0][1]
else:
  o = o_counter.most_common()[1][1] if len(o_counter) >= 2 else 0
  e = o_counter.most_common()[1][1] if len(e_counter) >= 2 else 0
  if o >= e:
    e = e_counter.most_common()[0][1]
  else:
    o = o_counter.most_common()[0][1]
ans = len(even)-e + len(odd)-o
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
even = vlist[0:n:2]
odd = vlist[1:n:2]
e_counter= collections.Counter(even)
o_counter = collections.Counter(odd)
e = e_counter.most_common()[0][1]
if e_counter.most_common()[0][0] != o_counter.most_common()[0][0]:
  o = o_counter.most_common()[0][1]
else:
  if len(o_counter) >= 2:
    o = o_counter.most_common()[1][1]
  else:
    o = 0
ans = len(even)-e + len(odd)-o
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int, input().split()))
if len(set(arr)) == 1:
    print(N//2)
    exit()
A = []
B = []
for i in range(N):
    if i % 2 == 0:
        A.append(arr[i])
    else:
        B.append(arr[i])
from collections import Counter
A_counter = Counter(A)
B_counter = Counter(B)
if A_counter.most_common()[0][0] != B_counter.most_common()[0][0]:
    print(N-A_counter.most_common()[0][1]-B_counter.most_common()[0][1])
elif A_counter.most_common()[0][1] >= B_counter.most_common()[0][1]:
    print(N-A_counter.most_common()[0][1]-B_counter.most_common()[1][1])
else:
    print(N-A_counter.most_common()[1][1]-B_counter.most_common()[0][1])

Submission status: Wrong Answer

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

def solve(n,v):
    if len(set(v))==1:
        return n//2
    Odd = [v[i] for i in range(n) if i%2==1]
    Even = [v[i] for i in range(n) if i%2==0]
    odd = len(set(Odd))-1
    even = len(set(Even))-1
    return odd + even
print(solve(n,v))

Submission status: Wrong Answer

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

def solve(n,v):
    if len(set(v))==1:
        return n//2
    Odd = [i for i in v if i%2==1]
    Even = [i for i in v if i%2==0]
    odd = len(set(Odd))-1
    even = len(set(Even))-1
    return odd + even
print(solve(n,v))

Submission status: Wrong Answer

Solution code:
import collections 
n=int(input())
v=list(map(int,input().split()))
c1,c2,ans=collections.Counter(v[::2]),collections.Counter(v[1::2]),0
a,b=c1.most_common(),c2.most_common()
if len(a)==len(b)==1:
  print(n//2 if a==b else 0)
  exit()
ans=n+(-a[0][1]-b[0][1] if a[0][1]!=b[0][1] else (-a[0][1]-b[1][1] if b[1][1]>=a[1][1] else -a[1][1]-b[0][1]))
print(ans)

Submission status: Wrong Answer

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

a = [v[i] for i in range(n) if i % 2]
b = [v[i] for i in range(n) if i % 2 == 0]
aa = Counter(a)
bb = Counter(b)
ans = 0

aas = sorted(aa.keys(), key=lambda key:aa[key], reverse=True)
bbs = sorted(bb.keys(), key=lambda key:bb[key], reverse=True)
if aas[0] != bbs[0]:
    ans += len(a) - aa[aas[0]]
    ans += len(b) - bb[bbs[0]]
else:
    if len(aa) == len(bb) and len(aa) == 1 and a[0] == b[0]:
        ans += min(len(a), len(b))
    else:
        if aa[aas[0]] > bb[bbs[0]]:
            ans += len(a) - aa[aas[0]]
            ans += len(b) - bb[bbs[1]]
        else:
            ans += len(a) - aa[aas[1]]
            ans += len(b) - bb[bbs[0]]

print(ans)

Submission status: Wrong Answer

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

a = [v[i] for i in range(n) if i % 2]
b = [v[i] for i in range(n) if i % 2 == 0]
aa = Counter(a)
bb = Counter(b)
ans = 0

aas = sorted(aa.keys(), key=lambda key:aa[key])
bbs = sorted(bb.keys(), key=lambda key:bb[key])
if aas[0] != bbs[0]:
    ans += len(a) - aa[aas[0]]
    ans += len(b) - bb[bbs[0]]
else:
    if len(aa) == len(bb) and len(aa) == 1 and a[0] == b[0]:
        ans += min(len(a), len(b))
    else:
        if aa[aas[0]] > bb[bbs[0]]:
            ans += len(a) - aa[aas[0]]
            ans += len(b) - bb[bbs[1]]
        else:
            ans += len(a) - aa[aas[1]]
            ans += len(b) - bb[bbs[0]]

print(ans)

Submission status: Wrong Answer

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

a = [v[i] for i in range(n) if i % 2]
b = [v[i] for i in range(n) if i % 2 == 0]
aa = Counter(a)
bb = Counter(b)
ans = 0

aas = sorted(aa.keys(), key=lambda key:aa[key])
bbs = sorted(bb.keys(), key=lambda key:bb[key])
if aas[0] != bbs[0]:
    ans += len(a) - aa[aas[0]]
    ans += len(b) - bb[bbs[0]]
else:
    if len(aa) == len(bb) and len(aa) == 1:
        ans += min(len(a), len(b))
    else:
        if aa[aas[0]] > bb[bbs[0]]:
            ans += len(a) - aa[aas[0]]
            ans += len(b) - bb[bbs[1]]
        else:
            ans += len(a) - aa[aas[1]]
            ans += len(b) - bb[bbs[0]]

print(ans)

Submission status: Wrong Answer

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

a = [v[i] for i in range(n) if i % 2]
b = [v[i] for i in range(n) if i % 2 == 0]
aa = Counter(a)
bb = Counter(b)
ans = 0
ans += len(a) - max(aa.values())
ans += len(b) - max(bb.values())

if ans == 0 and aa.keys() == bb.keys():
    ans += min(len(a), len(b))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
s = list(map(int,input().split()))
s1 = []
s2 = []

for i in range(n):
  if i%2 == 1:
    s2.append(s[i])
  else:
    s1.append(s[i])
s1_counter = Counter(s1)
s2_counter = Counter(s2)
s1_len = len(s1)
s2_len = len(s2)
s1_most_common = s1_counter.most_common()
s2_most_common = s2_counter.most_common()

if s1_most_common[0][0] != s2_most_common[0][0]:
  print(s1_len-s1_most_common[0][1]+s2_len-s2_most_common[0][1])
else:  
  if len(s1_most_common) + len(s2_most_common) == 2:
    print(n//2)
  elif s1_most_common[0][1] > s2_most_common[0][1]:
    print(s1_len-s1_most_common[0][1]+s2_len-s2_most_common[1][1])
  else:
    print(s1_len-s1_most_common[1][1]+s2_len-s2_most_common[0][1])

Submission status: Wrong Answer

Solution code:
#??????????????????????
from collections import defaultdict
def vvv(n , vl):

    ans = 0
    gdict = defaultdict(int)
    kdict = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            gdict[vl[i]] += 1
        else:
            kdict[vl[i]] += 1

    glist = sorted(list(gdict.items()) , key = lambda x: x[1])
    klist = sorted(list(kdict.items()) , key = lambda x: x[1])

    if int(glist[0][1]) == int(klist[0][1]):
        if int(glist[0][0]) == int(klist[0][0]):
            ans = int(klist[0][1])
    else:
        ans = sum(list(gdict.values())) - int(glist[0][1]) + sum(list(kdict.values())) - int(klist[0][1])

    return ans

def main():
    n = int(input())
    vl = list(map(int , input().split()))
    print(vvv(n , vl))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

a1 = {}
a2 = {}
for i in range(n) :
  a = v[i]
  if i%2 == 0 :
    if a in a1 :
      a1[a] += 1
    else :
      a1[a] = 1
  else :
    if a in a2 :
      a2[a] += 1
    else :
      a2[a] = 1

a1_s = sorted(a1.items(), key = lambda x : x[1], reverse = True)
a2_s = sorted(a2.items(), key = lambda x : x[1], reverse = True)

ans = n
for i in range(min(2,len(a1_s))) :
  for j in range(min(2,len(a2_s))) :
    if a1_s[i][0] == a2_s[j][0] :
      continue
    ans = min(ans,n-a1_s[i][1]-a2_s[j][1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

a1 = {}
a2 = {}
for i in range(n) :
  a = v[i]
  if i%2 == 0 :
    if a in a1 :
      a1[a] += 1
    else :
      a1[a] = 1
  if i%2 == 1 :
    if a in a2 :
      a2[a] += 1
    else :
      a2[a] = 1
      
a1_m = max(a1.values())
ans = n-a1_m

a2_l = sorted(a2.items(), key=lambda x:x[1], reverse=True)
keys = [k for k, v in a1.items() if v == a1_m]
for i in range(len(a2)) :
  for key in keys :
    if a2_l[i][0] != key :
      print(ans-a2_l[i][1])
      sys.exit()
      
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

a1 = {}
a2 = {}
for i in range(n) :
  a = v[i]
  if i%2 == 0 :
    if a in a1 :
      a1[a] += 1
    else :
      a1[a] = 1
  if i%2 == 1 :
    if a in a2 :
      a2[a] += 1
    else :
      a2[a] = 1
      
a1_m = max(a1.values())
ans = n-a1_m

a2_l = sorted(a2.items(), key=lambda x:x[1])
keys = [k for k, v in a1.items() if v == a1_m]
for i in range(len(a2)) :
  for key in keys :
    if a2_l[i][0] != key :
      print(ans-a2_l[i][1])
      sys.exit()
      
print(ans)

Submission status: Wrong Answer

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

A=v[0::2]
B=v[1::2]
a=len(A)
b=len(B)

if A==B:
    print(a)
else:    
    if Counter(A).most_common()[0][0] !=Counter(B).most_common()[0][0]:
        s=Counter(A).most_common()[0][1]
        t=Counter(B).most_common()[0][1]
        print( (a-s)+(b-t))
    else:
        o=Counter(A).most_common()[1][1]
        p=Counter(B).most_common()[0][1]
        r= (a-o)+(b-p)
        w=Counter(A).most_common()[0][1]
        x=Counter(B).most_common()[1][1]
        s= (a-w)+(b-x)

        print(min( r, s))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

A=v[0::2]
B=v[1::2]
a=len(A)
b=len(B)

if A==B:
    print(a)
else:    
    if Counter(A).most_common()[0][0] !=Counter(B).most_common()[0][0]:
        s=Counter(A).most_common()[0][1]
        t=Counter(B).most_common()[0][1]
        print( (a-s)+(b-t))
    else:
        r=float("inf")
        s=float("inf")
        if Counter(A).most_common()[0][1] < a:
            o=Counter(A).most_common()[1][1]
            p=Counter(B).most_common()[0][1]
            r= (a-o)+(b-p)
        if Counter(B).most_common()[0][1] < b:
            w=Counter(A).most_common()[0][1]
            x=Counter(B).most_common()[1][1]
            s= (a-w)+(b-x)

        print(min( r, s))

Submission status: Wrong Answer

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import Counter

def main():
    n = II()
    vv = MII()
    ee = Counter(vv[0::2])
    oo = Counter(vv[1::2])
    minv = 10**5
    ee1 = ee.most_common()[0]
    oo1 = oo.most_common()[0]
    if ee1[0] != oo1[0]:
        minv = min(minv, n - (ee1[1] + oo1[1]))
    else:
        ee2 = ee.most_common()[1] if len(ee) > 1 else (0, 0)
        oo2 = oo.most_common()[1] if len(oo) > 1 else (0, 0)
        minv = min(minv, n - (ee1[1] + oo2[1]))
        minv = min(minv, n - (ee2[1] + oo2[1]))
    print(minv)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def split_even_or_odd(vv, n, start):
    res = {}
    for i in range(start,n,2):
        v = vv[i]
        if not v in res.keys(): res[v] = 1
        else: res[v] += 1
    return res

def find_fs(target):
    maxk1 = maxv1 = 0
    for k, v in target.items():
        if maxv1 < v:
            maxk1, maxv1 = k, v
    maxk2 = maxv2 = 0
    for k, v in target.items():
        if maxv2 < v and v < maxv1:
            maxk2, maxv2 = k, v
    return (maxk1, maxv1), (maxk2, maxv2)

def main():
    n = II()
    vv = MII()
    ee = split_even_or_odd(vv, n, 0)
    oo = split_even_or_odd(vv, n, 1)

    e1kv, e2kv = find_fs(ee)
    o1kv, o2kv = find_fs(oo)

    minv = 10**5
    if e1kv[0] != o1kv[0]:
        minv = min(minv, n - (e1kv[1] + o1kv[1]))
    else:
        minv = min(minv, n - (e1kv[1] + o2kv[1]))
        minv = min(minv, n - (e2kv[1] + o1kv[1]))
    print(minv)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
import sys

n = int(input())
vn = list(map(int,input().split()))
vnodd = collections.Counter(vn[1::2]).most_common()
vneven= collections.Counter(vn[0::2]).most_common()

if vnodd[0][0] != vneven[0][0]:
  print(n - (vnodd[0][1] + vneven[0][1]))
else:
  print(n - max(vnodd[0][1], vneven[0][1]))

Submission status: Wrong Answer

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def split_even_or_odd(vv, n, start):
    res = {}
    for i in range(start,n,2):
        v = vv[i]
        if not v in res.keys(): res[v] = 1
        else: res[v] += 1
    return res

def main():
    n = II()
    vv = MII()
    ee = split_even_or_odd(vv, n, 0)
    oo = split_even_or_odd(vv, n, 1)

    total = 0
    cnt = 10**5+100
    maxv = 0; maxk = 0
    for k, v in ee.items():
        if v == n//2: cnt = 0; break
        else:
            cnt = min(cnt, n//2-v)
            if maxv < v:
                maxk = max(maxk, k)
                maxv = v
    total += cnt

    cnt = 10**5+100
    for k, v in oo.items():
        if k == maxk: continue
        if v == n//2: cnt = 0; break
        else: cnt = min(cnt, n//2-v)
    total += cnt

    ans = 0
    if len(oo) == 1 and len(ee) == 1:
        if oo == ee: ans = n//2
    else: ans = total
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def split_even_or_odd(vv, n, start):
    res = {}
    for i in range(start,n,2):
        v = vv[i]
        if not v in res.keys(): res[v] = 1
        else: res[v] += 1
    return res

def count(target, n):
    cnt = 10**5+100
    for k, v in target.items():
        if v == n//2:
            cnt = 0
            break
        else:
            cnt = min(cnt, n//2-v)
    return cnt

def main():
    n = II()
    vv = MII()
    ee = split_even_or_odd(vv, n, 0)
    oo = split_even_or_odd(vv, n, 1)
    e_cnt = count(ee, n)
    o_cnt = count(oo, n)
    ans = 0
    if len(oo) == 1 and len(ee) == 1:
        if oo == ee: ans = n//2
    else: ans = o_cnt + e_cnt
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

cnt = 0
if len(set(v)) < 2:
    cnt += 2
for i in range(n-2):
    if v[i] != v[i+2]:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [int(x) for x in input().split()]
c1 = Counter(v[0::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
  res = n // 2
else:
  if c1.most_common()[0][0] == c2.most_common()[0][0]:
    if c1.most_common()[0][1] >= c2.most_common()[0][1]:
      res = n - c1.most_common()[0][1] - c2.most_common()[1][1]
    else:
      res = n - c1.most_common()[1][1] - c2.most_common()[0][1]
  else:
    res = n - c1.most_common()[0][1] - c2.most_common()[0][1]
print(res)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=list(map(int,input().split()))
cto1,cto2,cte1,cte2=0,0,0,0
fro1,fro2,fre1,fre2=0,0,0,0
ve=v[1::2]
vo=v[::2]
ve.sort()
vo.sort()
ans=0
cnto=collections.Counter(vo)
cnte=collections.Counter(ve)
mco=cnto.most_common()
mce=cnte.most_common()

fro1,cto1=mco[0]
fre1,cte1=mce[0]
if cto1==cte1==n//2:
  if fro1==fre1:
    print(n//2)
  else:
    print(0)
  exit()
elif cto1==n//2:
  if fro1!=fre1:
    print(n//2-cte1)
  else:
    fre2,cte2=mce[1]
    print(n//2-cte2)
  exit()
elif cte1==n//2:
  if fro1!=fre1:
    print(n//2-cto1)
  else:
    fro2,cto2=mco[1]
    print(n//2-cto2)
  exit()



fro2,cto2=mco[1]
fre2,cte2=mce[1]

if fro1==fre1:
  if cto2>=cte2:
    ans=n-cte2-cto1
  else:
    ans=n-cto2-cte1
else:
  ans=n-cto1-cte1


#print(fro1,fro2,fre1,fre2)
#print(cto1,cto2,cte1,cte2)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=list(map(int,input().split()))
cto1,cto2,cte1,cte2=0,0,0,0
fro1,fro2,fre1,fre2=0,0,0,0
ve=v[1::2]
vo=v[::2]
ve.sort()
vo.sort()
ans=0
cnto=collections.Counter(vo)
cnte=collections.Counter(ve)
mco=cnto.most_common()
mce=cnte.most_common()
if mce[0][1]==mco[0][1]==n//2:
  if ve[0]==vo[0]:
    print(n//2)
    exit()
  else:
    print(0)
    exit()
elif mco[0][1]==n//2:
  ans=n//2-mce[0][1]
  print(ans)
  exit()
elif mce[0][1]==n//2:
  ans=n//2-mco[0][1]
  print(ans)
  exit()

fro1,cto1=mco[0]
fro2,cto2=mco[1]
fre1,cte1=mce[0]
fre2,cte2=mce[1]

if fro1==fre1:
  if cto2>=cte2:
    ans=n-cte2-cto1
  else:
    ans=n-cto2-cte1
else:
  ans=n-cto1-cte1


#print(fro1,fro2,fre1,fre2)
#print(cto1,cto2,cte1,cte2)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter 

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

    if len(Counter(v)) == 1:
        print(min(len(v[0::2]), len(v[1::2])))
    else:
        ve = list(Counter(v[0::2]).values())
        vo = list(Counter(v[1::2]).values())
        ve.sort(reverse=True)
        vo.sort(reverse=True)
        ve = sum(ve[1:])
        vo = sum(vo[1:])
        print(ve + vo)

main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    v = list(map(int, input().split()))
    if len(set(v)) == 1:
        print(n//2)
    else:
        a, b = [], []
        for i in range(n):
            if i%2 == 1:
                a.append(v[i])
            else:
                b.append(v[i])
        c = Counter(a)
        c = c.most_common()
        d = Counter(b)
        d = d.most_common()
        if c[0][0] != d[0][0]:
            print(n-c[0][1]-d[0][1])
        else:
            if len(c) == 1:
                if c[0][1] > d[0][1]:
                    print(n-c[0][1]-d[1][1])
                else:
                    print(n-d[0][1])
            elif len(d) == 1:
                if d[0][1] > c[0][1]:
                    print(n-d[0][1]-c[1][1])
                else:
                    print(n-c[0][1])
            else:
                if c[0][1] > d[0][1]:
                    print(n-c[0][1]-d[1][1])
                else:
                    print(n-c[1][1]-d[0][1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    v = list(map(int, input().split()))
    if len(set(v)) == 1:
        print(n//2)
    else:
        a, b = [], []
        for i in range(n):
            if i%2 == 1:
                a.append(v[i])
            else:
                b.append(v[i])
        c = Counter(a)
        c = c.most_common()
        d = Counter(b)
        d = d.most_common()
        if c[0][0] != d[0][0]:
            print(n-c[0][1]-d[0][1])
        else:
            if len(c) == 1:
                print(n-c[0][1]-d[1][1])
            elif len(d) == 1:
                print(n-c[1][1]-d[0][1])
            else:
                if c[0][1] > d[0][1]:
                    print(n-c[0][1]-d[1][1])
                else:
                    print(n-c[1][1]-d[0][1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    v = list(map(int, input().split()))
    if len(set(v)) == 1:
        print(n//2)
    else:
        a, b = [], []
        for i in range(n):
            if i%2 == 1:
                a.append(v[i])
            else:
                b.append(v[i])
        c = Counter(a)
        c = c.most_common()
        d = Counter(b)
        d = d.most_common()
        
        print(n-c[0][1]-d[0][1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    n, *v = map(int, open(0).read().split())

    if len(set(v)) == 1:
        ans = n//2
        print(ans)
        return

    ans = 0
    for i in (0,1):
        w = v[i::2]
        x = Counter(w)
        y = list(x.values())
        if len(set(w)) != 1:
            ans += sum(y[1:])
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

    c_even = sorted(Counter(v[::2]).items(), key=lambda x: x[1],reverse=True)
    c_odd  = sorted(Counter(v[1::2]).items(), key=lambda x: x[1],reverse=True)
    if c_even[0][0] == c_odd[0][0]:
        if c_even[0][1] == c_odd[0][1] == n//2:
            print(n//2)
        elif c_even[0][1] >= c_odd[0][1]:
            print(n - c_even[0][1] - c_odd[1][1])
        else:
            print(n - c_even[1][1] - c_odd[0][1])
    else:
        print(n - c_even[0][1] - c_odd[0][1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

    c_even = sorted(Counter(v[::2]).items(), key=lambda x: x[1],reverse=True)
    c_odd  = sorted(Counter(v[1::2]).items(), key=lambda x: x[1],reverse=True)
    if c_even[0][0] == c_odd[0][0]:
        print(n//2)
    else:
        print(n - c_even[0][1] - c_odd[0][1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
kisu = []
gusu = []
flag = True
for el in v:
    if flag:
        kisu.append(el)
    else:
        gusu.append(el)
    flag = not flag
a = Counter(kisu)
b = Counter(gusu)
a_max = list(a.values())[0]
b_max = list(b.values())[0]
if list(a.keys())[0] == list(b.keys())[0]:
    a_max2 = list(a.values())[1] if len(a) > 1 else 0
    b_max2 = list(b.values())[1] if len(b) > 1 else 0
    if a_max+b_max2 < a_max2+b_max:
        a_max = a_max2
    else:
        b_max = b_max2
print(len(v)-a_max-b_max)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
kisu = []
gusu = []
flag = True
for el in v:
    if flag:
        kisu.append(el)
    else:
        gusu.append(el)
    flag = not flag
a = Counter(kisu)
b = Counter(gusu)
a_max = list(a.values())[0]
b_max = list(b.values())[0]
if list(a.keys())[0] == list(b.keys())[0]:
    if len(a)==1 and len(b)==1:
        a_max = 0
    elif len(a) == 1:
        b_max = list(b.values())[1]
    elif len(b) == 1:
        a_max = list(a.values())[1]
    else:
        a_max2 = list(a.values())[1]
        b_max2 = list(b.values())[1]
        if a_max+b_max2 < a_max2+b_max:
            a_max = a_max2
        else:
            b_max = b_max2
print(len(v)-a_max-b_max)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
kisu = []
gusu = []
flag = True
for el in v:
    if flag:
        kisu.append(el)
    else:
        gusu.append(el)
    flag = not flag
a = Counter(kisu)
b = Counter(gusu)
a_max = list(a.values())[0]
b_max = list(b.values())[0]
if list(a.keys())[0] == list(b.keys())[0]:
    if a_max > b_max:
        b_max = list(b.values())[1]
    elif a_max < b_max:
        a_max = list(a.values())[1]
    else:
        if len(a) == 1 and len(b) == 1:
            a_max = 0
        else:
            a_max2 = list(a.values())[1]
            b_max2 = list(b.values())[1]
            if a_max2 < b_max2:
                b_max = b_max2
            else:
                a_max = a_max2
print(len(v)-a_max-b_max)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
kisu = []
gusu = []
flag = True
for el in v:
    if flag:
        kisu.append(el)
    else:
        gusu.append(el)
    flag = not flag
a = Counter(kisu)
b = Counter(gusu)
a_max = list(a.values())[0]
b_max = list(b.values())[0]
if list(a.keys())[0] == list(b.keys())[0]:
    if a_max > b_max:
        if len(b) < 2:
            b_max = 0
        else:
            b_max = list(b.values())[1]
    elif a_max < b_max:
        if len(a) < 2:
            a_max = 0
        else:
            a_max = list(a.values())[1]
    else:
        if len(a) == 1 and len(b) == 1:
            a_max = 0
        elif len(a) == 1:
            b_max = list(b.values())[1]
        elif len(b) == 1:
            a_max = list(a.values())[1]
        else:
            a_max2 = list(a.values())[1]
            b_max2 = list(b.values())[1]
            if a_max2 < b_max2:
                b_max = b_max2
            else:
                a_max = a_max2
print(len(v)-a_max-b_max)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
kisu = []
gusu = []
flag = True
for el in v:
    if flag:
        kisu.append(el)
    else:
        gusu.append(el)
    flag = not flag
a = Counter(kisu)
b = Counter(gusu)
a_max = list(a.values())[0]
b_max = list(b.values())[0]
if list(a.keys())[0] == list(b.keys())[0]:
    if a_max > b_max:
        if len(a) < 2:
            a_max = 0
        else:
            a_max = list(a.values())[1]
    elif a_max < b_max:
        if len(b) < 2:
            b_max = 0
        else:
            b_max = list(b.values())[1]
    else:
        if len(a) == 1 and len(b) == 1:
            a_max = 0
        elif len(a) == 1:
            b_max = list(b.values())[1]
        elif len(b) == 1:
            a_max = list(a.values())[1]
        else:
            a_max2 = list(a.values())[1]
            b_max2 = list(b.values())[1]
            if a_max2 < b_max2:
                b_max = b_max2
            else:
                a_max = a_max2
print(len(v)-a_max-b_max)