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: Runtime Error

Solution code:
import collections

N = int(input())
a = list(map(int,input()))

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

b_ =collections.Counter(b)
c_ =collections.Counter(c)

baa = b_.most_common(b_)
caa = c_.most_common(c_)

baa.append([0,0])
caa.append([0,0])

if baa[0][0] != caa[0][0]:
    print(N - baa[0][1] - caa[0][1])
else:
    print(max(N - baa[0][1] - caa[1][1],N - caa[0][1] - baa[1][1]))

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
a = []
b = []
for i in range(int(N/2 + 0.1)):
    a.append(input().split())
    b.append(input().split())

ac = collections.Counter(a)
bc = collections.Counter(b)

a_1 = ac.most_common()[0]
b_1 = ac.most_common()[0]

a1_ans = N/2 - a_1[1]
b1_ans = N/2 - b_1[1]
if len(ac.most_common()) == 1:
    a2_ans = N/2
else:
    a2_ans = N/2 - ac.most_common()[1][1]
if len(bc.most_common()) == 1:
    b2_ans = N/2
else:
    b2_ans = N/2 - bc.most_common()[1][1]

if a_1[0] != b_1[0]:
    print(int(a1_ans + b1_ans))
else:
    print(int(max(a1_ans+b2_ans,b1_ans+a2_ans)))

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
a = []
b = []
for i in range(int(N/2)):
    a.append(input().split())
    b.append(input().split())

ac = collections.Counter(a)
bc = collections.Counter(b)

a_1 = ac.most_common()[0]
b_1 = ac.most_common()[0]

a1_ans = N/2 - a_1[1]
b1_ans = N/2 - b_1[1]
if len(ac.most_common()) == 1:
    a2_ans = N/2
else:
    a2_ans = N/2 - ac.most_common()[1][1]
if len(bc.most_common()) == 1:
    b2_ans = N/2
else:
    b2_ans = N/2 - bc.most_common()[1][1]

if a_1[0] != b_1[0]:
    print(int(a1_ans + b1_ans))
else:
    print(int(max(a1_ans+b2_ans,b1_ans+a2_ans)))

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
a = []
b = []
for i in range(int(N/2)):
    a.append(input())
    b.append(input())

ac = collections.Counter(a)
bc = collections.Counter(b)

a_1 = ac.most_common()[0]
b_1 = ac.most_common()[0]

a1_ans = N/2 - a_1[1]
b1_ans = N/2 - b_1[1]
if len(ac.most_common()) == 1:
    a2_ans = N/2
else:
    a2_ans = N/2 - ac.most_common()[1][1]
if len(bc.most_common()) == 1:
    b2_ans = N/2
else:
    b2_ans = N/2 - bc.most_common()[1][1]

if a_1[0] != b_1[0]:
    print(int(a1_ans + b1_ans))
else:
    print(int(max(a1_ans+b2_ans,b1_ans+a2_ans)))

Submission status: Runtime Error

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

nn = n // 2
for i in range(nn):
    a[v[i * 2]] += 1
    b[v[i * 2 + 1]] += 1

ma1 = max(a, key=a.get)
mb1 = max(b, key=b.get)
mva1 = a[ma1]
mvb1 = b[mb1]
a[ma1] = 0
b[mb1] = 0
ma2 = max(a, key=a.get)
mb2 = max(b, key=b.get)
mva2 = a[ma2]
mvb2 = b[mb2]
a[ma2] = 0
b[mb2] = 0

ma = [(ma1, mva1), (ma2, mva2)]
mb = [(mb1, mvb1), (mb2, mvb2)]
mx = 0xFFFFFFFF
for i in ma:
    for j in mb:
        if i[0] == j[0]:
            pass
        else:
            mx = min(sum(a.values()) + i[1] + sum(b.values()) + j[1], mx)
if mx == 0xFFFFFFFF:
    print(0)
else:
    print(mx

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

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

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

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

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

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

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

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

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

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

Submission status: Runtime Error

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

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

lsacnt = sorted(acnt.items(), key=lambda x: x[1],reverse=True)
lsbcnt = sorted(bcnt.items(), key=lambda j: j[1],reverse=True)

def val(abcnt, ablscnt):
	if len(list(abcnt)) < 2:
		return 0
	else:
		return ablscnt[1][1]

if lsacnt[0][0] != lsbcnt[0][0]:
	ans = n - lsacnt[0][1] - lsbcnt[0][1]
elif lsacnt[0][0] == lsbcnt[0][0]:
	if lsacnt[0][1] > lsbcnt[0][1]:
		ans = n - lsacnt[0][1] - val(bcnt,lsbcnt)
	elif lsacnt[0][1] < lsbcnt[0][1]:
		ans = n - val(acnt,lsacnt) - lsbcnt[0][1]
	elif lsacnt[0][1] == lsbcnt[0][1]:
		ans = n - lsacnt[0][1] - max(lsacnt[1][1],lsbcnt[1][1])

print(ans)

Submission status: Runtime Error

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

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

lsacnt = sorted(acnt.items(), key=lambda x: x[1])
lsbcnt = sorted(bcnt.items(), key=lambda y: y[1])

def val(abcnt, ablscnt):
	if len(list(abcnt)) < 2:
		return ablscnt[1][1]
	else:
		return 0

if lsacnt[0][0] != lsbcnt[0][0]:
	ans = n - lsacnt[0][1] - lsbcnt[0][1]
elif lsacnt[0][0] == lsbcnt[0][0]:
	if lsacnt[0][1] >= lsbcnt[0][1]:
		ans = n - lsacnt[0][0] - val(bcnt,lsbcnt)
	else:
		ans = n - val(acnt,lsbcnt) - lsbcnt[0][0]

print(ans)

Submission status: Runtime Error

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

a = [arr[i] for i in range(0,n,2)]
b = [arr[y] for y in range(1,n,2)]

import collections
acnt = collections.Counter(a)
bcnt = collections.Counter(b)

amaxval = acnt[list(acnt)[0]]
bmaxval = bcnt[list(bcnt)[0]]

amaxkey = list(acnt)[0]
bmaxkey = list(bcnt)[0]

def val(ab, abcnt):
	if len(ab) < 2:
		return 0
	else:
		return abcnt[list(abcnt)[0]]

if amaxkey != bmaxkey:
	ans = n - amaxval - bmaxval
else:
	if amaxval >= bmaxval:
		ans = n - amaxval - val(b,bcnt)
	else:
		ans = n - val(a,acnt) - bmaxval

print(ans)

Submission status: Runtime Error

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

import collections
odd = collections.defaultdict(lambda : 0)
even = collections.defaultdict(lambda: 0)

for index, i in enumerate(li):
    if index % 2 == 0:
        even[i] += 1
    elif index % 2 != 0:
        odd[i] += 1

# odd = list(filter(lambda x: x % 2 != 0, li))
sorted_odd = [(k, odd[k]) for k in sorted(odd, key=odd.get, reverse=True)]
max_odd = sorted_odd[0]
# even = list(filter(lambda x: x % 2 == 0, li))
sorted_even = [(k, even[k]) for k in sorted(even, key=even.get, reverse=True)]
max_even = sorted_even[0]

if max_odd[0] == max_even[0] and len(sorted_odd) == 1 and len(sorted_even) == 1:
    print(int(n / 2))
elif max_odd[0] == max_even[0]:
    if len(sorted_odd) >= 2:
        print(int(n/2 - sorted_odd[1] + n/2 - max_even[1]))
    elif len(sorted_even) >= 2:
        print(int(n/2 - sorted_even[1] + n/2 - max_odd[1]))
else:
    print(int(n/2 - max_odd[1] + n/2 - max_even[1]))

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
even1 = v[0::2]
odd1 = v[1::2]
even2 = Counter(v1)
odd2 = Counter(v2)
a = even2.most_common()[0][0]
b = odd2.most_common()[0][0]
c = even2.most_common()[0][1]
d = odd2.most_common()[0][1]
if a != b:
 print(len(even1)-c+len(odd1)-d)
else:
 if len(list(set(even1))) == 1 and len(list(set(odd1))) == 1:
  print(len(even1))

 else:
  if c <= d:
   print(len(even1)*2-d-even2.most_common()[1][1])
  else:
   print(len(even1)*2-c-odd2.most_common()[1][1])

Submission status: Runtime Error

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

v_odd = []
v_even = []

for i in n:
  if i % 2 == 1:
  	v_odd.append(i)
  
for i in n:
  if i % 2 == 0:
  	v_even.append(i)
  
a = v_odd.most_common()[0][1]

b = v_even.most_common()[0][1]

print(n - a - b)

Submission status: Runtime Error

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

v_odd = []
v_even = []

for i in n:
  v_odd = v[n if n % 2 == 1]
  
for i in n:
  v_even = v[n if n % 2 == 0]
  
a = v_odd.most_common()[0][1]

b = v_even.most_common()[0][1]

print(n - a - b)

Submission status: Runtime Error

Solution code:
import numpy as np

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

if n == 2:
    if v[0] == v[1]:
        print(1)
    else:
        print(0)
else:
    m = int(n / 2)
    p = max(v)

    evens = np.array([0] * p)
    odds = np.array([0] * p)

    for i in range(0, m):
        evens[v[2 * i] - 1] += 1
        odds[v[2 * i + 1] - 1] += 1
    
    mode_e2, mode_e1 = evens.argsort()[-2:]
    mode_o2, mode_o1 = odds.argsort()[-2:]

    if mode_e1 == mode_o1:
        if evens[mode_e1] > odds[mode_o1]:
            print(n - evens[mode_e1] - odds[mode_o2])
        else:
            print(n - evens[mode_e2] - odds[mode_o1])
    else:
        print(n - evens[mode_e1] - odds[mode_o1])

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[::2]).most_common() #(数字,何回出現)が出現回数が大きい方から
b=Counter(v[1::2]).most_common()
if len(a)==1:
    a.append([0,0])
if len(b)==1:
    b.append([0,0])
if a[0][0]==b[0][0]:
    print(min(n-a[1,1]-b[0,1],n-a[0,1]-b[1,1]))
else:
    print(n-a[0,1]-b[0,1])

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[::2]).most_common() #(数字,何回出現)が出現回数が大きい方から
b=Counter(v[1::2]).most_common()
if len(a)==1:
    a.append([0,0])
if len(b)==1:
    b.append([0,0])
if a[0,0]==b[0,0]:
    print(min(n-a[1,1]-b[0,1],n-a[0,1]-b[1,1]))
else:
    print(n-a[0,1]-b[0,1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8

n = int(input().strip())
vs = [int(s) for s in input().strip().split()]

as_i = [vs[i*2] for i in range(n//2)]
as_i2 = [vs[i*2+1] for i in range(n//2)]

count_i = [0] * 10001
for a in as_i:
    count_i[a] += 1

as_i2 = [vs[i*2+1] for i in range(n//2)]
count_i2 = [0] * 10001
for a in as_i2:
    count_i2[a] += 1


max_val_i = 0
max_count_i = 0
next_max_val_i = 0
next_max_count_i = 0
for i in range(1, 10001):
    if count_i[i] > max_count_i:
        next_max_count_i, next_max_val_i = max_count_i, max_val_i
        max_count_i, max_val_i = count_i[i], i

max_val_i2 = 0
max_count_i2 = 0
next_max_val_i2 = 0
next_max_count_i2 = 0
for i in range(1, 10001):
    if count_i2[i] > max_count_i2:
        next_max_count_i2, next_max_val_i2 = max_count_i2, next_max_val_i2
        max_count_i2, max_val_i2 = count_i2[i], i

# print(max_val_i, max_count_i)
# print(max_val_i2, max_count_i2)

keep_num = 0
if max_val_i != max_val_i2:
    keep_count = max_count_i + max_count_i2
else:
    if max_count_i > max_count_i2:
        keep_count = max_count_i + next_max_count_i2
    else:
        keep_count = next_max_count_i + max_count_i2

print(n - keep_count)

Submission status: Runtime Error

Solution code:
_ = input()
seq = list(map(int,input().split()))
 
seq1 = seq[::2]
seq2 = seq[1::2]
 
if len(set(seq)) == 1:
    print(len(seq2))
    exit()
    
def count_dictonary(seq):
    ret_dict={}
    for item in seq:
        if item not in ret_dict:
            ret_dict[item] = 1
        else:
            ret_dict[item]+=1
    return ret_dict
 
def modes(counting_dict):
    #(11,2),(2,1),(3,3)
    ret={}
    for item in counting_dict.items():
        no, count = item
        if counting_dict[no] in ret:
            ret[count].append(no)
        else:
            ret[count]=[no]
            
    return ret
 
 
counting1 = count_dictonary(seq1)
counting2 = count_dictonary(seq2)
 
modes1 = sorted(modes(counting1).items(),reverse=True)
modes2 = sorted(modes(counting2).items(),reverse=True)
 
min_change=len(seq)
if modes1[0][1] != modes2[0][1]:
    min_change = (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[0][0])
else:
    m01=len(seq)
    m10=len(seq)
    #if len(modes2) !=1:
    m01 =  (len(seq1) - modes1[0][0]) + (len(seq2) - modes2[1][0])
    #if len(modes1) !=1:
    m10 =  (len(seq1) - modes1[1][0]) + (len(seq2) - modes2[0][0])
    min_change = min(m01,m10)
    
print(min_change)

Submission status: Runtime Error

Solution code:
_ = input()
seq = list(map(int,input().split()))
 
seq1 = seq[::2]
seq2 = seq[1::2]
 
if len(set(seq)) == 1:
    print(min(len(seq1),len(seq2)))
    exit()
    
def count_dictonary(seq):
    ret_dict={}
    for item in seq:
        if item not in ret_dict:
            ret_dict[item] = 1
        else:
            ret_dict[item]+=1
    return ret_dict
 '''
seq_dict1 = count_dictonary(seq1)
seq_dict2 = count_dictonary(seq2)
 
min_change=len(seq)
for i1 in seq_dict1:
    for i2 in seq_dict2:
        ch1 = len(seq1) - seq_dict1[i1]
        ch2 = len(seq2) - seq_dict2[i2]
        #print(i1,i2,ch1,ch2,ch1+ch2)
        change_ = ch1+ch2
        if(min_change > ch1+ch2):
            min_change = ch1+ch2
            
print(min_change)
'''

Submission status: Runtime Error

Solution code:
# coding:utf-8
import collections


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

    va = []
    vb = []
    for i in range(0, n, 2):
        va.append(v[i])
        vb.append(v[i + 1])

    c1mc = collections.Counter(va).most_common()
    c2mc = collections.Counter(vb).most_common()

    if c1mc[0][0] != c2mc[0][0]:
        print(n - c1mc[0][1] - c2mc[0][1])
        return

    else:
        a = n - c1mc[1][1] - c2mc[0][1]
        b = n - c1mc[0][1] - c2mc[1][1]

        if a < b:
            print(a)
        else:
            print(b)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
V_odd = V[::2]
V_eve = V[1::2]
odd_max = Counter(V_odd).most_common(1)
even_max = Counter(V_eve).most_common(1)

result = n - odd_max[0][1] - even_max[0][1]
if odd_max[0][0] == even_max[0][0]:
    odd_least,even_least = 0,0
    if Counter(V_odd).most_common(1) != Counter(V_odd).most_common(2):
        odd_least = (Counter(V_odd).most_common(2))[0][1]
    if Counter(V_eve).most_common(1) != Counter(V_eve).most_common(2):
        even_least = (Counter(V_eve).most_common(2))[0][1]
    if Counter(V_odd).most_common(1) == Counter(V_odd).most_common(2) and Counter(V_eve).most_common(1) == Counter(V_eve).most_common(2):
        result = int(n/2)
    else:
        result = min(n - odd_least - even_max,n - even_least - odd_max)


print(result)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
V_odd = V[::2]
v_eve = V[1::2]
odd_max = Counter(V_odd).most_common(1)
even_max = Counter(v_eve).most_common(1)

result = n - odd_max[0][1] - even_max[0][1]
if odd_max[0][0] == even_max[0][0]:
    odd_least,even_least = 0,0
    if Counter(V_odd).most_common(1) != Counter(V_odd).most_common(2):
        odd_least = (Counter(V_odd).most_common(2))[0][1]
    if Counter(v_eve).most_common(1) != Counter(v_eve).most_common(2):
        even_least = (Counter(V_eve).most_common(2))[0][1]
    if Counter(V_odd).most_common(1) == Counter(V_odd).most_common(2) and Counter(v_eve).most_common(1) == Counter(v_eve).most_common(2):
        result = int(n/2)
    else:
        result = min(n - odd_least - even_max,n - even_least - odd_max)


print(result)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

import numpy as np

n = int(input())

v = np.array([int(c) for c in input().split()])

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

v1_n, v1_cnt = np.unique(v1, return_counts=True)
v2_n, v2_cnt = np.unique(v2, return_counts=True)
v1_cnt = np.append(v1_cnt, 0)
v2_cnt = np.append(v2_cnt, 0)

if v1_n[0] != v2_n[0]:
    print(n - v1_cnt[0] - v2_cnt[0])
else:
    n1 = n - v1_cnt[0] - v2_cnt[1]
    n2 = n - v1_cnt[1] - v2_cnt[0]
    print(min(n1, n2))

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
print(a[0][0])
print(b[0][0])
if a[0][0] != b[0][0]:
    print(int(n-a[0][1]-b[0][1])
else:
    print(int(n/2))

Submission status: Runtime Error

Solution code:
n = int(input())

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

def p(v):
    if len(set(v)) == 1:
        return len(v)/2
    v_eve = v[::2]
    v_odd = v[1::2]
    if len(set(v_eve)) == 1 and len(set(v_odd)) == 1:
        return 0
    d_eve = {}
    d_odd = {}
    for num in v_eve:
        if d_eve.get(num):
            d_eve[num] += 1
        else:
            d_eve[num] = 1
    for num in v_odd:
        if d_odd.get(num):
            d_odd[num] += 1
        else:
            d_odd[num] = 1

    r_eve = sorted(list(d_eve.values()))
    r_odd = sorted(list(d_odd.values()))
    return int(len(v_eve)*2 - r_eve[-1] - r_odd(-1))

print(p(v))

Submission status: Runtime Error

Solution code:
n = int(input())

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

s = []
t = []


import collections

for i in range(0,n//2,2):
	s.append(v[i])
for i in range(1,n//2,2):
	t.append(v[i])

S = Counter(s)
	
T = Counter(t)

x = S.most_common()[0][0]  #sの最頻値

y = S.most_common()[1][0]  #sの2番目に多いやつ

z = T.most_common()[0][0]　

w = T.most_common()[1][0]

if x!=z:
	print(n-S.most_common()[0][1]-T.most_common()[0][1])
elif y>w:
	print(n-S.most_common()[0][1]-S.most_common()[1][1])
else:
	print(n-S.most_common()[0][1]-T.most_common()[1][1])

Submission status: Runtime Error

Solution code:
n = int(input())

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

s = []
t = []


import collections

for i in range(0,n,2):
	s.append(v[i])
for i in range(1,n,2):
	t.append(v[i])

S = Counter(s)
	
T = Counter(t)

x = S.most_common()[0][0]  #sの最頻値

y = S.most_common()[1][0]  #sの2番目に多いやつ

z = T.most_common()[0][0]　

w = T.most_common()[1][0]

if x!=z:
	print(n-S.most_common()[0][1]-T.most_common()[0][1])
elif y>w:
	print(n-S.most_common()[0][1]-S.most_common()[1][1])
else:
	print(n-S.most_common()[0][1]-T.most_common()[1][1])

Submission status: Runtime Error

Solution code:
n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)

#最頻値が同じの場合
if cnt_odd[0][1] == cnt_even[0][1]:
    #リスト内の値が１つの場合
    if len(cnt_odd) == len(cnt_even) == 1:
        ans = 1
    #リストが２つ以上の場合
    else:
        #第２最頻値の出現数が奇数の方が多い
        if cnt_odd[1][0] > cnt_even[1][0]:
            ans = n - cnt_odd[1][0] - cnt_even[0][0]
        #第二２最頻値の出現数が偶数の方が多い
        elif cnt_odd[1][0] < cnt_even[1][0]:
            ans = n - cnt_odd[0][0] - cnt_even[1][0]
#最頻値が異なる場合
else:
    ans = n - cnt_odd[0][0] - cnt_even[0][1]

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = ki.most_common()

if ki[0][0] == gu[0][0] :
    if(len(ki) == len(gu)) :
        print(n/2)
    else :
        if(ki[1][1] > gu[1][1]) :
            print(n-ki[1][1]-gu[0][1])
        else :
            print(n-ki[0][1]- gu[1][1])

else :
    print(n-ki[0][1]-gu[0][1])

Submission status: Runtime Error

Solution code:
n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)

if len(cnt_odd) == len(cnt_even) == 1:
    if cnt_even[0][1] != cnt_odd[0][1]:
        ans = 0
    elif cnt_even[0][1] == cnt_odd[0][1]:
        ans = int(n / 2)
elif cnt_even[0][1] != cnt_odd[0][1]:
    ans = n - cnt_odd[0][0] - cnt_even[0][0]

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
list = [int(i) for i in input().split()]

list_odd = list[::2]
list_even = list[1::2]

def cnt_element(x):
    dict = {}
    for i in x:
        if i not in dict:
            dict[i] = 1
        else:
            dict[i] += 1
    return [(v,k) for k,v in dict.items()]

cnt_odd = sorted(cnt_element(list_odd),reverse=True)
cnt_even = sorted(cnt_element(list_even),reverse=True)
print(cnt_odd)
print(cnt_even)

if len(cnt_odd) == len(cnt_even) == 1
    if cnt_even[0][1] != cnt_odd[0][1]:
        ans = 0
    elif cnt_even[0][1] == cnt_odd[0][1]:
        ans = int(n / 2)
elif cnt_even[0][1] != cnt_odd[0][1]:
    ans = n - cnt_odd[0][0] - cnt_even[0][0]

print(ans)

Submission status: Runtime Error

Solution code:
n = int(raw_input())
A = map(int, raw_input().split(" "))

c1 = collections.Counter(A[::2])
c2 = collections.Counter(A[1::2])

res = n
for i in c1:
    for j in c2:
        if i != j:
            res = min(res, n - c1[i] - c2[j])
print res

Submission status: Runtime Error

Solution code:
a = [[], []]
[a[i%2].append(t) for i, t in enumerate(map(int, input().split()))]
print(sum([(lambda x: len(x) -max([x.count(xi) for xi in x]))(ai) for ai in a]))

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())

arr = list(map(int, input().split(' ')))

print(arr)

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

odd_counter = Counter(odd)
even_counter = Counter(even)

print(odd_counter.most_common())
print(even_counter.most_common())

odd_mode = odd_counter.most_common()[0][0]
even_mode = even_counter.most_common()[0][0]

odd_diff = (N / 2) - odd_counter.most_common()[0][1]
even_diff = (N / 2) - even_counter.most_common()[0][1]

if odd_mode != even_mode:
	print(int(odd_diff + even_diff))

elif odd_diff == N /2:
	print(N / 2)
else:
	odd_diff2 = (N / 2) - odd_counter.most_common()[1][1]
	even_diff2 = (N / 2) - even_counter.most_common()[1][1]
	if odd_diff2 > even_diff2:
		print(int(odd_diff + even_diff2))
	else:
		print(int(odd_diff2 + even_diff))

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())

arr = list(map(int, input().split(' ')))

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

odd_counter = Counter(odd)
even_counter = Counter(even)

odd_mode = odd_counter.most_common()[0][0]
even_mode = even_counter.most_common()[0][0]

odd_diff = (N / 2) - odd_counter.most_common()[0][1]
even_diff = (N / 2) - even_counter.most_common()[0][1]

if odd_mode != even_mode:
	print(int(odd_diff + even_diff))
else:
	odd_diff2 = (N / 2) - odd_counter.most_common()[1][1]
	even_diff2 = (N / 2) - even_counter.most_common()[1][1]
	if odd_diff2 > even_diff2:
		print(int(odd_diff + even_diff2))
	else:
		print(int(odd_diff2 + even_diff))

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())

arr = [input() for i in range(0,N)]

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

odd_counter = Counter(odd)
even_counter = Counter(even)

odd_mode = odd_counter.most_common()[0][0]
even_mode = even_counter.most_common()[0][0]

odd_diff = (N / 2) - odd_counter.most_common()[0][1]
even_diff = (N / 2) - even_counter.most_common()[0][1]

if odd_mode != even_mode:
	print(odd_diff + even_diff)
else:
 	odd_diff2 = (N / 2) - odd_counter.most_common()[1][1]
	even_diff2 = (N / 2) - even_counter.most_common()[1][1]
    if odd_diff2 > even_diff2:
		print(odd_diff + even_diff2)
    else:
		print(odd_diff2 + even_diff)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import min

N = int(input())

arr = [input() for i in range(0,N)]

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

odd_counter = Counter(odd)
even_counter = Counter(even)

odd_mode = odd_counter.most_common()[0][0]
even_mode = even_counter.most_common()[0][0]

odd_diff = (N / 2) - odd_counter.most_common()[0][1]
even_diff = (N / 2) - even_counter.most_common()[0][1]

if odd_mode != even_mode:
	print(odd_diff + even_diff)
else:
 	odd_diff2 = (N / 2) - odd_counter.most_common()[1][1]
	even_diff2 = (N / 2) - even_counter.most_common()[1][1]
    if odd_diff2 > even_diff2:
		print(odd_diff + even_diff2)
    else:
		print(odd_diff2 + even_diff)

Submission status: Runtime Error

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
m = n//2

a = [v[2*i] for i in range(0,m)]
b = [v[2*i+1] for i in range(0,m)]

def mode(arr):
        r = [0] * (max(arr) + 1)
        for a in arr:
            r[a] += 1
        return r.index(max(r))

A = mode(a)
B = mode(b)

if v.remove(A) == []:
    print(m)
    exit()
if A == B:
    if a.count(A) < b.count(B):
        C = mode(a.remove(A))
        print(n - a.count(C) - b.count(B))
    else:
        if b.count(B) == m:
            print(n)
        else:
            C = mode(b.remove(B))
            print(n - a.count(A) - b.count(C))
else:
    print(n - a.count(A) - b.count(B))

Submission status: Runtime Error

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
m = n//2

a = [v[2*i] for i in range(0,m)]
b = [v[2*i+1] for i in range(0,m)]

def mode(arr):
        r = [0] * (max(arr) + 1)
        for a in arr:
            r[a] += 1
        return r.index(max(r))

A = mode(a)
B = mode(b)

if v.remove(A) == []:
    print(m)
    exit()
if A == B:
    if a.count(A) < b.count(B):
        C = mode(a.remove(A))
        print(n - a.count(C) - b.count(B))
    else:
        if b.count(B) == m:
            print(n-m)
        else:
            C = mode(b.remove(B))
            print(n - a.count(A) - b.count(C))
else:
    print(n - a.count(A) - b.count(B))

Submission status: Runtime Error

Solution code:
import collections

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

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

c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
if(c1.most_common()[0][0] != c2.most_common()[0][0]):
	print(n - c1.most_common()[0][1] - c2.most_common()[0][1])
else:
	if(c1.most_common()[0][1] == n/2):
		count1 = c2.most_common()[0][1]
	else:
		count1 = c1.most_common()[1][1] + c2.most_common()[0][1]

	if(c2.most_common()[0][1] == n/2):
		count2 = c1.most_common()[0][1]
	else:
		count2 = c1.most_common()[0][1] + c2.most_common()[1][1]

	if(count1 < cont2):
		print(n - count2)
	else:
		print(n - count1)

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
x1, x2 = [], []
y1, y2 = [], []
for i in range(n//2):
  if not a[2*i] in x1:
    x1.append(a[2*i])
    y1.append(1)
  else:
    y1[x1.index(a[2*i])] += 1

for i in range(n//2):
  if not a[2*i+1] in x2:
    x2.append(a[2*i+1])
    y2.append(1)
  else:
    y2[x2.index(a[2*i+1])] += 1

if len(x1)==1 and len(x2)==1 and x1[0]!=x2[0]:
  print(0)
  sys.exit()

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

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
x1, x2 = [], []
y1, y2 = [], []
for i in range(n//2):
  if not a[2*i] in x1:
    x1.append(a[2*i])
    y1.append(1)
  else:
    y1[x1.index(a[2*i])] += 1

for i in range(n//2):
  if not a[2*i+1] in x2:
    x2.append(a[2*i+1])
    y2.append(1)
  else:
    y2[x2.index(a[2*i+1])] += 1

if len(x1)==1 and len(x2)==1 and x1[0]!=x2[0]:
  print(0)
  sys.exit()

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

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
x1, x2 = [], []
y1, y2 = [], []
for i in range(n//2):
  if not a[2*i] in x1:
    x1.append(a[2*i])
    y1.append(1)
  else:
    y1[x1.index(a[2*i])] += 1
  
  if not a[2*i+1] in x2:
    x2.append(a[2*i+1])
    y2.append(1)
  else:
    y2[x2.index(a[2*i+1])] += 1
print(x1,y1,x2,y2)
if len(x1)==1 and len(x2)==1 and x1[0]!=x2[0]:
  print(0)
  sys.exit()

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