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: Runtime Error

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1

#ソートして一番目、二番目を見る
odd_sorted  = sorted(odd.items(), key = lambda x : -x[1])
even_sorted  = sorted(even.items(), key = lambda x : -x[1])


candidate_odd = []
candidate_even = []

candidate_odd.append



def count_rewrite(odd, even):
    ans = 0
    for i in range(len(v)):
        if i % 2:
            if v[i] != ans_odd:
                ans += 1
        else:
            if v[i] != ans_even:
                ans += 1
    return ans


ans = 100002
#候補が同じ場合
if odd_sorted[0][0] == even_sorted[0][0]:
    #奇数も偶数も2番目が存在する？
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        ans = min(ans, count_rewrute(odd_sorted[0][0], even_sorted[1][0]))
        ans = min(ans, count_rewrute(odd_sorted[1][0], even_sorted[0][0]))
    #お互いに二番目が存在しない(ただし数は必ず一致するのでどちらか)
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    #奇数に2番目が存在しない
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    #偶数に2番目が存在しない
    else: #len(even.keys()):
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1


print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
l = input().split()
v = [sorted([int(l[2 * i]) for i in range(n // 2)]).append(-1), \
sorted([int(l[2 * i + 1]) for i in range(n // 2)]).append(-1)]

cnt = [1, 1]
m = [[0, 0], [0, 0]]
num = [0, 0]
for i in range(n // 2):
    for j in range(2):
        if (v[j][i] == v[j][i + 1]):
            cnt[j] += 1
        else:
            if (m[j][0] <= cnt[j]):
                m[j][1] = m[j][0]
                m[j][0] = cnt[j]
                num[j] = v[j][i]
            cnt[j] = 1

out = n - (m[0][0] + m[1][0])
if (num[0] == num[1]):
    out += min(m[0][0] - m[0][1], m[1][0] - m[1][1])
print(out)

Submission status: Runtime Error

Solution code:
from collections import OrderedDict
n = int(input())

v = [int(x) for x in input().split()]

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(v[i],0)
        odd[v[i]] += 1
    else:
        even.setdefault(v[i],0)
        even[v[i]] += 1


oddl = OrderedDict(sorted(odd.items(),key = lambda x: x[1],reverse=True))
evenl = OrderedDict(sorted(even.items(),key = lambda x: x[1],reverse=True))


ok = [x for x in oddl.keys()]
ov  = [x for x in oddl.values()]
ek = [x for x in evenl.keys()]
ev = [x for x in evenl.values()]


if ok[0] != ek[0]:
    res1 = n - ov[0] - ev[1]
    res2 = n - ov[1] - ev[0]
    if res1 >= res2 :
        res = res2
    else:
        res = res1
else:
    res = n-ov[0]-ev[0]
    
print(res)

Submission status: Runtime Error

Solution code:
from collections import OrderedDict
n = int(input())

v = [int(x) for x in input().split()]

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(v[i],0)
        odd[v[i]] += 1
    else:
        even.setdefault(v[i],0)
        even[v[i]] += 1


oddl = OrderedDict(sorted(odd.items(),key = lambda x: x[1],reverse=True))
evenl = OrderedDict(sorted(even.items(),key = lambda x: x[1],reverse=True))


ok = [x for x in oddl.keys()]
ov  = [x for x in oddl.values()]
ek = [x for x in evenl.keys()]
ev = [x for x in evenl.values()]


if ok[0] != ek[0]:
    print(n - ov[0] - ev[0])
elif ov[0] > ev[0]:
    if (len(ov) == 1 and len(ev) != 1):
        print(int(n - n / 2 - ev[0]))
    elif (len(ev) == 1 and len(ov) != 1):
        print(int(n - (n / 2) - ov[0]))
    elif (len(ov) == 1 and len(ev) == 1):
        print(int(n - n / 2))
    print(n-ov[0]-ev[1])
else:
    if (len(ov) == 1 and len(ev) != 1):
        print(int(n - n / 2 - ev[0]))
    elif (len(ev) == 1 and len(ov) != 1):
        print(int(n - (n / 2) - ov[0]))
    elif (len(ov) == 1 and len(ev) == 1):
        print(int(n - n / 2))
    print(n-ov[1]-ev[0])

Submission status: Runtime Error

Solution code:
from collections import OrderedDict
n = int(input())

v = [int(x) for x in input().split()]

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(v[i],0)
        odd[v[i]] += 1
    else:
        even.setdefault(v[i],0)
        even[v[i]] += 1


oddl = OrderedDict(sorted(odd.items(),key = lambda x: x[1],reverse=True))
evenl = OrderedDict(sorted(even.items(),key = lambda x: x[1],reverse=True))


ok = [x for x in oddl.keys()]
ov  = [x for x in oddl.values()]
ek = [x for x in evenl.keys()]
ev = [x for x in evenl.values()]


if ok[0] != ek[0]:
    print(n - ov[0] - ev[0])
elif ov[0] > ev[0]:
    if (len(ov) == 1 and len(ev) != 1):
        print(n - n / 2 - ev[0])
    elif (len(ev) == 1 and len(ov) != 1):
        print(n - (n / 2) - ov[0])
    elif (len(ov) == 1 and len(ev) == 1):
        print(n - n / 2)
    print(n-ov[0]-ev[1])
else:
    if (len(ov) == 1 and len(ev) != 1):
        print(n - n / 2 - ev[0])
    elif (len(ev) == 1 and len(ov) != 1):
        print(n - (n / 2) - ov[0])
    elif (len(ov) == 1 and len(ev) == 1):
        print(n - n / 2)
    print(n-ov[1]-ev[0])

Submission status: Runtime Error

Solution code:
from collections import OrderedDict
n = int(input())

v = [int(x) for x in input().split()]

odd = OrderedDict()
even = OrderedDict()

for i in range(len(v)):
    if (i % 2 == 1):
        odd.setdefault(v[i],0)
        odd[v[i]] += 1
    else:
        even.setdefault(v[i],0)
        even[v[i]] += 1


oddl = OrderedDict(sorted(odd.items(),key = lambda x: x[1],reverse=True))
evenl = OrderedDict(sorted(even.items(),key = lambda x: x[1],reverse=True))


ok = [x for x in oddl.keys()]
ov  = [x for x in oddl.values()]
ek = [x for x in evenl.keys()]
ev = [x for x in evenl.values()]

if ok[0] != ek[0]:
    print(n - ov[0] - ev[0])
elif ov[0] > ev[0]:
    print(n-ov[0]-ev[1])
else:
    print(n-ov[1]-ev[0])

Submission status: Runtime Error

Solution code:
import collections

def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    v_odd = [j for i,j in enumerate(v) if i%2==1]
    v_even = [j for i,j in enumerate(v) if i%2==0]

    v_count = collections.Counter(v)
    #すべて同じ数字
    if(len(v_count)==1):
        return print(int(n/2))
    #異なる数字の時
    elif(len(v_count)!=1):
        
        
        v_odd_max = collections.Counter(v_odd).most_common()[0]
        v_even_max = collections.Counter(v_even).most_common()[0]
        if(v_odd_max[0] != v_even_max[0]):
            return print(int(n/2-v_odd_max[1])+int(n/2-v_even_max[1]))
        else:
            a = v_even.most_common()[1]
            return print(int(n/2-v_odd_max[1])+int(n/2-a[1]))
solve()

Submission status: Runtime Error

Solution code:
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif (ca[0][1] < cb[0][1]) :
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    s += na + nb - max(cb[0][1]+ca[1][1],ca[0][1]+cb[1][1])
    
print (s)

Submission status: Runtime Error

Solution code:
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif ( ca[0][1] < cb[0][1]   ):
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    s += na - ca[0][1] + nb - min(ca[1][1],cb[1][1])
print (s)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a1 = {}
a2 = {}

for i in range(0,n//2+1,2):
    if str(a[i]) in a1.keys():
        a1[str(a[i])] += 1
    else :
        a1[str(a[i])] = 1
    if str(a[i+1]) in a2.keys():
        a2[str(a[i+1])] += 1
    else :
        a2[str(a[i+1])] = 1

a1 = sorted(a1.items(), key=lambda x: -x[1])
a2 = sorted(a2.items(), key=lambda x: -x[1])

if a1[0][0] == a2[0][0]:
    print(n-max(a1[0][1]+a2[1][1],a1[1][1]+a2[0][1]))
else :
    print(n-a1[0][1]-a2[0][1])

Submission status: Runtime Error

Solution code:
n=int(input())
arr=map(int,input().split())
from collections import Counter
even=Counter(arr[::2])
even[0]=0
odd=Counter(arr[1::2])
odd[0]=0
even1,even2=even.most_common(2)
odd1,odd2=odd.most_common(2)
if even1[0]!=odd1[0]:
  print(n-(even1[1]+odd1[1]))
else:
  print(n-max(even1[1]+odd2[1],even2[1]+odd1[1]))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

e = Counter(v[::2]).most_common(2)
o = Counter(v[1::2]).most_common(2)

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

a_dict = {}
b_dict = {}

for i in range(n//2):
    a = v[2*i]
    b = v[2*i+1]
    if not a in a_dict.keys():
        a_dict[a] = 0
    if not b in b_dict.keys():
        b_dict[b] = 0
        
    a_dict[a] +=1
    b_dict[b] +=1
    
if len(a_dict) == 1 and len(b_dict) ==1 and list(a_dict.keys()) != list(b_dict.keys()):
    print(0)
    return
    
    
a_val= sorted(a_dict.items(), key=lambda x:x[1], reverse=True)
b_val = sorted(b_dict.items(), key=lambda x:x[1], reverse=True)

def sum_val(val):
    ret =0
    if len(val) >= 1:
        for it in val:
            ret += it[1]
    return ret

ret = 0
if a_val[0][0] != b_val[0][0]:
    ret += sum_val(a_val[1:])
    ret += sum_val(b_val[1:])
    print(ret)
elif a_val[0][1] > b_val[0][1]:
    ret += sum_val(a_val[1:])
    ret += sum_val(b_val[:1])
    ret += sum_val(b_val[2:])
    print(ret)
return

Submission status: Runtime Error

Solution code:
#coding: utf-8
from collections import Counter
N = int(input())
l = list(map(int,input().split()))
if len(set(l)) > 1:
  o, e = [], []
  for i in range(N):
    if i % 2==0:
      e.append(l[i])
    else:
      o.append(l[i])
  oc, oe = Counter(o).most_common(2), Counter(e).most_common(2)
  print(len(l) - oc[0][1] - oe[0][1] if oc[0][1] != oe[0][1] else len(l) - max(oc[0][1] + oe[1][1], oc[1][1] + oe[0][1]))

else:
  print(len(l) // 2)

Submission status: Runtime Error

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=m[::2]
b=m[1::2]
aa={}
bb={}
for i in range(n//2):
  if not a[i] in aa:
    aa[a[i]]=0
  aa[a[i]]+=1
  if not b[i] in bb:
    bb[b[i]]=0
  bb[b[i]]+=1
aaa=list(aa.values())
aaa.sort(reverse=True)
bbb=list(bb.values())
bbb.sort(reverse=True)
if not max(aa)==max(bb):
  print(n-aaa[0]-bbb[0])
else:
  print(min(n-aaa[1]-bbb[0],n-aaa[0]-bbb[1]))

Submission status: Runtime Error

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=m[::2]
b=m[1::2]
aa={}
bb={}
for i in range(n//2):
  if not a[i] in aa:
    aa[a[i]]=0
  aa[a[i]]+=1
  if not b[i] in bb:
    bb[b[i]]=0
  bb[b[i]]+=1
aaa=aa.values().sorted(reverse=True)
bbb=bb.values().sorted(reverse=True)
if not max(aa)==max(bb):
  print(n-aaa[0]-bbb[0])
else:
  print(min(n-aaa[1]-bbb[0],n-aaa[0]-bbb[1]))

Submission status: Runtime Error

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=m[::2]
b=m[1::2]
aa={}
bb={}
for i in range(n//2):
  if not a[i] in aa:
    aa[a[i]]=0
  aa[a[i]]+=1
  if not b[i] in bb:
    bb[b[i]]=0
  bb[b[i]]+=1
aaa=aa.values().sorted(reverse=True)
bbb=bb.values().sorted(reverse=True)
if not max(aa)==max(bb):
  print(n-aaa[0]-bbb[0])
else:
  print(min(n-aaa[1]-bbb[0],n-aaa[0]-bbb[1])

Submission status: Runtime Error

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=m[::2]
b=m[1::2]
aa={}
bb={}
for i in range(n//2):
  if not a[i] in aa:
    aa[a[i]]=0
  aa[a[i]]+=1
  if not b[i] in bb:
    bb[b[i]]=0
  bb[b[i]]+=1
aaa=aa.values().sort(reverse=True)
bbb=bb.values().sort(reverse=True)
if not max(aa)==max(bb):
  print(n-aaa[0]-bbb[0])
else:
  print(min(n-aaa[1]-bbb[0],n-aaa[0]-bbb[1])

Submission status: Runtime Error

Solution code:
n=int(input())
m=list(map(int,input().split()))
a=m[::2]
b=m[1::2]
aa={}
bb={}
for i in range(n//2):
  if not a[i] in aa:
    aa[a[i]]=0
  aa[a[i]]+=1
  if not b[i] in bb:
    bb[b[i]]=0
  bb[b[i]]+=1
if not max(aa)==max(bb):
  print(n-max(aa.values())-max(bb.values()))
else:
  print(min(n-max(aa.values())-bb.values().sort(reverse=1)[1],n-aa.values().sort(reverse=1)[1]-max(bb.values()))

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=v[0::2]
b=v[1::2]
c=dict()
d=dict()

for i in a:
  if i in c:
    c[i]+=1
  else:
    c[i]=1
for j in b:
  if j in d:
    d[j]+=1
  else:
    d[j]=1

e=sorted([[w,v] for v,w in c.items()],reverse=True)
f=sorted([[w,v] for v,w in d.items()],reverse=True)

if e[0][1]!=f[0][1]:
  print(n-e[0][0]-f[0][0])
elif e[0][0]>f[0][0]:
  print(n-e[0][0]-f[1][0])
elif e[0][0]<f[0][0]:
  print(n-e[1][0]-f[0][0])
elif e[0][0]==f[0][0] and e[0][1]==f[0][1]:
  if e[1][0]>f[1][0]:
    print(n-e[1][0]-f[0][0])
  else:
    print(n-e[0][0]-f[1][0])

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    v = LI()
    d = [defaultdict(int) for i in range(2)]
    for i in range(n):
        d[i%2][v[i]] += 1
    if len(d[0].keys()) == len(d[1].keys()) == 1:
        if d[0].keys() == d[1].keys():
            ans = n//2
    else:
        d = [list(d[i].values()) for i in range(2)]
        ans = sum(d[0])-max(d[0])+sum(d[1])-max(d[1])
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=v[0::2]
b=v[1::2]
c=dict()
d=dict()

for i in a:
  if i in c:
    c[i]+=1
  else:
    c[i]=1
for j in b:
  if j in d:
    d[j]+=1
  else:
    d[j]=1

e=sorted([[c,v] for v,c in c.items()],reverse=True)
f=sorted([[c,v] for v,c in d.items()],reverse=True)

if e[0][1]!=f[0][1]:
  print(n-e[0][0]-f[0][0])
elif e[0][0]>f[0][0]:
  print(n-e[0][0]-f[1][0])
else:
  print(n-e[1][0]-f[0][0])

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=v[0::2]
b=v[1::2]
c=dict()
d=dict()

for i in a:
  if i in c:
    c[i]+=1
  else:
    c[i]=1
for j in d:
  if j in d:
    d[j]+=1
  else:
    d[j]=1

e=sorted([[c,v] for v,c in c.items()],reverse=True)
f=sorted([[c,v] for v,c in d.items()],reverse=True)

if e[0][1]!=f[0][1]:
  print(n-e[0][0]-f[0][0])
elif e[0][0]>f[0][0]:
  print(n-e[0][0]-f[1][0])
else:
  print(n-e[1][0]-f[0][0])

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
c=dict()
d=dict()

for i in range(0,n,2):
  a.append(v[i])
  if v[i] in c:
    c[v[i]]+=1
  else:
    c[v[i]]=1
    
for j in range(1,n,2):
  b.appene(v[j])
  if v[i] in d:
    d[v[i]]+=1
  else:
    d[v[i]]=1

c_max=c.pop(c.value(max(c.value())))
c_max2=c.pop(c.value(max(c.value())))
d_max=d.pop(d.value(max(d.value())))
d_max2=d.pop(d.value(max(d.value())))
    
if :
  print(n-c_max-d_max)
else:
  if c_max>d_max:
    print(n-c_max-d_max2)
  else:
    print(n-c_max2-d_max)

Submission status: Runtime Error

Solution code:
N=int(input())
V=[int(x) for x in input().split()]
A=[[n,0] for n in range(10**5)]
B=[[n,0] for n in range(10**5)]
for i in range(len(V)):
    if (i % 2 == 0):
        A[V[i]][1]+=1
    else:
        B[V[i]][1]+=1

def sortsecond(i):
    return i[1]

A.sort(key=sortsecond, reverse=True)
B.sort(key=sortsecond, reverse=True)
a=A[0]
b=B[0]
if a[0]==b[0]:
    if A[1][1]+B[1][1]==0:
        b[1]=0
    elif a[1]>b[1]:
        b=B[1]
    else:
        a=A[1]

print(len(V)-a[1]-b[1])

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a).most_common()[:3]

if len(c) != 2:
    print(n-c[0][1]-c[1][1])
else:
    print(int((c[0][1] - c[1][1]) /2))

Submission status: Runtime Error

Solution code:
from statistics import mode
n = int(input())
vlist = list(map(int, input().split()))


a = vlist[::2]
b = vlist[1::2]

freq_a = mode(a)
freq_b = mode(b)


x = len(a) - freq_a
y = len(b) - freq_b


if len(set(vlist)) == 1:
    print(min(len(a), len(b)))
else:
    print(x+y)

Submission status: Runtime Error

Solution code:
from statistics import mode
n = int(input())
vlist = list(map(int, input().split()))


a = vlist[::2]
b = vlist[1::2]

freq_a = mode(a)
freq_b = mode(b)


x = len(a) - freq_a
y = len(b) - freq_b

print(a)
print(b)
print(freq_a)
print(freq_b)

if len(set(vlist)) == 1:
    print(min(len(a), len(b)))
else:
    print(x+y)

Submission status: Runtime Error

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

a = max(vlist[::2])
b = max(vlist[1::2])

x = len(a) - vlist[::2].count(a)
y = len(b) - vlist[1::2].count(b)

print(x+y)

Submission status: Runtime Error

Solution code:
from collections import*
n,*v=open(0).read().split()
n=int(n)
a=[v[s]for s in range(0,n,2)]
b=[v[s]for s in range(1,n,2)]
#print(Counter(a).most_common(),Counter(b).most_common())
c=Counter(a).most_common()
d=Counter(b).most_common()
if c[0][1]!=d[0][1]:
  print(sum([s[1]for s in c[1:]])+sum([s[1]for s in d[1:]]))
else:
  if len(c)and len(d)==1:
    if c==d:
      print(n//2)
    else:
      print(0)
  else:
    x=sum([s[1]for s in c[1:]])+sum(d[0][1]+[s[1]for s in d[2:]])
    y=sum([s[1]for s in d[1:]])+sum(c[0][1]+[s[1]for s in c[2:]])
    print(min(x,y))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import Counter

n = input()
v = input()
v = [int(i) for i in v.split(" ")]
odd_v = v[::2]
even_v = v[1::2]
m = int(n) / 2


count_odd_v = dict(Counter(odd_v))
count_even_v = dict(Counter(even_v))

o_idx1, o_cnt1 = sorted(count_odd_v.items(), key=lambda x: x[1])[0]
e_idx1, e_cnt1 = sorted(count_even_v.items(), key=lambda x: x[1])[0]

nb_change = 0
if len(count_even_v) == 1 and len(count_odd_v) == 1:
    if o_idx1 == e_idx1:
        nb_change += m
    else:
        nb_change += 0
elif len(count_even_v) == 1:
    nb_change += m - o_cnt1
elif len(count_odd_v) == 1:
    nb_change += m - e_cnt1
else:
    o_idx2, o_cnt2 = sorted(count_odd_v.items(), key=lambda x: x[1])[1]
    e_idx2, e_cnt2 = sorted(count_even_v.items(), key=lambda x: x[1])[1]

    # どちらの数列も同じ数字で、数が違った場合
    if o_idx1 == e_idx1:
        if o_cnt1 < e_cnt1:
            nb_change += m - e_cnt1 # even count
            nb_change += m - o_cnt2 # odd count
        elif e_cnt1 < o_cnt1:
            nb_change += m - e_cnt2  # even count
            nb_change += m - o_cnt1  # odd count
        elif o_cnt1 == e_cnt1:
            if o_cnt2 < e_cnt2:
                nb_change += m - e_cnt2 # even count
                nb_change += m - o_cnt1 # even count
            elif o_cnt2 <= e_cnt2:
                nb_change += m - o_cnt2  # even count
                nb_change += m - e_cnt1  # even count
    elif o_idx1 != e_idx1:
        nb_chagne += m - e_cnt1
        nb_chagne += m - o_cnt1

print(int(nb_change))

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import Counter

n = input()
v = input()
v = [int(i) for i in v.split(" ")]
odd_v = v[::2]
even_v = v[1::2]


count_odd_v = dict(Counter(odd_v))
count_even_v = dict(Counter(even_v))


max_odd = -1e+100
max_odd_idx = 0
for k, v in count_odd_v.items():
    if max(v, max_odd) == v:
        max_odd = v
        max_odd_idx = k

max_even = -1e+100
max_even_idx = 0
for k, v in count_even_v.items():
    if max(v, max_even) == v:
        max_even = v
        max_even_idx = k

should_change_odd = None

if max_odd_idx == max_even_idx:
    if max_odd <= max_even:
        should_change_odd = True
    else:
        should_change_odd = False

nb_change = 0
m = int(n) / 2

if should_change_odd is None:
    nb_change += m - max_odd
    nb_change += m - max_even
elif should_change_odd is True:
    # 2nd largest item
    if len(counter_odd.items()) == 1:
        if len(counter_even.items()) == 1:
            nb_change += m
        else:
            s = sorted(counter_even.items(), key=lambda x: x[1])[0][1]
            nb_change += m - s
    else:
        s = sorted(counter_odd.items(), key=lambda x:x[1])[0][1]
        nb_change += m - s
        nb_change += m - max_even
elif should_change_odd is False:
    # 2nd largest item
    if len(counter_even.items()) == 1:
        if len(counter_odd.items()) == 1:
            nb_change += m
        else:
            s = sorted(counter_odd.items(), key=lambda x: x[1])[0][1]
            nb_change += m - s
    else:
        s = sorted(counter_even.items(), key=lambda x: x[1])[0][1]
        nb_change += m - s
        nb_change += m - max_odd

print(int(nb_change))

Submission status: Runtime Error

Solution code:
n = input()

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


odd_v = v[::2]
even_v = v[1::2]

counter_odd = {}

for i in odd_v:
    if not i in counter_odd:
        counter_odd[i] = 1
    else:
        counter_odd[i] += 1

counter_even = {}
for i in even_v:
    if not i in counter_even:
        counter_even[i] = 1
    else:
        counter_even[i] += 1


max_odd = -1e+100
max_odd_idx = 0
for k, v in counter_odd.items():
    if max(v, max_odd) == v:
        max_odd = v
        max_odd_idx = k


max_even = -1e+100
max_even_idx = 0
for k, v in counter_even.items():
    if max(v, max_even) == v:
        max_even = v
        max_even_idx = k

should_change_odd = None

if max_odd_idx == max_even_idx:
    if max_odd <= max_even:
        should_change_odd = True
    else:
        should_change_odd = False

nb_change = 0
m = int(n) / 2

if should_change_odd is None:
    nb_change += m - max_odd
    nb_change += m - max_even
elif should_change_odd is True:
    # 2nd largest item
    if len(counter_odd.items()) == 1:
        nb_change += m
    else:
        s = sorted(counter_odd.items(), key= lambda x:x[1])[1]
        nb_change += m - s
        nb_change += m - max_even
elif should_change_odd is False:
    # 2nd largest item
    if len(counter_even.items()) == 1:
        nb_change += m
    else:
        s = sorted(counter_even.items(), key=lambda x: x[1])[1]
        nb_change += m - s
        nb_change += m - max_odd

print(int(nb_change))

Submission status: Runtime Error

Solution code:

import sys
from collections import *

n = int(input())
v = [int(x) for x in input().split()]

if not n:
    print(0)
    sys.exit()

n1 = Counter(v[::2])
n2 = Counter(v[1::2])

max1 = 0

n1 = sorted([(count, k) for k, count in n1.items()], reverse=True)
n2 = sorted([(count, k) for k, count in n2.items()], reverse=True)

if n1[0][1] == n2[0][1]:
    if len(n1) == 1 and len(n2) == 1:
        print(n//2)
        sys.exit()
    if len(n1) == 1 or n1[0][0] > n2[0][0]:
        print(n - n1[0][0] - n2[1][0])
        sys.exit()
    if len(n2) == 1 or n1[0][0] < n2[0][0]:
        print(n - n1[1][0] - n2[0][0])
        sys.exit()
    if n1[0][0] == n2[0][0]:
        if n1[1][0] >= n2[1][0]:
            print(n - n1[1][0] - n2[0][0])
        elif n1[1][0] < n2[1][0]:
            print(n - n1[0][0] - n2[1][0])
        sys.exit()

count = n1 - n1[0][0] - n2[0][0]
print(count)

Submission status: Runtime Error

Solution code:
from sys import stdin
import collections

n, v_list = stdin.readlines()
n = int(n.rstrip())
v_list = [int(v) for v in v_list.rstrip().split()]
#print(n, v_list)

v_list_odd  = [v_list[i] for i in range(1, n, 2)]
v_list_even = [v_list[i] for i in range(0, n, 2)]

c_odd  = collections.Counter(v_list_odd)
c_even = collections.Counter(v_list_even)

most_common_odd  = c_odd.most_common()
most_common_even = c_even.most_common()
#print(most_common_even)
#print(most_common_odd)

if most_common_odd[0][0] == most_common_even[0][0]:
  case1 = (n/2-most_common_odd[0][1]) + (n/2-most_common_even[1][1])
  case2 = (n/2-most_common_odd[1][1]) + (n/2-most_common_even[0][1])
  if case1 > case2:
    print(case2)
  else:
    print(case1)
else:
  odd_cnt  = most_common_odd[0][1]
  even_cnt = most_common_even[0][1]
  print(n-odd_cnt-even_cnt)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
nums = [int(each) for each in input().split()]
oddD = defaultdict(int)
evenD = defaultdict(int)
for i in range(len(nums)):
  if((i+1) % 2==0):
    evenD[nums[i]] += 1
  else:
    oddD[nums[i]] += 1
evenD_list = []
oddD_list = []
for key in evenD.keys():
  evenD_list.append([key, evenD[key]])
for key in oddD.keys():
  oddD_list.append([key,oddD[key]])
evenD_list.sort(key=lambda x :x[1])
oddD_list.sort(key=lambda x : x[1])
i = 0
j = 0
while(i < len(evenD_list) and j < len(oddD_list)):
  e_value, e_num = evenD_list[i]
  o_value, o_num = oddD_list[j]
  if(e_value == o_value):
    if(e_num < o_num):
      i += 1
    else:
      j += 1
  else:
    break
e_value, e_num = evenD_list[i]
o_value, o_num =oddD_list[j]
if(e_value == o_value):
  return n/2-max(e_num,o_num) + n/2
else:
  return n/2 - e_num + n/2 -o_num

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
print(a.most_common()[0]==b.most_common()[0])
print(len(list_1),a.most_common()[0][1])
if ((a.most_common()==b.most_common()) & a.most_common()[0][1]==len(list_1)):#２つの数列の全要素が一致する場合どちらかの数字を変更
  print('test1')
  print(n//2)
elif(a.most_common()[0]==b.most_common()[0]):#2つの数列の最大をとる数が等しい場合どちらかは最大個数の数に、もう１つはその次に多い数に置き換える。
  print('test2')
  print(n-a.most_common()[0][1]-b.most_common()[1][1])
else:
  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
#print(a.most_common()[0]==b.most_common()[0])
#print(len(list_1),a.most_common()[0][1])
if ((a.most_common()[0]==b.most_common()[0]) & a.most_common()[0][1]==len(list_1)):#２つの数列の各要素が一致する場合どちらかの数字を変更
  #print('test1')
  print(n//2)
elif(a.most_common()[0]==b.most_common()[0]):#2つの数列の最大をとる数が等しい場合どちらかは最大個数の数に、もう１つはその次に多い数に置き換える。
  #print('test2')
  print(n-a.most_common()[0][1]-b.most_common()[1][1])
  
else:
  #print(a)
  #print(b)
  #print(a.most_common())
  #print(b.most_common())
  #print(a.most_common()[0][1])
  #print(b.most_common()[0][1])

  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
if (a.most_common()==b.most_common()):
  print(n//2)
elif(a.most_common()[0]==b.most_common()[0]):
  print(n-a.most_common()[0]-b.most_common()[1][1])
else:
  #print(a)
  #print(b)
  #print(a.most_common())
  #print(b.most_common())
  #print(a.most_common()[0][1])
  #print(b.most_common()[0][1])

  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
#print(a)
#print(b)
#print(a.most_common())
#print(b.most_common())
if (list_1[0]==list_2[0] & all(list_1) & all(list_2)):
  print(n//2)
elif (a.most_common==b.most>common):
  print(n//2)
else:
  #print(a.most_common()[0][1])
  #print(b.most_common()[0][1])
  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
if (list_1[0]==list_2[0] & all(list_1) & all(list_2)):
  print(n//2)
  #print(list_1)
  #print(list_2)
  a=collections.Counter(list_1)
  b=collections.Counter(list_2)
elif(a==b):
  print(n//2)
else
  #print(a)
  #print(b)
  #print(a.most_common())
  #print(b.most_common())
  #print(a.most_common()[0][1])
  #print(b.most_common()[0][1])
  print(n-a.most_common()[0][1]-b.most_common()[0][1])

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
list=list(map(int,input().split()))
#print(list)
list_1=list[::2]
list_2=list[1::2]
if (list_1==list_2):
  print(n//2)
  break
#print(list_1)
#print(list_2)
a=collections.Counter(list_1)
b=collections.Counter(list_2)
#print(a)
#print(b)
#print(a.most_common())
#print(b.most_common())
#print(a.most_common()[0][1])
#print(b.most_common()[0][1])

print(n-a.most_common()[0][1]-b.most_common()[0][1])