Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
n = N // 2

index = 0
g_inputs = []
k_inputs = []

for i in input().split():
    if index % 2 == 0:
        g_inputs.append(int(i))
        index += 1
    else:
        k_inputs.append(int(i))
        index += 1

g = Counter(g_inputs)
k = Counter(k_inputs)

g_max = max([(v,k) for k,v in g.items()])[1] 
k_max = max([(v,k) for k,v in k.items()])[1]

if g_max == k_max:
    if g[g_max] < k[k_max]:
        del g[g_max]
        g_max = max([(v,k) for k,v in g.items()])[1]
        print(N - g[g_max] - k[k_max])
    elif g[g_max] > k[k_max]:
        del k[k_max]
        k_max = max([(v,k) for k,v in k.items()])[1]
        print(N - g[g_max] - k[k_max])
    else:
        del g[g_max]
        del k[k_max]
        if len(g) == 0 and len(k) == 0:
            print(n)
        elif len(g) != 0 and len(k) == 0:
            print(n - g[max([(v,k) for k,v in g.items()])[1]])
        elif len(g) == 0 and len(k) != 0:
            print(n - k[max([(v,k) for k,v in k.items()])[1]])
        elif len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            g_max = max([(v,k) for k,v in g.items()])[1]
            k_max = max([(v,k) for k,v in k.items()])[1]
            if g[g_max] < k[k_max]:
                print(n - k[k_max])
            elif g[g_max] > k[k_max]:
                print(n - g[g_max])
            else:
                print(N - g[g_max] - k[k_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

if odd == even:
    print(len(odd))
    exit(0)

if o.most_common()[0][0] == e.most_common()[0][0]:
    if o.most_common()[0][1] > e.most_common()[0][1] and e.most_common()[0][1] < len(e):
        maxevencnt = e.most_common()[1][1]
    elif o.most_common()[0][1] < e.most_common()[0][1] and o.most_common()[0][1] < len(o):
        maxoddcnt = o.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Wrong Answer

Solution code:
def exchange(v):
    cnt = 0
    pattern2 = 0
    for (i, num) in enumerate(v):
        if i == 0:
            pattern1 = num
        elif i % 2 == 0:
            if pattern1 != num:
                cnt += 1
        elif i % 2 == 1:
            if pattern2 == 0 and num != pattern1:
                pattern2 = num
            elif pattern2 != num:
                cnt += 1
    return cnt

        

if __name__ == "__main__":
    n = int(input())
    v = list(map(int,input().split()))
    print(exchange(v))

Submission status: Wrong Answer

Solution code:
import collections

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

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

else:
    odd = v[0::2]
    even = v[1::2]
    if len(set(odd)) > 1:
        odd_c = collections.Counter(odd).most_common()[1:]
        values, odd_counts = zip(*odd_c)
        odd_num=sum(odd_counts)
    else:
        odd_num=0
        
    if len(set(even)) > 1:
        even_c = collections.Counter(even).most_common()[1:]
        values, even_counts = zip(*even_c)
        even_num=sum(even_counts)
    else:
        even_num=0
        
    print(odd_num+even_num)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd_list = v[1::2]  # 偶数番目
even_list = v[::2]  # 奇数番目

odd_list_len = len(odd_list)
even_list_len = len(even_list)

odd_mode = Counter(odd_list).most_common(1)
even_mode = Counter(even_list).most_common(1)

ans = 0

if odd_mode[0][1] >= even_mode[0][1]:
    ans += odd_list_len - odd_mode[0][1]
    if odd_mode[0][0] != even_mode[0][0]:
        ans += even_list_len - even_mode[0][1]
    else:
        if len(Counter(even_list).most_common(2)) == 2:
            ans += even_list_len - Counter(even_list).most_common(2)[1][1]
        else:
            ans += even_list_len
else:
    ans += even_list_len - even_mode[0][1]
    if even_mode[0][0] != odd_mode[0][0]:
        ans += odd_list_len - odd_mode[0][1]
    else:
        if len(Counter(odd_list).most_common(2)) == 2:
            ans += odd_list_len - Counter(odd_list).most_common(2)[1][1]
        else:
            ans += odd_list_len
print(ans)

Submission status: Wrong Answer

Solution code:
import operator

n=int(input().strip())
lst=input().split(' ')
map(int, lst)

d1 = {}
d2 = {}

for i in range(len(lst)):
    if i % 2 == 0:
        if lst[i] in d1:
            d1[lst[i]] += 1
        else:
            d1[lst[i]] = 1
    else:
        if lst[i] in d2:
            d2[lst[i]] += 1
        else:
            d2[lst[i]] = 1

key1 = max(d1.items(), key=operator.itemgetter(1))[0]
key2 = max(d2.items(), key=operator.itemgetter(1))[0]

sorted1 = sorted(((v,k) for k,v in d1.items()))

if(key1 == key2):
    #print(n/2-d2[key2]+n/2-max(sorted(d1.values(), reverse=True)[1],sorted(d2.values(), reverse=True)[1]))
    toret = 0
    while(key1 != None and key2 != None and key1 == key2):
        toret += max(d1[key1],d2[key2])
        d1.pop(key1)
        d2.pop(key2)

        if len(d1) == 0 or len(d2) == 0:
            break

        key1 = max(d1.items(), key=operator.itemgetter(1))[0]
        key2 = max(d2.items(), key=operator.itemgetter(1))[0]

    print(toret + min(sum(d1.values()), sum(d2.values())))

else:
    print(n-d1[key1]-d2[key2])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
evens = []
odds = []
for i in range(0, n, 2):
    evens.append(v[i])
for i in range(1, n, 2):
    odds.append(v[i])
evens_cnts = Counter(evens)
odds_cnts = Counter(odds)
evens_change = n // 2 - max(evens_cnts.values())
odds_change = n // 2 - max(odds_cnts.values())
if evens_change == 0 and odds_change == 0:
    # 要素が全て同じか判定
    if evens[0] == odds[0]:
        print(n // 2)
    else:
        print(0)
else:
    # evens と odds が同じか判定
    if evens == odds:
        li = list(odds_cnts.keys())
        odds_cnts.pop(li[0])
        odds_change = n // 2 - max(odds_cnts.values())
    elif evens_change < odds_change:
        li = list(evens_cnts.keys())
        if li[0] in odds:
            odds_cnts.pop(li[0])
        odds_change = n // 2 - max(odds_cnts.values())
    else:
        li = list(odds_cnts.keys())
        if li[0] in evens:
            evens_cnts.pop(li[0])
        evens_change = n // 2 - max(evens_cnts.values())
    print(evens_change + odds_change)

Submission status: Wrong Answer

Solution code:
n=int(input())

l=list(map(int,input().split()))
l1=[]
l2=[]

for i in range(n):
	if i%2==0:
		l1.append(l[i])
	else:
		l2.append(l[i])

count1=[]
count2=[]

for i in range(100000):
	count1.append(0)
	count2.append(0)

for i in range(n//2):
	count1[l1[i]-1]+=1
	count2[l2[i]-1]+=1

max1=0
max2=0

maxc1=[]
maxc2=[]

for i in range(100000):
	if count1[i]>=max1:
		max1=count1[i]
		maxc1.append(i)

	if count2[i]>=max2:
		max2=count2[i]
		maxc2.append(i)

# print('maxc1',maxc1)
# print('maxc2',maxc2)
# print('max1',max1)
# print('max2',max2)

# if len(maxc2)+len(maxc1)>2 or (len(maxc2)+len(maxc1)==2 and maxc1[0]!=maxc2[0]):
# 	final=max1+max2

# else :
max3=0
max4=0
for i in range(100000):
	if i!=maxc1[0]:
		if count1[i]>max3:
			max3=count1[i]
			#maxc1.append(i)

	if i!=maxc2[0]:
		if count2[i]>max4:
			max4=count2[i]
			#maxc2.append(i)

final=max(max1+max4,max2+max3)

print(n-final)

Submission status: Wrong Answer

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

Vdic = [{}, {}]
# 0: even 1: odd
for i in range(len(V_list)):
    v = V_list[i]

    tmp = (i + 1) % 2
    Vdic[tmp][v] = Vdic[tmp].get(v, 0) + 1

even = sorted(Vdic[0].values())
odd = sorted(Vdic[1].values())

ans_even = [(-1, 0)]
ans_odd = [(-2, 0)]
if(len(even) == 1):
    t = max(Vdic[0], key=Vdic[0].get)
    ans_even.append((t, even[0]))
else:
    n1 = even[-1]
    n2 = even[-2]

    f1 = True
    f2 = True
    if(n1 == n2):
        for k, v in Vdic[0].items():
            if(v == n1):
                if(f1 is False and f2 is False):
                    continue
                if(f1 is False):
                    f2 = False
                f1 = False
                ans_even.append((k, v))
    else:
        for k, v in Vdic[0].items():
            if(v == n1 and f1 is True):
                f1 = False
                ans_even.append((k, v))
            if(v == n2 and f2 is True):
                f2 = False
                ans_even.append((k, v))

if(len(odd) == 1):
    t = max(Vdic[1], key=Vdic[1].get)
    ans_odd.append((t, odd[0]))
else:
    n1 = odd[-1]
    n2 = odd[-2]

    f1 = True
    f2 = True
    if(n1 == n2):
        for k, v in Vdic[1].items():
            if(v == n1):
                if(f1 is False and f2 is False):
                    continue
                if(f1 is False):
                    f2 = False
                f1 = False
                ans_odd.append((k, v))
    else:
        for k, v in Vdic[1].items():
            if(v == n1 and f1 is True):
                f1 = False
                ans_even.append((k, v))
            if(v == n2 and f2 is True):
                f2 = False
                ans_odd.append((k, v))


# print(ans_even, ans_odd)

ans = []
for ke, ve in ans_even:
    for ko, vo in ans_odd:
        if(ke != ko):
            ans.append(n - ve - vo)

print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
for i in range(len(a)):
    a[i]=int(a[i])
    
o = a[::2]
e = a[1::2]
x = [0] * int(n/2)
y = [0] * int(n/2)
mi = 0
for i in range(int(n / 2)):
    x[i],y[i] = 0, 0
    for j in range (int(n / 2)):
        if o[j] == o[i]:
            x[i] += 1
        if e[j] == e[i]:
            y[i] += 1

l = x.index(max(x))
m = y.index(max(y))
if o[l] != e[m]:
    mi = n - max(x) - max(y)
else:
    x.sort(reverse=True)
    y.sort(reverse=True)
    lA=[x[0]+y[1], y[0]+x[1]]
    mi = n - max(lA) 

print(mi)

Submission status: Wrong Answer

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 len(seh) == 1 and len(soh) == 1:
        print(len(a)//2)
    elif len(seh) == 1:
        print(len(a) - seh[0][1] - soh[1][1])
    elif len(soh) == 1:
        print(len(a) - soh[0][1] - seh[1][1])
    else:
        print(min(len(a) - seh[0][1] - soh[1][1], len(a) - soh[0][1] - seh[1][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
k = n//2
a = list(map(int,input().split()))
b = c = []
for i in range(k):
  b.append(a[2*i])
  c.append(a[2*i+1])
p = Counter(b).most_common()
q = Counter(c).most_common()
s, t = p[0], q[0]
if s[0]!=t[0]:
  ans = n - s[1]-t[1]
else:
  if len(p) == 1 and len(q) == 1:
    ans = k
  elif len(p) == 1:
    ans = n - q[1][1]
  elif len(q) == 1:
    ans = n - p[1][1]
  else:  
    if p[1][1] >= q[1][1]:
      ans = n - t[1]-p[1][1]
    else:
      ans = n - s[1] - q[1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import collections

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

c = 0
even, odd = [],[]

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

ce = collections.Counter(even)
co = collections.Counter(odd)
cV = collections.Counter(V)

if len(ce.keys()) == 1 and len(co.keys()) == 1:
    c = 0
    
elif len(ce.keys()) == 1:
    c = len(co) - co.most_common()[0][1]

elif len(co.keys()) == 1:
    c = len(ce) - ce.most_common()[0][1]

else:
    c = len(ce) + len(co) - ce.most_common()[0][1] - co.most_common()[0][1]
  

print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
array = [int(x) for x in input().split()]
tmp_dict = {}
tmp_dict2 = {}
tmp_array = array[::2]
tmp_array2 = array[1::2]
for i in tmp_array:
    if i in tmp_dict.keys():
        tmp_dict[i] += 1
    else:
        tmp_dict[i] = 1
for i in tmp_array2:
    if i in tmp_dict2.keys():
        tmp_dict2[i] += 1
    else:
        tmp_dict2[i] = 1

sorted_dict = sorted(tmp_dict.items(), key=lambda x: x[1], reverse=True)
sorted_dict2 = sorted(tmp_dict2.items(), key=lambda x: x[1], reverse=True)
tmp = sorted_dict[0][0]
tmp2 = sorted_dict2[0][0]

if sorted_dict == sorted_dict2:
    print(len(array)//2)
    exit()

if tmp == tmp2:
    if len(sorted_dict) == 1:
        tmp2 = sorted_dict2[1][0]
    elif len(sorted_dict2) == 1:
        tmp = sorted_dict[1][0]
    else:
        if sorted_dict2[1][1] > sorted_dict[1][1]:
            tmp2 = sorted_dict2[1][0]
        elif sorted_dict2[1][1] <= sorted_dict[1][1]:
            tmp = sorted_dict[1][0]
res = 0
for i in tmp_array:
    if i != tmp:
       res += 1
for i in tmp_array2:
    if i != tmp2:
       res += 1
print(res)

Submission status: Wrong Answer

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

head = vlist[::2]
foll = vlist[1::2]

import collections
ch = collections.Counter(head).most_common()
cf = collections.Counter(foll).most_common()

h_ = ch[0]
f_ = cf[0]

if h_[0] == f_[0]:
    if h_[1] == f_[1]:
        if h_[0] == vlist[0]:
            f_ = (-1.1, 0)
        else:
            h_ = (-1.1, 0)
    elif h_[1] > f_[1]:
        if len(cf) != 1:
            f_ = cf[1]
        else:
            f_ = (-1.1, 0)
    else:
        if len(ch) != 1:
            h_ = ch[1]
        else:
            h_ = (-1.1, 0)

count = 0
for i in range(len(vlist)):
    if i % 2 == 0 and vlist[i] != h_[0]:
        count += 1
    if i % 2 == 1 and vlist[i] != f_[0]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import collections
res = 0
n = int(input())
v = list(map(int, input().split()))
v_unique = set(v)
c = collections.Counter(v)
if len(v_unique) == 1:
    res = int(len(v) / 2)
    print(res)
    exit()
count = [c.most_common()[i][1] for i in range(len(v_unique))]
for i in range(2):
    while count[i] != int(len(v) / 2):
        if count[i] < int(len(v) / 2):
            for j in range(2, len(v_unique)):
                while count[j] != 0 and count[i] != int(len(v) / 2):
                    count[i] += 1
                    count[j] -= 1
                    res += abs(int(c.most_common()[i][0]) - int(c.most_common()[j][0]))
        else:
            count[i] -= 1
            count[i+1] += 1
            res += abs(int(c.most_common()[i][0]) - int(c.most_common()[i+1][0]))
print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import collections

input = sys.stdin.readline
a = input().split()
v = list(map(int, input().split()))

x = []
y = []

for i in range(len(v)):
    if i % 2 == 0:
        x.append(v[i])
    else:
        y.append(v[i])


if len(list(set(x))) == 1:
    c = collections.Counter(y)
    print(len(y) - c.most_common()[0][1])
else:
    c = collections.Counter(x)
    print(len(x) - c.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
a = int(input())

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

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

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

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
n = int(input())
str_num = input()
num = str_num.split()
even_num = {}
odd_num = {}

for index in range(0,n):
    if index%2 == 0:
        if num[index] in even_num:
            even_num[num[index]] += 1
        else:
            even_num[num[index]] = 1
    else:
        if num[index] in odd_num:
            odd_num[num[index]] += 1
        else:
            odd_num[num[index]] = 1

even_max_key = max(even_num, key=even_num.get)
odd_max_key = max(odd_num, key=odd_num.get)
even_change = int(n/2) - even_num[even_max_key]
odd_change = int(n/2) - odd_num[odd_max_key]

if even_max_key == odd_max_key:
	if even_change < odd_change:
		if len(even_num) == 1:
			odd_num = int(n/2)
		if len(even_num) != 1:
			del even_num[even_max_key]
			even_max_key = max(even_num, key=even_num.get)
			even_change = n/2 - even_num[even_max_key]
	else:
		if len(odd_num) == 1:
			even_change = int(n/2)
		if len(odd_num) != 1:
			del odd_num[odd_max_key]
			odd_max_key = max(odd_num, key=odd_num.get) 
			odd_change = n/2 - odd_num[odd_max_key]

ans = int(even_change + odd_change)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split(' ')]

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

vo = collections.Counter(v_odd).most_common()
ve = collections.Counter(v_even).most_common()

# 最大の値が同じ場合
if vo[0][0] == ve[0][0]:
    # 奇数のほうが少ない場合
    if vo[0][1] > ve[0][1]:
        result = len(v_odd) - vo[0][1] + len(v_even) - ve[1][1]
    elif vo[0][1] < ve[0][1]:
        result = len(v_odd) - vo[1][1] + len(v_even) - ve[0][1]
    else:
        result = len(v_odd) - vo[0][1] + len(v_even) 
else:
    result = len(v_odd) - vo[0][1] + len(v_even) - ve[0][1]

print(result)

Submission status: Wrong Answer

Solution code:
import collections

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

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

else:
    odd = v[0::2]
    even = v[1::2]
    if len(set(odd)) > 1:
        odd_c = collections.Counter(odd).most_common()[1:]
        values, odd_counts = zip(*odd_c)
        odd_num=sum(odd_counts)
    else:
        odd_num=1
        
    if len(set(even)) > 1:
        even_c = collections.Counter(even).most_common()[1:]
        values, even_counts = zip(*even_c)
        even_num=sum(even_counts)
    else:
        even_num=1
        
    print(odd_num+even_num)

Submission status: Wrong Answer

Solution code:
n=int(input())

l=list(map(int,input().split()))
l1=[]
l2=[]

for i in range(n):
	if i%2==0:
		l1.append(l[i])
	else:
		l2.append(l[i])

count1=[]
count2=[]

for i in range(100000):
	count1.append(0)
	count2.append(0)

for i in range(n//2):
	count1[l1[i]-1]+=1
	count2[l2[i]-1]+=1

max1=0
max2=0

maxc1=[]
maxc2=[]

for i in range(100000):
	if count1[i]>=max1:
		max1=count1[i]
		maxc1.append(i)

	if count2[i]>=max2:
		max2=count2[i]
		maxc2.append(i)

# print('maxc1',maxc1)
# print('maxc2',maxc2)
# print('max1',max1)
# print('max2',max2)

# if len(maxc2)+len(maxc1)>2 or (len(maxc2)+len(maxc1)==2 and maxc1[0]!=maxc2[0]):
# 	final=max1+max2

# else :
max3=0
max4=0
for i in range(100000):
	if i!=maxc1[0]:
		if count1[i]>=max3:
			max3=count1[i]
			maxc1.append(i)

	if i!=maxc2[0]:
		if count2[i]>=max4:
			max4=count2[i]
			maxc2.append(i)

final=max(max1+max4,max2+max3)

print(n-final)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

if o.most_common()[0][0] == e.most_common()[0][0]:
    if o.most_common()[0][1] > e.most_common()[0][1] and e.most_common()[0][1] < len(e):
        maxevencnt = e.most_common()[1][1]
    elif o.most_common()[0][1] < e.most_common()[0][1] and o.most_common()[0][1] < len(o):
        maxoddcnt = o.most_common()[1][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
count=0
v=[]
v=[int(i) for i in input().split()]
for i in range(n-2):
    if v[i]==v[i+2]:
        pass
    else:
        count+=1
num=v[0]
flag=True
for i in range(n-1):
    if v[i]==v[i+1]:
        continue
    else:
        flag=False
if flag:
    if n%2==0:
        count=int(n/2)
    else:
        count=int((n-1)/2)
print(count)

Submission status: Wrong Answer

Solution code:
import collections

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

def count_elem(x):
    coll = collections.Counter(x)
    return coll.most_common()

b = count_elem(a[::2])
c = count_elem(a[1::2])

if b[0][0] != c[0][0]:
    print(len(a) - b[0][1] - c[0][1])
else:
    if b[0][1] > c[0][1]:
        if len(c) > 1:
            print(len(a) - b[0][1] - c[1][1])
        else:
            print(len(a) - b[0][1])
    elif b[0][1] < c[0][1]:
        if len(b) > 1:
            print(len(a) - b[1][1] - c[0][1])
        else:
            print(len(a) - c[0][1])
    elif b[0][1] == c[0][1]:
        if len(a)/2 == b[0][1]:
            print(len(a)/2)
        else:
            if b[1][1] >= c[1][1]:
                print(len(a) - b[1][1] - c[0][1])
            else:
                print(len(a) - b[0][1] - c[1][1])

Submission status: Wrong Answer

Solution code:
a = int(input())

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

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

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

if k == kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v_l = list(map(int, input().split()))
v_l_bk = v_l
if len(set(v_l)) == 1:
    print(n // 2)
    exit()
elif len(set(v_l)) == n // 2:
    print(n // 2)
    exit()

v_l_odd = []
v_l_even = []

for i in range(n):
    if i % 2 == 0:
        v_l_odd.append(v_l[i])
    else:
        v_l_even.append(v_l[i])
times = 0
count_odd = collections.Counter(v_l_odd)
count_even = collections.Counter(v_l_even)
while True:
    mon = count_odd.most_common()[times][0]
    men = count_even.most_common()[times][0]

    v_l_odd_diff = []
    v_l_even_diff = []

    for i in range(n):
        if i % 2 == 0:
            if v_l[i] != mon:
                v_l_odd_diff.append(v_l[i])
                v_l[i] = mon
        else:
            if v_l[i] != men:
                v_l_even_diff.append(v_l[i])
                v_l[i] = men

    if len(set(v_l)) != 1:
        print(len(v_l_odd_diff) + len(v_l_even_diff))
        exit()
    else:
        times = times + 1
        v_l = v_l_bk

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
n = N // 2

index = 0
g_inputs = []
k_inputs = []

for i in input().split():
    if index % 2 == 0:
        g_inputs.append(int(i))
        index += 1
    else:
        k_inputs.append(int(i))
        index += 1

g = Counter(g_inputs)
k = Counter(k_inputs)

g_max = max([(v,k) for k,v in g.items()])[1] 
k_max = max([(v,k) for k,v in k.items()])[1]

if g_max == k_max:
    if g[g_max] < k[k_max]:
        del g[g_max]
        g_max = max([(v,k) for k,v in g.items()])[1]
        print(N - g[g_max] - k[k_max])
    elif g[g_max] > k[k_max]:
        del k[k_max]
        k_max = max([(v,k) for k,v in k.items()])[1]
        print(N - g[g_max] - k[k_max])
    else:
        del g[g_max]
        del k[k_max]
        if len(g) == 0 and len(k) == 0:
            print(n)
        if len(g) != 0 and len(k) == 0:
            print(n - g[max([(v,k) for k,v in g.items()])[1]])
        if len(g) == 0 and len(k) != 0:
            print(n - k[max([(v,k) for k,v in k.items()])[1]])
        if len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            g_max = max([(v,k) for k,v in g.items()])[1]
            k_max = max([(v,k) for k,v in k.items()])[1]
            if g[g_max] < k[k_max]:
                print(n - k[k_max])
            elif g[g_max] > k[k_max]:
                print(n - g[g_max])
            else:
                print(N - g[g_max] - k[k_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v_o = []
v_e = []
ans = 0

if len(Counter(v)) == 1:
    ans = len(v)//2
else:
    for i in range(len(v)):
        if (i+1)%2==1:
            v_o.append(v[i])
        else:
            v_e.append(v[i])

    o_values = list(Counter(v_o).values())
    o_values.sort(reverse=True)
    e_values = list(Counter(v_e).values())
    e_values.sort(reverse=True)

    for o in range(len(o_values)):
        ans += o_values[o]
    ans = ans - o_values[0]

    for e in range(len(e_values)):
        ans += e_values[e]
    ans = ans - e_values[0]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
gu = []
ki = []
ans = 0
k,g = False,False
if v.count(v[0]) == len(v):
    ans += len(v) // 2
else:
    for i, v in enumerate(v,1):
        if i % 2 == 1:
            ki.append(v)
        else:
            gu.append(v)

    kic = Counter(ki)
    guc = Counter(gu)
    k1 = kic.most_common(1)[0]
    g1 = guc.most_common(1)[0]
    if k1 == g1:
        if kic[k1] < guc[g1]:
            k = True
        else:
            g = True
    kic = list(kic.values())
    guc = list(guc.values())
    kic.sort(reverse = True)
    guc.sort(reverse = True)
    if len(kic) != 1:
        if k:
            ans += kic[0]
            ans += sum(kic[2::])
        else:
            ans += sum(kic[1::]) 
    if len(guc) != 1:
        if g:
            ans += guc[0]
            ans += sum(guc[2::])
        else:
            ans += sum(guc[1::])
print(ans)

Submission status: Wrong Answer

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 len(odds) == 1 and len(evens) == 1:
        ans = odds[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: Wrong Answer

Solution code:
n = int(input())

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

v1 = {}

v2 = {}

for i in range(n//2):
    if  v[2 *i +1] in v1.keys():
        v1[v[2 * i +1]] += 1
    else:
        v1[v[2 * i + 1]] = 1

    if v[2 * i] in v2.keys():
        v2[v[2 * i]] += 1
    else:
        v2[v[2 * i]] = 1


v1 = sorted(v1.items(),key=lambda x: - x[0])
v2 = sorted(v2.items(),key=lambda x: - x[0])
v1.reverse()
v2.reverse()
v1.append((None,0))
v2.append((None,0))
#print(v1)
if v1[0][0] == v2[0][0]:
    ans = max(v1[0][1]+v2[1][1] , v1[1][1] + v2[0][1])
else:
    ans = v1[0][1] + v2[0][1]

print(n - ans)

Submission status: Wrong Answer

Solution code:
#Bad_Beast
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1:
    print(int(n/2))
    
else:
    cur1=a[0]
    cur2=a[1]
    i=0
    t=True
    while i<n:
        if a[i]!=cur1:
            t=False
            break
        if a[i+1]!=cur2:
            t=False
            break
        i+=1
    if t:
        print(0)
        
    else:    
        i=0
        oc=[0]*100005
        for i in range(n):
            oc[a[i]]+=1
        m=0    
        cur1=0
        cur2=0
        for i in range(100005):
            if oc[i]>m:
                m=oc[i]
                cur1=i
        oc[cur1]=0
        m=0
        for i in range(100005):
            if oc[i]>m:
                m=oc[i]
                cur2=i
        ind1=100005
        ind2=100005
        for i in range(n):
            if a[i]==cur1:
                if i<ind1:
                    ind1=i
                
            elif a[i]==cur2:
                if i<ind2   : 
                    ind2=i
        #print(ind1,ind2)
        if ind1>ind2:
            total=0
            i=0
            while i<n:
                if a[i]!=cur2:
                    total+=1
                if a[i+1]!=cur1:
                    total+=1
                i+=2    
            print(total)
        elif ind1<ind2:
            total=0
            i=0
            while i<n:
                
                if a[i]!=cur1:
                    total+=1
                if a[i+1]!=cur2:
                    total+=1
                i+=2 
            print(total)