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:
from collections import Counter
N=int(input())
NN=N//2
l=list(map(int,input().split()))
l1=[l[2*i] for i in range(NN)]
l2=[l[2*i+1] for i in range(NN)]
l1c=Counter(l1)
l2c=Counter(l2)
r1=l1c.most_common()
r2=l2c.most_common()
if r1[0][0]==r2[0][0]:
  if r1[0][0]==NN and r2[0][0]==NN:
    ans=NN
  elif r1[0][1]>r2[0][1]:
    ans=N-r1[0][1]-r2[1][1]
  else:
    ans=N-r1[1][1]-r2[0][1]
else:
  ans=N-r1[0][1]-r2[0][1]
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input().strip())
vs = list(map(int, input().strip().split()))
oddv = [v for i, v in enumerate(vs) if i % 2 == 0]
evenv = [v for i, v in enumerate(vs) if i % 2 == 1]

oddc = Counter(oddv)
evenc = Counter(evenv)
if oddc.most_common(1)[0][0] != evenc.most_common(1)[0][0]:
  print(len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(1)[0][1])
else:
  if len(oddc.most_common()) == 1 and len(evenc.most_common()) == 1:
    print(len(oddv))
  elif len(oddc.most_common()) == 1:
    print(len(evenv) - evenc.most_common(2)[1][1])
  else len(evenc.most_common()) == 1:
    print(len(oddv) - oddc.most_common(2)[1][1])
  else:
    print(min(len(oddv) - oddc.most_common(2)[1][1] + len(evenv) - evenc.most_common(1)[0][1], len(oddv) - oddc.most_common(1)[0][1] + len(evenv) - evenc.most_common(2)[0][1]))

Submission status: Runtime Error

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

nums1 = nums[0::2]
nums2 = nums[1::2]

bug1 = [0] * 100000
bug2 = [0] * 100000

for num in nums1:
    bug1[num] += 1

for num in nums2:
    bug2[num] += 1

max_v_1 = max(bug1)
max_i_1 = bug1.index(max_v_1)
max_v_2 = max(bug2)
max_i_2 = bug2.index(max_v_2)

if max_i_1 == max_i_2:
    bug1[max_i_1] = 0
    bug2[max_i_2] = 0
    sec_max_v_1 = max(bug1)
    sec_max_v_2 = max(bug2)
    print(n - min(max_v_1, max_v_2) - max(sec_max_v_1, sec_max_v_2))
else:
    print(n - max_v_1 - max_v_2)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
vv = list(map(int, input().split()))
d1 = {}
d2 = {}

for i in range(n):
    v = vv[i]
    if i%2==0:
        if v not in d2:
            d2[v] = 0
        d2[v] += 1
    else:
        if v not in d1:
            d1[v] = 0
        d1[v] += 1

dl1 = sorted(list(d1.keys()), reverse=True, key=lambda k:d1[k])
dl2 = sorted(list(d2.keys()), reverse=True, key=lambda k:d2[k])
i1 = 0
i2 = 0

if len(dl1)==1 and len(dl2)==1:
    if dl1[0]==dl2[0]:
        print(n//2)
    else:
        print(0)
    exit()
elif len(dl1)==1:
    print(sum(sorted(d2.values(), reverse=True)[1:]))
    exit()
elif len(dl2)==1:
    print(sum(sorted(d1.values(), reverse=True)[1:]))
    exit()


if dl1[0]!=dl2[0]:
    res = 0
    res += sum(sorted(d1.values(), reverse=True)[1:])
    res += sum(sorted(d2.values(), reverse=True)[1:])
    print(res)
else:
    if d1[dl1[0]]<d2[dl2[0]]:
        res = 0
        l = sorted(d1.values(), reverse=True)
        res += sum(l[0]+l[2:])
        res += sum(sorted(d2.values(), reverse=True)[1:])
        print(res)
    else:
        res = 0
        l = sorted(d2.values(), reverse=True)
        res += sum(l[0]+l[2:])
        res += sum(sorted(d1.values(), reverse=True)[1:])
        print(res)

Submission status: Runtime Error

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

e = v[0::2]
o = v[1::2]

# 数値と個数
elst = sorted([{"num": n, "cnt": v.count(n)}
               for n in set(e)], key=lambda elem: elem["cnt"], reverse=True)
olst = sorted([{"num": n, "cnt": v.count(n)}
               for n in set(o)], key=lambda elem: elem["cnt"], reverse=True)

if len(elst[0]["num"]) == 1 and len(olst[0]["num"]) == 1:
    if elst[0]["num"] == olst[0]["num"]:
        print(olst[0]["cnt"])
    else:
        print(0)

elif elst[0]["num"] != olst[0]["num"]:
    ew = 0
    ow = 0
    if len(elst) != 1:
        ew = sum([elem["cnt"] for elem in elst[1:]])
    if len(olst) != 1:
        ow = sum([elem["cnt"] for elem in olst[1:]])

    print(ew+ow)

Submission status: Runtime Error

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

def count(in_list): # listを集計し、要素数が最小のものの個数
    l = list(set(in_list)) # 重複を除く
    result = [in_list.count(x) for x in l]
    return min(list(result))

def method(in_list):
    l = list(set(in_list)) # 重複を除く
    result = [(in_list.count(x), x) for x in l]
    result.sort()
    return result[:2]




def anser(n, p):
    # 例外① 全部同じ数
    sp = set(p)
    if len(sp) == 1:
        return int(n/2)
    o = [t[1] for t in enumerate(p) if t[0] % 2 == 0]
    e = [t[1] for t in enumerate(p) if t[0] % 2 == 1]
    # 例外② すでにVMVMになっているもの ①以外なのでo!=e

    sp = set(o)
    se = set(e)
    if len(so)) == 1 and len(se) == 1:
        return 0
    # case ① 片一方は0
    if len(so) == 1:
        return count(e)
    if len(se) == 1:
        return count(o)
    ee = method(e) # e = (個数、値)、(個数、値)
    oo = method(o) # o = (個数、値)、(個数、値)
    if ee[0][1] != oo[0][1]:
        return ee[0][0] + oo[0][0]
    else:
        return min(ee[0][0]+oo[1][0], ee[0][1]+oo[0][0])

print(anser(n, p))

Submission status: Runtime Error

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

def count(in_list): # listを集計し、要素数が最小のものの個数
    l = list(set(in_list)) # 重複を除く
    result = [in_list.count(x) for x in l]
    return min(list(result))

def anser(n, p):
    # 例外① 全部同じ数
    if len(set(p)) == 1:
        return int(n/2)
    o = [t[1] for t in enumerate(p) if t[0] % 2 == 0]
    e = [t[1] for t in enumerate(p) if t[0] % 2 == 1]
    # 例外② すでにVMVMになっているもの ①以外なのでo!=e
    if len(set(o)) == 1 and len(set(e)) == 1:
        return 0
    # case ① 片一方は0
    if len(set(o)) == 1:
        return count(e)
    if len(set(e)) == 1:
        return count(o)
    print(count(o)+count(2))


print(anser(n, p))

Submission status: Runtime Error

Solution code:
n = int(input())

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


if len(set(p)) == 1:
    print(int(n/2))
    return

o = []
e = []

for i in range(n):
    if i % 2 == 0:
        o.append(p[i])
    else:
        e.append(p[i])

# o = map(lambda v: v[1], list(filter(lambda x: x % 2 == 0, enumerate(list))))
# e = map(lambda v: v[1], list(filter(lambda x: x % 2 == 1, enumerate(list))))

def count(in_list):
    l = list(set(in_list)) # 重複を除く
    if len(l) == 1:
        return 0
    result = map(lambda x: in_list.count(x), l)
    return min(list(result))

print(count(o)+count(e))

Submission status: Runtime Error

Solution code:
mport collections as collect
N = int(input())
lists = list(map(int, input().split()))
if len(list(set(lists))) == 1:
    print(int(len(lists) / 2))
else:
    NewList = collect.Counter(lists)
    Values = NewList.values()
    List = list(Values)
    List = sorted(List)
    if List[-1] > sum(List[:-1]):
        print(int(N / 2 - List[-2]))
    else:
        sums = sum(List[:-2])
        print(sums)

Submission status: Runtime Error

Solution code:
from collections import Counter

def solve(size=int(input()), ary=list(map(int, input().split()))):
    if len(set(ary)) < 2: return len(ary) // 2

    even, odd = Counter(ary[::2]), Counter(ary[1::2])
    (e, em), (_, es) = even.most_common(2)
    (o, om), (_, os) = odd.most_common(2)
    return size - max(em + os, es + om) if e == o else size - em - om

print(solve())

Submission status: Runtime Error

Solution code:
from collections import Counter
def solve(size=int(input()), ary=list(map(int, input().split()))):
    even, odd = Counter(ary[::2]), Counter(ary[1::2])
    (e, em), (_, es) = even.most_common(2)
    (o, om), (_, os) = odd.most_common(2)
    return size - max(em + os, es + om) if e == o else size - em - om
print(solve())

Submission status: Runtime Error

Solution code:
from collections import Counter

given1 = int(input())
given2 = [int(_) for _ in input().split()]

def solve(size=given1, ary=given2):
    even, odd = Counter(ary[::2]), Counter(ary[1::2])

    emst, esec = even.most_common(2)
    eme, emf = emst
    ese, esf = esec

    omst, osec = odd.most_common(2)
    ome, omf = omst
    ose, osf = osec

    return size - max(emf + osf, omf + esf) if eme == ome else size - esf - osf


print(solve())

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
v0=[]
v1=[]
m=int(n/2)
for i in range(m):
    v0.append(v[i*2])
    v1.append(v[i*2+1])
v0.sort()
v1.sort()
mv0=[0,0]
mv1=[0,0]
jmv0=[0,0]
jmv1=[0,0]
c0=[0,0]
c1=[0,0]
for i in range(m):
    if c0[0]==v0[i]:
        c0[1]+=1
    else:
        if mv0[1]<=c0[1]:
            jmv0=mv0
            mv0=c0
        elif jmv0<=c0[1]:
            jmv0=c0
        c0=[v0[i],1]

    if c1[0]==v1[i]:
        c1[1]+=1
    else:
        if mv1[1]<=c1[1]:
            jmv1=mv1
            mv1=c1
        elif jmv1<=c1[1]:
            jmv1=c1
        c1=[v1[i],1]

if mv0[1]<=c0[1]:
            jmv0=mv0
            mv0=c0
elif jmv0<=c0[1]:
            jmv0=c0

if mv1[1]<=c1[1]:
            jmv1=mv1
            mv1=c1
elif jmv1<=c1[1]:
            jmv1=c1

if mv0[0]!=mv1[0]:
    print(n-mv0[1]-mv1[1])
else:
    print(min(n-mv0[1]-jmv1[1],n-jmv0[1]-mv1[1]))

Submission status: Runtime Error

Solution code:
n = int(input())
S = 0
for i in range(n):
  a = list(input())
  if a[i] == a[i+2]:
    S += 1
  elif a[i+1] == a[i+3]:
    S += 1
  else:
    continue
    
print(S)

Submission status: Runtime Error

Solution code:
n = int(input())
S = 0
for i in range(n):
  a = list(input())
  if a[i] == a[i+2]:
    S++
  elif a[i+1] == a[i+3]:
    S++
  else:
    continue
    
print(S)

Submission status: Runtime Error

Solution code:
from collections import Counter

def check(A):
    N = len(A)
    even = Counter()
    odd = Counter()
    for i, a in enumerate(A):
        if i % 2 == 0:
            odd[a] += 1
        else:
            even[a] += 1
    
    even = even.most_common() + [(None, 0)]
    odd = odd.most_common() + [(None, 0)]
    
    if even[0][0] != odd[0][0]:
        return N - even[0][1] - odd[0][1]
    else:
        return min(N - even[0][1] - odd[1][1], N - odd[0][1] - even[1][1])
    
A = map(int, raw_input.split())
ans = check(A)
print A

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
s1 = sorted(c1.items(), key=lambda x: x[1], reverse=True)
s2 = sorted(c2.items(), key=lambda x: x[1], reverse=True)

if len(s1) == 1 and len(s2) == 1:
    if s1[0][0] == s2[0][0]:
        ans = int(n / 2)
    else:
        ans = 0
else:
    if s1[0][0] != s2[0][0]:
        ans = n - s1[0][1] - s2[0][1]
    else:
        if s[0][1] > s2[0][1]:
            ans = n - s[0][1] - s[1][1]
        elif s[0][1] < s2[0][1]:
            ans = n - s[1][1] - s[0][1]
        else:
            ans = min(n - s[0][1] - s[1][1], n - s[1][1] - s[0][1])
print(ans)

Submission status: Runtime Error

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

import numpy as np
from collections import Counter


N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = np.array(map(int, raw_input().split()))

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

rest = 0

for _k in [odd, even]:
    counter = Counter(tmp_list)

    # counter.most_common()[0][0]
    # uni = list(set(_k))
    # cnt = np.zeros((len(uni), ))
    # for _i in uni:
    #     cnt[uni.index(_i)] += 1
    # unique = np.unique(odd, return_counts=True)
    # rest += len(_k) - count[np.argmax(count)]
    rest += len(_k) - counter.most_common()[0][1]
print rest

Submission status: Runtime Error

Solution code:
import numpy as np

N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = np.array(map(int, raw_input().split()))

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

np.unique(odd, return_counts=True)

Submission status: Runtime Error

Solution code:
import numpy as np

N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = map(int, raw_input().split())

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

rest = 0

for _k in [odd, even]:
    uni = list(set(_k))
    cnt = np.zeros((len(uni), ))
    for _i in _k:
        cnt[uni.index(_i_)] += 1

Submission status: Runtime Error

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

import numpy as np

N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = map(int, raw_input().split())

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

rest = 0

for _k in [odd, even]:
    uni = list(set(_k))
    cnt = np.zeros((len(uni), ))
    for _i in _k:
        cnt[uni.index(_i_)] += 1
    # unique = np.unique(odd, return_counts=True)
    # rest += len(_k) - count[np.argmax(count)]
    rest += len(_k) - np.max(cnt)
print rest

Submission status: Runtime Error

Solution code:
import numpy as np

N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = map(int, raw_input().split())

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

def get_count(L):
    for 


rest = 0
unique = np.unique(odd, return_counts=True)
print 'a'

Submission status: Runtime Error

Solution code:
import numpy as np

N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = map(int, raw_input().split())

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

rest = 0
aa = np.unique(odd, return_counts=True)

Submission status: Runtime Error

Solution code:
import numpy as np

N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = map(int, raw_input().split())

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

rest = 0
unique, count = np.unique(odd, return_counts=True)

print 'h'

Submission status: Runtime Error

Solution code:
import numpy as np

N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = map(int, raw_input().split())

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

rest = 0
for _k in [odd, even]:
    unique, count = np.unique(_k, return_counts=True)


print 'h'

Submission status: Runtime Error

Solution code:
import numpy as np

N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = map(int, raw_input().split())

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

rest = 0
for _k in [odd, even]:
    unique, count = np.unique(_k, return_counts=True)
    rest += np.sum(count) - count[np.argmax(count)]

print rest

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

N = input()
# N = int(input())
# t = np.array(list(map(int, input().split())))
t = map(int, raw_input().split())

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

rest = 0
for _k in [odd, even]:
    unique, count = np.unique(_k, return_counts=True)
    rest += np.sum(count) - count[np.argmax(count)]

print rest

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

N = int(input())
t = np.array(list(map(int, input().split())))

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

rest = 0
for _k in [odd, even]:
    unique, count = np.unique(_k, return_counts=True)
    rest += np.sum(count) - count[np.argmax(count)]

print(rest)

Submission status: Runtime Error

Solution code:
n = int(input().split())
a = list(map(int, input().split()))
MAX = 10**5 + 5
for k in range(2):
  cnt.append([0]*MAX)

for k in range(2):
  for i in range(k, n, 2):
     cnt[k][a[i]] += 1

print(n - max(cnt[0]) - max(cnt[1]))

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter


def main():
    n = int(input())
    values = list(map(int, input().split()))
    a = [v for i, v in enumerate(values) if i % 2 == 0]
    b = [v for i, v in enumerate(values) if i % 2 == 1]
    ac = list(Counter(a).items())
    bc = list(Counter(b).items())
    ans = 0
    for i in range(min(len(ac), 2)):
        for j in range(min(len(ac), 2)):
            if ac[i][0] != bc[j][0]:
                ans = max(ans, ac[i][1] + bc[j][1])

    print(n-ans) if ans != 0 else print(len(bc))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import collections
import numpy as np

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

#n = 4
npv = np.array( v, dtype=np.int32)
#npv = np.array( [3,1,3,2], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

#print(list0[0] ,list1[0])
#print(list0[1] ,list1[1])

if list0[0][0] == list1[0][0]:
    if list0[0][1] == list1[0][1]:
        if list0[1][1] > list1[1][1]:
            del list0[0]
        else:
            del list1[0]
    elif list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]
#print(list0[0] ,list1[0])
#print(list0[1] ,list1[1])

if list0.__len__() != 0:
    change0 = n//2 - list0[0][1]
else:
    change0 = n//2
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)

Submission status: Runtime Error

Solution code:
import collections
import numpy as np

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

#n = 4
npv = np.array( v, dtype=np.int32)
#npv = np.array( [3,1,3,2], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

print(list0[0] ,list1[0])
print(list0[1] ,list1[1])

if list0[0][0] == list1[0][0]:
    if list0[0][1] == list1[0][1]:
        if list0[1][1] > list1[1][1]:
            del list0[0]
        else:
            del list1[0]
    elif list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]
#print(list0[0] ,list1[0])
#print(list0[1] ,list1[1])

if list0.__len__() != 0:
    change0 = n//2 - list0[0][1]
else:
    change0 = n//2
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)

Submission status: Runtime Error

Solution code:
import collections
import numpy as np

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

#n = 4
npv = np.array( v, dtype=np.int32)
#npv = np.array( [3,1,3,2], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

if list0[0][0] == list1[0][0]:
    if list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]

change0 = n//2 - list0[0][1]
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)

Submission status: Runtime Error

Solution code:
import collections
import numpy as np

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

n = 8
npv = np.array( v, dtype=np.int32)
#npv = np.array( [1,1,1,1,1,3,2,3], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

if list0[0][0] == list1[0][0]:
    if list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]

change0 = n//2 - list0[0][1]
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)

Submission status: Runtime Error

Solution code:
#! /usr/bin/python
from collections import Counter
N = int(input())
V = list(map(int, input().split()))


def func(l):
    if len(l) == 0:
        return 0
    nanka = Counter(l).most_common()[0][1]
    return len(l) - nanka


if len([*set(V)]) == 1:
    print(N // 2)
else:
    print(func(V[::2]) + func(V[1::2]))

Submission status: Runtime Error

Solution code:
#! /usr/bin/python
from collections import Counter
N = int(input())
V = list(map(int, input().split()))


def func(l):
    nanka = Counter(l).most_common()[0][1]
    return len(l) - nanka


if len([*set(V)]) == 1:
    print(N // 2)
else:
    print(func(V[::2]) + func(V[1::2]))

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1m = max(c1.items(), key=lambda x:x[1])
c2m = max(c2.items(), key=lambda x:x[1])
c1m[0] = 0
c2m[0] = 0
c1c2 = max(c for k,c in c2.items() if c1m[0]!=k)
c2c1 = max(c for k,c in c1.items() if c2m[0]!=k)
print(min(N - c1m[1] - c1c2, N - c2m[1] - c2c1))

Submission status: Runtime Error

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

eve = {}
odd = {}

for i in range(len(vs)):
    if i % 2 == 0:
        if vs[i] in eve:
            eve[vs[i]] += 1
        else:
            eve[vs[i]] = 1
    else:
        if vs[i] in odd:
            odd[vs[i]] += 1
        else:
            odd[vs[i]] = 1

es = sorted(eve.items(), key=lambda x: -x[1])
os = sorted(odd.items(), key=lambda x: -x[1])

if es[0][0] == os[0][0]:
    if es[0][1] > os[0][1]:
        del es[0]
        if len(os) > 1 :
            del os[1]
    elif es[0][1] < os[0][1]:
        del os[0]
        if len(es) > 1 :
            del es[1]
    else:
        if len(es) == 1:
            del es[0]
            del os[1]
        elif len(os) == 1:
            del es[1]
            del os[0]
        else:
            if es[1][1] < os[1][1]:
                del es[0]
                del os[1]
            else:
                del es[0]
                del os[1]



else:
    del os[0]
    del es[0]

trans = 0

for i in range(len(es)):
    trans += es[i][1]
for i in range(len(os)):
    trans += os[i][1]

print(trans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input().strip())
vs = [int(i) for i in input().split(' ')]
vs1 = vs[::2]
vs2 = vs[1::2]
a = Counter(vs1).most_common()
b = Counter(vs2).most_common()

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    candidates = []
    if len(a) != 1:
        candidates.append(n - a[1][1] - b[0][1])
    if len(b) != 1:
        candidates.append(n - a[0][1] - b[1][1])
    if len(candidates) == 0:
        print(min(candidates))
    else:
        print(n//2)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input().strip())
vs = [int(i) for i in input().split(' ')]
vs1 = vs[::2]
vs2 = vs[1::2]
a = Counter(vs1).most_common()
b = Counter(vs2).most_common()

if a[0][0] != b[0][0]:
    print(n - a[0][1] - b[0][1])
else:
    candidates = []
#    candidates.append(len(vs2))
    if len(a) != 1:
        candidates.append(n - a[1][1] - b[0][1])
    if len(b) != 1:
        candidates.append(n - a[0][1] - b[1][1])
    print(min(candidates))

Submission status: Runtime Error

Solution code:
import numpy as np
import scipy
n = int(input())
v = np.array(list(map(int,input().split())))
v1 = v.reshape(n//2,2)[:,0]
v2 = v.reshape(n//2,2)[:,1]
unique1, counts1 = np.unique(v1, return_counts=True)
vv1 = list(np.asarray((unique1, counts1)).T)
vv1.sort(key = lambda x:x[1])
unique2, counts2 = np.unique(v2, return_counts=True)
vv2 = list(np.asarray((unique2, counts2)).T)
vv2.sort(key = lambda x:x[1])

if(vv1[0][0] != vv2[0][0]):
    ma = n - vv1[0][1] - vv2[0][1]
elif((vv1[0][1] + vv2[1][1]) > (vv1[1][1]+ vv2[0][1])):
    ma = n - vv1[0][1] - vv2[1][1]
else:
    ma = n - vv1[1][1] - vv2[0][1]
print(ma)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int, input().split()))
l1 = [li for i, li in enumerate(l) if i % 2 == 0]
l2 = [li for i, li in enumerate(l) if i % 2 == 1]
print(l1, l2)
def cnt(l):
    d = {}
    for li in l:
        if li in d:
            d[li] += 1
        else:
            d[li] = 1
    d = [(li, cnt) for li, cnt in d.items()]
    d = sorted(d, key=lambda di: di[0], reversed=True)
    return d

k1 = cnt(l1)[:2]
k2 = cnt(l2)[:2]

ans = 10000000
if k1[0][0] != k2[0][0]:
    ans = n - k1[0][1] - k2[0][1]
else:
    if len(k1) == 2:
        ans = n - k1[1][1] - k2[0][1]
    if len(k2) == 2:
        ans = min(ans, n - k1[0][1] - k2[0][1])
    if ans == 10000000:
        ans = n - max(k1[0][1], k2[0][1])
print(ans)

Submission status: Runtime Error

Solution code:

def DistanceFromVV(seq, el):
    """Return the numbers of edits required to make seq into a VV sequences
    using el as the first and second element, respectively.
    """

    distA = 0
    distB = 0
    for i in range(0, len(seq), 2):
        if seq[i] != el:
            distA += 1
    for j in range(1, len(seq), 2):
        if seq[j] != el:
            distB += 1
    return (distA, distB)

def CountElements(seq):
    """Count the number of occurrences of each element of seq, returning the 
    result as a dictionary.
    """

    count = {}
    for el in seq:
        if el in count:
            count[el] += 1
        else:
            count[el] = 1
    return count

def MinChanges(seq):
    """Return the minimum number of changes which must be made to the given 
    sequence in order to make it "VV".
    """

    element_count = CountElements(seq)
    elements_descending = sorted(element_count, 
                                 key=lambda key: element_count[key], 
                                 reverse=True)

    if (len(elements_descending) == 1):
        return len(seq) // 2

    best = [len(seq) + 1, len(seq) + 1]
    second_best = [len(seq) + 1, len(seq) + 1]
    best_elements = [-1, -1]
    for el in elements_descending:
        changes = DistanceFromVV(seq, el)
        for i in (0,1):
            if changes[i] <= best[i]:
                second_best[i] = best[i]
                best[i] = changes[i]
                best_elements[i] = el
            elif changes[i] < second_best[i]:
                second_best[i] = changes[i]

        if best_elements[0] != best_elements[1]:
            if best[0] <= len(seq)//4 and best[1] <= len(seq)//4:
                break
        elif (best[0] <= len(seq)//4 and second_best[1] <= len(seq)//4) \
                or (best[1] <= len(seq)//4 and second_best[0] <= len(seq)//4):
            break

    if best_elements[0] != best_elements[1]:
        return sum(best)
    else:
        return min(best[0] + second_best[1], best[1] + second_best[0])

lines = sys.stdin.read().split('\n')
n = int(lines[0])
entries = lines[1].split(' ')
v = []
for e in entries:
    v += [int(e)]

print(MinChanges(v))

Submission status: Runtime Error

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

v_e_cnt = [0 for i in range(10**6)]
v_o_cnt = [0 for i in range(10**6)]
for x in range(n):
	if x % 2 == 0:
		v_e_cnt[v[x]] += 1
	else:
		v_o_cnt[v[x]] += 1

max_e = [(0,0),(0,0)]
max_o = [(0,0),(0,0)]
for i in range(10**5+1):
	if max_e[1][0] < v_e_cnt[i]:
		if max_e[0][0] < v_e_cnt[i]:
			max_e[1] = max_e[0]
			max_e[0] = (v_e_cnt[i], i)
		else:
			max_e[1] = (v_e_cnt[i], i)
	if max_o[1][0] < v_o_cnt[i]:
		if max_o[0][0] > v_o_cnt[i]:
			max_o[1] = max_o[0]
			max_o[0] = (v_o_cnt[i], i)
		else:
			max_o[0] = (v_o_cnt[i], i)

ans = n - e[0][0] - o[0][0]
if e[0][1] == o[0][1]:
	ans = n - max(e[0][0] + o[1][0], e[1][0] + o[0][0])

print(ans)

Submission status: Runtime Error

Solution code:
n=[int(k) for k in raw_input().split(" ")][0]
t=[]
tp=0
ti=0
for i in range(n):
    t+=[[int(k) for k in raw_input().split(" ")]]
    if sum(t[-1])%2:
        ti+=1
    else:
        tp+=1

        
if ti==0:
    #que des pairs
    #bras = 1*6 + 2*4 + 4 * 4
    #j en utilise 2 pour chacun
    print 14
    print "1 1 1 1 1 1 2 2 2 2 4 4 4 4"
    b=["L" if i%2 else "R" for i in range(14)]
    for i in range(n):
        x,y=t[i]
        xa,ya=abs(x),abs(y)
        if xa%2:
            b[0]="R"
            b[1]="U"
        else:
            b[0]="L"
            b[1]="R"
        if (xa/2)%2:
            b[2]="R"
            b[3]="R"
        else:
            b[2]="L"
            b[3]="R"
        if (ya/2)%2:
            b[4]="U"
            b[5]="U"
        else:
            b[4]="L"
            b[5]="R"
        if (xa/4)%2:
            b[6]="R"
            b[7]="R"
        else:
            b[6]="L"
            b[7]="R"
        if (ya/4)%2:
            b[8]="U"
            b[9]="U"
        else:
            b[8]="L"
            b[9]="R"
        if (xa/8)%2:
            b[10]="R"
            b[11]="R"
        else:
            b[10]="L"
            b[11]="R"
        if (ya/8)%2:
            b[12]="U"
            b[13]="U"
        else:
            b[12]="L"
            b[13]="R"
        if xa!=x:
            b=[(k if k!= "L" else "R") if k!="R" else "L" for k in b]
        if ya!=y:
            b=[(k if k!= "U" else "D") if k!="D" else "U" for k in b]
        print "".join(b)
elif tp==0:
    print 13
    print "1 1 1 1 1 2 2 2 2 4 4 4 4"
    #que des impairs
    #bras = 1*5 + 2*4 + 4 * 4
    #j en utilise 2 pour chacun
    b=["L" if i%2 else "R" for i in range(14)]
    for i in range(n):
        x,y=t[i]
        xa,ya=abs(x),abs(y)
        if xa%2:
            b[1]="R"
        else:
            b[1]="U"
        if (xa/2)%2:
            b[2]="R"
            b[3]="R"
        else:
            b[2]="L"
            b[3]="R"
        if (ya/2)%2:
            b[4]="U"
            b[5]="U"
        else:
            b[4]="L"
            b[5]="R"
        if (xa/4)%2:
            b[6]="R"
            b[7]="R"
        else:
            b[6]="L"
            b[7]="R"
        if (ya/4)%2:
            b[8]="U"
            b[9]="U"
        else:
            b[8]="L"
            b[9]="R"
        if (xa/8)%2:
            b[10]="R"
            b[11]="R"
        else:
            b[10]="L"
            b[11]="R"
        if (ya/8)%2:
            b[12]="U"
            b[13]="U"
        else:
            b[12]="L"
            b[13]="R"
        if xa!=x:
            b=[(k if k!= "L" else "R") if k!="R" else "L" for k in b]
        if ya!=y:
            b=[(k if k!= "U" else "D") if k!="D" else "U" for k in b]
        print "".join(b[1:])
else:
    print -1