TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):

import collections
def myAnswer(N:int,V:list) -> int:
   odd = []
   even = []
   if len(set(V)) == 1:
      return N//2

   for n,v in enumerate(V):
      even.append(v) if n % 2 == 0 else odd.append(v)
   
   oddCounter = collections.Counter(odd)
   evenCounter = collections.Counter(even)
   oddCounter = sorted(oddCounter.items(),key=lambda x:x[1])
   evenCounter = sorted(evenCounter.items(),key=lambda x:x[1])
   oddMAX = oddCounter[-1][0]
   evenMAX = evenCounter[-1][0]
   if oddMAX == evenMAX:
      evenLen = len(evenCounter)
      oddLen = len(oddCounter)
      if evenLen >= 2 and oddLen >= 2:
         if evenCounter[-2][1] > oddCounter[-2][1]:
            evenMAX = evenCounter[-2][0]
         else:
            oddMAX = oddCounter[-2][0]
      elif evenLen >= 2:
         evenMAX = evenCounter[-2][0]
      else:
         oddMAX = oddCounter[-2][0]

   print(oddCounter,evenCounter,oddMAX,evenMAX)
   total = 0
   for n,v in enumerate(V):
      if n % 2 == 1:
         if oddMAX != v:
            total += 1
      else:
         if evenMAX != v:
            total += 1
   return total
def modelAnswer():
   return
def main():
   N = int(input())
   V = list(map(int,input().split()))
   print(myAnswer(N,V))


if __name__ == '__main__':
   main()



import collections
def myAnswer(N:int,V:list) -> int:
   odd = []
   even = []
   if len(set(V)) == 1:
      return N//2

   for n,v in enumerate(V):
      even.append(v) if n % 2 == 0 else odd.append(v)
   
   oddCounter = collections.Counter(odd)
   evenCounter = collections.Counter(even)
   oddCounter = sorted(oddCounter.items(),key=lambda x:x[1])
   evenCounter = sorted(evenCounter.items(),key=lambda x:x[1])
   oddMAX = oddCounter[-1][0]
   evenMAX = evenCounter[-1][0]
   if oddMAX == evenMAX:
      evenLen = len(evenCounter)
      oddLen = len(oddCounter)
      if evenLen >= 2 and oddLen >= 2:
         if evenCounter[-2][1] > oddCounter[-2][1]:
            evenMAX = evenCounter[-2][0]
         else:
            oddMAX = oddCounter[-2][0]
      elif evenLen >= 2:
         evenMAX = evenCounter[-2][0]
      else:
         oddMAX = oddCounter[-2][0]

   
   total = 0
   for n,v in enumerate(V):
      if n % 2 == 1:
         if oddMAX != v:
            total += 1
      else:
         if evenMAX != v:
            total += 1
   return total
def modelAnswer():
   return
def main():
   N = int(input())
   V = list(map(int,input().split()))
   print(myAnswer(N,V))


if __name__ == '__main__':
   main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
v = list(map(int, input().split()))

v = [v[::2], v[1::2]]

from collections import Counter
from operator import itemgetter
from itertools import product
c = list(map(Counter, v))
s = [sorted(d.items(), key=itemgetter(1), reverse=True) for d in c]
print(s)
s = [(d + [(0, 0)])[:2] for d in s]
keep = 0
for e, o in product(*s):
    print(e, o)
    if e[0] == o[0]:
        continue
    tmp = e[1] + o[1]
    if tmp > keep:
        keep = tmp
ans = n - keep
print(ans)

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

v = [v[::2], v[1::2]]

from collections import Counter
from operator import itemgetter
from itertools import product
c = list(map(Counter, v))
s = [sorted(d.items(), key=itemgetter(1), reverse=True) for d in c]
s = [(d + [(0, 0)])[:2] for d in s]
keep = 0
for e, o in product(*s):
    if e[0] == o[0]:
        continue
    tmp = e[1] + o[1]
    if tmp > keep:
        keep = tmp
ans = n - keep
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections
def main():
    n = int(input())
    v = list(map(int,input().split()))

    odd = v[1::2]
    count_e = collections.Counter(even)
    count_o = collections.Counter(odd)
    ce = count_e.most_common()
    co = count_o.most_common()
    if ce[0][0] != co[0][0]:
        print(n-ce[0][1] - co[0][1])
    else:
        if len(ce) == 1 and len(co) == 1:
            print(n//2)
        elif len(ce) == 1:
            print(n-co[1][1])
        elif len(co) == 1:
            print(n-ce[1][1])
        else:
            print(min(n-ce[0][1]-co[1][1], n-ce[1][1]-co[0][1]))




if __name__ == '__main__':
    main()


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

    even = v[::2]
    odd = v[1::2]
    count_e = collections.Counter(even)
    count_o = collections.Counter(odd)
    ce = count_e.most_common()
    co = count_o.most_common()
    if ce[0][0] != co[0][0]:
        print(n-ce[0][1] - co[0][1])
    else:
        if len(ce) == 1 and len(co) == 1:
            print(n//2)
        elif len(ce) == 1:
            print(n-co[1][1])
        elif len(co) == 1:
            print(n-ce[1][1])
        else:
            print(min(n-ce[0][1]-co[1][1], n-ce[1][1]-co[0][1]))




if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)


from collections import Counter
import sys

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

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



cnt = 0

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

A_counter = Counter(A)
B_counter = Counter(B)

A_top2 = A_counter.most_common(2)
B_top2 = B_counter.most_common(2)

if A_top2[0][0] != B_top2[0][0]:
    cnt += len(A) - A_top2[0][1]
    cnt += len(B) - B_top2[0][1]
else:
    cnt = min(
        len(A) - A_top2[0][1] + len(B) - B_top2[1][1],
        len(A) - A_top2[1][1] + len(B) - B_top2[0][1],
    )

print(cnt)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
n=int(input())
v=[i for i in input().strip().split()]

v1,v2=[v[i] for i in range(n) if i%2==0],[v[i] for i in range(n) if not i%2==0]
v1c=Counter(v1).most_common()+[(0,0)]
v2c=Counter(v2).most_common()+[(0,0)]


print(v1c,v2c)
if v1c[0][0]==v2c[0][0]:
    if v1c[0][1]<v2c[1][1]:
        print(n-v1c[0][1]-v2c[1][1])
    else:
        print(n-v1c[1][1]-v2c[0][1])
else:
    print(n-v1c[0][1]-v2c[0][1])

from collections import Counter
n=int(input())
v=[i for i in input().strip().split()]

v1,v2=[v[i] for i in range(n) if i%2==0],[v[i] for i in range(n) if not i%2==0]
v1c=Counter(v1).most_common()+[(0,0)]
v2c=Counter(v2).most_common()+[(0,0)]

if v1c[0][0]==v2c[0][0]:
    print(min(n-v1c[0][1]-v2c[1][1],n-v1c[1][1]-v2c[0][1]))

else:
    print(n-v1c[0][1]-v2c[0][1])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections as cole


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

v1 = v[::2]   #odd
v2 = v[1::2]  #even

d1 = cole.Counter(v1)
d2 = cole.Counter(v2)

values1, counts1 = zip(*d1.most_common())
values2, counts2 = zip(*d2.most_common())

max1 = values1[0]
max2 = values2[0]

if max1 == max2:
    if len(counts1) != 1 and counts1[0] == counts1[1]:
        max1 = values[1]
    elif len(counts2) != 1 and counts2[0] == counts[1]:
        max2 = values[1]
    elif len(counts1) != 1 and len(counts2) != 1:
        if counts1[1] > counts2[1]:
            max1 = values1[1]
        else:
            max2 = values2[1]
    elif len(counts1) != 1:
        max1 = values1[1]
    elif len(counts2) != 1:
        max2 = values2[1]

print(max1, max2)
count = 0
if max1 != max2:
    count += len([x for x in v1 if x != max1])
    count += len([y for y in v2 if y != max2])

else:
    count += len(v1)


print(count)


import collections as cole


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

v1 = v[::2]   #odd
v2 = v[1::2]  #even

d1 = cole.Counter(v1)
d2 = cole.Counter(v2)

values1, counts1 = zip(*d1.most_common())
values2, counts2 = zip(*d2.most_common())

max1 = values1[0]
max2 = values2[0]

if max1 == max2:
    if len(counts1) != 1 and counts1[0] == counts1[1]:
        max1 = values1[1]
    elif len(counts2) != 1 and counts2[0] == counts2[1]:
        max2 = values2[1]
    elif len(counts1) != 1 and len(counts2) != 1:
        if counts1[1] > counts2[1]:
            max1 = values1[1]
        else:
            max2 = values2[1]
    elif len(counts1) != 1:
        max1 = values1[1]
    elif len(counts2) != 1:
        max2 = values2[1]


count = 0
if max1 != max2:
    count += len([x for x in v1 if x != max1])
    count += len([y for y in v2 if y != max2])

else:
    count += len(v1)


print(count)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections
N=int(input())
L=list(map(int,input().split()))
E=[i for i in L[::2]]
O=[i for i in L[1::2]]
e = collections.Counter(E).most_common()
o = collections.Counter(O).most_common()
if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    if len(e) == 1 or len(o) == 1:
        print(N // 2)
    else:
        a = n - e[1][1] - o[0][1]
        b = n - e[0][1] - o[1][1]
        print(min(a, b))

import collections
N=int(input())
L=list(map(int,input().split()))
E=[i for i in L[::2]]
O=[i for i in L[1::2]]
e = collections.Counter(E).most_common()
o = collections.Counter(O).most_common()
if e[0][0] != o[0][0]:
    print(N - e[0][1] - o[0][1])
else:
    if len(e) == 1 or len(o) == 1:
        print(N // 2)
    else:
        a = N - e[1][1] - o[0][1]
        b = N - e[0][1] - o[1][1]
        print(min(a, b))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0] != b[0]:
        q = ((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
        w = ((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        e = ((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
        print(min(q, w, e))
else:
    print(len(v[1::2]))


from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()
    print(a)
    print(b)
    if a[0][0] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] < b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        elif a[0][1] > b[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
        elif a[0][1] == b[0][1]:
            if len(a) != 1:
                print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
            elif len(b) != 1:
                print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
else:
    print(len(v[1::2]))


from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()
    if a[0][0] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] < b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        elif a[0][1] > b[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
        elif a[0][1] == b[0][1]:
            if len(a) != 1 and len(b) != 1:
                if a[1][1] > b[1][1]:
                    print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
                elif a[1][1] < b[1][1]:
                    print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
                elif a[1][1] == b[1][1]:
                    print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
            elif len(a) != 1:
                print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
            elif len(b) != 1:
                print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
else:
    print(len(v[1::2]))


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

left = [0] * 10**5 + 1
right = [0] * 10**5 + 1

for i in range(len(v)):
    if i % 2 == 0:
        left[v[i]] += 1
    else:
        right[v[i]] += 1

left_max = 0
left_max_second = 0
right_max = 0
right_max_second = 0
left_flag = 0
right_flag = 0
for i in range(len(left)):
    if left_max < left[i]:
        left_max_second = left_max
        left_max = left[i]
        left_flag = i

    if right_max < right[i]:
        right_max_second = right_max
        right_max = right[i]
        right_flag = i

if left_flag == right_flag:
    tmp = min(left_max + right_max_second, right_max + left_max_second)
    
    print(n - tmp)
else:
    print((n // 2 - left_max) + (n // 2 - right_max))


from collections import Counter
from sys import stdin

n = int(stdin.readline().rstrip())
a = [int(i) for i in stdin.readline().rstrip().split()]

even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        even.append(a[i])
    else:
        odd.append(a[i])

even_conter = Counter(even)
odd_conter = Counter(odd)

even_sorted = even_conter.most_common()
odd_sorted = odd_conter.most_common()

even_key1 = even_sorted[0][0]
even_val1 = even_sorted[0][1]
odd_key1 = odd_sorted[0][0]
odd_val1 = odd_sorted[0][1]

ans = n
if even_key1 == odd_key1:
    if len(even_sorted) >= 2:
        even_val2 = even_sorted[1][1]
        odd_val2 = odd_sorted[1][1]
        ans -= max((even_val1 + odd_val2), (odd_val1 + even_val2))
    else:
        ans -= max(even_val1, odd_val1)
else:
    ans -= (even_val1 + odd_val1)

print(ans)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
v=list(map(int,input().split()))
w=[]
for i in range(n//2):
    w.append(v.pop(i))
print(v)
print(w)
import collections
cv = collections.Counter(v)
cw = collections.Counter(w)
scv = sorted(cv.items(), key=lambda x:-x[1])
scw = sorted(cw.items(), key=lambda x:-x[1])

v1=scv[0][0]
w1=scw[0][0]

if v1==w1:
    if len(scv)==1:
        v2=0
    else:
        v2=scv[1][1]
    if len(scw)==1:
        w2=0
    else:
        w2=scw[1][1]
        
    print(min(n-scv[0][1]-w2, n-scw[0][1]-v2))
        
else:
    print(n-scv[0][1]-scw[0][1])

n=int(input())
v=list(map(int,input().split()))
w=[]
for i in range(n//2):
    w.append(v.pop(i))

import collections
cv = collections.Counter(v)
cw = collections.Counter(w)
scv = sorted(cv.items(), key=lambda x:-x[1])
scw = sorted(cw.items(), key=lambda x:-x[1])

v1=scv[0][0]
w1=scw[0][0]

if v1==w1:
    if len(scv)==1:
        v2=0
    else:
        v2=scv[1][1]
    if len(scw)==1:
        w2=0
    else:
        w2=scw[1][1]
        
    print(min(n-scv[0][1]-w2, n-scw[0][1]-v2))
        
else:
    print(n-scv[0][1]-scw[0][1])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter as ct

n = int(input())
s = input().split()
a = ct(s[::2])
b = ct(s[1::2])
sa = sorted(a.items(), key=lambda x: -x[1])
sb = sorted(b.items(), key=lambda x: -x[1])
print(sa)
print(sb)

if sa[0][0] == sb[0][0]:
    if len(sa)*len(sb)==1:
        dt=n//2
    elif sa[0][1] - sa[1][1] < sb[0][1] - sb[1][1] or len(sb)==1:
        dt = sa[1][1] + sb[0][1]
    else:
        dt = sa[0][1] + sb[1][1]
else:
    dt = sa[0][1] + sb[0][1]
print(sum([x for x in a.values()]+[y for y in b.values()])-dt)


from collections import Counter as ct

n = int(input())
s = input().split()
a = ct(s[::2])
b = ct(s[1::2])
sa = sorted(a.items(), key=lambda x: -x[1])
sb = sorted(b.items(), key=lambda x: -x[1])
if sa[0][0] == sb[0][0]:
    if len(sa)*len(sb)==1:
        dt=n//2
    elif sa[0][1] - sa[1][1] < sb[0][1] - sb[1][1] or len(sb)==1:
        dt = sa[1][1] + sb[0][1]
    else:
        dt = sa[0][1] + sb[1][1]
else:
    dt = sa[0][1] + sb[0][1]
print(sum([x for x in a.values()]+[y for y in b.values()])-dt)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
l = list(map(int,input().split()))
dic1={}
dic2={}
for i in range(n):
  if i%2==0:
    if l[i] in dic1:
      dic1[l[i]] += 1
    else:
      dic1[l[i]].append(1)
  else:
    if l[i] in dic2:
      dic2[l[i]] += 1
    else:
      dic2[l[i]].append(1)
      
count = 0
ma = 0
check=0
for i in dic1.values():
  ma = max(ma,i)
  check += i
count += check-ma
ma = 0
check=0
for i in dic2.values():
  ma = max(ma,i)
  check += i
count += check-ma

print(count)



n = int(input())
l = list(map(int,input().split()))
dic1={}
dic2={}
for i in range(n):
  if i%2==0:
    if l[i] in dic1:
      dic1[l[i]] += 1
    else:
      dic1[l[i]]=1
  else:
    if l[i] in dic2:
      dic2[l[i]] += 1
    else:
      dic2[l[i]]=1
dic1a = sorted(dic1.items(),key = lambda x:x[1])
dic2a = sorted(dic2.items(),key = lambda x:x[1]) 
 
if dic1a[-1][0] == dic2a[-1][0]:
    if len(dic1a) == len(dic2a) == 1:
        print(n//2)
    else:
        if dic1a[-2][1] >= dic2a[-2][1]:
            print(sum(dic2.values())-dic2a[-1][1]+sum(dic1.values())-dic1a[-2][1])
        else:
            print(sum(dic1.values())-dic1a[-1][1]+sum(dic2.values())-dic2a[-2][1])
else:
    print(sum(dic1.values())-dic1a[-1][1]+sum(dic2.values())-dic2a[-1][1])


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
if len(set(V))==1:
  print(n//2)
else:
  v1=Counter(V[::2])
  v2=Counter(V[1::2])
  ans=0
  if v1.most_common()[0][0]==v2.most_common()[0][0]:
    if v1.most_common()[0][1]>v2.most_common()[0][1]:
      v1_s=v1.most_common()[0][1]
      v2_s=v2.most_common()[1][1]
    else:
      v1_s=v1.most_common()[1][1]
      v2_s=v2.most_common()[0][1]
  if len(v1)!=1:
    ans+=len(list(v1.elements()))-v1_s
  if len(v2)!=1:
    ans+=len(list(v2.elements()))-v2_s
  print(ans)

from collections import Counter
n=int(input())
V=list(map(int,input().split()))
v1=Counter(V[::2]).most_common()
v2=Counter(V[1::2]).most_common()
if len(v1) ==1:
  v1.append([0,0])
if len(v2) == 1:
  v2.append([0,0])
if v1[0][0]==v2[0][0]:
  print(min(n-v1[0][1]-v2[1][1],n-v1[1][1]-v2[0][1]))
else:
  print(n-v1[0][1]-v2[0][1])

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import*
n, *v = map(int, open(0).read().split())
a, b = map(lambda x: Counter(x).most_common(), [v[::2], v[1::2]])
try:
 print(n-a[0][1]-b[0][1] if a[0][0]!=a[0][0] else n - max(a[0][1]+b[1][1], a[1][1]+b[0][1]))
except IndexError:
 print(n//2)

from collections import*
n, v = map(int, open(0).read().split())
def l(x):
    o = Counter(x).most_common()
    return [o[0][0], o[0][1], o[1][1]]
a, b = map(l, [v[::2], v[1::2]])
print(n-a[1]-b[1] if a[0]!=a[0] else n - max(a[1]+b[2], a[2]+b[1])


from collections import*
n,*v=map(int,open(0).read().split())
a,b=[Counter(v[i::2]).most_common()+[(0,0)]for i in(0,1)]
s,x=a[0]
t,y=b[0]
print(n-[x+y,max(x+b[1][1],y+a[1][1])][s==t])

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter

n = int(input())
v = [int(_) for _ in input().split()]
v1 = v[::2]
v2 = v[1::2]

if v1 == v2:
    print(len(v1))
else:
    cv1 = Counter(v1)
    cv2 = Counter(v2)
    if cv1.most_common()[0][0] != cv2.most_common()[0][0]:
        ch1 = len(v1) - cv1.most_common()[0][1]
        ch2 = len(v2) - cv2.most_common()[0][1]
    else:
        if cv1.most_common()[0][1] > cv2.most_common()[0][1]:
            ch1 = len(v1) - cv1.most_common()[0][1]
            ch2 = len(v2) - cv2.most_common()[1][1]
        else:
            ch1 = len(v1) - cv1.most_common()[1][1]
            ch2 = len(v2) - cv2.most_common()[0][1]
            print(ch1 + ch2)

import sys
input = sys.stdin.readline

n = int(input())
v = [int(_) for _ in input().split()]
oddcnt = [[0, i] for i in range(10**5+1)]
evencnt = [[0, i] for i in range(10**5+1)]

for i, j in enumerate(v):
    if i % 2 == 0:
        oddcnt[j][0] += 1
    else:
        evencnt[j][0] += 1

oddcnt = sorted(oddcnt, key=lambda x: (-x[0], x[1]))
evencnt = sorted(evencnt, key=lambda x: (-x[0], -x[1]))

if oddcnt[0][1] != evencnt[0][1]:
    print(n-oddcnt[0][0]-evencnt[0][0])
elif oddcnt[0][0] > evencnt[0][0]:
    print(n-oddcnt[0][0]-evencnt[1][0])
elif oddcnt[0][0] < evencnt[0][0]:
    print(n-oddcnt[1][0]-evencnt[0][0])
elif oddcnt[1][0] > evencnt[1][0]:
    print(n-oddcnt[1][0]-evencnt[0][0])
else:
    print(n-oddcnt[0][0]-evencnt[1][0])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = input()
arr = list(map(int, input().split()))

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

amaxval = acnt[list(acnt)[0]]
bmaxval = bcnt[list(bcnt)[0]]

amaxkey = list(acnt)[0]
bmaxkey = list(bcnt)[0]

def val(ab, abcnt):
	if len(ab) < 2:
		return 0
	else:
		return abcnt[list(abcnt)[0]]

if amaxkey != bmaxkey:
	ans = n - amaxval - bmaxval
else:
	if amaxval >= bmaxval:
		ans = n - amaxval - val(b,bcnt)
	else:
		ans = n - val(a,acnt) - bmaxval

print(ans)
	

	

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

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

lsacnt = sorted(acnt.items(), key=lambda x: x[1],reverse=True)
lsbcnt = sorted(bcnt.items(), key=lambda j: j[1],reverse=True)

def val(abcnt, ablscnt):
	if len(list(abcnt)) < 2:
		return 0
	else:
		return ablscnt[1][1]

if lsacnt[0][0] != lsbcnt[0][0]:
	ans = n - lsacnt[0][1] - lsbcnt[0][1]
elif lsacnt[0][0] == lsbcnt[0][0]:
	if lsacnt[0][1] > lsbcnt[0][1]:
		ans = n - lsacnt[0][1] - val(bcnt,lsbcnt)
	elif lsacnt[0][1] < lsbcnt[0][1]:
		ans = n - val(acnt,lsacnt) - lsbcnt[0][1]
	elif lsacnt[0][1] == lsbcnt[0][1]:
		ans = n - lsacnt[0][1] - max(val(acnt,lsacnt),val(bcnt,lsbcnt))

print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections
n=int(input())
V=list(map(int, input().split()))

Vo=V[::2]
Ve=V[1::2]

oddmost = collections.Counter(Vo).most_common()[0][1]
oddsec = collections.Counter(Vo).most_common()[1][1]
evenmost = collections.Counter(Ve).most_common()[0][1]
evensec = collections.Counter(Ve).most_common()[1][1]

if oddmost!=evenmost:
    print(len(V)-oddmost-evenmost)
else:
    print(min(len(V)-oddmost-evensec, len(V)-evenmost-oddsec))

import collections

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

vs_odd=vs[::2]
c_odd=collections.Counter(vs_odd) 
C1=c_odd.most_common()
C1.append((0,0))
common1=C1[0][1] 
common1sec=C1[1][1] 

vs_even=vs[1::2]
c_even=collections.Counter(vs_even) 
C2=c_even.most_common()
C2.append((0,0))
common2=C2[0][1] 
common2sec=C2[1][1] 

Ans1=len(vs_odd)-common1
Ans2=len(vs_even)-common2
Ans3=len(vs_odd)-common1sec
Ans4=len(vs_even)-common2sec

if c_odd.most_common()[0][0] == c_even.most_common()[0][0]:
    
    print(min(Ans1+Ans4, Ans2+Ans3))
else:
    print(Ans1+Ans2)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections

n = int(input())
v = [int(i) for i in input().split()]
odd = collections.Counter(v[1::2])
even = collections.Counter(v[0::2])
# print(odd)

max_odd = max(odd, key=odd.get)
# print(max_odd)
max_even = max(even, key=even.get)
# print(max_even)

if max_odd == max_even:
    del(even[max_even])
    try:
        max_even = max(even, key=even.get)
        max_even_v = even[max_even]
    except:
        max_even_v = 0
    
max_odd_v = odd[max_odd]
num_change_odd = n / 2 - max_odd_v
num_change_even = n / 2 - max_even_v
print(int(num_change_odd + num_change_even))

import collections

n = int(input())
v = [int(i) for i in input().split()]
odd = collections.Counter(v[1::2])
even = collections.Counter(v[0::2])
# print(odd)

max_odd = max(odd, key=odd.get)
# print(max_odd)
max_even = max(even, key=even.get)
# print(max_even)

max_odd_v = odd[max_odd]
max_even_v = even[max_even]

if max_odd == max_even:
    if len(odd) > 1:
        max_2nd_odd = odd.most_common(2)[1][0]
        max_2nd_odd_v = odd[max_2nd_odd]
    else:
        max_2nd_odd_v = 0
    if len(even) > 1:
        max_2nd_even = even.most_common(2)[1][0]
        max_2nd_even_v = even[max_2nd_even]
    else:
        max_2nd_even_v = 0
    if (max_odd_v + max_2nd_even_v) < (max_even_v + max_2nd_odd_v):
        print(n - (max_even_v + max_2nd_odd_v))
    else:
        print(n - (max_odd_v + max_2nd_even_v))
else:
    print(n - (max_odd_v + max_even_v))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections as col
from functools import reduce
from operator import add
n = int(input())

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

if len(set(v)) == 1:
    print(int(n / 2))
    exit()

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

co = col.Counter(odd).most_common()
coli = list(co.values())
ce = col.Counter(even).most_common()
celi = list(ce.values())

cov = list(co.keys())
cev = list(ce.keys())

if cov[0] != cev[0]:
    a = reduce(add, coli[1:], 0)
    b = reduce(add, celi[1:], 0)
    print(n - coli[0] - coli[0])
else:
    # a1 = reduce(add, coli[1:], 0)
    # b1 = reduce(add, celi[2:], 0)
    # b1 = celi[0] + b1

    # a2 = reduce(add, coli[2:], 0)
    # b2 = reduce(add, celi[1:], 0)
    # a2 = a2 + coli[0]
    if len(coli) <= 1:
        coli.append(0)
    if len(celi) <= 1:
        celi.append(0)

    ans1 = n - coli[1] - celi[0]
    ans2 = n - coli[0] - celi[1]

    print(min(ans1, ans2))

import collections as col
from functools import reduce
from operator import add
n = int(input())

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

if len(set(v)) == 1:
    print(int(n / 2))
    exit()

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

co = col.Counter(odd)
coli = list(co.values())
ce = col.Counter(even)
celi = list(ce.values())

cov = list(co.keys())
cev = list(ce.keys())

if cov[0] != cev[0]:
    a = reduce(add, coli[1:], 0)
    b = reduce(add, celi[1:], 0)
    print(a + b)
    print(n - coli[0] - coli[0])
else:
    # a1 = reduce(add, coli[1:], 0)
    # b1 = reduce(add, celi[2:], 0)
    # b1 = celi[0] + b1

    # a2 = reduce(add, coli[2:], 0)
    # b2 = reduce(add, celi[1:], 0)
    # a2 = a2 + coli[0]
    if len(coli) <= 1:
        coli.append(0)
    if len(celi) <= 1:
        celi.append(0)

    ans1 = n - coli[1] - celi[0]
    ans2 = n - coli[0] - celi[1]

    print(min(ans1, ans2))

import collections as col
from functools import reduce
from operator import add
n = int(input())

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

if len(set(v)) == 1:
    print(int(n / 2))
    exit()

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

co = col.Counter(odd).most_common()
ce = col.Counter(even).most_common()

if co[0][0] != ce[0][0]:
    print(n - co[0][1] - ce[0][1])
else:
    # a1 = reduce(add, coli[1:], 0)
    # b1 = reduce(add, celi[2:], 0)
    # b1 = celi[0] + b1

    # a2 = reduce(add, coli[2:], 0)
    # b2 = reduce(add, celi[1:], 0)
    # a2 = a2 + coli[0]
    if len(co) <= 1:
        co.append((0, 0))
    if len(ce) <= 1:
        ce.append((0, 0))

    ans1 = n - co[1][1] - ce[0][1]
    ans2 = n - co[0][1] - ce[1][1]

    print(min(ans1, ans2))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import collections

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

a = []
b = []
a_f = 0
b_f = 0
a_s = 0
b_s = 0
for i in range(N):
    if i%2 == 0:
        a.append(l[i])
    else:
        b.append(l[i])
        
c_a = collections.Counter(a)
c_b = collections.Counter(b)

a_f = c_a.most_common()[0]
b_f = c_b.most_common()[0]

if a_f[0] != b_f[0]:
    print(N - a_f[1] - b_f[1])

elif len(set(a)) == 1 and len(set(b)) == 1:
    print(int(N/2))
elif len(set(a)) == 1:
    print(int(N/2 - c_b.most_common()[1][1]))
elif len(set(b)) == 1:
    print(int(N/2 - c_a.most_common()[1][1]))
elif a_f[1] == b_f[1]:
    second_a = c_a.most_common()[1][1]
    second_b = c_b.most_common()[1][1]
    if second_a >= second_b:
        print(int(N - b_f[1] - second_a)
    else:
        print(int(N - a_f[1] - second_b)
elif a_f[1] > b_f[1]:
    print(int(N - a_f[1] - c_b.most_common()[1][1]))
else:
    print(int(N - b_f[1] - c_a.most_common()[1][1]))

import collections

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

a = []
b = []
a_f = 0
b_f = 0
a_s = 0
b_s = 0
for i in range(N):
    if i%2 == 0:
        a.append(l[i])
    else:
        b.append(l[i])
        
c_a = collections.Counter(a)
c_b = collections.Counter(b)

a_f = c_a.most_common()[0]
b_f = c_b.most_common()[0]

if a_f[0] != b_f[0]:
    print(N - a_f[1] - b_f[1])

elif len(set(a)) == 1 and len(set(b)) == 1:
    print(int(N/2))
elif len(set(a)) == 1:
    print(int(N/2 - c_b.most_common()[1][1]))
elif len(set(b)) == 1:
    print(int(N/2 - c_a.most_common()[1][1]))
elif a_f[1] == b_f[1]:
    second_a = c_a.most_common()[1][1]
    second_b = c_b.most_common()[1][1]
    if second_a >= second_b:
        print(int(N - b_f[1] - second_a))
    else:
        print(int(N - a_f[1] - second_b))
elif a_f[1] > b_f[1]:
    print(int(N - a_f[1] - c_b.most_common()[1][1]))
else:
    print(int(N - b_f[1] - c_a.most_common()[1][1]))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import collections

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

eNum=collections.Counter(r[1::2])
oNum=collections.Counter(r[::2])


if eNum.keys()[0]==oNum.keys()[0]:
  print(len(r)-max(eNum[eNum.keys()[0]]+oNum[oNum.keys()[1]],eNum[eNum.keys()[1]]+oNum[oNum.keys()[0]]))
else:
  print(len(r)-eNum[eNum.keys()[0]]-oNum[oNum.keys()[1]])

import collections

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

eNum=collections.Counter(r[1::2]).most_common()
oNum=collections.Counter(r[::2]).most_common()
eNum.append((0,0))
oNum.append((0,0))



if eNum[0][0]==oNum[0][0]:
  print(len(r)-max(eNum[0][1]+oNum[1][1],eNum[1][1]+oNum[0][1]))
else:
  print(len(r)-eNum[0][1]-oNum[0][1])


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter


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


lst_o = lst_v[::2]
lst_e = lst_v[1::2]
cnt_o = Counter(lst_o).most_common() + [(0, 0)]
cnt_e = Counter(lst_e).most_common() + [(0, 0)]
print(cnt_o)
print(cnt_e)

if cnt_o[0][0] == cnt_e[0][0]:
    rem_number = max(cnt_o[0][1] + cnt_e[1][1], cnt_o[1][1] + cnt_e[0][1])
else:
    rem_number = cnt_o[0][1] + cnt_e[0][1]
ans = n - rem_number


print(ans)

from collections import Counter

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

ac = Counter(ls[::2]).most_common(2)
bd = Counter(ls[1::2]).most_common(2)

if ac[0][0] != bd[0][0]:
    print(n-ac[0][1]-bd[0][1])
else:
    if len(ac) == 1 or len(bd) == 1:
        print(n//2)
    else:
        print(n-max(ac[0][1] + bd[1][1], ac[1][1] + bd[0][1]))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
A = [int(x) for x in input().split()]

from collections import Counter
import operator
def f():
    evn = Counter(A[::2])
    odd = Counter(A[1::2])

    a = sorted(odd.most_common(2), key=operator.itemgetter(1, 0), reverse=True)
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0), reverse=True)

    ac = a[0][1]
    bc = b[0][1]
    ret = n - ac + bc
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else n // 2
        ac_2 = a[1][1] if len(a) != 1 else n // 2
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

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

from collections import Counter
import operator
def f():
    evn = Counter(A[::2])
    odd = Counter(A[1::2])

    a = sorted(odd.most_common(2), key=operator.itemgetter(1, 0), reverse=True)
    b = sorted(evn.most_common(2), key=operator.itemgetter(1, 0), reverse=True)

    ac = a[0][1]
    bc = b[0][1]
    ret = n - ac + bc
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

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

from collections import Counter
import operator
def f():
    a, b = Counter(A[::2]), Counter(A[1::2])
    ac, bc = a[0][1], b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

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

from collections import Counter
import operator
def f():
    a = Counter(A[::2]).most_common(2)
    b = Counter(A[1::2]).most_common(2)
    ac, bc = a[0][1], b[0][1]
    ret = n - (ac + bc)
    if a[0][0] == b[0][0]:
        bc_2 = b[1][1] if len(b) != 1 else 0
        ac_2 = a[1][1] if len(a) != 1 else 0
        ret = n - max(ac + bc_2, ac_2 + bc)
    return ret
print(f())

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-

from collections import defaultdict


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

def f(v):
    d = defaultdict(int)
    d[0] = 0

    for i in v:
        d[i] += 1
    return sorted(d.items(), key=lambda x: x[1], reverse=True)

t1 = f(v[::2])
t2 = f(v[1::2])

if t1[0][0] == t2[0][0]:
    if t1[0][1] + t2[1][1] > t1[1][1] + t2[0][1]:
        print(n - t1[0][1] - t2[1][1])
    else:
        print(n - t1[1][1] - t2[0][1])
else:
    print(n - t1[0][1] - t2[0][1])

# -*- coding: utf-8 -*-

from collections import defaultdict


n = int(input())
v = tuple(int(i) for i in input().split())

def f(v):
    d = defaultdict(int)
    d[0] = 0

    for i in v:
        d[i] += 1
    return sorted(d.items(), key=lambda x: x[1], reverse=True)

t1 = f(v[::2])
t2 = f(v[1::2])

if t1[0][0] == t2[0][0]:
    if t1[0][1] + t2[1][1] > t1[1][1] + t2[0][1]:
        print(n - t1[0][1] - t2[1][1])
    else:
        print(n - t1[1][1] - t2[0][1])
else:
    print(n - t1[0][1] - t2[0][1])


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import itertools
import math
import sys

n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
else:
    odd_cnt = [0] * 10 ** 5
    even_cnt = [0] * 10 ** 5
    for i in range(len(v)):
        if i % 2 == 0:
            even_cnt[v[i]] += 1
        else:
            odd_cnt[v[i]] += 1
    odd = odd_cnt.index(max(odd_cnt))
    even = even_cnt.index(max(even_cnt))
    ans = 0
    print("odd =", odd)
    print("even =", even)
    for i in range(len(v)):
        if i % 2 == 0:
            if v[i] != even:
                ans += 1
        else:
            if v[i] != odd:
                ans += 1
    print(ans)


import itertools
import math
import sys
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
e = Counter(v[0::2]).most_common()
o = Counter(v[1::2]).most_common()
if len(e) == 1 and len(o) == 1:
    if e[0][0] == o[0][0]:
        print(n // 2)
    else:
        print(0)
elif len(e) == 1:
    if e[0][0] != o[0][0]:
        print(n - e[0][1] - o[0][1])
    else:
        print(n - max(e[0][1] + o[0][1], o[1][1]))
elif len(o) == 1:
    if e[0][0] != o[0][0]:
        print(n - e[0][1] - o[0][1])
    else:
        print(n - max(e[0][1] + o[0][1], e[1][1]))
else:
    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]))




Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

v_odd_common.append((0,0))
v_even_common.append((0,0))

print(v_odd_common[0])

if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))

from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

v_odd_common.append((0,0))
v_even_common.append((0,0))

print(v_odd_common[0])

if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))

from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()

v_odd_common.append((0,0))
v_even_common.append((0,0))

if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))
  

Verdicts: Wrong Answer

Wrong Answer

Accepted