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

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

from collections import Counter

x = Counter(a)
y = Counter(b)
x = list(x.items())
y = list(y.items())
x.sort(reverse=1,key=lambda p: p[1])
y.sort(reverse=1,key=lambda p: p[1])

if x[0][0] != y[0][0]:
    print(n-x[0][1]-y[0][1])
else:
    if x[0][0] == y[0][0]:
        print(n-max(x[0][1]+y[1][1],y[0][1]+x[1][1]))

Submission status: Runtime Error

Solution code:
import collections

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

if len(set(v)) == 1:
  print(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cl1 = collections.Counter(v1)
  cl2 = collections.Counter(v2)
  
  cmc_1st_1 = cl1.most_common()[0][1]
  cmc_1st_2 = cl2.most_common()[0][1]
  
  if cmc_1st_1 == cmc_1st_2:
    cmc_2nd_1 = cl1.most_common()[1][1]
    cmc_2nd_2 = cl2.most_common()[1][1] 
    
    if cmc_2nd_1 > cmc_2nd_2:
      ans = len(v1) - cmc_2nd_1
      ans += len(v2) - cmc_1st_2
    else:
      ans = len(v1) - cmc_1st_1
      ans += len(v2) - cmc_2nd_2
  else:
    ans = len(v1) - cmc_1st_1
    ans += len(v2) - cmc_1st_2
  
  print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

if len(set(v)) == 1:
  print(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cl1 = collections.Counter(v1)
  cl2 = collections.Counter(v2)
  
  cmc_1st_1 = cl1.most_common()[0][1]
  cmc_1st_2 = cl2.most_common()[0][1]
  cmc_2nd_1 = cl1.most_common()[1][1]
  cmc_2nd_2 = cl2.most_common()[1][1] 
  
  if cmc_1st_1 == cmc_1st_2:
    if cmc_2nd_1 > cmc_2nd_2:
      ans = len(v1) - cmc_2nd_1
      ans += len(v2) - cmc_1st_2
    else:
      ans = len(v1) - cmc_1st_1
      ans += len(v2) - cmc_2nd_2
  else:
    ans = len(v1) - cmc_1st_1
    ans += len(v2) - cmc_1st_2
  
  print(ans)

Submission status: Runtime Error

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

li1=[]
li2=[]

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

li1=collections.Counter(li1).most_common()
li2=collections.Counter(li2).most_common()

if li1[0][0]!=li2[0][0]:
    print(n-li1[0][1]-li2[0][1])
else:
    if len(li1)==1 and len(li2)==1:
        print(n//2)
    elif len(li1)==1:
        print(n-li1[0][1]-li2[1][1])
    elif len(li2)==1:
        print(n-li1[1][1]-li2[0][1])
    else:
        print(min(n-li1[0][1]-li2[1][1]),n-li1[1][1]-li2[0][1])

Submission status: Runtime Error

Solution code:
from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])
# print(v_odd)
# print(v_even)
# print(Counter(v_odd).most_common())
# print(Counter(v_even).most_common())

if Counter(v_odd).most_common()[0][1] != Counter(v_even).most_common()[0][1]:
    number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
    number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]
else:
    if Counter(v_odd).most_common()[0][1] >= Counter(v_even).most_common()[0][1]:
        number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
        number_of_rewrites += len(v_even) - Counter(v_even).most_common()[1][1]
    else:
        number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[1][1]
        number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]


print(number_of_rewrites)

Submission status: Runtime Error

Solution code:
from collections import*
n, v = map(int, open(0).read().split())
def l(x):
    o = Counter(x).most_common()
    return [o[0][0], o[0][1], o[1][1]]
a, b = map(l, [v[::2], v[1::2]])
print(n-a[1]-b[1] if a[0]!=a[0] else n - max(a[1]+b[2], a[2]+b[1])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
list_odd = [vlist[i] for i in  range(n) if i % 2 ==0]
list_even = [vlist[i] for i in range(n) if i % 2 !=0]

def f(list1):
  ary1 = [[0,i] for i in range(10**5+2)]
  len1 = len(list1)
  for i in range(len1):
    ary1[list1[i]+1][0] += 1
  ary2 = sorted(ary1)
  return [ary2[-1],ary2[-2]]

list3 = f(list_odd)
list4 = f(list_even)


if list3[0][1] != list4[0][1]:
  print(n-list3[0][0]-list4[0][0])
else:
  x1 = n-list3[0][0]-list4[1][0]
  x2 = n-list3[1][0]-list4[0][0]
  print(min(x1,x2)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
list_odd = [vlist[i] for i in  range(n) if i % 2 ==0]
list_even = [vlist[i] for i in range(n) if i % 2 !=0]

def f(list1):
  ary1 = [0] * 10**5
  ary1 = [[0,i] for i in range(10**5+1)]
  len1 = len(list1)
  for i in range(len1):
    ary1[list1[i]+1][0] += 1
  ary2 = sorted(ary1)
  return [ary2[-1],ary2[-2]]

list3 = f(list_odd)
list4 = f(list_even)

print(n-list3[0][0]-list4[0][0])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
list_odd = [vlist[i] for i in  range(n) if i % 2 ==0]
list_even = [vlist[i] for i in range(n) if i % 2 !=0]

def f(list1):
  ary1 = [0] * 10**5
  ary1 = [[0,i] for i in range(10**5+1)]
  len1 = len(list1)
  for i in range(len1):
    ary1[list1[i]+1][0] += 1
  ary2 = sorted(ary1)
  return [ary2[-1],ary2[-2]]

list3 = f(list_odd)
list4 = f(list_even)

if list3[0][1] != list4[0][1]:
  print(n-list3[0][0]-list4[0][0])
else:
  if list3[0][0] >= list4[0][0]:
    print(n-list3[0][0]-list4[1][0])
  else:
    print(n-list3[1][0]-list4[0][0])

Submission status: Runtime Error

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

a1 = a[::2]
a2 = a[1::2]

from collections import defaultdict

d1 = defaultdict(int)
for ai in a1:
	d1[ai] += 1  

d2 = defaultdict(int)
for ai in a2:
	d[ai] += 1  

an1 = list(d1.items())
an1.sort(key = lambda x: -x[1])

an2 = list(d2.items())
an2.sort(key = lambda x: -x[1])

if an1[0][0] == an2[0][0]:
	print(n - max(an1[0][1] + an2[1][1], an1[1][1] + an2[0][1]))
else:
	print(n - an1[0][1] - an2[0][1])

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
v = list(map(int, input().split()))
gu = [0] * (10**5)
ki = [0] * (10**5)

for i in range(n):
  if i % 2:
    ki[v[i]] += 1
  else:
    gu[v[i]] += 1
import numpy as np
ki = np.array(ki)
gu = np.array(gu)

a = np.argmax(ki)
b = np.argmax(gu)

if a != b:
  print(n-ki[a]-gu[b])
else:
  if a > b:
    gu = sorted(gu)
    print(n-ki[a] - gu[-2])
  else:
    ki = sorted(ki)
    print(n-ki[-2]-gu[b])

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int main()
{

  int n;
  cin >> n;
  int v[n];

  rep(i, n) cin >> v[i];

  int seq0[100001] = {}, seq1[100001] = {};
  for (int i = 0; i < n; i += 2)
    ++seq0[v[i]];
  for (int i = 1; i < n; i += 2)
    ++seq1[v[i]];

  sort(seq0 + 1, seq0 + 100001, greater<int>());
  sort(seq1 + 1, seq1 + 100001, greater<int>());

  if (seq0[0] == seq1[0])
    cout << min(n - seq0[0] - seq1[1], n - seq0[1] - seq1[0]);
  else
    cout << n - seq0[0] - seq1[0];
}

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int main()
{

  int n;
  cin >> n;
  int v[n];

  rep(i, n) cin >> v[i];

  int seq0[100001] = {}, seq1[100001] = {};
  for (int i = 0; i < n; i += 2)
    ++seq0[v[i]];
  for (int i = 1; i < n; i += 2)
    ++seq1[v[i]];

  sort(seq0 + 1, seq0 + 100001, greater<int>());
  sort(seq1 + 1, seq1 + 100001, greater<int>());

  if (seq0[0] == seq1[0])
    cout << min(n - seq0[0][0] - seq1[0][1], n - seq[0][1] - seq1[0][0]);
  else
    cout << n - seq0[0][0] - seq1[0][0];
}

Submission status: Runtime Error

Solution code:
from collections import defaultdict


def main():

    n = int(input())

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

    odd = defaultdict(int)
    even = defaultdict(int)

    for i, num in enumerate(v):
        # print(i % 2)
        if (i % 2) == 0:
            even[num] += 1
        elif (i % 2) == 1:
            # print(i, ": ", num)
            odd[num] += 1

    x = sorted(even.items(), key=lambda x: x[1], reverse=True)
    y = sorted(odd.items, key=lambda x: x[1], reverse=True)

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

    print(ans)


main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict

n = int(input())

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

odd = defaultdict(int)
even = defaultdict(int)


for i, num in enumerate(v):
    # print(i % 2)
    if (i % 2) == 0:
        even[num] += 1
    elif (i % 2) == 1:
        # print(i, ": ", num)
        odd[num] += 1

even_list = [item for item in even.items()]
odd_list = [item for item in odd.items()]
sorted(even_list, key=lambda x: x[1], reverse=True)
sorted(odd_list, key=lambda x: x[1], reverse=True)

ans = 0
n2 = int(n / 2)

if even_list[0][0] != odd_list[0][0]:
    ans += (n2 - even_list[0][1]) + (n2 - odd_list[0][1])
elif even_list[0][0] == odd_list[0][0]:
    if even_list[0][1] >= odd_list[0][1]:
        ans += (n2 - even_list[0][1])
        ans += (n2 - odd_list[1][1])
    elif even_list[0][1] < odd_list[0][1]:
        ans += (n2 - odd_list[0][1])
        ans += (n2 - even_list[1][1])

print(ans)

Submission status: Runtime Error

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

odd = [[0, i] for i in range(10001)]
even = [[0, i] for i in range(10001)]

for i in range(0, n, 2):
  odd[v[i]][0] += 1
for i in range(1, n, 2):
  even[v[i]][0] += 1

odd.sort()
even.sort()

if odd[-1][1] != even[-1][1]:
  print(n - odd[-1][0] - even[-1][0])
else:
  print(n - max(odd[-2][0] + even[-1][0], odd[-1][0] + even[-2][0]))

Submission status: Runtime Error

Solution code:
V=list(map(int,input().split()))
V0=Counter(V[::2]).most_common()
V1=Counter(V[1::2]).most_common()
ans=0
if V0[0][0]==V1[0][0]:
  if len(V0)==1 and len(V1)==1:
    print(N//2)
    exit()
  elif len(V0)!=1 and len(V1)!=1:
    if V0[1][0]>=V1[1][0]:
      V0[0],V0[1]=V0[1],V0[0]
    else:
      V1[0],V1[1]=V1[1],V1[0]
  elif len(V0)>len(V1):
     V0[0],V0[1]=V0[1],V0[0]
  else:
    V1[0],V1[1]=V1[1],V1[0]
for i in range(1,len(V0)):
  ans+=V0[i][1]
for i in range(1,len(V1)):
  ans+=V1[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

for i in range(n//2):
  v_even.append(v[2*i])
  v_odd.append(v[2*i+1])

c_even = collections.Counter(v_even)
c_odd = collections.Counter(v_odd)

c_even = c_even.most_common()
c_odd = c_odd.most_common()

if(len(c_even) == 1):
  if(len(c_odd) == 1 and c_even[0][0] != c_odd[0][0]):
    print(0)
  elif(len(c_odd) == 1 and c_even[0][0] == c_odd[0][0]):
    print(n//2)
  else:
    print(n//2 - c_odd[0][1])

else:
  if(len(c_odd) == 1 and c_even[0][0] != c_odd[0][0]):
    print(n//2 - c_even[0][1])
  elif(len(c_odd) == 1 and c_even[0][0] == c_odd[0][0]):
    print(n//2 - c_even[1][1])
  elif(len(c_odd) != 1 and c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
  elif(len(c_odd) != 1 and c_even[0][0] == c_odd[0][0]):
    if(c_even[0][1] > c_odd[0][1]):
      print(n - c_even[0][1] - c_odd[0][2])
    else:
      print(n - c_even[0][2] - c_odd[0][1])

Submission status: Runtime Error

Solution code:
import sys

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

a1 = {}
a2 = {}
for i in range(n) :
  a = v[i]
  if i%2 == 0 :
    if a in a1 :
      a1[a] += 1
    else :
      a1[a] = 1
  else :
    if a in a2 :
      a2[a] += 1
    else :
      a2[a] = 1

a1_s = sorted(a1.items(), key = lambda x : x[1], reverse = True)
a2_s = sorted(a2.items(), key = lambda x : x[1], reverse = True)

ans = n
for i in range(2) :
  for j in range(2) :
    if a1_s[i][0] == a2_s[j][0] :
      continue
    ans = min(ans,n-a1_s[i][1]-a2_s[j][1])
    
print(ans)

Submission status: Runtime Error

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

A=v[0::2]
B=v[1::2]
a=len(A)
b=len(B)

#print(Counter(A).most_common()[0][0])
#print(Counter(B).most_common()[0][0])

if Counter(A).most_common()[0][0] !=Counter(B).most_common()[0][0]:
    s=Counter(A).most_common()[0][1]
    t=Counter(B).most_common()[0][1]
    print( (a-s)+(b-t))
else:
    o=Counter(A).most_common()[1][1]
    p=Counter(B).most_common()[0][1]
    r= (a-o)+(b-p)
    w=Counter(A).most_common()[0][1]
    x=Counter(B).most_common()[1][1]
    s= (a-w)+(b-x)
    print(min( r, s))

Submission status: Runtime Error

Solution code:
n = int(input())
base = list(map(int,input().split()))
even = [0]*(10**5)
odd = [0]*(10**5)

for i in range(1,n+1):
  sign = i%2
  num = base[i-1]
  
  if sign == 0:
    even[num] += 1
  elif sign == 1:
    odd[num] += 1

ans_e = max(even)
ans_o = max(odd)
even_i = even.index(ans_e)
odd_i = odd.index(ans_o)

if even_i == odd_i:
  even.sort()
  odd.sort()
  if even[10**5 - 2] <= odd[10**5 - 2]:
    ans_o = odd[10**5 - 2]
  else:
    ans_e = even[10**5 - 2]
  
print(n - ans_e - ans_o)

Submission status: Runtime Error

Solution code:
n = int(input())
base = list(map(int,input().split()))
even = [0]*(10**5)
odd = [0]*(10**5)

for i in range(1,n+1):
  sign = i%2
  num = base[i-1]
  
  if sign == 0:
    even[num] += 1
  elif sign == 1:
    odd[num] += 1

ans_e = max(even)
ans_o = max(odd)
even_i = even.index(ans_e)
odd_i = odd.index(ans_o)

if even_i == odd_i:
  even.sort()
  odd.sort()
  if even[10*5 - 2] <= odd[10*5 - 2]:
    ans_o = odd[10**5 - 2]
  else:
    ans_e = even[10**5 - 2]
  
print(n - ans_e - ans_o)

Submission status: Runtime Error

Solution code:
n = int(input())
base = list(map(int,input().split()))
even = [0]*100000
odd = [0]*100000

for i in range(n):
  sign = i%2
  num = base[i]
  if sign == 0:
    even[num] += 1
  elif sign == 1:
    odd[num] += 1

ans_e = max(even)
ans_o = max(odd)
even_i = even.index(ans_e)
odd_i = odd.index(ans_o)

if even_i == odd_i:
  even.sort()
  odd.sort()
  if even[10*5 - 2] <= odd[10*5 - 2]:
    ans_o = odd[10*5 - 2]
  else:
    ans_e = even[10*5 - 2]
  
print(n - ans_e - ans_o)

Submission status: Runtime Error

Solution code:
'''
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
'''
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n = int(readline())
  v = list(map(int, readline().split()))
  odd = Counter(v[::2])
  even = Counter(v[1::2])
  odd[-1] = 0
  even[-2] = 0
  ev = even.most_common(2)
  od = odd.most_common(2)
  
  answer = n
  for (k1,v1), (k2,v2) in product(ev,od):
    if k1 == k2:
      continue
    x = n-x1-x2
    if answer>x:
      answer = x
      
  print(answe)
    
  
  
  
  
  
if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
kisu = []
gusu = []
flag = True
for el in v:
    if flag:
        kisu.append(el)
    else:
        gusu.append(el)
    flag = not flag
a = Counter(kisu)
b = Counter(gusu)
a_max = list(a.values())[0]
b_max = list(b.values())[0]
if list(a.keys())[0] == list(b.keys())[0]:
    if a_max > b_max:
        if len(b) < 2:
            b_max = 0
        else:
            b_max = list(b.values())[1]
    elif a_max < b_max:
        if len(a) < 2:
            a_max = 0
        else:
            a_max = list(a.values())[1]
    else:
        if len(a) == 1 and len(b) == 1:
            a_max = 0
        elif len(a) == 1:
            b_max = list(b.values())[1]
        elif len(b) == 1:
            a_max = list(a.values())[1]
        else:
            a_max2 = list(a.values())[1]
            b_max2 = list(b.values())[1]
            if a_max2 < b_max2:
                b_max = b_max2
            else:
                a_max = a_max2
print(len(v)-a_max-b_max)

Submission status: Runtime Error

Solution code:
v = list(map(int, input().split()))
kisu = []
gusu = []
flag = True
for el in v:
    if flag:
        kisu.append(el)
    else:
        gusu.append(el)
    flag = not flag
a = Counter(kisu)
b = Counter(gusu)
a_max = list(a.values())[0]
b_max = list(b.values())[0]
if list(a.keys())[0] == list(b.keys())[0]:
    if a_max > b_max:
        if len(a) < 2:
            a_max = 0
        else:
            a_max = list(a.values())[1]
    elif a_max < b_max:
        if len(b) < 2:
            b_max = 0
        else:
            b_max = list(b.values())[1]
    else:
        if len(a) == 0 and len(b) == 0:
            a_max = 0
        elif len(a) == 0:
            b_max = list(b.values())[1]
        elif len(b) == 0:
            a_max = list(a.values())[1]
        else:
            a_max2 = list(a.values())[1]
            b_max2 = list(b.values())[1]
            if a_max2 < b_max2:
                b_max = b_max2
            else:
                a_max = a_max2
print(len(v)-a_max-b_max)

Submission status: Runtime Error

Solution code:
import collections

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

even_num=[v[i] for i in range(0,n,2)]
odd_num=[v[i] for i in range(1,n,2)]

count_even=collections.Counter(even_num).most_common()
count_odd=collections.Counter(odd_num).most_common()

#count_even.append((0,0))
#count_odd.append((0,0))

if count_even[0][0] != count_odd[0][0]:
    print(n-count_even[0][1]-count_odd[0][1])
elif len(count_even)==1 and len(count_odd)==1:
    print(n//2)
elif len(count_even)==1:
    print(n-count_odd[1][1])
elif len(count_odd)==1:
    print(n-count_even[1][1])
else:
    odd_even=count_odd[0][1]+count_even[1][1]
    even_odd=count_even[0][1]+count_odd[1][1]
    if odd_even>even_odd:
        print(n-odd_num)
    else:
        print(n-even_odd)

Submission status: Runtime Error

Solution code:
import collections

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

even_num=[v[i] for i in range(0,n,2)]
odd_num=[v[i] for i in range(1,n,2)]

count_even=collections.Counter(even_num).most_common()
count_odd=collections.Counter(odd_num).most_common()

count_even.append((0,0))
count_odd.append((0,0))

if count_even[0][0]!=count_odd[0][0]:
    print(n-count_even[0][1]-count_odd[0][1])
else:
    odd_even=count_odd[0][1]+count_even[1][1]
    even_odd=count_even[0][1]+count_odd[1][1]
    if odd_even>even_odd:
        print(n-odd_num)
    else:
        print(n-even_odd)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)

max_odd = 0
max_even = 0
f_odd = 0
f_even = 0
s_odd = 0
s_even = 0

for i, v in enumerate(V):
    i += 1
    if i % 2 == 0:
        even[v] += 1
        if even[v] > max_even:
            max_even = even[v]
            if f_even != 0 and v != f_even:
                s_even = f_even
                f_even = v
            elif f_even == 0:
                f_even = v

    elif i % 2 == 1:
        odd[v] += 1
        if odd[v] > max_odd:
            max_odd = odd[v]
            if f_odd != 0 and v != f_odd:
                s_odd = f_odd
                f_odd = v
            elif f_odd == 0:
                f_odd = v

half = n / 2
cnt = 0


if f_odd != f_even:
    c1 = (half - max_odd) + (half - max_even)
    c2 = (half - max_even) + (half - max_odd)
    if c1 > c2:
        cnt = c2
    else:
        cnt = c1
    num1 = f_odd
    num2 = f_even
elif f_odd == f_even:
    c1 = (half - max_odd) + (half - even[s_even])
    c2 = (half - max_even) + (half - odd[s_odd])
    if c1 > c2:
        cnt = c2
        num1 = s_odd
        num2 = f_even
    else:
        cnt = c1
        num1 = f_odd
        num2 = s_even

last_odd = V[-2]
last_even = V[-1]
if last_odd != num1 and last_odd == num2:
    cnt -= 1
if last_even != num2 and last_even == num1:
    cnt -= 1

print(int(cnt))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2 != 0]

counter_even = collections.Counter(v_even)
counter_odd = collections.Counter(v_odd)

count_even = sorted(counter_even.items(), key=lambda x:x[1], reverse=True)
print(count_even)
count_odd = sorted(counter_odd.items(), key=lambda x:x[1], reverse=True)
print(count_odd)

if len(counter_even) == 1 and len(counter_odd) == 1:
    if count_even[0][0] != count_odd[0][0]:
        ans = 0
    else:
        ans1 = 0
        for i in range(n // 2):
            if v_even[i] != count_even[1][0]:
                v_even[i] = count_even[1][0]
                ans1 += 1
            
            if v_odd[i] != count_odd[0][0]:
                v_odd[i] = count_odd[0][0]
                ans1 += 1
    
        ans2 = 0
        for i in range(n // 2):
            if v_even[i] != count_even[0][0]:
                v_even[i] = count_even[0][0]
                ans2 += 1
            
            if v_odd[i] != count_odd[1][0]:
                v_odd[i] = count_odd[1][0]
                ans2 += 1
                
        ans = min(ans1, ans2)

else:
    ans = 0 
    for i in range(n // 2):
        if v_even[i] != count_even[0][0]:
            v_even[i] = count_even[0][0]
            ans += 1
        
        if v_odd[i] != count_odd[0][0]:
            v_odd[i] = count_odd[0][0]
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
from copy import deepcopy
n = int(input())
v = list(map(int,input().split()))

odd = []
even = []

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

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

box_e = [0]*int(1e5+1)
box_o = [0]*int(1e5+1)
e = {}
o = {}
for i in range(n//2):
    if even[i] in e:
        e[even[i]] += 1
    else:
        e[even[i]] = 1
    if odd[i] in o:
        o[odd[i]] += 1
    else:
        o[odd[i]] = 1
values_e = list(e.values())
keys_e = list(e.keys())
values_o = list(o.values())
keys_o = list(o.keys())
Oddlist = []
Evenlist = []
for i in range(len(keys_e)):
    Evenlist.append([values_e[i],keys_e[i]])
for j in range(len(keys_o)):
    Oddlist.append([values_o[i],keys_o[i]])
Evenlist.sort()
Oddlist.sort()
mode_even = Evenlist[-1]
mode_even_2 = 0
if len(keys_e) >= 2:
    mode_even_2 = Evenlist[-2]
mode_odd = Oddlist[-1]
mode_odd_2 = 0
if len(keys_o) >= 2:
    mode_even_2 = Oddlist[-2]

ans = 0

if mode_even[1] != mode_odd[1]:
    ##print("hoge")
    for i in range(n//2):
        if odd[i] != mode_odd[1]:
            ans += 1
        if even[i] != mode_even[1]:
            ans += 1
else:
    if mode_even[0] > mode_odd[0]:
        for i in range(n//2):
            if odd[i] != mode_odd[1]:
                ans += 1
            if even[i] != mode_even_2[1]:
                ans += 1
    else:
        for i in range(n//2):
            if odd[i] != mode_odd_2[1]:
                ans += 1
            if even[i] != mode_even[1]:
                ans += 1
print(ans)

Submission status: Runtime Error

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

from collections import defaultdict

#入力   
n = int(input())
v = list(int, input().split())

def f(v):
    d = defaultdict(int)
    d[0] = 0

    for i in v:
        d[i] += 1
    return sorted(d.items(), key=lambda x: x[1], reverse=True)

t1 = f(v[::2])
t2 = f(v[1::2])

if t1[0][0] == t2[0][0]:
    if t1[0][1] + t2[1][1] > t1[1][1] + t2[0][1]:
        print(n - t1[0][1] - t2[1][1])
    else:
        print(n - t1[1][1] - t2[0][1])
else:
    print(n - t1[0][1] - t2[0][1])

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()
a.append([0,0])
b.append([0,0])

if a[0][0] != b[0][0]:
  print(n-(a[0][1]+b[0][1]))
else:
  print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1]))

Submission status: Runtime Error

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

e = Counter(v[::2])
o = Counter(v[1::2])

e = sorted([(k,v) for k, v in e.items()],key = lambda z:z[1],reverse = True) + [(0,0)]
o = sorted([(k,v) for k, v in o.items()],key = lambda z:z[1],reverse = True) + [(0,0)]

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    print(n - max(e[0][1] + o[1][1], e[1][1] + o[0][1]))

Submission status: Runtime Error

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

e = Counter(v[::2])
o = Counter(v[1::2])

e = sorted([(k,v) for k, v in e.items()],key = lambda z:z[1],reverse = True) + [(0,0)]
o = sorted([(k,v) for k, v in o.items()],key = lambda z:z[1],reverse = True) + [(0,0)]

if e[0][0] != o[0][0]:
    print(n - e[0][1] - o[0][1])
else:
    print(n - max(e[0][1] + o[1][1], e[1][1] + o[0][1]))

Submission status: Runtime Error

Solution code:
from collections import Counter

def solve(n, v):
    # すべて同じ値
    if len(set(v)) == 1:
        return len(v) / 2

    odd = []
    even = []

    for i, k in enumerate(v):
        if i % 2 == 0:
            even.append(k)
        else:
            odd.append(k)

    odd_dic = Counter(odd).most_common()
    even_dic = Counter(even).most_common()

    ans = 0

    if odd_dic[0][0] == even_dic[0][0]:
        if odd_dic[0][1] > even_dic[0][1]:
            odd_v = odd_dic[0][0]
            even_v = even_dic[1][0]
        elif odd_dic[0][1] < even_dic[0][1]:
            odd_v = odd_dic[1][0]
            even_v = even_dic[0][0]
        else:
            if odd_dic[1][1] >= even_dic[1][1]:
                odd_v = odd_dic[1][0]
                even_v = even_dic[0][0]
            else
                odd_v = odd_dic[0][0]
                even_v = even_dic[1][0]
    else:
        odd_v = odd_dic[0][0]
        even_v = even_dic[0][0]

    for i in range(len(even)):
        if even_v != even[i]:
           ans += 1

        if odd_v != odd[i]:
            ans += 1

    return ans

def test():
    assert solve(4, [3, 1, 3, 2]) == 1
    assert solve(6, [105, 119, 105, 119, 105, 119]) == 0
    assert solve(4, [1, 1, 1, 1]) == 2

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

if __name__ == '__main__':
    # test()
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter

def solve(n, v):
    # すべて同じ値
    if len(set(v)) == 1:
        return len(v) / 2

    odd = []
    even = []

    for i, k in enumerate(v):
        if i % 2 == 0:
            even.append(k)
        else:
            odd.append(k)

    odd_dic = Counter(odd).most_common()
    even_dic = Counter(even).most_common()

    ans = 0
    targ = 0

    if odd_dic[0][0] == even_dic[0][0]:
        while targ >= 0:
            if odd_dic[targ][1] == even_dic[targ][1]:
                targ += 1
                continue
            elif odd_dic[targ][1] > even_dic[targ][1]:
                odd_v = odd_dic[targ][0]
                even_v = even_dic[0][0]
            else:
                odd_v = odd_dic[0][0]
                even_v = even_dic[targ][0]
    else:
        odd_v = odd_dic[0][0]
        even_v = even_dic[0][0]

    for i in range(len(even)):
        if even_v != even[i]:
           ans += 1

        if odd_v != odd[i]:
            ans += 1

    return ans

def test():
    assert solve(4, [3, 1, 3, 2]) == 1
    assert solve(6, [105, 119, 105, 119, 105, 119]) == 0
    assert solve(4, [1, 1, 1, 1]) == 2

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

if __name__ == '__main__':
    # test()
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int, input().split()))
k = [0] * 100000
g = [0] * 100000

num = 1
for i in v:
    if num % 2 == 1:
        k[i] += 1
    else:
        g[i] += 1
    num += 1

max_k = max(k)
max_g = max(g)
print(n - (max_k+max_g))

Submission status: Runtime Error

Solution code:
# coding:utf-8
n = int(input())
v = list(map(int, input().split()))
k = [0] * 100000
g = [0] * 100000

num = 1
for i in v:
    if num % 2 == 1:
        k[i] += 1
    else:
        g[i] += 1
    num += 1

max_k = max(k)
max_g = max(g)
print(n - (max_k+max_g))

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
s1,s2=[],[]
for i in range(n):
  if i%2==0:
    s1.append(v[i])
  else:
    s2.append(v[i])
c1=Counter(s1)
c2=Counter(s2)
d1=c1.most_common()
d2=c2.most_common()
if d1[0][0]!=d2[0][0]:
  print(n-d1[0][1]-d2[0][1])
else:
  print(min(n-d1[0][1]-d2[1][1],n-d1[1][1]-d2[0][1]))

Submission status: Runtime Error

Solution code:
import Counter
n=int(input())
v=list(map(int,input().split()))
s1,s2=[],[]
for i in range(n):
  if i%2==0:
    s1.append(v[i])
  else:
    s2.append(v[i])
c1=Counter(s1)
c2=Counter(s2)
d1=c1.most_common()
d2=c2.most_common()
if d1[0][0]!=d2[0][0]:
  print(n-d1[0][1]-d2[0][1])
else:
  print(min(n-d1[0][1]-d2[1][1],n-d1[1][1]-d2[0][1]))

Submission status: Runtime Error

Solution code:
import collections

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

# 偶数列と奇数列に分ける
even_num = items[::2]
odd_num = items[1::2]

# それらの配列で一番数が多いものを判定、それに合わせる
dev = Counter(even_num).most_common(2)
dod = Counter(odd_num).most_common(2)

if dev[0][0] == dod[0][0] :
    if len(dev) == len(dod) == 1 :
        print(N//2)
    elif len(dev) < len(dod) :
        print(N//2 - dod[1][1])
    elif len(dev) > len(dod) :
        print(N//2 - dev[1][1])
    else :
        print(N - max(dod[1][1] + dev[0][1], dod[0][1] + dev[1][1]))
else :
    print(N - dod[0][1]- dev[0][1])