Problem:


Score : 300 points

Problem Statement

A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:

For each i = 1,2,..., n-2, a_i = a_{i+2}.

Exactly two different numbers appear in the sequence.

You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

Print the minimum number of elements that needs to be replaced.

Sample Input 1

4
3 1 3 2

Sample Output 1

1

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

The sequence 105,119,105,119,105,119 is /\/\/\/.

Sample Input 3

4
1 1 1 1

Sample Output 3

2

The elements of the sequence 1,1,1,1 are all the same, so it is not /\/\/\/.



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

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

kisu = v[::2]
gusu = v[1::2]

kisu_cnt = collections.Counter(kisu)
gusu_cnt = collections.Counter(gusu)

kisu_cnt = kisu_cnt.most_common(2)#引数にnを用意すると，出現回数の多い順にn子だけ呼び出せる
gusu_cnt = gusu_cnt.most_common(2)
kisu_most  = 0
gusu_most = 0
if kisu_cnt[0][0]!=gusu_cnt[0][0]:
    print(n-kisu_cnt[0][1]-gusu_cnt[0][1])
    exit()
else:
    if len(kisu_cnt)==len(gusu_cnt):
        print(n//2)
        exit()
    else:
        print(n-max(kisu_cnt[0][1]+gusu_cnt[1][1],kisu_cnt[1][1]+gusu_cnt[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
kisu = []
gusu = []
for i in range(n):
    if i%2==0:
        kisu.append(v[i])
    else:
        gusu.append(v[i])
kisu_cnt = collections.Counter(kisu)
gusu_cnt = collections.Counter(gusu)

kisu_cnt = kisu_cnt.most_common()
gusu_cnt = gusu_cnt.most_common()
kisu_most  = 0
gusu_most = 0

if kisu_cnt[-1][0] == gusu_cnt[-1][0]:
    if len(kisu_cnt)==len(gusu_cnt):
        print(len(kisu_cnt))
        exit()
    if kisu_cnt[-1][1] > gusu_cnt[-1][1]:
        kisu_most = kisu_cnt[-1][1]
        gusu_most = gusu_most[-2][1]
    else:
        kisu_most = kisu_cnt[-2][1]
        gusu_most = gusu_cnt[-1][1]
else:
    kisu_most = kisu_cnt[-1][1]
    gusu_most = gusu_cnt[-1][1]

print(n-kisu_most-gusu_most)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [int(i) for i in input().split()]
kisu = []
gusu = []
for i in range(n):
    if i%2==0:
        kisu.append(v[i])
    else:
        gusu.append(v[i])
kisu_cnt = collections.Counter(kisu)
gusu_cnt = collections.Counter(gusu)

kisu_cnt = kisu_cnt.most_common()
gusu_cnt = gusu_cnt.most_common()
kisu_most  = 0
gusu_most = 0
if len(kisu_cnt)==len(gusu_cnt)==1:
    print(0)
    exit()
if kisu_cnt[-1][0] == gusu_cnt[-1][0]:
    if kisu_cnt[-1][1] > gusu_cnt[-1][1]:
        kisu_most = kisu_cnt[-1][1]
        gusu_most = gusu_most[-2][1]
    else:
        kisu_most = kisu_cnt[-2][1]
        gusu_most = gusu_cnt[-1][1]
else:
    kisu_most = kisu_cnt[-1][1]
    gusu_most = gusu_cnt[-1][1]

print(n-kisu_most-gusu_most)

Submission status: Wrong Answer

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

n = len(v)
from collections import defaultdict
c0 = defaultdict(int)
for vi in v[0::2]:
    c0[vi] += 1
c1 = defaultdict(int)
for vi in v[1::2]:
    c1[vi] += 1

sc0 = sorted(c0.items(), key=lambda x: x[1])
sc1 = sorted(c1.items(), key=lambda x: x[1])

if sc0[-1][0] != sc1[-1][0]:
    #print('--1')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-1][1])
    exit()
if len(sc0) == 1 and len(sc1) == 1:
    #print('--2')
    print(n//2)
    exit()
if sc0[-1][1] == sc1[-1][1]:
    if sc0[-2][1] > sc1[-2][1]:
        print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    else:
        print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()
if sc0[-1][1] > sc1[-1][1]:
    #print('--3')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    exit()
else:
    #print('--4')
    print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()

Submission status: Wrong Answer

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

n = len(v)
from collections import defaultdict
c0 = defaultdict(int)
for vi in v[0::2]:
    c0[vi] += 1
c1 = defaultdict(int)
for vi in v[1::2]:
    c1[vi] += 1

sc0 = sorted(c0.items(), key=lambda x: x[1])
sc1 = sorted(c1.items(), key=lambda x: x[1])

#print(sc0, sc1)
if sc0[-1][0] != sc1[-1][0]:
    #print('--1')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-1][1])
    exit()
if len(sc0) == 1 and len(sc1) == 1:
    #print('--2')
    print(n//2)
    exit()
if sc0[-1][1] > sc1[-1][1]:
    #print('--3')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    exit()
else:
    #print('--4')
    print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()

Submission status: Wrong Answer

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

n = len(v)
from collections import defaultdict
c0 = defaultdict(int)
for vi in v[0::2]:
    c0[vi] += 1
c1 = defaultdict(int)
for vi in v[1::2]:
    c1[vi] += 1

sc0 = sorted(c0.items(), key=lambda x: x[1])
sc1 = sorted(c1.items(), key=lambda x: x[1])

#print(sc0, sc1)
if sc0[-1][0] != sc1[-1][0]:
    #print('--1')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-1][1])
    exit()
if len(sc0) == 1 and len(sc1) == 1:
    #print('--2')
    print(n//2)
    exit()
if sc0[-1][1] >= sc1[-1][1]:
    #print('--3')
    if sc0[-1][0] != sc1[-2][0]:
        print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    else:
        print(n//2 - sc0[-1][1] + n//2 - sc1[-3][1])
    exit()
else:
    #print('--4')
    print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()

Submission status: Wrong Answer

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

n = len(v)
from collections import defaultdict
c0 = defaultdict(int)
for vi in v[0::2]:
    c0[vi] += 1
c1 = defaultdict(int)
for vi in v[1::2]:
    c1[vi] += 1

sc0 = sorted(c0.items(), key=lambda x: x[1])
sc1 = sorted(c1.items(), key=lambda x: x[1])

#print(sc0, sc1)
if sc0[-1][0] != sc1[-1][0]:
    #print('--1')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-1][1])
    exit()
if len(sc0) == 1 and len(sc1) == 1:
    #print('--2')
    print(n//2)
    exit()
if sc0[-1][1] >= sc1[-1][1]:
    #print('--3')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    exit()
else:
    #print('--4')
    print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()

Submission status: Wrong Answer

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

n = len(v)
from collections import defaultdict
c0 = defaultdict(int)
for vi in v[0::2]:
    c0[vi] += 1
c1 = defaultdict(int)
for vi in v[1::2]:
    c1[vi] += 1

sc0 = sorted(c0.items(), key=lambda x: x[1])
sc1 = sorted(c1.items(), key=lambda x: x[1])

print(sc0, sc1)
if sc0[-1][0] != sc1[-1][0]:
    print('--1')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-1][1])
    exit()
if len(sc0) == 1 and len(sc1) == 1:
    print('--2')
    print(n//2)
    exit()
if sc0[-1][1] >= sc1[-1][1]:
    print('--3')
    print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    exit()
else:
    print('--4')
    print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()

Submission status: Wrong Answer

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

from collections import defaultdict
c0 = defaultdict(int)
for vi in v[0::2]:
    c0[vi] += 1
c1 = defaultdict(int)
for vi in v[1::2]:
    c1[vi] += 1

sc0 = sorted(c0.items(), key=lambda x: x[1])
sc1 = sorted(c1.items(), key=lambda x: x[1])

if sc0[-1][0] != sc1[-1][0]:
    print(n//2 - sc0[-1][1] + n//2 - sc1[-1][1])
    exit()
if len(sc0) == 1 and len(sc1) == 1:
    print(n//2)
    exit()
if sc0[-1][1] > sc1[-1][1]:
    print(n//2 - sc0[-1][1] + n//2 - sc1[-2][1])
    exit()
else:
    print(n//2 - sc0[-2][1] + n//2 - sc1[-1][1])
    exit()

Submission status: Wrong Answer

Solution code:
from itertools import combinations
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
s = list(set(a))
ans = 10**6
c = Counter(a)
if len(s)==1:
    print(n//2)
else:
    l = list(c.keys())[:2]
    d,e=0,0
    for i in range(n):
        if i%2==0:
            if l[1]!=a[i]:
                e+=1
            if l[0]!=a[i]:
                d+=1
        else:
            if l[1]!=a[i]:
                d+=1
            if l[0]!=a[i]:
                e+=1
    print(min(d,e))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split(' ')))
    v_odd, v_even = list(), list()
    for i in range(n):
        if i % 2 == 0:
            v_even.append(v[i])
        else:
            v_odd.append(v[i])
    odd_top2 = Counter(v_odd).most_common(2)
    even_top2 = Counter(v_even).most_common(2)
    if odd_top2[0][0] != even_top2[0][0]:
        print(n - odd_top2[0][1] - even_top2[0][1])
    else:
        odd_tbc = len(v_odd) - odd_top2[0][1]
        even_tbc = len(v_even) - even_top2[0][1]
        if odd_tbc < even_tbc:
            if len(even_top2) > 1:
                print(n - odd_top2[0][1] - even_top2[1][1])
            else:
                print(n - odd_top2[0][1])
        else:
            if len(odd_top2) > 1:
                print(n - odd_top2[1][1] - even_top2[0][1])
            else:
                print(n - even_top2[0][1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
v = list(map(int, input().split()))

# 偶数番目の要素において、iの数が何個あったか
even = [0 for i in range(100001)]
# 奇数番目の要素において、iの数が何個あったか
odd = [0 for i in range(100001)]

# 偶数番目、奇数番目の要素、それぞれ数える
for i in range(0, n-1, 2):
    even[v[i]] += 1
    odd[v[i+1]] += 1

# 偶数番目の要素のうち最も多かった数値
maxeveni = -1
# 偶数番目の要素のうち最も多かった数値の個数
maxeven = 0
# 偶数番目の要素のうち2番目に多かった数値の個数
preeven = 0

# 奇数番目の要素のうち最も多かった数値
maxoddi = -1
# 奇数番目の要素のうち最も多かった数値の個数
maxodd = 0
# 奇数番目の要素のうち2番目に多かった数値の個数
preodd = 0

# 偶数番目の要素を走査
for i in range(1, 100001):
    num = even[i]
    if maxeven <= num:
        maxeveni = i
        preeven = maxeven
        maxeven = num

# 奇数番目の要素を走査
for i in range(1, 100001):
    num = odd[i]
    if maxodd <= num:
        maxoddi = i
        preodd = maxodd
        maxodd = num

ans = 0

# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していなかった場合
if maxeveni != maxoddi:
    ans = n - maxeven - maxodd
# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していた場合
else:
    ans = min(n - preeven - maxodd, n - maxeven - preodd)
print(ans)

Submission status: Wrong Answer

Solution code:
inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
v = list(map(int, input().split()))

# 偶数番目の要素において、iの数が何個あったか
even = [0 for i in range(100001)]
# 奇数番目の要素において、iの数が何個あったか
odd = [0 for i in range(100001)]

# 偶数番目、奇数番目の要素、それぞれ数える
for i in range(0, n-1, 2):
    even[v[i]] += 1
    odd[v[i+1]] += 1

# 偶数番目の要素のうち最も多かった数値
maxeveni = -1
# 偶数番目の要素のうち最も多かった数値の個数
maxeven = 0
# 偶数番目の要素のうち2番目に多かった数値の個数
preeven = 0

# 奇数番目の要素のうち最も多かった数値
maxoddi = -1
# 奇数番目の要素のうち最も多かった数値の個数
maxodd = 0
# 奇数番目の要素のうち2番目に多かった数値の個数
preodd = 0

# 偶数番目の要素を走査
for i in range(1, 100001):
    num = even[i]
    if maxeven <= num:
        maxeveni = i
        preeven = maxeven
        maxeven = num

# 奇数番目の要素を走査
for i in range(1, 100001):
    num = odd[i]
    if maxodd <= num:
        maxoddi = i
        preodd = maxodd
        maxodd = num

ans = 0

# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していなかった場合
if maxeveni != maxoddi:
    ans = n - maxeven - maxodd
# 要素のうち最も多かった数値が偶数番目と奇数番目で一致していた場合
else:
    ans = max(n - preeven - maxodd, n - maxeven - preodd)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
ans1=[0]*(10**5+1)#偶数
ans2=[0]*(10**5+1)#奇数
for i in v[0::2]:
  ans1[i]+=1
for i in v[1::2]:
  ans2[i]+=1
m1=max(ans1)
m2=max(ans2)
flag=False
for i in range(10**5+1):
  if ans1[i]==m1 and ans2[i]==m2:
    falg=True
    ans1.sort()
    ans2.sort()
    m12=ans1[-2]
    m22=ans2[-2]
    break
if len(set(v))==1:
  print(n//2)
elif flag:
  print(n-max(m12+m1,m21+m2))
else:
  print(n-m1-m2)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
ans1=[0]*(10**5+1)#偶数
ans2=[0]*(10**5+1)#奇数
for i in v[0::2]:
  ans1[i]+=1
for i in v[1::2]:
  ans2[i]+=1
m1=max(ans1)
m2=max(ans2)
flag=False
for i in range(n+1):
  if ans1[i]==m1 and ans2[i]==m2:
    falg=True
    ans1.sort()
    ans2.sort()
    m12=ans1[-2]
    m22=ans2[-2]
    break
if len(set(v))==1:
  print(n//2)
elif flag:
  print(n-max(m12+m1,m21+m2))
else:
  print(n-m1-m2)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
ans1=[0]*(10**5+1)#偶数
ans2=[0]*(10**5+1)#奇数
for i in v[0::2]:
  ans1[i]+=1
for i in v[1::2]:
  ans2[i]+=1
m1=max(ans1)
m2=max(ans2)
flag=False
for i in range(n+1):
  if ans1[i]==m1 and ans2[i]==m2:
    falg=True
    ans1.sort()
    ans2.sort()
    m12=ans1[-2]
    m22=ans2[-2]
    break
if flag:
  print(n-max(m12+m1,m21+m2))
else:
  print(n-m1-m2)

Submission status: Wrong Answer

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

if len(set(V)) == 1:
    print(len(V)//2)
    sys.exit(0)

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

for i in range(N):
    if i % 2 == 0:
        even[V[i]] += 1
    else:
        odd[V[i]] += 1

ans = N - max(even.values()) - max(odd.values())
print(ans)

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq # 優先度付きキュー(最小値取り出し)

inf = 10**15
mod = 10**9+7
n = int(input())
v = list(map(int, input().split()))
left = [0 for i in range(100001)]
right = [0 for i in range(100001)]
for i in range(0,n,2):
    left[v[i]]+=1
    right[v[i+1]]+=1
maxleft = 0
maxlind = -1
preleft = 0
maxright = 0
maxrind = -1
preright = 0
for i in range(1,100001):
    num = left[i]
    if maxleft <= num:
        maxlind = i
        preleft = maxleft
        maxleft = num
for i in range(1,100001):
    num = right[i]
    if maxright <= num:
        maxrind = i
        preright = maxright
        maxright = num
ans = 0
if maxlind != maxrind:
    ans = n - maxleft - maxright
else:
    ans = min(n - preleft - maxright, n - maxleft - preright)
print(ans)

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq # 優先度付きキュー(最小値取り出し)

inf = 10**15
mod = 10**9+7
n = int(input())
v = list(map(int, input().split()))
left = [0 for i in range(100001)]
right = [0 for i in range(100001)]
for i in range(0,n-1,2):
    left[v[i]]+=1
    right[v[i+1]]+=1
maxleft = 0
maxlind = -1
preleft = 0
maxright = 0
maxrind = -1
preright = 0
for i in range(1,100001):
    num = left[i]
    if maxleft <= num:
        maxlind = i
        preleft = maxleft
        maxleft = num
for i in range(1,100001):
    num = right[i]
    if maxright <= num:
        maxrind = i
        preright = maxright
        maxright = num
ans = 0
if maxlind != maxrind:
    ans = n - maxleft - maxright
else:
    ans = max(n - preleft - maxright, n - maxleft - preright)
print(ans)

Submission status: Wrong Answer

Solution code:
inf = 10**15
mod = 10**9+7
n = int(input())
v = list(map(int, input().split()))
left = [0 for i in range(100001)]
right = [0 for i in range(100001)]
for i in range(0,n-1,2):
    left[v[i]]+=1
    right[v[i+1]]+=1
maxleft = 0
maxlind = -1
preleft = 0
maxright = 0
maxrind = -1
preright = 0
for i,num in enumerate(left):
    if maxleft <= num:
        maxlind = i
        preleft = maxleft
        maxleft = num
for i,num in enumerate(right):
    if maxright <= num:
        maxrind = i
        preright = maxright
        maxright = num
ans = 0
if maxlind != maxrind:
    ans = n - maxleft - maxright
else:
    ans = max(n - preleft - maxright, n - maxleft - preright)
print(ans)

Submission status: Wrong Answer

Solution code:
inf = 10**15
mod = 10**9+7
n = int(input())
v = list(map(int, input().split()))
left = [0 for i in range(100001)]
right = [0 for i in range(100001)]
for i in range(0,n-1,2):
    left[v[i]]+=1
    right[v[i+1]]+=1
maxleft = 0
maxlind = -1
preleft = 0
maxright = 0
maxrind = -1
preright = 0
for i,num in enumerate(left):
    if maxleft <= num:
        maxlind = i
        preleft = maxleft
        maxleft = num
for i,num in enumerate(right):
    if maxright <= num:
        maxrind = i
        preright = maxright
        maxright = num
if maxlind == maxrind:
    if preleft > preright:
        maxright = preright
    else:
        maxleft = preleft
print(n - maxleft - maxright)

Submission status: Wrong Answer

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

import collections
ans = collections.Counter(a)
ans = ans.most_common()

if len(ans) < 2:
  print(n//2)
    
elif len(ans) == 2:
  print(abs(n//2 - ans[0][1]))
  
else:
  print(abs(n//2 - ans[0][1]) + abs(n//2 - ans[1][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
V = [int(i) for i in input().split()]
Ki = []
Gu = []
switch = True
for i in range(N):
    if switch:
        Ki.append(V[i])
    else:
        Gu.append(V[i])
    switch = not switch

K = sorted(Counter(Ki).items(),key=lambda x:x[1],reverse=True)
G = sorted(Counter(Gu).items(),key=lambda x:x[1],reverse=True)
sk = len(K)
gk = len(G)
if sk==1 and gk==1:
    if G[0][0]==K[0][0]:
        print(N//2)
    else:
        print(N)
elif sk==1:
    if G[0][0]==K[0][0]:
        print(N-K[0][1]-G[1][1])
    else:
        print(N-K[0][1]-G[0][1])
elif gk == 1:
    if G[0][0]==K[0][0]:
        print(N-K[1][1]-G[0][1])
    else:
        print(N-K[0][1]-G[0][1])
else:
    if G[0][0] == K[0][0]:
        s1 = K[0][1]+G[1][1]
        s2 = K[1][1]+G[0][1]
        print(N-max(s1,s2))
    else:
        print(N-K[0][1]-G[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
V = [int(i) for i in input().split()]
Ki = []
Gu = []
switch = True
for i in range(N):
    if switch:
        Ki.append(V[i])
    else:
        Gu.append(V[i])
    switch = not switch

K = list(Counter(Ki).items())
G = list(Counter(Gu).items())
sk = len(K)
gk = len(G)
if sk==1 and gk==1:
    if G[0][0]==K[0][0]:
        print(N//2)
    else:
        print(0)
elif sk==1:
    if G[0][0]==K[0][0]:
        print(N-K[0][1]-G[1][1])
    else:
        print(N-K[0][1]-G[0][1])
elif gk == 1:
    if G[0][0]==K[0][0]:
        print(N-K[1][1]-G[0][1])
    else:
        print(N-K[0][1]-G[0][1])
else:
    if G[0][0] == K[0][0]:
        s1 = K[0][1]+G[1][1]
        s2 = K[1][1]+G[0][1]
        print(N-max(s1,s2))
    else:
        print(N-K[0][1]-G[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
conk=Counter(v[0:n:2])
cong=Counter(v[1:n:2])
ki=[]
gu=[]
khan=0

ghan=0

for i in range(len(v)):
  if i%2==0:
    ki.append(v[i])
    if khan < conk[v[i]]:
      khan=conk[v[i]]
      
  else:
    gu.append(v[i])
    if ghan < cong[v[i]]:
      ghan=cong[v[i]]
if len(set(v))!=1:
  print(n-ghan-khan)
else:
  print(n//2)

Submission status: Wrong Answer

Solution code:
inf = 10**15
mod = 10**9+7

n = int(input())
v = list(map(int, input().split()))
left = [0 for i in range(100001)]
right = [0 for i in range(100001)]
for i in range(0,n-1,2):
    left[v[i]]+=1
    right[v[i+1]]+=1
lmax = max(left)
rmax = max(right)
print(n-lmax-rmax)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
for i in range(n):
    if i%2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
if len(odd) == 1 and len(even) == 1:
    if odd.keys() == even.keys():
        print(n//2)
    else:
        print(0)
else:
    mx1 = 0
    mx2 = 0
    for i in odd.keys():
        if mx1 < odd[i]:
            mx2 = mx1
            mx1 = odd[i]
            nx = i
        elif mx2 < odd[i]:
            mx2 = odd[i]
    my1 = 0
    my2 = 0
    for i in even.keys():
        if my1 < even[i]:
            my2 = my1
            my1 = even[i]
            ny = i
        elif my2 < even[i]:
            my2 = even[i]
    if nx == ny:
        if mx1 > my1:
            print(n - mx1 - my2)
        else:
            print(n - mx2 - my1)
    else:
        print(n - mx1 - my1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
for i in range(n):
    if i%2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
if len(odd) == 1 and len(even) == 1:
    if odd.keys() == even.keys():
        print(n//2)
    else:
        print(0)
else:
    mx1 = 0
    mx2 = 0
    for i in odd.keys():
        if mx1 < odd[i]:
            mx2 = mx1
            mx1 = odd[i]
            nx = i
        elif mx2 < odd[i]:
            mx2 = odd[i]
    my1 = 0
    my2 = 0
    for i in even.keys():
        if my1 < even[i]:
            my2 = my1
            my1 = even[i]
            ny = i
        elif my2 < even[i]:
            my2 = even[i]
    if nx == ny:
        if mx1 > my1:
            print(sum(odd.values()) - mx1 + sum(even.values()) - my2)
        else:
            print(sum(odd.values()) - mx2 + sum(even.values()) - my1)
    else:
        print(sum(odd.values()) - mx1 + sum(even.values()) - my1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
for i in range(n):
    if i%2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
if len(odd) == 1 and len(even) == 1:
    if odd.keys() == even.keys():
        print(n//2)
    else:
        print(0)
else:
    mx1 = 0
    mx2 = 0
    for i in odd.keys():
        if mx1 < odd[i]:
            mx2 = mx1
            mx1 = odd[i]
            nx = i
    my1 = 0
    my2 = 0
    for i in even.keys():
        if my1 < even[i]:
            my2 = my1
            my1 = even[i]
            ny = i
    if nx == ny:
        if mx1 > my1:
            print(sum(odd.values()) - mx1 + sum(even.values()) - my2)
        else:
            print(sum(odd.values()) - mx2 + sum(even.values()) - my1)
    else:
        print(sum(odd.values()) - mx1 + sum(even.values()) - my1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
for i in range(n):
    if i%2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
if len(odd) == 1 and len(even) == 1:
    if odd.keys() == even.keys():
        print(n//2)
    else:
        print(0)
else:
    mx1 = -1
    mx2 = -2
    for i in odd.keys():
        if mx1 < odd[i]:
            mx2 = mx1
            mx1 = odd[i]
            nx = i
    my1 = -1
    my2 = -2
    for i in even.keys():
        if my1 < even[i]:
            my2 = my1
            my1 = even[i]
            ny = i
    if nx == ny:
        print(min(sum(odd.values()) - mx1 + sum(even.values()) - my2, sum(odd.values()) - mx2 + sum(even.values()) - my1))
        """
        if mx1 > my1:
            print(sum(odd.values()) - mx1 + sum(even.values()) - my2)
        else:
            print(sum(odd.values()) - mx2 + sum(even.values()) - my1)
        """
    else:
        print(sum(odd.values()) - mx1 + sum(even.values()) - my1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
for i in range(n):
    if i%2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
if len(odd) == 1 and len(even) == 1:
    if odd.keys() == even.keys():
        print(n//2)
    else:
        print(0)
else:
    mx1 = -1
    mx2 = -2
    for i in odd.keys():
        if mx1 < odd[i]:
            mx2 = mx1
            mx1 = odd[i]
            nx = i
    my1 = -1
    my2 = -2
    for i in even.keys():
        if my1 < even[i]:
            my2 = my1
            my1 = even[i]
            ny = i
    """
    if nx == ny:
        if mx1 > my1:
            print(sum(odd.values()) - mx1 + sum(even.values()) - my2)
        else:
            print(sum(odd.values()) - mx2 + sum(even.values()) - my1)
    """
    print(sum(odd.values()) - mx1 + sum(even.values()) - my1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
for i in range(n):
    if i%2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
if len(odd) == 1 and len(even) == 1:
    if odd.keys() == even.keys():
        print(n//2)
    else:
        print(0)
else:
    mx1 = -1
    mx2 = -2
    for i in odd.keys():
        if mx1 < odd[i]:
            mx2 = mx1
            mx1 = odd[i]
            nx = i
    my1 = -1
    my2 = -2
    for i in even.keys():
        if my1 < even[i]:
            my2 = my1
            my1 = even[i]
            ny = i
    if nx == ny:
        if mx1 < my1:
            print(sum(odd.values()) - mx1 + sum(even.values()) - my2)
        else:
            print(sum(odd.values()) - mx2 + sum(even.values()) - my1)
    else:
        print(sum(odd.values()) - mx1 + sum(even.values()) - my1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
for i in range(n):
    if i%2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
if len(odd) == 1 and len(even) == 1:
    if odd.keys() == even.keys():
        print(n//2)
    else:
        print(0)
else:
    mx1 = -1
    mx2 = -2
    for i in odd.keys():
        if mx1 < odd[i]:
            mx2 = mx1
            mx1 = odd[i]
            nx = i
    my1 = -1
    my2 = -2
    for i in even.keys():
        if my1 < even[i]:
            my2 = my1
            my1 = even[i]
            ny = i
    if nx == ny:
        if mx1 > my1:
            print(sum(odd.values()) - mx1 + sum(even.values()) - my2)
        else:
            print(sum(odd.values()) - mx2 + sum(even.values()) - my1)
    else:
        print(sum(odd.values()) - mx1 + sum(even.values()) - my1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
for i in range(n):
    if i%2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
if len(odd) == 1 and len(even) == 1:
    if odd.keys() == even.keys():
        print(n//2)
    else:
        print(0)
else:
    mx1 = -1
    mx2 = -2
    for i in odd.keys():
        if mx1 < odd[i]:
            mx2 = mx1
            mx1 = odd[i]
            nx = i
    my1 = -1
    my2 = -2
    for i in even.keys():
        if my1 < even[i]:
            my2 = my1
            my1 = even[i]
            ny = i
    if nx == ny:
        if mx1 > my1:
            print(sum(odd.values()) - mx1 + sum(even.values()) - my2)
        else:
            print(sum(odd.values()) - mx2 + sum(even.values()) - my1)
    else:
        print(sum(odd.values()) - max(odd.values()) + sum(even.values()) - max(even.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
odd = {}
even = {}
for i in range(n):
    if i%2 == 1:
        if v[i] not in odd:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1
    else:
        if v[i] not in even:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
if len(odd) == 1 and len(even) == 1:
    if odd.keys() == even.keys():
        print(n//2)
    else:
        print(0)
elif max(odd.values()) == n//2 and max(even.values()) == n//2:
    print(n//2)
else:
    print(sum(odd.values()) - max(odd.values()) + sum(even.values()) - max(even.values()))

Submission status: Wrong Answer

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

c_0 = collections.Counter(a[::2])
c_1 = collections.Counter(a[1::2])

if len(c_0.most_common()) == 1 and len(c_1.most_common()) == 1:
  if c_0.most_common()[0][0] == c_1.most_common()[0][0]:
    print(n // 2)
  else:
    print(0)
elif len(c_0.most_common()) == 1:
  if c_0.most_common()[0][0] == c_1.most_common()[0][0]:
    print(n // 2 - c_1.most_common()[1][1])
  else:
    print(n // 2 - c_1.most_common()[0][1])
elif len(c_1.most_common()) == 1:
  if c_0.most_common()[0][0] == c_1.most_common()[0][0]:
    print(n // 2 - c_0.most_common()[1][1])
  else:
    print(n // 2 - c_0.most_common()[0][1])
elif c_0.most_common()[0][0] == c_1.most_common()[1][0]:
  if c_0.most_common()[0][1] > c_1.most_common()[1][1]:
    print(n - c_0.most_common()[0][1] - c_1.most_common()[1][1])
  elif c_0.most_common()[0][1] < c_1.most_common()[1][1]:
    print(n - c_0.most_common()[1][1] - c_1.most_common()[0][1])
  else:
    print(n - c_0.most_common()[0][1] - max(c_0.most_common()[1][1],c_1.most_common()[1][1]))
else:
  print(n - c_0.most_common()[0][1] - c_1.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
odd=[v[i] for i in range(1,n,2)]
even=[v[i] for i in range(0,n,2)]
from collections import defaultdict
d_odd=defaultdict(int)
d_even=defaultdict(int)
for i in range(len(odd)):
    d_odd[odd[i]]+=1
for i in range(len(even)):
    d_even[even[i]]+=1

d_odd=sorted(d_odd.items(),key=lambda x:x[1])
d_even=sorted(d_even.items(),key=lambda x:x[1])
if d_odd[0][0]!=d_even[0][0]:
    ans=(len(odd)-d_odd[0][1])+(len(even)-d_even[0][1])
else:
    if len(d_odd)==1 and len(d_even)==1:
        ans=len(odd)
    elif len(d_odd)==1:
        ans=(len(even)-d_even[1][1])
    elif len(d_even)==1:
        ans=(len(odd)-d_odd[1][1])
    else:
        x=(len(odd)-d_odd[1][1])+(len(even)-d_even[0][1])
        y=(len(odd)-d_odd[0][1])+(len(even)-d_even[1][1])
        ans=min(x,y)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
V = [int(i) for i in input().split()]

C0 = collections.Counter(V[0::2])
C0[0] = 0

C1 = collections.Counter(V[1::2])
C1[0] = 0

if C0.most_common()[0][0] != C1.most_common()[0][0]:
    print(N-C0.most_common()[0][1]-C1.most_common()[0][1])
else:
    print(max(N-C0.most_common()[0][1]-C1.most_common()[1]
              [1], N-C0.most_common()[1][1]-C1.most_common()[0][1]))