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

def calc(l):
    new_l = []
    adic = {}
    count = 0
    for c in l:
        if c in adic.keys():new_l.append(adic[c])
        else:
            new_l.append(count)
            adic[c] = count
            count += 1
    return new_l

def mink(lis):
    #print(lis)
    l = lis[0::2]
    m = lis[1::2]

    ls = [[i,0] for i in (set(l))]
    for d in l:
        for f in ls:
            if d == f[0]:
                f[1] += 1
    nls = sorted(ls, key=lambda x: x[1])
    ms = [[i,0] for i in (set(m))]
    for e in m:
        for g in ms:
            if e == g[0]:
                g[1] += 1
    nms = sorted(ms, key=lambda x: x[1])

    if len(nls) > 1:sfls = nls[1][1]
    else:sfls = - 1
    if len(nms) > 1:sfms = nms[1][1]
    else:sfms = - 1

    ll = len(l) - nls[0][1]
    mm = len(m) - nms[0][1]
    if nls[0][0] == nms[0][0]:
        if nls[0][1] > nms[0][1]:
            if len(nms)>1:mm =len(m)-nms[1][1]
            else:mm = len(m)
        elif nls[0][1] < nms[0][1]:
            if len(nls)>1:ll=len(l)-nls[1][1]
            else:ll=len(l)
        else: #==
            mm=len(m)-max(sfls,sfms)
            if mm>len(m):mm=len(m)
    print(ll+mm)

mink(calc(v))

Submission status: Wrong Answer

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

even = {}
odd = {}
for i, v in enumerate(V):
    if i % 2 == 0:
        if v not in even:
            even[v] = 0
        even[v] += 1
    else:
        if v not in odd:
            odd[v] = 0
        odd[v] += 1

sorted_even = sorted(even.items(), key=lambda x: x[1])
sorted_odd = sorted(odd.items(), key=lambda x: x[1], reverse=True)
if len(sorted_even) == 1:
    if len(sorted_odd) == 1:
        if sorted_even[0][0] == sorted_odd[0][0]:
            print(min(sorted_even[0][1], sorted_odd[0][1]))
        else:
            print(0)
    else:
        if sorted_even[0][0] == sorted_odd[0][0]:
            print(min(n - sorted_even[0][1], n - sorted_odd[0][1]))
        else:
            print(sorted_odd[1][1])
else:
    if len(sorted_odd) == 1:
        if sorted_even[0][0] == sorted_odd[0][0]:
            print(min(n - sorted_even[0][1], sorted_odd[0][1]))
        else:
            print(sorted_even[1][1])
    else:
        if sorted_even[0][0] == sorted_odd[0][0]:
            print(min(sorted_even[0][1] + sorted_odd[1][1], sorted_even[1][1] + sorted_odd[0][1]))
        else:
            print(n - sorted_even[0][1] + n - sorted_odd[0][1])

Submission status: Wrong Answer

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

even = {}
odd = {}
for i, v in enumerate(V):
    if i % 2 == 0:
        if v not in even:
            even[v] = 0
        even[v] += 1
    else:
        if v not in odd:
            odd[v] = 0
        odd[v] += 1

sorted_even = sorted(even.items(), key=lambda x: x[1])
sorted_odd = sorted(odd.items(), key=lambda x: x[1], reverse=True)
if len(sorted_even) == 1:
    if len(sorted_odd) == 1:
        if sorted_even[0][0] == sorted_odd[0][0]:
            print(min(sorted_even[0][1], sorted_odd[0][1]))
        else:
            print(0)
    else:
        if sorted_even[0][0] == sorted_odd[0][0]:
            print(min(n - sorted_even[0][1], n - sorted_odd[0][1]))
        else:
            print(sorted_odd[1][1])
else:
    if len(sorted_odd) == 1:
        if sorted_even[0][0] == sorted_odd[0][0]:
            print(min(n - sorted_even[0][1], sorted_odd[0][1]))
        else:
            print(sorted_even[1][1])
    else:
        print(min(sorted_even[0][1] + sorted_odd[1][1], sorted_even[1][1] + sorted_odd[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
num1=Counter(v[0::2])
num2=Counter(v[1::2])
num1sort=sorted(num1.items(),key=lambda x:x[1],reverse=True)
num2sort=sorted(num2.items(),key=lambda x:x[1],reverse=True)
if num1sort[0][0] == num2sort[0][0]:
    if (len(num1) == 1 ):
        if(len(num2) == 1):
            print(n-2)
        else:
            print(n-1-num2sort[1][1])
    elif (len(num2) == 1):
        print(n-1-num1sort[1][1])
    else:
        p1 = num1sort[0][1] + num2sort[1][1]
        p2 = num1sort[1][1] + num2sort[0][1]
        if p1 > p2:
            print(n-p1)
        else:
            print(n-p2)
else:
    print(n-num1sort[0][1]-num2sort[0][1])

Submission status: Wrong Answer

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

odd = {}
even = {}

for idx in range(N):
  if idx%2 == 0:
    if V[idx] in even:
      even[V[idx]] += 1
    else:
      even[V[idx]] = 1
  else:
    if V[idx] in odd:
      odd[V[idx]] += 1
    else:
      odd[V[idx]] = 1
sorted_odd = sorted(odd.items(), key=lambda x: -x[1])
sorted_even = sorted(even.items(), key=lambda x: -x[1])
fs_odd = sorted_odd[0][0]
fs_even = sorted_even[0][0]
if fs_odd == fs_even:
  if len(odd) == 1:
    print(1)
  elif sorted_odd[0][1] > sorted_even[0][1]:
    fs_even = sorted_even[1][0]
    print(N-odd[fs_odd]-even[fs_even])
  elif sorted_odd[0][1] < sorted_even[0][1]:
    fs_odd = sorted_odd[1][0]
    print(N-odd[fs_odd]-even[fs_even])
  else:
    if len(sorted_odd) == 1:
      print(N//2)
    else:
      if sorted_odd[1][1] > sorted_even[1][1]:
        fs_odd = sorted_odd[1][0]
        print(N-odd[fs_odd]-even[fs_even])
      else:
        fs_even = sorted_even[1][0]
        print(N-odd[fs_odd]-even[fs_even])
else:
  print(N-odd[fs_odd]-even[fs_even])

Submission status: Wrong Answer

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

odd = {}
even = {}

for idx in range(N):
  if idx%2 == 0:
    if V[idx] in even:
      even[V[idx]] += 1
    else:
      even[V[idx]] = 1
  else:
    if V[idx] in odd:
      odd[V[idx]] += 1
    else:
      odd[V[idx]] = 1
sorted_odd = sorted(odd.items(), key=lambda x: -x[1])
sorted_even = sorted(even.items(), key=lambda x: -x[1])
fs_odd = sorted_odd[0][0]
fs_even = sorted_even[0][0]
if fs_odd == fs_even:
  if len(sorted_odd) == 1:
    print(2)
  elif sorted_odd[1][1] > sorted_even[1][1]:
    fs_odd = sorted_odd[1][0]
    print(N-odd[fs_odd]-even[fs_even])
  else:
    fs_even = sorted_even[1][0]
    print(N-odd[fs_odd]-even[fs_even])
else:
  print(N-odd[fs_odd]-even[fs_even])

Submission status: Wrong Answer

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

odd = {}
even = {}

for idx in range(N):
  if idx%2 == 0:
    if V[idx] in even:
      even[V[idx]] += 1
    else:
      even[V[idx]] = 1
  else:
    if V[idx] in odd:
      odd[V[idx]] += 1
    else:
      odd[V[idx]] = 1
sorted_odd = sorted(odd.items(), key=lambda x: -x[1])
sorted_even = sorted(even.items(), key=lambda x: -x[1])
fs_odd = sorted_odd[0][0]
fs_even = sorted_even[0][0]
if fs_odd == fs_even:
  if len(sorted_odd) == 1:
    print(0)
  elif sorted_odd[1][1] > sorted_even[1][1]:
    fs_odd = sorted_odd[1][0]
    print(N-odd[fs_odd]-even[fs_even])
  else:
    fs_even = sorted_even[1][0]
    print(N-odd[fs_odd]-even[fs_even])
else:
  print(N-odd[fs_odd]-even[fs_even])

Submission status: Wrong Answer

Solution code:
import collections

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

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

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common()[0]
me = collections.Counter(even).most_common()[0]
if mo[0] == me[0]:
    if set(mo) == 1:
        me = collections.Counter(even).most_common()[1]
    elif set(me) == 1:
        mo = collections.Counter(odd).most_common()[1]
    elif mo[1] < me[1]:
        mo = collections.Counter(odd).most_common()[1]
    elif me[1] < mo[1]:
        me = collections.Counter(even).most_common()[1]

print(abs((n // 2) - mo[1]) + abs((n // 2) - me[1]))

Submission status: Wrong Answer

Solution code:
import collections

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

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

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common()[0][1]
me = collections.Counter(even).most_common()[0][1]

print(abs((n // 2) - mo) + abs((n // 2) - me))

Submission status: Wrong Answer

Solution code:
import collections

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

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

odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common()[0][1]
me = collections.Counter(even).most_common()[0][1]

print(((n // 2) - mo) + (n // 2) - me)

Submission status: Wrong Answer

Solution code:
import collections

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

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

if s == 2:
    print(0)
    exit()
odd = v[::2]
even = v[1::2]
mo = collections.Counter(odd).most_common()[0][1]
me = collections.Counter(even).most_common()[0][1]

print(((n // 2) - mo) + (n // 2) - me)

Submission status: Wrong Answer

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

odd = {}
even = {}

for idx in range(N):
  if idx%2 == 0:
    if V[idx] in even:
      even[V[idx]] += 1
    else:
      even[V[idx]] = 1
  else:
    if V[idx] in odd:
      odd[V[idx]] += 1
    else:
      odd[V[idx]] = 1
sorted_odd = sorted(odd.items(), key=lambda x: -x[1])
sorted_even = sorted(even.items(), key=lambda x: -x[1])
fs_odd = sorted_odd[0][0]
fs_even = sorted_even[0][0]
if fs_odd == fs_even:
  if len(sorted_odd) == 1:
    print(1)
  elif sorted_odd[1][1] > sorted_even[1][1]:
    fs_odd = sorted_odd[1][0]
    print(N-odd[fs_odd]-even[fs_even])
  else:
    fs_even = sorted_even[1][0]
    print(N-odd[fs_odd]-even[fs_even])
else:
  print(N-odd[fs_odd]-even[fs_even])

Submission status: Wrong Answer

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

odd = {}
even = {}

for idx in range(N):
  if idx%2 == 0:
    if V[idx] in even:
      even[V[idx]] += 1
    else:
      even[V[idx]] = 1
  else:
    if V[idx] in odd:
      odd[V[idx]] += 1
    else:
      odd[V[idx]] = 1
sorted_odd = sorted(odd.items(), key=lambda x: -x[1])
sorted_even = sorted(even.items(), key=lambda x: -x[1])
fs_odd = sorted_odd[0][0]
fs_even = sorted_even[0][0]
if fs_odd == fs_even:
  print(0)
else:
  print(N-odd[fs_odd]-even[fs_even])

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
even = [[0,0]] + sorted([v,k] for k,v in Counter(a[1::2]).items())
odd = [[0,0]] + sorted([v,k] for k,v in Counter(a[0::2]).items())

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

Submission status: Wrong Answer

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

v1 = []
v2 = []
for i in range(n):
    if i%2 == 0:
        v1.append(v[i])
    else:
        v2.append(v[i])
v1.sort()
v2.sort()

v1num = []
v2num = []
cnt1 = []
cnt2 = [] 
for x in v1:
    if x not in v1num:
        v1num.append(x)
        cnt1.append(1)
    else:
        cnt1[-1] += 1
for x in v2:
    if x not in v2num:
        v2num.append(x)
        cnt2.append(1)
    else:
        cnt2[-1] += 1
#print(v1num,v2num,cnt1,cnt2)

res = 0
m1 = max(cnt1)
m2 = max(cnt2)
maxc1ind = cnt1.index(m1)
maxc2ind = cnt2.index(m2)
maxc1 = v1num[maxc1ind]
maxc2 = v2num[maxc2ind]
if maxc1 != maxc2:
    res = n - m1 - m2
else:
    if len(cnt1) == 1 and len(cnt2) == 1 and maxc1 == maxc2:
        res = n // 2
    else:    
        if m1 > m2:
            cnt2.sort(reverse=True)
            res = n - m1 - cnt2[1]
        else:
            cnt1.sort(reverse=True)
            res = n - m2 - cnt1[1]
print(res)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

def main():
    n = int(input())
    v = np.array(list(map(int, input().split())))

    len1 = n//2 + n&1
    len2 = n//2

    d1 = {0:0}
    d2 = {0:0}
    for i in range(0,n,2):
        if v[i] in d1:
            d1[v[i]] += 1
        else:
            d1[v[i]] = 1
    for i in range(1,n,2):
        if v[i] in d2:
            d2[v[i]] += 1
        else:
            d2[v[i]] = 1

    a = sorted(d1.items(), key = lambda x: (x[1], x[0]) , reverse=True)
    b = sorted(d2.items(), key = lambda x: (x[1], -x[0]), reverse=True)
    a1_key, a1_val = a[0]
    a2_key, a2_val = a[1]
    b1_key, b1_val = b[0]
    b2_key, b2_val = b[1]
    if a1_key != b1_key:
        print(n - a1_val - b1_val)
    else:
        print(min(n - a1_val - b2_val, n - a2_val - b2_val))



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

def main():
    n = int(input())
    v = np.array(list(map(int, input().split())))

    len1 = n//2 + n&1
    len2 = n//2

    d1 = {0:0}
    d2 = {0:0}
    for i in range(0,n,2):
        if v[i] in d1:
            d1[v[i]] += 1
        else:
            d1[v[i]] = 1
    for i in range(1,n,2):
        if v[i] in d2:
            d2[v[i]] += 1
        else:
            d2[v[i]] = 1

    t1 = sorted(d1.items(), key = lambda x: x[1], reverse=True)
    t2 = sorted(d2.items(), key = lambda x: x[1], reverse=True)
    # print(t1)
    # print(t2)
    if t1[0][0] != t2[0][0]:
        print(n - t1[0][1] - t2[0][1])
    else:
        # 必要変更数
        s1 = len1 - t1[0][1]
        s2 = len2 - t2[0][1]
        if s1 <= s2:
            print(n - t1[0][1] - t2[1][1])
        else:
            print(n - t1[1][1] - t2[0][1])




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
V.sort()
counters = [1]
for i in range(1, N):
	if V[i] != V[i-1]:
		counters.append(1)
	else:
		counters[-1] += 1
ans = 5000000000000000
if len(counters) == 1:
	ans = N // 2
else:
	counters.sort(reverse = True)
	if N // 2 < counters[0]:
		ans = counters[0] - N // 2 + (N - counters[0] - counters[1])
	else:
		ans = N - counters[0] - counters[1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=input().split()
a={}
for i in range(0,len(l),2):
    if l[i] in a:
        a[l[i]]+=1
    else:
        a[l[i]]=1
b={}  
for i in range(1,len(l),2):
    if l[i] in b:
        b[l[i]]+=1
    else:
        b[l[i]]=1

sorted(a.items(), key=lambda x: -x[1])
sorted(b.items(), key=lambda x: -x[1])

ans = n
for k,v in a.items():
    for kk,vv in b.items():
        if k!=kk:
            ans = min(ans,n-v-vv)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=input().split()
a={}
for i in range(0,len(l),2):
    if l[i] in a:
        a[l[i]]+=1
    else:
        a[l[i]]=1
b={}  
for i in range(1,len(l),2):
    if l[i] in b:
        b[l[i]]+=1
    else:
        b[l[i]]=1
maxA = max(a.values())
maxB = max(b.values())
print(n-maxA-maxB)

Submission status: Wrong Answer

Solution code:


n=int(input())
v=list(map(int,input().split()))
a=v[::2]
b=v[1::2]


def maxElem(L):
    s=list(set(L))
    c=[0]*len(s)
    for i in range(len(s)):
        for j in range(len(L)):
            if L[j]==s[i]:
                c[i]+=1
    return max(c)

print(n-int(maxElem(a))-int(maxElem(b)))

Submission status: Wrong Answer

Solution code:
import collections
from operator import itemgetter

N = int(input())

up = []
down = []
for i, v in enumerate(list(map(int, input().split()))):
    if i % 2 == 0:
        up.append(v)
    else:
        down.append(v)

ud = collections.Counter(up)
dd = collections.Counter(down)

ul = []
for u, c in ud.items():
    ul.append([u, c])
dl = []
for d, c in dd.items():
    dl.append([d, c])

ul.sort(key=itemgetter(1))
dl.sort(key=itemgetter(1))

if ul[0][0] != dl[0][0]:
    print(N - ul[0][1] - dl[0][1])
elif len(ul) == 1 and len(dl) > 1:
    print(N - ul[0][1] - dl[1][1])
elif len(ul) > 1 and len(dl) == 1:
    print(N - ul[1][1] - dl[0][1])
elif len(ul) == 1 and len(dl) == 1:
    print(N//2)
else:
    print(N - max(ul[0][1]+dl[1][1], ul[1][1]+dl[0][1]))

Submission status: Wrong Answer

Solution code:
import collections

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

vdic = collections.Counter(v)

vlist = []
over = False
for num, c in vdic.items():
    if c > n//2:
        over = True
    vlist.append(abs(c - n//2))

vlist.sort()
if len(vlist) == 1:
    print(vlist[0])
elif over:
    print(vlist[1])
else:
    print(vlist[0]+vlist[1])

Submission status: Wrong Answer

Solution code:
import collections
from operator import itemgetter

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

vdic = collections.Counter(v)

vlist = []
for num, c in vdic.items():
    vlist.append(abs(c - n//2))

vlist.sort()
if len(vlist) == 1:
    print(vlist[0])
else:
    print(vlist[0]+vlist[1])

Submission status: Wrong Answer

Solution code:
n = input()
V = [int(x) for x in input().split()]
Vodd = [V[i] for i in range(len(V)) if i % 2 == 1]
Veven = [V[i] for i in range(len(V)) if i % 2 == 0]
counts_Vodd = {}
counts_Veven = {}
for v in Vodd:
    counts_Vodd.setdefault(v, 0)
    counts_Vodd[v] = counts_Vodd[v] + 1
for v in Veven:
    counts_Veven.setdefault(v, 0)
    counts_Veven[v] = counts_Veven[v] + 1
vodd = sorted(counts_Vodd.items(), key=lambda x: x[1])
veven = sorted(counts_Veven.items(), key=lambda x: x[1])
if len(vodd) == 1 and len(veven) == 0 and vodd[-1][0] == veven[-1][0]:
    print(len(V) // 2)
    exit()
ans = len(V) - vodd[-1][1] - veven[-1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
V = [int(x) for x in input().split()]
Vodd = [V[i] for i in range(len(V)) if i % 2 == 1]
Veven = [V[i] for i in range(len(V)) if i % 2 == 0]
counts_Vodd = {}
counts_Veven = {}
for v in Vodd:
    counts_Vodd.setdefault(v, 0)
    counts_Vodd[v] = counts_Vodd[v] + 1
for v in Veven:
    counts_Veven.setdefault(v, 0)
    counts_Veven[v] = counts_Veven[v] + 1
vodd = sorted(counts_Vodd.items(), key=lambda x: x[1])
veven = sorted(counts_Veven.items(), key=lambda x: x[1])
if vodd[-1][0] == veven[-1][0]:
    print(len(V) // 2)
    exit()
ans = len(V) - vodd[-1][1] - veven[-1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
V = [int(x) for x in input().split()]
counts = {}
for v in V:
    counts.setdefault(v, 0)
    counts[v] = counts[v] + 1
srted = sorted(counts.items(), key=lambda x:x[1])
ans = len(V) // 2 if len(srted) == 1 else len(V) - srted[-1][1] - srted[-2][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ac = Counter(ls[::2]).most_common(2)
bd = Counter(ls[1::2]).most_common(2)

if ac[0][0] != bd[0][0]:
    print(n-ac[0][1]-bd[0][1])
else:
    if len(ac) == len(bd):
        print(n//2)
    else:
        print(n-max(ac[0][1] + bd[1][1], ac[1][1] + bd[0][1]))

Submission status: Wrong Answer

Solution code:
def sukuna(l):
	s=set(l)
	return min([l.count(i) for i in s])
	

def resolve():
	n=int(input())
	v=list(map(int,input().split()))
	if len(set(v))==1:
		print(n//2)
	else:
		vo=v[::2]
		ve=v[1::2]
		vos=set(vo)
		ves=set(ve)
		o=sukuna(vo) if len(vos)>1 else 0
		e=sukuna(ve) if len(ves)>1 else 0
		print(o+e)

		
resolve()

Submission status: Wrong Answer

Solution code:
n1 = [[j, 0] for j in range(100005)]
n2 = [[j, 0] for j in range(100005)]
n = int(input())
v = list(map(int, input().split()))
for i in range(n):
    if(i % 2 == 0):
        n1[v[i]][1] += 1
    else:
        n2[v[i]][1] += 1
n1 = sorted(n1, key=lambda x:x[1], reverse=True)
n2 = sorted(n2, key=lambda x:x[1], reverse=True)

if(n1[0][0] == n2[0][0]):
    ans1 = n//2 - n1[0][1] + n//2 - n1[1][1]
    ans2 = n//2 - n1[1][1] + n//2 - n1[0][1]
    ans = min(ans1, ans2)
    print(ans)
else:
    ans = n//2 - n1[0][1] + n//2 - n1[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC111 C
n = int(input())
v = list(map(int,input().split()))

ans1 = 0
s = v[0]
t = v[1]
if s == t:
    ans1 += 1
for i in range(2,n):
    if i % 2 == 0:
        if v[i] == s:
            continue
        else:
            ans1 += 1
    else:
        if v[i] == t and s != t:
            continue
        else:
            ans1 += 1
#print(ans1)
ans2 = 0
s = v[0]
t = v[1]
if s == t:
    ans2 += 1
for i in range(2,n):
    if i % 2 == 0:
        if v[i] == s and s != t:
            continue
        else:
            ans2 += 1
    else:
        if v[i] == t:
            continue
        else:
            ans2 += 1
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC111 C
n = int(input())
v = list(map(int,input().split()))

ans = 0
s = v[0]
t = v[1]
if s == t:
    ans += 1
for i in range(2,n):
    if i % 2 == 0:
        if v[i] == s:
            continue
        else:
            ans += 1
    else:
        if v[i] == t and s != t:
            continue
        else:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
a1=collections.Counter(a[0::2]).most_common()
a2=collections.Counter(a[1::2]).most_common()
print(a1,a2)
a1.append((0,0))
a2.append((0,0))
if a1[0]!=a2[0]:print(n-a1[0][1]-a2[0][1])
else:print(min(n-a1[0][1]-a2[1][1],n-a1[1][1]-a2[0][1]))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
v = np.array(list(map(int, input().split())))
v = v.reshape((n//2, 2))
ind1 = set(v[:,0])
ind2 = set(v[:,1])
dict1 = {i:0 for i in ind1}
dict2 = {i:0 for i in ind2}

dict1[-1] = 0
dict2[-1] = 0

for i in range(n//2):
    dict1[v[i][0]] += 1

for i in range(n//2):
    dict2[v[i][1]] += 1

d1 = sorted(dict1.items(), key=lambda x:(x[1], -x[0]), reverse=True)
d2 = sorted(dict2.items(), key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
if d1[0][1] > d2[0][1]:# d1から決める
    key1 = d1[0][0]
    ans += n//2 - dict1[key1]
    if key1 == d2[0][0]:
        key2 = d2[1][0]
    else:
        key2 = d2[0][0]
    ans += n//2 - dict2[key2]
else:# d2から決める
    key2 = d2[0][0]
    ans += n//2 - dict2[key2]
    if key2 == d1[0][0]:
        key1 = d1[1][0]
    else:
        key1 = d1[0][0]
    ans += n//2 - dict1[key1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
ind = set(v)
dict1 = {i:0 for i in ind}
dict2 = {i:0 for i in ind}

dict1[-1] = 0
dict2[-1] = 0

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

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

d1 = sorted(dict1.items(), key=lambda x:(x[1], -x[0]), reverse=True)
d2 = sorted(dict2.items(), key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
if d1[0][1] > d2[0][1]:# d1から決める
    key1 = d1[0][0]
    ans += n//2 - dict1[key1]
    if key1 == d2[0][0]:
        key2 = d2[1][0]
    else:
        key2 = d2[0][0]
    ans += n//2 - dict2[key2]
else:# d2から決める
    key2 = d2[0][0]
    ans += n//2 - dict2[key2]
    if key2 == d1[0][0]:
        key1 = d1[1][0]
    else:
        key1 = d1[0][0]
    ans += n//2 - dict1[key1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
ind = set(v)
dict1 = {i:0 for i in ind}
dict2 = {i:0 for i in ind}

dict1[-1] = 0
dict2[-1] = 0

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

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

d1 = sorted(dict1.items(), key=lambda x:(x[1], x[0]), reverse=True)
d2 = sorted(dict2.items(), key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
if d1[0][1] > d2[0][1]:# d1から決める
    key1 = d1[0][0]
    ans += n//2 - dict1[key1]
    if key1 == d2[0][0]:
        key2 = d2[1][0]
    else:
        key2 = d2[0][0]
    ans += n//2 - dict2[key2]
else:# d2から決める
    key2 = d2[0][0]
    ans += n//2 - dict2[key2]
    if key2 == d1[0][0]:
        key1 = d1[1][0]
    else:
        key1 = d1[0][0]
    ans += n//2 - dict1[key1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
ind = set(v)
dict1 = {i:0 for i in ind}
dict2 = {i:0 for i in ind}

dict1[-1] = 0
dict2[-1] = 0

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

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

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

ans = 0
if d1[0][1] > d2[0][1]:# d1から決める
    key1 = d1[0][0]
    ans += n//2 - dict1[key1]
    if key1 == d2[0][0]:
        key2 = d2[1][0]
    else:
        key2 = d2[0][0]
    ans += n//2 - dict2[key2]
else:# d2から決める
    key2 = d2[0][0]
    ans += n//2 - dict2[key2]
    if key2 == d1[0][0]:
        key1 = d1[1][0]
    else:
        key1 = d1[0][0]
    ans += n//2 - dict1[key1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
ind = set(v)
dict1 = {i:0 for i in ind}
dict2 = {i:0 for i in ind}

if len(ind) == 1:
    print(n//2)
else:
    ans = 0
    for i in range(0, n, 2):
        dict1[v[i]] += 1

    key1 = max(dict1, key=dict1.get)
    ans += n//2 - dict1[key1]

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

    tmp = sorted(dict2.items(), key=lambda x:x[1], reverse=True)
    if tmp[0][0] == key1:
        key2 = tmp[1][0]
    else:
        key2 = tmp[0][0]
    ans += n//2 - dict2[key2]

    print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in range(a):
    if str(b[i]) in c:
        c[str(b[i])] += 1
    else:
        c[str(b[i])] = 1
c = sorted(c.items(), key=lambda x: x[1], reverse=True)
if len(c) <= 1:
    print(a // 2)
elif len(c) == 2:
    e = [int(c[0][0]), int(c[1][0])] + b
    f = [int(c[1][0]), int(c[0][0])] + b
    ec = 0
    fc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
    print(min(ec, fc))
elif len(c) >= 3:
    e = [int(c[0][0]), int(c[1][0])] + b
    f = [int(c[1][0]), int(c[0][0])] + b
    g = [int(c[0][0]), int(c[2][0])] + b
    h = [int(c[1][0]), int(c[2][0])] + b
    j = [int(c[2][0]), int(c[0][0])] + b
    k = [int(c[2][0]), int(c[1][0])] + b

    ec = 0
    fc = 0
    gc = 0
    hc = 0
    jc = 0
    kc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
        if g[i] != g[i-2]:
            g[i] = g[i-2]
            gc += 1
        if h[i] != h[i-2]:
            h[i] = h[i-2]
            hc += 1
        if j[i] != j[i-2]:
            j[i] = j[i-2]
            jc += 1
        if k[i] != k[i-2]:
            k[i] = k[i-2]
            kc += 1
    print(min(ec, fc))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in range(a):
    if str(b[i]) in c:
        c[str(b[i])] += 1
    else:
        c[str(b[i])] = 1
c = sorted(c.items(), key=lambda x: x[1], reverse=True)
if len(c) <= 1:
    print(a // 2)
elif len(c) == 2:
    e = [int(c[0][0]), int(c[1][0])] + b
    f = [int(c[1][0]), int(c[0][0])] + b
    ec = 0
    fc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
    print(min(ec, fc))
elif len(c) >= 3:
    e = [int(c[0][0]), int(c[1][0])] + b
    f = [int(c[1][0]), int(c[0][0])] + b
    g = [int(c[0][0]), int(c[2][0])] + b
    h = [int(c[1][0]), int(c[2][0])] + b
    ec = 0
    fc = 0
    gc = 0
    hc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
        if g[i] != g[i-2]:
            g[i] = g[i-2]
            gc += 1
        if h[i] != h[i-2]:
            h[i] = h[i-2]
            hc += 1
    print(min(ec, fc))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in range(a):
    if str(b[i]) in c:
        c[str(b[i])] += 1
    else:
        c[str(b[i])] = 1
c = sorted(c.items(), key=lambda x: x[1], reverse=True)
if len(c) <= 1:
    print(a // 2)
else:
    e = [int(c[0][0]), int(c[1][0])] + b
    f = [int(c[1][0]), int(c[0][0])] + b
    ec = 0
    fc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
    print(min(ec, fc))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = []
for i in range(a):
    d = False
    for j in range(0, len(c)):
        if c[j][0] == b[i]:
            c[j][1] += 1
            d = True
            break
    if not d:
        c.append([b[i], 1])
c = sorted(c, key=lambda x: x[0], reverse=True)
print("test")
exit()
if len(c) <= 1:
    print(a // 2)
else:
    e = [c[0][0], c[1][0]] + b
    f = [c[1][0], c[0][0]] + b
    ec = 0
    fc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
    print(min(ec, fc))

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = []
for i in range(a):
    d = False
    for j in range(0, len(c), 2):
        if c[j][0] == b[i]:
            c[j][1] += 1
            d = True
            break
    if not d:
        c.append([b[i], 1])
c = sorted(c, key=lambda x: x[0], reverse=True)
if len(c) <= 1:
    print(a // 2)
else:
    e = [c[0][0], c[1][0]] + b
    f = [c[1][0], c[0][0]] + b
    ec = 0
    fc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
    print(min(ec, fc))