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()))
if v.count(v[0]) == n:
    print(n // 2)
    exit()
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
E1 = list(e_counter.keys())[0]
if len(list(e_counter.keys())) > 1:
    E2 = list(e_counter.keys())[1]
else:
    E2 = E1
O1 = list(o_counter.keys())[0]
if len(list(o_counter.keys())) > 1:
    O2 = list(o_counter.keys())[1]
else:
    O2 = O1
e_cnt = n // 2 - e.count(E1)
o_cnt = n // 2 - o.count(O1)
print(e_cnt, o_cnt)
if e_cnt == 0 and o_cnt == 0:
    print(0)
else:
    print(e_cnt + o_cnt)


from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if v.count(v[0]) == n:
    print(n // 2)
    exit()
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
E1 = list(e_counter.keys())[0]
if len(list(e_counter.keys())) > 1:
    E2 = list(e_counter.keys())[1]
else:
    E2 = E1
O1 = list(o_counter.keys())[0]
if len(list(o_counter.keys())) > 1:
    O2 = list(o_counter.keys())[1]
else:
    O2 = O1
e_cnt = n // 2 - max(e.count(E1))
o_cnt = n // 2 - max(o.count(O1))
if e_cnt == 0 and o_cnt == 0:
    print(0)
else:
    print(e_cnt + o_cnt)


from collections import Counter
n = int(input())
v = list(map(int, input().split()))
e = []
o = []
for i in range(n):
    if i % 2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
e_counter = Counter(e)
o_counter = Counter(o)
e_most = e_counter.most_common()
o_most = o_counter.most_common()
E1 = e_most[0][0]
E2 = E1
if len(e_most) > 1:
    E2 = e_most[1][0]
O1 = o_most[0][0]
O2 = O1
if len(o_most) > 1:
    O2 = o_most[1][0]
e_cnt = n // 2 - e.count(E1)
o_cnt = n // 2 - o.count(O1)
if e_cnt == 0 and o_cnt == 0:
    if e[0] == o[0]:
        print(n // 2)
    else:
        print(0)
else:
    if E1 != O1:
        print(e_cnt + o_cnt)
    else:
        if E1 == O2:
            e_cnt = n // 2 - e.count(E2)
            print(e_cnt + o_cnt)
        elif E2 == O1:
            o_cnt = n // 2 - o.count(O2)
            print(e_cnt + o_cnt)
        else:
            cnt1 = n // 2 - e.count(E2) + o_cnt
            cnt2 = e_cnt + n // 2 - o.count(O2)
            print(min(cnt1, cnt2))


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):
n = int(input())
v = list(map(int,input().split()))
l1 = []
l2 = []
for i,v_ in enumerate(v):
    if i%2==0:
        l1.append(v_)
    else:
        l2.append(v_)

from collections import Counter
if set(l1)==set(l2):
    print(n//2)
else:
    c1 = Counter(l1).most_common(2)
    c2 = Counter(l2).most_common(2)
    if c1[0][0]==c2[0][0]:
        print(n-max(v[0][1]+v[1][1], v[1][1]+v[0][1]))
    else:
        print(n-v[0][1]-v[0][1])


n = int(input())
v = list(map(int,input().split()))
l1 = []
l2 = []
for i,v_ in enumerate(v):
    if i%2==0:
        l1.append(v_)
    else:
        l2.append(v_)

from collections import Counter
if len(set(v))==1:
    print(n//2)
else:
    c1 = Counter(l1).most_common(2)
    c2 = Counter(l2).most_common(2)
    if c1[0][0]==c2[0][0]:
        print(n-max(c1[0][1]+c2[1][1], c1[1][1]+c2[0][1]))
    else:
        print(n-c1[0][1]-c2[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())
E = []
O = []
V = [int(el) for el in input().split(' ')]
for i in range(n):
    if i % 2 == 0:
        O.append(V[i])
    else:
        E.append(V[i])

E_count = Counter(E).most_common(1)[0][1]
O_count = Counter(O).most_common(1)[0][1]

if len(set(V)) == 1:
    print(n//2)
else:
    E_change = n // 2 - E_count
    O_change = n //2  - O_count
    print(E_change, O_change)
    print(E_change + O_change)


from collections import Counter
n = int(input())
V = [int(el) for el in input().split(' ')]

a = Counter(V[0::2]).most_common() + [(0,0)]
b = Counter(V[1::2]).most_common() + [(0,0)]

if a[0][0]!=b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(n-max(a[1][1]+b[0][1],a[0][1]+b[1][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
n = int(input())
lis = list(map(int, input().split()))

a = Counter(lis[::2])
b = Counter(lis[1::2])

aa = sorted(a.items(), key=lambda x:x[1], reverse=True)
bb = sorted(b.items(), key=lambda x:x[1], reverse=True)
print(aa)
print(bb)

if aa[0][0] == bb[0][0]:
    if len(aa) > 1 and len(bb) > 1:
        res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])
    elif len(aa) == 1 and len(bb) > 1:
        res = n - aa[0][1] - bb[1][1]
    elif len(aa) > 1 and len(bb) == 1:
        res = n - aa[1][1] - bb[0][1]
    else:
        res = n - aa[0][1]
else:
    res = n - aa[0][1] - bb[0][1]

print(res)


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

a = Counter(lis[::2])
b = Counter(lis[1::2])

aa = sorted(a.items(), key=lambda x:x[1], reverse=True)
bb = sorted(b.items(), key=lambda x:x[1], reverse=True)

aa.append((0, 0))
bb.append((0, 0))

if aa[0][0] == bb[0][0]:
    res = n - max(aa[0][1]+bb[1][1], aa[1][1]+bb[0][1])
else:
    res = n - aa[0][1] - bb[0][1]
print(res)


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 itertools
from collections import Counter
N = int(input())
V = list(map(int,input().split()))
even_counter = Counter(V[::2])
odd_counter = Counter(V[1::2])
even_counter[-1] = 0
odd_counter[-1] = 0
even = even_counter.most_common(2)
odd = odd_counter.most_common(2)
print(even,odd)
ans = N
for (k1,v1),(k2,v2) in itertools.product(even,odd):
  if k1 == k2:
    continue
  ans = min(ans,N - v1 - v2)
print(ans)

N=int(input())
V=[int(i) for i in input().split()]
K=list(set(V))
if len(K)==1:
    print(N//2)
    exit()

cnt={}
cnt[-1]=0
for k in K:
    cnt[k]=0
for i in range(0,N,2):
    cnt[V[i]]+=1
ev_MAX=0
sec_ev_MAX=0
ev=-1
ev_cnt=[(cnt[k],k) for k in K]
ev_cnt.sort(key=lambda x: x[0],reverse=True)
ev=ev_cnt[0][1]
ev_MAX=ev_cnt[0][0]
sec_ev_MAX=0 if len(ev_cnt)<2 else ev_cnt[1][0]
# print(ev_cnt)
cnt={}
cnt[-1]=0
for k in K:
    cnt[k]=0
for i in range(1,N,2):
    cnt[V[i]]+=1
od_MAX=0
sec_od_MAX=0
od=-1
od_cnt=[(cnt[k],k) for k in K]
od_cnt.sort(key=lambda x: x[0],reverse=True)
od=od_cnt[0][1]
od_MAX=od_cnt[0][0]
sec_od_MAX=0 if len(od_cnt)<2 else od_cnt[1][0]

ans=0
if od!=ev:
    # print('#',1)
    ans+=N//2-ev_MAX
    ans+=N//2-od_MAX
else:
    # print(sec_ev_MAX,od_MAX,sec_od_MAX,ev_MAX)
    ans+=min(N//2-sec_ev_MAX+N//2-od_MAX,N//2-sec_od_MAX+N//2-ev_MAX)
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

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

vlist1=[vlist[2*i] for i in range(n//2)]
vlist2=[vlist[2*i+1] for i in range(n//2)]
#print(vlist1)
#print(vlist2)

vc1=collections.Counter(vlist1).most_common()
vc2=collections.Counter(vlist2).most_common()
print(vc1)
print(vc2)

if vc1[0][0]!=vc2[0][0]:
  print(n-vc1[0][1]-vc2[0][1])
elif len(vc1)==1 and len(vc2)==1:
  print(n//2)
elif len(vc1)==1:
  print(n//2-vc2[1][1])
elif len(vc2)==1:
  print(n//2-vc1[1][1])
else:
  if vc1[0][1]>vc2[0][1]:
    print(n-vc1[0][1]-vc2[1][1])
  elif vc1[0][1]<vc2[0][1]:
    print(n-vc1[1][1]-vc2[0][1])
  else:
    max_2nd=max(vc1[1][1],vc2[1][1])
    print(n-vc1[0][1]-max_2nd)

import collections

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

vlist1=[vlist[2*i] for i in range(n//2)]
vlist2=[vlist[2*i+1] for i in range(n//2)]
#print(vlist1)
#print(vlist2)

vc1=collections.Counter(vlist1).most_common()
vc2=collections.Counter(vlist2).most_common()
#print(vc1)
#print(vc2)

if vc1[0][0]!=vc2[0][0]:
  print(n-vc1[0][1]-vc2[0][1])
elif len(vc1)==1 and len(vc2)==1:
  print(n//2)
elif len(vc1)==1:
  print(n//2-vc2[1][1])
elif len(vc2)==1:
  print(n//2-vc1[1][1])
else:
  if vc1[0][1]>vc2[0][1]:
    print(n-vc1[0][1]-vc2[1][1])
  elif vc1[0][1]<vc2[0][1]:
    print(n-vc1[1][1]-vc2[0][1])
  else:
    max_2nd=max(vc1[1][1],vc2[1][1])
    print(n-vc1[0][1]-max_2nd)

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, K = map(int, input().split())
print('N:{}, K:{}'.format(N, K))

if K % 2 == 0:
    print(((N-K//2)//K+1)**3+(N//K)**3)
else:
    print((N//K)**3)


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

print((len(v1)-v1.most_common()[0][1]) + (len(v2)-v2.most_common()[0][1]))

N, K = map(int, input().split())


if K % 2 == 0:
    print(((N-K//2)//K+1)**3+(N//K)**3)
else:
    print((N//K)**3)


import collections

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

if len(set(v)) == 1:
    ans=len(v[1::2])
else:
    if len(v1.most_common())==1:
        v1.append((0,0))
    if len(v2.most_common())==1:
        v2.append((0,0))
    ans=min(len(v) - v1.most_common()[0][1] - v2.most_common()[0][1],len(v) - v1.most_common()[0][1] - v2.most_common()[1][1],len(v) - v1.most_common()[1][1] - v2.most_common()[0][1])

print(ans)



import collections
N = int(input())
V = [int(i) for i in input().split()]

C0 = collections.Counter(V[0::2])
C0[0] = 0

C1 = collections.Counter(V[1::2])
C1[0] = 0

if C0.most_common()[0][0] != C1.most_common()[0][0]:
    print(N-C0.most_common()[0][1]-C1.most_common()[0][1])
else:
    print(min(N-C0.most_common()[0][1]-C1.most_common()[1][1],
              N-C0.most_common()[1][1]-C1.most_common()[0][1]))


Verdicts: Runtime Error

Runtime Error

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

# C - /\/\/\/

from collections import Counter

N, *A = map(int, open(0).read().split())

ev = A[0::2]
od = A[1::2]

ev_C = Counter(ev)
od_C = Counter(od)

ev_most = ev_C.most_common()[0][1]
od_most = od_C.most_common()[0][1]
ev_second = ev_C.most_common()[1][1]
od_second = od_C.most_common()[1][1]


if ev == od:
    print(N//2)
else:
    print(min(
        N-ev_most-od_most,
        N-ev_most-od_second,
        N-ev_second-od_most
    ))



# C - /\/\/\/

from collections import Counter

N, *A = map(int, open(0).read().split())

ev = A[0::2]
od = A[1::2]

ev_C = Counter(ev)
od_C = Counter(od)


if ev == od and ev_C.most_common()[0][1] == N//2:
    print(N//2)
else:
    ans = N
    ev_common = ev_C.most_common()
    od_common = od_C.most_common()
    ev_most = ev_common[0][1]
    od_most = od_common[0][1]
    if ev_common[0][0] == od_common[0][0]:
        ev_second = ev_common[1][1]
        od_second = od_common[1][1]
        ans = min(ans, N-ev_most-od_second)
        ans = min(ans, N-ev_second-od_most)
    else:
        ans = min(ans, N-ev_most-od_most)

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

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

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm[0])
else:
    if km1[1]-km2[1]>=gm1[1]-gm2[1]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])



n=int(input())

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

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm[0])
else:
    if km1[1]-km2[1]>=gm1[1]-gm2[1]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])



n=int(input())

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

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm1[0])
else:
    if km1[0]-km2[0]>=gm1[0]-gm2[0]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])


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

import collections
n=int(input())
a=list(map(int,input().split()))
a1=collections.Counter(a[0::2]).most_common()
a2=collections.Counter(a[1::2]).most_common()
a1.append((0,0))
a2.append((0,0))
if a1[0]!=a2[0]:print(n-a1[0][1]-a2[0][1])
else:print(min(n-a1[0][1]-a2[1][1],n-a1[1][1]-a2[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 defaultdict
n = int(input())
v = list(map(int,input().split()))
a = v[::2]
b = v[1::2]
def calc(l):
    d = defaultdict(int)
    for x in l:
        d[x] += 1
    return sorted([(d[x], x) for x in d],reverse=True)
A = calc(a)
B = calc(b)
al,ax = A[0]
bl,bx = B[0]
print(a,b)
if ax != bx:
    print(n-al-bl)
elif al > bl:
    if len(B) > 1:
        bl,bx = B[1]
    print(n-al-bl)
elif al < bl:
    if len(A) > 1:
        al,ax = A[1]
    print(n-al-bl)
else:
    print(n//2)

from collections import defaultdict
n = int(input())
v = list(map(int,input().split()))
a = v[::2]
b = v[1::2]
def calc(l):
    d = defaultdict(int)
    for x in l:
        d[x] += 1
    return sorted([(d[x], x) for x in d],reverse=True)
A = calc(a)
B = calc(b)
al,ax = A[0]
bl,bx = B[0]
if ax != bx:
    print(n-al-bl)
else:
    ar,ay = A[1] if len(A) > 1 else (0,None)
    br,by = B[1] if len(B) > 1 else (0,None)
    print(min(n-al-br,n-ar-bl))

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

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

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

if len(collections.Counter(v)):
    max_eq = max(len(odd),len(even))
    print(n - max_eq)
    exit()

odd_most = collections.Counter(odd).most_common(2)
even_most = collections.Counter(even).most_common(2)

max_count=0
for odd_top in odd_most:
    for even_top in even_most:
        max_count = max(max_count,odd_top[1]+even_top[1])
print(n-max_count)

import collections

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

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

if len(collections.Counter(v))==1:
    max_eq = max(len(odd),len(even))
    print(n - max_eq)
    exit()

odd_most = collections.Counter(odd).most_common(2)
even_most = collections.Counter(even).most_common(2)

max_count=0
for odd_top in odd_most:
    for even_top in even_most:
        if odd_top[0] == even_top[0]:
            continue
        max_count = max(max_count,odd_top[1]+even_top[1])
print(n-max_count)

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





odd = Counter(v[1::2]).most_common()
even = Counter(v[0::2]).most_common()

print(len(odd),len(even))


if odd[0][0] != even[0][0]:
	answer = n - odd[0][1] - even[0][1]

else:
	if len(odd) == 1 and len(even) >1:
		answer = n - even[0][1]
	elif len(even) == 1 and len(odd) >1:
		answer = n - odd[0][1]
	elif len(even) == 1 and len(odd) ==1:
		answer = n - even[0][1]
	else:		
		if odd[0][1] > even[0][1]:
			answer = n - odd[0][1] - even[1][1]
		elif odd[0][1] < even[0][1]:
			answer = n - even[0][1] - odd[1][1]
		else:
			if odd[1][1] > even[1][1]:
				answer = n - even[0][1] - odd[1][1]
			elif odd[1][1] < even[1][1]:
				answer = n - odd[0][1] - even[1][1]
			else:
				answer = n - odd[0][1] - even[1][1]
		
print(answer)







from collections import Counter

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





odd = Counter(v[1::2]).most_common()
even = Counter(v[0::2]).most_common()



if odd[0][0] != even[0][0]:
	answer = n - odd[0][1] - even[0][1]

else:
	if len(odd) == 1 and len(even) >1:
		answer = n - even[0][1]
	elif len(even) == 1 and len(odd) >1:
		answer = n - odd[0][1]
	elif len(even) == 1 and len(odd) ==1:
		answer = n - even[0][1]
	else:		
		if odd[0][1] > even[0][1]:
			answer = n - odd[0][1] - even[1][1]
		elif odd[0][1] < even[0][1]:
			answer = n - even[0][1] - odd[1][1]
		else:
			if odd[1][1] > even[1][1]:
				answer = n - even[0][1] - odd[1][1]
			elif odd[1][1] < even[1][1]:
				answer = n - odd[0][1] - even[1][1]
			else:
				answer = n - odd[0][1] - even[1][1]
		
print(answer)







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=list(map(int,input().split()))
E=Counter(V[::2]).most_common()
O=Counter(V[1::2]).most_common()
E2=Counter(V[1::2]).most_common()[1][1] if len(E)>1 else 0
O2=Counter(V[::2]).most_common()[1][1] if len(O)>1 else 0 
print(n-E[0][1]-O[0][1] if E[0][0]!=O[0][0] else n-max(E[0][1]+E2,O[0][1]+O2))

from collections import Counter
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()+[(0,0)]
O=Counter(V[1::2]).most_common()+[(0,0)]
print(n-E[0][1]-O[0][1] if E[0][0]!=O[0][0] else n-max(E[0][1]+O[1][1],O[0][1]+E[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())
h=[int(i) for i in input().split()]

h_o_l = len(h[1::2])
h_e_l = len(h[::2])

h_o = collections.Counter(h[1::2])
h_e = collections.Counter(h[::2])

o_ = h_o.most_common()
e_ = h_e.most_common()
o_.append((0,0))
e_.append((0,0))

if o_[0][0] != e_[0][0]:
    print(N-o_[1][1]-e_[1][1])
elif o_[0][0] == e_[0][0]:
    a =min(N-o_[0][1]-e_[1][1],N-e_[0][1]-o_[1][1])
    print(a)

import collections
N=int(input())
h=[int(i) for i in input().split()]

h_o_l = len(h[1::2])
h_e_l = len(h[::2])

h_o = collections.Counter(h[1::2])
h_e = collections.Counter(h[::2])

o_ = h_o.most_common()
e_ = h_e.most_common()
o_.append((0,0))
e_.append((0,0))

if o_[0][0] != e_[0][0]:
    print(N-o_[0][1]-e_[0][1])
elif o_[0][0] == e_[0][0]:
    a =min(N-o_[0][1]-e_[1][1],N-e_[0][1]-o_[1][1])
    print(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):
n = int(input())
v = [int(i) for i in input().split()] 
lv0 = []
dv0 = {}
lv1 = []
dv1 = {}

v.sort()
ans = -1

def func():
    count0 = 0
    count1 = 0
    for i,x in enumerate(v):
            if i%2 == 0:
                if x not in lv0:
                    lv0.append(x)
                    dv0[x] = 1
                else:
                    dv0[x] += 1
                if dv0[x] > count0:
                    count0 = dv0[x]
            else:
                if x not in lv1:
                    lv1.append(x)
                    dv1[x] = 1
                else:
                    dv1[x] += 1
                if dv1[x] > count1:
                    count1 = dv1[x]
    ans = n - count0 - count1



for i in range(int(n/2)):
    i0 = 2*i
    i1 = 2*i + 1
    if v[0] != v[1]:
        func()
        break
    if v[i0] != v[i1]:
        count = 0
        if v[i0] != v[i0-2]:
            for x in range(i,int(n/2)):
                x0 = 2*x
                if v[i0] != v[x0]:
                    break
                count += 1
        if v[i1] != v[i1-2]:
            for x in range(i,int(n/2)):
                x1 = 2*x + 1
                if v[i1] != v[x1]:
                    break
                count += 1
        ans = n - (i+1) - count
        break
print(ans)

from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i,ev in enumerate(v):
    if i%2 == 0:
        v0.append(ev)
    else:
        v1.append(ev)

mcv0 = Counter(v0).most_common(2)
mcv1 = Counter(v1).most_common(2)
cmcv0 = mcv0[0][1]
cmcv1 = mcv1[0][1]
ans = n - cmcv0 - cmcv1
if mcv0[0][0] == mcv1[0][0]:
    if (len(mcv0) == 1) and (len(mcv1) == 1):
        ans = int(n/2)
    else:
        ans = min(n - mcv0[1][1] - cmcv1, n - cmcv1 - mcv1[1][1])
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):
n=int(input())
v=list(map(int,input().split()))
d1=[0]*(10**5+1)
d2=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        d1[v[i]]+=1
    else:
        d2[v[i]]+=1
assert n-max(d1)-max(d2)<0
print(n-max(d1)-max(d2))


n=int(input())
v=list(map(int,input().split()))
d1=[0]*(10**5+1)
d2=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        d1[v[i]]+=1
    else:
        d2[v[i]]+=1
if d1.index(max(d1))==d2.index(max(d2)):
    d1n=sorted(d1,reverse=True)
    d2n=sorted(d2,reverse=True)
    if d1n[1]>d2n[1]:
        print(n-d1n[1]-d2n[0])
    else:
        print(n-d1n[0]-d2n[1])
else:
    print(n-max(d1)-max(d2))

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()))
countA = []
countB = []
if len(set(V)) == 1:
    print(n//2)
else:
    A = V[::2]
    B = V[1::2]
    for i in range(N//2):
        countA.append(A.count(A[i]))
        countB.append(B.count(B[i]))
    max_countA = max(countA)
    max_countB = max(countB)
    
    print(len(A)-max_countA + len(A)-max_countB)

n = int(input())
V = list(map(int, input().split()))
if len(set(V)) == 1:
    print(n//2)
else:
    A = V[::2]
    B = V[1::2]
    for _ in range(N//2):
        countA = [A.count(a) for a in set(A)]
        countB = [B.count(b) for b in set(B)]
    max_countA = max(countA)
    max_countB = max(countB)
    
    print(len(A)-max_countA + len(A)-max_countB)

n = int(input())
V = list(map(int, input().split()))
countA = []
countB = []
if len(set(V)) == 1:
    print(n//2)
else:
    A = V[::2]
    B = V[1::2]
    for i in range(n//2):
        print(A.count(A[i]))
        countA.append(A.count(A[i]))
        countB.append(B.count(B[i]))
    max_countA = max(countA)
    max_countB = max(countB)
    
    print(len(A)-max_countA + len(A)-max_countB)

from collections import Counter
from statistics import mode


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

A = V[::2]
B = V[1::2]
countA = sorted(list(Counter(A).items()), key=lambda x: -x[1])
countB = sorted(list(Counter(B).items()), key=lambda x: -x[1])
if len(set(V)) == 1:
    print(n//2)
elif countA[0][0] != countB[0][0]:
    print(len(A)-countA[0][1] + len(B)-countB[0][1])
else:
    print(min(
        len(A)-countA[0][1] + len(B)-countB[1][1],
        len(A)-countA[1][1] + len(B)-countB[0][1]
        ))

Verdicts: 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):
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk = i
    elif sc == 0:
        sk = i
        break
    sc += 1
if sc == 0:
    sk = 0

for i in t2:
    if tc == -1:
        tk = i
    elif tc == 0:
        tk = i
        break
    tc += 1
if tc == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)


import copy
n = int(input())
v = input().split()

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = copy.deepcopy(s)
t2 = copy.deepcopy(t)
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

ssym = 0
for i in s2:
    if sc == -1:
        sk = i
    elif sc == 0:
        sk = i
        ssym = 1
        break
    sc += 1
if sc == 0 and ssym == 0:
    sk = 0

tsym = 0
for i in t2:
    if tc == -1:
        tk = i
    elif tc == 0:
        tk = i
        tsym = 1
        break
    tc += 1
if tc == 0 and tsym == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)


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:
    c1 = Counter(v[0::2])
    c2 = Counter(v[1::2])
    
    c1m = c1.most_common(1)[0]
    c2m = c2.most_common(1)[0]
    
    ans1 = n//2-c2m[1]
    if c1m[0] != c2m[0]:
        ans1 += n//2-c1m[1]
    else:
        ans1 += n//2-c1.most_common(2)[1][1]
    
    ans2 += n//2-c1m[1]
    if c1m[0] != c2m[0]:
        ans2 += n//2-c2m[1]
    else:
        ans2 += n//2-c2.most_common(2)[1][1]
    print(min(ans1, ans2))

from collections import Counter

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

if len(set(v)) == 1:
    print(n//2)
else:
    c1 = Counter(v[0::2])
    c2 = Counter(v[1::2])
    
    c1m = c1.most_common(1)[0]
    c2m = c2.most_common(1)[0]
    
    ans1 = n//2-c2m[1]
    if c1m[0] != c2m[0]:
      ans1 += n//2-c1m[1]
      else:
        ans1 += n//2-c1.most_common(2)[1][1]
    
    ans2 += n//2-c1m[1]
    if c1m[0] != c2m[0]:
      ans2 += n//2-c2m[1]
      else:
        ans2 += n//2-c2.most_common(2)[1][1]
    print(min(ans1, ans2))

from collections import Counter

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

if len(set(v)) == 1:
    print(n//2)
else:
    c1 = Counter(v[0::2])
    c2 = Counter(v[1::2])
    
    c1m = c1.most_common(2)
    c2m = c2.most_common(2)
    
    if c1m[0][0] != c2m[0][0]:
        print(n-c1m[0][1]-c2m[0][1])
    else:
        mn = n
        if len(set(c1)) > 1:
            mn = min(mn, n-c1m[1][1]-c2m[0][1])
        if len(set(c2)) > 1:
            mn = min(mn, n-c1m[0][1]-c2m[1][1])
            
        print(mn)

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

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

for i in range(n):
    if V[0] != V[i]:
        break
    elif i == n - 1:
        print(min(len(Veven), len(Vodd)))
        exit()


Voc = Counter(Vodd)
Vec = Counter(Veven)

num = Voc.most_common()[0][1] + Voc.most_common()[0][1]

if Voc.most_common()[0][0] == Vec.most_common()[0][0]:
    if len(Vodd) - Voc.most_common()[0][1] < len(Veven) - Vec.most_common()[0][1]:
        num -= Voc.most_common()[0][1]
        num += Voc.most_common()[1][1]
    else:
        num -= Vec.most_common()[0][1]
        num += Vec.most_common()[1][1]


print(n - num)


from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

for i in range(n):
    if V[0] != V[i]:
        break
    elif i == n - 1:
        print(min(len(Veven), len(Vodd)))
        exit()


Voc = Counter(Vodd)
Vec = Counter(Veven)

num = Voc.most_common()[0][1] + Voc.most_common()[0][1]

if Voc.most_common()[0][0] == Vec.most_common()[0][0]:
    if len(Vodd) - Voc.most_common()[0][1] < len(Veven) - Voc.most_common()[0][1]:
        num -= Voc.most_common()[0][1]
        num += Voc.most_common()[1][1]
    else:
        num -= Vec.most_common()[0][1]
        num += Vec.most_common()[1][1]


print(n - num)


from collections import Counter

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

Vodd = V[: len(V):2]
Veven = V[1: len(V):2]

Voc = Counter(Vodd)
Vec = Counter(Veven)

Voc_val, Voc_cnt = zip(*Voc.most_common())
Vec_val, Vec_cnt = zip(*Vec.most_common())

Voc_val, Voc_cnt = list(Voc_val), list(Voc_cnt)
Vec_val, Vec_cnt = list(Vec_val), list(Vec_cnt)

num = Voc.most_common()[0][1] + Vec.most_common()[0][1]

if Voc_val[0] == Vec_val[0]:
    Voc_cnt.append(0)
    Vec_cnt.append(0)
    num += max(Voc_cnt[1] - Voc_cnt[0], Vec_cnt[1] - Vec_cnt[0])

print(n - num)


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 sys
n = int(input())
a = list(map(int, input().split()))
x1, x2 = [], []
y1, y2 = [], []
for i in range(n//2):
  if not a[2*i] in x1:
    x1.append(a[2*i])
    y1.append(1)
  else:
    y1[x1.index(a[2*i])] += 1
  
  if not a[2*i+1] in x2:
    x2.append(a[2*i+1])
    y2.append(1)
  else:
    y2[x2.index(a[2*i+1])] += 1
print(x1,y1,x2,y2)
if len(x1)==1 and len(x2)==1 and x1[0]!=x2[0]:
  print(0)
  sys.exit()

total = 0
if x1[y1.index(max(y1))]!=x2[y2.index(max(y2))]:
  total = sum(y1)-max(y1) + sum(y2) - max(y2)
elif len(x1)==1:
  y3 = y2.remove(x2.index(x1[0]))
  total = sum(y1)-max(y1) + sum(y2) - max(y3)
elif len(x2)==1:
  y3 = y1.remove(x1.index(x2[0]))
  total = sum(y1)-max(y3) + sum(y2) - max(y2)
else:
  y3 = y1.remove(max(y1))
  y4 = y2.remove(max(y2))
  if max(y3) >= max(y4):
    total = sum(y1) - max(y3) + sum(y2) - max(y2)
  else:
    total = sum(y1) - max(y1) + sum(y2) - max(y4)
print(total)

from collections import Counter
 
def f(n,v):
	a=Counter(v[0::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]:
		return n-(a[0][1]+b[0][1])
	else:
		return min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1]))
 
if __name__=="__main__":
	x=int(input())
	data=[int(i) for i in input().split()]
	print(f(x,data))

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()))
a = [0]*10000000
b = [0]*10000000
v1=[]
v2=[]

if len(set(V)) == 1:
    print(n//2)

else:
    for i in range(n):
        if i%2 == 0:
            a[V[i]-1] += 1
            v1.append(V[i])
        else:
            b[V[i]-1] += 1
            v2.append(V[i])

    max1 = 0
    max2 = 0

    for j in range(len(a)):
        if max1 < a[j]:
            max1 = a[j]
            c1 = j
    for k in range(len(b)):
        if max2 < b[k]:
            max2=b[k]
            c2=k

    if c1 != c2:
        print(n-max1-max2)
    else:
        a.sort()
        b.sort()
        print(min(n-max1-b[-2],n-max2-a[-2]))


from collections import Counter
N = int(input())
V = list(map(int,input().split()))
zero = Counter(V[::2]).most_common()
one = Counter(V[1::2]).most_common()
if zero[0][0] != one[0][0]:
    print(N-zero[0][1]-one[0][1])
else:
    if len(zero) == 1 and len(one) == 1:
        print(N//2)
    elif len(zero) == 1:
        print(N-zero[0][1]-one[1][1])
    elif len(one) == 1:
        print(N-zero[1][1]-one[0][1])
    else:
        print(min(N-zero[1][1]-one[0][1],N-zero[0][1]-one[1][1]))

Verdicts: Time Limit Exceeded

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

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

even = [[int(x),0] for x in range(1,10**5+1)]

odd = [[int(x),0] for x in range(1,10**5/2+1)]

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

even = sorted(even,key = lambda x:-x[1])
odd = sorted(odd,key = lambda x:-x[1])

if even[0][0] == odd[0][0]:
    print(min(n-even[0][1]-odd[1][1],n-even[1][1]-odd[0][1]))
else:
    print(n-even[0][1]-odd[0][1])


n = int(input())

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

even = [[int(x),0] for x in range(1,10**5/2+1)]

odd = [[int(x),0] for x in range(1,10**5+1/2+1)]

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

even = sorted(even,key = lambda x:-x[1])
odd = sorted(odd,key = lambda x:-x[1])

if even[0][0] == odd[0][0]:
    print(min(n-even[0][1]-odd[1][1],n-even[1][1]-odd[0][1]))
else:
    print(n-even[0][1]-odd[0][1])


n = int(input())

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

even = [[int(x),0] for x in range(10**5+1)]

odd = [[int(x),0] for x in range(10**5+1)]

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

even = sorted(even,key = lambda x:-x[1])
odd = sorted(odd,key = lambda x:-x[1])

if even[0][0] == odd[0][0]:
    print(min(n-even[0][1]-odd[1][1],n-even[1][1]-odd[0][1]))
else:
    print(n-even[0][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):
n = int(input())
v = list(map(int,input().split()))
d1 = {}
d2 = {}

for i in range(0,n//2+2,2):
  a1 = v[i]
  a2 = v[i+1]
  print(a1,a2)
  if a1 not in d1:
    d1[a1] = 1
  else:
    d1[a1] += 1
    
  if a2 not in d2:
    d2[a2] = 1
  else:
    d2[a2] += 1


l1 = list(sorted(d1.items(), key=lambda x:x[1]))
l2 = list(sorted(d2.items(), key=lambda x:x[1]))


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

if l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) >= 2:
  print(min(n - l1[-1][1] - l2[-2][1],n - l1[-2][1] - l2[-1][1]))
elif l1[-1][0] == l2[-1][0] and len(l1) == 1 and len(l2) >= 2:
  print(n - l1[-1][1] - l2[-2][1])
elif l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) == 1:
  print(n - l1[-2][1] - l2[-1][1])
else:
  print(n - l1[-1][1] - l2[-1][1])

n = int(input())
v = list(map(int,input().split()))
d1 = {}
d2 = {}

for i in range(0,n//2):
  a1 = v[2*i]
  a2 = v[2*i+1]
  
  if a1 not in d1:
    d1[a1] = 1
  else:
    d1[a1] += 1
    
  if a2 not in d2:
    d2[a2] = 1
  else:
    d2[a2] += 1


l1 = list(sorted(d1.items(), key=lambda x:x[1]))
l2 = list(sorted(d2.items(), key=lambda x:x[1]))


if len(set(v)) == 1:
  print(n//2)
  exit()
if l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) >= 2:
  print(min(n - l1[-1][1] - l2[-2][1],n - l1[-2][1] - l2[-1][1]))
elif l1[-1][0] == l2[-1][0] and len(l1) == 1 and len(l2) >= 2:
  print(n - l1[-1][1] - l2[-2][1])
elif l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) == 1:
  print(n - l1[-2][1] - l2[-1][1])
else:
  print(n - l1[-1][1] - l2[-1][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 math
import numpy as np
from fractions import gcd
import fractions
import collections

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

odd = []
even = []
for i in range(N):
    if (i%2 != 0):
        odd.append(A[i])
    else:
        even.append(A[i])

odd_c = collections.Counter(odd)
even_c = collections.Counter(even)

odd_sorted = dict(sorted(odd_c.items(), key=lambda x:x[1], reverse=True))
even_sorted = dict(sorted(even_c.items(), key=lambda x:x[1], reverse=True))

odd_keys = list(odd_sorted.keys())
even_keys = list(even_sorted.keys())

ans = 0
if (even_keys[0] != odd_keys[0]):
    for i in range(N):
        if (i%2 != 0 and A[i] != odd_keys[0]):
            ans += 1
        elif (i%2 == 0 and A[i] != even_keys[0]):
            ans += 1
elif(len(even_keys) >= 2 and len(odd_keys) >=2):
    tmp1 = 0
    tmp2 = 0
    for i in range(N):
        if (i%2 != 0 and A[i] != odd_keys[0]):
            tmp1 += 1
        elif (i%2 == 0 and A[i] != even_keys[1]):
            tmp1 += 1
    for i in range(N):
        if (i%2 != 0 and A[i] != odd_keys[1]):
            tmp2 += 1
        elif (i%2 == 0 and A[i] != even_keys[0]):
            tmp2 += 1
    ans = min(tmp1,tmp2)
elif(len(even_keys) == 1 and len(odd_keys) ==1):
    ans = N//2
else:
    ans = min(even_keys[-1], odd_keys[-1])
print(ans)

import math
import numpy as np
from fractions import gcd
import fractions
import collections

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

C = collections.Counter(A)
c_sorted = dict(sorted(C.items(), key=lambda x:x[1], reverse=True))

val = list(c_sorted.values())
if (len(val) == 1):
    print(val[0]//2)
else:
    print(sum(val[2:]))


import collections

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

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

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


if even_cnt.most_common()[0][0] != odd_cnt.most_common()[0][0]:
    ans = n - even_cnt.most_common()[0][1]- odd_cnt.most_common()[0][1]
else:
    if even_cnt.most_common()[0][1] == odd_cnt.most_common()[0][1]:
        if len(even_cnt.most_common()) >= 2:
            ans = n - even_cnt.most_common()[0][1]- max(even_cnt.most_common()[1][1],odd_cnt.most_common()[1][1])
        else:
            ans = n//2
    else:
        if even_cnt.most_common()[0][1] > odd_cnt.most_common()[0][1]:
            ans = n - even_cnt.most_common()[0][1] - odd_cnt.most_common()[1][1]
        else:
            ans = n - odd_cnt.most_common()[0][1] - even_cnt.most_common()[1][1]
print(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):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
cnt_o = Counter(v[::2]).most_common(2)
cnt_e = Counter(v[1::2]).most_common(2)

mo = cnt_o[0][0]
me = cnt_e[0][0]
if mo == me:
    print(n - cnt_o[0][1] - cnt_e[0][1])
else:
    del1 = cnt_o[0][1] - cnt_o[1][1]
    del2 = cnt_e[0][1] - cnt_e[1][1]
    print(n - cnt_o[0][1] - cnt_e[0][1] + min(del1, del2))

from collections import Counter

n = int(input())
v = list(map(int, input().split()))
cnt_o = Counter(v[::2]).most_common(2)
cnt_e = Counter(v[1::2]).most_common(2)
cnt_o.append((0, 0))
cnt_e.append((0, 0))

if cnt_o[0][0] != cnt_e[0][0]:
    print(n - cnt_o[0][1] - cnt_e[0][1])
else:
    del1 = cnt_o[0][1] - cnt_o[1][1]
    del2 = cnt_e[0][1] - cnt_e[1][1]
    print(n - cnt_o[0][1] - cnt_e[0][1] + min(del1, del2))

Verdicts: Runtime Error

Accepted