Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
import collections
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])
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]
    
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)
  elif max_even <= max_odd:
    if max_odd == second_odd:
      print(int(n) - max_odd - max_even)
    else:
      print(int(n) - max_odd - second_even)
  else : 
    if second_odd > second_even:
      print(int(n) - max_even - second_odd)
    else :
      print(int(n) - max_odd - second_even)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
list = input().split(" ")
array = [int(s) for s in list]
even = []
odd = []
for i in range(n):
  num = array[i]
  if i % 2 == 0:
    even.append(num)
  else:
    odd.append(num)
e = collections.Counter(even)
o = collections.Counter(odd)
e_max = e.most_common()[0][0]
o_max = o.most_common()[0][0]
if even == odd:
  count = len(even)
  print(count)
  exit()
elif e_max == o_max:
  if e.most_common()[1][1] <= o.most_common()[1][1]:
    o_max = o.most_common()[1][1]
  else:
    e_max = e.most_common()[1][1] 
sol = [] 
for i in even:
  if i != e_max:
    sol.append(1)
for i in odd:
  if i != o_max:
    sol.append(1)
ans = len(sol)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
MAX = 100001
li = input().split(" ")
el = []
ol = []
for i in range(n):
    if i % 2 == 0:
        el.append(int(li[i]))
    else:
        ol.append(int(li[i]))
n_el = len(list(set(el)))
n_ol = len(list(set(ol)))
if n_el == 1 and n_ol == 1 and el[0] != ol[0]:
    print(0)
elif n_el == 1 and n_ol == 1 and el[0] == ol[0]:
    print(len(ol))
else:
    kinds = sorted(list(set(li)))
    nums = [[0,0] for i in range(MAX)]
    for e in el:
        nums[e][0] += 1
    for o in ol:
        nums[o][1] += 1
    costs = [[0,0] for i in range(MAX)]
    for i in range(MAX):
        costs[i] = [n//2 - nums[i][0], n//2 - nums[i][1]]
    index_e = []
    index_o = []
    min_e = 1000000
    min_o = 1000000
    for i in range(MAX):
        if min_e > costs[i][0]:
            min_e = costs[i][0]
            index_e = [i]
        elif min_e == costs[i][0]:
            index_e.append(i)
        if min_o > costs[i][1]:
            min_o = costs[i][1]
            index_o = [i]
        elif min_o == costs[i][1]:
            index_o.append(i)
    ans_temp = 1000000
    
    # e が最小だったら
    temp_cost_e = []
    for j in range(MAX):
        temp_cost_e.append(costs[j][1])
    for i in index_e:
        temp_cost = copy.deepcopy(temp_cost_e)
        temp_cost[i] = 999999
        tete = min_e + min(temp_cost)
        if tete < ans_temp:
            ans_temp = tete
    temp_cost_o = []
    for j in range(MAX):
        temp_cost_o.append(costs[j][1])
    for i in index_o:
        temp_cost = copy.deepcopy(temp_cost_o)
        temp_cost[i] = 999999
        tete = min_o + min(temp_cost)
        if tete < ans_temp:
            ans_temp = tete
    print(ans_temp)

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)+100)]
cc = [0 for i in range(pow(10,5)+100)]
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
k = 0
kk = 0
for i in range(len(c)):
    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:
#! /usr/bin/python3
from collections import Counter
import sys

def debug(*f):
    print(*f, file=sys.stderr)

def f(odd, even, N):
    debug(N, odd, even)


def main(N, V):
    debug("N=",N)
    debug("V=",V)
    N = int(N)
    V = [int(x) for x in V.split(" ")]

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

    if odd[0][0] != even[0][0]: # 異なる文字
        return N - odd[0][1] - even[0][1]
    else:
        if odd[0][1] > even[0][1]:
            return N - odd[0][1] - even[1][1]
        elif odd[0][1] < even[0][1]:
            return N - odd[1][1] - even[0][1]
        elif odd[0][1] == N // 2:
            return N // 2
        else:
            return N - odd[0][1]  - max(odd[1][1], even[1][1])



if 0==1:
    import sys
    assert main("4", "3 1 3 2") == 1
    assert main("4", "1 1 1 1") == 2
    assert main("6", "105 119 105 119 105 119") == 0
    assert main("14", "1 1 1 1 1 1 2 2 2 2 3 4 3 5") == 9

    print("OK", file=sys.stderr)


N = input()
V = input()
main(N, V)

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[1])

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

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

cv1 = collections.Counter(v[::2])
cv2 = collections.Counter(v[1::2])
num1 = cv1.most_common()[0][0]
num2 = cv2.most_common()[0][0]
cnt1 = cv1.most_common()[0][1]
cnt2 = cv2.most_common()[0][1]

if num1==num2:
  temp1 = cv1.most_common()[1][1]
  temp2 = cv2.most_common()[1][1]
  
  if cnt1+temp1>cnt2+temp2:
    cnt2 = temp2
  else:
    cnt1 = temp1

print(n-(cnt1+cnt2))

Submission status: Wrong Answer

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

A=[[0,i] for i in range(10**5+3)]
B=[[0,i] for i in range(10**5+3)]

for i in range(0,n,2):
    A[V[i]][0]+=1
for i in range(1,n,2):
    B[V[i]][0]+=1

A.sort(reverse=1)
B.sort(reverse=1)

#print(A[:10])
#print(B[:10])

Ma=[]
Mb=[]

ma=A[0][0]
mb=B[0][0]
i=0
j=0
while A[i][0]==ma :
    Ma.append(A[i][1])
    i+=1

while B[j][0]==mb :
    Mb.append(B[j][1])
    j+=1

if Ma==Mb :
    print(min(n-ma-B[j][0],n-mb-A[i][0],n-1))
else :
    print(n-ma-mb)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
count = len(set(v))
if count == 2:
    print(0)
else:
    if n % 2 != 0:
        print(n-2)
    else :
        print(n-2+1)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
num_list = input().split()
m=1
num_list_1 = []
num_list_2 = []
for n in range(0, n, 2):
    num_list_1.append(num_list[n])
    num_list_2.append(num_list[n+1])
c_1 = collections.Counter(num_list_1)
c_2 = collections.Counter(num_list_2)

lib_1 = c_1.most_common()
lib_2 = c_2.most_common()
k = 0

z = len(lib_1)
for n in range(1,z):
    k += int(lib_1[n][1])

z = len(lib_2)
for n in range(1,z):
    k += int(lib_2[n][1])
    
if lib_1[0][0] != lib_2[0][0]:
    print(k)
else:
    if lib_1[0][1] >= lib_2[0][1]:
        print(k+lib_2[0][1])
    else:
        print(k+lib_1[0][1])

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:
    if len(list(set(y))) == 1 and x[0] == y[0]:
        print(len(x))
        exit()
    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:
from collections import Counter


def solve(V):
    odd = Counter()
    even = Counter()
    total = Counter()
    for i, c in enumerate(V):
        total.update([c])
        if i % 2 == 0:
            even.update([c])
        else:
            odd.update([c])

    total_max = total.most_common()[0]
    if total_max[1] == len(V):
        return len(V) / 2

    even_maxs = even.most_common(2)
    odd_maxs = odd.most_common(2)
    if len(odd_maxs) > 1:
        odd_max, odd_2nd_max = odd_maxs[0], odd_maxs[1]
    else:
        odd_max, odd_2nd_max = odd_maxs[0], None

    if len(even_maxs) > 1:
        even_max, even_2nd_max = even_maxs[0], even_maxs[1]
    else:
        even_max, even_2nd_max = even_maxs[0], None

    ans = 0
    if odd_max[0] != even_max[0]:
        odd_max = odd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max != None and even_2nd_max == None:
        odd_max = odd_2nd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max == None and even_2nd_max != None:
        odd_max = odd_max[0]
        even_max = even_2nd_max[0]
    else:
        if even_2nd_max[0] == odd_2nd_max[0]:
            if odd_max[1] + even_2nd_max[1] > odd_2nd_max[1] + even_max[1]:
                odd_max = odd_max[0]
                even_max = even_2nd_max[0]
            else:
                odd_max = odd_2nd_max[0]
                even_max = even_max[0]
        else:
            odd_max = odd_2nd_max[0]
            even_max = even_2nd_max[0]

    for key, count in even.items():
        if key != even_max:
            ans += count
    for key, count in odd.items():
        if key != odd_max:
            ans += count
    return ans


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
from collections import Counter
 
n = int(input())
li = [int(x) for x in input().split()]
li_o = [li[i] for i in range(n) if i%2==0]
li_e = [li[i] for i in range(n) if i%2!=0]
 
if li_o == li_e:
    print(len(li_o))
else:
    val_o = Counter(li_o).most_common()[0][0]
    val_e = Counter(li_e).most_common()[0][0]
    if val_o == val_e:
        val_oo = Counter(li_o).most_common()[1][0]
        val_ee = Counter(li_e).most_common()[1][0]
        if val_oo > val_ee:
            val_o2 = len(li_o) - li_o.count(val_o)
            val_e2 = len(li_e) - li_e.count(val_ee)
        elif val_oo < val_ee:
            val_o2 = len(li_o) - li_o.count(val_oo)
            val_e2 = len(li_e) - li_e.count(val_e)
    else:
        val_o2 = len(li_o) - li_o.count(val_o)
        val_e2 = len(li_e) - li_e.count(val_e)

    print(val_o2 + val_e2)

Submission status: Wrong Answer

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

def w2(x):
    return x[::2], x[1:][::2]

def isnnn(x):
    return len(set(x))==2 and len(set(x[::2]))==1 and len(set(x[1:][::2]))==1

def sa(v):
    vd = {}
    for i in v:
        if i in vd:
            vd[i] += 1
        else:
            vd[i] = 1
    max_k = max(vd, key=vd.get)
    return max_k, len(v) - vd[max_k]

if isnnn(vs):
    print(0)
elif len(set(vs))==1:
    print(int(len(vs)/2))
else:
    v1, v2 = w2(vs)
    v1_k, sa1 = sa(v1)
    v2_k, sa2 = sa(v2)
    if v1_k != v2_k:
        print(sa1+sa2)
    elif sa1 > sa2:
        v1_s = list(filter(lambda x: x != v1_k, v1))
        v1_k2, sa12 = sa(v1_s)
        print(sa12+sa2+v1.count(v1_k))
    else:
        v2_s = list(filter(lambda x: x != v2_k, v2))
        v2_k2, sa22 = sa(v2_s)
        print(sa1+sa22+v2.count(v2_k))

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)+100)]
cc = [0 for i in range(pow(10,5)+100)]
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
k = 0
kk = 0
for i in range(len(c)):
    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:
dumyy = input()
A = list(map(int, input().split()))
A_odd =[]
A_eve =[]
for i, a in enumerate(A):
    i += 1
    if i % 2 == 1:
        # 奇数番目のリスト
        A_odd.append(a)
    else:
        # 偶数番目のリスト
        A_eve.append(a)

# 奇数列の数値出現数
odd_cnt = {}
for x in A_odd:
    if x in odd_cnt:
        odd_cnt[x] += 1
    else:
        odd_cnt[x] = 1

# 偶数列の数値出現数
eve_cnt = {}
for x in A_eve:
    if x in eve_cnt:
        eve_cnt[x] += 1
    else:
        eve_cnt[x] = 1

# 奇数列の最多出現数値
odd_max_key = max(odd_cnt, key=odd_cnt.get)
# 奇数列の最多出現数値の個数
odd_max_key_cnt = max(odd_cnt.values())
# 偶数列の最多出現数値
eve_max_key = max(eve_cnt, key=eve_cnt.get)
# 偶数列の最多出現数値の個数
eve_max_key_cnt = max(eve_cnt.values())

#print('偶数列の最多出現は', odd_max_key, "出現個数は", odd_max_key_cnt)
#print('奇数列の最多出現は', eve_max_key, "出現個数は", eve_max_key_cnt)

# 偶数番目と奇数番目が同じ場合も考慮

# 奇数列を0,1,2・・・にした場合の最小操作回数を出す
odd_min_cnt = {}
eve_min_cnt = {}
for x in range(0, 10):
    odd_min_cnt[x] = len(A_odd) - A_odd.count(x)
    eve_min_cnt[x] = len(A_eve) - A_eve.count(x)

#print(odd_min_cnt)
#print(eve_min_cnt)

ans = min(odd_min_cnt.values()) + min(eve_min_cnt.values())
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

n = int(raw_input())
v = raw_input().split(" ")

dict = {}
for i in v:
    if i in dict.keys():
        dict[i] += 1
    else:
        dict[i] = 1

#全て同じ数のときは全体を2で割ればいい
if len(dict) == 1:
    print n / 2
    sys.exit()



counts = []
for i in range(0, len(dict) - 1):
    a1 = dict.keys()[i]
    for j in range(i + 1, len(dict)):
        a2 = dict.keys()[j]

        #網羅的に調べる
        count = 0
        for k in range(0, n):
            if k % 2 == 0:  # 奇数番のとき
                if v[k] != a1:
                    count += 1
            if k % 2 == 1:
                if v[k] != a2:
                    count += 1
        if count == 0:
            print 0
            sys.exit()

        counts.append(count)



print min(counts)

Submission status: Wrong Answer

Solution code:
# c

from collections import Counter

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

odd = a[::2]
even = a[1::2]
#print(odd,even)

cnt_odd = Counter(odd)
cnt_even = Counter(even)

if odd==even: print(N//2)
elif len(cnt_odd)==1:
    for i,key in enumerate(cnt_odd):
        ko = key
    ve = sorted(cnt_even.values())[-1]
    if cnt_even[ko]!=ve:
        print(N//2 - sorted(cnt_even.values())[-1])
    else: print(N//2 - sorted(cnt_even.values())[-2])

elif len(cnt_even)==1:
    for i,key in enumerate(cnt_even):
        ke = key
    vo = sorted(cnt_odd.values())[-1]
    if cnt_odd[ke]!=vo:
        print(N//2 - sorted(cnt_odd.values())[-1])
    else: print(N//2 - sorted(cnt_odd.values())[-2])

else:
    vo1 = sorted(cnt_odd.values())[-1]
    vo2 = sorted(cnt_odd.values())[-2]
    ve1 = sorted(cnt_even.values())[-1]
    ve2 = sorted(cnt_even.values())[-2]
    for i,key in enumerate(cnt_odd):
        if cnt_odd[key]==vo1: ko1 = key
    for i,key in enumerate(cnt_odd):
        if cnt_odd[key]==vo2: ko2 = key
    for i,key in enumerate(cnt_even):
        if cnt_even[key]==ve1: ke1 = key
    for i,key in enumerate(cnt_even):
        if cnt_even[key]==ve2: ke2 = key
    if ko1!=ke1: print(N - sorted(cnt_odd.values())[-1] - sorted(cnt_even.values())[-1])
    else:
        ans1 = N - sorted(cnt_odd.values())[-1] - sorted(cnt_even.values())[-2]
        ans2 = N - sorted(cnt_odd.values())[-2] - sorted(cnt_even.values())[-1]
        print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
m = input().split(" ")
li = [int(i) for i in m]
li_0 = [k for ix, k in enumerate(li) if ix%2 == 0]
li_1 = [k for ix, k in enumerate(li) if ix%2 == 1]

#li_0
se_0 = set(li_0)
li_02 = list(se_0) 
s0 = []
for i in range(len(li_02)):
    c = li_0.count(li_02[i])
    s0.append(c)
s0.sort()
change_0 = sum(s0) - s0[-1]

#li_1
se_1 = set(li_1)
li_12 = list(se_1) 
s1 = []
for i in range(len(li_12)):
    c = li_1.count(li_12[i])
    s1.append(c)
s1.sort()
change_1 = sum(s1) - s1[-1]

print(change_0 + change_1)

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:
    if len(list(set(y))) == 1:
        print(len(x))
        exit()
    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:
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
e = []
o = []
for i, a in enumerate(v):
    if i % 2:
        o.append(a)
    else:
        e.append(a)
oc = Counter(o)
ec = Counter(e)
h = n//2
ans = h

a = []
for i, (k, v) in enumerate(oc.most_common()):
    if not v in a:
        a.append(v)
    if len(a) >= 3:
        break
a = []
for j, (k, v) in enumerate(ec.most_common()):
    if not v in a:
        a.append(v)
    if len(a) >= 3:
        break
for k, v in oc.most_common(i+1):
    for k2, v2 in ec.most_common(j+1):
        if k == k2:
            continue
        ans = min(ans, h - v + h - v2)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = []
b = []
for i, x in enumerate(al):
    if i%2 == 0:
        a.append(x)
    else:
        b.append(x)

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

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) >= 2 and ac[0][1] == ac[1][1]:
        print(n-ac[0][1]-bc[0][1])
    elif len(bc) >= 2 and bc[0][1] == bc[1][1]:
        print(n-ac[0][1]-bc[0][1])
        
    elif ac[0][1] >= bc[0][1]:
        if len(bc) <= 1:
            print(n-ac[0][1])
        else:
            print(n-ac[0][1]-bc[1][1])
    else:
        if len(ac) <= 1:
            print(n-bc[0][1])
        else:
            print(n-ac[1][1]-bc[0][1])

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:
                if num != pattern1:
                    pattern2 = num
                    continue
                else:
                    cnt += 1
            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:
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]
v_0 = v[0::2]
v_1 = v[1::2]
ans = 0

c0 = Counter(v_0)
c1 = Counter(v_1)

# もしMAXが両方同じ整数なら
if c0.most_common(1)[0][0] == c1.most_common(1)[0][0]:
    # v_0の方がカウントが大きい
    if c0.most_common(1)[0][1] > c1.most_common(1)[0][1]:
        c0[c0.most_common(1)[0][0]] = 0
        if len(c1) != 1:
            c1[c1.most_common(2)[1][0]] = 0

    else:
        if len(c1) != 1:
            c0[c0.most_common(2)[1][0]] = 0
        c1[c1.most_common(1)[0][0]] = 0
else:
    c0[c0.most_common(1)[0][0]] = 0
    c1[c1.most_common(1)[0][0]] = 0

ans += sum(c0.values())
ans += sum(c1.values())

print(ans)

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] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    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 as cl

n=int(input())
vlist=list(input().split())

vg=vlist[0::2]
vk=vlist[1::2]

vgcnt=cl.Counter(vg)
vkcnt=cl.Counter(vk)

vgmax=max(vgcnt,key=vgcnt.get)
vkmax=max(vkcnt,key=vkcnt.get)

if vgmax==vkmax:
    if vgcnt[vgmax]<vkcnt[vkmax]:
        vgcnt.pop(vgmax)
        if len(vgcnt)>0:
            vgmax=max(vgcnt)
        else:
            vgmax='a'
    else:
        vkcnt.pop(vkmax)
        if len(vkcnt)>0:
            vkmax=max(vkcnt)
        else:
            vkmax='a'

ans=0
for i in range(len(vg)):
    if vg[i]!=vgmax:
        ans+=1
for i in range(len(vk)):
    if vk[i]!=vkmax:
        ans+=1

print(ans)

Submission status: Wrong Answer

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

def check(odd,even):
    if odd != even:
        odd_d = collections.Counter(odd)
        even_d = collections.Counter(even)
        if len(odd_d) == 1 and len(even_d) == 1:
            return True
    return False

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

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


ans = 0
tmp_odd = odd
tmp_even = even

ch = 0
while not(check(tmp_odd,tmp_even)):
    odd_d = {}
    even_d = {}
    odd_d = collections.Counter(odd)
    even_d = collections.Counter(even)

    for i,n in enumerate(odd_d.keys()):
        if i == 0:
            odd_ind = n
        elif i == 1 and ch == 1:
            odd_ind = n
        else:
            break
    for i, n in enumerate(even_d.keys()):
        if i == 0:
            even_ind = n
        elif i == 1 and ch == 2:
            even_ind = n
        else:
            break

    tmp_odd,tmp_even = [],[]
    ans = N - odd_d[odd_ind] - even_d[even_ind]
    tmo_odd = [odd_d[odd_ind] if i != odd_d[odd_ind] else i for i in odd]
    tmp_even = [even_d[even_ind] if i != even_d[even_ind] else i for i in even]

    if ch == 0:
        ch = 1
    elif ch == 1:
        ch = 2
    else:
        break
print(ans)


# if odd == even and len(odd_d) == 1 and len(even_d) == 1:
#     ans = len(odd)

# elif len(odd_d) == 1 and len(even_d) == 1:
#     ans = 0

# else:
#     for i,n in enumerate(odd_d.keys()):
#         if i == 0:
#             odd_ind = n
#         elif i == 1:
#             odd_ind2 = n
#         else:
#             break
#     for i, n in enumerate(even_d.keys()):
#         if i == 0:
#             even_ind = n
#         elif i == 1:
#             even_ind2 = n
#         else:
#             break

#     if odd_ind != even_ind:
#         ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind])
#     else:
#         if odd_d[odd_ind] == odd_d[odd_ind2] or even_d[even_ind] == even_d[even_ind2]:
#             ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind])
#         elif odd_d[odd_ind] >= even_d[even_ind]:
#             ans = (N//2 - odd_d[odd_ind]) + (N//2 - even_d[even_ind2])
#         else:
#             ans = (N//2 - odd_d[odd_ind2]) + (N//2 - even_d[even_ind])
# print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
list = input().split(" ")
array = [int(s) for s in list]
even = []
odd = []
for i in range(n):
  num = array[i]
  if i % 2 == 0:
    even.append(num)
  else:
    odd.append(num)
e = collections.Counter(even)
o = collections.Counter(odd)
e_max = e.most_common()[0][0]
o_max = o.most_common()[0][0]
if even == odd:
  count = len(even)
  print(count)
  exit()
elif e_max == o_max:
  if e.most_common()[1][1] <= o.most_common()[1][1]:
    o_max = o.most_common()[1][1]
  else:
    e_max = e.most_common()[1][1] 
sol = [] 
for i in even:
  if i != e_max:
    sol.append(1)
for i in odd:
  if i != o_max:
    sol.append(1)
ans = len(sol)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=[]
for li in input().split():
  v.append(li)

c1=[]
c2=[]
i=1
while i <= n:
  c1.append(v[i-1])
  i+=2
  
i=2
while i <= n:
 
  c2.append(v[i-1])
  i+=2

import collections

a1 = collections.Counter(c1)
a2 = collections.Counter(c2)

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

if d1[0][0] == d2[0][0]:
  if d1[0][1] >= d2[0][1]:
    if len(d2) >1: 
      N=n-d1[0][1]-d2[1][1]
    else:
      N=n-d1[0][1]
  else :
    if len(d1)>1:
      N=n-d1[1][1]-d2[0][1]
    else:
      N=n-d2[0][1]
else:
  N=n-d1[0][1]-d2[0][1]
print(N)

Submission status: Wrong Answer

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


def main():
    from collections import Counter

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

    if len(set(v)) == 1:
        print(half)
        exit()
    else:
        even = Counter(v[::2]).most_common(1)[0][0]
        odd = Counter(v[1::2]).most_common(1)[0][0]
        ans1 = 0

        for i in range(2, n):
            if i % 2 == 0:
                if v[i] != even:
                    ans1 += 1
            else:
                if v[i] != odd:
                    ans1 += 1

        print(ans1)


if __name__ == '__main__':
    main()

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()[1][1] + e.most_common()[0][1] > o.most_common()[0][1] + e.most_common()[1][1]:
        maxevencnt = e.most_common()[1][1]
    elif o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxoddcnt = o.most_common()[1][1]

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

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[0] == g1[0]:
        if k1[1] < g1[1]:
            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:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+100)]
cc = [0 for i in range(pow(10,5)+100)]
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
k = 0
kk = 0
for i in range(d+10):
    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())
V=list(map(int,input().split()))

A=[[0,i] for i in range(10**5+3)]
B=[[0,i] for i in range(10**5+3)]

for i in range(0,n,2):
    A[V[i]][0]+=1
for i in range(1,n,2):
    B[V[i]][0]+=1

A.sort(reverse=1)
B.sort(reverse=1)

#print(A[:10])
#print(B[:10])

Ma=[]
Mb=[]

ma=A[0][0]
mb=B[0][0]
i=0
j=0
while A[i][0]==ma :
    Ma.append(A[i][1])
    i+=1

while B[j][0]==mb :
    Mb.append(B[j][1])
    j+=1

if Ma==Mb :
    print(min(n-ma-B[j][0],n-mb-A[i][0]))
else :
    print(n-ma-mb)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

even = dict()
even_rev = dict()
odd = dict()
odd_rev = dict()

# マップ作成
for i, c in enumerate(a):
    if i%2 == 0:
        if c in even:
            even[c] += 1
        else:
            even[c] = 1
    else:
        if c in odd:
            odd[c] += 1
        else:
            odd[c] = 1

for k, v in sorted(even.items(), key=lambda x:x[1]):
    even_rev[v] = k

for k, v in sorted(odd.items(), key=lambda x:x[1]):
    odd_rev[v] = k

flg = False
for even_x in even_rev:
    for odd_x in odd_rev:
        if even_rev[even_x] == odd_rev[odd_x]:
            pass
        else:
            kotae = n - even_x - odd_x
            flg = True
    if(flg):
        break

if(flg)==False:
    kotae = int(n/2) 


print(kotae)