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):
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
V_1=[(0,0)]+sorted(Counter([V[i] for i in range(n) if i%2==0]).items(), key=lambda x:x[1])
V_2=[(0,0)]+sorted(Counter([V[j] for j in range(n) if j%2==1]).items(), key=lambda x:x[1])

a,b=V_1[-1],V_2[-1]
if a==b:b=V_2[-2]

cnt=0
for i in range(n):
    if i%2==0:
        if V[i]!=a:cnt +=1
    else:
        if V[i]!=b:cnt +=1

print(cnt)

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

even=[(0,0)]+sorted(Counter(V[::2]).items(), key=lambda x:x[1])
odd=[(0,0)]+sorted(Counter(V[1::2]).items(), key=lambda x:x[1])

if even[-1][0]==odd[-1][0]:
    if even[-2][1]>odd[-2][1]:even=even[-2][0];odd=odd[-1][0]
    else:even=even[-1][0];odd=odd[-2][0]
else:even=even[-1][0];odd=odd[-1][0]

cnt=0
for i,j in enumerate(V):
    if i%2==0 and j!=even:cnt +=1
    elif i%2==1 and j!=odd:cnt +=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())
l = list(map(int, input().split(' ')))
l_odd = l[0::2]
l_even = l[1::2]
dict_odd = Counter(l_odd)
dict_even = Counter(l_even)
most_odd = dict_odd.most_common()[0][0]
most_even = dict_even.most_common()[0][0]

if dict_odd.most_common()[0][1] == dict_even.most_common()[0][1] == N / 2:
    ans = N / 2

elif dict_odd.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_even.most_common()[1][1]

elif dict_even.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_odd.most_common()[1][1]

elif most_odd != most_even:
    ans = N - dict_odd.most_common()[0][1] - dict_even.most_common()[0][1]

else:
    ans = N - max(most_odd + dict_even.most_common()[1][0], most_even + dict_odd.most_common()[1][0])

print(ans)

from collections import Counter

N = int(input())
l = list(map(int, input().split(' ')))
l_odd = l[0::2]
l_even = l[1::2]
dict_odd = Counter(l_odd)
dict_even = Counter(l_even)
most_odd = dict_odd.most_common()[0][0]
most_even = dict_even.most_common()[0][0]

if dict_odd.most_common()[0][1] == dict_even.most_common()[0][1] == N / 2:
    if most_odd == most_even:
        ans = N / 2
    else:
        ans = 0

elif dict_odd.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_even.most_common()[1][1]

elif dict_even.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_odd.most_common()[1][1]

elif most_odd != most_even:
    ans = N - dict_odd.most_common()[0][1] - dict_even.most_common()[0][1]

else:
    ans = N - max(dict_odd.most_common()[0][1] + dict_even.most_common()[1][1], dict_even.most_common()[0][1] + dict_odd.most_common()[1][1])

print(dict_odd, dict_even)
print(int(ans))

from collections import Counter

N = int(input())
l = list(map(int, input().split(' ')))
l_odd = l[0::2]
l_even = l[1::2]
dict_odd = Counter(l_odd)
dict_even = Counter(l_even)
most_odd = dict_odd.most_common()[0][0]
most_even = dict_even.most_common()[0][0]

if dict_odd.most_common()[0][1] == dict_even.most_common()[0][1] == N / 2:
    if most_odd == most_even:
        ans = N / 2
    else:
        ans = 0

elif dict_odd.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_even.most_common()[0][1]

elif dict_even.most_common()[0][1] == N / 2:
    ans = N / 2 - dict_odd.most_common()[0][1]

elif most_odd != most_even:
    ans = N - dict_odd.most_common()[0][1] - dict_even.most_common()[0][1]

else:
    ans = N - max(dict_odd.most_common()[0][1] + dict_even.most_common()[1][1], dict_even.most_common()[0][1] + dict_odd.most_common()[1][1])

print(int(ans))

Verdicts: Wrong Answer

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())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
half_count = len(even)
even = collections.Counter(even).most_common(1)
even_elem = even[0][0]
even_count = even[0][1]
odd = collections.Counter(odd).most_common(1)
odd_elem = odd[0][0]
odd_count = odd[0][1]

if (even_count > odd_count):
    print((half_count - even_count) + (half_count + len(odd.count(even_elem))))
elif (even_count < odd_count):
    print((half_count - odd_count) + (half_count + len(even.count(odd_elem))))
else:
    print(0)

import collections
N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
even_count = collections.Counter(even).most_common(2)
odd_count = collections.Counter(odd).most_common(2)

if even_count == N/2:
    print(N / 2 - odd_count)
elif odd_count == N/2:
    print(N / 2 - even_count)
else:
    print(N - odd_count - even_count)

import collections

N = int(input())
V = list(int(i) for i in input().split())
even = V[0::2]
odd =  V[1::2]
all_length = len(V)
even = collections.Counter(even).most_common(2)
odd = collections.Counter(odd).most_common(2)
if (even[0][0] != odd[0][0]):
    print(all_length - even[0][1] - odd[0][1])
else:
    if(len(even) == 1 and len(odd) == 1):
        print(all_length // 2)
    elif(len(even)==1):
        print(all_length // 2 - odd[1][1])
    elif(len(odd)==1):
        print(all_length // 2 - even[1][1])    
    else:
        print(min(all_length - even[0][1] - odd[1][1], all_length - even[1][1] - odd[0][1]))


Verdicts: Runtime Error

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):
# 2019/07/24

from collections import Counter

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

even=[]
odd=[]

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

e=Counter(even).most_common(2)
e=list([e[0][0]]+[e[1][0]])
o=Counter(odd).most_common(2)
o=list([o[0][0]]+[o[1][0]])
ans=float('inf')
for i in e:
    for j in o:
        cnt=0
        if i==j:continue
        for k in range(n):
            if k%2==0 and v[k]!=i:
                cnt+=1
            elif k%2==1 and v[k]!=j:
                cnt+=1
        ans=min(cnt,ans)

print(ans)

# 2019/07/24

from collections import Counter

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

even=[]
odd=[]

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

e=Counter(even).most_common(2)
if len(e)<2:e=[e[0][0]]
else:e=list([e[0][0]]+[e[1][0]])
o=Counter(odd).most_common(2)
if len(o)<2:o=[o[0][0]]
else:o=list([o[0][0]]+[o[1][0]])

ans=float('inf')
for i in e:
    for j in o:
        cnt=0
        if i==j:continue
        for k in range(n):
            if k%2==0 and v[k]!=i:
                cnt+=1
            elif k%2==1 and v[k]!=j:
                cnt+=1
        ans=min(cnt,ans)

if ans==float('inf'):ans=n//2
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 sys
from collections import Counter

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common(1)
    odd_c = Counter(odd).most_common(1)
    
    if even_c[0][0] == odd_c[0][0]:
        print(even_c[0][1])
    else:
        print(len(m) - (even_c + odd_c))

if __name__ == '__main__':
    main()


import sys
from collections import Counter

def defs(c1, c2):
    if c1[0][0] > c2[0][0]:
        return c1[1], c2[0]
    else:
        return c1[0], c2[1]

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    if even_c[0] == odd_c[0]:
        print(len(m) / 2)
        return
    
#    print(even_c)
#    print(odd_c)
    
    even_c, odd_c = defs(even_c, odd_c)
    
    if even_c[1] == odd_c[1]:
        ans = len(odd) - min(even_c[1], odd_c[1])
        
    else:
        ans = len(m) - (even_c[1] + odd_c[1])
    
    print(ans)


if __name__ == '__main__':
    main()
    


import sys
from collections import Counter
 
def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    ans = -1
    
    #print(even_c)
    #print(odd_c)
    #print(len(even_c))
    
    
    if even_c[0][0] != odd_c[0][0]:
        ans = len(m) - (even_c[0][1] + odd_c[0][1])
    
    
    elif even_c[0][0] == odd_c[0][0] and len(even_c) > 1:
        ans1 = len(m) - (even_c[0][1] + odd_c[1][1])
        ans2 = len(m) - (even_c[1][1] + odd_c[0][1])
        ans = ans1 if ans1 <= ans2 else ans2
    
    
    else:
        ans = even_c[0][1]
        
    
    print(ans)
    
if __name__ == '__main__':
    main()
   

Verdicts: Runtime Error

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):
def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)
    print(ac,bc)
    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(l)
    print(solve(l.split(" ")))

from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)
    print(ac,bc)
    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(l)
    print(solve(l.split(" ")))

from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)
   
    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


if __name__ == "__main__":
    n = int(input())
    l = input()

    print(solve(l.split(" ")))

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 collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[::2]).most_common() 
b=Counter(v[1::2]).most_common()
if len(a)==1:
    a.append([0,0])
if len(b)==1:
    b.append([0,0])
if a[0,0]==b[0,0]:
    print(min(n-a[1,1]-b[0,1],n-a[0,1]-b[1,1]))
else:
    print(n-a[0,1]-b[0,1])


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


from collections import Counter
n=int(input())
v=list(map(int,input().split()))
set_v=set(v)
if len(set_v)==1:
    print(n//2)
    exit()
a=Counter(v[::2]).most_common() 
b=Counter(v[1::2]).most_common()
if a[0][0]==b[0][0]:
    print(min(n-b[0][1]-a[1][1],n-a[0][1]-b[1][1]))
else:
    print(n-a[0][1]-b[0][1])

Verdicts: Runtime Error

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()))
a = sorted(([i,v[::2].count(i)] for i in set(v[::2])), key=lambda x:x[1])
b = sorted(([j,v[1::2].count(j)] for j in set(v[1::2])),key=lambda x:x[1])
if a[-1]!=b[-1]:
    print(n-a[-1][1]-b[-1][1])
elif len(a) == 1 and len(b) == 1:
    print(min(a[-1][1],b[-1][1]))
elif len(a) ==1:
    print(n-a[-1][1]-b[-2][1])
elif len(b) ==1:
    print(n-a[-2][1]-b[-1][1])
else:
    print(min(n-a[-2][1]-b[-1][1],n-a[-1][1]-b[-2][1])

from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])

if a[0][0]!=b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(min(n-a[1][1]-b[0][1],n-a[0][1]-b[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 = [int(_) for _ in input().split()]





v1 = v[0:n-2:2]
v2 = v[1:n-1:2]
v1_count = Counter(v1)
v2_count = Counter(v2)

v1_1st_common = v1_count.most_common(1)
v1_2nd_common = v1_count.most_common(2)

v2_1st_common = v2_count.most_common(1)
v2_2nd_common = v2_count.most_common(2)
sols = []


n1 = v1_1st_common[1]

if v1_1st_common[0] == v2_1st_common[0]:
    n2 = v2_2nd_common[1]
else:
    n2 = v2_1st_common[1]
sols.append(n-n1-n2)


n2 = v2_1st_common[1]

if v1_1st_common[0] == v2_1st_common[0]:
    n1 = v1_2nd_common[1]
else:
    n1 = v1_1st_common[1]
sols.append(n-n1-n2)
print(min(sols))


from collections import Counter

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





if len(Counter(v)) > 1:
    v1 = v[0:n+1:2]
    # print(v)
    # print(v1)
    v2 = v[1:n+2:2]
    # print(v2)
    v1_count = Counter(v1)
    v2_count = Counter(v2)

    v1_1st_common = v1_count.most_common(1)
    v2_1st_common = v2_count.most_common(1)
    sols = []
    # print(v1_1st_common[0][1], v2_1st_common[0][1])
    
    n1 = v1_1st_common[0][1]
    
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
        if len(v2_count) >= 2:
            v2_2nd_common = v2_count.most_common(2)
            n2 = v2_2nd_common[1][1]
        else:
            print(n//2)
    else:
        n2 = v2_1st_common[0][1]
    sols.append(n-n1-n2)

    
    n2 = v2_1st_common[0][1]
    
    if v1_1st_common[0][0] == v2_1st_common[0][0]:
         if len(v1_count) >= 2:
            v1_2nd_common = v1_count.most_common(2)
            n1 = v1_2nd_common[1][1]
         else:
            print(n//2)
    else:
        n1 = v1_1st_common[0][1]
    sols.append(n-n1-n2)
    print(min(sols))
else:
    print(n//2)

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()) // 2
ns = list(map(int, input().split()))

n = 200000
ns = [i for i in range(n)]

a = [ns[i] for i in range(len(ns)) if i % 2 == 0]
b = [ns[i] for i in range(len(ns)) if i % 2 == 1]
sa = set(a)
sb = set(b)
#ca = sorted([(a.count(s), s) for s in sa])[::-1]


da = {}
db = {}
for s in sa:
    da[s] = da.get(s, 0) + 1
for s in sb:
    db[s] = db.get(s, 0) + 1
ca = sorted([(v, k) for k, v in da.items()])
cb = sorted([(v, k) for k, v in db.items()])[::-1]

if ca[0][1] != cb[0][1]:
    print(n-ca[0][0] + n-cb[0][0])
else:
    if len(ca) == 1 and len(cb) == 1:
        print(n)
    elif len(ca) == 1:
        print(n-ca[0][0] + n-cb[1][0])
    else:
        print(n-ca[1][0] + n-cb[0][0])

n = int(input()) // 2
ns = list(map(int, input().split()))

a = [ns[i] for i in range(len(ns)) if i % 2 == 0]
b = [ns[i] for i in range(len(ns)) if i % 2 == 1]
sa = set(a)
sb = set(b)
#ca = sorted([(a.count(s), s) for s in sa])[::-1]


da = {}
db = {}
for s in sa:
    da[s] = da.get(s, 0) + 1
for s in sb:
    db[s] = db.get(s, 0) + 1
ca = sorted([(v, k) for k, v in da.items()])
cb = sorted([(v, k) for k, v in db.items()])[::-1]

if ca[0][1] != cb[0][1]:
    print(n-ca[0][0] + n-cb[0][0])
else:
    if len(ca) == 1 and len(cb) == 1:
        print(n)
    elif len(ca) == 1:
        print(n-ca[0][0] + n-cb[1][0])
    else:
        print(n-ca[1][0] + n-cb[0][0])

n = int(input()) // 2
ns = list(map(int, input().split()))

a = [ns[i] for i in range(len(ns)) if i % 2 == 0]
b = [ns[i] for i in range(len(ns)) if i % 2 == 1]
#ca = sorted([(a.count(s), s) for s in sa])[::-1]


da = {}
db = {}
for s in a:
    da[s] = da.get(s, 0) + 1
for s in b:
    db[s] = db.get(s, 0) + 1
ca = sorted([(v, k) for k, v in da.items()])[::-1]
cb = sorted([(v, k) for k, v in db.items()])[::-1]

if ca[0][1] != cb[0][1]:
    print(n-ca[0][0] + n-cb[0][0])
else:
    if len(ca) == 1 and len(cb) == 1:
        print(n)
    elif len(ca) == 1 and len(cb) > 1:
        print(n-ca[0][0] + n-cb[1][0])
    elif len(ca) > 1 and len(cb) == 1:
        print(n-ca[1][0] + n-cb[0][0])
    else:
        print(min(n-ca[1][0] + n-cb[0][0], n-ca[0][0] + n-cb[1][0]))  # ?

Verdicts: Wrong Answer

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=list(map(int,input().split()))
v1=[]
v2=[]
for i in range(n//2):
    v1.append(v[2*i])
    v2.append(v[2*i+1])
v1_count=Counter(v1)
v2_count=Counter(v2)
if v1==v2:
  print(n//2)
elif v1_count.most_common()[0][0]!=v2_count.most_common()[0][0]:
    print(n-v1_count.most_common()[0][1]-v2_count.most_common()[0][1])
    print(v1_count.most_common())
    print(v1)
else:
    if v1_count.most_common()[0][0]-v1_count.most_common()[1][0]>=v2_count.most_common()[0][0]-v2_count.most_common()[1][0]:
        print(n-v2_count.most_common()[1][1]-v1_count.most_common()[0][1])
    else:
        print(n-v1_count.most_common()[1][1]-v2_count.most_common()[0][1])

from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=Counter(v[::2])
v2=Counter(v[1::2])
v1[0]=0
v2[0]=0
v1_max=v1.most_common()[0]
v2_max=v2.most_common()[0]
v1_second=v1.most_common()[1]
v2_second=v2.most_common()[1]
if v1_max[0]!=v2_max[0]:
    print(n-v1_max[1]-v2_max[1])
else:
    print(min(n-v1_max[1]-v2_second[1],n-v2_max[1]-v1_second[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
def solve():
  n = int(input())
  odd = []
  even = []
  a = list(int(i) for i in input().split())
  for i in range(n):
    if i%2 == 0:
      odd.append(a[i])
    else:
      even.append(a[i])
  ans = 0
  c1 = collections.Counter(odd)
  c2 = collections.Counter(even)
  n1 = len(odd)
  n2 = len(even)
  if len(set(a)) == 1:
    print(n//2)
    exit()
  ans = 10**12
  if c1.most_common()[0][0]  ==   c2.most_common()[0][0]:
    if not len(c2) ==1:
     ans = min((n-c1.most_common()[0][1]-c2.most_common()[1][1]),ans)
    if not len(c1) ==1:
     ans = min((n-c2.most_common()[0][1]-c1.most_common()[1][1]),ans)
  else:
         ans +=n1-c1.most_common()[0][1]+n2-c2.most_common()[0][1]
  print(ans)
                  
                  
solve()

import collections
def solve():
  n = int(input())
  odd = []
  even = []
  a = list(int(i) for i in input().split())
  for i in range(n):
    if i%2 == 0:
      odd.append(a[i])
    else:
      even.append(a[i])
  ans = 0
  c1 = collections.Counter(odd)
  c2 = collections.Counter(even)
  n1 = len(odd)
  n2 = len(even)
  if len(set(a)) == 1:
    print(n//2)
    exit()
  ans = 10**12
  if c1.most_common()[0][0]  ==   c2.most_common()[0][0]:
    if not len(c2) ==1:
     ans = min((n-c1.most_common()[0][1]-c2.most_common()[1][1]),ans)
    if not len(c1) ==1:
     ans = min((n-c2.most_common()[0][1]-c1.most_common()[1][1]),ans)
  else:
         ans = min(ans,(n1-c1.most_common()[0][1]+n2-c2.most_common()[0][1]))
  print(ans)
                  
                  
solve()

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()))
cnt = 0
cnt1 = 0
if len(set(V)) == 1:
  print(n//2)
  exit()
for i in range(n-2):
  if V[i] == V[i+2] and i%2==0:
    cnt += 1
  elif V[i] == V[i+2] and i%2==1:
    cnt1 += 1
  else:
    print(n//2)
    exit()
print(max(cnt,cnt1)-min(cnt,cnt1))

from collections import Counter
N = int(input())
V = list(map(int,input().split()))
v1 = V[0::2]
v2 = V[1::2]
v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()
v1c.append((0,0))
v2c.append((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):
n = int(input())
lst = list(map(int, input().split()))
m = 0
for i in range(0,n-2):
	if lst[i] != lst[i+2]:
    	lst[i+2] = lst[i]
    	m += 1
    elif lst[i] == lst[i+1]:
		m += 1
print(m)


n = int(input())
lst = list(map(int, input().split()))
m1 = {}
m2 = {}
for i in range(0, n, 2):
    if lst[i] in m1:
        m1[lst[i]] += 1
    else:
        m1[lst[i]] = 1
    if lst[i+1] in m2:
        m2[lst[i+1]] += 1
    else:
        m2[lst[i+1]] = 1
if max(m1, key=m1.get) != max(m2, key=m2.get):
    mm = n - max(m1.values()) - max(m2.values())
else:
    mm1 = max(m1.values())
    mm2 = max(m2.values())
    m1[max(m1, key=m1.get)] = 0
    m2[max(m2, key=m2.get)] = 0
    mm = min(n - max(m1.values()) - mm2, n - max(m2.values()) - mm1) 
print(mm)

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 defaultdict

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

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


d_even = defaultdict(int)
d_odd = defaultdict(int)

for i in range(N):
    v = L[i]
    if i % 2 == 0:
        d_even[v] += 1
    else:
        d_odd[v] += 1

l_even = sorted(d_even.items(), key=lambda x: -x[1])
l_odd = sorted(d_odd.items(), key=lambda x: -x[1])

odd_1 = l_even[0]
even_1 = l_even[0]

if even_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = l_even[1]
odd_2 = l_odd[1]

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)


from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
odd_2 = c_odd[1]
even_1 = c_even[0]
even_2 = c_even[1]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

ans = N
ans = min(N, N - odd_1[1] - even_2[1])
ans = min(N, N - odd_2[1] - even_1[1])
print(ans)


from collections import Counter

N = int(input())
L = list(map(int, input().split()))
odd = [v for i, v in enumerate(L) if i % 2 == 0]
even = [v for i, v in enumerate(L) if i % 2 == 1]

if len(set(L)) == 1:
    print(N//2)
    exit()
if N == 2:
    print(0)
    exit()


c_odd = sorted(dict(Counter(odd)).items(), key=lambda x: -x[1])
c_even = sorted(dict(Counter(even)).items(), key=lambda x: -x[1])

odd_1 = c_odd[0]
even_1 = c_even[0]

if odd_1[0] != even_1[0]:
    print(N - odd_1[1] - even_1[1])
    exit()

even_2 = c_even[1]
odd_2 = c_odd[1]

ans = N
ans = min(ans, N - odd_1[1] - even_2[1])
ans = min(ans, N - odd_2[1] - even_1[1])
print(ans)


Verdicts: Runtime Error

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()))
l = list(range(n))
odd = [v[i] for i in l if i%2 == 0]
even = [v[i] for i in l if i%2 == 1]

import collections
oddm = collections.Counter(odd).most_common()
evenm = collections.Counter(odd).most_common()

if oddm[0][0] == evenm[0][0]:
    a = len(odd)
else:
    a = (n/2)-numodd+(n/2)-numeven
print(int(a))

n = int(input())
v = list(map(int,input().split()))
l = list(range(n))
odd = [v[i] for i in l if i%2 == 0]
even = [v[i] for i in l if i%2 == 1]

import collections
oddm = collections.Counter(odd).most_common()
evenm = collections.Counter(odd).most_common()

if oddm[0][0] != evenm[0][0]:
    a = (n/2)-oddm[0][1]+(n/2)-evenm[0][1]
else:
    if len(oddm) == 1 and len(evenm) == 1:
        a = n/2
    elif len(oddm) == 1:
        a = (n/2)-evenm[1][1]
    elif len(evenm) == 1:
        a = (n/2)-oddm[1][1]
    else:
        a = n-max(evenm[1][1]+oddm[0][1],evenm[0][1]+oddm[1][1])

print(int(a))


n = int(input())
v = list(map(int,input().split()))
l = list(range(n))
odd = [v[i] for i in l if i%2 == 0]
even = [v[i] for i in l if i%2 == 1]

import collections
oddm = collections.Counter(odd).most_common()
evenm = collections.Counter(even).most_common()

if oddm[0][0] != evenm[0][0]:
    a = (n/2)-oddm[0][1]+(n/2)-evenm[0][1]
else:
    if len(oddm) == 1 and len(evenm) == 1:
        a = n/2
    elif len(oddm) == 1:
        a = (n/2)-evenm[1][1]
    elif len(evenm) == 1:
        a = (n/2)-oddm[1][1]
    else:
        a = n-max(evenm[1][1]+oddm[0][1],evenm[0][1]+oddm[1][1])

print(int(a))


Verdicts: Wrong Answer

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())
v=list(map(int, input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
v10=collections.Counter(v1)
v11=v10.most_common()
v20=collections.Counter(v2)
v21=v20.most_common()
if v11[0][0]==v21[0][0] and v11[0][1]==n//2 and v21[0][1]==n//2:
    print(n//2)
elif v11[0][0]==v21[0][0]:
    x1=n//2-v11[0][1]
    x2=n//2-v11[1][1]
    y1=n//2-v21[0][1]
    y2=n//2-v21[1][1]
    print(min(x1+y2,x2+y1))
    
else:
    x=n//2-v11[0][1]
    y=n//2-v21[0][1]
    print(x1+y1)

import collections
n=int(input())
v=list(map(int, input().split()))
v1=v[0:n:2]
v2=v[1:n:2]
v10=collections.Counter(v1)
v11=v10.most_common()
v20=collections.Counter(v2)
v21=v20.most_common()
if v11[0][0]==v21[0][0] and v11[0][1]==n//2 and v21[0][1]==n//2:
    print(n//2)
elif v11[0][0]==v21[0][0]:
    x1=n//2-v11[0][1]
    x2=n//2-v11[1][1]
    y1=n//2-v21[0][1]
    y2=n//2-v21[1][1]
    print(min(x1+y2,x2+y1))
    
else:
    x1=n//2-v11[0][1]
    y1=n//2-v21[0][1]
    print(x1+y1)

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()))
v1 = v[0::2]
v2 = v[1::2]

from collections import Counter
c1 = list(Counter(v1).items())
c2 = list(Counter(v2).items())

c1 = sorted(c1, key= lambda x: x[1], reverse= True)
c2 = sorted(c2, key= lambda x: x[1], reverse= True)

c1.append((0,0))
c2.append((0,0))

print(c1[:3], c2[:3])
if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    a = c1[0][1] + c2[1][1]
    b = c1[1][1] + c2[0][1]
    if a < b:
        print(n - b)
    else:
        print(n - a)

n = int(input())
v = list(map(int, input().split()))
v1 = v[0::2]
v2 = v[1::2]

from collections import Counter
c1 = list(Counter(v1).items())
c2 = list(Counter(v2).items())

c1 = sorted(c1, key= lambda x: x[1], reverse= True)
c2 = sorted(c2, key= lambda x: x[1], reverse= True)

c1.append((0,0))
c2.append((0,0))

#print(c1[:3], c2[:3])
if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    a = c1[0][1] + c2[1][1]
    b = c1[1][1] + c2[0][1]
    if a < b:
        print(n - b)
    else:
        print(n - a)

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):
#! /usr/bin/python
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
#N = 4
#V = list(map(int, "105 119 105 119 105 119".split()))


def func(l, aa):
    counter = Counter(l)
    if counter[aa] == 0:
        c, count = counter.most_common()[0]
    else:
        c, count = counter.most_common()[1]
    print(l, len(l) - count)
    return (c, len(l) - count)


if len(set(V)) == 1:
    print(N // 2)
else:
    c, count = func(V[::2], -1)
    c2, count2 = func(V[1::2], c)
    print(count + count2)


#! /usr/bin/python
from collections import Counter
N = int(input())
V = list(map(int, input().split()))
#N = 4
#V = list(map(int, "1 2 3 2 2 2 2 2 1 1 2 3 4 5 2 12 1 1".split()))


def func(l, aa):
    counter = Counter(l)
    if counter[aa] == 0:
        c, count = counter.most_common()[0]
    else:
        c, count = counter.most_common()[1]
    
    return (c, len(l) - count)


if len(set(V)) == 1:
    print(N // 2)
else:
    c, count = func(V[::2], -1)
    c2, count2 = func(V[1::2], c)
    a = count + count2
    c2, count2 = func(V[1::2], -1)
    c, count = func(V[::2], c2)
    print(min(a, count + count2))


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 = list(map(int,input().split()))
odd_list = []
even_list = []

for i in range(n):
    if i % 2 == 0:
        odd_list.append(v_list[i]) 
    else:
        even_list.append(v_list[i])

import collections

odd_list_c = collections.Counter(odd_list)
even_list_c = collections.Counter(even_list)

if odd_list_c.most_common()[0][0] != even_list_c.most_common()[0][0]:
    ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[0][1]
else:
    if len(even_list_c) == 1 && len(odd_list_c) == 1:
        ans = n // 2
    else: 
        if odd_list_c.most_common()[0][1] >= even_list_c.most_common()[0][1]:
            ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[1][1]
        elif odd_list_c.most_common()[0][1] < even_list_c.most_common()[0][1]:
            ans = n - odd_list_c.most_common()[1][1] - even_list_c.most_common()[0][1]

print(ans)

n=int(input())
v_list = list(map(int,input().split()))
odd_list = []
even_list = []

for i in range(n):
    if i % 2 == 0:
        odd_list.append(v_list[i]) 
    else:
        even_list.append(v_list[i])

import collections

odd_list_c = collections.Counter(odd_list)
even_list_c = collections.Counter(even_list)

if odd_list_c.most_common()[0][0] != even_list_c.most_common()[0][0]:
    ans = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[0][1]
else:
    if len(even_list_c) == 1 and len(odd_list_c) == 1:
        ans = n // 2
    else: 
        ans1 = n - odd_list_c.most_common()[0][1] - even_list_c.most_common()[1][1]
        ans2 = n - odd_list_c.most_common()[1][1] - even_list_c.most_common()[0][1]
        ans = min(ans1, ans2)

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):
from collections import Counter

n = int(input().strip())
vs = list(map(int, input().strip().split()))
oddv = [v for i, v in enumerate(vs) if i % 2 == 0]
evenv = [v for i, v in enumerate(vs) if i % 2 == 1]

oddc = Counter(oddv)
evenc = Counter(evenv)
if oddc.most_common(1)[0][0] != evenc.most_common(1)[0][0]:
  print(len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(1)[0][1])
else:
  if len(oddc.most_common()) == 1 and len(evenc.most_common()) == 1:
    print(len(oddv))
  elif len(oddc.most_common()) == 1:
    print(len(evenv) - evenc.most_common(2)[1][1])
  else len(evenc.most_common()) == 1:
    print(len(oddv) - oddc.most_common(2)[1][1])
  else:
    print(min(len(oddv) - oddc.most_common(2)[1][1] + len(evenv) - evenc.most_common(1)[0][1], len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(2)[0][1]))

from collections import Counter

n = int(input().strip())
vs = list(map(int, input().strip().split()))
oddv = [v for i, v in enumerate(vs) if i % 2 == 0]
evenv = [v for i, v in enumerate(vs) if i % 2 == 1]

oddc = Counter(oddv)
evenc = Counter(evenv)
if oddc.most_common(1)[0][0] != evenc.most_common(1)[0][0]:
  print(len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(1)[0][1])
else:
  if len(oddc.most_common()) == 1 and len(evenc.most_common()) == 1:
    print(len(oddv))
  elif len(oddc.most_common()) == 1:
    print(len(evenv) - evenc.most_common(2)[1][1])
  elif len(evenc.most_common()) == 1:
    print(len(oddv) - oddc.most_common(2)[1][1])
  else:
    print(min(len(oddv) - oddc.most_common(2)[1][1] + len(evenv) - evenc.most_common(1)[0][1], len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(2)[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 as C
n = int(input())
a = list(map(int,input().split()))
c1 = C(a[::2])
c2 = C(a[1::2])
mc1 = c1.most_common(2)
mc2 = c2.most_common(2)
if mc1[0][0] == mc2[0][0]:
  if mc1[1][1] >= mc2[1][1]:
    ans = n - mc1[1][1] - mc2[0][1]
  else:
    ans = n - mc1[0][1] - mc2[][1]
print(ans)

from collections import Counter as C
n = int(input())
a = list(map(int,input().split()))
c1 = C(a[::2])
c2 = C(a[1::2])
mc1 = c1.most_common(2)
mc2 = c2.most_common(2)
if mc1[0][0] != mc2[0][0]:
  ans = n - mc1[0][1] - mc2[0][1]
else:
  if len(mc1) + len(mc2) == 2:
    ans = n // 2
  elif len(mc1) == 1:
    ans = n - mc1[0][1] - mc2[1][1]
  elif len(mc2) == 1:
    ans = n - mc1[1][1] - mc2[0][1]
  else:
    if mc1[1][1] >= mc2[1][1]:
      ans = n - mc1[1][1] - mc2[0][1]
    else:
      ans = n - mc1[0][1] - mc2[1][1]
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):
from collections import Counter

def solve(size=int(input()), ary=list(map(int, input().split()))):
    if len(set(ary)) < 2: return len(ary) // 2

    even, odd = Counter(ary[::2]), Counter(ary[1::2])
    (e, em), (_, es) = even.most_common(2)
    (o, om), (_, os) = odd.most_common(2)
    return size - max(em + os, es + om) if e == o else size - em - om

print(solve())

from collections import Counter

given1 = int(input())
given2 = [int(_) for _ in input().split()]

def solve(size=given1, ary=given2):
    even, odd = Counter(ary[::2]), Counter(ary[1::2])

    emst, esec = even.most_common(2)
    eme, emf = emst
    ese, esf = esec

    omst, osec = odd.most_common(2)
    ome, omf = omst
    ose, osf = osec

    return size - max(emf + osf, omf + esf) if eme == ome else size - esf - osf


print(solve())


from collections import Counter
def solve(size=int(input()), ary=list(map(int, input().split()))):
    even, odd = Counter(ary[::2]), Counter(ary[1::2])
    (e, em), (_, es) = even.most_common(2)
    (o, om), (_, os) = odd.most_common(2)
    return size - max(em + os, es + om) if e == o else size - em - om
print(solve())

from collections import Counter

def solve(size=int(input()), ary=list(map(int, input().split()))):
    even, odd = Counter(ary[::2]), Counter(ary[1::2])
    even[0], odd[0] = 0, 0
    print(even)
    print(odd)
    (e, em), (_, es) = even.most_common(2)
    (o, om), (_, os) = odd.most_common(2)
    return size - max(em + os, es + om) if e == o else size - em - om

print(solve())

def solve(size=int(input()), ary=list(map(int, input().split())), max_range=100001):
    even = [0 for _ in range(max_range)]
    odd = [0 for _ in range(max_range)]

    (em, ei), (om, oi) = (0, 0), (0, 0)

    for i in range(size):
        if i % 2 == 0:
            even[ary[i]] += 1
            if even[ary[i]] > em:
                em, ei = even[ary[i]], ary[i]
        else:
            odd[ary[i]] += 1
            if odd[ary[i]] > om:
                om, oi = odd[ary[i]], ary[i]

    if ei == oi:
        even[ei], odd[oi] = 0, 0
        return size - max(max(even) + om, max(odd) + em)
    else:
        return size - (em + om)

print(solve())

Verdicts: Runtime Error

Runtime Error

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):

def main():
  from collections import Counter
  N=int(input())
  A=list(ma())
  evens = Counter(A[::2])
  odds = Counter(A[1::2])
  evens[0]=0 
  odds[0]=0 #
  
  e1, e2=evens.most_common(2) 
  o1, o2=odds.most_common(2) #
  
  if e1[0]!=o1[0]:
    print(N - (e1[1] + o1[1]))
  else: 
    print(N - max(e1[1]+o2[1], e2[1]+o1[1]))
  
if __name__ == '__main__':
  main()


def ma():
  return map(int,input().split())

def main():
  from collections import Counter
  N=int(input())
  A=list(ma())
  evens = Counter(A[::2])
  odds = Counter(A[1::2])
  evens[0]=0 
  odds[0]=0 #
  
  e1, e2=evens.most_common(2) 
  o1, o2=odds.most_common(2) #
  
  if e1[0]!=o1[0]:
    print(N - (e1[1] + o1[1]))
  else: 
    print(N - max(e1[1]+o2[1], e2[1]+o1[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):
import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
elif a.most_common()[1][0] + b.most_common()[0][0] > a.most_common()[0][0] + b.most_common()[1][0]
    print(n-a.most_common()[1][0] - b.most_common()[0][0])
else:
    print(n-a.most_common()[0][0] - b.most_common()[1][0])

import collections
n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(n // 2):
    a.append(v[(i+1)*2-1])
    b.append(v[(i+1)*2-2])
a = collections.Counter(a)
b = collections.Counter(b)


if a.most_common()[0][0] != b.most_common()[0][0]:
    print(n - a.most_common()[0][1] - b.most_common()[0][1])
elif len(a.most_common()) == 1 and len(b.most_common()) == 1:
    print(n//2)
elif a.most_common()[1][1] + b.most_common()[0][1] > a.most_common()[0][1] + b.most_common()[1][1]:
    print(n - a.most_common()[1][1] - b.most_common()[0][1])
else:
    print(n - a.most_common()[0][1] - b.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):
from collections import Counter

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

one = sorted(Counter([v[i] for i in range(0, n, 2)]).items(), key=lambda x: x[1], reverse=True)
two = sorted(Counter([v[i] for i in range(1, n, 2)]).items(), key=lambda x: x[1], reverse=True)

print(one, two)
if one[0][0] != two[0][0]:
	print(n - one[0][1] - two[0][1])
else:
	if len(one) == 1 and len(two) == 1:
		print(n // 2)
	elif len(one) == 1:
		print(n // 2 - two[1][1])
	elif len(two) == 1:
		print(n // 2 - one[1][1])
	else:
		print(min(n - one[0][1] - two[1][1]), n - one[1][1] - two[0][1])

from collections import Counter

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

one = sorted(Counter([v[i] for i in range(0, n, 2)]).items(), key=lambda x: x[1], reverse=True)
two = sorted(Counter([v[i] for i in range(1, n, 2)]).items(), key=lambda x: x[1], reverse=True)


if one[0][0] != two[0][0]:
	print(n - one[0][1] - two[0][1])
else:
	if len(one) == 1 and len(two) == 1:
		print(n // 2)
	elif len(one) == 1:
		print(n // 2 - two[1][1])
	elif len(two) == 1:
		print(n // 2 - one[1][1])
	else:
		print(min(n - one[0][1] - two[1][1], n - one[1][1] - two[0][1]))

Verdicts: Runtime Error

Accepted