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: Runtime Error

Solution code:
N = int(input())
V =  list(map(int,input().split()))
l = V[0::2]
r = V[1::2]
#print(l,r)
from collections import Counter

l = list(Counter(l).most_common(2))
r = list(Counter(r).most_common(2))

if l[0][0] != r[0][0]:
    ans = N -( l[0][1] + r[0][1])
elif l[0][0] == r[0][0]:
    if len(l) == 1 or len(r) == 1:
        ans = N//2
    elif l[1][1] > r[1][1]:
        ans = N-(l[0][1] +  r[1][1])
    elif l[1][1] < r[1][1]:
        ans = N-(l[1][1] +  r[0][1])

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()

if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
v=list(map(int,input().split()))
c1=collections.Counter(v[::2])
c2=collections.Counter(v[1::2])
c1_v1=c1.most_common()[0][0]
c2_v1=c2.most_common()[0][0]
c1_n1=c1.most_common()[0][1]
c2_n1=c2.most_common()[0][1]
c1_n2=c1.most_common(2)[1][1]
c2_n2=c2.most_common(2)[1][1]

if c1_v1!=c2_v1:
    print(n-c1_n1-c2_n1)
else:
    if c1_n1==n//2:
        if c2_n1==n//2:
            print(n//2)
        else:
            print(n-c1_n1-c2_n2)
    else:
        if c2_n1==n//2:
            print(n-c1_n2-c2_n1)
        else:
            print(n-c1_n2-c2_n2)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,M = IL()
data = ILL(M)
p = IL()

B = []
for d in data:
  d = d[1:]
  b = 0
  for i in d:
    b += 1<<(i-1)
  B.append(b)
  
ans = 0
for k in range(1<<N):
  flag = 1
  for i in range(M):
    b = B[i]
    if count_bit(b&k) % 2 == p[i]:
      flag *= 0
  if flag:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
v=list(map(str,input().split()))
#v=list(input())
c=collections.Counter(v)
for i in range(n-1):
    if v[i]==v[i+1]:
        print(n//2)
else:

#print(c)
#print(c.items())
#print(c.most_common()[0])
#print(c.most_common()[1])
#print(v.index(c.most_common()[0][0]))
#print(v.index(c.most_common()[1][0]))  
    if v.index(c.most_common()[0][0]) %2==0 and v.index(c.most_common()[1][0]) %2 !=0:
        print(len(v)-(c.most_common()[0][1] + c.most_common()[1][1]))
        #print("3",len(v),(c.most_common()[0][1]),(c.most_common()[1][1]))
    elif v.index(c.most_common()[0][0]) %2!=0 and v.index(c.most_common()[1][0]) %2 ==0:
        print(len(v)-(c.most_common()[0][1] + c.most_common()[1][1]))

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
v=list(map(str,input().split()))
#v=list(input())
c=collections.Counter(v)
for i in range(n-1):
    if v[i]==v[i+1]:
        print(n//2)
else:

#print(c)
#print(c.items())
#print(c.most_common()[0])
#print(c.most_common()[1])
#print(v.index(c.most_common()[0][0]))
#print(v.index(c.most_common()[1][0]))  
    if v.index(c.most_common()[0][0]) %2==0 and v.index(c.most_common()[1][0]) %2 !=0:
        print('1',len(v)-(c.most_common()[0][1] + c.most_common()[1][1]))
        #print("3",len(v),(c.most_common()[0][1]),(c.most_common()[1][1]))
    elif v.index(c.most_common()[0][0]) %2!=0 and v.index(c.most_common()[1][0]) %2 ==0:
        print("2",len(v)-(c.most_common()[0][1] + c.most_common()[1][1]))

Submission status: Runtime Error

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

    from collections import Counter
    a = Counter(v[::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0][0] != b[0][0]:
        print(n-(a[0][1]+b[0][1]))
    else:
        print(min(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1])))
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
v = [int(x) for x in input().split()]
v1 = Counter( v[::2])
v2 = Counter(v[1::2])
ev = max(v1.values())
od = max(v2.values())
max_v1 = max(v1, key=v1.get)
max_v2 = max(v2, key=v2.get)


if ev > od and len(v2.keys())>1:
    ans = n//2 - sorted(v2.keys(), reverse=True)[1]
elif (ev == od and len(v1.keys()) > 1 and len(v2.keys()) > 1):
    ans = min(n//2 - sorted(v2.keys(), reverse=True)[1], n//2 - sorted(v1.keys(), reverse=True)[1])
elif max_v1 == max_v2:
    ans = min(ev, od)
elif len(v1.keys()) > 1:
    ans=n//2 - sorted(v2.keys(), reverse=True)[1]
else:
    ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
temp1=[]
temp2=[]
for i in range(0,n):
  if i%2==0:
    temp1.append(v[i])
  else:
    temp2.append(v[i])
count=0
from collections import Counter
c1=Counter(temp1)
mode1=c1.most_common()[0][1]
mode1s=c1.most_common()[1][1]
c2=Counter(temp2)
mode2=c2.most_common()[0][1]
mode2s=c2.most_common()[1][1]
if c1.most_common()[0][0]==c2.most_common()[0][0]:
  if mode1s>=mode2s:
    count=len(temp1)-mode1s
  else:
    count=len(temp2)-mode2s
else:
  count=len(temp1)-mode1+len(temp2)-mode2
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
C1 = []
C2 = []
for i in range(n)[::2]:
    C1.append(v[i])
    C2.append(v[i+1])

C1 = Counter(C1).most_common()
C2 = Counter(C2).most_common()

if C1[0][0] != C2[0][0]:
    print(n-C1[0][1]-C2[0][1])
else:
    ans1 = n-C1[0][1]-C2[1][1]
    ans2 = n-C1[1][1]-C2[0][1]
    print(min(ans1, ans2))

Submission status: Runtime Error

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

ki = li[::2]
gu = li[1::2]

ki.sort()
gu.sort()

from itertools import groupby

ki_li = []
gu_li = []

for key, value in groupby(ki):
    ki_li.append((key,len(list(value))))

for key, value in groupby(gu):
    gu_li.append((key,len(list(value))))

ki_li.sort(key=lambda x:(x[1]*(-1)))
gu_li.sort(key=lambda x:(x[1]*(-1)))

if ki_li[0][0] == gu_li[0][0]:
    if ki_li[0][1] > gu_li[0][1]:
        if len(gu_li) >= 2:
            ans = n-ki_li[0][1]-gu_li[1][1]
        else:
            ans = n-ki_li[0][1]
    elif ki_li[0][1] == gu_li[0][1]:
        if ki_li[1][1] >= gu_li[1][1]:
            ans = n-gu_li[0][1]-ki_li[1][1]
        else:
            ans = n-ki_li[0][1]-gu_li[1][1]
    else:
        if len(ki_li) >= 2:
            ans = n-gu_li[0][1]-ki_li[1][1]
        else:
            ans = n-gu_li[0][1]
else:
    ans = n-gu_li[0][1]-ki_li[0][1]

print(ans)

Submission status: Runtime Error

Solution code:
# AtCoder Beginner Contest 111
# C - /\/\/\/
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter

N, *A = map(int, open(0).read().split())

ev = A[0::2]
od = A[1::2]

ev_C = Counter(ev)
od_C = Counter(od)

if ev == od and ev_C.most_common()[0][0]==N//2:
    print(N//2)
else:
    ans = N
    ev_common = ev_C.most_common()
    od_common = od_C.most_common()
    ev_most = ev_common[0][1]
    od_most = od_common[0][1]
    if ev_common[0][0] == od_common[0][0]:
        ev_second = ev_common[1][1]
        od_second = od_common[1][1]
        ans = min(ans, N-ev_most-od_second)
        ans = min(ans, N-ev_second-od_most)
    else:
        ans = min(ans, N-ev_most-od_most) 

    print(ans)

Submission status: Runtime Error

Solution code:
# AtCoder Beginner Contest 111
# C - /\/\/\/
# https://atcoder.jp/contests/abc111/tasks/arc103_a
from collections import Counter

N, *A = map(int, open(0).read().split())

ev = A[0::2]
od = A[1::2]

ev_C = Counter(ev)
od_C = Counter(od)

ev_most = ev_C.most_common()[0][1]
od_most = od_C.most_common()[0][1]
ev_second = ev_C.most_common()[1][1]
od_second = od_C.most_common()[1][1]


if ev == od:
    print(N//2)
else:
    print(min(
        N-ev_most-od_most,
        N-ev_most-od_second,
        N-ev_second-od_most
    ))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

if len(set(v)) == 1:
    print(n//2)
else:
    c1 = Counter(v[0::2])
    c2 = Counter(v[1::2])
    
    c1m = c1.most_common(1)[0]
    c2m = c2.most_common(1)[0]
    
    ans1 = n//2-c2m[1]
    if c1m[0] != c2m[0]:
        ans1 += n//2-c1m[1]
    else:
        ans1 += n//2-c1.most_common(2)[1][1]
    
    ans2 += n//2-c1m[1]
    if c1m[0] != c2m[0]:
        ans2 += n//2-c2m[1]
    else:
        ans2 += n//2-c2.most_common(2)[1][1]
    print(min(ans1, ans2))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

if len(set(v)) == 1:
    print(n//2)
else:
    c1 = Counter(v[0::2])
    c2 = Counter(v[1::2])
    
    c1m = c1.most_common(1)[0]
    c2m = c2.most_common(1)[0]
    
    ans1 = n//2-c2m[1]
    if c1m[0] != c2m[0]:
      ans1 += n//2-c1m[1]
      else:
        ans1 += n//2-c1.most_common(2)[1][1]
    
    ans2 += n//2-c1m[1]
    if c1m[0] != c2m[0]:
      ans2 += n//2-c2m[1]
      else:
        ans2 += n//2-c2.most_common(2)[1][1]
    print(min(ans1, ans2))

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
# def count(aaa):
#     if len(set(aaa))!=1:
#         aaa_max = Counter(aaa).most_common(1)[0][1]
#         aaa_min = len(aaa)-aaa_max
#         most_aaa = Counter(aaa).most_common(1)[0][0]
#     else:
#         aaa_min = 0
#         most_aaa = set(aaa)[0]
#     return int(aaa_min),most_aaa
if len(set(v))==1:
    print(int(n/2))
else:
    if len(set(even))!=1:
        even_max = Counter(even).most_common(1)[0][1]
        even_min = len(even)-even_max
        even_most = Counter(even).most_common(1)[0][0]
    else:
        even_min = 0
        even_most = even[0]
    if len(set(odd))!=1:
        odd_most = Counter(odd).most_common()
        for key in odd_most:
            if key[0]!=even_most:
                odd_max = key[1]
                dd_min = len(odd)-odd_max
                break
    else:
        odd_most = odd[0]
        if odd_most != even_most:
            odd_min = 0
        else:
            odd_min = len(odd)
    print(even_min+odd_min)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
# def count(aaa):
#     if len(set(aaa))!=1:
#         aaa_max = Counter(aaa).most_common(1)[0][1]
#         aaa_min = len(aaa)-aaa_max
#         most_aaa = Counter(aaa).most_common(1)[0][0]
#     else:
#         aaa_min = 0
#         most_aaa = set(aaa)[0]
#     return int(aaa_min),most_aaa
if len(set(v))==1:
    print(int(n/2))
else:
    if len(set(even))!=1:
        even_max = Counter(even).most_common(1)[0][1]
        even_min = len(even)-even_max
        even_most = Counter(even).most_common(1)[0][0]
    else:
        aaa_min = 0
        even_most = even[0]
    if len(set(odd))!=1:
        odd_most = Counter(odd).most_common()
        for key in odd_most:
            if key[0]!=even_most:
                odd_max = key[1]
                odd_min = len(odd)-odd_max
                break
    else:
        odd_most = odd[0]
        if odd_most != even_most:
            odd_min = 0
        else:
            odd_min = len(odd)
    print(even_min+odd_min)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
# def count(aaa):
#     if len(set(aaa))!=1:
#         aaa_max = Counter(aaa).most_common(1)[0][1]
#         aaa_min = len(aaa)-aaa_max
#         most_aaa = Counter(aaa).most_common(1)[0][0]
#     else:
#         aaa_min = 0
#         most_aaa = set(aaa)[0]
#     return int(aaa_min),most_aaa
if len(set(v))==1:
    print(int(n/2))
else:
    if len(set(even))!=1:
        even_max = Counter(even).most_common(1)[0][1]
        even_min = len(even)-even_max
        even_most = Counter(even).most_common(1)[0][0]
    else:
        aaa_min = 0
        even_most = set(even)[0]
    if len(set(odd))!=1:
        odd_most = Counter(odd).most_common()
        for key in odd_most:
            if key[0]!=even_most:
                odd_max = key[1]
                odd_min = len(odd)-odd_max
                break
    else:
        odd_min = 0
        odd_most = set(odd)[0]
    print(even_min+odd_min)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
V = getList()

# 条件を満たすもののうちで最も多く現れる多い２数を採用する方針
even = [0] * (200 + 1)
odd = [0] * (200 + 1)
for i in range(N):
    if i % 2 == 0:
        even[V[i]] += 1
    else:
        odd[V[i]] += 1
# 偶数列、奇数列に現れる数字の中で一番多かったもの
topeven = even.index(max(even))
topodd = odd.index(max(odd))
even.sort()
odd.sort()

ans = 0
if topeven == topodd:
    # 偶数列で一番多かった数、奇数列で２番目に多かった数
    opt1 = N - even[-1] - odd[-2]
    # 偶数列で２番目に多かった数、奇数列で一番多かった数
    opt2 = N - even[-2] - odd[-1]
    # どちらか小さい方
    ans = min(opt1, opt2)
else:
    ans = N - even[-1] - odd[-1]
print(ans)

Submission status: Runtime Error

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

odd_li = []
even_li = []
for i in range(n):
    if i%2==0:
        odd_li.append(v_input[i])
    else:
        even_li.append(v_input[i])
odd_count = sorted(Counter(odd_li).items(),key=lambda x:x[1])
even_count = sorted(Counter(even_li).items(),key=lambda x:x[1])

odd_max = odd_count[0][0]
even_max = even_count[0][0]

if odd_max==even_max and len(odd_count)==1:
    ans = odd_count[0][1]

elif odd_max==even_max:
    odd_next = odd_count[1][1]
    even_next = even_count[1][1]
    ans = n//2-odd_count[0][1] + n//2 - max(odd_next)
else:
    ans = n//2-odd_count[0][1] + n//2 - even_count[0][1]

print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


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


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


def main():
    n = readint()
    v = list(readnums())
    ve = [x for i, x in enumerate(v) if not i % 2]
    vo = [x for i, x in enumerate(v) if i % 2]
    cve = Counter(ve)
    cvo = Counter(vo)
    if cve.most_common()[0][0] == cvo.most_common()[0][0]:
        print(min(len(ve) - cve.most_common()[1][1] + len(vo) - cvo.most_common()[0][1], len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[1][1]))
    else:
        print(len(ve) - cve.most_common()[0][1] + len(vo) - cvo.most_common()[0][1])


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter


def main():
    n = int(input())
    v = list(map(int, input().split()))
    a = [v[i] for i in range(n) if i % 2 == 0]
    b = [v[i] for i in range(n) if i % 2 == 1]
    half_n = n // 2
    a_count = Counter.most_common(Counter(a))
    b_count = Counter.most_common(Counter(b))
    ans = 0
    if a_count[0][1] > b_count[0][1]:
        ans += half_n - a_count[0][1]
        if a_count[0][0] == b_count[0][0]:
            ans += half_n - b_count[1][1]
        else:
            ans += half_n - b_count[0][1]
    elif a_count[0][1] < b_count[0][1]:
        ans += half_n - b_count[0][1]
        if a_count[0][0] == b_count[0][0]:
            ans += half_n - a_count[1][1]
        else:
            ans += half_n - a_count[0][1]
    else:
        if a_count[0][0] == b_count[0][0]:
            ans += half_n - a_count[0][1]
            ans += half_n - b_count[1][1]
        else:
            ans += half_n - a_count[0][1]
            ans += half_n - b_count[0][1]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

t = collections.Counter(odd).most_common()
t2 = collections.Counter(even).most_common()

t = list(t.items())
t.sort(reverse=True)

t2 = list(t2.items())
t2.sort(reverse=True)


t.append([0, 0])
t2.append([0, 0])
ans = t[0][1] + t2[0][1]
if t[0][0] == t2[0][0]:
    ans = max(t[0][1] + t2[1][1], t[1][1]+t2[0][1])
print(n - ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*10009
c=[0]*10009
for i in range(n//2):
  b[a[i*2]]+=1
  c[a[i*2+1]]+=1
t=max(b)
r=max(c)
s=b.index(t)
p=c.index(r)
if s==p:
  b[s]=0
  k=max(b)
  c[p]=0
  j=max(c)
  f=max(k+r,t+j)
else:
  f=t+r
print(n-f)

Submission status: Runtime Error

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)
print('-----------')
print(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]:
    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()
 (2054, 12394), (27775, 12395)
(50652, 12393), (27775, 12395)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
num_list = list(map(int,input().split()))

even_cnt = [0]*10**5
odd_cnt = [0]*10**5
for i in range(n):
    if i % 2 == 0:
        even_cnt[num_list[i]] += 1
    else:
        odd_cnt[num_list[i]] += 1
ame = np.argmax(even_cnt)
amo = np.argmax(odd_cnt)
if ame != amo:
    print(1)
    
    
else:
    tmp_e_max =  max(even_cnt)
    tmp_o_max = max(odd_cnt)
    even_cnt[ame] = 0
    odd_cnt[amo] = 0
    if tmp_e_max-max(even_cnt) >=  tmp_o_max - max(odd_cnt):
        print(len(num_list) - max(odd_cnt) -  tmp_e_max)
    else:
        print(len(num_list) - max(even_cnt) -  tmp_o_max)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
num_list = list(map(int,input().split()))

even_cnt = [0]*10**5
odd_cnt = [0]*10**5
for i in range(n):
    if i % 2 == 0:
        even_cnt[num_list[i]] += 1
    else:
        odd_cnt[num_list[i]] += 1
ame = np.argmax(even_cnt)
amo = np.argmax(odd_cnt)
if ame != amo:
    print(len(num_list) - max(even_cnt) -  max(odd_cnt))
    
else:
    print(1)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
num_list = list(map(int,input().split()))

even_cnt = [0]*10**5
odd_cnt = [0]*10**5
for i in range(n):
    if i % 2 == 0:
        even_cnt[num_list[i]] += 1
    else:
        odd_cnt[num_list[i]] += 1
ame = np.argmax(even_cnt)
amo = np.argmax(odd_cnt)
if ame != amo:
    print(len(num_list) - max(even_cnt) -  max(odd_cnt))
    
else:
    tmp_e_max =  max(even_cnt)
    tmp_o_max = max(odd_cnt)
    even_cnt[ame] = 0
    odd_cnt[amo] = 0
    if tmp_e_max-max(even_cnt) >=  tmp_o_max - max(odd_cnt):
        print(len(num_list) - max(odd_cnt) -  tmp_e_max)
    else:
        print(len(num_list) - max(even_cnt) -  tmp_o_max)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
num_list = list(map(int,input().split()))

even_cnt = [0]*10**5
odd_cnt = [0]*10**5
for i in range(n):
    if i % 2 == 0:
        even_cnt[num_list[i]] += 1
    else:
        odd_cnt[num_list[i]] += 1
ame = np.argmax(even_cnt)
amo = np.argmax(odd_cnt)
if ame != amo:
    print(len(num_list) - max(even_cnt) -  max(odd_cnt))
    
else:
    tmp_e_max =  max(even_cnt)
    tmp_o_max = max(odd_cnt)
    even_cnt[ame] = 0
    even_cnt[amo] = 0
    if tmp_e_max-max(even_cnt) >=  tmp_o_max - max(odd_cnt):
        print(len(num_list) - max(odd_cnt) -  tmp_e_max)
    else:
        print(len(num_list) - max(even_cnt) -  tmp_o_max)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
num_list = list(map(int,input().split()))

even_cnt = [0]*10**5
odd_cnt = [0]*10**5
for i in range(n):
    if i % 2 == 0:
        even_cnt[num_list[i]] += 1
    else:
        odd_cnt[num_list[i]] += 1
ame = np.argmax(even_cnt)
amo = np.argmax(odd_cnt)
if ame != amo:
    print(len(num_list) - max(even_cnt) -  max(odd_cnt))
    
else:
    tmp_e_max =  max(even_cnt)
    tmp_o_max = max(odd_cnt)
    even_cnt[ame] = 0
    even_cnt[amo] = 0
    if max(even_cnt) >=  max(even_cnt):
        print(len(num_list) - max(even_cnt) -  tmp_o_max)
    else:
        print(len(num_list) - max(odd_cnt) -  tmp_e_max)

Submission status: Runtime Error

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:
    flag=True
    ans1.sort()
    ans2.sort()
    m12=ans1[-2]
    m22=ans2[-2]
    break
print(m1,m12,m2,m22)
if len(set(v))==1:
  print(n//2)
elif flag==True:
  print(n-max(m12+m2,m1+m22))
else:
  print(n-m1-m2)

Submission status: Runtime Error

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+2):
  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: Runtime Error

Solution code:
import numpy as np

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
leftnp = np.array(left)
rightnp = np.array(right)
leftnpind = np.argsort(leftnp, axis=0)[::-1]
rightnpind = np.argsort(rightnp, axis=0)[::-1]
if leftnpind[0] != rightnpind[0]:
    lmax = leftnp[leftnpind[0]]
    rmax = rightnp[rightnpind[0]]
else:
    if leftnp[leftnpind[1]] > rightnp[rightnpind[1]]:
        lmax = leftnp[leftnpind[1]]
        rmax = rightnp[rightnpind[0]]
    else:
        lmax = leftnp[leftnpind[0]]
        rmax = rightnp[rightnpind[1]]
print(n - lmax - rmax)

Submission status: Runtime Error

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: Runtime Error

Solution code:
N, K = map(int, input().split())
# print('N:{}, K:{}'.format(N, K))

if K % 2 == 0:
    print(((N-K//2)//K+1)**3+(N//K)**3)
else:
    print((N//K)**3)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
print('N:{}, K:{}'.format(N, K))

if K % 2 == 0:
    print(((N-K//2)//K+1)**3+(N//K)**3)
else:
    print((N//K)**3)

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
dic1={}
dic2={}
for i in range(0,n):
  if i%2==0:
    at=v[i]
    if at in dic1:
      dic1[at]+=1
    else:
      dic1[at]=1
  else:
    at=v[i]
    if at in dic2:
      dic2[at]+=1
    else:
      dic2[at]=1 

count1=0
count2=0
kep1=0
kep2=0
for i in range(len(dic1)):
  at=dic1.popitem()
  moji=at[0]
  count=at[1]
  if count>count2:
    kep2=moji
    count2=count
  if count2>count1:
    moji_tamotu=kep1
    count_tamotu=count1
    kep1=kep2
    kep2=moji_tamotu
    count1=count2
    count2=count_tamotu

odd_1_moji=kep1
odd_1_count=count1
odd_2_moji=kep2
odd_2_count=count2
    
count1=0
count2=0
kep1=0
kep2=0
for i in range(len(dic2)):
  at=dic2.popitem()
  moji=at[0]
  count=at[1]
  if count>count2:
    kep2=moji
    count2=count
  if count2>count1:
    moji_tamotu=kep1
    count_tamotu=count1
    kep1=kep2
    kep2=moji_tamotu
    count1=count2
    count2=count_tamotu

even_1_moji=kep1
even_1_count=count1
even_2_moji=kep2
even_2_count=count2

if even_1_moji!=odd_1_moji:
  kouho=[odd_1_moji,even_1_moji]*(n//2)
else:
  if even_1_count+odd_2_count>=even_2_count+odd_1_count:
    kouho=[odd_2_moji,even_1_moji]*2
  else:
    kouho=[odd_1_moji,even_2_moji]*2
    
res=0
for i in range(0,n):
  if v[i]!=kouho[i]:
    res+=1
print(res)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

v1=[]
v2=[]

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

v1c = Counter(v1).most_common()
v2c = Counter(v2).most_common()
ans2=float("inf")
ans3=float("inf")


if v1c[0][0]!=v2c[0][0]:
  ans=len(v1)-v1c[0][1]+len(v2)-v2c[0][1]
  print(ans)

else:
  if len(v1c) !=1:
  	ans2=len(v1)-v1c[1][1]+len(v2)-v2c[0][1]
  elif len(v2c) !=1:
    ans3=len(v1)-v1c[0][1]+len(v2)-v2c[1][1]
  else:
    ans4=min(len(v1),len(v2))
  print(min(ans2,ans3,ans4))

Submission status: Runtime Error

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

a = [v[2*i] for i in range(int(n/2))]
b = [v[2*i+1] for i in range(int(n/2))]

from collections import Counter

x = Counter(a)
y = Counter(b)
x = list(x.items())
y = list(y.items())
x.sort(reverse=1,key=lambda p: p[1])
y.sort(reverse=1,key=lambda p: p[1])

if x[0][0] != y[0][0]:
    print(n-x[0][1]-y[0][1])
else:
    if x[0][0] == y[0][0]:
        if min(len(x),len(y))>=2:
            print(n-max(x[0][1]+y[1][1],y[0][1]+x[1][1]))
        elif len(x)==2:
            print(n-x[1][1]-y[0][1])
        else:
            print(n-y[1][1]-x[0][1])