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 deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
v = RI()

ans1 = 0
ans2 = 0

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

ac = Counter(a)
bc = Counter(b)

ma = 0
mb = 0

for i in ac:
    if ma<ac[i]:
        ma = ac[i]
        no1 = i
    else:
        pass

for i in bc:
    if mb<bc[i] and i!=no1:
        mb = bc[i]
        no2 = i
    else:
        pass

ans1 += len(a) - ma
ans1 += len(b) - mb

ma = 0
mb = 0

for i in bc:
    if ma<bc[i]:
        mb = bc[i]
        no2 = i
    else:
        pass

for i in ac:
    if ma<ac[i] and i!=no2:
        ma = ac[i]
        no1 = i
    else:
        pass

ans2 += len(a) - ma
ans2 += len(b) - mb

print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
v_list = list(map(int,input().split()))
v_list_odd = v_list[::2]
v_list_ev = v_list[1::2]
import collections
c_odd = collections.Counter(v_list_odd)
c_even = collections.Counter(v_list_ev)

c_odd = sorted(c_odd.items(),reverse = True)
c_even = sorted(c_even.items(),reverse = True)

if c_odd[0][0] != c_even[0][0]:
  print(n - c_odd[0][1] - c_even[0][1])
else:
  if len(c_odd) == 1 and len(c_even) == 1:
    print(n - c_odd[0][1])
  elif len(c_odd) == 1:
    print(n - c_odd[0][1] - c_even[1][1])
  elif len(c_even) == 1:
    print(n - c_odd[1][1] - c_even[0][1])
  else:
    print(n - max(c_odd[1][1] + c_even[0][1],c_odd[0][1] + c_even[1][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

V_even = V[: : 2]
V_odd = V[1: : 2]

D_even = Counter(V_even)
D_odd = Counter(V_odd)

ans = 0
even, odd = D_even.most_common(2), D_odd.most_common(2)
even_key, odd_key = even[0][0], odd[0][0]
if even_key != odd_key:
    ans = n - D_even[even_key] - D_odd[odd_key]
else:
    if len(D_even) == len(D_odd) == 1:
        ans = n // 2
    else:
        if D_even[even[1][0]] < D_odd[odd[1][0]]:
            even_key = even[1][0]
            ans = n - D_even[even_key] - D_odd[odd_key]
        else:
            odd_key = odd[1][0]
            ans = n - D_even[even_key] - D_odd[odd_key]

print(ans)

Submission status: Wrong Answer

Solution code:
def count(l):
    odd = {}
    even = {}
    for idx, d in enumerate(l):
        if idx%2 == 0:
            res = even
        else:
            res = odd
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return odd, even
n = int(input())
data = list(map(int, input().split()))
odd, even = count(data)
odd = sorted(odd.items(), key=lambda x:-x[1])
even = sorted(even.items(), key=lambda x:-x[1])
if len(odd) == 1 and len(even) == 1:
    if odd[0][0] != even[0][0]:
        print(0)
    else:
        print(min(odd[0][1], even[0][1]))
else:
    size = n//2
    o_idx = 0
    e_idx = 0
    if odd[0][0] == even[0][0]:
        if odd[0][1] >= even[0][1]:
            e_idx += 1
        else:
            o_idx += 1
    ans = size - odd[o_idx][1] + size - even[e_idx][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
def count(l):
    odd = {}
    even = {}
    for idx, d in enumerate(l):
        if idx%2 == 0:
            res = even
        else:
            res = odd
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return odd, even
n = int(input())
data = list(map(int, input().split()))
odd, even = count(data)
odd = sorted(odd.items(), key=lambda x:x[1])
even = sorted(even.items(), key=lambda x:x[1])
if len(odd) == 1 and len(even) == 1:
    if odd[0][0] != even[0][0]:
        print(0)
    else:
        print(min(odd[0][1], even[0][1]))
else:
    ans = 0
    if odd[0][0] != even[0][0]:
        ans += n//2 - odd[0][1] + n//2 - even[0][1]
    else:
        if odd[0][1] >= even[0][1]:
            ans += n//2 - odd[0][1]
            ans += n//2 - even[1][1]
        else:
            ans += n//2 - even[0][1]
            ans += n//2 - odd[1][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
odd = []
even = []
for i in range(N):
    if i % 2 == 1:
        odd.append(A[i])
    else:
        even.append(A[i])
Dic_odd = collections.Counter(odd)
Dic_eve = collections.Counter(even)
M_odd = Dic_odd.most_common()
M_eve = Dic_eve.most_common()
#print(M_odd, M_eve)
if M_odd[0][0] != M_eve[0][0]:
    ans = len(odd) - M_odd[0][1] + len(even) - M_eve[0][1]
else:
    if len(M_odd) == 1 and len(M_eve) == 1:
        ans = min(len(odd), len(even))
    elif len(M_odd) == 1:
        ans = min(len(even) - M_eve[1][1], len(even) - M_eve[0][1] + len(odd))
    elif len(M_eve) == 1:
        ans = min(len(odd) - M_odd[1][1], len(odd) - M_odd[0][1] + len(even))
    else:
        ans = len(odd) + len(even) - min(M_odd[0][1] + M_eve[1][1], M_odd[1][1] + M_eve[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
odd = []
even = []
for i in range(N):
    if i % 2 == 1:
        odd.append(A[i])
    else:
        even.append(A[i])
Dic_odd = collections.Counter(odd)
Dic_eve = collections.Counter(even)
M_odd = Dic_odd.most_common()
M_eve = Dic_eve.most_common()
#print(M_odd, M_eve)
if M_odd[0][0] != M_eve[0][0]:
    ans = len(odd) - M_odd[0][1] + len(even) - M_eve[0][1]
else:
    if len(M_odd) == 1 and len(M_eve) == 1:
        ans = min(len(odd), len(even))
    elif len(M_odd) == 1:
        ans = len(odd) + len(even) - M_odd[0][1] - M_eve[1][1]
    elif len(M_eve) == 1:
        ans = len(odd) + len(even) - M_odd[1][1] - M_eve[0][1]
    else:
        ans = len(odd) + len(even) - min(M_odd[0][1] + M_eve[1][1], M_odd[1][1] + M_eve[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v2 = set(v)
if len(v2)==1:
    print(n//2)
else:
    v_o = v[0::2]
    v_e = v[1::2]
    c1 = dict(Counter(v_o))
    c2 = dict(Counter(v_e))
    cnt = 0
    if len(c2)!=1:
        min = 10**5
        for i,(k,v) in enumerate(c2.items()):
            if min>v:
                min = v
        else:
            cnt+=min
    elif len(c1)!=1:
        min = 10**5
        for i,(k,v) in enumerate(c1.items()):
            if min>v:
                min = v
        else:
            cnt+=min
    print(cnt)

Submission status: Wrong Answer

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

d1 = [0]*(10**5+1)
d2 = [0]*(10**5+1)
for i in range(n):
    if i%2: d2[v[i]] += 1
    else: d1[v[i]] += 1
        
max_d1 = [0, 0]
max_d2 = [0, 0]
submax_d1 = [0, 0]
submax_d2 = [0, 0]
for i in range(10**5+1):
    if max_d1[1] < d1[i]:
        submax_d1 = deepcopy(max_d1)
        max_d1[0] = i
        max_d1[1] = d1[i]
    if max_d2[1] < d2[i]:
        submax_d2 = deepcopy(max_d2)
        max_d2[0] = i
        max_d2[1] = d2[i]
if max_d1[0] == max_d2[0]:
    if max_d1[1] + submax_d2[1] > max_d2[1]+submax_d1[1]:
        print(n-max_d1[1]-submax_d2[1])
    else:
        print(n-max_d2[1]-submax_d1[1])
else:
    print(n-max_d1[1]-max_d2[1])

Submission status: Wrong Answer

Solution code:
# C - /\/\/\/

from collections import defaultdict
import sys
readline = sys.stdin.readline

n = int(readline())
v = list(int(x) for x in readline().split())

d = defaultdict(int)

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

d = list(d.items())
d.sort(key=lambda x: x[1], reverse=True)

flg0 = 0
flg1 = 0
cnt0 = 0
cnt1 = 0
tmpkey = 0
for (i, key), cnt in d:
    if i == 0:
        if flg0 == 0:
            if tmpkey != key:
                flg0 = 1
                tmpkey = key
                cnt0 = cnt
        else:
            continue
    else:
        if flg1 == 0:
            if tmpkey != key:
                flg1 = 1
                tmpkey = key
                cnt1 = cnt
        else:
            continue

print(n - cnt0 - cnt1)

Submission status: Wrong Answer

Solution code:
# C - /\/\/\/

from collections import defaultdict
import sys
readline = sys.stdin.readline

n = int(readline())
v = list(int(x) for x in readline().split())

d = defaultdict(int)

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

d = list(d.items())
d.sort(key=lambda x: x[1], reverse=True)

flg0 = 0
flg1 = 0
ans = 0
tmpkey = 0
for (i, key), cnt in d:
    if i == 0:
        if flg0 == 0:
            if tmpkey != key:
                flg0 = 1
                tmpkey = key
                ans += n//2 - cnt
        else:
            continue
    else:
        if flg1 == 0:
            if tmpkey != key:
                flg1 = 1
                tmpkey = key
                ans += n//2 - cnt
        else:
            continue

print(ans)

Submission status: Wrong Answer

Solution code:
# C - /\/\/\/

from collections import Counter
import sys
readline = sys.stdin.readline

n = int(readline())
v = list(int(x) for x in readline().split())

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

v0c = Counter(v0)
v1c = Counter(v1)

v0val, v0cnt = v0c.most_common()[0]
v1val, v1cnt = v1c.most_common()[0]

if v0val == v1val:
    if v0cnt > v1cnt and v1cnt != n//2:
        v1val, v1cnt = v1c.most_common()[1]
    elif v0cnt <= v1cnt and v0cnt != n//2:
        v0val, v0cnt = v0c.most_common()[1]

ans = n//2 - v0cnt + n//2 - v1cnt
print(ans)

Submission status: Wrong Answer

Solution code:
# C - /\/\/\/

from collections import Counter
import sys
readline = sys.stdin.readline

n = int(readline())
v = list(int(x) for x in readline().split())

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

v0c = Counter(v0)
v1c = Counter(v1)

v0val, v0cnt = v0c.most_common()[0]
v1val, v1cnt = v1c.most_common()[0]

if v0val == v1val:
    if v0cnt > v1cnt and v1cnt != n//2:
        v1val, v1cnt = v1c.most_common()[1]
    elif v0cnt <= v1cnt and v0cnt != n//2:
        v0val, v1cnt = v0c.most_common()[1]

ans = n//2 - v0cnt + n//2 - v1cnt
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

V_even = V[: : 2]
V_odd = V[1: : 2]

D_even = Counter(V_even)
D_odd = Counter(V_odd)

ans = 0
even_keys, odd_keys = list(D_even.keys()), list(D_odd.keys())
if even_keys[0] != odd_keys[0]:
    ans = n - D_even[even_keys[0]] - D_odd[odd_keys[0]]
else:
    if len(D_even) == len(D_odd) == 1:
        ans = n // 2
    elif len(D_even) == 1:
        ans = n - D_even[even_keys[0]] - D_odd[odd_keys[1]]
    elif len(D_odd) == 1:
        ans = n - D_even[even_keys[1]] - D_odd[odd_keys[0]]
    else:
        if D_even[even_keys[1]] < D_odd[odd_keys[1]]:
            ans = n - D_even[even_keys[1]] - D_odd[odd_keys[0]]
        else:
            ans = n - D_even[even_keys[0]] - D_odd[odd_keys[1]]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

V_even = V[: : 2]
V_odd = V[1: : 2]

D_even = Counter(V_even)
D_odd = Counter(V_odd)

max_even_key, _ = max(D_even.items(), key=lambda x: x[1])
max_odd_key, _ = max(D_odd.items(), key=lambda x: x[1])

ans = 0
if max_even_key != max_odd_key:
    ans = n - D_even[max_even_key] - D_odd[max_odd_key]
else:
    if len(D_even) == len(D_odd) == 1:
        ans = n // 2
    else:
        pass

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
from collections import Counter
v_odd=Counter([v[i] for i in range(n) if i%2==0])
v_eve=Counter([v[i] for i in range(n) if i%2==1])
v_odd_max=-1
v_odd_max_p=-1
v_eve_max=-1
v_eve_max_p=-1
v_eve[-1]=0
v_odd[-1]=0
for k in v_odd:
  if v_odd[k]>=v_odd[v_odd_max]:
    v_odd_max,v_odd_max_p=k,v_odd_max

for k in v_eve:
  if v_eve[k]>=v_eve[v_eve_max]:
    v_eve_max,v_eve_max_p=k,v_eve_max

if v_eve_max!=v_odd_max:
  print(n-v_eve[v_eve_max]-v_odd[v_odd_max])
else:
  ans0=n-v_eve[v_eve_max]-v_odd[v_odd_max_p]
  ans1=n-v_eve[v_eve_max_p]-v_odd[v_odd_max]
  print(min(ans0,ans1))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
from collections import Counter
v_odd=Counter([v[i] for i in range(n) if i%2==0])
v_eve=Counter([v[i] for i in range(n) if i%2==1])
v_odd_max=-1
v_odd_max_p=-1
v_eve_max=-1
v_eve_max_p=-1
v_eve[-1]=0
v_odd[-1]=0
for k in v_odd:
  if v_odd[k]>v_odd[v_odd_max]:
    v_odd_max,v_odd_max_p=k,v_odd_max

for k in v_eve:
  if v_eve[k]>v_eve[v_eve_max]:
    v_eve_max,v_eve_max_p=k,v_eve_max

if v_eve_max!=v_odd_max:
  print(n-v_eve[v_eve_max]-v_odd[v_odd_max])
else:
  ans0=n-v_eve[v_eve_max]-v_odd[v_odd_max_p]
  ans1=n-v_eve[v_eve_max_p]-v_odd[v_odd_max]
  print(min(ans0,ans1))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

odd = sorted(Counter(v[0:n:2]).items(), key=lambda x: x[1])
even = sorted(Counter(v[1:n+1:2]).items(), key=lambda x: x[1])

if odd[0][0] != even[0][0]:
    res = n - odd[0][1] - even[0][1]
elif len(odd) == 1:
    res = odd[0][1]
else:
    if odd[0][1] == even[0][1]:
        if odd[1][1] >= even[1][1]:
            res = n - odd[1][1] - even[0][1]
        else:
            res = n - odd[0][1] - even[1][1]
    elif odd[0][1] > even[0][1]:
        res = n - odd[0][1] - even[1][1]
    else:
        res = n - odd[1][1] - even[0][1]

print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = input().split()
v1 = Counter(v[::2]).most_common()
v2 = Counter(v[1::2]).most_common()

if v1[0][0] != v2[0][0]:
    print(n - (v1[0][1] + v2[0][1]))
elif v1[0] == v2[0]:
    print(n // 2)
elif v1[0][1] == v2[0][1]:
    print(n - max(v1[1][1], v2[1][1]))
else:
    if v1[0][1] > v2[0][1]:
        print(n - v1[0][1] + n - v2[1][1])
    elif v1[0][1] < v2[0][1]:
        print(n - v1[1][1] + n - v2[0][1])

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter 
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    if len(set(a)) == 1: 
        print(n//2)
        return
    odd = Counter(a[::2]).most_common(2)
    even = Counter(a[1::2]).most_common(2)
    odd.append((0, 0))
    even.append((0, 0))
    if odd[0][0] == even[0][0]:
        print(min(n-odd[1][1]-even[0][1], n-odd[0][1]-even[1][0]))
        return
    print(n-odd[0][1]-even[0][1])
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter 
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    if len(set(a)) == 1: 
        print(n//2)
        return
    odd = Counter(a[::2]).most_common(2)
    even = Counter(a[1::2]).most_common(2)
    if ((len(odd) == 1) and (len(even) == 1)) and (odd[0][1] == even[0][1]):
        print(n-odd[0][1]-even[0][1]) 
        return
    if odd[0][1] == even[0][1]:
        ans = min(n - odd[1][1] - even[0][1], n - odd[0][1] - even[1][1])
        print(ans)
        return
    print(n - odd[0][1] - even[0][1])
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = input().split()

v1 = Counter(v[::2]).most_common()
v2 = Counter(v[1::2]).most_common()
a = len(v[::2]) - v1[0][1]
if v1 == v2:
    a += len(v[1::2]) if len(v2) == 1 else (len(v[1::2]) - v2[1][1])
else:
    a += len(v[1::2]) - v2[0][1]
print(a)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter 
from itertools import repeat
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    if len(set(a)) == 1: 
        print(n//2)
        return
    odd = Counter(a[::2]).most_common(1)
    even = Counter(a[1::2]).most_common(1)
    print(n - odd[0][1] - even[0][1])
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter 
from itertools import repeat
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    if len(set(a)) == 1: 
        print(n//2)
        return
    dd = []
    for i in range(0, n-1, 2):
        dd.append((a[i], a[i+1]))
    dd = Counter(dd)
    mx = 0
    mxKey = (0, 0)
    for key, val in dd.items():    
        if val > mx:
            mxKey = key
    cnt = 0
    for i in range(0, n-1, 2):
        x, y = mxKey
        if a[i] != x:
            cnt += 1
        if a[i+1] != y:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

n = int(input())
v_list = [int(i) for i in input().split()]
#
# print(v_list[0::2])
# print(v_list[1::2])

odd_set = set(v_list[0::2])
even_set = set(v_list[1::2])

if even_set == odd_set:
    print(int(n / 2))
else:
    print(len(odd_set) + len(even_set) - 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
L = list(map(int, input().split()))
L1 = L[::2]
L2 = L[1::2]
c1 = Counter(L1).most_common()
c2 = Counter(L2).most_common()
if len(set(L1)) == len(set(L2)) == 1:
    if L1[0] == L2[0]:
        print(len(L1))
    else:
        print(0)
else:
    if c1[0][0] != c2[0][0]:
        print(n - c1[0][1] - c2[0][1])
    else:
        if c1[0][1] >= c2[0][1]:
            print(n - c1[0][1] - c2[1][1])
        else:
            print(n - c1[1][1] - c2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
L = list(map(int, input().split()))
L1 = L[::2]
L2 = L[1::2]
c1 = Counter(L1).most_common()
c2 = Counter(L2).most_common()
if len(set(L1)) == len(set(L2)) == 1:
    if L1[0] == L2[0]:
        print(len(L1))
    else:
        print(0)
elif len(set(L1)) == 1:
    if c2[0][0] != L1[0]:
        print(len(L2) - c2[0][1])
    else:
        print(len(L2) - c2[1][1])
elif len(set(L2)) == 1:
    if c1[0][0] != L2[0]:
        print(len(L1) - c1[0][1])
    else:
        print(len(L1) - c1[1][1])
else:
    if c1[0][0] != c2[0][0]:
        print(len(L1) - c1[0][1] + len(L2) - c2[0][1])
    else:
        if c1[0][1] >= c2[0][1]:
            print(len(L1) - c1[0][1] + len(L2) - c2[1][1])
        else:
            print(len(L1) - c1[1][1] + len(L2) - c2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1 = [v[i] for i in range(n) if i % 2 == 0]
v2 = [v[i] for i in range(n) if i % 2 != 0]

c1 = Counter(v1)
c2 = Counter(v2)

c1 = sorted(c1.items(), key=lambda x:(x[1], -x[0]), reverse=True)
c2 = sorted(c2.items(), key=lambda x:(x[1], -x[0]), reverse=True)
print(c1, c2)
ans = 0
if c1[0][0] != c2[0][0]:
    if len(c1) != 1:
        for k, v in c1[1:]:
            ans += v
    if len(c2) != 1:
        for k, v in c2[1:]:
            ans += v
    print(ans)
else:
    if len(c1) == 1 and len(c2) == 1:
        ans += n // 2
    elif len(c1) == 1 and len(c2) > 1:
        ans += len(v2) - c2[1][1]
    elif len(c1) > 1 and len(c2) == 1:
        ans += len(v1) - c1[1][1]
    else:
        if c1[1][1] < c2[1][1]:
            ans += len(v1) - c1[0][1]
            ans += len(v2) - c2[1][1]
        else:
            ans += len(v1) - c1[1][1]
            ans += len(v2) - c2[0][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1 = [v[i] for i in range(n) if i % 2 == 0]
v2 = [v[i] for i in range(n) if i % 2 != 0]

c1 = Counter(v1)
c2 = Counter(v2)

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

ans = 0
if c1[0][0] != c2[0][0]:
    if len(c1) != 1:
        for k, v in c1[1:]:
            ans += v
    if len(c2) != 1:
        for k, v in c2[1:]:
            ans += v
    print(ans)
else:
    if len(c1) <= len(c2):
        if len(c1) != 1:
            for k, v in c1[1:]:
                ans += v
        if len(c2) == 1:
            ans += len(v2)
        else:
            ans += len(v2)-c2[1][1]
        print(ans)
    else:
        if len(c2) != 1:
            for k, v in c2[1:]:
                ans += v
        if len(c1) == 1:
            ans += len(v1)
        else:
            ans += len(v1)-c1[1][1]
        print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

c1 = Counter(v1)
c2 = Counter(v2)

c1 = c1.most_common()
c2 = c2.most_common()

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
elif c1[0][0] + c2[0][1] >= c2[0][0] + c1[0][1]:
    ans = n - c1[0][0] - c2[0][1]
else:
    ans = n - c2[0][0] - c1[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

c1 = Counter(v1)
c2 = Counter(v2)

c1 = c1.most_common()
c2 = c2.most_common()

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
elif c1[0][0] + c2[0][1] >= c2[0][0] + c1[0][1]:
    ans = n - c1[0][0] + c2[0][1]
else:
    ans = n - c2[0][0] + c1[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

c1 = Counter(v1)
c2 = Counter(v2)

c1 = list(c1.items())
c2 = list(c2.items())

c1.sort(key=lambda x: x[1], reverse=True)
c2.sort(key=lambda x: x[1], reverse=True)

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
elif c1[0][1] >= c2[0][1]:
    if len(c2) == 1:
        ans = n - c1[0][1]
    else:
        ans = n - c1[0][1] - c2[1][1]
else:
    if len(c1) == 1:
        ans = n - c2[0][1]
    else:
        ans = n - c2[0][1] - c1[1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

c1 = Counter(v1)
c2 = Counter(v2)

c1 = list(c1.items())
c2 = list(c2.items())

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
elif c1[0][1] >= c2[0][1]:
    if len(c2) == 1:
        ans = n - c1[0][1]
    else:
        ans = n - c1[0][1] - c2[1][1]
else:
    if len(c1) == 1:
        ans = n - c2[0][1]
    else:
        ans = n - c2[0][1] - c1[1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# check
if len(set(v)) == 1:
    print(len(v[::2]))
elif len(set(v[::2])) == 1 and len(set(v[1::2])) == 1:
    print(0)
else:
    a = v[::2]
    b = v[1::2]

    change_cnt = 0
    if len(set(a)) > 1:
        change_cnt += sum(
            [
                c
                for al, c in Counter(a).most_common()[1:]
            ]
        )
    if len(set(b)) > 1:
        change_cnt += sum(
            [
                c
                for al, c in Counter(b).most_common()[1:]
            ]
        )

    print(change_cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# check
if len(set(v[::2])) == 1 and len(set(v[1::2])) == 1:
    print(0)
else:
    a = v[::2]
    b = v[1::2]

    change_cnt = 0
    if len(set(a)) > 1: 
        change_cnt += sum(
            [
                c
                for al, c in Counter(a).most_common()[1:]
            ]
        )
    if len(set(b)) > 1:
        change_cnt += sum(
            [
                c
                for al, c in Counter(b).most_common()[1:]
            ]
        )
    
    print(change_cnt)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(input().split())
l=len(v)
if len(set(v))==1:
  print(l//2)
  exit()
c=collections.Counter(v)
mc=c.most_common()
mc.sort(key=lambda x:x[1],reverse=True)
sama=[mc[0][0],mc[1][0]]*(l//2)
samb=[mc[1][0],mc[0][0]]*(l//2)
cnta=0
cntb=0
for i in range(l):
  if v[i]!=sama[i]:
    cnta+=1
  if v[i]!=samb[i]:
    cntb+=1
print(min(cnta,cntb))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(input().split())
vv=''.join(v)
l=len(v)
if len(set(v))==1:
  print(l//2)
  exit()
c=collections.Counter(v)
mc=c.most_common()
mc.sort(key=lambda x:x[1],reverse=True)
sama=(mc[0][0]+mc[1][0])*(l//2)
samb=(mc[1][0]+mc[0][0])*(l//2)
cnta=0
cntb=0
for i in range(l):
  if vv[i]!=sama[i]:
    cnta+=1
  if vv[i]!=samb[i]:
    cntb+=1
print(min(cnta,cntb))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(input().split())
vv=''.join(v)
l=len(v)
if len(set(v))==1:
  print(l//2)
  exit()
c=collections.Counter(v)
mc=c.most_common()
mc.sort(key=lambda x:x[1],reverse=True)
sama=(mc[0][0]+mc[1][0])*(l//2)
samb=(mc[1][0]+mc[0][0])*(l//2)
cnta=0
cntb=0
for i in range(l//2):
  if vv[i]!=sama[i]:
    cnta+=1
  if vv[i]!=samb[i]:
    cntb+=1
print(min(cnta,cntb))

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


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

    d_odd = defaultdict(int)
    d_even = defaultdict(int)
    one_kind = True
    for i, v in enumerate(V):
        if v != V[0]: one_kind = False
        if i % 2 == 0: d_even[v] += 1
        if i % 2 != 0: d_odd[v] += 1
    if one_kind:
        print(n // 2)
        return
    
    """
    修正した結果すべての数字が一致する場合を省かないといけないのがコーナーケース
    """
    (even_val, even_max) = (0, 0)
    (even_pre_val, even_pre_max) = (0, 0)
    for v in d_even:
        if even_max < d_even[v]:
            even_max, even_pre_max  = d_even[v], even_max
            even_val, even_pre_val = v, even_val
    (odd_val, odd_max) = (0, 0)
    (odd_pre_val, odd_pre_max) = (0, 0)
    for v in d_odd:
        if odd_max < d_odd[v]:
            odd_max, odd_pre_max = d_odd[v], odd_max
            odd_val, odd_pre_val = v, odd_val

    if even_val != odd_val: print(n - even_max - odd_max)
    else: print(min(n - even_max - odd_pre_max, n - even_pre_max - odd_max))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


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

    d_odd = defaultdict(int)
    d_even = defaultdict(int)
    one_kind = True
    for i, v in enumerate(V):
        if v != V[0]: one_kind = False
        if i % 2 == 0: d_even[v] += 1
        if i % 2 != 0: d_odd[v] += 1
    if one_kind:
        print(n // 2)
        return
    
    even_max = 0
    for v in d_even: even_max = max(even_max, d_even[v])
    odd_max = 0
    for v in d_odd: odd_max = max(odd_max, d_odd[v])
    print(n - even_max - odd_max)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


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

    d_odd = defaultdict(int)
    d_even = defaultdict(int)
    for i, v in enumerate(v):
        if i % 2 == 0: d_even[v] += 1
        if i % 2 != 0: d_odd[v] += 1
    
    even_max = 0
    for v in d_even: even_max = max(even_max, d_even[v])
    odd_max = 0
    for v in d_odd: odd_max = max(odd_max, d_odd[v])
    val = n - even_max - odd_max
    if val != 0: print(val)
    else: print(n // 2)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


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

    d_odd = defaultdict(int)
    d_even = defaultdict(int)
    for i, v in enumerate(v):
        if i % 2 == 0: d_even[v] += 1
        if i % 2 != 0: d_odd[v] += 1
    
    even_max = 0
    for v in d_even: even_max = max(even_max, d_even[v])
    odd_max = 0
    for v in d_odd: odd_max = max(odd_max, d_odd[v])
    print(n - even_max - odd_max)



if __name__ == "__main__":
    main()