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 as col
N= int(input())
A = [int(x) for x in input().split()]
a = A[::2]
a = col.Counter(a)
b = A[1::2]
b = col.Counter(b)
ans = 0
i = 0
j = 0
#while a.most_common()[i][0]!=b.most_common()[j][0]:
if a.most_common(1)[0][0]!=b.most_common(1)[0][0]:
  ans += sum(a.values())+sum(b.values())-a.most_common(1)[0][1]-b.most_common(1)[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

count = 0

from collections import Counter

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

od = Counter(odd)
ev = Counter(even)

#print(od, ev)
ch_odd, _ = od.most_common()[0]
ch_even, _ = ev.most_common()[0]

# 最頻値が異なる
if ch_odd != ch_even:
    for c in odd:
        if c != ch_odd:
            count += 1

    for c in even:
        if c != ch_even:
            count += 1

# 最頻値が同じ場合は、二番目でトライ
else:
    ch_odd, _ = od.most_common(1)[0]
    ch_even, _ = ev.most_common(2)[0]

    if ch_odd == ch_even:
        ch_even += 1

    count1 = 0
    for c in odd:
        if c != ch_odd:
            count1 += 1

    for c in even:
        if c != ch_even:
            count1 += 1

    ch_odd, _ = od.most_common(2)[0]
    ch_even, _ = ev.most_common(1)[0]

    if ch_odd == ch_even:
        ch_even += 1
    count2 = 0
    for c in odd:
        if c != ch_odd:
            count2 += 1

    for c in even:
        if c != ch_even:
            count2 += 1

    count = min(count1, count2)

print(count)

Submission status: Wrong Answer

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

count = 0

from collections import Counter

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

od = Counter(odd)
ev = Counter(even)

#print(od, ev)
ch_odd, _ = od.most_common()[0]
ch_even, _ = ev.most_common()[0]

for c in odd:
    if c != ch_odd:
        count += 1

if ch_odd == ch_even:
    ch_even += 1

for c in even:
    if c != ch_even:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

count = 0

from collections import Counter

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

od = Counter(odd)
ev = Counter(even)

#print(od, ev)
ch_odd, _ = od.most_common()[0]
ch_even, _ = ev.most_common()[0]

for i in range(2, len(V), 2):
    if V[i] != ch_odd:
        count += 1

if ch_odd == ch_even:
    count += 1
    ch_even += 1

for i in range(3, len(V), 2):
    if V[i] != ch_even:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
V = [int(v) for v in input().split()]
count = 0
c1 = Counter(V[::2]).most_common()[0][0]
for v in V[::2]:
    if v != c1:
        count += 1
c2 = Counter(V[1::2]).most_common()
c2.append((0, 1))
c2 = c2[0][0] if c2[0][0] != c1 else c2[1][0]
for v in V[1::2]:
    if v != c2:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
V = [int(v) for v in input().split()]
count = 0
c1 = Counter(V[::2]).most_common()[0][0]
for v in V[::2]:
    if v != c1:
        count += 1
c2 = Counter(V[1::2] + [0]).most_common()
if c1 != c2[0][0]:
    c2 = c2[1][0] if c2[0][0] == 0 else c2[0][0]
else:
    c2 = c2[1][0]
for v in V[1::2]:
    if v != c2:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
V = [int(v) for v in input().split()]
count = 0
c1 = Counter(V[::2] + [0]).most_common()[0][0]
for v in V[::2]:
    if v != c1:
        count += 1
c2 = Counter(V[1::2] + [0]).most_common()
c2 = c2[0][0] if c1 != c2[0][0] else c2[1][0]
for v in V[1::2]:
    if v != c2:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
V = [int(v) for v in input().split()]
count = 0
c1 = Counter(V[::2] + [0]).most_common()[0][0]
for v in V[::2]:
    if v != c1:
        count += 1
c2 = Counter(V[1::2] + [0]).most_common()
c2 = c2[0][0] if c1 != c2[0][0] else c2[1][0]
for v in V[1::2]:
    if v != c2:
        count += 1
print(count)

Submission status: Wrong Answer

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

ki = {}
guu = {}

for i in range(len(V)):
    if i % 2 == 0:
        guu.setdefault(str(V[i]), 0)
        guu[str(V[i])] += 1
    else:
        ki.setdefault(str(V[i]), 0)
        ki[str(V[i])] += 1

guu = sorted(guu.items(), key=lambda x: -x[1])
ki = sorted(ki.items(), key=lambda x: -x[1])

if len(guu) == 1 and len(ki) != 1:
    if ki[0][0] != guu[0][0]:
        print(N//2 - ki[0][1])
        exit()
    else:
        print(N//2 - ki[1][1])
        exit()

if len(ki) == 1 and len(guu) != 1:
    if guu[0][0] != ki[0][0]:
        print(N//2 - guu[0][1])
        exit()
    else:
        print(N//2 - guu[1][1])
        exit()

if len(ki) == 1 and len(guu) == 1:
    if ki[0][0] == guu[0][0]:
        print(N//2)
        exit()
    else:
        print(0)
        exit()

if guu[0][0] != ki[0][0]:
    print(N - guu[0][1]-ki[0][1])
    exit()

if guu[0][1] > ki[0][1]:  # guuを採用する
    print(N - guu[0][1] - ki[1][1])
    exit()
else:  # kiを採用する
    print(N - ki[0][1] - guu[1][1])
    exit()

Submission status: Wrong Answer

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

ki = {}
guu = {}

for i in range(len(V)):
    if i % 2 == 0:
        guu.setdefault(str(V[i]), 0)
        guu[str(V[i])] += 1
    else:
        ki.setdefault(str(V[i]), 0)
        ki[str(V[i])] += 1

guu = sorted(guu.items(), key=lambda x: -x[1])
ki = sorted(ki.items(), key=lambda x: -x[1])

if len(guu) == 1 and len(ki) != 1:
    if ki[0][0] != guu[0][0]:
        print(N//2 - ki[0][1])
        exit()
    else:
        print(N//2 - ki[1][1])
        exit()

if len(ki) == 1 and len(guu) != 1:
    if guu[0][0] != ki[0][0]:
        print(N//2 - guu[0][1])
        exit()
    else:
        print(N//2 - guu[1][1])
        exit()

if len(ki) == 1 and len(guu) == 1:
    if ki[0][0] == guu[0][0]:
        print(N//2)
        exit()
    else:
        print(0)
        exit()

if guu[0][0] != ki[0][0]:
    print(N - guu[0][1]-ki[0][1])
    exit()
else:
    if guu[0][1] >= ki[0][1]:  # guuを採用する
        print(N - guu[0][1] - ki[1][1])
        exit()
    else:  # kiを採用する
        print(N - ki[0][1] - guu[1][1])
        exit()

Submission status: Wrong Answer

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

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

print(len(set(v[::2]))-1 + len(set(v[1::2]))-1)

Submission status: Wrong Answer

Solution code:
import collections

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

eNum=collections.Counter(r[1::2])
oNum=collections.Counter(r[::2])
eIndex=list(eNum)
oIndex=list(oNum)
eIndex.append(0)
oIndex.append(0)
eNum[0]=0
oNum[0]=0

if eIndex[0]==oIndex[0]:
  print(len(r)-max(eNum[eIndex[0]]+oNum[oIndex[1]],eNum[eIndex[1]]+oNum[oIndex[0]]))
else:
  print(len(r)-eNum[eIndex[0]]-oNum[oIndex[0]])

Submission status: Wrong Answer

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

eNum=[]
oNum=[]

i=0
for item in r:
  if i%2==0:eNum.append(item)
  else:oNum.append(item)
  i+=1
  
setE=set(eNum)
setO=set(oNum)

maxE=0
for item in setE:
  maxE=max(maxE,eNum.count(item))

maxO=0
for item in setO:
  maxO=max(maxO,oNum.count(item))

print(len(r)-maxE-maxO)

Submission status: Wrong Answer

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

E=Counter(V[::2]).most_common() + [(0, 0)]
O=Counter(V[1::2]).most_common() + [(0, 0)]
if E[0][0]!=O[0][0]:
  print(n-E[0][1]+O[0][1])
else:
  print(n-max(E[1][1]+O[0][1],E[0][1]+O[1][1]))

Submission status: Wrong Answer

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

odd=[V[i] for i in range(n) if i%2==0]
eve=[V[i] for i in range(n) if i%2==1]

if len(set(odd))==1 and len(set(eve))==1:
  if set(odd)==set(eve):
    print(n//2)
  else:
    print(0)
else:
  oc=collections.Counter(odd)
  ec=collections.Counter(eve)
  omost = oc.most_common()
  emost = ec.most_common()
  if omost[0][0]!=emost[0][0]:
    if omost[0][1]==n//2:
      print(n//2-emost[0][1])
    elif emost[0][1]==n//2:
      print(n//2-omost[0][1])
    else:
      print(min(n//2-omost[0][1],n//2-emost[0][1]))
  else:
    print(min((n//2-omost[1][1])+(n//2-emost[0][1]),(n//2-omost[0][1])+(n//2-emost[1][1])))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections

# コンテスト外回答

n = int(stdin.readline())
v = [int(x) for x in stdin.readline().rstrip().split()]

# [【Python】 リストから一つおきにデータを取り出す \- 旅行好きなソフトエンジニアの備忘録](http://ni4muraano.hatenablog.com/entry/2017/07/16/212133)
# [start:stop:step]
v1 = v[0::2]
v2 = v[1::2]

tmp = len(v1) - len(v2)

v_c = collections.Counter(v)
v1_c = collections.Counter(v1)
v2_c = collections.Counter(v2)

if v1_c.most_common()[0][0] == v2_c.most_common()[0][0]:

    # print(len(v))
    # print(v_c.most_common()[0][0])

    if len(v) == (v_c.most_common()[0][1]):
        print(1)
        ans = len(v) // 2

    else:
        ansA = len(v1) - v1_c.most_common()[0][1] + \
            len(v2) - v2_c.most_common()[1][1]

        ansB = len(v1) - v1_c.most_common()[1][1] + \
            len(v2) - v2_c.most_common()[0][1]

        print(2)
        ans = min(ansA, ansB)

else:
    print(3)
    ans = len(v1) - v1_c.most_common()[0][1] + \
        len(v2) - v2_c.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections

# コンテスト外回答

n = int(stdin.readline())
v = [int(x) for x in stdin.readline().rstrip().split()]

# [【Python】 リストから一つおきにデータを取り出す \- 旅行好きなソフトエンジニアの備忘録](http://ni4muraano.hatenablog.com/entry/2017/07/16/212133)
# [start:stop:step]
v1 = v[0::2]
v2 = v[1::2]

tmp = len(v1) - len(v2)

v_c = collections.Counter(v)
v1_c = collections.Counter(v1)
v2_c = collections.Counter(v2)

if v1_c.most_common()[0][0] == v2_c.most_common()[0][0]:

    # print(len(v))
    # print(v_c.most_common()[0][0])

    if len(v) == (v_c.most_common()[0][1]):
        ans = len(v) // 2

    elif v1_c.most_common()[0][1] - tmp > v2_c.most_common()[0][1]:
        ans = len(v1) - v1_c.most_common()[0][1] + \
            len(v2) - v2_c.most_common()[1][0]
    else:
        ans = len(v1) - v1_c.most_common()[1][0] + \
            len(v2) - v2_c.most_common()[0][1]

else:
    ans = len(v1) - v1_c.most_common()[0][1] + \
        len(v2) - v2_c.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections

# コンテスト外回答

n = int(stdin.readline())
v = [int(x) for x in stdin.readline().rstrip().split()]

# [【Python】 リストから一つおきにデータを取り出す \- 旅行好きなソフトエンジニアの備忘録](http://ni4muraano.hatenablog.com/entry/2017/07/16/212133)
# [start:stop:step]
v1 = v[0::2]
v2 = v[1::2]

v_c = collections.Counter(v)
v1_c = collections.Counter(v1)
v2_c = collections.Counter(v2)

if v1_c.most_common()[0][0] == v2_c.most_common()[0][0]:

    # print(len(v))
    # print(v_c.most_common()[0][0])

    if len(v) == (v_c.most_common()[0][1]):
        ans = len(v) // 2

    elif v1_c.most_common()[0][1] > v2_c.most_common()[0][1]:
        ans = len(v1) - v1_c.most_common()[0][1] + \
            len(v2) - v2_c.most_common()[1][0]
    else:
        ans = len(v1) - v1_c.most_common()[1][0] + \
            len(v2) - v2_c.most_common()[0][1]

else:
    ans = len(v1) - v1_c.most_common()[0][1] + \
        len(v2) - v2_c.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

evenCnt = Counter(V[::2]).items()
oddCnt = Counter(V[1::2]).items()

evenCnt = list(evenCnt)
oddCnt = list(oddCnt)

evenCnt.sort(key=lambda A: A[1])
oddCnt.sort(key=lambda A: A[1])

if evenCnt[0][0] != oddCnt[0][0]:
    ans = (-(-N // 2) - evenCnt[0][1]) + (N // 2 - oddCnt[0][1])
    print(ans)
else:
    ans = min(
        (-(-N // 2) - evenCnt[0][1]) + N // 2,
        -(-N // 2) + (N // 2 - oddCnt[0][1])
    )
    if len(evenCnt) > 1:
        ans = min(ans, (-(-N // 2) - evenCnt[1][1]) + (N // 2 - oddCnt[0][1]))
    if len(oddCnt) > 1:
        ans = min(ans, (-(-N // 2) - evenCnt[0][1]) + (N // 2 - oddCnt[1][1]))

    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

evenCnt = Counter(V[::2]).items()
oddCnt = Counter(V[1::2]).items()

evenCnt = list(evenCnt)
oddCnt = list(oddCnt)

evenCnt.sort(key=lambda A: A[1])
oddCnt.sort(key=lambda A: A[1])

if evenCnt[0][0] != oddCnt[0][0]:
    ans = (-(-N // 2) - evenCnt[0][1]) + (N // 2 - oddCnt[0][1])
    print(ans)
else:
    ans = min(
        (-(-N // 2) - evenCnt[0][1]) + N // 2,
        -(-N // 2) + (N // 2 - oddCnt[0][1])
    )
    if len(evenCnt) > 1:
        ans = min(ans, (-(-N // 2) - evenCnt[1][1]) + (N // 2 - oddCnt[0][0]))
    if len(oddCnt) > 1:
        ans = min(ans, (-(-N // 2) - evenCnt[0][1]) + (N // 2 - oddCnt[1][1]))

    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
c1, c2 = Counter(v[::2]), Counter(v[1::2])
mc1, mc2 = c1.most_common(2), c2.most_common(2)
mc1.append((0, 0))
mc2.append((0, 0))

ans = 0
if mc1[0][0] == mc2[0][0]:
    ans = n - (mc1[0][1] + mc2[1][1]) if mc1[0][1] > mc2[0][1] else n - (mc1[1][1] + mc2[0][1])
else: ans = n - (mc1[0][1] + mc2[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []

for i in range(n):
    if i % 2 == 0:
        odd.append(inp[i])
    else:
        even.append(inp[i])

# odd.sort()
# even.sort()

o_c = collections.Counter(odd)
o_e = collections.Counter(even)

o_most = o_c.most_common()
e_most = o_e.most_common()

if len(o_most) == len(e_most) == 1:
    if o_most[0][0] != e_most[0][0]:
        ans = 0
    else:
        ans = min(o_most[0][1], e_most[0][1])

else:
    # odd
    if len(o_most) == 1:
        o_ans = 0
    else:
        o_ans = 0
        for i in range(len(o_most)-1):
            o_ans += o_most[i+1][1]

    # even
    if len(e_most) == 1:
        e_ans = 0
    else:
        e_ans = 0
        for i in range(len(e_most)-1):
            e_ans += e_most[i+1][1]
            
    # judge
    ans = o_ans + e_ans

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []

for i in range(n):
    if i % 2 == 0:
        odd.append(inp[i])
    else:
        even.append(inp[i])

# odd.sort()
# even.sort()

o_c = collections.Counter(odd)
o_e = collections.Counter(even)

o_most = o_c.most_common()
e_most = o_e.most_common()

if len(o_most) == len(e_most) == 1:
    if o_most[0][0] != e_most[0][0]:
        ans = 0
    else:
        ans = min(o_most[0][1], e_most[0][1])

else:
    # odd
    if len(o_most) == 1:
        o_ans = 10 ** 5
    else:
        o_ans = 0
        for i in range(len(o_most)-1):
            o_ans += o_most[i+1][1]

    # even
    if len(e_most) == 1:
        e_ans = 10 ** 5
    else:
        e_ans = 0
        for i in range(len(e_most)-1):
            e_ans += e_most[i+1][1]
            
    # judge
    ans = min(o_ans, e_ans)

print(ans)

Submission status: Wrong Answer

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

even = list(Counter(V[0::2]).most_common())
even.append((100001,0))
odd = list(Counter(V[1::2]).most_common())
odd.append((100001,0))
if even[0][0] == odd[0][0]:
    o = []
    o.append(even[0][1]+odd[1][1])
    o.append(even[1][0]+odd[0][1])
    print(N-max(o))
else:
    print(N-even[0][1]-odd[0][1])

Submission status: Wrong Answer

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

even = list(Counter(V[0::2]).most_common())
even.append((100001,0))
odd = list(Counter(V[1::2]).most_common())
odd.append((100001,0))
if even[0][0] == odd[0][0]:
    o = []
    o.append(even[0][1]+odd[1][1])
    o.append(even[1][0]+odd[0][1])
    print(N-min(o))
else:
    print(N-even[0][1]-odd[0][1])

Submission status: Wrong Answer

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

V_=[0,0]

for i,v in enumerate(V):
    V_[i%2] += int(v/(V[i%2])!=1)

V_[0]=min(V_[0],N//2-V_[0])
V_[1]=min(V_[1],N//2-V_[1])

if V[0]==V[1]:
    if V_[0]>V_[1]:
        V_[0]=N//2-V_[0]
    else:
        V_[1]=N//2-V_[1]

print(V_[0]+V_[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
from statistics import mode


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

A = V[::2]
B = V[1::2]
countA = sorted(list(Counter(A).items()), key=lambda x: x[1])
countB = sorted(list(Counter(B).items()), key=lambda x: x[1])

if len(set(V)) == 1:
    print(n//2)
elif countA[0][0] != countB[0][0]:
    print(len(A)-countA[0][1] + len(B)-countB[0][1])
else:
    print(min(
        len(A)-countA[0][1] + len(B)-countB[1][1],
        len(A)-countA[1][1] + len(B)-countB[0][1]
        ))

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
countA = []
countB = []
if len(set(V)) == 1:
    print(n//2)
else:
    A = V[::2]
    B = V[1::2]
    for i in range(n//2):
        print(A.count(A[i]))
        countA.append(A.count(A[i]))
        countB.append(B.count(B[i]))
    max_countA = max(countA)
    max_countB = max(countB)
    
    print(len(A)-max_countA + len(A)-max_countB)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
if len(set(V)) == 1:
    print(n//2)
else:
    A = V[::2]
    B = V[1::2]
    max_countA = max([A.count(a) for a in set(A)])
    max_countB = max([B.count(b) for b in set(B)])
    if len(set(A)) == 1:
        max_countA = 0
    if len(set(B)) == 1:
        max_countB = 0
    
    print(max_countA + max_countB)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
if len(set(V)) == 1:
    print(n//2)
else:
    A = [a for i, a in enumerate(V) if i % 2 == 0]
    B = [b for i, b in enumerate(V) if i % 2 == 1]
    max_countA = max([A.count(a) for a in set(A)])
    max_countB = max([B.count(b) for b in set(B)])
    print(max_countA + max_countB - 2)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
if len(set(V)) == 1:
    print(n//2)
else:
    A = [a for i, a in enumerate(V) if i % 2 == 0]
    B = [b for i, b in enumerate(V) if i % 2 == 1]
    max_countA = max([A.count(a) for a in A])
    max_countB = max([B.count(b) for b in B])
    print(max_countA + max_countB - 2)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
if len(set(V)) == 1:
    print(n//2)
else:
    A = len(set([a for i, a in enumerate(V) if i % 2 == 0]))
    B = len(set([b for i, b in enumerate(V) if i % 2 == 1]))
    print(A+B-2)

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]

cv1 = Counter(v1).most_common(2)
cv2 = Counter(v2).most_common(2)

if cv1[0][0] != cv2[0][0]:
    print(n - cv1[0][1] - cv2[0][1])
elif cv1[0][1] > cv2[0][1]:
    print(n - cv1[0][1] - cv2[1][1] if len(cv2) >= 2 else n - cv1[0][1])
else:
    print(n - cv2[0][1] - cv1[1][1] if len(cv1) >= 2 else n - cv2[0][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]

cv1 = Counter(v1).most_common(2)
cv2 = Counter(v2).most_common(2)

if cv1[0][0] != cv2[0][0]:
    print(n - cv1[0][1] - cv2[0][1])
elif cv1[0][1] > cv2[0][1]:
    print(n - cv1[0][1] - cv2[1][1] if len(cv2) >= 2 else n - cv1[0][1])
else:
    print(n - cv2[0][1] - cv1[1][1] if len(cv1) >= 2 else n - cv2[0][1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

if len(set(vvv)) == 1:
    print(N // 2)
    exit()
elif N == 2:
    print(0)
elif N == 3:
    odd_0, odd_1 = vvv[0], vvv[2]
    if odd_0 != odd_1:
        print(1)
    else:
        print(0)

vvv_odd = vvv[::2]
vvv_even = vvv[1::2]

dp_odd = [0] * max(vvv_odd)
dp_even = [0] * max(vvv_even)

for v_odd, v_even in zip(vvv_odd, vvv_even):
    dp_odd[v_odd - 1] += 1
    dp_even[v_even - 1] += 1

max_appear_odd = max(dp_odd)
max_appear_even = max(dp_even)

# max_odd_val = dp_odd.index(max_appear_odd) + 1
# max_even_val = dp_even.index(max_appear_even) + 1

n_replace = N // 2 - max_appear_odd
n_replace += N // 2 - max_appear_even

print(n_replace)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

if len(set(vvv)) == 1:
    print(N // 2)
    exit()

vvv_odd = vvv[::2]
vvv_even = vvv[1::2]

dp_odd = [0] * max(vvv_odd)
dp_even = [0] * max(vvv_even)

for v_odd, v_even in zip(vvv_odd, vvv_even):
    dp_odd[v_odd - 1] += 1
    dp_even[v_even - 1] += 1

max_appear_odd = max(dp_odd)
max_appear_even = max(dp_even)

# max_odd_val = dp_odd.index(max_appear_odd) + 1
# max_even_val = dp_even.index(max_appear_even) + 1

n_replace = N // 2 - max_appear_odd
n_replace += N // 2 - max_appear_even

print(n_replace)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

vvv_odd = vvv[::2]
vvv_even = vvv[1::2]

dp_odd = [0] * max(vvv_odd)
dp_even = [0] * max(vvv_even)

for v_odd, v_even in zip(vvv_odd, vvv_even):
    dp_odd[v_odd - 1] += 1
    dp_even[v_even - 1] += 1

max_appear_odd = max(dp_odd)
max_appear_even = max(dp_even)

# max_odd_val = dp_odd.index(max_appear_odd) + 1
# max_even_val = dp_even.index(max_appear_even) + 1

n_replace = N // 2 - max_appear_odd
n_replace += N // 2 - max_appear_even

print(n_replace)

Submission status: Wrong Answer

Solution code:
a = int(input())
q=int((a/2)-1)
l=list(map(int ,input().split()))
zeroind=0
oneind=1
ind=2
iind=3
count=0
if len(set(l))==1:
        print(int(a/2))
else:
        for i in range(q):
                if l[zeroind]==l[ind]:
                        ind+=2
                else:
                        count+=1
                        ind+=2 
        
        for i in range(q):
                if l[oneind]==l[iind]:
                        iind+=2
                else:
                        count+=1
                        iind+=2
        print(count)

Submission status: Wrong Answer

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

v1=v[::2]
v2=v[1::2]
dic1=Counter(v1)
dic2=Counter(v2)
dic1=sorted(dic1.items(),key=lambda x:x[1])
dic2=sorted(dic2.items(),key=lambda x:x[1])

if n==2:
    if v[0]==v[1]:
        ans=1
    else:
        ans=0

elif dic1[0][0]!=dic2[0][0]:
    ans=len(v1)-dic1[0][1]
    ans+=len(v2)-dic2[0][1]

elif dic1[0][0]==dic2[0][0] and len(v1)==dic1[0][1] and len(v2)==dic2[0][1]:
    ans=len(v2)

elif dic1[0][0]==dic2[0][0] and len(v1)==dic1[0][1] and len(v2)!=dic2[0][1]:
    ans=len(v2)-dic2[1][1]
    
elif dic1[0][0]==dic2[0][0] and len(v1)!=dic1[0][1] and len(v2)==dic2[0][1]:
    ans=len(v1)-dic1[1][1]
    
elif dic1[0][0]==dic2[0][0]:
    ans = min(len(v1)-dic1[0][1]+len(v2)-dic2[1][1],len(v1)-dic1[1][1]+len(v2)-dic2[0][1])
print(ans)

Submission status: Wrong Answer

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

v1=v[::2]
v2=v[1::2]
dic1=Counter(v1)
dic2=Counter(v2)
dic1=sorted(dic1.items(),key=lambda x:x[1])
dic2=sorted(dic2.items(),key=lambda x:x[1])

if dic1[0][0]!=dic2[0][0]:
    ans=len(v1)-dic1[0][1]
    ans+=len(v2)-dic2[0][1]

elif dic1[0][0]==dic2[0][0] and len(v1)==dic1[0][1] and len(v2)==dic2[0][1]:
    ans=len(v2)

elif dic1[0][0]==dic2[0][0] and len(v1)==dic1[0][1] and len(v2)!=dic2[0][1]:
    ans=len(v2)-dic2[1][1]
    
elif dic1[0][0]==dic2[0][0] and len(v1)!=dic1[0][1] and len(v2)==dic2[0][1]:
    ans=len(v1)-dic1[1][1]
    
elif dic1[0][0]==dic2[0][0]:
    ans = min(len(v1)-dic1[0][1]+len(v2)-dic2[1][1],len(v1)-dic1[1][1]+len(v2)-dic2[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
l=list(map(int ,input().split()))
if len(set(l))==1:
        print(int(a/2))
else:
        print(len(set(l))-2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

vvv_odd = vvv[::2]
vvv_even = vvv[1::2]

odd_vocab = set(vvv_odd)
even_vocab = set(vvv_even)


def calc_rewrite_number(vvv_each, vocab):
    global N

    max_count = -1
    for v in vocab:
        max_count = max(max_count, vvv_each.count(v))
    return N // 2 - max_count


# Calculation for odd and even elements in vvv
n_rewrite = 0
if len(odd_vocab & even_vocab) == 1:
    print(N // 2)
    exit()
else:
    n_rewrite += calc_rewrite_number(vvv_odd, odd_vocab)
    n_rewrite += calc_rewrite_number(vvv_even, even_vocab)

# Output
print(n_rewrite)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

vvv_odd = vvv[::2]
vvv_even = vvv[1::2]

odd_vocab = set(vvv_odd)
even_vocab = set(vvv_even)


def calc_rewrite_number(vvv_each, vocab):
    max_count = -1
    for v in vocab:
        max_count = max(max_count, vvv_each.count(v))
    len_vvv_each = len(vvv_each)
    return len_vvv_each - max_count


# Calculation for odd and even elements in vvv
n_rewrite = 0
if len(odd_vocab & even_vocab) == 1:
    print(N // 2)
    exit()
else:
    n_rewrite += calc_rewrite_number(vvv_odd, odd_vocab)
    n_rewrite += calc_rewrite_number(vvv_even, even_vocab)

# Output
print(n_rewrite)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

vvv_odd = vvv[::2]
vvv_even = vvv[1::2]

odd_vocab = set(vvv_odd)
even_vocab = set(vvv_even)


def calc_rewrite_number(vvv_each, vocab):
    max_count = -1
    for v in vocab:
        max_count = max(max_count, vvv_each.count(v))
    len_vvv_each = len(vvv_each)
    return len_vvv_each - max_count


# Calculation for odd and even elements in vvv
n_rewrite = 0
if len(odd_vocab & even_vocab) == 1:
    print(N/2)
    exit()
else:
    n_rewrite += calc_rewrite_number(vvv_odd, odd_vocab)
    n_rewrite += calc_rewrite_number(vvv_even, even_vocab)

# Output
print(n_rewrite)

Submission status: Wrong Answer

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

dl = {}
du = {}

for i in range(n):
  v = l[i]
  if i%2 == 0:
    if v in dl:
      dl[v] += 1
    else:
      dl[v] = 1
  else:
    if v in du:
      du[v] += 1
    else:
      du[v] = 1

if max(dl, key=dl.get) != max(du, key=du.get):
  ans = n - max(dl.values()) - max(du.values())
else:
  vsl = list(dl.values())
  vsl.sort()
  vsu = list(du.values())
  vsu.sort()
  if len(vsl) == 1 or len(vsu) == 1:
    ans = n//2
  else:
    ans = min(n-vsu[0]-vsl[1], n-vsl[0]-vsu[1])
  
print(ans)

Submission status: Wrong Answer

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

dl = {}
du = {}

for i in range(n):
  v = l[i]
  if i%2 == 0:
    if v in dl:
      dl[v] += 1
    else:
      dl[v] = 1
  else:
    if v in du:
      du[v] += 1
    else:
      du[v] = 1

if max(dl, key=dl.get) != max(du, key=du.get):
  ans = n - max(dl.values()) - max(du.values())
else:
  vsl = list(dl.values())
  vsl.sort()
  vsu = list(du.values())
  vsu.sort()
  if len(vsl) == 1 or len(vsu) == 1:
    ans = n//2
  else:
    ans = min(n//2-vsl[1], n//2-vsu[1])
  
print(ans)

Submission status: Wrong Answer

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

dl = {}
du = {}

for i in range(n):
  v = l[i]
  if i%2 == 0:
    if v in dl:
      dl[v] += 1
    else:
      dl[v] = 1
  else:
    if v in du:
      du[v] += 1
    else:
      du[v] = 1
if max(dl, key=dl.get) != max(du, key=du.get):
  ans = n - max(dl.values()) - max(du.values())
else:
  if max(dl.values()) >= max(du.values()):
    vs = list(dl.values())
    vs.sort(reverse=True)
    if len(vs) >=2:
      ans = n - max(dl.values()) - vs[1]
    else:
      ans = n - max(dl.values())
  else:
    vs = list(dl.values())
    vs.sort(reverse=True)
    if len(vs) >=2:
      ans = n - max(du.values()) - vs[1]
    else:
      ans = n - max(du.values())

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v_even = []
v_odd = []

for i in range(n):
    if i % 2 == 0:
        v_even.append(v[i])
    else:
        v_odd.append(v[i])

even = Counter(v_even).most_common()[0]
odd = Counter(v_odd).most_common()[0]

if even[0] == odd[0]:
    ans = n - even[1]
else:
    ans = n - even[1] - odd[1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
s=list(map(int,input().split()))
a=s[::2]
b=s[1::2]
if len(set(a))==1 and len(set(b))==1:
  if len(set(s))==1:
    print(n//2)
  else:
    print(0)
elif len(set(a))==1:
  B1=collections.Counter(b).most_common()[0][0]
  print(n//2-b.count(B1))
elif len(set(b))==1:
  A1=collections.Counter(a).most_common()[0][0]
  print(n//2-a.count(A1))
else:
  A1=collections.Counter(a).most_common()[0][0]
  A2=collections.Counter(a).most_common()[1][0]
  B1=collections.Counter(b).most_common()[0][0]
  B2=collections.Counter(b).most_common()[1][0]
  if A1+B2>=A2+B1:
    print(n-(A1+B2))
  else:
    print(n-(A2+B1))