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:
#include <iostream>
using namespace std;

int main(){
  int n;
  cin >> n;
  n = n / 2;
  int* a = new int[n];
  int* ax = new int[n];
  int* ay = new int[n];
  int ac = 0;
  int* b = new int[n];
  int* bx = new int[n];
  int* by = new int[n];
  int bc = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    int an = 0;
    for(int j = 0; j < ac; j++){
      if(a[i] == ax[j]){
        ay[j]++;
        an = 1;
        break;
      }
    }
    if(an == 0){
      ax[ac] = a[i];
      ay[ac] = 1;
      ac++;
    }
    cin >> b[i];
    int bn = 0;
    for(int j = 0; j < ac; j++){
      if(b[i] == bx[j]){
        by[j]++;
        bn = 1;
        break;
      }
    }
    if(bn == 0){
      bx[bc] = b[i];
      by[bc] = 1;
      bc++;
    }
  }
  int az = 0;
  int ai = 0;
  int az2 = 0;
  for(int i = 0; i < ac; i++){
    if(ay[i] > az){
      az2 = az;
      az = ay[i];
      ai = i;
    }else if(ay[i] > az2){
      az2 = ay[i];
    }
  }
  int bz = 0;
  int bi = 0;
  int bz2 = 0;
  for(int i = 0; i < bc; i++){
    if(by[i] > bz){
      bz2 = bz;
      bz = by[i];
      bi = i;
    }else if(by[i] > bz){
      bz2 = by[i];
    }
  }
  if(ax[ai] == bx[ai]){
    if(az2 < bz2){
      az = az2;
    }else{
      bz = bz2;
    }
  }
  az = n - az;
  bz = n - bz;
  int ans = az + bz;
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
import collections as cole


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

v1 = v[::2]   #odd
v2 = v[1::2]  #even

d1 = cole.Counter(v1)
d2 = cole.Counter(v2)

values1, counts1 = zip(*d1.most_common())
values2, counts2 = zip(*d2.most_common())

max1 = values1[0]
max2 = values2[0]

if max1 == max2:
    if len(counts1) != 1 and counts1[0] == counts1[1]:
        max1 = values[1]
    elif len(counts2) != 1 and counts2[0] == counts[1]:
        max2 = values[1]
    elif len(counts1) != 1 and len(counts2) != 1:
        if counts1[1] > counts2[1]:
            max1 = values1[1]
        else:
            max2 = values2[1]
    elif len(counts1) != 1:
        max1 = values1[1]
    elif len(counts2) != 1:
        max2 = values2[1]

print(max1, max2)
count = 0
if max1 != max2:
    count += len([x for x in v1 if x != max1])
    count += len([y for y in v2 if y != max2])

else:
    count += len(v1)


print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
N=list(map(int,input().split()))
even=[]
odd=[]
for i in range(len(N)):
    if i%2==0:
        even.append(N[i])
    if i%2==1:
        odd.append(N[i])
import collections
c = collections.Counter(even)
x=c.most_common()[0][0]
o=even.count(x)
d= collections.Counter(odd)
y=d.most_common()[0][0]
p=odd.count(y)
s=len(even)-even.count(x)
t=len(odd)-odd.count(y)
if x!=y and o==len(even) and p==len(odd):
    print(0)
elif x==y and o==len(even) and p==len(odd):
    print(n/2)
elif x==y and (o!=len(even) or p!=len(odd)):
    if o>p:
        y=d.most_common()[1][0]
        s=len(even)-even.count(x)
        t=len(odd)-odd.count(y)
        print(s+t)
    else:
        x=c.most_common()[1][0]
        s=len(even)-even.count(x)
        t=len(odd)-odd.count(y)
        print(s+t)
elif:
    print(s+t)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = input().split()
v_int = [int(i) for i in v]
v_odd = []
v_even = []
for i in range(int(n/2)):
  v_even.append(v_int[i*2])
  v_odd.append(v_int[i*2+1])
print(v_even)
print(v_odd)
c_odd = collections.Counter(v_odd)
c_even = collections.Counter(v_even)
max_odd = 0
second_odd = 0
max_key_odd = 0
for key in c_odd:
  if max_odd < c_odd[key]:
    second_odd = max_odd
    max_odd = c_odd[key]
    max_key_odd = key
  elif second_odd < c_odd[key]:
    second_odd = c_odd[key]
    
max_even = 0
second_even = 0
max_key_even = 0
for key in c_even:
  if max_even < c_even[key]:
    second_even = max_even
    max_even = c_even[key]
    max_key_even = key
  elif second_even < c_even[key]:
    second_even = c_even[key]
    
print(second_odd)
print(second_even)
if max_key_even != max_key_odd:
  print(int(n)- max_even - max_odd)
else:
  if max_even > max_odd:
    if max_even == second_even:
      print(int(n) - max_even - max_odd)
    else:
      print(int(n) - max_even - second_odd)
  else:
    if max_odd = second_odd:
      print(int(n) - max_odd - max_even)
    else:
      print(int(n) - max_odd - second_even)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = input().split()
v1 = v[::2]
v2 = v[1::2]
mc1 = Counter(v1).most_common(2)
mc2 = Counter(v2).most_common(2)
f1 = 0
f2 = 0
c = 0
for i in mc1:
    if c == 0:
        mv1 = mc1[0][1]
        c += 1
    if c == 1:
        m1v1 = mc1[1][1]
        f1 = 1
        c += 1
    if c == 2:
        break
c = 0
for i in mc2:
    if c == 0:
        mv2 = mc2[0][1]
        c += 1
    if c == 1:
        m1v2 = mc2[1][1]
        f2 = 1
        c += 1
    if c == 2:
        break
if mc1[0][0] != mc2[0][0]:
    print(n - mv1 - mv2)
elif f1 == 0 and f2 == 0:
    print(n // 2)
elif f1 > 0 and f2 == 0:
    print(n - m1v1)
elif f1 == 0 and f2 > 0:
    print(n - m1v2)
elif mv1 > mv2:
    print(n - mv1 - m1v2)
else:
    print(n - mv2 - m1v1)

Submission status: Runtime Error

Solution code:
import collections

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

v0 = [v[i] for i in range(0,n,2)]
v1 = [v[i] for i in range(1,n,2)]

v0cnt = collections.Counter(v0)
v1cnt = collections.Counter(v1)

v0most = v0cnt.most_common()[0]
v1most = v1cnt.most_common()[0]
v0next = v0cnt.most_common()[1]
v1next = v1cnt.most_common()[1]
if v0most[0] != v1most[0]:
    ans = n - v0most[1] -v1most[1]
else:
    if v0most[1] == v1most[1]:
        if v0most[1] == n//2:
            ans = n//2
        else:
            if v0next[1] > v1next[1]:
                ans = n - v1most[1] - v0next[1]
            else:
                ans = n - v0most[1] - v1next[1]            
    elif v0most[1] > v1most[1]:
        ans = n - v0most[1] - v1next[1]
    else:
        ans = n - v1most[1] - v0next[1]

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

odds_counter = defaultdict(int)
evens_counter = defaultdict(int)

for o in V[0::2]:
    odds_counter[o] += 1
for e in V[1::2]:
    evens_counter[e] += 1

odds = sorted(odds_counter.items(), key=lambda x: x[1], reverse=True)
evens = sorted(evens_counter.items(), key=lambda x: x[1], reverse=True)

if odds[0][0] != evens[0][0]:
    ans = n - odds[0][1] - evens[0][1]
else:
    if odds[0][1] >= evens[0][1]:
        if len(odds) == 1:
            ans = n//2 - evens[1][1]
        else:
            ans = n - evens[0][1] - odds[1][1]
    else:
        if len(evens) == 1:
            ans = n//2 - odds[1][1]
        else:
            ans = n - odds[0][1] - evens[1][1]
print(ans)

Submission status: Runtime Error

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

def add_entry(hist, aa):
    if aa in hist:
        hist[aa] += 1
    else:
        hist[aa] = 1


def make_hist(a):
    even_hist = {}
    odd_hist = {}

    for i in range(len(a)//2):
        add_entry(even_hist, a[2*i])
        add_entry(odd_hist, a[2*i+1])

    return even_hist, odd_hist


def get_sorted_hist(hist):
    return sorted(hist.items(), key=lambda x: -x[0])


eh, oh = make_hist(a)
seh = get_sorted_hist(eh)
soh = get_sorted_hist(oh)

if seh[0][0] != soh[0][0]
    print(len(a) - seh[0][1] - soh[0][1])
else:
    if seh[0][1] >= soh[0][1]:
        print(len(a) - seh[0][1] - soh[1][1])
    else:
        print(len(a) - seh[1][1] - soh[0][1])

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().strip().split(" ")))
odd = []
even = []
for i in range(len(v)):
    if(i % 2 == 0):
        even.append(v[i])
    else:
        odd.append(v[i])


c_even = Counter(even).most_common()
c_odd = Counter(odd).most_common()

if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
elif(len(c_even) != 1 and len(c_odd) != 1):
    second = max[c_even[1][1], c_odd[1][1]]
    print(n - c_even[0][1] - second)
else:
    print(min([c_even[0][1], c_odd[0][1]]))

Submission status: Runtime Error

Solution code:
#encoding utf-8

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


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

#odd part
count={}
for i in range(len(v_odd)):
    if v_odd[i] in count.keys():
        count[v_odd[i]] += 1
    else:
        count[v_odd[i]] = 1



for k, v in sorted(count.items(), key=lambda x: -x[1]):
    pass
keys = list(count.keys())
# num_odd = len(v_odd)-int(count[keys[0]])


#even part
even_count={}

for i in range(len(v_even)):
    if v_even[i] in even_count.keys():
        even_count[v_even[i]] += 1
    else:
        even_count[v_even[i]] = 1


for k, v in sorted(even_count.items(), key=lambda x: -x[1]):
    pass
even_keys = list(even_count.keys())
# num += len(v_even)-int(count[even_keys[0]])


if even_keys[0] == keys[0]:
    if len(keys) == 1 and len(even_keys) == 1:
        answer = int(len(v_odd))
    elif len(keys) == 1:
        answer = len(v_even)-int(v_even[even_keys[1]])
    elif len(even_keys) == 1:
        answer = len(v_odd)-int(v_odd[keys[1]])
    else:
        if int(v_even[even_keys[0]]) >= int(v_odd[keys[0]]):
            answer = len(v_odd)-int(count[keys[1]])
            answer += len(v_even)-int(even_count[even_keys[0]])
        else:
            answer = len(v_odd)-int(count[keys[0]])
            answer += len(v_even)-int(even_count[even_keys[1]])

else:
    answer = len(v_odd)-int(count[keys[0]])+len(v_even)-int(even_count[even_keys[0]])
print(int(answer))

Submission status: Runtime Error

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

if max(v)==min(v):
	print(int(n/2))
else:
	dic1 = {}
	dic2 = {}
	
	for i in range(n):
		if i % 2 == 1:
			if str(v[i]) in dic1.keys():
				dic1[str(v[i])] = dic1[str(v[i])] + 1
			else:
				dic1[str(v[i])] = 1
	
		if i % 2 == 0:
			if str(v[i]) in dic2.keys():
				dic2[str(v[i])] = dic2[str(v[i])] + 1
			else:
				dic2[str(v[i])] = 1
	
	max1 = max(dic1, key=dic1.get)
	max2 = max(dic2, key=dic2.get)
	p1 = dic1[max1]
	p2 = dic2[max2]
	if max1 == max2:
		dic1.pop(max1)
		dic2.pop(max2)
		if dic1 == {}:
			p3 = 0
		else:
			max3 = max(dic1, key=dic1.get)
			p3 = dict[max3]
		if dic2 == {}:
			p4 = 0
		else:
			max4 = max(dic2, key=dic2.get)
			p4 = dic4[max4]
		if p1 + p4 > p2 + p3:
			p2 = p4
		else:
			p1 = p3
	
	print(n-p1-p2)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

counter1 = Counter(v1)
x1 = counter1.most_common(2)
counter2 = Counter(v2)
x2 = counter2.most_common(2)

n = n//2
ans = 0
if x1[0][0] == x2[0][0]:
    if x1[0][1] > x2[0][1]:
        ans = (n - x1[0][1]) + (n - x2[1][1])
    else:
        ans =  (n - x2[0][1]) + (n - x1[1][1])
else:
    ans = (n - x1[0][1]) + (n - x2[0][1])
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import statistics
import collections
n=int(input())
all_str=list(map(int,input().split()))
i=0
o_str=[]   # 0, ,2,
e_str=[]   #  ,1, ,3,
while(2*i+1<n):
  o_str.append(all_str[2*i])
  e_str.append(all_str[2*i+1])
  i+=1
o_mode=statistics.mode(o_str)
e_mode=statistics.mode(e_str)
if(o_mode!=e_mode):
  alt=len(all_str)-o_str.count(o_mode)-e_str.count(e_mode)
else:
  alt=min(o_str.count(o_mode),e_str.count(e_mode))
print(alt)

Submission status: Runtime Error

Solution code:
m1 = []
m2 = []
for i in range(10**5+1):
    m1.append(0)
    m2.append(0)
for i in range(n):
    if i%2 == 0:
        m1[i] += 1
    elif i%2 == 1:
        m2[i] += 1
print(n-max(m1)-max(m2))

Submission status: Runtime Error

Solution code:
#coding:utf-8
import numpy as np
import collections
N = 1000000
ls = list(map(int,input().split()))
ls.append(N)
ls.append(N)
array = np.array(ls).reshape(-1,2).T
c_even = collections.Counter(array[0])
c_odd = collections.Counter(array[1])
if len(set(ls))==2:
    print (int((len(ls)-2)/2))
elif c_even.most_common()[0][0] != c_odd.most_common()[0][0]:
    print (len(ls)-c_even.most_common()[0][1]-c_odd.most_common()[0][1]-2)
else:
    print (min(len(ls)-c_even.most_common()[0][1]-c_odd.most_common()[1][1]-2,len(ls)-c_even.most_common()[1][1]-c_odd.most_common()[0][1]-2))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

counter1 = Counter(v1)
x1 = counter1.most_common()[0:2]
counter2 = Counter(v2)
x2 = counter2.most_common()[0:2]

n = n//2
ans = 0
if x1[0][0] == x2[0][0]:
    if x1[0][1] > x2[0][1]:
        ans = (n - x1[0][1]) + (n - x2[1][1])
    else:
        ans =  (n - x2[0][1]) + (n - x1[1][1])
else:
    ans = (n - x1[0][1]) + (n - x2[0][1])
print(ans)

Submission status: Runtime Error

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

if max(v)==min(v):
	print(int(n/2))
else:
	dic1 = {}
	dic2 = {}
	
	for i in range(n):
		if i % 2 == 1:
			if str(v[i]) in dic1.keys():
				dic1[str(v[i])] = dic1[str(v[i])] + 1
			else:
				dic1[str(v[i])] = 1
	
		if i % 2 == 0:
			if str(v[i]) in dic2.keys():
				dic2[str(v[i])] = dic2[str(v[i])] + 1
			else:
				dic2[str(v[i])] = 1
	
	max1 = max(dic1, key=dic1.get)
	max2 = max(dic2, key=dic2.get)
	p1 = dic1[max1]
	p2 = dic2[max2]
	if max1 == max2:
		dic1.pop(max1)
		dic2.pop(max2)
		max3 = max(dic1, key=dic1.get)
		max4 = max(dic2, key=dic2.get)
		p3 = dic3[max3]
		p4 = dic4[max4]
		if p1 + p4 > p2 + p3:
			p2 = p4
		else:
			p1 = p3
	
	print(n-p1-p2)

Submission status: Runtime Error

Solution code:
#encoding utf-8

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


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

#odd part
count={}
for i in range(len(v_odd)):
    if v_odd[i] in count.keys():
        count[v_odd[i]] += 1
    else:
        count[v_odd[i]] = 1

if len(count) == 1:
    pass
    # num_odd = 0
else:
    for k, v in sorted(count.items(), key=lambda x: -x[1]):
        pass
    keys = list(count.keys())
    # num_odd = len(v_odd)-int(count[keys[0]])
# print(num)

#even part
even_count={}

for i in range(len(v_even)):
    if v_even[i] in even_count.keys():
        even_count[v_even[i]] += 1
    else:
        even_count[v_even[i]] = 1

if len(even_count) == 1:
    pass
    # num += 0
else:
    for k, v in sorted(even_count.items(), key=lambda x: -x[1]):
        pass
    even_keys = list(even_count.keys())
    # num += len(v_even)-int(count[even_keys[0]])

if even_keys[0] == keys[0]:
    if len(keys) == 1 and len(even_keys) == 1:
        answer = int(len(keys))
    elif len(keys) == 1:
        answer = len(v_even)-int(v_even[even_keys[1]])
    elif len(even_keys) == 1:
        answer = len(v_odd)-int(v_odd[keys[1]])
    else:
        if int(v_even[even_keys[0]]) >= int(v_odd[keys[0]]):
            answer = len(v_odd)-int(count[keys[1]])
            answer += len(v_even)-int(even_count[even_keys[0]])
        else:
            answer = len(v_odd)-int(count[keys[0]])
            answer += len(v_even)-int(even_count[even_keys[1]])
print(int(answer))

Submission status: Runtime Error

Solution code:
import collections

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

v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]

count1 = collections.Counter(v1)
count2 = collections.Counter(v2)

if v1 == v2:
    print(len(v1))

elif len(count1) == 1 and len(count2) == 1:
    print(0)

else:
    res = 0
    ct1 = list(count1.values())
    ct2 = list(count2.values())

    if len(ct1) != 1:
        for i in ct1[1:]:
            res = res + ct1[i]

    if len(ct2) != 1:
        for i in ct2[1:]:
            res = res + ct2[i]
    print(res)

Submission status: Runtime Error

Solution code:
import collections

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

a = []
b = []
a_f = 0
b_f = 0
a_s = 0
b_s = 0
for i in range(N):
    if i%2 == 0:
        a.append(l[i])
    else:
        b.append(l[i])
        
c_a = collections.Counter(a)
c_b = collections.Counter(b)

a_f = c_a.most_common()[0]
b_f = c_b.most_common()[0]

if a_f[0] != b_f[0]:
    print(N - a_f[1] - b_f[1])

elif len(set(a)) == 1 and len(set(b)) == 1:
    print(int(N/2))
elif len(set(a)) == 1:
    print(int(N/2 - c_b.most_common()[1][1]))
elif len(set(b)) == 1:
    print(int(N/2 - c_a.most_common()[1][1]))
elif a_f[1] == b_f[1]:
    second_a = c_a.most_common()[1][1]
    second_b = c_b.most_common()[1][1]
    if second_a >= second_b:
        print(int(N - b_f[1] - second_a)
    else:
        print(int(N - a_f[1] - second_b)
elif a_f[1] > b_f[1]:
    print(int(N - a_f[1] - c_b.most_common()[1][1]))
else:
    print(int(N - b_f[1] - c_a.most_common()[1][1]))

Submission status: Runtime Error

Solution code:
import collections

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

v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]

count1 = collections.Counter(v1)
count2 = collections.Counter(v2)

if v1 == v2:
    print(len(v1))

elif len(count1) == 1 and len(count2) == 1:
    print(0)

else:
    res = 0
    ct1 = list(count1.values())
    ct2 = list(count2.values())

    for i in ct1[1:]:
        res = res + ct1[i]

    for i in ct2[1:]:
        res = res + ct2[i]
    print(res)

Submission status: Runtime Error

Solution code:
import collections

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

a = []
b = []
a_f = 0
b_f = 0
a_s = 0
b_s = 0
for i in range(N):
    if i%2 == 0:
        a.append(l[i])
    else:
        b.append(l[i])
        
c_a = collections.Counter(a)
c_b = collections.Counter(b)

a_f = c_a.most_common()[0]
b_f = c_b.most_common()[0]

if a_f[0] != b_f[0]:
    print(N - a_f[1] - b_f[1])

elif len(set(a)) == 1 and len(set(b)) == 1:
    print(int(N/2))
elif len(set(a)) == 1:
    print(int(N/2 - c_b.most_common()[1][1]))
elif len(set(b)) == 1:
    print(int(N/2 - c_a.most_common()[1][1]))
elif a_f[1] == b_f[1]:
    if c_a.most_common()[1][1] >= c_b.most_common()[1][1]:
        print(int(N - b_f[1] - c_a.most_common()[1][1]))
    else:
        print(int(N - a_f[1] - b_a.most_common()[1][1]))
elif a_f[1] > b_f[1]:
    print(int(N - a_f[1] - c_b.most_common()[1][1]))
else:
    print(int(N - b_f[1] - c_a.most_common()[1][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
v_odd = {}
v_even = {}
vlist = list(map(int, input().split()))
for i in range(n):
    if i % 2 == 1:
        if vlist[i] in v_odd:
            v_odd[vlist[i]] += 1
        else:
            v_odd[vlist[i]] = 1
    else:
        if i in v_even:
            v_even[vlist[i]] += 1
        else:
            v_even[vlist[i]] = 1
omax = max(v_odd, key=(lambda x: v_odd[x]))
emax = max(v_even, key=(lambda x: v_even[x]))
if omax != emax:
    orewrite = sum(v_odd[i] for i in v_odd) - v_odd[omax]
    erewrite = sum(v_even[i] for i in v_even) - v_even[emax]
    ans = orewrite + erewrite
    print(ans)
else:
    lo = len(v_odd)
    le = len(v_even)
    if lo == 1 and le == 1:
        print(v_odd[omax])
    elif lo != 1:
        osum = sum(v_odd[i] for i in v_odd)
        v_odd[omax] = 0
        osecmax = max(v_odd, key=(lambda x: v_odd[x]))
        ans = osum - osecmax + sum(v_even[i] for i in v_even) - v_even[emax]
        print(ans)
    else:
        esum = sum(v_even[i] for i in v_even)
        v_even[emax] = 0
        esecmax = max(v_even, key=(lambda x: v_even[x]))
        ans = esum - esecmax + sum(v_odd[i] for i in v_odd) - v_odd[omax]
        print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

counter1 = Counter(v1)
x1 = counter1.most_common()[0][0]
counter2 = Counter(v2)
x2 = counter2.most_common()[0][0]

x1_count = counter1.most_common()[0][1]
x2_count = counter2.most_common()[0][1]

n = n//2
ans = 0
if x1 == x2:
    if x1_count > x2_count:
        ans = (n - x1_count) + (n - counter2.most_common()[1][1])
    else:
        ans = (n - x2_count) + (n - counter1.most_common()[1][1])
else:
    ans = (n - x1_count) + (n - x2_count)
print(ans)

Submission status: Runtime Error

Solution code:
from statistics import mode
n=int(input())
v=list(map(int,input().split()))
m=int(n/2)
w=['']*m
x=['']*m
xcntr=0
wcnt=n+1
xcnt=n+1
for i in range(m):
	w[i]=v[i*2]
	x[i]=v[i*2+1]
for l in range(m):
	if x[l]!=mode(w):
		xcntr=max(xcntr,x.count(x[l]))
ans=n-(w.count(mode(w))+xcntr)
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]

count1 = collections.Counter(v1)
count2 = collections.Counter(v2)

if v1 == v2:
    print(len(v1))

elif len(count1) == 1 and len(count2) == 1:
    print(0)

else:
    res = 0
    ct1 = list(count1.values())
    ct2 = list(count2.values())

    for i in ct1[1:]:
        if i == 0:
            continue
        res = res + ct1[i]

    for i in ct2[1:]:
        if i == 0:
            continue
        res = res + ct2[i]
    print(res)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

counter1 = Counter(v1)
x1 = counter1.most_common()[0][0]
counter2 = Counter(v2)
x2 = counter2.most_common()[0][0]

x1_count = v1.count(x1)
x2_count = v2.count(x2)

n = n//2
ans = 0
if x1 == x2:
    if x1_count > x2_count:
        ans = (n - x1_count) + (n - counter2.most_common()[1][1])
    else:
        ans = (n - x2_count) + (n - counter1.most_common()[1][1])
else:
    ans = (n - x1_count) + (n - x2_count)
print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5))]
cc = [0 for i in range(pow(10,5))]
for i in range(a):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
p = 0
pp = 0
for i in range(d):
    if one < c[i]:
        onee = one
        one = c[i]
        p += 1
    if two < cc[i]:
        twoo = two
        two = cc[i]
        p += 1
    if p == 2
        pp = 1
    else:
        pp = 0
    p = 0

t = max(one+twoo,onee+two)

if pp == 0
    print(a-one-two)
else:
    print(a-t)

Submission status: Runtime Error

Solution code:
import collections

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

v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]

count1 = collections.Counter(v1)
count2 = collections.Counter(v2)

if v1 == v2:
    print(len(v1))

elif len(count1) == 1 and len(count2) == 1:
    print(0)

else:
    res = 0
    ct1 = list(count1.values())
    ct2 = list(count2.values())

    for i in ct1[1:]:
        if i == 0:
            continue
        res = res + ct1[i]

    for i in ct2[1:]:
        if i == 0:
            continue
        res = res + ct2[i]
    print(res)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
v = [int(i) for i in input().split()]
odd = collections.Counter(v[1::2])
even = collections.Counter(v[0::2])
# print(odd)

max_odd = max(odd, key=odd.get)
# print(max_odd)
max_even = max(even, key=even.get)
# print(max_even)

if max_odd == max_even:
    del(even[max_even])
    try:
        max_even = max(even, key=even.get)
        max_even_v = even[max_even]
    except:
        max_even_v = 0
    
max_odd_v = odd[max_odd]
num_change_odd = n / 2 - max_odd_v
num_change_even = n / 2 - max_even_v
print(int(num_change_odd + num_change_even))

Submission status: Runtime Error

Solution code:
n = int(input())
v_odd = {}
v_even = {}
vlist = list(map(int, input().split()))
for i in range(n):
    if i % 2 == 1:
        if vlist[i] in v_odd:
            v_odd[vlist[i]] += 1
        else:
            v_odd[vlist[i]] = 1
    else:
        if i in v_even:
            v_even[vlist[i]] += 1
        else:
            v_even[vlist[i]] = 1
omax = max(v_odd, key=(lambda x: v_odd[x]))
emax = max(v_even, key=(lambda x: v_even[x]))
if omax != emax:
    orewrite = sum(v_odd[i] for i in v_odd) - v_odd[omax]
    erewrite = sum(v_even[i] for i in v_even) - v_even[emax]
    ans = orewrite + erewrite
    print(ans)
else:
    lo = len(v_odd)
    le = len(v_even)
    if lo == 1 and le == 1:
        print(v_odd[omax])
    elif lo != 1:
        sum = sum(v_odd[i] for i in v_odd)
        v_odd[omax] = 0
        osecmax = max(v_odd, key=(lambda x: v_odd[x]))
        ans = sum - osecmax
        print(ans)
    else:
        sum = sum(v_even[i] for i in v_even)
        v_even[emax] = 0
        esecmax = max(v_even, key=(lambda x: v_even[x]))
        ans = sum - esecmax
        print(ans)

Submission status: Runtime Error

Solution code:
import collections

N = int(raw_input().replace("\n", ""))

a_list = map(int, raw_input().replace("\n", "").split(" "))
even_list = a_list[::2]
odd_list = a_list[1::2]

len_vec = N / 2

even_c = collections.Counter(even_list)
odd_c = collections.Counter(odd_list)

even_first_value, even_first_count = even_c.most_common()[0]
odd_first_value, odd_first_count  = odd_c.most_common()[0]
#(even_first_value, even_first_count), (even_second_value, even_second_count) = even_c.most_common()[:2]
#(odd_first_value, odd_first_count), (odd_second_value, odd_second_count) = odd_c.most_common()[:2]

if even_first_value == odd_first_value and len(even_c) == 1 and len(odd_c) == 1:
    cost = len_vec
elif even_first_value != odd_first_value:
    cost =  (even_first_count + odd_first_count)
elif len(even_c) == 1 and len(odd_c) > 1:
    odd_second_value, odd_second_count = odd_c.most_common(1)
    cost = len_vec + odd_second_count
elif len(odd_c) == 1 and len(even_c) > 1:
    even_second_value, even_second_count = even_c.most_common(1)
    cost = len_vec + odd_second_count
else: # ryouhou no first ga onaji de hutatuijou arutoki
    odd_second_value, odd_second_count = odd_c.most_common(1)
    even_second_value, even_second_count = even_c.most_common(1)
    cost = max(even_first_count+odd_second_count, even_second_count+odd_first_count)

print 2* len_vec - cost

Submission status: Runtime Error

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

left = [0] * 10**5 + 1
right = [0] * 10**5 + 1

for i in range(len(v)):
    if i % 2 == 0:
        left[v[i]] += 1
    else:
        right[v[i]] += 1

left_max = 0
left_max_second = 0
right_max = 0
right_max_second = 0
left_flag = 0
right_flag = 0
for i in range(len(left)):
    if left_max < left[i]:
        left_max_second = left_max
        left_max = left[i]
        left_flag = i

    if right_max < right[i]:
        right_max_second = right_max
        right_max = right[i]
        right_flag = i

if left_flag == right_flag:
    tmp = min(left_max + right_max_second, right_max + left_max_second)
    # print(left_max, left_max_second, right_max, right_max_second)
    print(n - tmp)
else:
    print((n // 2 - left_max) + (n // 2 - right_max))

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int,input().split()))
v2 = []
for i in range(0, n - 1, 1):
    v2.append(abs(v[i] - v[i + 1]))
count = 0
for i in range(0, len(v2), 1):
    if v2[0] != v2[i + 1]:
        count += 1
if count > len(v2) - count:
    ans = len(v2) - count
else:
    ans = count
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
lst = list(map(int, input().split()))
m = 0
for i in range(0,n-2):
	if lst[i] != lst[i+2]:
    	lst[i+2] = lst[i]
    	m += 1
    elif lst[i] == lst[i+1]:
		m += 1
print(m)

Submission status: Runtime Error

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
v = [int(i) for i in stdin.readline().rstrip().split()]

left = [0] * 10**5
right = [0] * 10**5

for i in range(len(v)):
    if i % 2 == 0:
        left[v[i]] += 1
    else:
        right[v[i]] += 1

left_max = 0
left_max_second = 0
right_max = 0
right_max_second = 0
left_flag = 0
right_flag = 0
for i in range(len(left)):
    if left_max < left[i]:
        left_max_second = left_max
        left_max = left[i]
        left_flag = i

    if right_max < right[i]:
        right_max_second = right_max
        right_max = right[i]
        right_flag = i

if left_flag == right_flag:
    tmp = min(left_max + right_max_second, right_max + left_max_second)
    # print(left_max, left_max_second, right_max, right_max_second)
    print(n - tmp)
else:
    print((n // 2 - left_max) + (n // 2 - right_max))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':                                                                                                                                                  n = int(input())
    vs = list(map(int, input().split()))

    even = vs[::2]
    odd = vs[1::2]

    from collections import Counter

    result = 0
    #evenの処理
    ce = Counter(even)
    emode = ce.most_common(1)[0]

    oe = Counter(odd)
    omode = oe.most_common(1)[0]
    if emode[0] == omode[0]:
        if emode[1] > omode[1]:
            for i in range(len(even)):
                if even[i] != emode[0]:
                    result += 1
            if len(oe.most_common()) == 1:
                omode = -1
                result += len(odd)
            else:
                omode = oe.most_common(2)[0][0]
                for i in range(len(odd)):
                    if odd[i] != omode:
                        result += 1

        else:
            for i in range(len(odd)):
                if odd[i] != omode[0]:
                    result += 1
            if len(ce.most_common()) == 1:
                emode = -1
                result += len(even)
            else:
                emode = ce.most_common(2)[0][0]
                for i in range(len(even)):
                    if even[i] != emode:
                        result += 1
    else:
        for i in range(len(even)):
            if even[i] != emode[0]:
                result += 1
        for i in range(len(odd)):
            if odd[i] != omode[0]:
                result += 1

    print(result)