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=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
    
a_count=collections.Counter(a)
b_count=collections.Counter(b)
if a_count.most_common()[0][0]==b_count.most_common()[0][0]:
    if a_count.most_common()[0][1]==n//2 and b_count.most_common()[0][1]==n//2:
        print(a_count.most_common()[0][1])
    elif a_count.most_common()[0][1]==n//2 and b_count.most_common()[0][1]!=n//2:
        print(a_count.most_common()[1][1])
    elif a_count.most_common()[0][1]!=n//2 and b_count.most_common()[0][1]==n//2:
        print(b_count.most_common()[1][1])
    else:
        print(min(a_count.most_common()[1][1],b_count.most_common()[1][1]))
else:
    ans=n-a_count.most_common()[0][1]-b_count.most_common()[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
    
a_count=collections.Counter(a)
b_count=collections.Counter(b)
if a_count.most_common()[0][0]==b_count.most_common()[0][0]:
    if a_count.most_common()[0][1]==n//2 and b_count.most_common()[0][1]==n//2:
        print(a_count.most_common()[0][1])
    elif a_count.most_common()[0][1]==n//2 and b_count.most_common()[0][1]!=n//2:
        print(b_count.most_common()[1][1])
    elif a_count.most_common()[0][1]!=n//2 and b_count.most_common()[0][1]==n//2:
        print(a_count.most_common()[1][1])
    else:
        print(min(a_count.most_common()[1][1],b_count.most_common()[1][1]))
else:
    ans=n-a_count.most_common()[0][1]-b_count.most_common()[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
    
a_count=collections.Counter(a)
b_count=collections.Counter(b)
if a_count.most_common()[0][0]==b_count.most_common()[0][0]:
    
    print(n-a_count.most_common()[0][1])
else:
    ans=n-a_count.most_common()[0][1]-b_count.most_common()[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,n,2):
    a.append(v[i])
    b.append(v[i+1])
    
a_count=collections.Counter(a)
b_count=collections.Counter(b)
if a_count.most_common()[0][1]==b_count.most_common()[0][1]:
    print(n-a_count.most_common()[0][1])
else:
    ans=n-a_count.most_common()[0][1]-b_count.most_common()[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
def multi_diff(es):
    return es == [es[0]] * len(es) if es else False

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

if multi_diff(v) == True:
    i = 2
    while i < n:
        v[i] = 2
        i += 1
ans = 0
for i in range(n - 2):
    if v[i] != v[i + 2]:
        v[i+2] = v[i]
        ans += 1
print(ans)

Submission status: Wrong Answer

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

import collections

E = []
O = []
for i, v in enumerate(V):
  if i % 2 == 0:
    E.append(v)
  else:
    O.append(v)

ec = collections.Counter(E)
oc = collections.Counter(O)
e_common = ec.most_common()
o_common = oc.most_common()

E1 = e_common[0][1]
E2 = E1
if len(e_common) > 1:
  E2 = e_common[1][1]

O1 = o_common[0][1]
O2 = O1
if len(o_common) > 1:
  O2 = o_common[1][1]

if e_common[0][0] == o_common[0][0]:
  A1 = N - E1 - O2
  A2 = N - O1 - E2
  print(min(A1, A2))
else:
  ans = N - E1 - O1
  print(ans)

Submission status: Wrong Answer

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

import collections

E = []
O = []
for i, v in enumerate(V):
  if i % 2 == 0:
    E.append(v)
  else:
    O.append(v)

ec = collections.Counter(E)
oc = collections.Counter(O)
e_common = ec.most_common()
o_common = oc.most_common()

E1 = e_common[0][1]
E2 = E1
if len(e_common) > 1:
  E2 = e_common[1][1]

O1 = o_common[0][1]
O2 = O1
if len(o_common) > 1:
  O2 = o_common[1][1]

HN = int(N/2)
A1 = abs(HN - E1) + abs(HN - O2)
A2 = abs(HN - O1) + abs(HN - E2)

print(min(A1, A2))

Submission status: Wrong Answer

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

import collections

v = collections.Counter(V)
common = v.most_common()

HN = int(N / 2)
A1 = abs(HN - common[0][1])

A2 = 0
if len(common) > 1:
  A2 = abs(HN - common[1][1])

print(A1+A2)

Submission status: Wrong Answer

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

V1 = V[::2]
V2 = V[1::2]
ans = 0
d1 = Counter(V1)
d2 = Counter(V2)
m1 = max(d1.items(), key = lambda x:x[1])
m2 = max(d2.items(), key = lambda x:x[1])
d1.pop(m1[0])
d2.pop(m2[0])
a = m1[1]
b = m2[1]
if m1[0] != m2[0]:
    if d1:
      ans += sum(d1.values())
    if d2:
      ans += sum(d2.values())
else:
    c = 0
    d = 0
    if d1:
	    c = max(d1.values())
    if d2:
	    d = max(d2.values())
    if c != 0:
        tmp = N-b-c
    if c == 0:
        tmp = N-b-a
    if d != 0:
        ttmp = N-a-d
    if d == 0:
        ttmp = N-a-b
    
    ans = min(tmp,ttmp)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
V = list(map(int,input().split(" ")))
V1 = V[::2]
V2 = V[1::2]
ans = 0
if V1 == V2:
  ans = N//2
else:
  d1 = Counter(V1)
  d2 = Counter(V2)
  m1 = max(d1.items(), key = lambda x:x[1])
  m2 = max(d2.items(), key = lambda x:x[1])
  d1.pop(m1[0])
  d2.pop(m2[0])
  a = m1[1]
  b = m2[1]
  if m1[0] != m2[0]:
    if d1:
      ans += sum(d1.values())
    if d2:
      ans += sum(d2.values())
  else:
    c = 0
    d = 0
    if d1:
	    c = max(d1.values())
    if d2:
	    d = max(d2.values())
    tmp = N - a - d
    ans = min(tmp,N - b - c)
print(ans)

Submission status: Wrong Answer

Solution code:
x=int(input())
a=list(map(int,input().split()))
d=[0]*100001
d0=[0]*100001
p=0
q=0
m0=0
n0=0
m=n=0
for i in range(x):
    if i%2==0:
        d[a[i]]+=1
        if d[a[i]]>p:
            p=max(p,d[a[i]])
            if a[i]!=m:
                m0=m
                m=a[i]
    else:
        d0[a[i]]+=1
        if d0[a[i]]>q:
            q=max(q,d0[a[i]])
            if a[i]!=n:
                n0=n
                n=a[i]
if m==n:
    if d[m0]>d0[n0]:
        p=d[m0]
    else:
        q=d0[n0]
print(x-p-q)        
#print(m0,n0,d[m0],d0[n0])

Submission status: Wrong Answer

Solution code:
x=int(input())
a=list(map(int,input().split()))
d=[0]*100001
d0=[0]*100001
p=0
q=0
for i in range(x):
    if i%2==0:
        d[a[i]]+=1
        p=max(p,d[a[i]])
    else:
        d0[a[i]]+=1
        q=max(q,d0[a[i]])
if d[a[0]]==x//2 and d0[a[1]]==x//2 and a[0]==a[1]:
    q=0
print(x-p-q)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = input().split(" ")
    even = {}
    odd = {}
    for i in range(n):
        if i % 2 == 0:
            even.setdefault(v[i], 0)
            even[v[i]] += 1
        else:
            odd.setdefault(v[i], 0)
            odd[v[i]] += 1
    even = sorted(even.items(), key=lambda x: x[1])
    odd = sorted(odd.items(), key=lambda x: x[1])
    # print(even,odd)
    if even[0][0] == odd[0][0]:
        if len(even) > 1 and len(odd) > 1:
            print(n - int(even[0][1]) - max(even[1][1], odd[1][1]))
        elif len(even) > 1:
            print(n - odd[0][1] - even[1][1])
        elif len(odd) > 1:
            print(n - even[0][1] - odd[1][1])
        else:
            print(n // 2)
    else:
        print(n - int(even[0][1]) - int(odd[0][1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    v = input().split(" ")
    even = {}
    odd = {}
    for i in range(n):
        if i % 2 == 0:
            even.setdefault(v[i], 0)
            even[v[i]] += 1
        else:
            odd.setdefault(v[i], 0)
            odd[v[i]] += 1
    even = sorted(even.items(), key=lambda x: x[1])
    odd = sorted(odd.items(), key=lambda x: x[1])
    # print(even,odd)
    if even[0][0] == odd[0][0]:
        if len(even) > 2 and len(odd) > 2:
            print(n - int(even[0][1]) - max(even[1][1], odd[1][1]))
        elif len(even) > 2:
            print(n - odd[0][1] - even[1][1])
        elif len(odd) > 2:
            print(n - even[0][1] - odd[1][1])
        else:
            print(n // 2)
    else:
        print(n - int(even[0][1]) - int(odd[0][1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = v[0:n:2]
even = v[1:n:2]

odClass = Counter(odd)
evClass = Counter(even)
mostOd = odClass.most_common()
mostEv = evClass.most_common()

numOd = mostOd[0]
numEv = mostEv[0]

if len(mostOd) == 1 and len(mostEv) == 1:
    if mostOd[0][0] == mostEv[0][0]:
        print(len(odd))
    else:
        print(0)
    exit()
elif len(mostOd) == 1 and len(mostEv) != 1:
    if mostOd[0][0] == mostEv[0][0]:
        numEv = mostEv[1]
elif len(mostOd) != 1 and len(mostEv) == 1:
    if mostOd[0][0] == mostEv[0][0]:
        numOd = mostOd[1]

print(len(odd) + len(even) - numOd[1] - numEv[1])
#print(len(odd) , len(even) , numOd[1] , numEv[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
V = list(map(int,input().split(" ")))
V1 = V[::2]
V2 = V[1::2]
ans = 0
if V1 == V2:
  ans = N//2
else:
  d1 = Counter(V1)
  d2 = Counter(V2)
  m1 = max(d1)
  m2 = max(d2)
  d1.pop(m1)
  d2.pop(m2)
  if d1:
    ans += sum(d1.values())
  if d2:
    ans += sum(d2.values())

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = Counter()
even = Counter()

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

oddCmn = odd.most_common(2)
evenCmn = even.most_common(2)

oddCmn.append((0, 0))
evenCmn.append((0, 0))

od = 0
ev = 0
if oddCmn[od][0] == evenCmn[ev][0]:
    if oddCmn[od][1] + oddCmn[ev + 1][1] < evenCmn[ev][1] + evenCmn[od + 1][1]:
        od += 1
    else:
        ev += 1


print(N - oddCmn[od][1] - evenCmn[ev][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = Counter()
even = Counter()

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

oddCmn = odd.most_common(2)
evenCmn = even.most_common(2)

oddCmn.append((0, 0))
evenCmn.append((0, 0))

od = 0
ev = 0
if oddCmn[od][0] == evenCmn[ev][0]:
    if oddCmn[od][1] + oddCmn[od + 1][1] < evenCmn[ev][1] + evenCmn[ev + 1][1]:
        od += 1
    else:
        ev += 1


print(N - oddCmn[od][1] - evenCmn[ev][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = Counter()
even = Counter()

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

oddCmn = odd.most_common(1)
evenCmn = even.most_common(1)

print(N - oddCmn[0][1] - evenCmn[0][1])

Submission status: Wrong Answer

Solution code:
#111
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
L=list(Counter(v[0::2]).items())
R=list(Counter(v[1::2]).items())


if L[0][0]!=R[0][0]:#再頻出の数がRとLで同一ではない場合
    ans=n-L[0][1]-R[0][1]
elif len(R)!=1 and len(L)!=1:
    ans=n-max(L[0][1]+R[1][1],L[1][1]+R[0][1])
elif len(R)!=1 and len(L)==1:
    ans=n-R[1][1]-L[0][1]
elif len(R)==1 and len(L)!=1:
    ans=n-R[0][1]-L[1][1]
elif len(R)==1 and len(L)==1:
    ans=n//2
print(ans)

Submission status: Wrong Answer

Solution code:
#111
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
L=list(Counter(v[0::2]).items())
R=list(Counter(v[1::2]).items())


if L[0][0]!=R[0][0]:#再頻出の数がRとLで同一ではない場合
    ans=n-L[0][1]-R[0][1]
elif len(R)!=1 and len(L)!=1:
    ans=n-max(L[0][1]+R[1][1],L[1][1]+R[0][1])
elif len(R)!=1 and len(L)==1:
    ans=n-R[1][1]-L[0][1]
elif len(R)==1 and len(L)!=1:
    ans=n-R[0][1]-L[1][1]
else :
    ans=n//2
print(ans)

Submission status: Wrong Answer

Solution code:
#111
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
L=list(Counter(v[0::2]).items())
R=list(Counter(v[1::2]).items())


if L[0][0]!=R[0][0]:#再頻出の数がRとLで同一ではない場合
    ans=n-L[0][1]-R[0][1]
elif len(R)!=1 and len(L)!=1:
    ans=n-max(L[0][1]+R[1][1],L[1][1]+R[0][1])
elif len(R)!=1 and len(L)==1:
    ans=n-R[0][1]-L[1][1]
elif len(R)==1 and len(L)!=1:
    ans=n-R[1][1]-L[1][0]
else :
    ans=n//2
print(ans)

Submission status: Wrong Answer

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

a = {}
b = {}
for i in range(n):
  if i%2 == 0:
    if v[i] in a:
      a[v[i]] += 1
    else:
      a[v[i]] = 1
  else:
    if v[i] in b:
      b[v[i]] += 1
    else:
      b[v[i]] = 1
   
print(abs(n- max(a) - max(b)))

Submission status: Wrong Answer

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

NG=0
if V[-1]==V[-2]:
    NG+=1
for i in range(N-2):
    if V[i]==V[i+1] or V[i]!=V[i+2]:
        NG+=1
print(-(-NG//2))

Submission status: Wrong Answer

Solution code:
import itertools
"""
n = int(input())
m, a, r, c, h = [0] * 5
for i in range(n):
    s = input()
    if s[0] == "M": m += 1
    if s[0] == "A": a += 1
    if s[0] == "R": r += 1
    if s[0] == "C": c += 1
    if s[0] == "H": h += 1
x = [m, a, r, c, h]
y = ["M", "A", "R", "C", "H"]
ans = 0
for i in itertools.combinations(x, 3):
    ans += i[0] * i[1] * i[2]
print(ans)
"""

# n <= 10**5
n = int(input())
# vi <= 10**5
v = list(map(int, input().split()))
a = [[0] * 100010 for _ in range(2)]
for i in range(n):
    a[i % 2][v[i]] += 1

od, ev = [], []
for i in range(100010):
    od.append([a[1][i], i])
    ev.append([a[0][i], i])
od.sort()
od.reverse()
ev.sort()
ev.reverse()
if od[0][1] != ev[0][1]: print(n - od[0][0] - ev[0][0])
else: print(n - max(od[0][0] + ev[0][1], od[1][0] + ev[0][0]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def solve(n, V):
    odds = V[0::2]
    evens = V[1::2]
    a = Counter(odds).most_common()[0][0]
    b = Counter(evens).most_common()[0][0]
    if a == b:
        b = -1
    return len(odds) - odds.count(a) + len(evens) - evens.count(b)

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def solve(n, V):
    cs = Counter(V).most_common(2)
    a = cs[0][0]
    b = cs[1][0] if len(cs) == 2 else -1
    count1, count2 = 0, 0
    for i, v in enumerate(V):
        if i % 2 == 0:
            if v != a:
                count1 += 1
            if v != b:
                count2 += 1
        if i % 2 == 1:
            if v != b:
                count1 += 1
            if v != a:
                count2 += 1
    return min(count1, count2)

_n = int(input())
_V = list(map(int, input().split()))
print(solve(_n, _V))

Submission status: Wrong Answer

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

ans = 0
for i in range(n - 2):
    if v[i] != v[i + 2]:
        v[i + 2] = -1
        ans += 1
    elif v[i] == v[i + 1] and v[i + 1] != -1:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

ans = n
for i in range(n - 2):
    if v[i] == v[i + 2] and v[i] != v[i + 1]:
        ans -= 1
print(ans - 2)

Submission status: Wrong Answer

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

v.sort()

ans = 0
for i in range(n - 1):
    if v[i] != v[i + 1]:
        ans += 1
if ans == 0:
    ans = n // 2
    print(ans)
else:   
    print(ans - 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
A1=A[0:n-1:2]
A2=A[1:n:2]
L=Counter(A)
L1=Counter(A1)
L2=Counter(A2)
comon=L.most_common()
comon1=L1.most_common()
comon2=L2.most_common()
hanbun=n//2
if len(comon)==1:
    print(hanbun)
else:
    cnt=0
    saidai11=comon1[0][1]
    saidai21=comon2[0][1]
    if saidai11>=saidai21:
        cnt+=hanbun-saidai11
        if comon1[0][0]==comon2[0][0]:
            cnt+=hanbun-comon2[1][1]
        else:
            cnt+=hanbun-saidai21
    else:
        cnt+=hanbun-saidai11
        if comon1[0][0]==comon2[0][0]:
            cnt+=hanbun-comon1[1][1]
        else:
            cnt+=hanbun-saidai11
    print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
L=Counter(A)
comon=L.most_common()
hanbun=n//2
if len(comon)==1:
    print(hanbun)
else:
    saidai=L.most_common()[0][1]
    saidai2=L.most_common()[1][1]
    if saidai>=hanbun:
        print(hanbun-saidai2)
    else:
        print(n-saidai-saidai2)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
v1 = v[0::2]
v2 = v[1::2]
v1_count = v1.count(v1[0])
v2_count = v2.count(v2[0])
ans1 = min(v1_count,len(v1)-v1_count)
ans2 = min(v2_count,len(v2)-v2_count)
if ans1 == 0 and ans2 == 0 and v1[0] == v2[0]:
    print(n//2)
else:
    print(ans1+ans2)

Submission status: Wrong Answer

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

cnt1=0
cnt2=0
a,b=0,0
v = collections.Counter(V)
S=[]
S= v.most_common(2)

if len(S)==1:
  print(N//2)
else:
  for i in range(0,len(V),2):
    if V[i]!=S[0][0]:
      cnt1+=1
    if V[i]!=S[1][0]:
      cnt2+=1
    a=min(cnt1,cnt2)
  #print(cnt1,cnt2)
  if cnt1>=cnt2:
    for i in range(1,len(V),2):
      if V[i]!=S[0][0]:
        b+=1
  else:
    for i in range(1,len(V),2):
      if V[i]!=S[1][0]:
        b+=1
  print(a+b)

Submission status: Wrong Answer

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

cnt1=0
cnt2=0
a,b=0,0
v = collections.Counter(V)
S=[]
S= v.most_common(2)

if len(S)==1:
  print(N//2)
else:
  for i in range(0,N,2):
    if V[i]!=S[0][0]:
      cnt1+=1
    if V[i]!=S[1][0]:
      cnt2+=1
    a=min(cnt1,cnt2)
  #print(cnt1,cnt2)
  if cnt1>=cnt2:
    for i in range(1,N,2):
      if V[i]!=S[0][0]:
        b+=1
  else:
    for i in range(1,N,2):
      if V[i]!=S[1][0]:
        b+=1
  print(a+b)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list( map(int,input().split()))
C0 = [ [0,i] for i in range(100005) ]
C1 = [ [0,i] for i in range(100005) ]
for i in range(0,N,2):
    C0[A[i]][0] += 1
    C1[A[i+1]][0] += 1
C0.sort(reverse=True)
C1.sort(reverse=True)
if C0[0][1] == C1[0][1]:
    ans = N - min(C0[0][0]+C1[1][0], C0[1][0]+C1[0][0])
else:
    ans = N - C0[0][0] - C1[0][0]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list( map(int,input().split()))
C0 = [ [0,i] for i in range(100005) ]
C1 = [ [0,i] for i in range(100005) ]
for i in range(0,N,2):
    C0[A[i]][0] += 1
    C1[A[i+1]][0] += 1
C0 = sorted(C0, reverse=True)
C1 = sorted(C1, reverse=True)
if C0[0][1] == C1[0][1]:
    if C0[0][0] > C1[0][0]:
        ans = N - C0[0][0] - C1[1][0]
    else:
        ans = N - C0[1][0] - C1[0][0]
else:
    ans = N - C0[0][0] - C1[0][0]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import math

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

if len(set(vn)) == 1:
    print(math.ceil(len(vn) / 2))
    exit()

v_a=[]
v_b=[]

for i in range(n):
    if i % 2 == 0:
        v_a.append(vn[i])
    else:
        v_b.append(vn[i])

v_a_fir = collections.Counter(v_a).most_common()[0][0]
if len(collections.Counter(v_a).most_common()) >= 2:
    v_a_sec = collections.Counter(v_a).most_common()[1][0]
else:
    v_a_sec = 0

v_b_fir = collections.Counter(v_b).most_common()[0][0]
if len(collections.Counter(v_b).most_common()) >= 2:
    v_b_sec = collections.Counter(v_b).most_common()[1][0]
else:
    v_b_sec = 0

ab = len([x for x in v_a if x != v_a_fir]) + len([y for y in v_b if y != v_b_sec])
ba = len([x for x in v_a if x != v_a_sec]) + len([y for y in v_b if y != v_b_fir])

if ab <= ba:
    print(ab)
else:
    print(ba)

Submission status: Wrong Answer

Solution code:
import collections
import math

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

if len(set(vn)) == 1:
    print(math.ceil(len(vn) / 2))
    exit()

v_a=[]
v_b=[]

for i in range(n):
    if i % 2 == 0:
        v_a.append(vn[i])
    else:
        v_b.append(vn[i])

v_a_fir = collections.Counter(v_a).most_common()[0][0]
if len(collections.Counter(v_a).most_common()) >= 2:
    v_a_sec = collections.Counter(v_a).most_common()[1][0]
else:
    v_a_sec = v_a_fir

v_b_fir = collections.Counter(v_b).most_common()[0][0]
if len(collections.Counter(v_b).most_common()) >= 2:
    v_b_sec = collections.Counter(v_b).most_common()[1][0]
else:
    v_b_sec = v_b_fir

ab = len([x for x in v_a if x != v_a_fir]) + len([y for y in v_b if y != v_b_sec])
ba = len([x for x in v_a if x != v_a_sec]) + len([y for y in v_b if y != v_b_fir])

if ab <= ba:
    print(ab)
else:
    print(ba)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
dic1={}
dic2={}
for i in range(n):
  if i%2==0:
    if l[i] in dic1:
      dic1[l[i]] += 1
    else:
      dic1[l[i]]=1
  else:
    if l[i] in dic2:
      dic2[l[i]] += 1
    else:
      dic2[l[i]]=1
      
count = 0
ma = 0
check=0
for i in dic1.values():
  ma = max(ma,i)
  check += i
count += check-ma
ma = 0
check=0
for i in dic2.values():
  ma = max(ma,i)
  check += i
count += check-ma

print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
nums = [int(i) for i in input().split()]

if len(set(nums)) == 1:
    print(n // 2)
else:
    odd_freq = defaultdict(int)
    even_freq = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            # この時位置的には奇数番目
            odd_freq[nums[i]] += 1
        else:
            even_freq[nums[i]] += 1

    odd_max_freq = sorted(odd_freq.items(), reverse=True)[:2]
    even_max_freq = sorted(even_freq.items(), reverse=True)[:2]
    tmp_odd_max = odd_max_freq[0]
    tmp_even_max = even_max_freq[0]
    if tmp_odd_max[0] == tmp_even_max[0]:
        # 最頻の数字が奇数番目と偶数番目で同じなので対応が必要
        if tmp_odd_max[1] > tmp_even_max[1]:
            final_odd_freq = tmp_odd_max[1]
            final_even_freq = even_max_freq[1][1]
        else:
            final_odd_freq = odd_max_freq[1][1]
            final_even_freq = tmp_even_max[1]
    else:
        final_odd_freq = tmp_odd_max[1]
        final_even_freq = tmp_even_max[1]

    print(n - final_odd_freq - final_even_freq)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
nums = [int(i) for i in input().split()]

if len(set(nums)) == 1:
    print(n // 2)
else:
    odd_freq = defaultdict(int)
    even_freq = defaultdict(int)
    for i in range(n):
        if i % 2 == 0:
            # この時位置的には奇数番目
            odd_freq[nums[i]] += 1
        else:
            even_freq[nums[i]] += 1

    odd_max_freq = sorted(odd_freq.values())[-1]
    even_max_freq = sorted(even_freq.values())[-1]
    print(n - odd_max_freq - even_max_freq)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import collections
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])
C1 = collections.Counter(V1)
C2 = collections.Counter(V2)
#print(c1.most_common()[0][1],c2.most_common()[0][1])

c1=C1.most_common()
c2=C2.most_common()
#print(len(c1))
#print(len(c2))
if c1[0][0]==c2[0][0]:
    if c1[0][1]>=c2[0][1]:
        if len(c2)==1:
            print(N-c1[0][1])
        else:
            print(N-c1[0][1]-c2[1][1])
    else:
        if len(c1)==1:
            print(N-c2[0][1])
        else:
            print(N-c2[0][1]-c1[1][1])
else:
    print(N-c1[0][1]-c2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v_1 = v[0:n:2]
v_2 = v[1:n:2]
count_1 = dict(Counter(v_1))
count_2 = dict(Counter(v_2))

# 同じ値かチェック
v1 = sorted(count_1.items(), key=lambda x:x[1], reverse=True)
v2 = sorted(count_2.items(), key=lambda x:x[1], reverse=True)

if v1[0][0] == v2[0][0]:
    if v1[0][1] > v2[0][1]:
        s1 = v1[0][0]
        if len(v2) == 1:
            s2 = s1 + 1
        else:
            s2 = v2[1][0]
    else:
        s2 = v2[0][0]
        if len(v2) == 1:
            s1 = s2 + 1
        else:
            s1 = v1[1][0]
else:
    s1 = v1[0][0]
    s2 = v2[0][0]

ans = n - v_1.count(s1) - v_2.count(s2)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
v_odd = collections.Counter(v[::2])
v_even = collections.Counter(v[1::2])
if len(v_odd) == len(v_even) and v_odd.most_common()[0][0] == v_even.most_common()[0][0]:
    print(n // 2)
    exit()
if v_odd.most_common()[0][0] != v_even.most_common()[0][0]:
    print(len(v[::2]) - v_odd.most_common()[0][1] + len(v[1::2]) - v_even.most_common()[0][1])
else:
    c1 = len(v[1::2]) - v_even.most_common()[0][1] + len(v[::2]) - v_odd.most_common()[1][1]
    c2 = len(v[1::2]) - v_even.most_common()[1][1] + len(v[::2]) - v_odd.most_common()[0][1]
    print(min(c1, c2))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
v_odd = collections.Counter(v[::2])
v_even = collections.Counter(v[1::2])
if len(v_odd) == len(v_even):
    print(n // 2)
    exit()
if v_odd.most_common()[0][0] != v_even.most_common()[0][0]:
    print(len(v[::2]) - v_odd.most_common()[0][1] + len(v[1::2]) - v_even.most_common()[0][1])
else:
    c1 = len(v[1::2]) - v_even.most_common()[0][1] + len(v[::2]) - v_odd.most_common()[1][1]
    c2 = len(v[1::2]) - v_even.most_common()[1][1] + len(v[::2]) - v_odd.most_common()[0][1]
    print(min(c1, c2))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as DD
import numpy as np
N = int(input())
v = list(map(int, input().split()))

E = DD(int)
O = DD(int)
E[-1] = 0
O[-1] = 0
for i in range(N):
  if i % 2 == 1:
    E[v[i]] += 1
  else:
    O[v[i]] += 1

NE = np.array(sorted(E.items(), key=lambda x: x[1], reverse = True))
NO = np.array(sorted(O.items(), key=lambda x: x[1], reverse = True))

#print (NE)
#print (NO)
ans = 0
if NE[0][0] == NO[0][0]:
  if len(NE) == 2 and  len(NO) == 2:
    ans = NE[0][1]
  else:
    if  NE[0][1] > NO[0][1]:
      ans = sum(NO[:,1]) - NO[1][1] + sum(NE[1:,1]) 
    else:
      ans = sum(NE[:,1]) - NE[1][1] + sum(NO[1:,1]) 
else:
  ans = sum(NE[1:,1]) + sum(NO[1:,1])
print (ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as DD
import numpy as np
N = int(input())
v = list(map(int, input().split()))

E = DD(int)
O = DD(int)
E[-1] = 0
O[-1] = 0
for i in range(N):
  if i % 2 == 1:
    E[v[i]] += 1
  else:
    O[v[i]] += 1

NE = np.array(sorted(E.items(), key=lambda x: x[1], reverse = True))
NO = np.array(sorted(O.items(), key=lambda x: x[1], reverse = True))

#print (NE)
#print (NO)
ans = 0
if NE[0][0] == NO[0][0]:
  if len(NE) == 2 and  len(NO) == 2:
    ans = NE[0][1]
  else:
    if  NE[0][1] >= NO[0][1]:
      ans = sum(NO[:,1]) - NO[1][1] + sum(NE[1:,1]) 
    else:
      ans = sum(NE[:,1]) - NE[1][1] + sum(NO[1:,1]) 
else:
  ans = sum(NE[1:,1]) + sum(NO[1:,1])
print (ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as DD
import numpy as np
N = int(input())
v = list(map(int, input().split()))

E = DD(int)
O = DD(int)
E[-1] = 0
O[-1] = 0
for i in range(N):
  if i % 2 == 1:
    E[v[i]] += 1
  else:
    O[v[i]] += 1

NE = np.array(sorted(E.items(), key=lambda x: x[1], reverse = True))
NO = np.array(sorted(O.items(), key=lambda x: x[1], reverse = True))

#print (NE)
#print (NO)
ans = 0
if NE[0][0] == NO[0][0]:
  if len(NE) == 2 and  len(NO) == 2:
    ans = NE[0][1]
  else:
    if  NE[0][1] >= NO[0][1]:
      ans = NO[0][1] + sum(NE[1:,1]) 
    else:
      ans = NE[0][1] + sum(NO[1:,1]) 
else:
  ans = sum(NE[1:,1]) + sum(NO[1:,1])
print (ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as DD
import numpy as np
N = int(input())
v = list(map(int, input().split()))

E = DD(int)
O = DD(int)

for i in range(N):
  if i % 2 == 1:
    E[v[i]] += 1
  else:
    O[v[i]] += 1


NE = np.array(sorted(E.items(), key=lambda x: x[1], reverse = True))
NO = np.array(sorted(O.items(), key=lambda x: x[1], reverse = True))

ans = 0
if NE[0][0] == NO[0][0]:
  if len(NE) == 1 and  len(NO) == 1:
    ans += NE[0][1]
  elif len(NE) == 1 and len(NO) > 1:
    ans += NO[0][1]
  elif len(NE) > 1 and  len(NO) == 1:
    ans += NE[0][1]
  else:
    if  NE[0][1] > NO[0][1]:
      ans += NO[0][1] + sum(NE[1:,1]) 
    else:
      ans += NE[0][1] + sum(NO[1:,1]) 
else:
  if len(NE) > 1: ans += sum(NE[1:,1])
  if len(NO) > 1: ans += sum(NO[1:,1])
print (ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
eve = []
odd = []
b = set()
for i in range(n):
    b.add(a[i])
    if i%2:odd.append(a[i])
    else:eve.append(a[i])
evec = Counter(eve)
oddc = Counter(odd)
even = sum(evec.values())-max(evec.values())
oddn = sum(oddc.values())-max(oddc.values())
#print(len(evec.keys()),len(oddc.keys()),even,oddn,evec,oddc)
if len(evec.keys()) != 1 and len(oddc.keys()) !=  1:
    print(even + oddn)
elif len(evec.keys()) != 1:
    print(even)
elif len(oddc.keys()) != 1:
    print(oddn)
else:
    if len(b) == 1:print(n//2)
    else:print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math
n = int(input())
a = list(map(int, input().split()))
eve = []
odd = []
b = set()
for i in range(n):
    b.add(a[i])
    if i%2:odd.append(a[i])
    else:eve.append(a[i])
evec = Counter(eve)
oddc = Counter(odd)
even = sum(evec.values())-max(evec.values())
oddn = sum(oddc.values())-max(oddc.values())
#print(len(evec.keys()),len(oddc.keys()),even,oddn,evec,oddc)
if len(evec.keys()) != 1 and len(oddc.keys()) !=  1:
    print(even + oddn)
elif len(evec.keys()) != 1:
    print(even)
elif len(oddc.keys()) != 1:
    print(oddn)
else:
    if len(b) == 1:print(math.ceil(n/2))
    else:print(0)