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:
# C
import numpy as np
n = int(input())
v = [int(i) for i in input().split()]
solo_check = len(list(set(v)))
average = round(np.mean(v))
if solo_check == 1:
    print(int(n/2))
else:
    diff_list = [x - average for x in v]
    print(int(sum(diff_list)))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main() -> None:
    n = int(input())
    p = [int(i) for i in input().split()]

    # 奇数番目の配列
    l1 = [int(p[i]) for i in range(0, n, 2)]
    # 偶数盤面の配列
    l2 = [int(p[i]) for i in range(1, n, 2)]

    if len(set(p)) == 1:
        # ゾロ目判定
        print(n // 2)
    else:
        lc1 = Counter(l1).most_common(2)
        lc2 = Counter(l2).most_common(2)

        if lc1[0][0] == lc2[0][0]:
            # 最頻値がかぶってしまった場合
            print(n - max(lc1[0][1] + lc2[1][1], lc1[1][1] + lc2[0][1]))
        else:
            # かぶっていなかったら最頻値を引く
            print(n - lc1[0][1] - lc2[0][1])

Submission status: Wrong Answer

Solution code:
import collections
import operator


def main() -> None:
    n = int(input())
    p = [int(i) for i in input().split()]

    # 奇数番目の配列
    ch1 = [int(p[i]) for i in range(0, n, 2)]
    # 偶数盤面の配列
    ch2 = [int(p[i]) for i in range(1, n, 2)]

    if max(ch1) == min(ch1) and max(ch2) == min(ch2) and ch1 != ch2:
        # 既に達成済み、配列内が全て同じで1、2は別配列
        print("{}".format("0"))
    elif ch1 == ch2:
        # ゾロ目の場合、片方の配列全てを履き替え
        print("{}".format(len(ch1)))
    else:
        # 上記のパターン以外は演算が必要
        # 数字ごとにグルーピング
        p1 = collections.Counter(ch1)
        p2 = collections.Counter(ch2)
        # print(p1)
        # print(p2)
        num = 0

        # p1の書き換え
        p1s = sorted(p1.items(), reverse=True, key=operator.itemgetter(1))
        # print(p1s)
        # p2の書き換え
        p2s = sorted(p2.items(), reverse=True, key=operator.itemgetter(1))
        # print(p2s)

        # 最頻値がかぶった
        if p1s[0] == p2s[0]:
            # p1sの最貧を入れ替える
            tmp = p1s[1]
            p1s[1] = p1s[0]
            p1s[0] = tmp

            min1 = 0
            min1 = min1 + sum(v for k, v in p1s[1:])
            min1 = min1 + sum(v for k, v in p2s[1:])

            # 戻し
            tmp = p1s[1]
            p1s[1] = p1s[0]
            p1s[0] = tmp

            # p2sの最貧を入れ替える
            tmp = p2s[1]
            p2s[1] = p2s[0]
            p2s[0] = tmp

            min2 = 0
            min2 = min2 + sum(v for k, v in p1s[1:])
            min2 = min2 + sum(v for k, v in p2s[1:])

            num = min(min1, min2)
        else:
            num = num + sum(v for k, v in p1s[1:])
            num = num + sum(v for k, v in p2s[1:])

        print("{}".format(num))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
import operator


def main() -> None:
    n = int(input())
    p = [int(i) for i in input().split()]

    ch1 = [int(p[i]) for i in range(0, n, 2)]
    ch2 = [int(p[i]) for i in range(1, n, 2)]

    if max(ch1) == min(ch1) and max(ch2) == min(ch2) and ch1 != ch2:
        # 既に達成済み
        print("{}".format("0"))
    elif ch1 == ch2:
        # ゾロ目
        print("{}".format(len(ch1)))
    else:
        # 本体
        p1 = collections.Counter(ch1)
        p2 = collections.Counter(ch2)
        num = 0
        if p1 != 1:
            # p1の書き換え
            p1s = sorted(p1.items(), reverse=True, key=operator.itemgetter(1))
            num = num + sum(v for k, v in p1s[1:])
        if p2 != 1:
            # p2の書き換え
            p2s = sorted(p2.items(), reverse=True, key=operator.itemgetter(1))
            num = num + sum(v for k, v in p2s[1:])
        print("{}".format(num))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
import operator


def main() -> None:
    n = int(input())
    p = [int(i) for i in input().split()]

    ch1 = [int(p[i]) for i in range(0, n, 2)]
    ch2 = [int(p[i]) for i in range(1, n, 2)]

    if max(ch1) == min(ch1) and max(ch2) == min(ch2) and ch1 != ch2:
        # 既に達成済み
        print("{}".format("0"))
    elif ch1 == ch2:
        # ゾロ目
        print("{}".format(len(ch1)))
    else:
        # 本体
        p1 = collections.Counter(ch1)
        p2 = collections.Counter(ch2)
        num = 0
        if p1 != 1:
            p1s = sorted(p1.items(), reverse=True, key=operator.itemgetter(1))
            num = num + sum(v for k, v in p1s[1:])
        if p2 != 1:
            p2s = sorted(p2.items(), reverse=True, key=operator.itemgetter(1))
            num = num + sum(v for k, v in p2s[1:])
        print("{}".format(num))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections


def main() -> None:
    n = int(input())
    p = [int(i) for i in input().split()]
    # 書き換えの必要があるか？
    ch1 = [int(p[i]) for i in range(0, n, 2)]
    ch2 = [int(p[i]) for i in range(1, n, 2)]

    if max(ch1) == min(ch1) and max(ch2) == min(ch2) and ch1 != ch2:
        print("{}".format("0"))
    elif ch1 == ch2:
        print("{}".format(len(ch1)))
    else:
        p1 = collections.Counter(ch1)
        p2 = collections.Counter(ch2)
        num = 0
        if p1 != 1:
            p1s = sorted(p1, reverse=True)
            num = num + sum(p1s[1:])
        if p2 != 1:
            p2s = sorted(p2, reverse=True)
            num = num + sum(p2s[1:])
        print("{}".format(num))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = []
L = list(map(int,input().split()))
if len(list(filter(lambda x:x==L[0] ,L))) == len(L):
    print(n//2)
    quit()


import collections as col
L1 = L[::2]
L2 = L[1::2]
c1 = list(col.Counter(L1).items())
c2 = list(col.Counter(L2).items())


for i in range(2):
    for j in range(2):
        try:
            tmp1 = c1[i][0]
            tmp2 = c2[j][0]
            if tmp1 == tmp2 :
                continue
            a1 = n//2 - c1[i][1]
            a2 = n//2 - c2[j][1]
            ans.append(a1+a2)
        except:
            pass
print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = []
L = list(map(int,input().split()))
if len(list(filter(lambda x:x==L[0] ,L))) == len(L):
    print(n//2)
    quit()


import collections as col
L1 = L[::2]
L2 = L[1::2]
c1 = list(col.Counter(L1).items())
c2 = list(col.Counter(L2).items())


for i in range(2):
    for j in range(2):
        try:
            tmp1 = c1[i][0]
            tmp2 = c2[j][0]
            if tmp1 == tmp2 :
                continue
            a1 = n//2 - c1[i][1]
            a2 = n//2 - c1[j][1]
            ans.append(a1+a2)
        except:
            pass
print(min(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
L = list(map(int,input().split()))
if len(list(filter(lambda x:x==L[0] ,L))) == len(L):
    print(n//2)
    quit()


import collections as col
L1 = L[::2]
L2 = L[1::2]
c1 = list(col.Counter(L1).items())
c2 = list(col.Counter(L2).items())

if c1[0][0] != c2[0][0]:
    ans += n//2 - c1[0][1]
    ans += n//2 - c2[0][1]
elif c1[0] == c2[0]:
    if c1[1][1] > c2[1][1]:
        ans += n//2 - c1[1][1]
        ans += n//2 - c2[0][1]
    else:
        ans += n//2 - c1[0][1]
        ans += n//2 - c2[1][1]
elif c1[0][1] > c2[0][1]:
        ans += n//2 - c1[0][1]
        ans += n//2 - c2[1][1]
elif c1[0][1] < c2[0][1]:
        ans += n//2 - c1[1][1]
        ans += n//2 - c2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
L = list(map(int,input().split()))
if len(list(filter(lambda x:x==L[0] ,L))) == len(L):
    print(n//2)
    quit()


import collections as col
L1 = L[::2]
L2 = L[1::2]
c1 = list(col.Counter(L1).items())
c2 = list(col.Counter(L2).items())
ans += n//2 - c1[0][1]
ans += n//2- c2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
l1 = []
l2 = []
for i,v_ in enumerate(v):
    if i%2==0:
        l1.append(v_)
    else:
        l2.append(v_)

from collections import Counter
if set(l1)==set(l2):
    print(n//2)
else:
    c1 = Counter(l1).most_common(2)
    c2 = Counter(l2).most_common(2)
    if c1[0][0]==c2[0][0]:
        print(n-max(c1[0][1]+c2[1][1], c1[1][1]+c2[0][1]))
    else:
        print(n-c1[0][1]-c2[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
l1 = []
l2 = []
for i,v_ in enumerate(v):
    if i%2==0:
        l1.append(v_)
    else:
        l2.append(v_)

l1 = sorted(l1)
l2 = sorted(l2)
c1 = []
c2 = []
for i in range(len(l1)-1):
    if not l1[i]==l1[i+1]:
        c1.append(i)
    if not l2[i]==l2[i+1]:
        c2.append(i)
d1 = []
d2 = []
for i in range(len(c1)-1):
    d1.append(c1[i+1]-c1[i])
for i in range(len(c2)-1):
    d2.append(c2[i+1]-c2[i])
d1 = max(d1) if d1 else 0
d2 = max(d2) if d2 else 0
if len(c1)==1:
    d1=1
elif not d1:
    d1 = len(l1)
if len(c2)==1:
    d2=1
elif not d2:
    d2 = len(l2)

if min(v)==max(v):
    print(len(v)//2)
else:
    print((len(l1)-d1)+(len(l2)-d2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
a=int(input())
A=list(map(int,input().split()))
bx=[A[i] for i in range(a) if i%2==0]
cx=[A[i] for i in range(a) if i%2==1]
b=sorted(bx)
c=sorted(cx)
print(b,c)
if b==c and len(set(b))==1 and len(set(c))==1:
    print(a//2)
else:
    bc=Counter(b).most_common()
    cc=Counter(c).most_common()
    print(bc,cc)
    if bc[0][0]==cc[0][0]:
        print(a-max(bc[1][1]+cc[0][1],bc[0][1]+cc[1][1]))
    else: print(a-bc[0][1]-cc[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
a=int(input())
A=list(map(int,input().split()))
bx=[A[i] for i in range(a) if i%2==0]
cx=[A[i] for i in range(a) if i%2==1]
b=sorted(bx)
c=sorted(cx)
if b==c:
    print(a//2)
else:
    bc=Counter(b).most_common()
    cc=Counter(c).most_common()
    if bc[0][0]==cc[0][0]:
        print(a-max(bc[1][1]+cc[0][1],bc[0][1]+cc[1][1]))
    else: print(a-bc[0][1]-cc[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
a=int(input())
A=list(map(int,input().split()))
b=[A[i] for i in range(a) if i%2==0].sort()
c=[A[i] for i in range(a) if i%2==1].sort()
if b==c:
    print(a//2)
else:
    bc=Counter(b).most_common()
    cc=Counter(c).most_common()
    if bc[0][0]==cc[0][0]:
        print(a-max(bc[1][1]+cc[0][1],bc[0][1]+cc[1][1]))
    else: print(a-bc[0][1]-cc[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
a=int(input())
A=list(map(int,input().split()))
b=[A[i] for i in range(a) if i%2==0]
c=[A[i] for i in range(a) if i%2==1]
if b==c:
    print(a//2)
else:
    bc=Counter(b).most_common()
    cc=Counter(c).most_common()
    if bc[0][0]==cc[0][0]:
        print(a-max(bc[1][1]+cc[0][1],bc[0][1]+cc[1][1]))
    else: print(a-bc[0][1]-cc[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
a=int(input())
A=list(map(int,input().split()))
b=[A[i] for i in range(a) if i%2==0]
c=[A[i] for i in range(a) if i%2==1]
if b==c:
    print(a//2)
else:
    bc=Counter(b).most_common()
    cc=Counter(c).most_common()
    if bc[0][0]==cc[0][0]:
        print(a-min(bc[1][1]+cc[0][1],bc[0][1]+cc[1][1]))
    else: print(a-bc[0][1]-cc[0][1])

Submission status: Wrong Answer

Solution code:
import collections
input()
l=list(map(int,input().split()))
c1=collections.Counter(l[0::2])
c2=collections.Counter(l[1::2])
m1=c1.most_common(2)
m2=c2.most_common(2)
a=m1[0][1]
b=m2[0][1]
if m1[0][0]==m2[0][0]:
  if len(m1)==1 and len(m2)==1:
    b=0
  elif len(m1)==1:
    b=m2[1][1]
  elif len(m2)==1:
    a=m1[1][1]
  else:
    if a>b:
      b=m2[1][1]
    else:
      a=m1[1][1]
print(len(l)-a-b)

Submission status: Wrong Answer

Solution code:
import collections
input()
l=list(map(int,input().split()))
c1=collections.Counter(l[0::2])
c2=collections.Counter(l[1::2])
m1=c1.most_common()[0]
m2=c2.most_common()[0]
if m1[0] !=m2[0]:
  print(len(l)-m1[1]-m2[1])
else:
  print(len(l)-m1[1])

Submission status: Wrong Answer

Solution code:
import collections
d=input()
l=list(map(int,input().split()))
c1=collections.Counter(l[0::2])
c2=collections.Counter(l[1::2])
print(len(l)-c1.most_common()[0][1]\
            -c2.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
def sortcounts(c: dict):
    a = [(v, k) for k, v in c.items()]
    return sorted(a)


def solve(a):
    m = len(a)//2

    o = [a[i] for i in range(len(a)) if i%2==0]
    e = [a[i] for i in range(len(a)) if i%2==1]

    # print(o)
    # print(e)

    import collections
    co = sortcounts(collections.Counter(o))
    ce = sortcounts(collections.Counter(e))

    # print(co)
    # print(ce)

    no, vo = co[0]
    ne, ve = ce[0]

    if vo != ve:
        ans = (m-no) + (m-ne)
    else:
        anse = (m-no) + m-(0 if len(co)<2 else co[1][0])
        anso = (m-ne) + m-(0 if len(ce)<2 else ce[1][0])
        ans = min(anse, anso)

    return ans


def main():
    _=input()
    a = list(map(int, input().split()))
    print(solve(a))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
A=V[::2]
B=V[1::2]
A_counter=Counter(A)
a_freqnum=A_counter.most_common()[0][0]
a_freq=A_counter.most_common()[0][1]
B_counter=Counter(B)
b_freqnum=B_counter.most_common()[0][0]
b_freq=B_counter.most_common()[0][1]
if a_freqnum!=b_freqnum:
    ans=n-(a_freq+b_freq)
else:
    if a_freq==n//2:
        if b_freq==n//2:
            ans=n//2
        else:
            b_freq_sec=B_counter.most_common()[1][0]
            ans=n//2-b_freq_sec
    else:
        a_freq_sec=A_counter.most_common()[1][0]
        if b_freq==n//2:
            ans=n//2-a_freq_sec
        else:
            b_freq_sec=B_counter.most_common()[1][0]
            ans=n-a_freq-max(a_freq_sec,b_freq_sec)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==4:
  exit()
l=list(map(int,input().split()))
l1={}
l2={}
f=0
for i in l:
  if f==0:
    if i not in l1:
      l1[i]=1
    else:
      l1[i]+=1
    f=1
  else:
    if i not in l2:
      l2[i]=1
    else:
      l2[i]+=1
    f=0
l1=sorted(l1.items(),key=lambda x:x[1],reverse=True)
l2=sorted(l2.items(),key=lambda x:x[1],reverse=True)
if l1[0][0]==l2[0][0]:
  if l1[0][1]==l2[0][1] and l1[0][1]==n//2:
    print(n//2)
  elif l1[0][1]>=l2[0][1]:
    print(n-l1[0][1]-l2[1][1])
  else:
    print(n-l1[1][1]-l2[0][1])
else:
  print(n-l1[0][1]-l2[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==8:
  exit()
l=list(map(int,input().split()))
l1={}
l2={}
f=0
for i in l:
  if f==0:
    if i not in l1:
      l1[i]=1
    else:
      l1[i]+=1
    f=1
  else:
    if i not in l2:
      l2[i]=1
    else:
      l2[i]+=1
    f=0
l1=sorted(l1.items(),key=lambda x:x[1],reverse=True)
l2=sorted(l2.items(),key=lambda x:x[1],reverse=True)
if l1[0][0]==l2[0][0]:
  if l1[0][1]==l2[0][1] and l1[0][1]==n//2:
    print(n//2)
  elif l1[0][1]>=l2[0][1]:
    print(n-l1[0][1]-l2[1][1])
  else:
    print(n-l1[1][1]-l2[0][1])
else:
  print(n-l1[0][1]-l2[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1={}
l2={}
f=0
for i in l:
  if f==0:
    if i not in l1:
      l1[i]=1
    else:
      l1[i]+=1
    f=1
  else:
    if i not in l2:
      l2[i]=1
    else:
      l2[i]+=1
    f=0
l1=sorted(l1.items(),key=lambda x:x[1],reverse=True)
l2=sorted(l2.items(),key=lambda x:x[1],reverse=True)
if l1[0][0]==l2[0][0]:
  if l1[0][1]==l2[0][1]:
    print(n//2)
  elif l1[0][1]>l2[0][1]:
    print(n-l1[0][1]-l2[1][1])
  else:
    print(n-l1[1][1]-l2[0][1])
else:
  print(n-l1[0][1]-l2[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==8:
  exit()
l=list(map(int,input().split()))
l1={}
l2={}
f=0
for i in l:
  if f==0:
    if i not in l1:
      l1[i]=1
    else:
      l1[i]+=1
    f=1
  else:
    if i not in l2:
      l2[i]=1
    else:
      l2[i]+=1
    f=0
l1=sorted(l1.items(),key=lambda x:x[1],reverse=True)
l2=sorted(l2.items(),key=lambda x:x[1],reverse=True)
if l1[0][0]==l2[0][0]:
  if l1[0][1]==l2[0][1]:
    print(n//2)
  elif l1[0][1]>l2[0][1]:
    print(n-l1[0][1]-l2[1][1])
  else:
    print(n-l1[1][1]-l2[0][1])
else:
  print(n-l1[0][1]-l2[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1={}
l2={}
f=0
for i in l:
  if f==0:
    if i not in l1:
      l1[i]=1
    else:
      l1[i]+=1
    f=1
  else:
    if i not in l2:
      l2[i]=1
    else:
      l2[i]+=1
    f=0
x=max(l1.values())
y=max(l2.values())
if x==y and l[0]==l[1]:
  print(n//2)
  exit()
print(n-x-y)

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==6:
  exit()
l=list(map(int,input().split()))
l1={}
l2={}
f=0
for i in l:
  if f==0:
    if i not in l1:
      l1[i]=1
    else:
      l1[i]+=1
    f=1
  else:
    if i not in l2:
      l2[i]=1
    else:
      l2[i]+=1
    f=0
x=max(l1.values())
y=max(l2.values())
if x==y and l[0]==l[1]:
  print(n//2)
  exit()
print(n-x-y)

Submission status: Wrong Answer

Solution code:
import collections
if __name__ == '__main__':
    n = int(input())
    v = list(map(int, input().split()))
    gu = []
    ki = []
    for i, tmp in enumerate(v):
        if i % 2 == 0:
            gu.append(tmp)
        elif i % 2 != 0:
            ki.append(tmp)
    res = 0
    ki_sorted = sorted(list(collections.Counter(ki).items()), key=lambda x:x[1])
    gu_sorted = sorted(list(collections.Counter(gu).items()), key=lambda x:x[1])
    if ki_sorted[0][0] != gu_sorted[0][0]:
        res += len(ki) - ki_sorted[0][1]
        res += len(gu) - gu_sorted[0][1]
    elif ki_sorted[0][0] == gu_sorted[0][0]:
        if len(gu_sorted) == 1:
            if len(ki_sorted) == 1:
                res += ki_sorted[0][1]
            else:
                res += len(ki) - ki_sorted[1][1]
                res += len(gu) - gu_sorted[0][1]
        elif len(ki_sorted) == 1:
            res += len(ki) - ki_sorted[0][1]
            res += len(gu) - gu_sorted[1][1]
        else:
            res += min(len(ki) - ki_sorted[0][1] + len(gu) - gu_sorted[1][1], len(ki) - ki_sorted[1][1] + len(gu) - gu_sorted[0][1])            
    print(res)

Submission status: Wrong Answer

Solution code:
import collections
if __name__ == '__main__':
    n = int(input())
    v = list(map(int, input().split()))
    gu = []
    ki = []
    for i, tmp in enumerate(v):
        if i % 2 == 0:
            gu.append(tmp)
        elif i % 2 != 0:
            ki.append(tmp)
    res = 0
    res += len(ki) - sorted(list(collections.Counter(ki).items()), key=lambda x:x[1])[0][1]
    res += len(gu) - sorted(list(collections.Counter(gu).items()), key=lambda x:x[1])[0][1]
    print(res)

Submission status: Wrong Answer

Solution code:
import collections

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

v0=[v[i] for i in range(n) if i%2==0]
v1=[v[i] for i in range(n) if i%2==1]

count_dict = collections.Counter(v0)
max0=count_dict.most_common(1)

count_dict = collections.Counter(v1)
max1=count_dict.most_common(1)

if len(set(v))==1:
  print(n//2)
else:
  print(len(v0)-max0[0][1]+len(v1)-max1[0][1])

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())

v=[int(i) for i in input().split()]
vset=set(v)

if len(vset)==1:
    if len(v)%2:
        print(int(len(v)/2-0.5))
    else:
        print(int(len(v)/2))

else:
    odd=[]
    even=[]

    for i in range(0,len(v),2):
        odd.append(v[i])

    for i in range(1,len(v),2):
        even.append(v[i])

    count_odd=collections.Counter(odd)
    count_even=collections.Counter(even)

    max_odd=max(count_odd)
    max_odd=count_odd[max_odd]
    max_even=max(count_even)
    max_even=count_even[max_even]

    print(len(odd)-max_odd + len(even)-max_even)

Submission status: Wrong Answer

Solution code:
import collections

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

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

odd_c = collections.Counter(odd)
eve_c = collections.Counter(eve)

odd_key = odd_c.most_common()[0][0]
odd_value = odd_c.most_common()[0][1]
eve_key = eve_c.most_common()[0][0]
eve_value = eve_c.most_common()[0][1]

if odd_key == eve_key:
    if odd_value >= eve_value:
        if len(eve_c.most_common()) == 1:
            eve_value = 0
        else:
            eve_key = eve_c.most_common()[1][0]
            eve_value = eve_c.most_common()[1][1]
    else:
        if len(odd_c.most_common()) == 1:
            odd_value = 0
        else:
            odd_key = odd_c.most_common()[1][0]
            odd_value = odd_c.most_common()[1][1]
else:
    pass

ans = int(n/2 - eve_value + n/2 - odd_value)
print(ans)

Submission status: Wrong Answer

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
N = int(input())
h_H = int(N/2)
V = list(map(int,input().split()))
v1 = [i for i in V[::2]]
v2 = [i for i in V[1::2]]

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

if c1.most_common()[0][0] != c2.most_common()[0][0]:
  print((h_H-c1.most_common()[0][1])+(h_H-c2.most_common()[0][1]))
else:
  if len(c1) == 1 and len(c2) == 1:
    print(h_H)
  elif len(c1) == 1:
    print(min([(h_H-c1.most_common()[0][1])+(h_H-c2.most_common()[1][1]),
          (h_H-c1.most_common()[0][1])+(h_H-c2.most_common()[0][1])]))
  elif len(c2) == 1:
    print(min([(h_H-c1.most_common()[0][1])+(h_H-c2.most_common()[0][1]),
             (h_H-c1.most_common()[1][1])+(h_H-c2.most_common()[0][1])]))
  else:
    print(min([(h_H-c1.most_common()[0][1])+(h_H-c2.most_common()[0][1]),
          (h_H-c1.most_common()[1][1])+(h_H-c2.most_common()[1][1])]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
vl = [int(i) for i in input().split()]
oc = Counter(a for i, a in enumerate(vl) if i % 2 == 0)
ec = Counter(a for i, a in enumerate(vl) if i % 2 == 1)
ol = sorted(((v, k) for k, v in oc.items()), reverse=True)
el = sorted(((v, k) for k, v in ec.items()), reverse=True)

if ol[0][1] != el[0][1]:
    print(n - ol[0][0] - el[0][0])
else:
    if ol[0][0] >= el[0][0]:
        if len(el) >= 2:
            print(n - ol[0][0] - el[1][0])
        else:
            print(n // 2)
    else:
        if len(ol) >= 2:
            print(n - ol[1][0] - el[0][0])
        else:
            print(n // 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
vl = [int(i) for i in input().split()]
oc = Counter(a for i, a in enumerate(vl) if i % 2 == 0)
ec = Counter(a for i, a in enumerate(vl) if i % 2 == 1)
ol = sorted(((v, k) for k, v in oc.items()), reverse=True)
el = sorted(((v, k) for k, v in ec.items()), reverse=True)

if ol[0][1] != el[0][1]:
    print(n - ol[0][0] - el[0][0])
else:
    if ol[0][0] >= el[0][0]:
        if len(el) >= 2:
            print(n - ol[0][0] - el[1][0])
        else:
            print(n - ol[0][0])
    else:
        if len(ol) >= 2:
            print(n - ol[1][0] - el[0][0])
        else:
            print(n - el[0][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
vl = [int(i) for i in input().split()]
ol = []
el = []

for i in range(n//2):
    ol.append(vl[i * 2])
    el.append(vl[i * 2 + 1])

oc = Counter(ol)
ec = Counter(el)

if oc.most_common()[0][0] != ec.most_common()[0][0]:
    print(n - oc.most_common()[0][1] - ec.most_common()[0][1])
else:
    if oc.most_common()[0][1] >= ec.most_common()[0][1]:
        if len(ec) >= 2:
            print(n - oc.most_common()[0][1] - ec.most_common()[1][1])
        else:
            print(n - oc.most_common()[0][1])
    else:
        if len(oc) >= 2:
            print(n - oc.most_common()[1][1] - ec.most_common()[0][1])
        else:
            print(n - ec.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
vl = [int(i) for i in input().split()]
al = []
el = []

for i in range(n//2):
    al.append(vl[i * 2])
    el.append(vl[i * 2 + 1])

ac = Counter(al)
ec = Counter(el)

if ac.most_common()[0][0] != ec.most_common()[0][0]:
    print((len(al) - ac.most_common()[0][1]) + (len(el) - ec.most_common()[0][1]))
else:
    if ac.most_common()[0][1] >= ec.most_common()[0][1]:
        if len(ec) >= 2:
            print((len(al) - ac.most_common()[0][1]) + (len(el) - ec.most_common()[1][1]))
        else:
            print((len(al) - ac.most_common()[0][1]) + len(el))
    else:
        if len(ac) >= 2:
            print((len(al) - ac.most_common()[1][1]) + (len(el) - ec.most_common()[0][1]))
        else:
            print(len(al) + (len(el) - ec.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
vl = [int(i) for i in input().split()]
al = []
el = []

for i in range(n//2):
    al.append(vl[i * 2])
    el.append(vl[i * 2 + 1])

ac = Counter(al)
ec = Counter(el)

print((len(al) - ac.most_common()[0][1]) + (len(el) - ec.most_common()[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    aa = list(map(int, input().split()))
    cs_a0 = Counter(a for i, a in enumerate(aa) if i % 2 == 0)
    cs_a1 = Counter(a for i, a in enumerate(aa) if i % 2 == 1)
    vs_a0 = sorted(((v, k) for k, v in cs_a0.items()), reverse=True)
    vs_a1 = sorted(((v, k) for k, v in cs_a1.items()), reverse=True)
    if vs_a0[0][1] != vs_a1[0][1]:
        print(n - vs_a0[0][0] - vs_a1[0][0])
    else:
        res = 1 << 30
        if len(vs_a0) > 1:
            res = min(res, n - vs_a0[1][0] - vs_a1[0][0])
        if len(vs_a1) > 1:
            res = min(res, n - vs_a0[0][0] - vs_a1[1][0])
        print(res)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int,input().split()))
even = [0]*(10**5+10)
odd = [0]*(10**5+10)
for v in V[::2]:
  even[v] += 1
for v in V[1::2]:
  odd[v] += 1
max_even = max(even)
max_odd = max(odd)
if(even.index(max_even) != odd.index(max_odd)):
  print(N - max_even - max_odd)
else:
  print(min(N - even[0] - odd[1], N - even[1] - odd[0]))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int,input().split()))
d = {}
for i in range(N):
  if(V[i] not in d):
    d[V[i]] = 1
  else:
    d[V[i]] += 1
tmp = sorted(d.items(), key = lambda x: -x[1])
len_tmp = len(tmp)
if(len_tmp == 1):
  print(tmp[0][1]//2)
elif(len_tmp == 2):
  print(0)
else:
  print(tmp[0][1] - tmp[1][1])

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
ve=v[0::2]
vo=v[1::2]
print(ve,vo)

ce=collections.Counter(vo).most_common(2)
co=collections.Counter(ve).most_common(2)
print(ce,co)
if ce[0][0] != co[0][0]:
    ans = len(v)-ce[0][1]-co[0][1]
elif len(ce)==1 and len(co)==1:
    ans = len(v)//2
elif len(ce)==1:
    ans = len(v)//2 - co[1][1]
elif len(co)==1:
    ans = len(v)//2-ce[1][1]
else:
    ans = len(v)-max(ce[0][1]+co[1][1],ce[1][1]+co[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a,s=[],[]
d,f=[],[]
for i in range(int(n/2)):
    a.append(v[i*2])
    s.append(v[i*2+1])
aa,ss=set(a),set(s)
for j in aa:
    d.append([j,a.count(j)])
for l in ss:
    f.append([l,s.count(l)])
dd=sorted(d,key = lambda x:x[1])
ff=sorted(f,key = lambda x:x[1])
if dd[0][0] == ff[0][0]:
    if len(aa)>=2 and len(ss)>=2:
        print(min((n-dd[0][1]-ff[1][1]),(n-dd[1][1]-ff[0][1])))
    elif len(aa)==1 and len(ss)>=2:
        print(n-dd[0][1]-ff[1][1])
    elif len(aa)>=2 and len(ss)==1:
        print(n-dd[1][1]-ff[0][1])
    else:
        print(int(n/2))
else:
    print(n-dd[0][1]-f[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a,s=[],[]
d,f=[],[]
for i in range(int(n/2)):
    a.append(v[i*2])
    s.append(v[i*2+1])
aa,ss=set(a),set(s)
for j in aa:
    d.append([j,a.count(j)])
for l in ss:
    f.append([l,s.count(l)])
dd=sorted(d,key = lambda x:x[1])
ff=sorted(f,key = lambda x:x[1])
if dd[0][0] == ff[0][0]:
    if len(aa)>=2 and len(ss)>=2:
        if dd[0][1]>=ff[0][1]:
            print(n-dd[0][1]-ff[1][1])
        else:
            print(n-dd[1][1]-ff[0][1])
    else:
        if dd[0][1]==int(n/2) and ff[0][1]<int(n/2):
            print(int(n/2)-ff[0][1])
        elif ff[0][1]==int(n/2) and dd[0][1]<int(n/2):
            print(int(n/2)-dd[0][1])
        else:
            print(int(n/2))    
else:
    print(n-dd[0][1]-f[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
ve = v[0::2]
vo = v[1::2]
# print(ve,vo)

ce=collections.Counter(vo).most_common(2)
co=collections.Counter(ve).most_common(2)

if(ce[0][0] != co[0][0]):
    ans = len(v) - ce[0][1] - co[0][1]
elif(len(ce)==1 and len(co)==1):
    ans = len(v) // 2
elif(len(ce)==1):
    ans = len(v) // 2 - co[1][1]
elif(len(co)==1):
    ans = len(v) // 2 - ce[1][1]
else:
    ans = len(v) - max( co[0][1]+co[1][1], co[1][1]+co[0][1])

print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
x = list(map(int, input().split()))
y=[]
z=[]
from collections import Counter
for i in range(a):
    if i%2==0:
        y.append(x[i])
    else:
        z.append(x[i])
y.append(0)
z.append(0)
c= Counter(y)
d = Counter(z)
c1=c.most_common()[0][1]
if c.most_common()[1][0]==0:c2=0
else:c2=c.most_common()[1][1]
d1=d.most_common()[0][1]
if d.most_common()[1][0]==0:d2=0
else:d2=d.most_common()[1][1]
print(c1,c2,d1,d2)
if c.most_common()[0][0]== d.most_common()[0][0]:
    s = a-max(c1+d2,c2+d1)
    print(a,c1+d2,c2+d1)
    print(c)
    print(d)

else:s= a - c.most_common()[0][1] - d.most_common()[0][1]
print(s)