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:
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)
al = defaultdict(int)

for i in range(len(v)):
  al[v[i]] += 1
  if(i % 2 == 0): # even
    even[v[i]] += 1
  else: # odd
    odd[v[i]] += 1

if(len(al) == 1):
  print(int(n / 2))
  exit()

even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)
odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)

print(even_sorted)
print(odd_sorted)

op = 0
if(even_sorted[0][0] == odd_sorted[0][0]): 
  if(even_sorted[0][1] < odd_sorted[0][1]):
    op = even_sorted[0][1]
    even_sorted.pop(0)
  else:
    op = odd_sorted[0][1]
    odd_sorted.pop(0)

for i in range(1, len(even_sorted)):
  op += even_sorted[i][1]
for i in range(1, len(odd_sorted)):
  op += odd_sorted[i][1]
print(op)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)
al = defaultdict(int)

for i in range(len(v)):
  al[v[i]] += 1
  if(i % 2 == 0): # even
    even[v[i]] += 1
  else: # odd
    odd[v[i]] += 1

sorted(even.items(), key=lambda x: x[1], reverse=True)
sorted(odd.items(), key=lambda x: x[1], reverse=True)

#print(even.items())
#print(odd.items())
if(len(al) == 1):
  print(int(n / 2))
  exit()

op = 0
for i in range(1, len(even)):
  op += even[i]
for i in range(1, len(odd)):
  op += odd[i]
print(op)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
#まず偶奇分けして二つの配列にします
Vodd = []
Veven = []
for i in range(n//2):
  Vodd.append(V[2*i])
  Veven.append(V[2*i+1])
#それぞれの配列の最頻と2番目を探します
import collections
Codd = collections.Counter(Vodd)
Ceven = collections.Counter(Veven)
cmlstodd = Codd.most_common()
cmlsteven = Ceven.most_common()
#print(cmlstodd, cmlsteven)
#仕方ないのでここからは地道に場合分けします
if len(cmlstodd)==1:
  if cmlstodd[0][0] == cmlsteven[0][0]:
    if len(cmlsteven)==1:
      print(n//2)
    else:
      print(n//2 - cmlsteven[1][1])
  else:
    print(n//2 - cmlsteven[0][1])
elif len(cmlsteven)==1:
  if cmlsteven[0][0] == cmlstodd[0][0]:
    print(n//2 - cmlstodd[1][1])
  else:
    print(n//2 - cmlstodd[0][1])
else:
  if cmlsteven[0][0] == cmlstodd[0][0]:
    print(n - max(cmlsteven[0][1] + cmlstodd[1][1], cmlsteven[1][1] + cmlstodd[0][1]))
  else:
    print(n - cmlstodd[1][1] - cmlsteven[1][1])

Submission status: Wrong Answer

Solution code:
N=int(input())
h=[int(i) for i in input().split()]
#print(h)
h_o = h[1::2]
h_e = h[::2]
h_o1 = len(h_o) - h_o.count(max(h_o))
h_e1 = len(h_e) - h_e.count(max(h_e))

if h_e == h_o:
    print(len(h)//2)
else:
    print(h_o1+h_e1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0] != b[0][0]:
    print(n-a[0][1]-b[0][1])
else:
    print(n-max(a[0][1]+b[1][1],a[1][0]+b[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
def resolve():
    n=int(input())
    v=list(map(int,input().split()))
    v1=collections.Counter(v[::2])
    v1=sorted(v1.items(), key=lambda x:x[1],reverse=True)
    v2=collections.Counter(v[1::2])
    v2=sorted(v2.items(), key=lambda x:x[1],reverse=True)
    if v1[0][0] == v2[0][0]:
        if v1[0][1]>v2[0][1]:
            del v2[0]
        else:
            del v1[0]
    if not v1:
        print(len(v[::2]) + len(v[1::2])-v2[0][1])
    elif not v2:
        print(len(v[::2])-v1[0][1] + len(v[1::2]))
    else:
        print(len(v[::2])-v1[0][1] + len(v[1::2])-v2[0][1])
resolve()

Submission status: Wrong Answer

Solution code:
import collections
def resolve():
    n=int(input())
    v=list(map(int,input().split()))
    v1=collections.Counter(v[::2])
    v1=sorted(v1.items(), key=lambda x:x[1])
    v2=collections.Counter(v[1::2])
    v2=sorted(v2.items(), key=lambda x:x[1])
    if v1[0][0] == v2[0][0]:
        if v1[0][1]>v2[0][1]:
            del v2[0]
        else:
            del v1[0]
    if not v1:
        print(len(v[::2]) + len(v[1::2])-v2[0][1])
    elif not v2:
        print(len(v[::2])-v1[0][1] + len(v[1::2]))
    else:
        print(len(v[::2])-v1[0][1] + len(v[1::2])-v2[0][1])
resolve()

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
dic_odd = {}
dic_even = {}

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

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

odd_sorted = sorted(dic_odd.items(), key=lambda x:x[1])
even_sorted = sorted(dic_even.items(), key=lambda x:x[1])

if odd_sorted[len(odd_sorted)-1][0] == even_sorted[len(even_sorted)-1][0]:
    if len(odd_sorted) == 1 and len(even_sorted) == 1:
        print(n//2)
    elif len(odd_sorted) == 1:
        print(n//2-even_sorted[len(even_sorted)-2][1])
    elif len(even_sorted) == 1:
        print(n//2-odd_sorted[len(odd_sorted)-2][1])
    else:
        if odd_sorted[len(odd_sorted)-1][1] < even_sorted[len(even_sorted)-1][1]:
            print(n - (odd_sorted[len(odd_sorted)-2][1] + even_sorted[len(even_sorted)-1][1]))
        else:
            print(n - (odd_sorted[len(odd_sorted)-1][1] + even_sorted[len(even_sorted)-2][1]))
else:
    print(n-(odd_sorted[len(odd_sorted)-1][1]+even_sorted[len(even_sorted)-1][1]))

Submission status: Wrong Answer

Solution code:
import math
import sys
from itertools import accumulate
from functools import reduce
from collections import Counter
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = list(map(int, sys.stdin.readline().split()))
    l = N // 2
    eL = Counter([L[i] for i in range(N) if i % 2 != 0])
    oL = Counter([L[i] for i in range(N) if i % 2 == 0])
    eLc = eL.most_common() # even list most common
    oLc = oL.most_common() # odd  list most common

    if eLc[0][0] != oLc[0][0]:
        print((l - eLc[0][1]) + (l - oLc[0][1]))
    else:
        if eLc[0][1] > oLc[0][1]:
            print((l - eLc[0][1]) + l)
        else:
            print((l - oLc[0][1]) + l)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
v1 = []
v2 = []
ans = 0

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

c1 = collections.Counter(v1)
mostChar1, mostCount1 = c1.most_common()[0]

c2 = collections.Counter(v2)
mostChar2, mostCount2 = c2.most_common()[0]

if mostChar1 == mostChar2:
    ans = n//2
else:
    ans = n - mostCount1 - mostCount2

print(ans)

Submission status: Wrong Answer

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

v2 = collections.Counter(v)
ans = list(v2.values())
c = ans.count(n/2)
print(int(sum(ans)-c*n/2))

Submission status: Wrong Answer

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

if len(set(v))==1:
    print(n//2)
else:
    a=[]
    b=[]
    for i in range(n):
        if i%2==0:
            a.append(v[i])
        else:
            b.append(v[i])
    a=collections.Counter(a)
    a0=a.most_common()[0]
    b=collections.Counter(b)
    b0=b.most_common()[0]
    if a0[0]!=b0[0]:
        print(n-a0[1]-b0[1])
    elif a0[0]==b0[0]:
        if a0[1]>b0[1]:
            print(n-a0[1]+n-b.most_common()[1][1])
        elif a0[1]<b0[1]:
            print(n-b0[1]+n-a.most_common()[1][1])
        elif a0==b0:
            if b.most_common()[1][1]>=a.most_common()[1][1]:
                print(n-a0[1]+n-b.most_common()[1][1])
            elif b.most_common()[1][1]<=a.most_common()[1][1]:
                print(n-b0[1]+n-a.most_common()[1][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def solve():
    n = int(input())
    v = list(map(int, input().split()))
    evens = v[::2]
    odds = v[1::2]
    d_even, d_odd = defaultdict(int), defaultdict(int)
    for e in evens:
        d_even[e] += 1
    for o in odds:
        d_odd[o] += 1

    # if top_e != top_o:
    #   (e1, o1)
    # else:
    #   (e1, o2) or (e2, o1)
    d_even = sorted(d_even.items(), key=lambda x: x[1])
    d_odd = sorted(d_odd.items(), key=lambda x: x[1])
    e1 = d_even[0]
    try:
        e2 = d_even[1]
    except IndexError:
        e2 = (0, 0)

    o1 = d_odd[0]
    try:
        o2 = d_odd[1]
    except IndexError:
        o2 = (0, 0)

    if e1[0] != o1[0]:
        return n - (e1[1] + o1[1])
    else:
        cand1 = e1[1] + o2[1]
        cand2 = e2[1] + o1[1]
        c = max(cand1, cand2)
        return n - c


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def solve():
    n = int(input())
    v = list(map(int, input().split()))
    evens = v[::2]
    odds = v[1::2]
    d_even, d_odd = defaultdict(int), defaultdict(int)
    for e in evens:
        d_even[e] += 1
    for o in odds:
        d_odd[o] += 1

    # if top_e != top_o:
    #   (e1, o1)
    # else:
    #   (e1, o2) or (e2, o1)
    d_even = sorted(d_even.items(), key=lambda x: x[1])
    d_odd = sorted(d_odd.items(), key=lambda x: x[1])
    e1 = d_even[0]
    try:
        e2 = d_even[1]
    except IndexError:
        e2 = (0, 0)

    o1 = d_odd[0]
    try:
        o2 = d_odd[1]
    except IndexError:
        o2 = (0, 0)

    if e1[0] != o1[0]:
        return n - (e1[1] + o1[1])
    else:
        if len(d_even) == len(d_odd) == 1:
            return n // 2
        if len(d_odd) > 1 and len(d_even) > 1:
            cand1 = e1[1] + o2[1]
            cand2 = e2[1] + o1[1]
            c = max(cand1, cand2)
        elif len(d_odd) > 1:
            c = e1[1] + o2[1]
        elif len(d_even) > 1:
            c = e2[1] + o1[1]
        else:
            return n // 2
        return n - c


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def solve():
    n = int(input())
    v = list(map(int, input().split()))
    evens = v[::2]
    odds = v[1::2]
    d_even, d_odd = defaultdict(int), defaultdict(int)
    for e in evens:
        d_even[e] += 1
    for o in odds:
        d_odd[o] += 1

    # if top_e != top_o:
    #   (e1, o1)
    # else:
    #   (e1, o2) or (e2, o1)
    d_even = sorted(d_even.items(), key=lambda x: x[1])
    d_odd = sorted(d_odd.items(), key=lambda x: x[1])
    if d_even[0][0] != d_odd[0][0]:
        return n - (d_even[0][1] + d_odd[0][1])
    else:
        if len(d_even) == len(d_odd) == 1:
            return n // 2
        if len(d_odd) > 1 and len(d_even) > 1:
            cand1 = d_even[0][1] + d_odd[1][1]
            cand2 = d_even[1][1] + d_odd[0][1]
            c = max(cand1, cand2)
        elif len(d_odd) > 1:
            c = d_even[0][1] + d_odd[1][1]
        elif len(d_even) > 1:
            c = d_even[1][1] + d_odd[0][1]
        else:
            return n // 2
        return n - c


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def solve():
    n = int(input())
    v = list(map(int, input().split()))
    evens = v[::2]
    odds = v[1::2]
    d_even, d_odd = defaultdict(int), defaultdict(int)
    for e in evens:
        d_even[e] += 1
    for o in odds:
        d_odd[o] += 1

    # if top_e != top_o:
    #   (e1, o1)
    # else:
    #   (e1, o2) or (e2, o1)
    d_even = sorted(d_even.items(), key=lambda x: x[1])
    d_odd = sorted(d_odd.items(), key=lambda x: x[1])
    if d_even[0][0] != d_odd[0][0]:
        return len(v) - (d_even[0][1] + d_odd[0][1])
    else:
        if len(d_odd) > 1 and len(d_even) > 1:
            cand1 = d_even[0][1] + d_odd[1][1]
            cand2 = d_even[1][1] + d_odd[0][1]
            c = max(cand1, cand2)
        elif len(d_odd) > 1:
            c = d_even[0][1] + d_odd[1][1]
        elif len(d_even) > 1:
            c = d_even[1][1] + d_odd[0][1]
        else:
            return len(v) // 2
        return len(v) - c


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

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


A=[0]*(10**5)
B=[0]*(10**5)


for i in range(n):
    if i%2==0:
        A[v[i]-1]+=1
    else:
        B[v[i]-1]+=1
x=n//2-max(A)
y=n//2-max(B)
AA=''.join(map(str,A))
BB=''.join(map(str,B))
a=AA.find(str(max(A)))
b=BB.rfind(str(max(B)))
if a!=b:
    print(x+y)
else:
    if len(set(v))==1:
        print(n//2)
    else:
        A.sort()
        B.sort()
        A=A[::-1]
        B=B[::-1]
        for i in range(5):
            if A[i]==B[i]:
                continue
            elif A[i]>B[i]:
                print(sum(A)-A[i]+sum(B)-B[0])
                break
            else:
                print(sum(B)-B[i]+sum(A)-A[0])
                break
        else:
            print(sum(A)-A[1]+sum(B)-B[0])

Submission status: Wrong Answer

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


A=[0]*(10**5)
B=[0]*(10**5)


for i in range(n):
    if i%2==0:
        A[v[i]-1]+=1
    else:
        B[v[i]-1]+=1
x=n//2-max(A)
y=n//2-max(B)
AA=''.join(map(str,A))
BB=''.join(map(str,B))
a=AA.find(str(max(A)))
b=BB.rfind(str(max(B)))
if a!=b:
    print(x+y)
else:
    if len(set(v))==1:
        print(n//2)
    else:
        for i in range(2):
            A=A[::-1]
            B=B[::-1]
            if A[i]==B[i]:
                continue
            elif A[i]>B[i]:
                print(sum(A)-A[i]+sum(B)-B[0])
                break
            else:
                print(sum(B)-B[i]+sum(A)-A[0])
                break
        else:
            print(sum(A)-A[1]+sum(B)-B[0])

Submission status: Wrong Answer

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


A=[0]*(10**5)
B=[0]*(10**5)


for i in range(n):
    if i%2==0:
        A[v[i]-1]+=1
    else:
        B[v[i]-1]+=1
x=n//2-max(A)
y=n//2-max(B)
AA=''.join(map(str,A))
BB=''.join(map(str,B))
a=AA.find(str(max(A)))
b=BB.rfind(str(max(B)))
if a!=b:
    print(x+y)
else:
    if len(set(v))==1:
        print(n//2)
    else:
        for i in range(len(A)):
            A=A[::-1]
            B=B[::-1]
            if A[i]==B[i]:
                continue
            elif A[i]>B[i]:
                print(sum(A)-A[i]+sum(B)-B[0])
                break
            else:
                print(sum(B)-B[i]+sum(A)-A[0])
                break

Submission status: Wrong Answer

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


A=[0]*(10**5)
B=[0]*(10**5)


for i in range(n):
    if i%2==0:
        A[v[i]-1]+=1
    else:
        B[v[i]-1]+=1
x=n//2-max(A)
y=n//2-max(B)
AA=''.join(map(str,A))
BB=''.join(map(str,B))
a=AA.find(str(max(A)))
b=BB.rfind(str(max(B)))
if a!=b:
    print(x+y)
else:
    if A==B:
        print(n//2)

Submission status: Wrong Answer

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


A=[0]*(10**5)
B=[0]*(10**5)


for i in range(n):
    if i%2==0:
        A[v[i]-1]+=1
    else:
        B[v[i]-1]+=1
x=n//2-max(A)
y=n//2-max(B)
AA=''.join(map(str,A))
BB=''.join(map(str,B))
a=AA.find(str(max(A)))
b=BB.rfind(str(max(B)))
if a!=b:
    print(x+y)
if A==B:
    print(n//2)

Submission status: Wrong Answer

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


A=[0]*(10**5)
B=[0]*(10**5)


for i in range(n):
    if i%2==0:
        A[v[i]-1]+=1
    else:
        B[v[i]-1]+=1
x=n//2-max(A)
y=n//2-max(B)
AA=''.join(map(str,A))
BB=''.join(map(str,B))
a=AA.find(str(max(A)))
b=BB.rfind(str(max(B)))
if a!=b:
    print(x+y)

Submission status: Wrong Answer

Solution code:
import sys

from collections import Counter

n = int(input())

v = []
v1 = []
v2 = []

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

for i in range(int(n/2)):
    v1.append(v[2*i])
    v2.append(v[2*i+1])

e = Counter(v1)
o = Counter(v2)

ee = e.most_common(2)
oo = o.most_common(2)

if ee[0][0] != oo[0][0]:
    print(n - (ee[0][1]+oo[0][1]))
    sys.exit()

if ee[0][0] == oo[0][0]:
    if len(ee) == 1 and len(oo) == 1:
        print(n - (ee[0][1]))
        sys.exit()

    if len(ee) == 1:
        print(n - (ee[0][1]+oo[1][1]))
        sys.exit()

    if len(oo) == 1:
        print(n - (ee[1][1]+oo[0][1]))
        sys.exit()

    if ee[0][1] == oo[0][1]:
        print(n - (ee[0][1] + min(ee[1][1],oo[1][1])))
    
    if ee[0][1] > oo[0][1]:
        print(n - (ee[0][1]+oo[1][1]))
        sys.exit()
    else:
        print(n - (ee[1][1]+oo[0][1]))
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys

from collections import Counter

n = int(input())

v = []
v1 = []
v2 = []

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

for i in range(int(n/2)):
    v1.append(v[2*i])
    v2.append(v[2*i+1])

e = Counter(v1)
o = Counter(v2)

ee = e.most_common(2)
oo = o.most_common(2)

if ee[0][0] != oo[0][0]:
    print(n - (ee[0][1]+oo[0][1]))
    sys.exit()

if ee[0][0] == oo[0][0]:
    if len(ee) == 1 and len(oo) == 1:
        print(n - (ee[0][1]))
        sys.exit()

    if len(ee) == 1:
        print(n - (ee[0][1]+oo[1][1]))
        sys.exit()

    if len(oo) == 1:
        print(n - (ee[1][1]+oo[0][1]))
        sys.exit()

    if ee[0][1] == oo[0][1]:
        print(n - (ee[0][1] + max(ee[1][1],oo[1][1])))
    
    if ee[0][1] > oo[0][1]:
        print(n - (ee[0][1]+oo[1][1]))
        sys.exit()
    else:
        print(n - (ee[1][1]+oo[0][1]))
        sys.exit()

Submission status: Wrong Answer

Solution code:
import sys

from collections import Counter

n = int(input())

v = []
v1 = []
v2 = []

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

for i in range(int(n/2)):
    v1.append(v[2*i])
    v2.append(v[2*i+1])

e = Counter(v1)
o = Counter(v2)

ee = e.most_common(2)
oo = o.most_common(2)

if ee[0][0] != oo[0][0]:
    print(n - (ee[0][1]+oo[0][1]))
    sys.exit()

if ee[0][0] == oo[0][0]:
    if len(ee) == 1 and len(oo) == 1:
        print(n - (ee[0][1]))
        sys.exit()

    if len(ee) == 1:
        print(n - (ee[0][1]+oo[1][1]))
        sys.exit()

    if len(oo) == 1:
        print(n - (ee[1][1]+oo[0][1]))
        sys.exit()

    if ee[0][1] >= oo[0][1]:
        print(n - (ee[0][1]+oo[1][1]))
        sys.exit()
    else:
        print(n - (ee[1][1]+oo[0][1]))
        sys.exit()

Submission status: Wrong Answer

Solution code:
N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}
for i in range(N):
    if i%2==0:#even
        if lv[i] in dev:
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
    else:#odd
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1

max1_ev=[0,0]
max2_ev=[0,0]
max1_od=[0,0]
max2_od=[0,0]
#for i in range(len(dev)):
for v in dev:#max even
    if dev[v]>max1_ev[1]:
        max1_ev=[v,dev[v]]
    elif dev[v]>max2_ev[1]:
        max2_ev=[v,dev[v]]
for v in dod:#max odd
    if dod[v]>max1_od[1]:
        max1_od=[v,dod[v]]
    elif dod[v]>max2_od[1]:
        max2_od=[v,dod[v]]
if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
else:
    print(min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

from collections import Counter

def cnt_mode(v1, v2, n, mode1, mode2):
    cc1 = 0
    cc2 = 0
    for i in range(int(n/2)):
        if v1[i] == int(mode1):
            cc1 += 1
        if v2[i] == int(mode2):
            cc2 += 1
    return n-(cc1+cc2)


n = int(input())

v = np.array([])
v1 = np.array([], dtype=np.int64)
v2 = np.array([], dtype=np.int64)

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

for i in range(int(n/2)):
    v1 = np.append(v1, v[2*i])
    v2 = np.append(v2, v[2*i+1])

e = Counter(v1)
o = Counter(v2)

ee = e.most_common(2)
oo = o.most_common(2)

print(oo)
print(ee)

if ee[0][0] != oo[0][0]:
    mode2 = oo[0][0]
    mode1 = ee[0][0]
    print(cnt_mode(v1, v2, n, mode1, mode2))
    sys.exit()

if ee[0][0] == oo[0][0]:
    if len(ee) == 1 and len(oo) == 1:
        mode2 = int(ee[0][0]) + 1
        mode1 = ee[0][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()

    if len(ee) == 1:
        mode2 = ee[0][0]
        mode1 = oo[1][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()

    if len(oo) == 1:
        mode2 = ee[1][0]
        mode1 = oo[0][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()

    if ee[0][1] >= oo[0][1]:
        mode2 = ee[0][0]
        mode1 = oo[1][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()
    else:
        mode2 = ee[1][0]
        mode1 = oo[0][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

from collections import Counter

def cnt_mode(v1, v2, n, mode1, mode2):
    cc1 = 0
    cc2 = 0
    for i in range(int(n/2)):
        print(i, v1[i], mode1, v2[i], mode2)
        if v1[i] == int(mode1):
            cc1 += 1
        if v2[i] == int(mode2):
            cc2 += 1
    print('cc1', cc1)
    print('cc2', cc2)
    return n-(cc1+cc2)


n = int(input())

v = np.array([])
v1 = np.array([], dtype=np.int64)
v2 = np.array([], dtype=np.int64)

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

for i in range(int(n/2)):
    v1 = np.append(v1, v[2*i])
    v2 = np.append(v2, v[2*i+1])

e = Counter(v1)
o = Counter(v2)

ee = e.most_common(2)
oo = o.most_common(2)

print(oo)
print(ee)

if ee[0][0] != oo[0][0]:
    mode2 = oo[0][0]
    mode1 = ee[0][0]
    print(cnt_mode(v1, v2, n, mode1, mode2))
    sys.exit()

if ee[0][0] == oo[0][0]:
    if len(ee) == 1 and len(oo) == 1:
        mode2 = int(ee[0][0]) + 1
        mode1 = ee[0][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()

    if len(ee) == 1:
        mode2 = ee[0][0]
        mode1 = oo[1][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()

    if len(oo) == 1:
        mode2 = ee[1][0]
        mode1 = oo[0][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()

    if ee[0][1] >= oo[0][1]:
        mode2 = ee[0][0]
        mode1 = oo[1][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()
    else:
        mode2 = ee[1][0]
        mode1 = oo[0][0]
        print(cnt_mode(v1, v2, n, mode1, mode2))
        sys.exit()

Submission status: Wrong Answer

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

a = {}
for i in range(0, len(v), 2):
    a[v[i]] = a.get(v[i], 0) + 1

b = {}
for i in range(1, len(v), 2):
    b[v[i]] = b.get(v[i], 0) + 1

sorted_a = sorted(a.items(), reverse=True, key=lambda x: x[1])
sorted_b = sorted(b.items(), reverse=True, key=lambda x: x[1])

res = 0
if sorted_a[0][0] == sorted_b[0][0]:
    if sorted_a[0][1] >= sorted_b[0][1]:
        if len(sorted_b) > 1:
            sorted_b[0], sorted_b[1] = sorted_b[1], sorted_b[0]
        else:
            res += sorted_b[0][1]
            
    else:
        if len(sorted_a) > 1:
            sorted_a[0], sorted_a[1] = sorted_a[1], sorted_a[0]
        else:
            res += sorted_a[0][1]

res += len(v) - sorted_a[0][1] - sorted_b[0][1]

print(res)

Submission status: Wrong Answer

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

a = {}
for i in range(0, len(v), 2):
    a[v[i]] = a.get(v[i], 0) + 1

b = {}
for i in range(1, len(v), 2):
    b[v[i]] = b.get(v[i], 0) + 1

sorted_a = sorted(a.items(), reverse=True, key=lambda x: x[1])
sorted_b = sorted(b.items(), reverse=True, key=lambda x: x[1])

res = 0
if sorted_a[0][0] == sorted_b[0][0]:
    if sorted_a[0][1] >= sorted_b[0][1]:
        if len(sorted_b) > 1:
            sorted_b[0], sorted_b[1] = sorted_b[1], sorted_b[0]
        else:
            res += sorted_b[0][1]
            
    else:
        if len(sorted_a) > 1:
            sorted_a[0], sorted_a[1] = sorted_a[1], sorted_a[0]
        else:
            res += sorted_a[0][1]

for i in range(len(sorted_a)):
    if i == 0:
        continue
    res += sorted_a[i][1]
for i in range(len(sorted_b)):
    if i == 0:
        continue
    res += sorted_b[i][1]

print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}
#cev=0#devの種類数
#cod=0#dodの種類数
max1_ev=[0,0]#数字,個数
max2_ev=[0,0]
max1_od=[0,0]#数字,個数
max2_od=[0,0]

for i in range(N):
    if i%2==0:#even
        #max1_ev=[0,0]#数字,個数
        #max2_ev=[0,0]
        #毎回初期化していた！！

        if lv[i] in dev:#辞書の更新
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
            #maxの更新
            #cev+=1
            #if cev==1:
            #    max1_ev=[i,lv[i]]
            #elif cev==2:
            #    max2_ev=[i,lv[i]]
        ##3種目以降
        #最大個数の更新
        if dev[lv[i]]>max1_ev[1]:
            max1_ev=[lv[i],dev[lv[i]]]
        #elif dev[lv[i]]>max2_ev[1]:
        elif dev[lv[i]]>=max2_ev[1]:
            max2_ev=[lv[i],dev[lv[i]]]
        #print("dev[lv[i]]",dev[lv[i]])
        #print("max1__ev[1]",max1_ev[1])
        #print("max1_ev",max1_ev)
        #print("max2_ev",max2_ev)
        #if i==0:
        #    max1=[0,1]
        #elif i==1:
        #    max2
    else:#odd
        #max1_od=[0,0]
        #max2_od=[0,0]
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1
        if dod[lv[i]]>max1_od[1]:
            max1_od=[lv[i],dod[lv[i]]]
        #elif dod[lv[i]]>max2_od[1]:
        elif dod[lv[i]]>=max2_od[1]:
            max2_od=[lv[i],dod[lv[i]]]
print("dev",dev)#ok
print("dod",dod)#ok
print("max1_ev",max1_ev)
print("max2_ev",max2_ev)


#if len(dev)==1 and len(dod)==1:
#    print(int(N/2))
#elif len(dev)==1:
    #for i in range(len(dod)):
    #    if i==0:
    #        max1_od=
#    if max1_ev[0]!=max1_od[0]:
#        print(N-max1_ev[1]-max1_od[1])
##        print(max)
if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
elif len(dev)==1 and len(dod)==1:
    print(int(N/2))
elif len(dev)==1:
    print(int(N/2)-max2_od[1])
elif len(dod)==1:
    print(int(N/2)-max2_ev[1])
else:
    #print(max(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))#minをmaxとしていた
    print(min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}
#cev=0#devの種類数
#cod=0#dodの種類数
for i in range(N):
    if i%2==0:#even
        max1_ev=[0,0]#数字,個数
        max2_ev=[0,0]
        if lv[i] in dev:#辞書の更新
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
            #maxの更新
            #cev+=1
            #if cev==1:
            #    max1_ev=[i,lv[i]]
            #elif cev==2:
            #    max2_ev=[i,lv[i]]
        ##3種目以降
        #最大個数の更新
        if dev[lv[i]]>max1_ev[1]:
            max1_ev=[lv[i],dev[lv[i]]]
        elif dev[lv[i]]>max2_ev[1]:
            max2_ev=[lv[i],dev[lv[i]]]

        #if i==0:
        #    max1=[0,1]
        #elif i==1:
        #    max2
    else:#odd
        max1_od=[0,0]
        max2_od=[0,0]
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1
        if dod[lv[i]]>max1_od[1]:
            max1_od=[lv[i],dod[lv[i]]]
        elif dod[lv[i]]>max2_od[1]:
            max2_od=[lv[i],dod[lv[i]]]


#if len(dev)==1 and len(dod)==1:
#    print(int(N/2))
#elif len(dev)==1:
    #for i in range(len(dod)):
    #    if i==0:
    #        max1_od=
#    if max1_ev[0]!=max1_od[0]:
#        print(N-max1_ev[1]-max1_od[1])
##        print(max)
if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
elif len(dev)==1 and len(dod)==1:
    print(int(N/2))
elif len(dev)==1:
    print(int(N/2)-max2_od[1])
elif len(dod)==1:
    print(int(N/2)-max2_ev[1])
else:
    #print(max(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))
    print(min(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
lv=list(map(int,input().split()))
dev={}
dod={}
#cev=0#devの種類数
#cod=0#dodの種類数
for i in range(N):
    if i%2==0:#even
        max1_ev=[0,0]#数字,個数
        max2_ev=[0,0]
        if lv[i] in dev:#辞書の更新
            dev[lv[i]]+=1
        else:
            dev[lv[i]]=1
            #maxの更新
            #cev+=1
            #if cev==1:
            #    max1_ev=[i,lv[i]]
            #elif cev==2:
            #    max2_ev=[i,lv[i]]
        ##3種目以降
        #最大個数の更新
        if dev[lv[i]]>max1_ev[1]:
            max1_ev=[lv[i],dev[lv[i]]]
        elif dev[lv[i]]>max2_ev[1]:
            max2_ev=[lv[i],dev[lv[i]]]

        #if i==0:
        #    max1=[0,1]
        #elif i==1:
        #    max2
    else:#odd
        max1_od=[0,0]
        max2_od=[0,0]
        if lv[i] in dod:
            dod[lv[i]]+=1
        else:
            dod[lv[i]]=1
        if dod[lv[i]]>max1_od[1]:
            max1_od=[lv[i],dod[lv[i]]]
        elif dod[lv[i]]>max2_od[1]:
            max2_od=[lv[i],dod[lv[i]]]


#if len(dev)==1 and len(dod)==1:
#    print(int(N/2))
#elif len(dev)==1:
    #for i in range(len(dod)):
    #    if i==0:
    #        max1_od=
#    if max1_ev[0]!=max1_od[0]:
#        print(N-max1_ev[1]-max1_od[1])
##        print(max)
if max1_ev[0]!=max1_od[0]:
    print(N-max1_ev[1]-max1_od[1])
elif len(dev)==1 and len(dod)==1:
    print(int(N/2))
elif len(dev)==1:
    print(int(N/2)-max2_od[1])
elif len(dod)==1:
    print(int(N/2)-max2_ev[1])
else:
    print(max(N-max1_ev[1]-max2_od[1],N-max2_ev[1]-max1_od[1]))