Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
from statistics import mode

tmp_list = [1, 1, 1, 1, 0, 1, 1]
print(mode(tmp_list))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
cnt = 0
if v.count(v[0]) == n:
    print(n//2)
else:
    for i in range(0,n-2,2):
        if v[i] != v[i+2]:
            cnt +=1
    for i in range(1,n-2,2):
        if v[i] != v[i+2]:
            cnt +=1  
    print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
cnt = 0
if v.count(1) == n:
    print(n//2)
else:
    for i in range(0,n-2,2):
        if v[i] != v[i+2]:
            cnt +=1
    for i in range(1,n-2,2):
        if v[i] != v[i+2]:
            cnt +=1  
    print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
li = list(map(int, input().split()))
c = collections.Counter(li)
count = 0
if len(c.most_common(2)) == 1:
    print(c.most_common(2)[0][1]//2)
    exit()
elif len(c.most_common(2)) == 2 and c.most_common(2)[0][1] == c.most_common(2)[1][1]:
    print(0)
    exit()
else:
    for item in c.most_common()[2:]:
        count += item[1]
print(count)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
li = list(map(int, input().split()))
c = collections.Counter(li)
if c.most_common()[-1][1] == n//2: 
    print(0)
elif c.most_common()[-1][1] == n:
    print(n//2)
else:
    print(c.most_common()[-1][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter


def num_of_nth_often(lst, nth):
    counted_list = sorted(list(Counter(lst).values()), reverse=True)

    if len(counted_list) < nth:
        return 0
    else:
        return counted_list[nth - 1]


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

v_even = []
v_odd = []

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

if v[0] != v[1]:
    rewrite_num = len(v_even) - num_of_nth_often(v_even, 1) + len(v_odd) - num_of_nth_often(v_odd, 1)
    print(rewrite_num)
else:
    rewrite_num1 = len(v_even) - num_of_nth_often(v_even, 1) + len(v_odd) - num_of_nth_often(v_odd, 2)
    rewrite_num2 = len(v_even) - num_of_nth_often(v_even, 2) + len(v_odd) - num_of_nth_often(v_odd, 1)
    print(min(rewrite_num1, rewrite_num2))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def num_of_nth_often(lst, nth):
    counted_list = sorted(list(Counter(lst).values()), reverse=True)

    if len(counted_list) < nth:
        return 0
    else:
        return counted_list[nth - 1]


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

v_even = []
v_odd = []

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

if v[0] != v[1]:
    rewrite_num = len(v_even) - num_of_nth_often(v_even, 1) + len(v_odd) - num_of_nth_often(v_odd, 1)
    print(rewrite_num)
else:
    rewrite_num1 = len(v_even) - num_of_nth_often(v_even, 1) + len(v_odd) - num_of_nth_often(v_odd, 2)
    rewrite_num2 = len(v_even) - num_of_nth_often(v_even, 2) + len(v_odd) - num_of_nth_often(v_odd, 1)
    print(max(rewrite_num1, rewrite_num2))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split( )))
v_even = v[0::2]
v_odd = v[1::2]
v = collections.Counter(v)
v0 = collections.Counter(v_even)
v1 = collections.Counter(v_odd)
values, counts = zip(*v.most_common())
values0, counts0 = zip(*v0.most_common())
values1, counts1 = zip(*v1.most_common())
count = 0
if len(counts) == 1:
    count += min(counts0[0],counts1[0]) 
if len(counts0) != 1:
    count += sum(counts0) - counts0[0]
if len(counts1) != 1:
    count += sum(counts1) - counts1[0]
print(count)

Submission status: Wrong Answer

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

count = 0
v1 = []
v2 = []
while count < n:
  v1.append(v[count])
  v2.append(v[count + 1])
  count += 2

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

num1, count1 = c1.most_common()[0]
num2, count2 = c2.most_common()[0]

if num1 != num2:
  min_count = (n // 2 - count1) + (n // 2 - count2)
elif count1 == count2 and count1 == n // 2:
  min_count = (n // 2)
else:
  if count1 > count2:
    num2, count2 = c2.most_common()[1]
    min_count = (n // 2 - count1) + (n // 2 - count2)
  elif count == count2:
    print("test")
    for i in range(min(len(c1.most_common()), c2.most_common())):
        a = i + 1
        if c1.most_common()[a][a] == c2.most_common()[a][a]:
            continue
        if c1.most_common()[a][a] > c2.most_common()[a][a]:
            num2, count2 = c2.most_common()[a]
            break
        else:
            num1, count1 = c1.most_common()[a]
            break
    min_count = (n // 2 - count1) + (n // 2 - count2)
  else:
    num1, count1 = c1.most_common()[1]
    min_count = (n // 2 - count2) + (n // 2 - count1)
print(min_count)

Submission status: Wrong Answer

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

count = 0
v1 = []
v2 = []
while count < n:
  v1.append(v[count])
  v2.append(v[count + 1])
  count += 2

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

num1, count1 = c1.most_common()[0]
num2, count2 = c2.most_common()[0]

if num1 != num2:
  min_count = (n // 2 - count1) + (n // 2 - count2)
elif count1 == count2 and count1 == n // 2:
  min_count = (n // 2)
else:
  if count1 > count2:
    num2, count2 = c2.most_common()[1]
    min_count = (n // 2 - count1) + (n // 2 - count2)
  elif count == count2:
    for i in range(min(len(c1.most_common()), c2.most_common())):
        a = i + 1
        if c1.most_common()[a][a] == c2.most_common()[a][a]:
            continue
        if c1.most_common()[a][a] > c2.most_common()[a][a]:
            num2, count2 = c2.most_common()[a]
            break
        else:
            num1, count1 = c1.most_common()[a]
            break
    min_count = (n // 2 - count1) + (n // 2 - count2)
  else:
    num1, count1 = c1.most_common()[1]
    min_count = (n // 2 - count2) + (n // 2 - count1)
print(min_count)

Submission status: Wrong Answer

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

count = 0
v1 = []
v2 = []
while count < n:
  v1.append(v[count])
  v2.append(v[count + 1])
  count += 2

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

num1, count1 = c1.most_common()[0]
num2, count2 = c2.most_common()[0]

if num1 != num2:
  min_count = (n // 2 - count1) + (n // 2 - count2)
elif count1 == count2 and count1 == n // 2:
  min_count = (n // 2)
else:
  if count1 > count2:
    num2, count2 = c2.most_common()[1]
    min_count = (n // 2 - count1) + (n // 2 - count2)
  elif count == count2:
    if c1.most_common()[1][1] > c2.most_common()[1][1]:
      num2, count2 = c2.most_common()[1]
    else:
      num1, count1 = c1.most_common()[1]
    min_count = (n // 2 - count1) + (n // 2 - count2)
  else:
    num1, count1 = c1.most_common()[1]
    min_count = (n // 2 - count2) + (n // 2 - count1)
print(min_count)

Submission status: Wrong Answer

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

count = 0
v1 = []
v2 = []
while count < n:
  v1.append(v[count])
  v2.append(v[count + 1])
  count += 2

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

num1, count1 = c1.most_common()[0]
num2, count2 = c2.most_common()[0]

if num1 != num2:
  min_count = (n // 2 - count1) + (n // 2 - count2)
elif num1 == num2 and count1 == count2 and count1 == n // 2:
  min_count = (n // 2)
else:
  if count1 > count2:
    num2, count2 = c2.most_common()[1]
    min_count = (n // 2 - count1) + (n // 2 - count2)
  else:
    num1, count1 = c1.most_common()[1]
    min_count = (n // 2 - count2) + (n // 2 - count1)
print(min_count)

Submission status: Wrong Answer

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

count = 0
v1 = []
v2 = []
while count < n:
  v1.append(v[count])
  v2.append(v[count + 1])
  count += 2

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

num1, count1 = c1.most_common()[0]
num2, count2 = c2.most_common()[0]

if num1 != num2:
  min_count = (n // 2 - count1) + (n // 2 - count2)
elif count1 == count2:
  min_count = (n // 2)
else:
  num2, count2 = c2.most_common()[1]
  min_count = (n // 2 - count1) + (n // 2 - count2)
print(min_count)

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(A)
b=Counter(B)
x=a.most_common(2)
y=b.most_common(2)
if x[0][0]!=y[0][0]:
  print((n//2-x[0][1])+(n//2-y[0][1]))
else:
  if len(x)>1 and len(y)>1:
    if x[0][1]>y[0][1]:
      print((n//2-x[0][1])+(n//2-y[1][1]))
    else:
      print((n//2-x[1][1])+(n//2-y[0][1]))
  elif len(x)>1:
    print(n//2-x[1][1])
  elif len(y)>1:
    print(n//2-y[1][1])
  else:
    print(n//2)

Submission status: Wrong Answer

Solution code:
from scipy import stats
n=int(input())
v=list(map(int,input().split()))
guusuu=v[0::2]
kisuu=v[1::2]


saihin_g,tyome=stats.mode(guusuu)
saihin_k,tyome=stats.mode(kisuu)
saihin_g=int(saihin_g)
saihin_k=int(saihin_k)

if all(guusuu)==saihin_g and all(kisuu)==saihin_k:
    tuika_k=0
    tuika_g=n//2
else:
    tuika_g=n//2-guusuu.count(saihin_g)
    tuika_k=n//2-kisuu.count(saihin_k)

print(tuika_g+tuika_k)

Submission status: Wrong Answer

Solution code:
from scipy import stats
n=int(input())
v=list(map(int,input().split()))
guusuu=v[0::2]
kisuu=v[1::2]


saihin_g,tyome=stats.mode(guusuu)
saihin_k,tyome=stats.mode(kisuu)
saihin_g=int(saihin_g)
saihin_k=int(saihin_k)

if all(v)==saihin_g:
    tuika_k=0
    tuika_g=n//2
else:
    tuika_g=n//2-guusuu.count(saihin_g)
    tuika_k=n//2-kisuu.count(saihin_k)

print(tuika_g+tuika_k)

Submission status: Wrong Answer

Solution code:
from scipy import stats
n=int(input())
v=list(map(int,input().split()))
guusuu=v[0::2]
kisuu=v[1::2]


saihin_g,tyome=stats.mode(guusuu)
saihin_k,tyome=stats.mode(kisuu)
saihin_g=int(saihin_g)
saihin_k=int(saihin_k)

if all(v):
    tuika_k=0
    tuika_g=n//2
else:
    tuika_g=n//2-guusuu.count(saihin_g)
    tuika_k=n//2-kisuu.count(saihin_k)

print(tuika_g+tuika_k)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SLR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

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

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if args else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

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

    d1 = defaultdict(int)
    for i in range(0, n, 2):
        d1[v[i]] += 1
    d2 = defaultdict(int)
    for i in range(1, n, 2):
        d2[v[i]] += 1

    c1, c2 = Counter(d1), Counter(d2)
    if c1.most_common(1)[0][0] == c2.most_common(1)[0][0]:
        if len(c1) == 1 and len(c2) == 1:
            print(n // 2)
        elif c1.most_common(1)[0][1] >= c2.most_common(1)[0][1]:
            print(n - c1.most_common(1)[0][1] - c2.most_common(2)[-1][1])
        else:
            print(n - c1.most_common(2)[-1][1] - c2.most_common(1)[0][1])
    else:
        print(n - c1.most_common(1)[0][1] - c2.most_common(1)[0][1])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a = [list(map(int, input().split())) for i in range(2)]

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

evendic = {}
odddic = {}

evenmax = []
oddmax = []

ans = 0

for i in even:
    if i in evendic:
        evendic[i] += 1
    else:
        evendic[i] = 1
  
for i in odd:
    if i in odddic:
        odddic[i] += 1
    else:
        odddic[i] = 1

evennum = max(evendic.values())
oddnum = max(odddic.values())

for k, v in evendic.items():
    if v == evennum :
        evenmax.append(k)

for k, v in odddic.items():
    if v == oddnum:
        oddmax.append(k)

if even == odd:
    ans = a[0][0] // 2

elif evennum == oddnum:
    if len(evenmax) >= 2 or len(oddmax) >= 2:
        ans = a[0][0] - evennum * 2
    elif max(evendic.items(), key = lambda x:x[1])[0] != max(odddic.items(), key = lambda x:x[1])[0]:
        ans = a[0][0] - evennum * 2
    else:
        ans = a[0][0] - evennum - max([sorted(odddic.values())[-2], sorted(evendic.values())[-2]])

else:
    if max(evendic.items(), key = lambda x:x[1])[0] != max(odddic.items(), key = lambda x:x[1])[0]:
        ans = a[0][0] - evennum - oddnum
    else:
        if evennum > oddnum:
            ans = a[0][0] - evennum - sorted(odddic.values())[-2]
        else:
            ans = a[0][0] - oddnum - sorted(evendic.values())[-2]

    
print(ans)

Submission status: Wrong Answer

Solution code:
a = [list(map(int, input().split())) for i in range(2)]

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

dic = {}
evendic = {}
odddic = {}

for i in a[1]:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

for i in even:
    if i in evendic:
        evendic[i] += 1
    else:
        evendic[i] = 1
  
for i in odd:
    if i in odddic:
        odddic[i] += 1
    else:
        odddic[i] = 1

dicnum = max(dic.values())
evennum = max(evendic.values())
oddnum = max(odddic.values())

if dicnum == a[0][0]:
    print(a[0][0] // 2)
else:
    print(a[0][0] - evennum - oddnum)

Submission status: Wrong Answer

Solution code:
n=int(input())
e=[]
o=[]
v=list(map(int,input().split()))
for i in range(n):
  if i%2==0:
    o.append(v[i])
  else:
    e.append(v[i])
from collections import Counter
o=Counter(o)
e=Counter(e)
o=sorted(o.items(),key=lambda x:x[1],reverse=True)
e=sorted(e.items(),key=lambda x:x[1],reverse=True)

if o[0][0]!=e[0][0]:
  print(n-o[0][1]-e[0][1])
else:
  if o[0][1]==n//2 and e[0][1]==n//2:
    print(n//2)
  elif o[0][1]==n//2:
    print(n//2-e[1][1])
  elif e[0][1]==n//2:
    print(n//2-o[1][1])
  else:
    print(max(n-o[0][1]-e[1][1],n-o[1][1]-e[0][1]))

Submission status: Wrong Answer

Solution code:
n=int(input())
e=[]
o=[]
v=list(map(int,input().split()))
for i in range(n):
  if i%2==0:
    o.append(v[i])
  else:
    e.append(v[i])
from collections import Counter
o=Counter(o)
e=Counter(e)
o=sorted(o.items(),key=lambda x:x[1],reverse=True)
e=sorted(e.items(),key=lambda x:x[1],reverse=True)

if o[0][0]!=e[0][0]:
  print(n-o[0][1]-e[0][1])
else:
  if o[0][1]==n//2 and o[0][1]==n//2:
    print(n//2)
  elif o[0][1]==n//2:
    print(n//2-e[1][1])
  elif e[0][1]==n//2:
    print(n//2-o[1][1])
  else:
    print(max(n-o[0][1]-e[1][1],n-o[1][1]-e[0][1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
assert len(V) == N

Bs = {n:0 for n in V[1::2]}
As = {n:0 for n in V[::2]}

for a,b in zip(V[::2], V[1::2]):
  As[a] += 1
  Bs[b] += 1

As, Bs = reversed(sorted([As, Bs], key=lambda v:max(v.values())))
# Asの方がBsよりも強い

maxA = max(As, key=lambda v:As[v])
seqB = [b for b in Bs if b != maxA]
if len(seqB):
  maxB = max([b for b in Bs if b != maxA], key=lambda v:Bs[v])
  print(N - As[maxA] - Bs[maxB])
else:
  print(N  - As[maxA])

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))
assert len(V) == N

Bs = {n:0 for n in V[1::2]}
As = {n:0 for n in V[::2]}

for a,b in zip(V[::2], V[1::2]):
  As[a] += 1
  Bs[b] += 1

As, Bs = reversed(sorted([As, Bs], key=lambda v:max(v.values())))
# Asの方がBsよりも強い

maxA = max(As, key=lambda v:As[v])
seqB = [b for b in Bs if b != maxA]
if len(seqB):
  maxB = max([b for b in Bs if b != maxA], key=lambda v:Bs[v])
  print(N - As[maxA] - Bs[maxB])
else:
  print(N // 2)

Submission status: Wrong Answer

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

out=0
ki,gu=[], []
for i in range(n):
    if i%2==0:
        ki.append(v[i])
    else:
        gu.append(v[i])
# print('ki,gu:',ki,gu)

if len(set(v)) ==1:  #1種類
    out=len(v)//2

else:
    kiC, guC = collections.Counter(ki), collections.Counter(gu)
    kiI, guI = list(kiC.keys()), list(guC.keys())
    kiV, guV = list(kiC.values()), list(guC.values())
    if max(kiC) == max(guC):
        kiV, guV = sorted(kiV), sorted(guV)
        out = min(kiV[-1] + guV[-2], kiV[-2] + guV[-1] )
    # print(kiC,kiV, guC,guV
    else:
        out+=len(ki) - max(kiV)
        out+=len(gu) - max(guV)

print(out)

Submission status: Wrong Answer

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

out=0
ki,gu=[], []
for i in range(n):
    if i%2==0:
        ki.append(v[i])
    else:
        gu.append(v[i])
# print('ki,gu:',ki,gu)

if len(set(v)) ==1:  #1種類
    out=len(v)//2

else:
    kiC, guC = collections.Counter(ki), collections.Counter(gu)
    kiV, guV = list(kiC.values()), list(guC.values())
    # print(kiC,kiV, guC,guV)
    out+=len(ki) - max(kiV)
    out+=len(gu) - max(guV)

print(out)

Submission status: Wrong Answer

Solution code:
# author:  Taichicchi
# created: 21.09.2020 23:02:12

import sys
from collections import Counter

n = int(input())

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

ans = 0

c1 = Counter(v[::2])

c1_max = max(c1, key=c1.get)

for i in v[::2]:
    if i != c1_max:
        ans += 1

c2 = Counter(v[1::2])

c2_max = max(c2, key=c2.get)

if c1_max == c2_max:
    if len(c2) > 1:
        c2.pop(c2_max)
        c2_max = max(c2, key=c2.get)
    else:
        c2_max += 1

for i in v[1::2]:
    if i != c2_max:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(input().split())
from collections import Counter
x, y = Counter(v[::2]).values(), Counter(v[1::2]).values()
print((n//2-max(x))+(n//2+n%2-max(y)))

Submission status: Wrong Answer

Solution code:
import copy


def check_num(numlist, num):
    index = len(numlist)
    if num in numlist:
        indexs = [i for i, x in enumerate(numlist) if x == num]
        for i in range(len(indexs)):
            if indexs[i]%2 == 0:
                index = indexs[i]
    if index == len(numlist):
        numlist.append(num)
        numlist.append(1)
    else:
        numlist[index+1] += 1

    return numlist


input = [input() for i in range(2)]
n = int(input[0])
input = list(map(int, input[1].split()))
inputcop = copy.copy(input)
del input[::2]
del inputcop[1:-1:2]

def main(n, input):
    numlist = []
    for i in range(n):
        numlist = check_num(numlist, input[i])
    del numlist[::2]
    numlistlen = len(numlist)
    if numlistlen == 1:
        return n
    else:
        maxindex = numlist.index(max(numlist))
        maxval = numlist[maxindex]
        #del numlist[maxindex]
        #max_t_index = numlist.index(max(numlist))
        #max_t_val = numlist[max_t_index]
        return maxval

ans = n
ans -= main(n//2, input)
ans -= main(n//2, inputcop)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy


def check_num(numlist, num):
    index = len(numlist)
    if num in numlist:
        indexs = [i for i, x in enumerate(numlist) if x == num]
        for i in range(len(indexs)):
            if indexs[i]%2 == 0:
                index = indexs[i]
    if index == len(numlist):
        numlist.append(num)
        numlist.append(1)
    else:
        numlist[index+1] += 1

    return numlist


input = [input() for i in range(2)]
n = int(input[0])
input = list(map(int, input[1].split()))
inputcop = copy.copy(input)
del input[::2]
del inputcop[1:-1:2]

def main(n, input):
    numlist = []
    for i in range(n):
        numlist = check_num(numlist, input[i])
    del numlist[::2]
    numlistlen = len(numlist)
    if numlistlen == 1:
        return n
    else:
        maxindex = numlist.index(max(numlist))
        maxval = numlist[maxindex]
        #del numlist[maxindex]
        #max_t_index = numlist.index(max(numlist))
        #max_t_val = numlist[max_t_index]
        return maxval

ans = n
ans -= main(n//2, input)
ans -= main(n//2, inputcop)

Submission status: Wrong Answer

Solution code:
def check_num(numlist, num):
    index = len(numlist)
    if num in numlist:
        indexs = [i for i, x in enumerate(numlist) if x == num]
        for i in range(len(indexs)):
            if indexs[i]%2 == 0:
                index = indexs[i]
    if index == len(numlist):
        numlist.append(num)
        numlist.append(1)
    else:
        numlist[index+1] += 1

    return numlist


input = [input() for i in range(2)]
n = int(input[0])
input = list(map(int, input[1].split()))

numlist = []
for i in range(n):
    numlist = check_num(numlist, input[i])

del numlist[::2]
numlistlen = len(numlist)
if numlistlen == 1:
    if n % 2 == 0:
        print(n//2)
    else:
        print((n-1)//2)
else:
    maxindex = numlist.index(max(numlist))
    maxval = numlist[maxindex]
    del numlist[maxindex]
    #max_t_index = numlist.index(max(numlist))
    #max_t_val = numlist[max_t_index]
    print(n - maxval - 1)

Submission status: Wrong Answer

Solution code:
def check_num(numlist, num):
    index = len(numlist)
    if num in numlist:
        indexs = [i for i, x in enumerate(numlist) if x == num]
        for i in range(len(indexs)):
            if indexs[i]%2 == 0:
                index = indexs[i]
    if index == len(numlist):
        numlist.append(num)
        numlist.append(1)
    else:
        numlist[index+1] += 1

    return numlist


input = [input() for i in range(2)]
n = int(input[0])
input = list(map(int, input[1].split()))

numlist = []
for i in range(n):
    numlist = check_num(numlist, input[i])

del numlist[::2]
numlist = sorted(numlist)
numlistlen = len(numlist)
if numlistlen==1:
    if n %2 == 0:
        print(n//2)
    else:
        print((n-1)//2)
else:
    print(n - numlist[numlistlen -1] - numlist[numlistlen -2])

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
num1= [0]*1000001
num2= [0]*1000001
flag = False
if N%2==0:
  pass
else:
  flag =True
  
  
for i in range(0,N//2):
  num1[a[2*i]]+=1
  num2[a[2*i+1]]+=1
  if i==N//2-1 and flag == True:
    num1[a[2*i+2]]+=1
#print(num1,num2)
max_1 = 0
max_2 = 0
num_1 = 0
num_2 = 0
sec = 0
sec2 = 0
for i in range(100001):
  if max_1<=num1[i]:
    sec = max_1
    max_1 = num1[i]
    num_1 = i
  if max_2<=num2[i]:
    sec2 = max_2
    max_2 = num2[i]
    num_2 = i
if num_1 == num_2:
  if  max_1+sec2>= max_2+sec:
    print(N-max_1+sec2)
  else:
    print(N-max_2+sec)
else:
  #print(max_1,max_2)
  print(N-(max_1+max_2))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
v0 = v[0:n-1:2]
v1 = v[1:n:2]
from collections import Counter
V0 = Counter(v0)
V1 = Counter(v1)
if V0.most_common()[0][0] != V1.most_common()[0][0]:
    a = V0.most_common()[0][1]
    b = V1.most_common()[0][1]
else:
    if V0.most_common()[0][1] >= V1.most_common()[0][1]:
        if len(V1) > 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        else:
            a = V0.most_common()[0][1]
            b = 0
    else:
        if len(V0) > 1:
            a = V1.most_common()[0][1]
            b = V0.most_common()[1][1]
        else:
            a = 0
            b = V1.most_common()[0][1]
print(n-a-b)

Submission status: Wrong Answer

Solution code:
import collections

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

v_list_1 = []
v_list_2 = []

for i in range(0,n//2):
    v_list_1.append(v_list[2*i])
    v_list_2.append(v_list[2*i+1])
    
v_1_c = collections.Counter(v_list_1)
v_2_c = collections.Counter(v_list_2)
v_1_cnt = v_1_c.most_common()[::-1]
v_2_cnt = v_2_c.most_common()[::-1]
ans = 0

ans_1_1 = n//2 -v_1_cnt[-1][1]
ans_2_1 = n//2 -v_2_cnt[-1][1]
if len(v_1_cnt) == 1 and len(v_2_cnt) == 1:
    if v_1_cnt[-1][0] != v_2_cnt[-1][0]:
        ans = 0
    else:
        ans = n//2
else:
    if v_1_cnt[-1][0] != v_2_cnt[-1][0]:
        ans = ans_1_1 + ans_2_1
    else:
        ans_1_2 = n//2 -v_1_cnt[-2][1]
        ans_2_2 = n//2 -v_2_cnt[-2][1]
        ans = min(ans_1_1, ans_1_2) + min(ans_2_1, ans_2_2)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(int(v) for v in input().split())

v_max = max(v)

v0 = v[::2]
v1 = v[1::2]

counter0 = [0] * (v_max + 1)
counter1 = [0] * (v_max + 1)

for v in v0:
    counter0[v] += 1
for v in v1:
    counter1[v] += 1

max0 = 0
for i in range(len(counter0)):
    if counter0[i] > max0:
        max0 = counter0[i]

max1 = 0
for i in range(len(counter1)):
    if counter1[i] > max1:
        max1 = counter1[i]

print(n - max0 - max1)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(int(v) for v in input().split())

v_max = max(v)

v0 = v[::2]
v1 = v[1::2]

counter0 = [0] * (v_max + 1)
counter1 = [0] * (v_max + 1)

for v in v0:
    counter0[v] += 1
for v in v1:
    counter1[v] += 1

max0 = 0
for i in range(len(counter0)):
    if counter0[i] > max0:
        max0 = counter0[i]

max1 = 0
for i in range(len(counter1)):
    if counter1[i] > max1:
        max0 = counter0[i]

print(n - max0 - max1)

Submission status: Wrong Answer

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
import collections
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, Vi):
    V1 = Vi[::2]
    V2 = Vi[1::2]
    c_V1 = dict(collections.Counter(V1))
    c_V2 = dict(collections.Counter(V2))
    c_V1 = sorted(c_V1.items(), key=lambda x: x[1], reverse=True)
    c_V2 = sorted(c_V2.items(), key=lambda x: x[1], reverse=True)
    c_V1.append((-1, 0))
    c_V2.append((-1, 0))
    V1_cnt_max = 0
    V2_cnt_max = 0
    if c_V1[0][0] == c_V2[0][0]:
        if c_V1[0][1] >= c_V2[0][1]:
            V1_cnt_max = c_V1[0][1]
            V2_cnt_max = c_V2[1][1]
        else:
            V1_cnt_max = c_V1[1][1]
            V2_cnt_max = c_V2[0][1]
    else:
        V1_cnt_max = c_V1[0][1]
        V2_cnt_max = c_V2[0][1]
    print(len(V1) - V1_cnt_max + len(V2) - V2_cnt_max)


if __name__ == '__main__':
    N = int(input())
    Vi = [int(i) for i in input().split()]
    solve(N, Vi)

    # # test
    # from random import randint
    # from func import random_str
    # N = 10 ** 5
    # Vi = [randint(1, 5) for _ in range(N)]
    # solve(N, Vi)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

C=Counter(A[::2])
CC=Counter(A[1::2])
A=[[i,j] for i,j in C.items()]+[[None,0]]
AA=[[i,j] for i,j in CC.items()]+[[None,0]]
A=sorted(A, key=lambda x:x[1])
AA=sorted(AA, key=lambda x:x[1])
if A[-1][0]==AA[-1][0]:
    if A[-2][1]> AA[-2][1]:
        print(sum(C.values())-max(C.values()) + sum(CC.values())- AA[-2][1] )
    else:
        print(sum(CC.values())-max(CC.values()) + sum(C.values())- A[-2][1] )
    exit()

print(sum(C.values())-max(C.values())+ sum(CC.values()) - max(CC.values()))

Submission status: Wrong Answer

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

if len(list(set(v))) == 2 and n == 2:
    print(0)

elif len(list(set(v))) == 1 and n == 2:
    print(1)
    

elif len(list(set(v))) >= 2:
    for i in range(n//2):
        if v[0] != v[2*i]:
            cnt += 1
    for i in range(n//2):
        if v[1] != v[2*i+1]:
            cnt += 1
    print(cnt)   

else :
    print(n//2)

Submission status: Wrong Answer

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

if len(list(set(v))) >= 2:
    for i in range(n//2):
        if v[0] != v[2*i]:
            cnt += 1
    for i in range(n//2):
        if v[1] != v[2*i+1]:
            cnt += 1
    print(cnt)   

else :
    print(n//2)

Submission status: Wrong Answer

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

if len(list(set(v))) >= 2:
    for i in range(0, n-2, 2):
        if v[0] != v[i+2]:
            cnt += 1
    for i in range(1, n-2, 2):
        if v[1] != v[i+2]:
            cnt += 1
    print(cnt)   

else :
    print(n//2)

Submission status: Wrong Answer

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

if len(list(set(v))) >= 2:
    for i in range(n-2):
        if v[i] != v[i+2]:
            cnt += 1
    print(cnt)   

else :
    print(n//2)

Submission status: Wrong Answer

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

if len(list(set(v))) == 2:
    for i in range(n-2):
        if v[i] != v[i+2]:
            cnt += 1
    print(cnt)   

else :
    print(n//2)