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 math,sys,copy

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

if len(list(set(v))) == 1:
	print(math.floor(n/2))
	sys.exit()

e = [0]*(max(v)+1)
o = [0]*(max(v)+1)
for i, x in enumerate(v):
	if i % 2 == 0: # 1,3,5,....
		o[x] += 1
	else: # 2,4,6,...
		e[x] += 1

o_ = o[1:]

om = max(o_)

i = o_.index(max(o_))

t = copy.deepcopy(e)

t.pop(i+1)
if type(t) is int:
	t = [t]
em = max(t)

print(sum(o) + sum(e) - om - em)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
v=list(input().split())
k=v[0::2]
g=v[1::2]

c1 = collections.Counter(k)
c2 = collections.Counter(g)

res1 = n/2 - c1.most_common()[0][1]
res2 = n/2 - c2.most_common()[0][1]

if c1.most_common()[0][0] == c2.most_common()[0][0]:
    if(c1.most_common()[0][1] > c2.most_common()[0][1]):
        res2 = n/2 - c2.most_common()[1][1]
    elif(c1.most_common()[0][1] < c2.most_common()[0][1]):
        res1 = n/2 - c1.most_common()[1][1]
    else:
        if(res1 > 0):
            res1 = n/2 - c1.most_common()[1][1]
print(int(res1+res2))

Submission status: Wrong Answer

Solution code:
def cal(n,v):
    k=n//2
    even=range(0,2*k,2)
    odd=range(1,2*k+1,2)

    el=[]
    for i in even:
        el.append(v[i])
    ol=[]
    for i in odd:
        ol.append(v[i])

    d={}
    for i in el:
        if((i in d)is False ):
            d[i]=0
        else:
            d[i]+=1

    f={}
    for i in ol:
        if((i in f)is False ):
            f[i]=0
        else:
            f[i]+=1

    while(True):
        e = max(d, key=d.get)
        o = max(f, key=f.get)
        if(e==o):
            if(d[e]>f[o]):
                del f[o]
            elif(d[e]<f[o]):
                del d[e]
            else:
                return print(k)
        else:
            break

    sum=0
    for i in el:
        if(i!=e):
            sum+=1
    for i in ol:
        if(i!=o):
            sum+=1
    return print(sum)

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

v1 = [v for i,v in enumerate(vl) if i%2 ==0]
v2 = [v for i,v in enumerate(vl) if i%2 ==1]

table1 = {}
table2 = {}

for x in v1:
    table1.setdefault(x,0)
    table1[x] += 1

for x in v2:
    table2.setdefault(x,0)
    table2[x] += 1

v1 = [(k,table1[k]) for k in table1]
v2 = [(k,table2[k]) for k in table2]

v1 = sorted(v1,key= lambda v: v[1],reverse=True)
v2 = sorted(v2,key= lambda v: v[1],reverse=True)

size= int(n/2)
ans=0
if v1[0][0] != v2[0][0]:
    ans += size - v1[0][1]
    ans += size - v2[0][1]
else:
    if len(v1) == 1 and len(v2) == 1:
        print(size)
        exit()
    elif len(v1) == 1 and len(v2) != 1:
        print(size - v2[1][1])
        exit()
    elif len(v1) != 1 and len(v2) == 1:
        print(size - v1[1][1])
        exit()   


    if v1[1][1] == v1[0][1] or v2[1][1] == v2[0][1]:
        ans += size - v1[0][1]
        ans += size - v2[0][1]
    elif v1[1][0] < v2[1][0]:
        ans += size - v1[0][1]
        ans += size - v2[1][1]
    else:
        ans += size - v1[1][1]
        ans += size - v2[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
V=list(map(int, input().split(" ")))
d1=[0 for i in range(100000)]
for i in V[::2]:
    d1[i-1]+=1
d2=[0 for i in range(100000)]
for i in V[1::2]:
    d2[i-1]+=1

m1=max(d1)
m2=max(d2)
maxind1 = [i for i, x in enumerate(d1) if x == m1]
maxind2 = [i for i, x in enumerate(d2) if x == m2]

#in1=d1.index(max(d1))
#in2=d2.index(max(d2))

if maxind1[0] == maxind2[0]:
    if (len(maxind1) == 1) and (len(maxind2) == 1):
        if m1>m2:
            d2[maxind2[0]]=0
        else:
            d1[maxind1[0]]=0

#print(d1[:5])
#print(d2[:5])
tmp1=n/2-max(d1)
tmp2=n/2-max(d2)
print(int(tmp1+tmp2))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())

array = list(map(int, input().split()))
array_0 = collections.Counter(array[::2]).most_common()
array_1 = collections.Counter(array[1::2]).most_common()

array_0_v = array_0[0][0]
array_1_v = array_1[0][0]

if array_0_v == array_1_v:
    if array_0[0][1] > array_1[0][1]:
        if len(array_1) > 1:
            array_1_v = array_1[1][0]
        else:
            if array_0_v != 1:
                array_1_v = array_0_v - 1
            else:
                array_1_v = array_0_v + 1
    else:
        if len(array_0) > 1:
            array_0_v = array_0[1][0]
        else:
            if array_1_v != 1:
                array_0_v = array_1_v - 1
            else:
                array_0_v = array_1_v + 1
count = 0
for i in range(n // 2):
    if array[i * 2] != array_0_v:
        count += 1
    if array[i * 2 + 1] != array_1_v:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input()) 

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

o = {}
e = {}

for i in range(int(n / 2)):
    if v[2 * i] in o:
        o[v[2 * i]] += 1
    else:
        o[v[2 * i]] = 1
    if v[2 * i+1] in e:
        e[v[2 * i+1]] += 1
    else:
        e[v[2 * i+1]] = 1

if len(e) == 1 and len(o) == 1:
    if e.keys() == o.keys():
        print(int(n / 2))
    else:
        print(0)
else:
    if len(e) == 2 and len(o) == 2:
        if e.keys() == o.keys():
            if max(e.values()) > max(o.values()):
                l = min(o.values())
                m = max(e.values())
                print(n - l - m)
            else:
                l = min(e.values())
                m = max(o.values())
                print(n - l - m)
    else:
        l = max(o.values())
        m = max(e.values())
        print(n-l-m)

Submission status: Wrong Answer

Solution code:
import numpy as np
from string import ascii_lowercase

n = int(input())
v_ = map(int, input().split())
v = []
for val in v_:
	v.append(val)
v = np.array(v)

u = np.unique(v)
if len(u) < 2:
	print(2)
elif len(u) == 2:
	print(0)
else:
	u_hat = sorted(u)
	v_c = []

	for a in range(0, 11, 1):
		if sum(v==a) != 0:
			v_c.append(sum(v==a))
	print(sum(sorted(v_c, reverse=True)[2:]))

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python3
from collections import Counter


def main(N, 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] == N // 2:
            r = N // 2
            return r
        if odd[0][1] > even[0][1]:
            r = N - odd[0][1] - even[1][1]
            return r
        else:
            r = N - odd[1][1] - even[0][1]
            return r


if 1==0:
    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
    print("OK", file=sys.stderr)


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

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
A = []
B = []
Q = [0,0]
R = [0,0]
S = [0,0]
T = [0,0]
J = 1
K = 1
for i in range(n):
  if (i%2 == 0):
    A.append(L[i])
  else:
    B.append(L[i])
A.sort()
B.sort()
A.append(-1)
B.append(-1)
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J >= Q[0]):
      del Q[0]
      Q.insert(0,J)
      J = 1
      del R[0]
      R.insert(0,A[j-1])
      j += J
    elif (Q[0] >= J >= Q[1]):
      del Q[1]
      Q.append(J)
      J = 1
      del R[1]
      R.append(A[j-1])
      j += J
    else:
      J = 1
      j += J
for k in range(1,len(B)):
  if (B[k-1] == B[k]):
    K += 1
  else:
    if (K >= S[0]):
      del S[0]
      S.insert(0,K)
      K = 1
      del T[0]
      T.insert(0,B[k-1])
      k += K
    elif (S[0] >= J >= S[1]):
      del S[1]
      S.append(K)
      K = 1
      del T[1]
      T.append(B[k-1])
      k += K
    else:
      K = 1
      k += K
if (R[0] != T[0]):
  print(n-Q[0]-S[0])
else:
  if (Q[0] >= S[0]):
    print(n-Q[0]-S[1])
  else:
    print(n-S[0]-Q[1])

Submission status: Wrong Answer

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

a = set()
b = set()

for i in range(n):
    if i % 2 == 1:
        a.add(v[i])
for j in range(n):
    if j % 2 == 0:
        b.add(v[j])

if (len(a) == 1) and (len(b) == 1) and (a == b):
    print(n//2)
else:
    print(len(a) + len(b) -2)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__' :
    n = int(input())
    x = list(input().split())
    a = {}
    b = {}
    ai = 0
    bi = 0
    for i,t in enumerate(x):
        if i % 2 == 0:
            ai += 1
            if t in a:
                a[t] += 1
            else:
                a[t] = 1
        else:
            bi += 1
            if t in b:
                b[t] += 1
            else:
                b[t] = 1

    a_kv = max(a.items(), key=lambda x: x[1])
    b_kv = max(b.items(), key=lambda x: x[1])

    if a_kv[0] == b_kv[0]:
        if a_kv[1] > b_kv[1]:
            if bi - b_kv[1] == 0:
                print(bi)
            else:
                b.pop(b_kv[0])
                b_kv = max(b.items(), key=lambda x: x[1])
                print(ai-a_kv[1]+bi-b_kv[1])
        else:
            if ai - a_kv[1] == 0:
                print(ai)
            else:
                a.pop(a_kv[0])
                a_kv = max(a.items(), key=lambda x: x[1])
                print(ai-a_kv[1]+bi-b_kv[1])
    else:
        print(ai-a_kv[1]+bi-b_kv[1])

Submission status: Wrong Answer

Solution code:
import collections

n = int(raw_input())
v = map(int, raw_input().split())

even = [vi for i,vi in enumerate(v) if i % 2 == 0]
odd  = [vi for i,vi in enumerate(v) if i % 2 == 1]

evenc = collections.Counter(even)
oddc = collections.Counter(odd)

if evenc.most_common()[0][0] != oddc.most_common()[0][0]:
    res = len(set(even)) + len(set(odd)) - 2
    print(res)
else:
    if evenc.most_common()[0][1] >= oddc.most_common()[0][1]:
        a = len(even) - evenc.most_common()[0][1]
        b = len(odd)
        if len(oddc.most_common()) > 1:
            b = len(odd) - oddc.most_common()[1][1]
        print(a+b)
    elif evenc.most_common()[0][1] < oddc.most_common()[0][1]:
        a = len(odd) - oddc.most_common()[0][1]
        # evencc = collections.Counter(filter(lambda a: a != evenc.most_common()[0], even) )
        b = len(even)
        if len(evenc.most_common()) > 1:
            b = len(even) - evenc.most_common()[1][1]
        print(a+b)

Submission status: Wrong Answer

Solution code:
import collections

n = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)
print(odd_c)
print(even_c)
if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most)
    else:
        print(len(even) - even_next_most)
else:
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    if odd_change + even_change == 0:
        if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
            print(len(even))
            exit()
    print(odd_change + even_change)

Submission status: Wrong Answer

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]
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 v0cnt.most_common()[1] > v1cnt.most_common()[1]:
                ans = n - v0most[1] - v0cnt.most_common()[1][1]
            else:
                ans = n - v0most[1] - v1cnt.most_common()[1][1]            
    elif v0most[1] > v1most[1]:
        ans = n - v0most[1] - v1cnt.most_common()[1][1]
    else:
        ans = n - v1most[1] - v0cnt.most_common()[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)
ans = 0
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:
from collections import Counter

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

v1 = Counter(v[0::2]).most_common()
v2 = Counter(v[1::2]).most_common()

if len(v1)==1 and len(v2)==1:
    if v1[0]==v2[0]:
        print(v1[0][1])
    else:
        print(0)
else:
    c = 0
    if len(v1) >= 2:
        for i in v1[1:]:
            c += i[1]
    if len(v2) >= 2:
        for i in v2[1:]:
            c += i[1]
    print(c)

Submission status: Wrong Answer

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

kisuuSyuL=[]
kisuuKosuL=[]
gusuSyuL=[]
gusuKosuL=[]

index=0
beforeG=""
countG=0
beforeK=""
countK=0
while index < len(numberL):
    if index==0:
        beforeG=numberL[index]
        countG+=1
    elif index==1:
        beforeK=numberL[index]
        countK+=1
    else:
        if index%2==0:
            if beforeG== numberL[index]:
                countG+=1
            else:
                gusuSyuL.append(beforeG)
                gusuKosuL.append(countG)
                beforeG= numberL[index]
                countG=1
        else:
            if beforeK==numberL[index]:
                countK+=1
            else:
                kisuuSyuL.append(beforeK)
                kisuuKosuL.append(countK)
                beforeK=numberL[index]
                countK=1
    index+=1
gusuSyuL.append(beforeG)
gusuKosuL.append(countG)
kisuuSyuL.append(beforeK)
kisuuKosuL.append(countK)

if len(kisuuSyuL)==1 and len(gusuSyuL)==1:
    if kisuuSyuL[0]==gusuSyuL[0]:
        print(int(n/2))
    else:
        print(0)
else:
    kiIndex = kisuuKosuL.index(max(kisuuKosuL))
    guIndex = gusuKosuL.index(max(gusuKosuL))
    if kisuuSyuL[kiIndex]!=gusuSyuL[guIndex]:
        noC=max(kisuuKosuL)+max(gusuKosuL)
        print(n-noC)
    else:
        if max(kisuuKosuL) < max(gusuKosuL):
            kisuuKosuL.sort()
            noC=kisuuKosuL[len(kisuuKosuL)-1]+max(gusuKosuL)
            print(n-noC)
        else:
            gusuKosuL.sort()
            noC=gusuKosuL[len(gusuKosuL)-1]+max(kisuuKosuL)
            print(n-noC)

Submission status: Wrong Answer

Solution code:
a = int(input())
a2 = int(a/2)
b = list(map(int,input().split()))
c = []
d = []
e = 0
f = 0
for i in range(a):
    if i%2 == 0:
        c.append(b[i])
    else:
        d.append(b[i])
if c == d:
    print(int(a/2))
else:
    for i in range(a2):
        if i != 0:
            if c[0] != c[i]:
                e += 1
            if d[0] != d[i]:
                f += 1
    if e > int(a2/2):
        e = a2 - e
    if f > int(a2/2):
        f = a2 - f
    print(e+f)

Submission status: Wrong Answer

Solution code:
import collections

n = int(raw_input())
v = map(int, raw_input().split())

vo = v[1::2]
ve = v[::2]

number = 0

if len(set(v)) == 1:
	number = len(v) / 2
else:
	if len(set(vo)) != 1:
  		c = collections.Counter(vo)
  		number += len(vo) - max(c.values())
	if len(set(ve)) != 1:
  		c = collections.Counter(ve)
  		number += len(ve) - max(c.values())
  
print number

Submission status: Wrong Answer

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:
    max_odd_v = odd[max_odd]
    del(even[max_even])
    try:
        max_even = max(even, key=even.get)
        max_even_v = even[max_even]
    except:
        max_even_v = 0
else:
    max_odd_v = odd[max_odd]
    max_even_v = even[max_even]

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: 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)
    print(sa1+sa2)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(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])

count_odd = collections.Counter(v_odd)
count_even = collections.Counter(v_even)
temp_odd = list(count_odd.values())
temp_even = list(count_even.values())
# print(temp_odd)
# print(temp_even)
if list(count_even.keys())[0] != list(count_odd.keys())[0]:
    odd_sum = sum(temp_odd)-temp_odd[0]
    even_sum = sum(temp_even)-temp_even[0]
    print(odd_sum+even_sum)
else:
    if temp_odd[0]>=temp_even[0]:
        odd_sum = sum(temp_odd)-temp_odd[0]
        try:
            even_sum = sum(temp_even)-temp_even[1]
        except:
            even_sum = temp_even[0]
        print(odd_sum+even_sum)
    else:
        try:
            odd_sum = sum(temp_odd)-temp_odd[1]
        except:
            odd_sum = temp_odd[0]
        even_sum = sum(temp_even)-temp_even[0]
        print(odd_sum+even_sum)

Submission status: Wrong Answer

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

dd_even = defaultdict(int)
dd_odd  = defaultdict(int)

# 偶数番目のヒストグラムを作る
for i in range(0, n, 2):
    dd_even[v[i]] += 1

l_even = list(dd_even.items())
l_even.sort(key= lambda x:x[1])
top_even = l_even[-1][0]
#print(l_even)

# 奇数番目のヒストグラムを作る
for i in range(1, n, 2):
    dd_odd[v[i]] += 1

l_odd = list(dd_odd.items())
l_odd.sort(key= lambda x:x[1])
#print(l_odd)
top_odd = l_odd[-1][0]

if top_even == top_odd:
    if len(l_odd) == 1: # つまり全部同じ数字のとき
        res = int(n / 2)
        print(res)
        sys.exit()
    else:
        l_odd = [l for l in l_odd if l[0] != l_odd[-2][0]]

l_odd = [l for l in l_odd if l[0] != top_odd]
sum_odd = sum(l[1] for l in l_odd)
#print(l_odd, sum_odd)

l_even = [l for l in l_even if l[0] != top_even]
sum_even = sum(l[1] for l in l_even)
#print(l_even, sum_even)

res = sum_odd + sum_even
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

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

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

odd_d = collections.Counter(odd)
even_d = collections.Counter(even)

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] >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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

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


#a1とa2になる数を決める
for i in range(1, n, 2):
    a1 = v[0]
    a2 = v[i]
    if a1 == a2:
        continue

if a1 == a2: #全て同じ数のときは半分を変えればいい
    print n / 2
    sys.exit()


count = 0
for i in range(0, n):
    if i % 2 == 0: #奇数番のとき
        if v[i] != a1:
            count += 1
    if i % 2 == 1: #偶数番のとき
        if v[i] != a2:
            count += 1

print count

Submission status: Wrong Answer

Solution code:
#! /usr/bin/python3
from collections import Counter


def main(N, 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] == N // 2:
            r = N // 2
            print(r)
            return r
        if odd[0][1] > even[0][1]:
            r = N - odd[0][1] - even[1][1]
            print(r)
            return r
        else:
            r = N - odd[1][1] - even[0][1]
            print(r)
            return r


if 0==1:
    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


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

Submission status: Wrong Answer

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

# 配列で1番および2番目に登場する数を見つける
def find_most_common(array):
    second_max, scnt = 0, 0
    max_int, mcnt = 0, 0

    S = set(array)
    for s in S:
        res = array.count(s)
        if mcnt < res:
            second_int, sec_cnt = max_int, mcnt
            max_int, mcnt  = s, res

    return (max_int, mcnt, second_int, scnt)

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

vo1_val, vo1_cnt, vo2_val, vo2_cnt = find_most_common(v_odd)
ve1_val, ve1_cnt, ve2_val, ve2_cnt = find_most_common(v_even)

# 最大登場する数が同じ場合は登場回数が大きい方を採用して、少ない方は第２候補
if vo1_val == ve1_val:
    if vo1_cnt > ve1_cnt:
        result = (len(v_odd) - vo1_cnt) + (len(v_even) - ve2_cnt)
    else:
        result = (len(v_odd) - vo2_cnt) + (len(v_even) - ve1_cnt)
else:
    result = (len(v_odd) - vo1_cnt) + (len(v_even) - ve1_cnt)
print(result)

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 = len(odds)
    elif len(odds) == 1 and len(evens) != 1:
        ans = n - evens[1][1]
    elif len(odds) != 1 and len(evens) == 1:
        ans = n - odds[1][1]
    elif odds[0][1] >= evens[0][1]:
        ans = n - odds[0][1] - evens[1][1]
    else:
        ans = n - odds[1][1] - evens[0][1]
        
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
li = input().split()

a = 0
b = 0
c = 0
d = 0
e = 1
while a < N / 2:
    if li[a] != li[a + 2]:
        b += 1
    a += 1

while c < N:
    if li[c] == li[c + 1]:
        b += 1
    c += 2
while d < N:
    if N - d < 5:
        break
    else:
        if li[d] != li[d + 4]:
            b += 1
    d += 4

while e < N:
    if N - e < 5 :
        break
    else:
        if li[e] != li[e + 4]:
            b += 1
    e += 4


print(b)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d1={}
d2={}
r=len(a)
sum=0
maxs=0
maxs2=0
d1[maxs]=d2[maxs2]=0
for i in range(r):
    if i%2:
        if a[i] in d1:
            d1[a[i]]+=1
            if d1[a[i]]>d1[maxs]:
                maxs=a[i]
        else:
            d1[a[i]]=1
            sum+=1
            if d1[a[i]]>d1[maxs]:
                maxs=a[i]
    else:
        if a[i] in d2:
            d2[a[i]]+=1
            if d2[a[i]]>d2[maxs2]:
                maxs2=a[i]
        else:
            d2[a[i]]=1
            sum+=1
            if d2[a[i]]>d2[maxs2]:
                maxs2=a[i]
if maxs!=maxs2:
    print(n-d1[maxs]-d2[maxs2])
else:
    mmmm=0
    for i in d2:
        if i!=maxs2 and d2[i]>mmmm:
            mmmm=d2[i]
    print(n - d1[maxs] - mmmm)

Submission status: Wrong Answer

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

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

f1 = Counter(v1).most_common(2)
f2 = Counter(v2).most_common(2)

ans = 0

if len(set(v1)) == len(set(v2)) == 1:
    if v1 == v2:
        ans = len(v2)
else:
    if f1[0][0] != f2[0][0]:
        ans = (len(v1) - f1[0][1]) + (len(v2) - f2[0][1])
    else:
        if f1[0][1] > f2[0][1]:
            ans = (len(v1) - f1[0][1]) + (len(v2) - f2[1][1])
        else:
            ans = (len(v1) - f1[1][1]) + (len(v2) - f2[0][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.append((None,0))
v2.append((None,0))

ans = 0
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:
from collections import Counter

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

v_1 = []
v_2 = []

k = int(n / 2)

for i in range(k):
    s = (v[2*i])
    t = (v[2*i+1])
    v_1.append(s)
    v_2.append(t)

a = Counter(v_1)
a_1 = a.most_common(1)
a_2 = a_1[0][1]
b = Counter(v_2)
b_1 = b.most_common(1)
b_2 = b_1[0][1]
c = Counter(v)
c_1 = c.most_common(1)
c_2 = c_1[0][1]


if c_2 == n:
    print(k)
else:
    print(n - a_2 - b_2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
vn = list(map(int,input().split()))
v0 = [0]*(n//2)
v1 = [0]*(n//2)
for i in range(n//2):
  v0[i] = vn[i*2+0]
  v1[i] = vn[i*2+1]
v0 = Counter(v0)
v1 = Counter(v1)
v0c0 = v0.most_common()[0]
v1c0 = v1.most_common()[0]
v0c1 = [0,0] if (len(v0.most_common()) == 1) else v0.most_common()[1]
v1c1 = [0,0] if (len(v1.most_common()) == 1) else v1.most_common()[1]

if v0c0[0] != v1c0[0]:
  print(n-v0c0[1]-v1c0[1])
elif v0c0[1] < v1c0[1]:
  print(n-v0c1[1]-v1c0[1])
elif v0c0[1] > v1c0[1]:
  print(n-v0c0[1]-v1c1[1])
elif n-v0c1[1] > v1c1[1]:
  print(n-v0c1[1]-v1c0[1])
elif n-v0c1[1] < v1c1[1]:
  print(n-v0c0[1]-v1c1[1])
else:
  print(n-v0c0[1]-v1c1[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:
    print(int(n) - max_even - second_odd)
  else:
    print(int(n) - max_odd - second_even)

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
else:
    c = ce.most_common()[-1][1] + co.most_common()[-1][1]

print(c)

Submission status: Wrong Answer

Solution code:
import collections

def get_max_value(dict1, dict2):
    max_dict1=max(dict1, key=dict1.get)
    max_dict2=max(dict2, key=dict2.get)
    return max_dict1, max_dict2

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

if len(collections.Counter(a))==1:
    print(int(n/2))
else:
    a_even=[a[i] for i in range(0,n,2)]
    a_odd=[a[i]for i in range(1,n,2)]

    a_even_c=collections.Counter(a_even)
    a_odd_c=collections.Counter(a_odd)

    while(True):
        max_a_even, max_a_odd=get_max_value(a_even_c, a_odd_c)
        if max_a_even!=max_a_odd:
            replace_count=n-a_even_c[max_a_even]-a_odd_c[max_a_odd]
            break
        else:
            if a_even_c[max_a_even]>=a_odd_c[max_a_odd]:
                del a_odd_c[max_a_odd]
            else:
                del a_even_c[max_a_even]

    print(replace_count)

Submission status: Wrong Answer

Solution code:
import collections
n=input()
N=list(map(int,input().split(" ")))
list_odd=N[::2]
list_even=N[1::2]
c_odd = collections.Counter(list_odd)
c_even = collections.Counter(list_even)
most_odd=c_odd.most_common()[0][1]
most_even=c_even.most_common()[0][1]
if(c_odd.most_common()[0][0]==c_even.most_common()[0][0] and most_even==most_odd):
    print(most_odd)
else:
    print(len(list_even)+len(list_odd)-most_even-most_odd)