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 numpy as np
from collections import Counter
n = int(input())
As = input().split()
As = [int(A) for A in As]

A_odd = As[::2]         #奇数列
A_even = As[1:][::2]    #偶数列

odd_max,odd1,odd2 = 0,[],[]
even_max,even1,even2 = 0,[],[]

odd_pair = Counter(A_odd).most_common(2)
even_pair = Counter(A_even).most_common(2)

if odd_pair[0][0] != even_pair[0][0]:
    N = n-odd_pair[0][1]-even_pair[0][1]
else:
    if len(odd_pair) == 1 and len(even_pair) == 1:
        N = n/2
    elif len(odd_pair) == 1:
        N = n-even_pair[1][1]
    elif len(even_pair) == 1:
        N = n-odd_pair[1][1] 
    elif odd_pair[1][1] > even_pair[1][1]:
        N = n-even_pair[0][1]-odd_pair[1][1]
    else:
        N = n-odd_pair[0][1]-odd_pair[1][1]
print(int(N))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
As = input().split()
As = [int(A) for A in As]
# n=4
# As = [3,1,3,2,4,3,1,1]
# As = [1,1,1,2,1,1,1,1]

# print(As)
A_odd = As[::2]         #奇数列
A_even = As[1:][::2]    #偶数列

print(A_odd,A_even)

def num_pair(l):
    counts_pair = []
    for i in set(l):
        counts_pair.append([i,l.count(i)])
    odd = np.array(counts_pair)
    return odd[odd[:,1].argsort()[::-1],:]

odd_pair = num_pair(A_odd)
even_pair = num_pair(A_even)


if odd_pair[0][0] != even_pair[0][0]:
    print(n-odd_pair[0][1]-even_pair[0][1])
else:
    if len(odd_pair) == 1 and len(even_pair) == 1:
        print(n/2)
    elif len(odd_pair) == 1:
        print(n-even_pair[1][1])
    elif len(even_pair) == 1:
        print(n-odd_pair[1][1]) 
    elif odd_pair[1][1] > even_pair[1][1]:
        print(n-even_pair[0][1]-odd_pair[1][1])
    else:
        print(n-odd_pair[0][1]-odd_pair[1][1])

Submission status: Wrong Answer

Solution code:
import collections as c
N = int(input())
a = list(map(int,input().split()))
ue = a[0::2]
sita = a[1::2]
dictue = c.defaultdict(int)
dictsita = c.defaultdict(int)
for i in ue:
    dictue[i] += 1
for i in sita:
    dictsita[i] += 1
ue = list(dictue.items())
ue.sort(key=lambda x:x[1])
sita = list(dictsita.items())
sita.sort(key=lambda x:x[1])
m = ue[len(ue)-1]
n = sita[len(sita)-1]
if m[0] == n[0]:
    if len(ue) == 1:
        if len(sita) == 1:
            print(N//2)
        else:
            print(N-sita[len(sita)-2][1])
    else:
        if len(sita) == 1:
            print(N-ue[len(ue)-2][1])
        else:
            print(min(N-ue[len(ue)-2][1],N-sita[len(sita)-2][1]))
else:
    print(N-m[1]-n[1])

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    v = LI()

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

    #  n = 10**5
    #  #  v = [10**5 - i%18 for i in range(n)]
    #  v = [random.randint(0, 100) for i in range(n)]
    #  print(v[:10])

    odd = []
    even = []
    for idx, i in enumerate(v):
        if idx % 2 == 0:
            even.append(i)
        else:
            odd.append(i)

    # Counterが速い
    odd_count = collections.Counter(odd)
    even_count = collections.Counter(even)

    #  print(odd_count, even_count)
    if len(odd_count) == len(even_count) == 1:
        # 変更の必要なし
        print(0)
        exit()

    if odd_count.most_common(1)[0][0] != even_count.most_common(1)[0][0]:
        # 楽なほう
        if len(odd_count) == 1:
            even_result = sum([i[1] for i in even_count.most_common(len(even_count))[1:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
            print(odd_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
            even_result = sum([i[1] for i in even_count.most_common(len(even_count))[1:]])
            print(odd_result + even_result)
    else:
        # 全部同じ数字にならないようにしたい
        # ２個め同士で比べて、２個めをより多く含んでる方はそっちにしちゃう
        if len(odd_count) == 1:
            even_result = even_count.most_common(1)[0][1]
            even_result += sum([i[1] for i in even_count.most_common(len(even_count))[2:]])
            print(even_result)
        elif len(even_count) == 1:
            odd_result = odd_count.most_common(1)[0][1]
            odd_result += sum([i[1] for i in odd_count.most_common(len(odd_count))[2:]])
            print(odd_result)
        elif odd_count.most_common(2)[1][1] > even_count.most_common(2)[1][1]:
            # oddは２つめに多いものを不変にする
            # evenは１つめを不変に
            odd_result = odd_count.most_common(1)[0][1]
            even_result = sum([i[1] for i in even_count.most_common(len(even_count))[1:]])
            print(odd_result + even_result)
        else:
            odd_result = sum([i[1] for i in odd_count.most_common(len(odd_count))[1:]])
            even_result = even_count.most_common(1)[0][1]
            print(odd_result + even_result)

main()

Submission status: Wrong Answer

Solution code:
def ans():
  N = int(input())
  V = list(map(int,input().split()))
  even = [0]*1000001
  odd = [0]*1000001
  for v in V[1::2]:
    even[v] += 1
  for v in V[::2]:
    odd[v] += 1
  me = max(even)
  mo = max(odd)
  if(even.index(me) != odd.index(mo)):
    print(N - me - mo)
  else:
    even.sort()
    odd.sort()
    print(min(N-even[-1]-odd[-2], N-even[2]-odd[-1]))
ans()

Submission status: Wrong Answer

Solution code:
def ans():
  N = int(input())
  V = list(map(int,input().split()))
  even = [0]*100001
  odd = [0]*100001
  for v in V[1::2]:
    even[v] += 1
  for v in V[::2]:
    odd[v] += 1
  me = max(even)
  mo = max(odd)
  if(even.index(me) != odd.index(mo)):
    print(N - me - mo)
  else:
    even.sort()
    odd.sort()
    print(min(N-even[-1]-odd[-2], N-even[2]-odd[-1]))
ans()

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

n = I()
v = LI() 

# 貪欲的にいけばよさそう
# set() => count() で多い要素はそのままにし、少ない要素を多い要素に変換していけばよい
# あとは計算時間
# 実際に変更する必要はなく、カウントを足していけばいいのでは？？？


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

odd = []
even = []
for idx, i in enumerate(v):
    if idx % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

odd_set = set(odd)
odd_count = [[o, odd.count(o)] for o in odd_set]
odd_count = sorted(odd_count, key=lambda x: x[1], reverse=True)

even_set = set(even)
even_count = [[e, even.count(e)] for e in even_set]
even_count = sorted(even_count, key=lambda x: x[1], reverse=True)

#  print(odd_count, even_count)
if len(odd_count) == len(even_count) == 1:
    print(0)
    exit()
result = 0
if odd_count[0][0] != even_count[0][0]:
    # 楽なほう
    if len(odd_count) == 1:
        print(even_count[1][1])
    elif len(even_count) == 1:
        print(odd_count[1][1])
    else:
        print(odd_count[1][1] + even_count[1][1])
else:
    # 全部同じ数字にならないようにしたい
    # ２個め同士で比べて、２個めをより多く含んでる方はそっちにしちゃう
    if len(odd_count) == 1:
        print(even_count[0][1])
    elif len(even_count) == 1:
        print(odd_count[0][1])
    elif odd_count[1][1] > even_count[1][1]:
        print(odd_count[0][1] + even_count[1][1])
    else:
        print(odd_count[1][1] + even_count[0][1])

Submission status: Wrong Answer

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n = ri()
v=rl()
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
for i in range(1,n,2):
    b.append(v[i])

import collections
ca = collections.Counter(a)
ca = ca.most_common()
cb = collections.Counter(b)
cb = cb.most_common()
la = len(a)
lb = len(b)

if ca[0][0] != cb[0][0]:
    ans = (la - ca[0][1]) + (lb - cb[0][1])
else:
    ans = []
    if len(ca) >= 2:
        ans.append(la-ca[1][1] + lb-cb[0][1])
    if len(cb) >= 2:
        ans.append(la-ca[0][1] + lb-cb[1][1])
    if len(ca)==1 and len(cb)==1:
        ans.append(ca[0][1])
        ans.append(cb[0][1])
    ans = max(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n = ri()
v=rl()
a = []
b = []
for i in range(0,n,2):
    a.append(v[i])
for i in range(1,n,2):
    b.append(v[i])

import collections
ca = collections.Counter(a)
ca = ca.most_common()
cb = collections.Counter(b)
cb = cb.most_common()
la = len(a)
lb = len(b)

if ca[0][0] != cb[0][0]:
    ans = (la - ca[0][1]) + (lb - cb[0][1])
else:
    ans = [max(ca[0][1],cb[0][1])]
    if len(ca) >= 2:
        ans.append(la-ca[1][1] + lb-cb[0][1])
    if len(cb) >= 2:
        ans.append(la-ca[0][1] + lb-cb[1][1])
    ans = max(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split()]
even=[v[i] for i in range(len(v)) if i%2==0]
cnt=collections.Counter(even)
first_even=list(cnt.keys())[0]
second_even=list(cnt.keys())[-1]

odd=[v[i] for i in range(len(v)) if i%2==1]
cnt=collections.Counter(odd)
first_odd=list(cnt.keys())[0]
second_odd=list(cnt.keys())[-1]
if first_odd==first_even:
    if second_even==second_odd:
        print(len(even))
    else:
        one=len(even)-even.count(first_even)+len(odd)-odd.count(second_odd)
        two=len(even)-even.count(second_even)+len(odd)-odd.count(first_odd)
        print(min(one,two))
else:
    print(len(even)-even.count(first_even)+len(odd)-odd.count(first_odd))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split()]
even=[v[i] for i in range(len(v)) if i%2==0]
cnt=collections.Counter(even)
first_even=list(cnt.keys())[0]
second_even=list(cnt.keys())[-1]

odd=[v[i] for i in range(len(v)) if i%2==1]
cnt=collections.Counter(odd)
first_odd=list(cnt.keys())[0]
second_odd=list(cnt.keys())[-1]
if even!=odd:
    one=len(even)-even.count(first_even)+len(odd)-odd.count(second_odd)
    two=len(even)-even.count(second_even)+len(odd)-odd.count(first_odd)
    print(min(one,two))
else:
    print(len(even))

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split()]
even=[v[i] for i in range(len(v)) if i%2==0]
cnt=collections.Counter(even)
first_even=list(cnt.keys())[0]
second_even=list(cnt.keys())[-1]

odd=[v[i] for i in range(len(v)) if i%2==1]
cnt=collections.Counter(odd)
first_odd=list(cnt.keys())[0]
second_odd=list(cnt.keys())[-1]
if even!=odd:
    one=abs(sum(even)-first_even*len(even))+abs(sum(odd)-second_odd*len(odd))
    two=abs(sum(even)-second_even*len(even))+abs(sum(odd)-first_odd*len(odd))
    print(min(one,two))
else:
    print(len(even))

Submission status: Wrong Answer

Solution code:
def dekoboko(n: int, v: list) -> int:
    o, e = {}, {}
    for i, vv in enumerate(v):
        if i % 2 == 0:
            if vv not in e:
                e[vv] = 1
            else:
                e[vv] += 1
        else:
            if vv not in o:
                o[vv] = 1
            else:
                o[vv] += 1

    ol = sorted(o.items(), key=lambda x: -x[1])
    el = sorted(e.items(), key=lambda x: -x[1])

    # pivot 選択
    # 頻度が最大のものを固定してそれに合わす様にしたいが、
    # 偶数番号列と奇数番号列とで同じあたいの pivot を使う
    # ことはできない。なので、頻度が最大のものがかぶる様な
    # ら、2番目に頻度が多いものを比較して、頻度の多い方は
    # 2番目のものを使う様にする。
    if ol[0][1] == el[0][1]:
        if len(ol) > 1:
            # 長さが 1 でない時は 2 番目に頻度が高いものを比べる。
            if ol[1][1] > el[1][1]:
                ol[0], ol[1] = ol[1], ol[0]
            else:
                el[0], el[1] = el[1], el[0]
        else:  # len(ol) == 1
            # 長さが 1 の時はダミーを挿入する
            el.append((0, 0))
            el[0], el[1] = el[1], el[0]

    return sum(v for _, v in ol[1:]) + sum(v for _, v in el[1:])


if __name__ == "__main__":
    n = int(input())
    v = map(int, input().split())
    ans = dekoboko(n, v)
    print(ans)

Submission status: Wrong Answer

Solution code:
def dekoboko(n: int, v: list) -> int:
    o, e = {}, {}
    for i, vv in enumerate(v):
        if i % 2 == 0:
            if vv not in e:
                e[vv] = 1
            else:
                e[vv] += 1
        else:
            if vv not in o:
                o[vv] = 1
            else:
                o[vv] += 1

    ol = sorted(o.items(), key=lambda x: -x[1])
    el = sorted(e.items(), key=lambda x: -x[1])

    # pivot 選択
    # 頻度が最大のものを固定してそれに合わす様にしたいが、
    # 偶数番号列と奇数番号列とで同じあたいの pivot を使う
    # ことはできない。なので、頻度が最大のものがかぶる様な
    # ら、2番目に頻度が多いものを比較して、頻度の多い方は
    # 2番目のものを使う様にする。
    op, ep = ol[0][0], el[0][0]
    if op == ep:
        if len(ol) > 1:
            op2, ep2 = ol[1][0], el[1][0]
            if op2 > ep2:
                op = op2
                ol[0], ol[1] = ol[1], ol[0]
            else:
                ep = ep2
                el[0], el[1] = el[1], el[0]
        else:  # len(ol) == 1
            el.append((0, 0))
            el[0], el[1] = el[1], el[0]

    return sum(v for _, v in ol[1:]) + sum(v for _, v in el[1:])


if __name__ == "__main__":
    n = int(input())
    v = map(int, input().split())
    ans = dekoboko(n, v)
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

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

even_count=collections.Counter(even).most_common()
odd_count=collections.Counter(odd).most_common()

#最多出現のものが重複していない
if even_count[0][0]!=odd_count[0][0]:
    print(n-even_count[0][1]-odd_count[0][1])
    
#最多出現のものが重複
else:
    if len(even_count)==1:
        a=0
    else:
        a=even_count[1][1]

    if len(odd_count)==1:
        b=0
    else:
        b=even_count[1][1]    
    
    ans1=n-a-odd_count[0][1]
    ans2=n-even_count[0][1]-b
    print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
if len(set(V))==1:
  print(int(n/2))
else:
  even = V[0::2]
  odd = V[1::2]
  even_count = []
  for char in set(even):
    even_count.append(even.count(char))
  odd_count = []
  for char in set(odd):
    odd_count.append(odd.count(char))
  ans = n-max(even_count)+n-max(odd_count)
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int,input().split()))
if len(set(V))==1:
  print(int(n/2))
else:
  even = [V[2*i] for i in range(int(n/2))]
  odd = [V[2*i+1] for i in range(int(n/2))]
  even_count = {}
  for char in set(even):
    even_count[char] = even.count(char)
  odd_count = {}
  for char in set(odd):
    odd_count[char] = odd.count(char)
  ans = sum(even_count)-max(even_count)+sum(odd_count)-max(odd_count)
  print(ans)

Submission status: Wrong Answer

Solution code:
#nへの代入
n=int(input())

#vのリストを作成
v_list=list(map(int,input().split()))

if(len(set(v_list))>1):
    #偶数番目と奇数番目に登場した数字の辞書を作成
    even_dict=dict()
    odd_dict=dict()
    
    for i in range(n):
        if(i%2==0):
            try:
                even_dict[v_list[i]]+=1
            except KeyError:
                even_dict[v_list[i]]=1
        else:
            try:
                odd_dict[v_list[i]]+=1
            except KeyError:
                odd_dict[v_list[i]]=1
    
    even_list=even_dict.values()
    odd_list=odd_dict.values()
    
    ans=n-max(even_list)-max(odd_list)
    
    print(ans)
else:
    print(int(n/2))

Submission status: Wrong Answer

Solution code:
#nへの代入
n=int(input())

#vのリストを作成
v_list=list(map(int,input().split()))

#偶数番目と奇数番目に登場した数字の辞書を作成
even_dict=dict()
odd_dict=dict()

for i in range(n):
    if(i%2==0):
        try:
            even_dict[v_list[i]]+=1
        except KeyError:
            even_dict[v_list[i]]=1
    else:
        try:
            odd_dict[v_list[i]]+=1
        except KeyError:
            odd_dict[v_list[i]]=1

even_list=even_dict.values()
odd_list=odd_dict.values()

ans=n-max(even_list)-max(odd_list)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])

a = Counter(a)
amc = a.most_common()
b = Counter(b)
bmc = b.most_common()
amc.append((0,0))
bmc.append((0,0))
rewrite = 0

if amc[0][0] == bmc[0][0]:
    rewrite = min(amc[0][1]+bmc[1][1],amc[1][1]+bmc[0][1])
else:
    rewrite = amc[0][1]+bmc[0][1]



print(n-rewrite)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    even = Counter(v[::2]).most_common()
    odd = Counter(v[1::2]).most_common()
    v_count = Counter(v)

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

    # oddとevenで文字が一緒
    elif even[0][0] == odd[0][0]:
        # 大きい方を採用するのです
        # evenの方が大きかったら
        if even[0][1] > odd[0][1]:
            # oddは2番めに頻出を使うよ
            print(n - even[0][1] - odd[1][1])
        else:
            print(n - even[1][1] - odd[0][1])

    else:
        print(n - even[0][1] - odd[0][1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    even = Counter(v[::2]).most_common()
    odd = Counter(v[1::2]).most_common()
    v_count = Counter(v)

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

    # oddとevenで文字が一緒
    elif even[0][0] == odd[0][0]:
        # 大きい方を採用するのです
        # evenの方が大きかったら
        if max(even[0][1], odd[0][1]) == even[0][1]:
            # oddは2番めに頻出を使うよ
            print(n - even[0][1] - odd[1][1])
        else:
            print(n - even[1][1] - odd[0][1])

    else:
        print(n - even[0][1] - odd[0][1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

v_a = v[0:len(v)+1:2]
v_b = v[1:len(v):2]

sum_a = 0
sum_b = 0
v_ac = collections.Counter(v_a)
v_bc = collections.Counter(v_b)
v_ac_val = v_ac.values()
v_bc_val = v_bc.values()
v_ac_val = sorted(v_ac_val,reverse=True)
v_bc_val = sorted(v_bc_val,reverse=True)

if len(set(v))==1:
  print(int(len(v)/2))
else:
  print(sum(v_ac_val[1:])+sum(v_bc_val[1:]))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    even = Counter(v[::2]).most_common()
    odd = Counter(v[1::2]).most_common()
    v_count = Counter(v)

    if len(v_count) == 1:
        print(int(n/2))
    elif even[0][0] != odd[0][0]:
        print(n - even[0][1] - odd[0][1])
    else:
        print(n - max(even[0][1] + odd[0][1], even[1][1] + odd[0][1]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

v_a = v[0:len(v)+1:2]
v_b = v[1:len(v):2]

if len(set(v))==1:
  print(int(len(v)/2))
else:
  print(len(set(v_a))+len(set(v_b))-2)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    even = Counter(v[::2]).most_common()[0][1]
    odd = Counter(v[1::2]).most_common()[0][1]
    v_count = Counter(v)

    if len(v_count) == 1:
        print(int(n/2))
    else:
        print(len(v) - even - odd)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    c_val = list(c.values())[::-1]
    len_c_keys = len(c.keys())

    if len_c_keys > 2:
        print(len(v) - c_val[0] - c_val[1])
    elif len_c_keys < 2:
        print(int(c_val[0]/2))
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    c_val = list(c.values())[::-1]
    len_c_keys = len(c.keys())

    if len_c_keys > 2:
        print(c_val[0] - c_val[1])
    elif len_c_keys < 2:
        print(int(c_val[0]/2))
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    c_val = list(c.values())
    len_c_keys = len(c.keys())

    if len_c_keys > 2:
        print(c_val[0] - c_val[1])
    elif len_c_keys < 2:
        print(int(c_val[0]/2))
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    c_val = list(c.values())
    len_c_keys = len(c.keys())

    if len_c_keys > 2:
        print(sum(c_val[2:])-1)
    elif len_c_keys < 2:
        print(int(c_val[0]/2))
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    c_val = list(c.values())
    len_c_keys = len(c.keys())

    if len_c_keys > 2:
        print(sum(c_val[2:]))
    elif len_c_keys < 2:
        print(int(c_val[0]/2))
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
odd=[]#1,3,5
even=[]#0,2,4,6
for i in range(len(v)):
    if i%2==0:#even
        even.append(v[i])
    else:#odd
        odd.append(v[i])
c_even=collections.Counter(even)
c_odd=collections.Counter(odd)
#print(c_even)
#print(c_odd)
e=int(n/2)-max(c_even.values())
o=int(n/2)-max(c_odd.values())
#print(len(c_even))
#print(e)
#print(o)
ans=e+o

if c_even.keys()==c_odd.keys():
    ans=int(n/2)
else:
    ans=e+o
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

    c_val = list(c.values())

    result = list(c_val).index(min(c_val))

    if len(c.keys()) > 2:
        print(c_val[result])
    elif len(c.keys()) < 2:
        print(int(c_val[result]/2))
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
V1 = []
V2 = []
temp = 0
for _ in map(int,input().split()):
    if(temp%2==0):
        V1.append(_)
    else:
        V2.append(_)
    temp += 1
def  find_set(lis):
    Inte = [0]*(max(lis)+1)#整数値iが初めて出現した配列番号jとしてInte[j]=i
    count = 0 
    for l in lis:
        if(Inte[l] == -1):
            Inte[l] = 1
        elif(Inte[l] != -1):
            Inte[l] += 1
        count += 1
    return Inte

ans = 0
V1fre = find_set(V1)
V2fre = find_set(V2)
pmax1 = V1fre.index(max(V1fre))
pmax2 = V2fre.index(max(V2fre))
if(pmax1 == pmax2):
    if(max(V1fre) == max(V2fre)):
        print(int(n/2))
    elif(max(V1fre) > max(V2fre)):
        sort_V2fre = sorted(V2fre)
        print(n-sort_V2fre[-2]-max(V1fre))
    elif(max(V1fre) < max(V2fre)):
        sort_V1fre = sorted(V1fre)
        print(n-sort_V1fre[-2]-max(V2fre))
    
else:
    print(n-max(V1fre)-max(V2fre))

Submission status: Wrong Answer

Solution code:
n = int(input())
V1 = []
V2 = []
temp = 0
for _ in map(int,input().split()):
    if(temp%2==0):
        V1.append(_)
    else:
        V2.append(_)
    temp += 1
def  find_set(lis):
    Inte = [-1]*(max(lis)+1)#整数値iが初めて出現した配列番号jとしてInte[j]=i
    count = 0 
    for l in lis:
        if(Inte[l] == -1):
            Inte[l] = 1
        elif(Inte[l] != -1):
            Inte[l] += 1
        count += 1
    return Inte

ans = 0
V1fre = find_set(V1)
V2fre = find_set(V2)
pmax1 = V1fre.index(max(V1fre))
pmax2 = V2fre.index(max(V2fre))

for x,y in zip(V1,V2):
    if(x != pmax1):
        ans += 1
    if(y != pmax2):
        ans += 1

print(ans)

Submission status: Wrong Answer

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

def  find_set(lis):#与えられた整数から成る配列が各々どの集合に属するのか判定する
#その際配列に入る値はその値が最初に出た配列番号となる
    Ans = [0]*len(lis)
    Inte = [-1]*(max(lis)+1)#整数値iが初めて出現した配列番号jとしてInte[j]=i
    count = 0 
    for l in lis:
        if(Inte[l] == -1):
            Inte[l] = count
            Ans[count] = count
        elif(Inte[l] != -1):
            Ans[count] = Inte[l]
        count += 1
    return Ans
#print(find_set(V))
ans = 0
List = find_set(V)
for x in List:
    if(x >= 2):
        ans += 1
if(sum(List) == 0):
    print(int(n/2))
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
arr=input().split(" ")
arr_s=set(arr)
#print(arr)
a=0
most_e=0
most_o=0
arr_e=[0 for i in range(int(n/2))]
arr_o=[0 for i in range(int(n/2))]
for i in range(int(n/2)):
    arr_e[i]=arr[a]
    arr_o[i]=arr[a+1]
    a+=2
ce=collections.Counter(arr_e).most_common()[0][1]
co=collections.Counter(arr_o).most_common()[0][1]
if len(arr_s)==1:
    print(int(n/2))
else:
    print(n-ce-co)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
arr=input().split(" ")
arr_s=set(arr)
#print(arr)
a=0
most_e=0
most_o=0
arr_e=[0 for i in range(int(n/2))]
arr_o=[0 for i in range(int(n/2))]
for i in range(int(n/2)):
    arr_e[i]=arr[a]
    arr_o[i]=arr[a+1]
    a+=2
#print(arr_e,arr_o)
arr_es=set(arr_e)
arr_os=set(arr_o)

if len(arr_s)==1:
    print(int(n/2))
else:
    print(n-collections.Counter(arr_e).most_common()[0][1]-collections.Counter(arr_o).most_common()[0][1])

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(0, n - 1, 2):
	odd.append(v[i])
	even.append(v[i + 1])
N = n // 2
co = collections.Counter(odd)
ce = collections.Counter(even)
omost = co.most_common(2)
emost = ce.most_common(2)
if len(omost) == 1 and len(emost) == 1:
	if omost[0][0] != emost[0][0]:
		print(0)
	else:
		print(N)
elif len(omost) == 1:
	print(N - emost[0][1])
elif len(emost) == 1:
	print(N - omost[0][1])
else:
	if omost[0][0] != emost[0][0]:
		print(N - omost[0][1] - emost[0][1])
	else:
		print(min(N - omost[0][1] - emost[1][1], N - omost[1][1] - emost[0][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())

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


dif = [v[i+1] - v[i] for i in range(n-1)]

c = 0

for i in range(n-2):
	if dif[i+1] != -1 * dif[i]:
		c += 1

print(c)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

def defs(c1, c2):
    
    if c1[0][1] == c2[0][1]:
        return c1[0], c2[0]
    
    if c1[0][1] > c2[0][1]:
        return c1[0], c2[1]
    else:
        return c2[0], c1[1]

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    if even_c[0] == odd_c[0]:
        print(int(len(m) / 2))
        return
    
    l1, l2 = defs(even_c, odd_c)
    
    #最頻値が同じかつ、出現回数も同じ
    if l1[1] == l2[1] and l1[0] == l2[0]:
        print(0)
        return
    
    #全部バラバラ
    if l1[1] == 1 and l2[1] == 1:
        print(len(m) - 1)
        return
    
    print(len(m) - l1[1] - l2[1])
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

def defs(c1, c2):
    
    if c1[0][1] == c2[0][1]:
        return c1[0], c2[0]
    
    if c1[0][1] > c2[0][1]:
        return c1[0], c2[1]
    else:
        return c2[0], c1[1]

def main():
    input = sys.stdin.readline
    
    n = int(input())
    m = [int(i) for i in input().split()]
    
    even = [m[i] for i, _ in enumerate(m) if i % 2 == 0]
    odd = [m[i] for i, _ in enumerate(m) if i % 2 == 1]
    
    even_c = Counter(even).most_common()
    odd_c = Counter(odd).most_common()
    
    if even_c[0] == odd_c[0]:
        print(int(len(m) / 2))
        return
    
    l1, l2 = defs(even_c, odd_c)
    
    #奇数, 偶数の最頻値が同じとき
    if even_c[0][1] == odd_c[0][1]:
        print(0)
        return
    
    #全部バラバラ
    if l1[1] == 1 and l2[1] == 1:
        print(len(m) - 1)
        return
        
    #奇数,偶数の最頻値が異なる
    print(len(m) - l1[1] - l2[1])
    
if __name__ == '__main__':
    main()