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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
count = 0
v_unique = list(set(v))
for i in range(n-2):
    if v[i] == v[i+2]:
        pass
    else:
        count += 1
if len(v_unique) == 2:
    print(count)
elif len(v_unique) == 1:
    if n % 2 == 0:
        print(int(n/2))
    else:
        print(int((n-1)/2))
else:
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
i_num = 0
two_0 = []
two_1 = []
for i in v:
    if i_num % 2 == 0:
        two_0.append(i)
    else:
        two_1.append(i)
    i_num += 1
two_1_counter = Counter(two_1)
t1_elem = two_1_counter.most_common()[0][0]
t1 = two_1_counter.most_common()[0][1]
two_0_counter = Counter(two_0)
if two_0_counter.most_common()[0][0] == t1_elem:
    if two_0_counter.most_common()[0][1] != len(two_0):
        t0 = two_0_counter.most_common()[1][1]
    else:
        t0 = 0
else:
    t0 = two_0_counter.most_common()[0][1]
print(n - (t0+t1))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
i_num = 0
two_0 = []
two_1 = []
for i in v:
    if i_num % 2 == 0:
        two_0.append(i)
    else:
        two_1.append(i)
    i_num += 1
two_0_counter = Counter(two_0)
t0_elem = two_0_counter.most_common()[0][0]
t0 = two_0_counter.most_common()[0][1]
two_1_counter = Counter(two_1)
if two_1_counter.most_common()[0][0] == t0_elem:
    if two_1_counter.most_common()[0][1] != len(two_1):
        t1 = two_1_counter.most_common()[1][1]
    else:
        t1 = 0
else:
    t1 = two_1_counter.most_common()[0][1]
print(n - (t0+t1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
odd=[0*i for i in range(100002)]
even=[0*j for j in range(100002)]
for i in range(n):
  if i%2:
    even[v[i]] += 1
  else:
    odd[v[i]] += 1

mode_odd=0
mode_even=0
secondary_mode_odd=0
secondary_mode_even=0
count_mode_odd=0
count_mode_even=0
count_secondary_mode_odd=0
count_secondary_mode_even=0
for i in range(len(odd)):
  if count_mode_odd <= odd[i]:
    secondary_mode_odd = mode_odd
    count_secondary_mode_odd = count_mode_odd
    mode_odd = i
    count_mode_odd = odd[i]
  else:
    pass
for j in range(len(even)):
  if count_mode_even <= even[j]:
    secondary_mode_even = mode_even
    count_secondary_mode_even = count_mode_even
    mode_even = j
    count_mode_even = even[j]
  else:
    pass

if mode_odd != mode_even:
  print(n-odd[mode_odd]-even[mode_even])
else:
  print(min(n-odd[secondary_mode_odd]-even[mode_even], n-odd[mode_odd]-even[secondary_mode_even]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int, input().split()))
v1=Counter(v[::2])
v2=Counter(v[1::2])
c1=v1.most_common()+[(0, 0)]
c2=v2.most_common()+[(0, 0)]
if c1[0][0]==c2[0][0]:
    ans=max(c1[1][1]+c2[0][1], c1[0][1]-c2[1][1])
    print(n-ans)
else:
    print(n-c1[0][1]-c2[0][1])

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

def calc_replace_count(v):
    nums_count = {}

    for v_i in v:
        if v_i in nums_count:
            nums_count[v_i] += 1
        else:
            nums_count[v_i] = 1

    max_v = max(nums_count.items(), key=lambda x:x[1])

    return len(v) - max_v[1], max_v[0]


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

v_odd = v[::2]
v_even = v[1::2]

odd_count, odd_key = calc_replace_count(v_odd)
even_count, even_key = calc_replace_count(v_even)

print(len(v) // 2 if odd_key == even_key else odd_count + even_count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

if len(odd) == 1 and len(even) == 1:
    if odd[0] == even[0]:
        ans = n // 2
    else:
        ans = 0
else:
    if len(odd) == 1:
        if odd[0][0] != even[0][0]:
            ans = n // 2 - even[0][1]
        else:
            ans = n // 2 - even[1][1]
    elif len(even) == 1:
        if even[0][0] != odd[0][0]:
            ans = n // 2 - odd[0][1]
        else:
            ans = n // 2 - odd[1][1]
    else:
        if odd[0][0] == even[0][0]:
            tmp = [n // 2 - odd[0][1] - even[1][1],
                   n // 2 - odd[1][1] - even[0][1]]
            ans = min(tmp)
        else:
            ans = n - odd[0][1] - even[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections as col
n = int(input())
v = list(map(int,input().split()))

vE,vO = v[0::2],v[1::2]
ansE,ansO = 0,0

lmodeE, lmodeO = col.Counter(vE).most_common(), col.Counter(vO).most_common()
modeE, nmodeE = lmodeE[0][0], lmodeE[0][1]
modeO, nmodeO = lmodeO[0][0], lmodeO[0][1]

if modeE == modeO:
    if nmodeE > nmodeO:
        if len(lmodeO) == 1:
            nmodeO = 0
        else:
            modeO, nmodeO = lmodeO[1][0], lmodeO[1][1]
    if nmodeO >= nmodeE:
        if len(lmodeE) == 1:
            nmodeE = 0
        else:
            modeE, nmodeE = lmodeE[1][0], lmodeE[1][1]

ansE = int(n/2) - nmodeE
ansO = int(n/2) - nmodeO

print(ansE+ansO)

Submission status: Wrong Answer

Solution code:
import collections as col
n = int(input())
v = list(map(int,input().split()))

vE,vO = v[0::2],v[1::2]
ansE,ansO = 0,0

lmodeE, lmodeO = col.Counter(vE).most_common(), col.Counter(vO).most_common()
modeE, nmodeE = lmodeE[0][0], lmodeE[0][1]
modeO, nmodeO = lmodeO[0][0], lmodeO[0][1]

if modeE == modeO:
    if nmodeE > nmodeO:
        if len(lmodeO) == 1:
            nmodeO = 0
        else:
            modeO, nmodeO = lmodeO[1][0], lmodeO[1][1]
    if nmodeO >= nmodeE:
        if len(lmodeE) == 1:
            nmodeE = 0
        else:
            modeE, nmodeE = lmodeE[0][0], lmodeE[0][1]

ansE = int(n/2) - nmodeE
ansO = int(n/2) - nmodeO

print(ansE+ansO)

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

def main():
    a = sorted(V[::2])
    b = sorted(V[1::2])

    freq_a = [(k, len(list(g))) for k, g in groupby(a)]
    freq_b = [(k, len(list(g))) for k, g in groupby(b)]

    freq_a.sort(key=lambda t: t[1], reverse=True)
    freq_b.sort(key=lambda t: t[1], reverse=True)

    freq_a.append((0, 0))
    freq_b.append((0, 0))

    if freq_a[0][0] == freq_b[0][0]:
        if freq_a[0][1] > freq_b[0][1]:
            na = freq_a[0][1]
            nb = freq_b[1][1]
        elif freq_a[0][1] < freq_b[0][1]:
            na = freq_a[1][1]
            nb = freq_b[0][1]
        else:
            if freq_a[1][1] >= freq_b[1][1]:
                na = freq_a[0][1]
                nb = freq_b[1][1]
            else:
                na = freq_a[1][1]
                nb = freq_b[0][1]
    else:
        na = freq_a[0][1]
        nb = freq_b[0][1]
        
    ans = len(a) - na + len(b) - nb

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import groupby

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

def main():
    a = sorted(V[::2])
    b = sorted(V[1::2])
    
    freq_a = [(k, len(list(g))) for k, g in groupby(a)]
    freq_b = [(k, len(list(g))) for k, g in groupby(b)]

    freq_a.sort(key=lambda t: t[1], reverse=True)
    freq_b.sort(key=lambda t: t[1], reverse=True)

    freq_a.append((0, 0))
    freq_b.append((0, 0))

    if freq_a[0][0] == freq_b[0][0]:
        if freq_a[0][1] >= freq_b[0][1]:
            na = freq_a[0][1]
            nb = freq_b[1][1]
        else:
            na = freq_a[1][1]
            nb = freq_b[0][1]
    else:
        na = freq_a[0][1]
        nb = freq_b[0][1]
        
    ans = len(a) - na + len(b) - nb

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import statistics
def find_max_mode(list1):
    list_table = statistics._counts(list1)
    len_table = len(list_table)

    if len_table == 1:
        max_mode = statistics.mode(list1)
    else:
        new_list = []
        for i in range(len_table):
            new_list.append(list_table[i][0])
        max_mode = max(new_list) # use the max value here
    return max_mode

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

g = []
k = []

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

kave = find_max_mode(k)
gave = find_max_mode(g)
if kave == gave:
    kave += 1

ans = 0

for i in range(len(k)):
    if k[i] != kave:
        ans += 1
    if g[i] != gave:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

g = []
k = []

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

kave = round(sum(k) / len(k))
gave = round(sum(g) / len(g))
if kave == gave:
    kave += 1

print(kave)
print(gave)

ans = 0

for i in range(len(k)):
    if k[i] != kave:
        ans += 1
    if g[i] != gave:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

g = []
k = []

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

kave = round(sum(k) / len(k))
gave = round(sum(g) / len(g))
if kave == gave:
    kave += 1

ans = 0

for i in range(len(k)):
    ans += abs(k[i] - kave)
    ans += abs(g[i] - gave)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
vs = input().split()
even = []
odd = []

if len(list(set(vs))) == 1:
  res = int(len(vs) / 2)
else:
  for i, v in enumerate(vs):
    if i % 2 == 0:
      even.append(int(v))
    else:
      odd.append(int(v))
  counter_even = Counter(even)
  counter_odd = Counter(odd)
  res = len(even) - counter_even.most_common()[0][1] + len(odd) - counter_odd.most_common()[0][1] 

print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = input().split()
vls = []

for x in v:
    vls.append(int(x))

v1 = vls[0::2]
v2 = vls[1::2]

c1 = Counter(v1)
c2 = Counter(v2)

ya1 = c1.most_common()[0]
ya2 = c2.most_common()[0]

if ya1[0] == ya2[0]:
    if len(c1.most_common())== 1 and len(c2.most_common()) == 1:
        print(len(v2))
        exit()
    elif ya1[1] >= ya2[1]:
        ya2 = c2.most_common()[1]
    else:
        ya1 = c1.most_common()[1]

print(int(((n/2)-ya1[1]) + ((n/2)-ya2[1])))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = input().split()
vls = []

for x in v:
    vls.append(int(x))

v1 = vls[0::2]
v2 = vls[1::2]

c1 = Counter(v1)
c2 = Counter(v2)

ya1 = c1.most_common()[0]
ya2 = c2.most_common()[0]

if ya1[0] == ya2[0]:
    if len(c1.most_common()) and len(c2.most_common()) == 1:
        print(len(v2))
        exit()
    elif ya1[1] >= ya2[1]:
        ya2 = c2.most_common()[1]
    else:
        ya1 = c1.most_common()[1]

print(int(((n/2)-ya1[1]) + ((n/2)-ya2[1])))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import Counter
def main():
    va = []
    vb = []
    n = int(input())
    *v, = map(int, input().split())
    for i in range(len(v)):
        if i % 2 == 0:
            va.append(v[i])
        else:
            vb.append(v[i])
    a1 = Counter(va).most_common()[0][0]
    a2 = Counter(vb).most_common()[0][0]
    how_many_a1 = Counter(va).most_common()[0][1]
    how_many_a2 = Counter(vb).most_common()[0][1]
    if a1 != a2:
        print(n - how_many_a1 - how_many_a2)
    else:
        print(int(n/2))

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import Counter
def main():
    va = []
    vb = []
    n = int(input())
    *v, = map(int, input().split())
    for i in range(len(v)):
        if i % 2 == 0:
            va.append(v[i])
        else:
            vb.append(v[i])
    a1 = Counter(va).most_common()[0][1]
    a2 = Counter(vb).most_common()[0][1]
    if a1 != a2:
        print(n - a1 - a2)
    else:
        print(int(n/2))

main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import Counter
def main():
    va = []
    vb = []
    n = int(input())
    *v, = map(int, input().split())
    for i in range(len(v)):
        if i % 2 == 0:
            va.append(v[i])
        else:
            vb.append(v[i])
    a1 = Counter(va).most_common()[0][1]
    a2 = Counter(vb).most_common()[0][1]
    print(n - a1 - a2)


main()

Submission status: Wrong Answer

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


odd = len(set(v[0:n:2]))
even = len(set(v[1:n:2]))
print(abs(odd - even))

Submission status: Wrong Answer

Solution code:
import collections

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

Submission status: Wrong Answer

Solution code:
import collections

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

Submission status: Wrong Answer

Solution code:
import collections

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

Submission status: Wrong Answer

Solution code:
import collections

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

Submission status: Wrong Answer

Solution code:
import collections

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

if (even_count > odd_count):
    print((half_count - even_count) + (half_count - odd_count))
elif (even_count < odd_count):
    print((half_count - odd_count) + (half_count - even_count))
else:
    # if(odd_elem == even_elem):
    #     print((half_count - odd_count) + (half_count - even_count))
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v_ = list(map(int,input().split()))
v_g = v_[0:len(v_):2]
v_k = v_[1:len(v_):2]

counter_g = collections.Counter(v_g)
counter_g = sorted(counter_g.items(),key=lambda x:x[1])[::-1]
counter_k = collections.Counter(v_k)
counter_k = sorted(counter_k.items(),key=lambda x:x[1])[::-1]


if counter_g[0][0] == counter_k[0][0]:
  if len(counter_g) == 1 and len(counter_k) == 1:
    print(int(n/2))
  else:
    if len(counter_g) == 1:
      print(len(counter_k)-counter_k[1][1])
    else:
      print(len(counter_g)-counter_g[1][1])
else:
  print(n - counter_g[0][1] - counter_k[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v_ = list(map(int,input().split()))
v_g = v_[0:len(v_):2]
v_k = v_[1:len(v_):2]

counter_g = collections.Counter(v_g)
counter_g = sorted(counter_g.items(),key=lambda x:x[1])[::-1]
counter_k = collections.Counter(v_k)
counter_k = sorted(counter_k.items(),key=lambda x:x[1])[::-1]


if counter_g[0][0] == counter_k[0][0]:
  if len(counter_g) == 1 and len(counter_k) == 1:
    print(int(n/2))
  else:
    if len(counter_g) == 1:
      print(n-counter_k[1][1])
    else:
      print(n-counter_g[1][1])
else:
  print(n - counter_g[0][1] - counter_k[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v_ = list(map(int,input().split()))
v_g = v_[0:len(v_):2]
v_k = v_[1:len(v_):2]

counter_g = collections.Counter(v_g)
counter_g = sorted(counter_g.items(),key=lambda x:x[1])
counter_k = collections.Counter(v_k)
counter_k = sorted(counter_k.items(),key=lambda x:x[1])


if counter_g[-1] == counter_k[-1]:
  print(int(n/2))
else:
  print(n - counter_g[-1][1] - counter_k[-1][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v_ = list(map(int,input().split()))
counter = collections.Counter(v_)
counter = sorted(counter.items(),key=lambda x:x[1])[::-1]
if len(counter) == 1:
  print(int(n/2))
else:
  print(n - counter[0][1] - counter[1][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
v1 = [v[i*2+1] for i in range(n//2)]
v2 = [v[i*2] for i in range(n//2)]
c1 = collections.Counter(v1).most_common()
c2 = collections.Counter(v2).most_common()

if len(set(v1)) == len(set(v2)) == 1:
  if c1[0][0] != c2[0][0]:
    print(0)
  else:
    print(min(len(v1), len(v2)))    
elif len(set(v1))==1:
  if c1[0][0] != c2[0][0]:
    print(sum(c2[1][1:]))
  else:
    print(sum(c2[:][1])-c2[1][1])
elif len(set(v2))==1:
  if c1[0][0] != c2[0][0]:
    print(sum(c1[1][1:]))
  else:
    print(sum(c1[:][1])-c1[1][1])
else:
  if c1[0][0] != c2[0][0]:
    print(sum(c1[1:][1]) + sum(c2[1:][1]))
  else:
    print(min(sum(c1[1:][1])+(sum(c2[:][1])-c2[1][1]), (sum(c1[:][1])-c1[1][1])+sum(c2[1:][1])))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
v1 = [v[i*2+1] for i in range(n//2)]
v2 = [v[i*2] for i in range(n//2)]
c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
print(sum(sorted(c1.values())[1:]) + sum(sorted(c2.values())[1:]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
v = list(map(int, input().split()))
v1, v2 = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2]
c1, c2 = Counter(v1).most_common(), Counter(v2).most_common()
l1, l2 = len(c1), len(c2)
if l1 == l2 == 1:
    if c1[0][0] == c2[0][0]:
        print(n // 2)
    else:
        print(0)
elif l1 == 1:
    if c1[0][0] == c2[0][0]:
        print(n//2 - c2[1][1])
    else:
        print(n//2 - c2[0][1])
elif l2 == 1:
    if c1[0][0] == c2[0][0]:
        print(n//2 - c1[1][1])
    else:
        print(n//2 - c1[0][1])
else:
    if c1[0][0] == c2[0][0]:
        if c1[0][1] + c2[1][1] < c1[1][1] + c2[0][1]:
            print(n - c1[1][1] + c2[0][1])
        else:
            print(n - c1[0][1] + c2[1][1])
    else:
        print(n - c1[0][1] + c2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
v = list(map(int, input().split()))
v1, v2 = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2]
c1, c2 = Counter(v1).most_common(), Counter(v2).most_common()
l1, l2 = len(c1), len(c2)
if l1 == l2 == 1:
    if c1[0][0] == c2[0][0]:
        print(n // 2)
    else:
        print(0)
elif l1 == 1:
    if c1[0][0] == c2[0][0]:
        print(n//2 - c2[1][1])
    else:
        print(n//2 - c2[0][1])
else:
    if c1[0][0] == c2[0][0]:
        if c1[0][1] + c2[1][1] < c1[1][1] + c2[0][1]:
            print(n - c1[1][1] + c2[0][1])
        else:
            print(n - c1[0][1] + c2[1][1])
    else:
        print(n - c1[0][1] + c2[0][1])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N = 0
V = []


def set_inputs():
    global N, V
    N = get_int()
    V = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    x = V[0::2]
    y = V[1::2]
    x_counter = Counter(x)
    y_counter = Counter(y)
    x_val = x_counter.most_common(1)[0][1]
    y_val = y_counter.most_common(1)[0][1]
    ans = N - x_val - y_val
    if x_val == y_val:
        if len(x_counter) == 1:
            if len(y_counter) == 1:
                ans = N // 2
            else:
                y_val = y_counter.most_common(2)[1][1]
                ans = N - x_val - y_val
        else:
            x_val = x_counter.most_common(2)[1][1]
            ans = N - x_val - y_val
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
input()
v = list(map(int,input().split(' ')))

n = len(v)

ev = v[::2]
ov = v[1::2]

es = set(ev)
os = set(ov)

el = sorted([[s,ev.count(s)] for s in es],reverse=True,key = lambda x:x[1])
ol = sorted([[s,ov.count(s)] for s in os],reverse=True,key = lambda x:x[1])

el.append([0,0])
ol.append([0,0])
emax = el[0][1]
omax = ol[0][1]
print(el,ol)

dif = 0
if el[0][0] == ol[0][0]:
	edif = el[0][1] - el[1][1]
	odif = ol[0][1] - ol[1][1]
	dif = min(edif,odif)

print(n-emax-omax+dif)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(len(v) // 2)
    sys.exit()

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

# 以下ifがない場合，n = 6 v = [1,1,1,1,1,2,2,1,1,1]でWA
# v[0],v[2],...,v[2//n]で最も多く出現する数字が
# v[1],v[3],...,v[2//n-1]で最も多く出現する数字と等しい場合
if even.most_common()[0][0] == odd.most_common()[0][0]:
    min(len(v) - odd.most_common()[0][1] - even.most_common()[1][1], len(v) - odd.most_common()[1][1] - even.most_common()[0][1])
    sys.exit()

print(len(v) - even.most_common()[0][1] - odd.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(len(v) // 2)
    sys.exit()

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

# 以下ifがない場合，n = 6 v = [1,1,1,1,1,2,2,1,1,1]でWA
# v[0],v[2],...,v[2//n]で最も多く出現する数字が
# v[1],v[3],...,v[2//n-1]で最も多く出現する数字と等しい場合
if even.most_common()[0][0] == odd.most_common()[0][0]:
    if even.most_common()[0][1] < odd.most_common()[0][1]:
        print(len(v) - odd.most_common()[0][1] - even.most_common()[1][1])
    else:
        print(len(v) - odd.most_common()[1][1] - even.most_common()[0][1])
    sys.exit()

print(len(v) - even.most_common()[0][1] - odd.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(len(v) // 2)
    sys.exit()

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

Submission status: Wrong Answer

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

import collections


'''
奇数番目の数列
'''
v_odd = []
for i in range(0,n,2):
  v_odd.append(v[i])

c_odd = collections.Counter(v_odd)
c_common_odd = c_odd.most_common()


'''
偶数番目の数列
'''
v_even = []
for i in range(1,n,2):
  v_even.append(v[i])

c_even = collections.Counter(v_even)
c_common_even = c_even.most_common()


'''
後処理

下記の4種類でパターン別に出力
また、各パターンごとに一番カウント数が大きい数字を比較する。

a.奇数・偶数共に数字が２種類以上
b.奇数については数字が一種類
c.偶数については数字が一種類
d.両方の数字がそれぞれ一種類
'''

# a.奇数・偶数共に数字が２種類以上
if len(c_common_odd) >= 2 and len(c_common_even) >= 2:
  # 一番多くカウントした数字が異なる
  if c_common_odd[0][0] != c_common_even[0][0]:
    ans = n - c_common_odd[0][1] - c_common_even[0][1]
  # 一致する
  else:
    # 奇数の方がカウント数が大きい
    if c_common_odd[0][1] >= c_common_even[0][1]:
      ans = n - c_common_odd[0][1] - c_common_even[1][1]
    # 偶数の方がカウント数が大きい
    else:
      ans = n - c_common_odd[1][1] - c_common_even[0][1]

# b.奇数については数字が一種類
elif len(c_common_odd) < 2 and len(c_common_even) >= 2:
  # 一番カウント数が大きい数字が一致している
  if c_common_odd[0][0] == c_common_even[0][0]:
    ans = int(n / 2) - c_common_even[1][1]
  else:
    ans = int(n / 2) - c_common_even[0][1]

# c.偶数については数字が一種類
elif len(c_common_odd) >= 2 and len(c_common_even) < 2:
  # 一番カウント数が大きい数字が一致している
  if c_common_odd[0][0] == c_common_even[0][0]:
    ans = int(n / 2) - c_common_odd[1][1]
  else:
    ans = int(n / 2) - c_common_odd[0][1]

# d.両方の数字がそれぞれ一種類
else:
  if c_common_odd[0][0] == c_common_even[0][0]:
    ans = int(n / 2)
  else:
    ans = 0

print(ans)

Submission status: Wrong Answer

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

import collections


'''
奇数番目の数列
'''
v_odd = []
for i in range(0,n,2):
  v_odd.append(v[i])

c_odd = collections.Counter(v_odd)
c_common_odd = c_odd.most_common()


'''
偶数番目の数列
'''
v_even = []
for i in range(1,n,2):
  v_even.append(v[i])

c_even = collections.Counter(v_even)
c_common_even = c_even.most_common()


'''
後処理

1.一番多くカウントした数字が同じ数字
2番目に多くカウントした数字について比較し、数字が小さい方を採用する

2.一番多くカウントした数字が異なる数字
単純に計算

ただし、奇数・偶数の数列に出てくる数字の種類が2種類以上か否か、を考慮する必要がある
'''
# 

if len(c_common_odd) >= 2 and len(c_common_even) >= 2:
  if c_common_odd[0][0] != c_common_even[0][0]:
    ans = n - c_common_odd[0][1] - c_common_even[0][1]
  else:
    if c_common_odd[0][1] >= c_common_even[0][1]:
      ans = n - c_common_odd[0][1] - c_common_even[1][1]
    else:
      ans = n - c_common_odd[1][1] - c_common_even[0][1]
# 奇数については数字が一種類
elif len(c_common_odd) < 2 and len(c_common_even) >= 2:
  if c_common_odd[0][0] == c_common_even[0][0]:
    ans = int(n / 2) - c_common_even[1][1]
  else:
    ans = int(n / 2) - c_common_even[0][1]
# 偶数については数字が一種類
elif len(c_common_odd) >= 2 and len(c_common_even) < 2:
  if c_common_odd[0][0] == c_common_even[0][0]:
    ans = int(n / 2) - c_common_odd[1][1]
  else:
    ans = int(n / 2) - c_common_odd[0][1]
# 両方の数字がそれぞれ一種類
else:
  if c_common_odd[0][0] == c_common_even[0][0]:
    ans = int(n / 2)
  else:
    ans = 0

print(ans)