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 copy import *
n=int(input())
arr=list(map(int,input().split()))
arr1=[]
arr2=[]
for i in range(1,100001):
	arr1.append([0,i])
	arr2.append([0,i])

for i in range(0,n,2):
	arr1[arr[i]-1][0]+=1
#arr1.sort()
#print(arr1[-1])
for i in range(1,n,2):
	arr2[arr[i]-1][0]+=1
arr1.sort(reverse=True)
arr2.sort(reverse=True)
#print(arr1[-1],arr2[-1])
if(arr1[0][1]==arr2[0][1]):
	print(min(n-arr1[0][0]-arr2[1][0],n-arr1[1][0]-arr2[0][0]))	
else:
	print(n-arr1[-1][0]-arr2[-1][0])


from copy import *
n=int(input())
arr=list(map(int,input().split()))
arr1=[]
arr2=[]
for i in range(1,100001):
	arr1.append([0,i])
	arr2.append([0,i])

for i in range(0,n,2):
	arr1[arr[i]-1][0]+=1
#arr1.sort()
#print(arr1[-1])
for i in range(1,n,2):
	arr2[arr[i]-1][0]+=1
arr1.sort(reverse=True)
arr2.sort(reverse=True)
#print(arr1[-1],arr2[-1])
if(arr1[0][1]==arr2[0][1]):
	print(min(n-arr1[0][0]-arr2[1][0],n-arr1[1][0]-arr2[0][0]))	
else:
	print(n-arr1[0][0]-arr2[0][0])


Verdicts: Wrong Answer

Accepted
Problem: A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:    * For each i = 1,2,..., n-2, a_i = a_{i+2}.   * Exactly two different numbers appear in the sequence.  You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.

Submission attempts (in order):

import sys
from collections import *

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

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

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

max1 = 0

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

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

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



import sys
from collections import *

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

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

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

max1 = 0

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

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

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


Verdicts: Runtime Error

Accepted
Problem: A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:    * For each i = 1,2,..., n-2, a_i = a_{i+2}.   * Exactly two different numbers appear in the sequence.  You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.

Submission attempts (in order):
from collections import Counter

n=int(input())
s=list(map(int,input().split()))
e=Counter(s[0::2])
o=Counter(s[1::2])
e[0]=0
o[0]=0
e1,e2=e.most_common(2)
o1,o2=o.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]))z

from collections import Counter

n=int(input())
s=list(map(int,input().split()))
e=Counter(s[0::2])
o=Counter(s[1::2])
e[0]=0
o[0]=0
e1,e2=e.most_common(2)
o1,o2=o.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]))

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
from itertools import takewhile

n = int(input())
vvv = list(map(int, input().split()))
cnt1 = Counter(vvv[0::2])
cnt2 = Counter(vvv[1::2])
mc1 = cnt1.most_common()
mc2 = cnt2.most_common()
mcs1 = list(takewhile(lambda x: x[1] == mc1[0][1], mc1))
mcs2 = list(takewhile(lambda x: x[1] == mc2[0][1], mc2))
print(mc1, mc2, mcs1, mcs2)
if len(mcs1) == len(mcs2) and mcs1[0][0] == mcs2[0][0]:
    if len(mc1) > 1:
        if len(mc2) > 1:
            print(min(n - mc1[0][1] - mc2[1][1], n - mc1[1][1] - mc2[0][1]))
        else:
            print(min(n - mc1[0][1], n - mc1[1][1] - mc2[0][1]))
    else:
        if len(mc2) > 1:
            print(min(n - mc1[0][1] - mc2[1][1], n - mc2[0][1]))
        else:
            print(min(n - mc1[0][1], n - mc2[0][1]))
else:
    print(n - mc1[0][1] - mc2[0][1])


from collections import Counter

n = int(input())
vvv = list(map(int, input().split()))
cnt1 = Counter(vvv[0::2])
cnt2 = Counter(vvv[1::2])
mc1 = cnt1.most_common(2)
mc2 = cnt2.most_common(2)
if mc1[0][0] == mc2[0][0]:
    sc1 = mc1[1][1] if len(mc1) > 1 else 0
    sc2 = mc2[1][1] if len(mc2) > 1 else 0
    print(min(n - mc1[0][1] - sc2, n - sc1 - mc2[0][1]))
else:
    print(n - mc1[0][1] - mc2[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*
n,*v=open(0).read().split()
n=int(n)
a=[v[s]for s in range(0,n,2)]
b=[v[s]for s in range(1,n,2)]
c=Counter(a).most_common()
d=Counter(b).most_common()
print(c,d)
if len(c)==1 and len(d)==1:
  if c==d:
    print(n//2)
  else:
    print(0)
elif c[0][1]!=d[0][1]:
  print(sum([s[1]for s in c[1:]])+sum([s[1]for s in d[1:]]))
else:
  x=sum([s[1]for s in c[1:]])+d[0][1]+sum([s[1]for s in d[2:]])
  y=sum([s[1]for s in d[1:]])+c[0][1]+sum([s[1]for s in c[2:]])
  print(min(x,y))

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

from collections import*
n,*a=map(int,open(0).read().split())
odd =Counter([v for k,v in enumerate(a) if k%2==0]).most_common()
even=Counter([v for k,v in enumerate(a) if k%2==1]).most_common()


if len(odd)==len(even)==1:
    if odd[0][0]==even[0][0]:
        print(len(a)//2)
    else:
        print(0)
elif odd[0][0]!=even[0][0]:
    print(sum(t for(s,t)in odd[1:])+sum(t for(s,t)in even[1:]))
else:
    a=odd[0][1]+sum(t for(s,t)in odd[2:])+sum(t for(s,t)in even[1:])
    b=even[0][1]+sum(t for(s,t)in even[2:])+sum(t for(s,t)in odd[1:])
    print(min(a,b))


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):
n=int(input())
v=list(map(int,input().split()))
a=v[0::2]
b=v[1::2]
c=dict()
d=dict()

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

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

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

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

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

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

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

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

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

if len(set(a))==len(set(b))==1 and e[0][1]==f[0][1] and e[0][0]==f[0][0]:
  print(min(len(a),len(b)))
elif e[0][1]!=f[0][1]:
  print(n-e[0][0]-f[0][0])
elif e[0][0]>f[0][0]:
  print(n-e[0][0]-f[1][0])
elif e[0][0]<f[0][0]:
  print(n-e[1][0]-f[0][0])
elif e[0][0]==f[0][0] and e[0][1]==f[0][1]:
  if e[1][0]>f[1][0]:
    print(n-e[1][0]-f[0][0])
  else:
    print(n-e[0][0]-f[1][0])

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


def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    ans = 0
    odd = Counter(v[1::2])
    even = Counter(v[::2])
    odd_mosts = odd.most_common(2)
    even_mosts = even.most_common(2)
    if odd_mosts[0][0] == even_mosts[0][0]:
        if len(odd) == len(even) == 1:
            ans = n//2
        else:
            ans_sel = []
            ans_sel.append(n//2-odd_mosts[0][1]+n//2-even_mosts[1][1])
            ans_sel.append(n//2-odd_mosts[1][1]+n//2-even_mosts[0][1])
            ans = min(ans_sel)
    else:
        ans+=(n//2-odd_mosts[0][1])
        ans+=(n//2-even_mosts[0][1])
    print(ans)

from collections import Counter


def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    ans = 0
    odd = Counter(v[1::2])
    even = Counter(v[::2])
    odd_mosts = odd.most_common(2)
    even_mosts = even.most_common(2)
    if odd_mosts[0][0] == even_mosts[0][0]:
        if len(odd) == len(even) == 1:
            ans = n//2
        else:
            ans_sel = []
            ans_sel.append(n//2-odd_mosts[0][1]+n//2-even_mosts[1][1])
            ans_sel.append(n//2-odd_mosts[1][1]+n//2-even_mosts[0][1])
            ans = min(ans_sel)
    else:
        ans+=(n//2-odd_mosts[0][1])
        ans+=(n//2-even_mosts[0][1])
    print(ans)

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:    * For each i = 1,2,..., n-2, a_i = a_{i+2}.   * Exactly two different numbers appear in the sequence.  You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.

Submission attempts (in order):
N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)


sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
a = 0
if sortdictV1[0][0] != sortdictV2[0][0]:
    a = N - sortdictV1[0][1] - sortdictV2[0][1]
else:
  if len(dictV1) == len(dictV2) == 1:
    a = N // 2
  else:
    if len(dictV1) == 1:
      a = N - sortdictV1[0][1] - sortdictV2[1][1]
    elif len(dictV2) == 1:
      a = N - sortdictV1[1][1] - sortdictV2[0][1]
    else:
      a = min(N - sortdictV1[0][1] - sortdictV2[1][1], N - sortdictV1[1][1] - sortdictV2[0][1])
  print(a)

N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)


sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
a = 0
if len(dictV1) == 1:
  a = a + 0
else:
  a = a + N/2 - sortdictV1[0][1]
if len(dictV2) == 1:
  a = a + 0
else:
  a = a + N/2 - sortdictV2[0][1]
if sortdictV1[0][0] == sortdictV2[0][0]:
  a = 0
  a = a + min(N/2 - sortdiictV1[0][1] + N/2 - sortdictV2[1][1], N/2 - sortdiictV2[0][1] + N/2 - sortdictV1[1][1])
print(a)


N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)


sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
a = 0
if sortdictV1[0][0] != sortdictV2[0][0]:
    a = N - sortdictV1[0][1] - sortdictV2[0][1]
else:
  if len(dictV1) == len(dictV2) == 1:
    a = N // 2
  else:
    if len(dictV1) == 1:
      a = N - sortdictV1[0][1] - sortdictV2[1][1]
    elif len(dictV2) == 1:
      a = N - sortdictV1[1][1] - sortdictV2[0][1]
    else:
      a = min(N - sortdictV1[0][1] - sortdictV2[1][1], N - sortdictV1[1][1] - sortdictV2[0][1])
print(a)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:    * For each i = 1,2,..., n-2, a_i = a_{i+2}.   * Exactly two different numbers appear in the sequence.  You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.

Submission attempts (in order):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n = read()
v = reads()

evens = sorted((v, k) for k, v in Counter(v[::2]).items()) + [(0, -1)]
odds = sorted((v, k) for k, v in Counter(v[1::2]).items()) + [(0, -1)]

print(evens, odds)

if evens[0][1] != odds[0][1]:
  ans = n - evens[0][0] - odds[0][0]
else:
  ans = n - max(evens[0][0] + odds[1][0], evens[1][0] + odds[0][0])

print(ans)

from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n = read()
v = reads()

evens = sorted(((v, k) for k, v in Counter(v[::2]).items()), reverse=True) + [(0, -1)]
odds = sorted(((v, k) for k, v in Counter(v[1::2]).items()), reverse=True) + [(0, -1)]

if evens[0][1] != odds[0][1]:
  ans = n - evens[0][0] - odds[0][0]
else:
  ans = n - max(evens[0][0] + odds[1][0], evens[1][0] + odds[0][0])

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())
v = list(map(int, input().split()))
even = [v[2*i] for i in range(n//2)]
odd = [v[2**i+1] for i in range(n//2)]
dEven = collections.Counter(even).most_common()
dOdd = collections.Counter(odd).most_common()
if dEven[0][0] != dOdd[0][0]:
    ans = n - dEven[0][1]  - dOdd[0][1]
else:
    ans = n - max(dEven[0][1]+dOdd[1][0], dEven[1][0]+dOdd[0][1])
print(ans)

import collections
n = int(input())
v = list(map(int, input().split()))
even = [v[2*i] for i in range(n//2)]
odd = [v[2*i+1] for i in range(n//2)]
dEven = collections.Counter(even).most_common()
dOdd = collections.Counter(odd).most_common()
if dEven[0][0] != dOdd[0][0]:
    ans = n - dEven[0][1]  - dOdd[0][1]
else:
    if len(dEven) >=2 and len(dOdd) >= 2:
        ans = n - max(dEven[0][1]+dOdd[1][1], dEven[1][1]+dOdd[0][1])
    elif len(dEven) < len(dOdd):
        ans = n - (dEven[0][1]+dOdd[1][1])
    elif len(dEven) > len(dOdd):
        ans = n - (dEven[1][1]+dOdd[0][1])
    else:
        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):
from statistics import mode
n = int(input())
vlist = list(map(int, input().split()))


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

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


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

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

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


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


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

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


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


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


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

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

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

print(x+y)

from collections import Counter

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


Counter_evens = Counter(vlist[::2])
Counter_odds = Counter(vlist[1::2])


# even_indexes
top2_even = Counter_evens.most_common(2)  

E_most_common = top2_even[0][0]
Emnum = top2_even[0][1]

if len(top2_even) == 2:
    E_2nd_common = top2_even[1][0]
    E2num = top2_even[1][1]
else:
    E_2nd_common = 'foo'
    E2num = 0


top2_odd = Counter_odds.most_common(2)

O_most_common = top2_odd[0][0]
Omnum = top2_odd[0][1]

if len(top2_odd) == 2:
    O_2nd_common = top2_odd[1][0]
    O2num = top2_odd[1][1]
else:
    O_2nd_common = 'foo'
    O2num = 0


if E_most_common == O_most_common:  
    
    

    
    x = len(vlist[::2]) - Emnum + len(vlist[1::2]) - O2num
    
    y = len(vlist[::2]) - E2num + len(vlist[1::2]) - Omnum

    print(min(x, y))
else:
    
    
    print(len(vlist[::2]) - Emnum + len(vlist[1::2]) - Omnum)


Verdicts: 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):
# coding: utf-8
# Your code here!

import numpy as np

def canbe_solved(positions):
    flg = np.dot(positions[0],np.ones(2,int))%2
    for p in positions:
        flg ^= (np.dot(p,np.ones(2,int)) %2 )
        if flg:
            return False
    return True

def solutions(p,vals):
    u = np.dot(p, np.array([1,1]))
    v = np.dot(p, np.array([1,-1]))
    for val in vals:
        if u >=0:
            if v >= 0:
                print('R',end="")
                u -= val
                v -= val
            else:
                print('U',end="")
                u -= val
                v += val
        else:
            if v >= 0:
                print('D',end="")
                u += val
                v -= val
            else:
                print('L',end="")
                u += val
                v += val
    print()
    
    
def main():
    #input
    n = int(input().rstrip())
    positions = [np.asarray(list(map(int,input().rstrip().split()))) for _ in range(n)]
    vals = [1<<i for i in range(30,-1,-1)]
    if np.dot(positions[0], np.ones(2,int)) % 2 == 0:
        vals.append(1)

    if canbe_solved(positions):
        print(len(vals))
        for i,p in enumerate(vals):
            print(p,end="")
            if i == len(vals)-1:
                print('')
        else:
            print(' ', end="")

        for p in positions:
            solutions(p,vals)
    else:
        print('-1')
        
main()

    

import collections

arr_length = int(input().rstrip())
arr = list(map(int,input().rstrip().split()))

arr_odd = arr[0::2]
arr_even = arr[1::2]

def count_strange(arr):
    c = collections.Counter(arr)
    keys, vals = zip(*c.most_common())
    return keys, vals

def proc(arr1, arr2):
    keys1, vals1 = count_strange(arr1)
    keys2, vals2 = count_strange(arr2)
    
    if keys1[0] == keys2[0]:
        if len(keys1) == 1 and len(keys2) == 1:
            print(vals1[0])
        elif len(keys1) == 1 and len(keys2) > 1:
            print(len(arr2)-vals2[1])
        elif len(keys1) > 1 and len(keys2) == 1:
            print(len(arr1)-vals1[1])
        else: #>1
            print(
                min(
                    len(arr1)-vals1[1] + len(arr2)-vals2[0],
                    len(arr1)-vals1[0] + len(arr2)-vals2[1]
                    )
                    )
    else:
        print(len(arr1)-vals1[0] + len(arr2)-vals2[0])
    
proc(arr_odd, arr_even)

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())
arr=map(int,input().split())
from collections import Counter
even=Counter(arr[::2])
even[0]=0
odd=Counter(arr[1::2])
odd[0]=0
even1,even2=even.most_common(2)
odd1,odd2=odd.most_common(2)
if even1[0]!=odd1[0]:
  print(n-(even1[1]+odd1[1]))
else:
  print(n-max(even1[1]+odd2[1],even2[1]+odd1[1]))

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


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

if n == 2:
    if l[0] == l[1]:
        print(1)
    else:
        print(0)
else:
    a = []
    b = []
    for i in range(n):
        if i % 2 == 0:
            a.append(l[i])
        else:
            b.append(l[i])

    da = {}
    for e in a:
        if e not in da:
            da[e] = (1,e)
        else:
            da[e] = (da[e][0]+1,da[e][1])

    db = {}
    for e in b:
        if e not in db:
            db[e] = (1,e)
        else:
            db[e] = (db[e][0]+1,db[e][1])

    la = list(reversed(sorted(list(da.values()))))
    lb = list(reversed(sorted(list(db.values()))))
    #print(la)
    #print(lb)

    la[-1] = (0,-1)
    lb[-1] = (0,-1)

    if la[0][1] == lb[0][1]:
        ans = n- (la[0][0] + max(la[1][0],lb[1][0]))
    else:
        ans = n - (la[0][0] + lb[0][0])
    print(ans)


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

a = []
b = []

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

def createMyList(li):
    d = {-1:(0,-1)}
    for e in li:
        if e not in d:
            d[e] = (1,e)
        else:
            d[e] = (d[e][0] + 1, d[e][1])
    return list(reversed(sorted(list(d.values()))))

la = createMyList(a)
lb = createMyList(b)
#print(la)
#print(lb)

if la[0][1] == lb[0][1]:
    ans = n- max(lb[0][0] + la[1][0], la[0][0] +lb[1][0])
else:
    ans = n - (la[0][0] + lb[0][0])
print(ans)


Verdicts: Runtime Error

Accepted
Problem: A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:    * For each i = 1,2,..., n-2, a_i = a_{i+2}.   * Exactly two different numbers appear in the sequence.  You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.

Submission attempts (in order):
import collections
n = int(input())
v=[]
v=list(map(int,input().split(' ')))

odv = []
evv = []

for i in range(n):
    if i%2 == 1:
        odv.append(v[i])
    else:
        evv.append(v[i])

odvc=collections.Counter(odv)
evvc=collections.Counter(evv)

odvs=len(odvc.most_common())
evvs=len(evvc.most_common()) 

if evvc.most_common()[0][0] != odvc.most_common()[0][0]:
    print( odvs-odvc.most_common()[0][1] + evvs-evvc.most_common()[0][1] )
else:
    if odvs > 1 and evvs > 1:
        print( min(odvs-odvc.most_common()[0][1] + evvs-evvc.most_common()[1][1] ,
                   odvs-odvc.most_common()[1][1] + evvs-evvc.most_common()[0][1] ) )
    else:
        if odvs > 1:
            print( odvs-odvc.most_common()[0][1] )
        elif evvs > 1:
            print( evvs-evvc.most_common()[0][1] )
        else:
            print(min(odvs,evvs))




import collections
n = int(input())
v=[]
v=list(map(int,input().split(' ')))

odv = []
evv = []

for i in range(n):
    if i%2 == 1:
        odv.append(v[i])
    else:
        evv.append(v[i])

odvc=collections.Counter(odv)
evvc=collections.Counter(evv)

odvs=len(odv)
evvs=len(evv)

odv_kind=len(odvc.most_common())
evv_kind=len(evvc.most_common()) 

if evvc.most_common()[0][0] != odvc.most_common()[0][0]:
    print( odvs-odvc.most_common()[0][1] + evvs-evvc.most_common()[0][1] )
else:
    if odv_kind > 1 and evv_kind > 1:
        print( min(odvs-odvc.most_common()[0][1] + evvs-evvc.most_common()[1][1] ,
                   odvs-odvc.most_common()[1][1] + evvs-evvc.most_common()[0][1] ) )
    else:
        if odv_kind > 1:
            print( odvs-odvc.most_common()[0][1] )
        elif evv_kind > 1:
            print( evvs-evvc.most_common()[0][1] )
        else:
            print(min(odvs,evvs))




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())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1m = max(c1.items(), key=lambda x:x[1])
c2m = max(c2.items(), key=lambda x:x[1])
c1m[0] = 0
c2m[0] = 0
c1c2 = max(c for k,c in c2.items() if c1m[0]!=k)
c2c1 = max(c for k,c in c1.items() if c2m[0]!=k)
print(min(N - c1m[1] - c1c2, N - c2m[1] - c2c1))

from collections import Counter
n = int(input())
V = list(map(int, input().split()))
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
c1[0] = 0
c2[0] = 0
(x, cx), (_, cxx) = c1.most_common(2)
(y, cy), (_, cyy) = c2.most_common(2)
if x == y:
    print(n - max(cx + cyy, cy + cxx))
else:
    print(n - cx + cy)

from collections import Counter
n = int(input())
V = list(map(int, input().split()))
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
c1[0] = 0
c2[0] = 0
(x, cx), (_, cxx) = c1.most_common(2)
(y, cy), (_, cyy) = c2.most_common(2)
if x == y:
    print(n - max(cx + cyy, cy + cxx))
else:
    print(n - cx - cy)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:    * For each i = 1,2,..., n-2, a_i = a_{i+2}.   * Exactly two different numbers appear in the sequence.  You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.

Submission attempts (in order):
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

even = Counter(a[::2])
odd = Counter(a[1::2])

es = [(0,0)]
for ek,ev in even.items():
    es.append((ev,ek))
    
es.sort(reverse=True)
    
    
os = [(0,0)]
for ok,ov in odd.items():
    os.append((ov,ok))
    
os.sort(reverse=True)
    

if es[-1][1] != os[-1][1]:
    print((n//2-es[-1][0]) + (n//2-os[-1][0]))
else:
    print(max((n//2-es[-1][0]) + (n//2-os[-2][0]),
              (n//2-es[-2][0]) + (n//2-os[-1][0])))

import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

even = Counter(a[::2])
odd = Counter(a[1::2])

es = even.most_common(2)
os = odd.most_common(2)

es = es + [(0,0)]
os = os + [(0,0)]

if es[0][0] != os[0][0]:
    print((n//2-es[0][1]) + (n//2-os[0][1]))
else:
    print(min((n//2-es[1][1]) + (n//2-os[0][1]),
              (n//2-es[0][1]) + (n//2-os[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):
n = int(input())
l = list(map(int, input().split()))
l1 = [li for i, li in enumerate(l) if i % 2 == 0]
l2 = [li for i, li in enumerate(l) if i % 2 == 1]
print(l1, l2)
def cnt(l):
    d = {}
    for li in l:
        if li in d:
            d[li] += 1
        else:
            d[li] = 1
    d = [(li, cnt) for li, cnt in d.items()]
    d = sorted(d, key=lambda di: di[0], reversed=True)
    return d

k1 = cnt(l1)[:2]
k2 = cnt(l2)[:2]

ans = 10000000
if k1[0][0] != k2[0][0]:
    ans = n - k1[0][1] - k2[0][1]
else:
    if len(k1) == 2:
        ans = n - k1[1][1] - k2[0][1]
    if len(k2) == 2:
        ans = min(ans, n - k1[0][1] - k2[0][1])
    if ans == 10000000:
        ans = n - max(k1[0][1], k2[0][1])
print(ans)




n = int(input())
l = list(map(int, input().split()))
l1 = [li for i, li in enumerate(l) if i % 2 == 0]
l2 = [li for i, li in enumerate(l) if i % 2 == 1]
def cnt(l):
    d = {}
    for li in l:
        if li in d:
            d[li] += 1
        else:
            d[li] = 1
    d = [(li, cnt) for li, cnt in d.items()]
    return sorted(d, key=lambda di: di[1], reverse=True)

k1 = cnt(l1)[:2]
k2 = cnt(l2)[:2]
ans = 10000000
if k1[0][0] != k2[0][0]:
    ans = n - k1[0][1] - k2[0][1]
if len(k1) == 2:
    ans = min(ans, n - k1[1][1] - k2[0][1])
if len(k2) == 2:
    ans = min(ans, n - k1[0][1] - k2[1][1])
if ans == 10000000:
    ans = n - max(k1[0][1], k2[0][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

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

cnt1 = Counter(v[::2]).most_common()
cnt2 = Counter(v[1::2]).most_common()
cnt1 += [(-1,0)]
cnt2 += [(-1,0)]
print(cnt1, cnt2)
if cnt1[0][0] != cnt2[0][0]:
    print(n - (cnt1[0][1] + cnt2[0][1]))
else:
    print(n - max(cnt1[1][1] + cnt2[0][1], cnt1[1][1] + cnt2[0][1]))

from collections import Counter

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

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

def f(x, y):
  return n - ( x + y )

v0 = Counter(v[::2])
v1 = Counter(v[1::2])
L = v0.most_common(2)
R = v1.most_common(2)

print(L, R)

if L[0][0] != R[0][0]:
  print(f(L[0][1], R[0][1]))
elif len(L) > len(R):
  print(f(L[1][1], R[0][1]))
elif len(L) < len(R):
  print(f(L[0][1], R[1][1]))
elif len(L) == 2:
  print(min(f(L[1][1], R[0][1]), f(L[0][1], R[1][1])))
else:
  print(n//2)



from collections import Counter

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

def f(x, y):
  return n - ( x + y )

v0 = Counter(v[::2])
v1 = Counter(v[1::2])
L = v0.most_common(2)
R = v1.most_common(2)

#print(L, R)

if L[0][0] != R[0][0]:
  print(f(L[0][1], R[0][1]))
elif len(L) > len(R):
  print(f(L[1][1], R[0][1]))
elif len(L) < len(R):
  print(f(L[0][1], R[1][1]))
elif len(L) == 2:
  print(min(f(L[1][1], R[0][1]), f(L[0][1], R[1][1])))
else:
  print(n//2)

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*
n,*v=map(int,open(0).read().split())
a=Counter(v[::2]).most_common()+[(0,0)]
b=Counter(v[1::2]).most_common()+[(0,0)]
print(a,b)
if a[0][0]==b[0][0]:
    print(min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1]))
else:
    print(n-a[0][1]-b[0][1])

from collections import*
n,*v=map(int,open(0).read().split())
a=Counter(v[::2]).most_common()+[(0,0)]
b=Counter(v[1::2]).most_common()+[(0,0)]
if a[0][0]==b[0][0]:
    print(min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1]))
else:
    print(n-a[0][1]-b[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):

# arr1, arr2

from collections import *
N = int(input())
As = list(map(int, input().split()))

def solve(arr1, arr2):
    cnt1 = Counter(arr1)
    cnt2 = Counter(arr2)

    
    
    most1 = cnt1.most_common(1)
    most2 = cnt2.most_common(1)

    if len(most1) > 1 or len(most2) > 1:
        return len(arr1) - most1[0][1] + len(arr2) - most2[0][1]
    elif most1[0][0] != most2[0][0]:
        return 0
    else:
        try:
            ans1 = len(arr1) - most1[0][1] \
                + len(arr2) - cnt2.most_common(2)[1][1]
        except:
            ans1 = len(arr1) - most1[0][1] \
                + len(arr2)
        try:
            ans2 = len(arr2) - most2[0][1] \
                + len(arr1) - cnt1.most_common(2)[1][1]
        except:
            ans2 = len(arr2) - most2[0][1] \
                + len(arr1)
        return min(ans1, ans2)


arr1 = As[0::2]
arr2 = As[1::2]
print(solve(arr1, arr2))


from collections import *
N = int(input())
As = list(map(int, input().split()))

def solve(arr1, arr2):
    cnt1 = Counter(arr1)
    cnt2 = Counter(arr2)

    most1 = cnt1.most_common()
    most2 = cnt2.most_common()

    
    most1.append(('_', 0))
    most2.append(('_', 0))

    
    if most1[0][0] != most2[0][0]:
        return len(arr1) * 2 - most1[0][1] - most2[0][1]
    
    else:
        ans1 = len(arr1) * 2 - most1[0][1] - most2[1][1]
        ans2 = len(arr1) * 2 - most1[1][1] - most2[0][1]
        return min(ans1, ans2)

arr1 = As[0::2]
arr2 = As[1::2]
print(solve(arr1, arr2))


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

v1 = {}
v2 = {}
for i in range(len(v)):
    if(i % 2 == 0):
        if((v[i] in v1) == True):
            v1[v[i]] += 1
        else:
            v1[v[i]] = 1
    else: 
        if((v[i] in v2) == True):
            v2[v[i]] += 1
        else:
            v2[v[i]] = 1


if(max_k1 == max_k2):
    if(v1[max_k1] > v2[max_k2]):
        v2[max_k2] = 0
        max_k2 = max(v2, key=v2.get)
    else:
        v1[max_k1] = 0
        max_k1 = max(v1, key=v1.get)


ans = n // 2 - v1[max_k1]
ans += n // 2 - v2[max_k2]

print(ans)

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

v1 = {}
v2 = {}
for i in range(n):
    if(i % 2 == 0):
        if((v[i] in v1) == True):
            v1[v[i]] += 1
        else:
            v1[v[i]] = 1
    else: 
        if((v[i] in v2) == True):
            v2[v[i]] += 1
        else:
            v2[v[i]] = 1

max_k1 = max(v1, key=v1.get)
max_k2 = max(v2, key=v2.get)

ans1 = 1e9
ans2 = 1e9
if(max_k1 == max_k2):
    tmp = v1[max_k1]
    v1[max_k1] = 0
    max_k1 = max(v1, key=v1.get)
    ans1 = n - v1[max_k1] - v2[max_k2]
    v1[max_k1] = tmp
    max_k1 = max(v1, key=v1.get)

    v2[max_k2] = 0
    max_k2 = max(v2, key=v2.get)
    ans2 = n - v1[max_k1] - v2[max_k2]
else: ans1 = n - v1[max_k1] - v2[max_k2]

print(min(ans1, ans2))

Verdicts: Runtime Error

Accepted
Problem: A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:    * For each i = 1,2,..., n-2, a_i = a_{i+2}.   * Exactly two different numbers appear in the sequence.  You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.

Submission attempts (in order):
n=int(input())
s=input().split()
s=[int(o) for o in s]
left=dict()
right=dict()
def count_nums(mydict,o):
  if o in mydict.keys():
    mydict[o]+=1
  else:
    mydict[o]=1
flag=True
for o in s:
  if flag:
    count_nums(left,o)
    flag=False
  else:
    count_nums(right,o)
    flag=True
myleft=sorted(left.keys(),key=lambda x: left[x])
myright=sorted(right.keys(),key=lambda x: right[x])
if myleft[-1]!=myright[-1]:
  print( len(s)-left[myleft[-1]]-right[myright[-1]])
a0,b0=left[myleft[-1]],right[myright[-1]]
a1=0 if len(myleft)==1 else left[myleft[-2]]
b1=0 if len(myright)==1 else right[myright[-2]]
print( len(s)-max(a0+b1,a1+b0))

n=int(input())
s=input().split()
s=[int(o) for o in s]
left=dict()
right=dict()
def count_nums(mydict,o):
  if o in mydict.keys():
    mydict[o]+=1
  else:
    mydict[o]=1
flag=True
for o in s:
  if flag:
    count_nums(left,o)
    flag=False
  else:
    count_nums(right,o)
    flag=True
myleft=sorted(left.keys(),key=lambda x: left[x])
myright=sorted(right.keys(),key=lambda x: right[x])
if myleft[-1]!=myright[-1]:
  print( len(s)-left[myleft[-1]]-right[myright[-1]])
else:
  a0,b0=left[myleft[-1]],right[myright[-1]]
  a1=0 if len(myleft)==1 else left[myleft[-2]]
  b1=0 if len(myright)==1 else right[myright[-2]]
  print( len(s)-max(a0+b1,a1+b0))

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):
def main():
    n=int(input())
    v=list(map(int,input().split()))
    l1=[0]*(10**5+1)
    l2=[0]*(10**5+1)
    for i,vn in enumerate(v):
        if i%2==0:
            l1[vn]+=1
        else:
            l2[vn]+=1
    f1,f2,s1,s2=0,0,0,0
    for i,ln in enumerate(l1):
        s1=max(s1,min(ln,f1))
        f1=max(f1,ln)
    for i,ln in enumerate(l2):
        s2=max(s2,min(ln,f2))
        f2=max(f2,ln)
    print(max(n-f1-s2,n-f2-s1))

if __name__ == '__main__':
    main()

def main():
    n=int(input())
    v=list(map(int,input().split()))
    l1=[0]*(10**5+1)
    l2=[0]*(10**5+1)
    for i,vn in enumerate(v):
        if i%2==0:
            l1[vn]+=1
        else:
            l2[vn]+=1
    f1,f2,s1,s2,m1,m2=0,0,0,0,0,0
    for i,ln in enumerate(l1):
        s1=max(s1,min(ln,f1))
        if f1<ln:
            m1=i
        f1=max(f1,ln)
    for i,ln in enumerate(l2):
        s2=max(s2,min(ln,f2))
        if f2<ln:
            m2=i
        f2=max(f2,ln)
    if m1==m2:
        print(min(n-f1-s2,n-f2-s1))
    else:
        print(n-f1-f2)

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:    * For each i = 1,2,..., n-2, a_i = a_{i+2}.   * Exactly two different numbers appear in the sequence.  You are given a sequence v_1,v_2,...,v_n whose length is even. We would like to make this sequence /\/\/\/ by replacing some of its elements. Find the minimum number of elements that needs to be replaced.

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


if V1c[0][0]==V2c[0][0]:
  if len(V1c)==1 and len(V2c)==1:
    print(n//2)
  elif len(V1c)==1:
    print(V2c[0][1])
  elif len(V2c)==1:
    print(V1c[0][1])   
  else:
    print(n-max(V1c[0][1]+V2c[1][1],V1c[1][1]+V2c[0][1]))
else:
  print(n-V1c[0][1]-V2c[0][1])


#%%
import collections

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

#print(v1)
#print(v2)


l1 = list(collections.Counter(v1).most_common())
l2 = list(collections.Counter(v2).most_common())


if l1[0][0] != l2[0][0]:
    tmp = l1[0][1] + l2[0][1]
else:
    if len(l1) > 1 and len(l2) > 1: 
        tmp = max(l1[1][1] + l2[0][1], l1[0][1] + l2[1][1])
    elif len(l1) == 1 and len(l2) > 1:
        tmp = max(l2[0][1], l1[0][1] + l2[1][1])
    elif len(l2) == 1 and len(l1) > 1:
        tmp = max(l1[1][1] + l2[0][1], l1[0][1])
    else:
        tmp = max(l2[0][1], l1[0][1])

ans = n - tmp
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):
vs = [int(i) for i in input().strip()]
n = (len(vs) - 2)//2
def main(vs):
    if vs[0] != 1:
        print(-1)
        return -1
    if vs[-1] != 0:
        print(-1)
        return -1
    if vs[-2] != 1:
        print(-1)
        return -1
    for i in range(n):
        if vs[i+1] != vs[-2-i-1]:
            print(-1)
            return

    temp = 1
    for i in range(n+1 if len(vs) % 2 == 0 else n+2):
        print(1, temp+1)
        temp += 1
    temptemp = temp
    temp = 1
    for i in range(n):
        x = 1+n-i
        if vs[n-i] == 1:
            print(temptemp, temptemp+1)
            temp = temptemp
            temptemp += 1
        else:
            print(temp, temptemp+1) 
            temptemp += 1

main(vs)


from collections import Counter
n = int(input().strip())
vs = [int(i) for i in input().split(' ')]
vs1 = vs[::2]
vs2 = vs[1::2]
a = Counter(vs1).most_common()
b = Counter(vs2).most_common()

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    candidates = []
    if len(a) != 1:
        candidates.append(n - a[1][1] - b[0][1])
    if len(b) != 1:
        candidates.append(n - a[0][1] - b[1][1])
    if len(candidates) != 0:
        print(min(candidates))
    else:
        print(n//2)


Verdicts: Wrong Answer

Accepted