Problem:


Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
oddsum = 0
evensum = 0
odd = []
even = []
for i in range(0, n - 1, 2):
	oddsum += v[i]
	odd.append(v[i])
	evensum += v[i + 1]
	even.append(v[i + 1])
oddmean = 2 * oddsum / n
evenmean = 2 * evensum / n
odddif = list(map(lambda x: abs(x - oddmean), odd))
evendif = list(map(lambda x: abs(x - evenmean), even))
oddmean = odd[odddif.index(min(odddif))]
evenmean = even[evendif.index(min(evendif))]

count = 0
if oddmean != evenmean:
	for i in range(0, n - 1, 2):
		count += abs(oddmean - v[i]) + abs(evenmean - v[i + 1])
else:
	oddmean += 1
	for i in range(0, n - 1, 2):
		count += abs(oddmean - v[i]) + abs(evenmean - v[i + 1])
print(int(count))

Submission status: Wrong Answer

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

for i in range(0, n - 1, 2):
	oddsum += v[i]
	evensum += v[i + 1]
oddmean = 2 * oddsum // n
evenmean = 2 * evensum // n

count = 0
if oddmean != evenmean:
	for i in range(0, n - 1, 2):
		count += abs(oddmean - v[i]) + abs(evenmean - v[i + 1])
else:
	oddmean += 1
	for i in range(0, n - 1, 2):
		count += abs(oddmean - v[i]) + abs(evenmean - v[i + 1])
print(int(count))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
vs = list(map(int, input().split()))

odds = [n*((i+1)%2) for i,n in enumerate(vs)]
evens = [n*(i%2) for i,n in enumerate(vs)]

half = int(N/2)
odds_half = sorted(odds)[half:]
evens_half = sorted(evens)[half:]

om_n = 0
om_c = 0
for n in set(odds_half):
    if odds_half.count(n) > om_c:
        om_n = n
em_n = 0
em_c = 0
for n in set(evens_half):
    if evens_half.count(n) > em_c:
        em_n = n

sum_odds = sum(map(lambda x: abs(x-om_n), odds_half))
sum_evens = sum(map(lambda x: abs(x-em_n), evens_half))

print(sum_odds+sum_evens)

Submission status: Wrong Answer

Solution code:
N = int(input())
vs = list(map(int, input().split()))

odds = [n*((i+1)%2) for i,n in enumerate(vs)]
evens = [n*(i%2) for i,n in enumerate(vs)]
#print(odds)
#print(evens)

half = int(N/2)
odds_half = sorted(odds)[half:]
evens_half = sorted(evens)[half:]
#print(odds_half)
#print(evens_half)

median_odds = odds_half[int(N/4)]
median_evens = evens_half[int(N/4)]
#print(median_odds)
#print(median_evens)

sum_odds = sum(map(lambda x: abs(x-median_odds), odds_half))
sum_evens = sum(map(lambda x: abs(x-median_evens), evens_half))

print(sum_odds+sum_evens)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
V = list(map(int, input().split()))

def modification(d):
    d_keys = list(d.values())
    if len(d_keys) == 1:
        return 0
    d_keys.sort(reverse=True)
    return int(n / 2) - d_keys[0]

if len(set(V)) == 1:
    print(int(n / 2))
else:
    o = defaultdict(int)
    e = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            e[V[i]] += 1
        else:
            o[V[i]] += 1
    print(modification(o) + modification(e))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
vn = list(map(int, input().split()))

vn_e = vn[0::2]
vn_o = vn[1::2]

most_freq_e = Counter(vn_e).most_common()
most_freq_o = Counter(vn_o).most_common()

if most_freq_o[0][0] == most_freq_e[0][0]:
    print((len(vn_e)-most_freq_e[0][1])+(len(vn_o)-most_freq_o[0][1])+len(vn_e))
else:
    print((len(vn_e)-most_freq_e[0][1])+(len(vn_o)-most_freq_o[0][1]))

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[6]:


import collections


# In[115]:


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


# In[116]:


values1,count1 = zip(*collections.Counter(v[::2]).most_common())    
values2,count2 = zip(*collections.Counter(v[1::2]).most_common())

if values1[0] != values2[0]:
    ret = sum(count1[1:]) + sum(count2[1:])
else:
    if len(count1) == 1 and len(count2) == 1:
        ret = sum(count1)
    elif len(count1) == 1:
        ret = sum(count2[1:])
    elif len(count2) == 1:
        ret = sum(count1[1:])
    else:
        if count1[1] > count2[1]:
            ret = sum(count1[1:]) + sum(count2) - count2[0]
        else:
            ret = sum(count1) - count1[0] + sum(count2)


# In[117]:


print(ret)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
V = list(map(int, input().split()))
e = list(Counter(V[0::2]).items())
o = list(Counter(V[1::2]).items())

e.sort(key=lambda x:x[1], reverse=True)
o.sort(key=lambda x:x[1], reverse=True)

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    ans = 100010
    for i in e[:2]:
        for j in o[:2]:
            ans = min(ans, n - i[1] - j[1])
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
V = list(map(int, input().split()))
e = list(Counter(V[0::2]).items())
o = list(Counter(V[1::2]).items())

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    ans = 100010
    for i in e[:2]:
        for j in o[:2]:
            ans = min(ans, n - i[1] - j[1])
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
listV = list(map(int, input().split()))
oddL=[]
evenL=[]
index=0
while index < len(listV):
    if index%2==0:
        oddL.append(listV[index])
    else:
        evenL.append(listV[index])
    index+=1
oddL.sort()
evenL.sort()
oddKanri=[0, 0, 0, 0, 0, 0] #1thNum, 1thCounter, 2thNum, 2thCounter, currentNum, currentCounter
evenKanri=[0, 0, 0, 0, 0, 0]

index2=0
while index2 < len(oddL):
    if index2 == 0:
        oddKanri[4] = oddL[index2]
        oddKanri[5]=1
    else:
        if oddL[index2] == oddKanri[4]:
            oddKanri[5]+=1
        else:
            if oddKanri[5] > oddKanri[1]:
                oddKanri[0] = oddKanri[4]
                oddKanri[1] = oddKanri[5]
            elif oddKanri[5] > oddKanri[3]:
                oddKanri[2] = oddKanri[4]
                oddKanri[3] = oddKanri[5]
            oddKanri[4] = listV[index2]
            oddKanri[5]=1
    index2+=1
if oddKanri[5] > oddKanri[1]:
    oddKanri[0] = oddKanri[4]
    oddKanri[1] = oddKanri[5]
elif oddKanri[5] > oddKanri[3]:
    oddKanri[2] = oddKanri[4]
    oddKanri[3] = oddKanri[5]

index2 = 0
while index2 < len(evenL):
    if index2 == 0:
        evenKanri[4] = evenL[index2]
        evenKanri[5] = 1
    else:
        if evenL[index2] == evenKanri[4]:
            evenKanri[5] += 1
        else:
            if evenKanri[5] > evenKanri[1]:
                evenKanri[0] = evenKanri[4]
                evenKanri[1] = evenKanri[5]
            elif evenKanri[5] > evenKanri[3]:
                evenKanri[2] = evenKanri[4]
                evenKanri[3] = evenKanri[5]
            evenKanri[4] = listV[index2]
            evenKanri[5] = 1
    index2 += 1
if evenKanri[5] > evenKanri[1]:
    evenKanri[0] = evenKanri[4]
    evenKanri[1] = evenKanri[5]
elif evenKanri[5] > evenKanri[3]:
    evenKanri[2] = evenKanri[4]
    evenKanri[3] = evenKanri[5]

if oddKanri[0]!=evenKanri[0]:
    print(n-oddKanri[1]-evenKanri[1])
else:
    print(n-max(oddKanri[1]+evenKanri[3], oddKanri[3]+evenKanri[1]))

Submission status: Wrong Answer

Solution code:
#cording: utf-8

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

count = 0

if len(list(set( v ))) == 1:
    count = int(N/2)
    print(count)

else:
    for i in range(N-2):
        if v[i] != v[i+2]:
            #v[i]とv[i+2]以降の要素v[j]のうち，多く含まれる方の出ないものを多く含まれるものにする
            List = []
            count_vi = 0
            count_vi2 = 0
            for j in range(i, N-2, 2):
                List.append(v[j])
            count_vi = List.count(v[i])
            count_vi2 = List.count(v[i+2])
            #ここまで
            if count_vi < count_vi2:
                v[i] = v[i+2]
            if count_vi > count_vi2:
                v[i+2] = v[i]
            if count_vi == count_vi2:
                v[i] = v[i+2]
            count += 1

print(count)

Submission status: Wrong Answer

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

va, ve = v[0::2], v[1::2]
da, de = {}, {}
for a in va:
  da[a] = da.get(a, 0)+1
for e in ve:
  de[e] = de.get(e, 0)+1
add = sorted([(k,v) for k,v in da.items()], key=lambda x:-x[1])+[(0,0)]
even = sorted([(k,v) for k,v in de.items()], key=lambda x:-x[1])+[(0,0)]
if add[0][0] == even[0][0]:
  if add[1][1] <= even[1][1]:
    even.pop(0)
  else:
    add.pop(0)
print(n-add[0][1]-even[0][1])
print(add, even)

Submission status: Wrong Answer

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

va, ve = v[0::2], v[1::2]
da, de = {}, {}
for a in va:
  da[a] = da.get(a, 0)+1
for e in ve:
  de[e] = de.get(e, 0)+1
add = sorted([(k,v) for k,v in da.items()], key=lambda x:-x[1])+[(0,0)]
even = sorted([(k,v) for k,v in de.items()], key=lambda x:-x[1])+[(0,0)]
if add[0][0] == even[0][0]:
  if add[1][1] <= even[1][1]:
    add.pop(0)
  else:
    even.pop(0)

print(n-add[0][1]-even[0][1])

Submission status: Wrong Answer

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

va, ve = v[0::2], v[1::2]
da, de = {}, {}
for a in va:
  da[a] = da.get(a, 0)+1
for e in ve:
  de[e] = de.get(e, 0)+1
add = sorted([(k,v) for k,v in da.items()], key=lambda x:x[1])+[(0,0)]
even = sorted([(k,v) for k,v in de.items()], key=lambda x:x[1])+[(0,0)]
if add[0][0] == even[0][0]:
  if add[1][1] <= even[1][1]:
    add.pop(0)
  else:
    even.pop(0)
print(n-add[0][1]-even[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
va, ve = v[0::2], v[1::2]

add = max([va.count(i) for i in set(va)])
even = max([ve.count(i) for i in set(ve)])

print(len(v)-add-even if add!=even else len(v)-add)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
v = list(map(int, input().split()))

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

o = Counter(odd).most_common(2)
e = Counter(even).most_common(2)

o.append((0,0))
e.append((0,0))

ans = N//2

for d1 in o:
    for d2 in e:
        if d1[0]!=d2[0]:
            ans = min(ans, N-d1[1]-d2[1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
v = list(map(int, input().split()))

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

o = Counter(odd).most_common(2)
e = Counter(even).most_common(2)

ans = N//2
for d1 in o:
    for d2 in e:
        if d1[0]!=d2[0]:
            ans = min(ans, N-d1[1]-d2[1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
v = list(map(int, input().split()))

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

o = Counter(odd).most_common(2)
e = Counter(even).most_common(2)

ans = int(N/2)
for d1 in o:
    for d2 in e:
        if d1[0]==d2[0] :
            continue
        ans = min(ans, N-d1[1]-d2[1])

print(ans)

Submission status: Wrong Answer

Solution code:
#import itertools
from collections import Counter

def op(v):
    count = Counter(v).most_common() 

    #v_ = itertools.groupby(sorted(v))
    #count = sorted([(k, len(list(g))) for k, g in v_], key = lambda x:x[1])
    return count

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

if len(set(V)) == 1:
    ans = len(V) // 2
else:
    vp_ = [v for i, v in enumerate(V) if i%2 == 0] 
    vn_ = [v for i, v in enumerate(V) if i%2 != 0] 

    vp = op(vp_)
    vn = op(vn_)    

    if vp[0][0] != vn[0][0]:
        gp = vp[0][1]
        gn = vn[0][1]
    else:
        if vp[0][1] > vn[0][1]:
            gp = vp[0][1]
            gn = vn[1][1]
        else:
            gp = vp[1][1]
            gn = vn[0][1]

    #ans_p = sum([g for k, g in vp]) - gp
    #ans_n = sum([g for k, g in vn]) - gn

    #ans  = ans_p + ans_n
    ans = n - gp - gn

print(ans)

Submission status: Wrong Answer

Solution code:
#import itertools
from collections import Counter

def op(v):
    count = Counter(v).most_common() 

    #v_ = itertools.groupby(sorted(v))
    #count = sorted([(k, len(list(g))) for k, g in v_], key = lambda x:x[1])
    return count

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

if len(set(V)) == 1:
    ans = len(V) // 2
else:
    vp_ = [v for i, v in enumerate(V) if i%2 == 0] 
    vn_ = [v for i, v in enumerate(V) if i%2 != 0] 

    vp = op(vp_)
    vn = op(vn_)    

    if vp[-1][0] != vn[-1][0]:
        gp = vp[-1][1]
        gn = vn[-1][1]
    else:
        if vp[-1][1] > vn[-1][1]:
            gp = vp[-1][1]
            gn = vn[-2][1]
        else:
            gp = vp[-2][1]
            gn = vn[-1][1]

    #ans_p = sum([g for k, g in vp]) - gp
    #ans_n = sum([g for k, g in vn]) - gn

    #ans  = ans_p + ans_n
    ans = n - gp - gn

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
v = input().split()

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

o = Counter(odd).most_common(3)
e = Counter(even).most_common(3)

ans = int(N/2)
for d1 in o:
    for d2 in e:
        if d1[0]==d2[0] :
            continue
        ans = min(ans, N-d1[1]-d2[1])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
v = input().split()

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

o = Counter(odd).most_common(2)
e = Counter(even).most_common(2)

ans = int(N/2)
for d1 in o:
    for d2 in e:
        if d1[0]==d2[0] :
            continue
        ans = min(ans, N-d1[1]-d2[1])

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def op(v):
    v_ = itertools.groupby(sorted(v))
    count = sorted([(k, len(list(g))) for k, g in v_], key = lambda x:x[1])
    return count

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

if len(set(V)) == 1:
    ans = len(V) // 2
else:
    vp_ = [v for i, v in enumerate(V) if i%2 == 0] 
    vn_ = [v for i, v in enumerate(V) if i%2 != 0] 

    vp = op(vp_)
    vn = op(vn_)    

    if vp[-1][0] != vn[-1][0]:
        gp = vp[-1][1]
        gn = vn[-1][1]
    else:
        if vp[-1][1] > vn[-1][1]:
            gp = vp[-1][1]
            gn = vn[-2][1]
        else:
            gp = vp[-2][1]
            gn = vn[-1][1]

    #ans_p = sum([g for k, g in vp]) - gp
    #ans_n = sum([g for k, g in vn]) - gn

    #ans  = ans_p + ans_n
    ans = n - gp - gn

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def op(v):
    v_ = itertools.groupby(sorted(v))
    count = sorted([(k, len(list(g))) for k, g in v_], key = lambda x:x[1])
    return count

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

if len(set(V)) == 1:
    ans = len(V) // 2
else:
    vp_ = [v for i, v in enumerate(V) if i%2 == 0] 
    vn_ = [v for i, v in enumerate(V) if i%2 != 0] 

    vp = op(vp_)
    vn = op(vn_)    

    if vp[-1][0] != vn[-1][0]:
        gp = vp[-1][1]
        gn = vn[-1][1]
    else:
        if vp[-1][1] > vn[-1][1]:
            gp = vp[-1][1]
            gn = vn[-2][1]
        else:
            gp = vp[-2][1]
            gn = vn[-1][1]

    ans_p = sum([g for k, g in vp]) - gp
    ans_n = sum([g for k, g in vn]) - gn
    ans  = ans_p + ans_n
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def op(v):
    v_ = itertools.groupby(sorted(v))
    count = sorted([(k, len(list(g))) for k, g in v_], key = lambda x:x[1])
    return count

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

if len(set(V)) == 1:
    ans = int(len(V)/2)
else:
    vp_ = [v for i, v in enumerate(V) if i%2 == 0] 
    vn_ = [v for i, v in enumerate(V) if i%2 != 0] 

    vp = op(vp_)
    vn = op(vn_)    

    if vp[-1][0] != vn[-1][0]:
        gp = vp[-1][1]
        gn = vn[-1][1]
    else:
        if vp[-1][1] > vn[-1][1]:
            gp = vp[-1][1]
            gn = vn[-2][1]
        else:
            gp = vp[-2][1]
            gn = vn[-1][1]

    ans_p = sum([g for k, g in vp]) - gp
    ans_n = sum([g for k, g in vn]) - gn
    ans  = ans_p + ans_n
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def op(v):
    v_ = itertools.groupby(sorted(v))
    count = sorted([(k, len(list(g))) for k, g in v_], key = lambda x:x[1])
    return count

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

if len(set(V)) == 1:
    ans = int(len(V)/2)
else:
    vp_ = [v for i, v in enumerate(V) if i%2 == 0] 
    vn_ = [v for i, v in enumerate(V) if i%2 != 0] 

    vp = op(vp_)
    vn = op(vn_)    

    if vp[-1][0] != vn[-1][0]:
        gp = vp[-1][1]
        gn = vn[-1][1]
    else:
        if vp[-1][1] >= vn[-1][1]:
            gp = vp[-1][1]
            gn = vn[-2][1]
        else:
            gp = vp[-2][1]
            gn = vn[-1][1]

    ans_p = sum([g for k, g in vp]) - gp
    ans_n = sum([g for k, g in vn]) - gn
    ans  = ans_p + ans_n
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
do = {0:0}
de = {0:0}
for i in range(n):
    if i % 2:
        do[v[i]] = do.get(v[i], 0) + 1
    else:
        de[v[i]] = de.get(v[i], 0) + 1
o = max(do, key=do.get)
e = max(de, key=de.get)
if o != e:
    print(n-do[o]-de[e])
else:
    vo = do.pop(o)
    ve = de.pop(e)
    vo2 = max(do.values())
    ve2 = max(de.values())
    print(n - min(vo+ve2, ve+vo2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
if len(set(V))==1:
  print(n//2)
  exit()
v1=Counter(V[::2]).most_common()
v2=Counter(V[1::2]).most_common()
if v1[0][0]==v2[0][0]:
  if v1[0][1]>v2[0][1]:
    print(n-v1[1][1]-v2[0][1])
  else:
    print(n-v1[0][1]-v2[1][1])
else:
  print(n-v1[0][1]-v2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
if len(set(V))==1:
  print(n//2)
  exit()
v1=Counter(V[::2]).most_common()
v2=Counter(V[1::2]).most_common()
if v1[0][0]==v2[0][0]:
  if v1[0][1]>v2[0][1]:
    print(n-v1[0][1]-v2[1][1])
  else:
    print(n-v1[1][1]-v2[0][1])
else:
  print(n-v1[0][1]-v2[0][1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools

def op(v):
    v_ = itertools.groupby(sorted(v))
    count = sorted([len(list(g)) for k, g in v_])
    return sum(count[:-1])

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

if len(set(V)) == 1:
    ans = int(len(V)/2)
else:
    Vp = [v for i, v in enumerate(V) if i%2 == 0] 
    Vn = [v for i, v in enumerate(V) if i%2 != 0] 
    ans = op(Vp) + op(Vn)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def op(v):
    v_ = itertools.groupby(v)
    count = sorted([len(list(g)) for k, g in v_])
    return sum(count[:-1])

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

if len(set(V)) == 1:
    ans = int(len(V)/2)
else:
    Vp = [v for i, v in enumerate(V) if i%2 == 0] 
    Vn = [v for i, v in enumerate(V) if i%2 != 0] 
    ans = op(Vp) + op(Vn)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

def op(v):
    v_ = itertools.groupby(v)
    count = sorted([len(list(g)) for k, g in v_])
    return sum(count[:-1])

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

if len(set(V)) == 1:
    ans = int(len(V)/2)
else:
    Vp = itertools.islice(V, 0, n, 2)
    Vn = itertools.islice(V, 1, n, 2)
    ans = op(Vp) + op(Vn)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
elist=[]
olist=[]
ae=list(map(int,input().split(" ")))
for i in range(int(N/2)):
    elist.append(ae[2*i])
    olist.append(ae[2*i+1])
maxe=elist.count(max(elist))
maxo=olist.count(max(olist))
if max(elist)==max(olist):
    if elist.count(max(elist))!=(N/2):
        elist.remove(max(elist))
        maxe=elist.count(max(elist))
        res=N-maxe-maxo
    else:
        res=maxo
else:
    res=N-maxe-maxo
print(res)

Submission status: Wrong Answer

Solution code:
odd = {}
even = {}
N = int(input())
V = list(map(int, input().split()))
for i in range(N):
    if i % 2 == 0:
        odd.setdefault(V[i], 0)
        odd[V[i]] += 1
    else:
        even.setdefault(V[i], 0)
        even[V[i]] += 1
cnt = 0
maxodd1 = 0
maxodd2 = 0
for i, kv in enumerate(sorted(odd.items(), key=lambda x:x[1], reverse=True)):
    if i == 0:
        maxodd1 = kv[0]
        continue
    elif i == 1:
        maxodd2 = kv[0]
    cnt += kv[1]
skipi = -1
cnts = [0, 0]
for i, k in enumerate(sorted(even.items(), key=lambda x:x[1], reverse=True)):
    if skipi == i:
        continue
    if i == 0:
        if maxodd1 == k[0]:
            cnts[0] += k[1]
            skipi = i + 1
        else:
            continue
    else:
        cnts[0] += k[1]
skipi = 0
for i, k in enumerate(sorted(even.items(), key=lambda x:x[1], reverse=True)):
    if skipi == i:
        continue
    if i == 0:
        if maxodd2 == k[0]:
            cnts[1] += k[1]
            skipi = i + 1
        else:
            continue
    else:
        cnts[1] += k[1]
print(cnt + min(cnts))

Submission status: Wrong Answer

Solution code:
odd = {}
even = {}
N = int(input())
V = list(map(int, input().split()))
for i in range(N):
    if i % 2 == 0:
        odd.setdefault(V[i], 0)
        odd[V[i]] += 1
    else:
        even.setdefault(V[i], 0)
        even[V[i]] += 1
cnt = 0
maxodd = 0
for i, kv in enumerate(sorted(odd.items(), key=lambda x:x[1], reverse=True)):
    if i == 0:
        maxodd = kv[0]
    else:
        cnt += kv[1]
skipi = -1
for i, k in enumerate(sorted(even.items(), key=lambda x:x[1], reverse=True)):
    if skipi == i:
        continue
    if i == 0:
        if maxodd == k[0]:
            cnt += k[1]
            skipi = i + 1
        else:
            continue
    else:
        cnt += k[1]
print(cnt)

Submission status: Wrong Answer

Solution code:
odd = {}
even = {}
N = int(input())
V = list(map(int, input().split()))
for i in range(N):
    if i % 2 == 0:
        odd.setdefault(V[i], 0)
        odd[V[i]] += 1
    else:
        even.setdefault(V[i], 0)
        even[V[i]] += 1
sorted(odd.items(), key=lambda x:x[1], reverse=True)
sorted(even.items(), key=lambda x:x[1], reverse=True)
cnt = 0
maxodd = 0
for i, k in enumerate(odd.keys()):
    if i == 0:
        maxodd = k
    else:
        cnt += odd[k]
skipi = -1
for i, k in enumerate(even.keys()):
    if skipi == i:
        continue
    if maxodd == k:
        cnt += even[k]
        skipi = i + 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 0:
    print("0")
else:
    l=input().split()
    even = l[::2]
    odd = l[1::2]
    evenset = set(l[::2])
    oddset = set(l[1::2])

    b=[]
    c=[]
    for u in evenset:
        b.append(int(even.count(u)))
    for j in oddset:
        c.append(int(odd.count(j)))

    print(sum(b)+sum(c)-max(b)-max(c))

Submission status: Wrong Answer

Solution code:
n = int(input())
l=input().split()
a1 = l[::2]
a2 = l[1::2]
a3 = set(l[::2])
a4 = set(l[1::2])

b=[]
c=[]
for u in a3:
    b.append(int(a1.count(u)))
for j in a4:
    c.append(int(a2.count(j)))

print(sum(b)+sum(c)-max(b)-max(c))

Submission status: Wrong Answer

Solution code:
n = input()
v = input()
v = [int(i) for i in v.split(' ')]
ch1={}
ch1_k = []
ch2={}
ch2_k = []

cnt=0
init = v[0]
from operator import itemgetter
for i in range(int(int(n)/2)):
    if v[i] == init:
        cnt += 1
    if v[i*2] not in ch1:
        ch1[v[i*2]] = 1
        ch1_k.append(v[i*2])
    else:
        ch1[v[i*2]] += 1


    if v[i*2+1] not in ch2:
        ch2[v[i*2+1]] = 1
        ch2_k.append(v[i*2+1])
    else:
        ch2[v[i*2+1]] += 1


if len(ch1) == len(ch2)  and len(ch1) == 1 and ch1_k[0] == ch2_k[0]:
    print(int(int(n)/2))
elif max(ch1.items(), key=itemgetter(1))[0] == max(ch2.items(), key=itemgetter(1))[0]:
    a = int(int(n)/2) - max(ch1.values())
    del ch2[max(ch1.items(), key=itemgetter(1))[0]]
    b = int(int(n)/2) - max(ch2.values())
    print(a+b)
else:
    a = int(int(n)/2) - max(ch1.values())
    b = int(int(n)/2) - max(ch2.values())
    print(a+b)

Submission status: Wrong Answer

Solution code:
n = input()
v = input()
v = [int(i) for i in v.split(' ')]
ch1={}
ch1_k = []
ch2={}
ch2_k = []

cnt=0
init = v[0]
from operator import itemgetter
for i in range(int(int(n)/2)):
    if v[i] == init:
        cnt += 1
    if v[i*2] not in ch1:
        ch1[v[i*2]] = 1
        ch1_k.append(v[i*2])
    else:
        ch1[v[i*2]] += 1


    if v[i*2+1] not in ch2:
        ch2[v[i*2+1]] = 1
        ch2_k.append(v[i*2+1])
    else:
        ch2[v[i*2+1]] += 1


if len(ch1) == len(ch2) and len(ch1) == 1 and ch1_k[0] != ch2_k[0]:
    print(0)
elif len(ch1) == len(ch2)  and len(ch1) == 1 and ch1_k[0] == ch2_k[0]:
    print(int(int(n)/2))
elif max(ch1.items(), key=itemgetter(1))[0] == max(ch2.items(), key=itemgetter(1))[0]:
    a = int(int(n)/2) - max(ch1.values())
    del ch2[max(ch1.items(), key=itemgetter(1))[0]]
    b = int(int(n)/2) - max(ch2.values())
    print(a+b)
else:
    a = int(int(n)/2) - max(ch1.values())
    b = int(int(n)/2) - max(ch2.values())
    print(a+b)