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: Accepted

Solution code:
# C 
n = int(input())
v_list = list(map(int, input().split()))

l_dict = dict()
r_dict = dict()

for i in range(n):
    v = v_list[i]
    if i % 2 == 0:
        if v in l_dict.keys():
            l_dict[v] += 1
        else:
            l_dict[v] = 1
    else:
        if v in r_dict.keys():
            r_dict[v] += 1
        else:
            r_dict[v] = 1 

l1 = 0
l2 = 0
l1_cnt = 0
l2_cnt = 0

for k in l_dict.keys():
    if l_dict[k] > l1_cnt:
        l2 = l1
        l2_cnt = l1_cnt
        l1 = k
        l1_cnt = l_dict[k]
    elif l_dict[k] > l2_cnt:
        l2 = k
        l2_cnt = l_dict[k]
        
r1 = 0
r2 = 0
r1_cnt = 0
r2_cnt = 0

for k in r_dict.keys():
    if r_dict[k] > r1_cnt:
        r2 = r1
        r2_cnt = r1_cnt
        r1 = k
        r1_cnt = r_dict[k]
    elif r_dict[k] > r2_cnt:
        r2 = k
        r2_cnt = r_dict[k]
        
if l1 != r1:
    res = n - (l1_cnt + r1_cnt)
else:
    res = n - (l1_cnt + max(l2_cnt, r2_cnt))
    
print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, V):
    M = N // 2

    def build(off):
        d = dict()
        for i in range(off, N, 2):
            if V[i] not in d:
                d[V[i]] = 0
            d[V[i]] += 1

        arr = []
        for k, v in d.items():
            arr.append((M - v, k))

        arr.append((M, -1))

        arr.sort()
        return arr

    A = build(0)
    B = build(1)

    best = N
    for c1, v1 in A:
        for c2, v2 in B:
            if v1 != v2:
                best = min(best, c1 + c2)
                break
    return best


def main():
    N = int(inp())
    V = [int(e) for e in inp().split()]
    assert len(V) == N
    print(solve(N, V))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input() )

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


odd = Counter(val for i,val in enumerate(v) if i%2==1)
even =Counter(val for i,val in enumerate(v) if i%2==0)
if odd.most_common(1)[0] != even.most_common(1)[0]:
    print(n-odd.most_common(1)[0][1] - even.most_common(1)[0][1])
else:
    try:
        a = n-odd.most_common(2)[1][1] - even.most_common(1)[0][1]
        b= n-odd.most_common(1)[0][1] - even.most_common(2)[1][1]
        print(min(a,b))
    except IndexError:
        print(n//2)

Submission status: Accepted

Solution code:
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())
from collections import Counter

n = ii()
a = li()
c0 = Counter(a[::2])
c1 = Counter(a[1::2])
x0, y0 = c0.most_common(1)[0]
x1, y1 = c1.most_common(1)[0]
if x0 != x1:
    ans = n - y0 - y1
else:
    y00 = c0.most_common(2)[1][1] if len(c0) > 1 else 0
    y11 = c1.most_common(2)[1][1] if len(c1) > 1 else 0
    ans = min(n - y0 - y11, n - y00 - y1)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
A = [int(x) for x in input().split()]
even = A[0::2]
odd = A[1::2]
EC = defaultdict(int)
EC[0] = 0
OC = defaultdict(int)
OC[0] = 0
for e in even:
  EC[e] += 1
for o in odd:
  OC[o] += 1
E = sorted([[v, k] for k, v in EC.items()], reverse=True)
O = sorted([[v, k] for k, v in OC.items()], reverse=True)
if E[0][1] != O[0][1]:
  print(n - E[0][0] - O[0][0])
elif E[1][0] >= O[1][0]:
  print(n - E[1][0] - O[0][0])
else:
  print(n - E[0][0] - O[1][0])

Submission status: Accepted

Solution code:

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n=int(input())

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

d1={-1:0}
for i in a[::2]:
    if i in d1: d1[i]+=1
    else: d1[i]=1

d2={-2:0}
for i in a[1::2]:
    if i in d2: d2[i]+=1
    else: d2[i]=1

l1=list(d1.items())
l1.sort(key=lambda x:-x[1])
l2=list(d2.items())
l2.sort(key=lambda x:-x[1])

l1=l1[:5]
l2=l2[:5]

keep=0
for i,j in l1:
    for k,l in l2:
        if i==k: continue
        keep=max(keep,j+l)
print(n-keep)

Submission status: Accepted

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

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

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

def main():
    n = I()
    a = LI()
    c1 = collections.defaultdict(int)
    c2 = collections.defaultdict(int)
    c1['.'] = 0
    c2['a'] = 0
    for i in range(n//2):
        c1[a[i*2]] += 1
        c2[a[i*2+1]] += 1
    m = 0
    for k,v in sorted(c1.items(), key=lambda x: [-x[1], x[0]])[:2]:
        for k2,v2 in sorted(c2.items(), key=lambda x: [-x[1], x[0]]):
            if k2 == k:
                continue
            if m < v+v2:
                m = v+v2
                break

    return n - m


print(main())

Submission status: Runtime Error

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

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:
    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:
    if len(c1.most_common()) > 1 and len(c2.most_common()):
      num3, count3 = c1.most_common()[1]
      num4, count4 = c2.most_common()[1]
      a = (n // 2 - count1) + (n // 2 -count4)
      b = (n // 2 - count2) + (n // 2 -count3)
      min_count = min(a,b)
    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: Runtime Error

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:
    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:
    if len(c1.most_common()) > 1 and len(c2.most_common())
      num3, count3 = c1.most_common()[1]
      num4, count4 = c2.most_common()[1]
      a = (n // 2 - count1) + (n // 2 -count4)
      b = (n // 2 - count2) + (n // 2 -count3)
      min_count = min(a,b)
    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: Runtime Error

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:
    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:
    num3, count3 = c1.most_common()[1]
    num4, count4 = c2.most_common()[1]
    a = (n // 2 - count1) + (n // 2 -count4)
    b = (n // 2 - count2) + (n // 2 -count3)
    min_count = min(a,b)
print(min_count)

Submission status: Runtime Error

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

a = v[0::2]
b = v[1::2]

aa = Counter(a)
bb = Counter(b)

aaa = aa.most_common()
bbb = bb.most_common()

ans = 0

if aaa[0][0] != bbb[0][0]:
  ans = n - aaa[0][1] - bbb[0][1]

else:
  if len(aa) == len(bb) == 1:
    ans = min(aaa[0][1], bbb[0][1])
  else:
    aaa.append[('-', 0)]
    bbb.append[('-', 0)]
    ans = n - max(aaa[0][1]+bbb[1][1], aaa[1][1]+bbb[0][1])

print(ans)

Submission status: Runtime Error

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

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.values()) == max(guC.values()):
        kiV, guV = sorted(kiV), sorted(guV)
        out = min(len(ki) - kiV[-1] +  len(gu) - guV[-2], len(ki) - kiV[-2] + len(gu) - guV[-1] )
    # print(kiC,kiV, guC,guV
    else:
        out+=len(ki) - max(kiV)
        out+=len(gu) - max(guV)

print(out)

Submission status: Runtime Error

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.values()) == max(guC.values()):
        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: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0]*10**5+3
c = [0]*10**5+3
for i in range(n):
  if i%2==0:
    b[a[i]]+=1
  else:
    c[a[i]]+=1
bm=max(b)
cm=max(c)
if b.index(max(b))==c.index(max(c)):
  b[b.index(max(b))]=0
  c[c.index(max(c))]=0
  bm2=max(b)
  cm2=max(c)
  print(min(n-bm-cm2,n-cm-bm2))
else:
  print(n-bm-cm)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0]*10**5
c = [0]*10**5
for i in range(n):
  if i%2==0:
    b[a[i]]+=1
  else:
    c[a[i]]+=1
bm=max(b)
cm=max(c)
if b.index(max(b))==c.index(max(c)):
  b[b.index(max(b))]=0
  c[c.index(max(c))]=0
  bm2=max(b)
  cm2=max(c)
  print(min(n-bm-cm2,n-cm-bm2))
else:
  print(n-bm-cm)

Submission status: Runtime Error

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
    elif V0.most_common()[0][1] < V1.most_common()[0][1]:
        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]
    else:
        if len(V0) == 1 and len(V1) == 1:
            a = 0
            b = V0.most_common()[1][1]
        elif len(V0) == 1:
            a = V0.most_common()[0][1]
            b = V1.most_common()[1][1]
        elif len(V1) == 1:
            a = V0.most_common()[1][1]
            b = V1.most_common()[0][1]
        else:
            a = V0.most_common()[0][1]
            b = max(V0.most_common()[1][1],V1.most_common()[1][1])
print(n-a-b)

Submission status: Runtime Error

Solution code:

n = int(raw_input())
h = {}
un = set()
for i,b in enumerate(map(int,raw_input().split())):

	for a in un:
		if a != b:
			h[(a,b)] = (h[(b,a)] if (b,a) in h else 1) + 1
	un.add(b)

print n - max(h.values())

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
if len(set(a)) == n:
    print(n - 2)
elif len(set(a)) == 1:
    print(n//2)
else:
    f = {}
    s = {}
    for i in range(n):
        if i % 2 == 0:
            if a[i] not in f:
                f[a[i]] = 0
            f[a[i]] += 1
        else:
            if a[i] not in s:
                s[a[i]] = 0
            s[a[i]] += 1
    fsum = sum(f.values())
    ssum = sum(s.values())
    f = sorted(f.items(), key=lambda x: x[1], reverse=True)
    s = sorted(s.items(), key=lambda x: x[1], reverse=True)
    if f[0][0] == s[0][0]:
        tmp1 = fsum - f[0][1] + ssum - s[0][2]
        tmp2 = fsum - f[0][2] + ssum - s[0][1]
        print(min(tmp1, tmp2))
    else:
        print(fsum - f[0][1] + ssum - s[0][1])

Submission status: Runtime Error

Solution code:
x = input().split().pop(0)

w = len(x)

y = []

while True:
    
    a = x[0]
    y.append(x.count(a))
    x.remove(a)
    if len(set(x)) == 1:
        x = [4]
        break
    if len(x) == 0:
        break



y = sorted(y, reverse=True)

if len(y) ==1:
    print(2)
else:
    a = w -  (y[0] + y[1])
    print(a)

Submission status: Runtime Error

Solution code:
#input template
from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda: list(map(int, cin().split()))

def chars(): #function for taking string input as character array since string in python is immutable
    s = cin()
    return(list(s[:len(s) - 1]))

#print list	
def pl(a):	
	for val in a:
		cout(str(val) + ' ')
	cout('\n')
		
#main

def get_key(d, val): 
    for key, value in d.items(): 
         if val == value: 
             return key



n, = mp()
v = mp()

d1 = {}
d2 = {}

for i in range(n):
	if i%2:
		if v[i] in d1:
			d1[v[i]] += 1
		else:
			d1[v[i]] = 1
	else:
		if v[i] in d2:
			d2[v[i]] += 1
		else:
			d2[v[i]] = 1
l1 = sorted(d1.values())
l2 = sorted(d2.values())

if get_key(d1, l1[-1]) == get_key(d2, l2[-1]):
	if l1[-1] + l2[-1] == n:
		cout(str(n//2))
	else:
		if l1[-1] > l2[-1]:
			x = n//2 - l1[-1]
			y = n//2 - l2[-2] 
			cout(str(x+y))
		else:
			x = n//2 - l2[-1]
			x = n//2 - l1[-2]
			cout(str(x+y))
else:
	x = n//2 - l1[-1]
	y = n//2 - l2[-1]
	cout(str(x+y))

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(map(int, input().split())) 
a = 0
b = [0]*(10**5+10)
c = [0]*10**5
d = [0]*10**5
e = [0]*10**5
for i in range(n-1):
  if v[i]==v[i+1]:
    a +=1
if(a == n-1):
  print(int(n/2))
else:
  for i in range(0,n,2):
    b[v[i]] = b[v[i]] + 1
  for j in range(1,n+1,2):
    c[v[j]] =c[v[j]] + 1
  d = sorted(b,reverse=True)
  e = sorted(c,reverse=True)
  f = int(n/2)-d[0]
  g = int(n/2)-e[0]
  print(f+g)

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
odd=[]
even=[]
for i in range(n):
  if (i+1)%2==1:
    odd.append(v[i])
  else:
    even.append(v[i])
    
if set(odd)==set(even):
  print(min(len(odd),len(even)))
else:
  #odd evenのそれぞれで最大回数出てくる要素を抜いて、残った要素の個数が答えになる
  #でも最大回数でてくる要素の抽出方法がわからない。ギブ

Submission status: Runtime Error

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

odd=[[0,0] for _ in range(5+1)]
even=[[0,0] for _ in range(5+1)]
ev=0
od=0


for i,v in enumerate(vv):
    if i%2==0:
        ev+=1
        even[v-1][1]=v-1
        even[v-1][0]+=1
    else:
        od+=1
        odd[v-1][1]=v-1
        odd[v-1][0]+=1


even.sort()
odd.sort()

#print(odd)
#print(even)


if even[-1][1]!=odd[-1][1]:
    print(ev-even[-1][0]+od-odd[-1][0])
else:
    print(min(ev-even[-2][0]+od-odd[-1][0],ev-even[-1][0]+od-odd[-2][0]))

Submission status: Runtime Error

Solution code:
N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)
#print(dictV1, dictV2)

sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
a = 0
if len(dictV1) == 1:
  a = a + 0
else:
  a = a + N/2 - sortdictV1[0][1]
if len(dictV2) == 1:
  a = a + 0
else:
  a = a + N/2 - sortdictV2[0][1]
if sortdictV1[0][0] == sortdictV2[0][0]:
  a = 0
  a = a + min(N/2 - sortdiictV1[0][1] + N/2 - sortdictV2[1][1], N/2 - sortdiictV2[0][1] + N/2 - sortdictV1[1][1])
print(a)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
l = list(map(int,input().split()))

if len(set(l)) == 1:
  print(N//2)
else:
  l_odd,l_even = [],[]

  for i in range(N):
    if i%2 == 0:
      l_odd.append(l[i])
  else:
    l_even.append(l[i])

    C_odd = Counter(l_odd).most_common()
    C_even = Counter(l_even).most_common()

    if C_odd[0][0] != C_even[0][0]:
      ans = N - C_odd[0][1] - C_even[0][1]
    else:
      ans = min(N - C_odd[0][1] - C_even[1][1],N - C_odd[1][1] - C_even[0][1])

    print(ans)

Submission status: Runtime Error

Solution code:
import  collections
n=int(input())
v=list(map(int,input().split()))
o=v[0::2]
s=v[1::2]
vv=collections.Counter(v)
if vv.most_common()[0][1]==n:
    print(n//2)
    exit()

of=collections.Counter(o)
sf=collections.Counter(s)
off=of.most_common()[0][1]
sff=sf.most_common()[0][1]
if off==sff:
    df=of.most_common()[1][1]
    tmp=n-df-sff
    qf=sf.most_common()[1][1]
    ans=min(tmp,n-qf-off)
    print(ans)
else:
    ans=n-off-sff
    print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import numpy as np

def canbe_solved(positions):
    flg = np.dot(positions[0],np.ones(2,int))%2
    for p in positions:
        flg ^= (np.dot(p,np.ones(2,int)) %2 )
        if flg:
            return False
    return True

def solutions(p,vals):
    u = np.dot(p, np.array([1,1]))
    v = np.dot(p, np.array([1,-1]))
    for val in vals:
        if u >=0:
            if v >= 0:
                print('R',end="")
                u -= val
                v -= val
            else:
                print('U',end="")
                u -= val
                v += val
        else:
            if v >= 0:
                print('D',end="")
                u += val
                v -= val
            else:
                print('L',end="")
                u += val
                v += val
    print()
    
    
def main():
    #input
    n = int(input().rstrip())
    positions = [np.asarray(list(map(int,input().rstrip().split()))) for _ in range(n)]
    vals = [1<<i for i in range(30,-1,-1)]
    if np.dot(positions[0], np.ones(2,int)) % 2 == 0:
        vals.append(1)

    if canbe_solved(positions):
        print(len(vals))
        for i,p in enumerate(vals):
            print(p,end="")
            if i == len(vals)-1:
                print('')
        else:
            print(' ', end="")

        for p in positions:
            solutions(p,vals)
    else:
        print('-1')
        
main()

Submission status: Runtime Error

Solution code:
import collections

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

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

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

if v1 == v2 and len(c1.most_common()) == 1
    print(len(v1))
elif c1.most_common()[0][0] != c2.most_common()[0][0]:
    print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[0][1])
else:
    if c1.most_common()[1][1] < c2.most_common()[1][1]:
        print(len(v1) - c1.most_common()[0][1] + len(v2) - c2.most_common()[1][1])
    else:
        print(len(v1) - c1.most_common()[1][1] + len(v2) - c2.most_common()[0][1])

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

result=0

dic_a=defaultdict(int)
dic_b=defaultdict(int)

for i in range(n//2):
    dic_a[v[i*2]]+=1
    dic_b[v[i*2+1]]+=1


#それぞれの最大値を取得
max_a=max(dic_a.items(),key=lambda x:[1])
max_b=max(dic_b.items(),key=lambda x:[1])

if max_a[0] != max_b[0]:
    result=n-max_a[1]-max_b[1]

elif len(dic_a)==1 and len(dic_b)==1:
    result=n//2

elif len(dic_a)==1:
    dic_b.pop(max_b[0])
    max_b=max(dic_b.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

elif len(dic_b)==1:
    dic_a.pop(max_a[0])
    max_a=max(dic_a.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

else:
    dic_a.pop(max_a[0])
    max_a2=max(dic_a.items(),key=lambda x:[1])

    dic_b.pop(max_b[0])
    max_b2=max(dic_b.items(),key=lambda x:[1])

    if max_a2>max_b2:
        result=n-max_a2-max_b
    else:
        result=n-max_a-max_b2

print(result)

Submission status: Runtime Error

Solution code:
n=int(input())
v=[int(x) for x in input().rstrip().split()]
guusuu=[0 for i in range(10**5)]
kisuu=[0 for i in range(10**5)]
len_v=len(list(set(v)))
for i in range(0,n,2):
  guusuu[v[i]]+=1

for i in range(1,n,2):
  kisuu[v[i]]+=1


guusuu.sort(reverse=True)
kisuu.sort(reverse=True)

if len_v==1:
  print(n//2)
else:
  print(kisuu[1]+guusuu[1])

Submission status: Runtime Error

Solution code:
rom collections import Counter

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

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

C = Counter(A)
D = Counter(B)

E = C.most_common()
F = D.most_common()

E += [(-1,0)]
F += [(-1,0)]

if E[0][0] != F[0][0]:
    print(n-E[0][1]-F[0][1])
else:
    print(n-max(E[0][1]+F[1][1],E[1][1]+F[0][1]))

Submission status: Runtime Error

Solution code:

def main():
  from collections import Counter
  N=int(input())
  A=list(ma())
  evens = Counter(A[::2])
  odds = Counter(A[1::2])
  evens[0]=0 #この部分は文字列が小さい時に必要
  odds[0]=0 #
  
  e1, e2=evens.most_common(2) #上位２つを実際の数字をⅠ番目に、出てきた回数を２こめ
  o1, o2=odds.most_common(2) #
  
  if e1[0]!=o1[0]:
    print(N - (e1[1] + o1[1]))
  else: 
    print(N - max(e1[1]+o2[1], e2[1]+o1[1]))
  
if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
from collections import Counter

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

cnt1 = Counter(v[::2]).most_common()
cnt2 = Counter(v[1::2]).most_common()
if cnt1[0][0] != cnt2[0][0]:
    print(n - (cnt1[0][1] + cnt2[0][1]))
else:
    print(n - min(cnt1[1][1] + cnt2[0][1], cnt1[1][1] + cnt2[0][1]))

Submission status: Runtime Error

Solution code:
from collections import Counter as C
n = int(input())
a = list(map(int,input().split()))
c1 = C(a[::2])
c2 = C(a[1::2])
mc1 = c1.most_common(2)
mc2 = c2.most_common(2)
if mc1[0][0] == mc2[0][0]:
  if mc1[1][1] >= mc2[1][1]:
    ans = n - mc1[1][1] - mc2[0][1]
  else:
    ans = n - mc1[0][1] - mc2[][1]
print(ans)

Submission status: Runtime Error

Solution code:

N = [int(i) for i in input().split()][0]
Vn = [int(i) for i in input().split()]

Veven = [0 for _ in range(100000)]
Vodd = [0 for _ in range(100000)]

for n in range(N):
  v = Vn[n]
  if n % 2 == 0:
    Veven[v] += 1
  else:
    Vodd[v] += 1
N_odd = N // 2
N_even = N - N_odd
max_even = max(Veven)
max_odd = max(Vodd)
idx_even = -1
idx_odd = -1
for v in range(100000):
  if max_even == Veven[v]:
    idx_even = v
  if max_odd == Vodd[v]:
    idx_odd = v

if idx_even == idx_odd:
  diff_even = N_even - max_even
  diff_odd = N_odd - max_odd
  if diff_even < diff_odd:
    Vodd[idx_odd] = 0
    max_odd = max(Vodd)
  elif diff_even > diff_odd:
    Veven[idx_even] = 0
    max_even = max(Veven)
  else:
    Vodd[idx_odd] = 0
    max_odd = max(Vodd)
    
    
    
print(N- max_even -max_odd)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())
V = tuple(map(int, input().split()))
X, Y = Counter(), Counter()
for i in range(0, N):
    if i & 1:
        Y[V[i]] += 1
    else:
        X[V[i]] += 1
x = sorted(X.items(), reverse=True, key=lambda x: x[1])[:2]
y = sorted(Y.items(), reverse=True, key=lambda x: x[1])[:2]
if x[0][0] == y[0][0]:
    ans = N
    tmp = 0
    for i in range(0, N):
        if i & 1:
            if V[i] != y[1][0]:
                tmp += 1
        else:
            if V[i] != x[0][0]:
                tmp += 1
    ans = min(ans, tmp)
    tmp = 0
    for i in range(0, N):
        if i & 1:
            if V[i] != y[0][0]:
                tmp += 1
        else:
            if V[i] != x[1][0]:
                tmp += 1
    ans = min(ans, tmp)
else:
    ans = 0
    for i in range(0, N):
        if i & 1:
            if V[i] != y[0][0]:
                ans += 1
        else:
            if V[i] != x[0][0]:
                ans += 1
print(ans)

Submission status: Runtime Error

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

count_even = [0] * (10 ** 5 + 1)
count_odd = [0] * (10 ** 5 + 1)

while i < n:
  count_even[i] += 1
  count_odd[i+1] += 1
  i += 2
  
print(n - max(count_even) - max(count_odd))

Submission status: Runtime Error

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

O = [0] * 10 ** 5
E = [0] * 10 ** 5

for v in range(len(V)):
  if v % 2 == 0:
    E[V[v]] += 1
  else:
    O[V[v]] += 1
    
o_max = max(O)
e_max = max(E)

o = [i for i,x in enumerate(O) if x == o_max and x % 2 == 1]
e = [i for i,x in enumerate(E) if x == e_max and x % 2 == 0]

ans = 0
if len(o) == 1 and len(e) == 1 and e[0] == o[0]:
  a=max(sorted(O)[-2],sorted(E)[-2])
  if a == 0:
    print(int(N/2))
  else:
    print(int(int(N/2 - o_max) + int(N/2 - e_max)))
print(int(int(N/2 - o_max) + int(N/2 - e_max)))

Submission status: Runtime Error

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

v1 = [0] * (10**5)
v2 = [0] * (10**5)

for i in range(0,n,2):
	v1[v[i]] += 1

for i in range(1,n,2):
	v2[v[i]] += 1

ans = n - ( max(v1) + max(v2) )
if ans == 0:
	if v[0] == v[1]:
		print(n//2)
		exit()

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
v = list(int(input()) for _ in range(n))
kisu = sorted(v[0::2])
gusu = sorted(v[1::2])
ans = 0
if len(set(v)) == 1 :
    ans += len(set(v))//2
else:
    for i in range(0, len(kisu)-1) :
        if kisu[i] != kisu[i+1]:
            ans += 1
    for i in range(0, len(gusu)-1) :
        if gusu[i] != gusu[i+1]:
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
v = [s for s in input().split()]
v_0, v_1 = {}, {}
for i, vi in enumerate(v):
    if i % 2 == 0:
        if vi not in v_0.keys():
            v_0[vi] = 0
        v_0[vi] += 1
    else:
        if vi not in v_1.keys():
            v_1[vi] = 0
        v_1[vi] += 1
v_0 = sorted(v_0.items(), key=lambda x:x[1])[::-1]
v_1 = sorted(v_1.items(), key=lambda x:x[1])[::-1]
if v_0[0][0] != v_1[0][0]: print(int(n - v_0[0][1] - v_1[0][1]))
else:
    if v_0[0][1] <= v_1[0][1]: print(int(n - v_0[1][1] - v_1[0][1]))
    else: print(int(n - v_0[0][1] - v_1[1][1]))