Problem:


Score : 300 points

Problem Statement

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

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

Exactly two different numbers appear in the sequence.

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

Constraints

2 \leq n \leq 10^5

n is even.

1 \leq v_i \leq 10^5

v_i is an integer.

Input

Input is given from Standard Input in the following format:

n
v_1 v_2 ... v_n

Output

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

Sample Input 1

4
3 1 3 2

Sample Output 1

1

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

Sample Input 2

6
105 119 105 119 105 119

Sample Output 2

0

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

Sample Input 3

4
1 1 1 1

Sample Output 3

2

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



Sample input:
4
3 1 3 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
v = il()

a = dict()
b = dict()
for cnt, i in enumerate(v):
    if cnt%2 == 0:
        if i in a:
            a[i] += 1;
        else:
            a[i] = 1;
    else:
        if i in b:
            b[i] += 1;
        else:
            b[i] = 1;
a = sorted(a.items(), key=lambda x: x[1])
b = sorted(b.items(), key=lambda x: x[1])
if a[0][0] == b[0][0]:
    A = n//2 if len(a) == 1 else a[1][1]
    B = n//2 if len(b) == 1 else b[1][1]
    print(n-max(A, B))
else:
    print(n-a[0][1]-b[0][1])

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
list = list(map(int,input().strip().split()))
list_c = collections.Counter(list)
odd_list = []
even_list = []

if N == list_c.most_common()[0][1]:
    ans = N//2

else:
    for i in range(N//2):
        odd_list.append(list[2*i-2])
        even_list.append(list[2*i-1])

    odd_list_c = collections.Counter(odd_list)
    even_list_c = collections.Counter(even_list)

    cnt_odd = odd_list_c.most_common()[0][1]
    cnt_even = even_list_c.most_common()[0][1]
    cnt = cnt_odd + cnt_even
    ans = N - cnt

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
list = list(map(int,input().strip().split()))
list_c = collections.Counter(list)
cnt = len(list)

def count(a):
    global cnt
    cnt -= list_c.most_common()[a][1]
    return cnt

if count(0) == 0:
    ans = len(list)//2
elif count(1) == 0:
    ans = (list_c.most_common()[0][1]\
          - list_c.most_common()[1][1])//2
else:
    ans = len(list)\
    - list_c.most_common()[0][1]\
    - list_c.most_common()[1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
list = list(map(int,input().strip().split()))
list_c = collections.Counter(list)
cnt = len(list)

def count(a):
    global cnt
    cnt -= list_c.most_common()[a][1]
    return cnt

if count(0) == 0:
    ans = len(list)//2
elif count(1) == 0:
    ans = 0
else:
    ans = len(list)\
    - list_c.most_common()[0][1]\
    - list_c.most_common()[1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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


V_e = V[1::2]
V_o = V[::2]

dic_e = collections.Counter(V_e)
dic_o = collections.Counter(V_o)

e_keys = list(dic_e.keys())
o_keys = list(dic_o.keys())



# dic_o を優先

tar_o = o_keys[0]

if e_keys[0] != tar_o:# and len(list(dic_e.keys())) != 0:
    tar_e = e_keys[0]
    ans_o = (n//2 - dic_o[tar_o]) + (n//2 - dic_e[tar_e])
elif len(e_keys) > 1:
    tar_e = e_keys[1]
    ans_o = (n//2 - dic_o[tar_o]) + (n//2 - dic_e[tar_e])
else:
    ans_o = (n//2 - dic_o[tar_o]) + (n//2)


# dic_e を優先

tar_e = e_keys[0]

if o_keys[0] != tar_e:# and len(list(dic_e.keys())) != 0:
    tar_o = o_keys[0]
    ans_e = (n//2 - dic_o[tar_o]) + (n//2 - dic_e[tar_e])
elif len(o_keys) > 1:
    tar_o = o_keys[1]
    ans_e = (n//2 - dic_o[tar_o]) + (n//2 - dic_e[tar_e])
else:
    ans_e = (n//2 - dic_e[tar_o]) + (n//2)


ans = min(ans_e,ans_o)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
v = input().split()

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = copy.deepcopy(s)
t2 = copy.deepcopy(t)
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk = i
    elif sc == 0:
        sk = i
        break
    sc += 1
if sc == 0:
    sk = 0

for i in t2:
    if tc == -1:
        tk = i
    elif tc == 0:
        tk = i
        break
    tc += 1
if tc == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
v = input().split()

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = copy.deepcopy(s)
t2 = copy.deepcopy(t)
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk = i
    elif i != sk and sc > -1:
        sk = i
        break
    sc += 1
if sc == 0:
    sk = 0

for i in t2:
    if tc == -1:
        tk = i
    elif i != tk and tc > -1:
        tk = i
        break
    tc += 1
if tc == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Wrong Answer

Solution code:
import collections
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_c=collections.Counter(a).most_common()
b_c=collections.Counter(b).most_common()
if a_c[0][0]==b_c[0][0]:
    if a_c[0][1]==b_c[0][1]:
        if a_c[0][1]==n/2:
            print(n//2)
        else:
            print(n-a_c[0][0]-max(a_c[0][1],b_c[0][1]))
    elif a_c[0][1]>b_c[0][1]:
        if len(b_c)>1:
            print(n-a_c[0][1]-b_c[1][1])
        else:
            print(n-a_c[0][1])
    else:
        if len(a_c)>1:
            print(n-a_c[1][1]-b_c[0][1])
        else:
            print(n-b_c[0][1])
else:
    print(n-a_c[0][1]-b_c[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_c=collections.Counter(a).most_common()
b_c=collections.Counter(b).most_common()
if a_c[0][0]==b_c[0][0]:
    if a_c[0][1]==b_c[0][1]:
        if len(a_c)==n/2:
            print(n//2)
        else:
            print(n-a_c[0][0]-max(a_c[0][1],b_c[0][1]))
    elif a_c[0][1]>b_c[0][1]:
        if len(b_c)>1:
            print(n-a_c[0][1]-b_c[1][1])
        else:
            print(n-a_c[0][1])
    else:
        if len(a_c)>1:
            print(n-a_c[1][1]-b_c[0][1])
        else:
            print(n-b_c[0][1])
else:
    print(n-a_c[0][1]-b_c[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_c=collections.Counter(a).most_common()
b_c=collections.Counter(b).most_common()
if a_c[0][0]==b_c[0][0]:
    if a_c[0][1]==b_c[0][1]:
        if len(a_c)==n/2:
            print(n//2)
        else:
            print(n-a_c[0][0]-min(a_c[0][1],b_c[0][1]))
    elif a_c[0][1]>b_c[0][1]:
        if len(b_c)>1:
            print(n-a_c[0][1]-b_c[1][1])
        else:
            print(n-a_c[0][1])
    else:
        if len(a_c)>1:
            print(n-a_c[1][1]-b_c[0][1])
        else:
            print(n-b_c[0][1])
else:
    print(n-a_c[0][1]-b_c[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_c=collections.Counter(a).most_common()
b_c=collections.Counter(b).most_common()
if a_c[0][0]==b_c[0][0]:
    if a_c[0][1]==b_c[0][1]:
        if len(a_c)==n:
            print(n//2)
        else:
            print(n-a_c[0][0]-min(a_c[0][1],b_c[0][1]))
    elif a_c[0][1]>b_c[0][1]:
        if len(b_c)>1:
            print(n-a_c[0][1]-b_c[1][1])
        else:
            print(n-a_c[0][1])
    else:
        if len(a_c)>1:
            print(n-a_c[1][1]-b_c[0][1])
        else:
            print(n-b_c[0][1])
else:
    print(n-a_c[0][1]-b_c[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_c=collections.Counter(a).most_common()
b_c=collections.Counter(b).most_common()
if a_c[0][0]==b_c[0][0]:
    if a_c[0][1]==b_c[0][1]:
        print(n//2)
    elif a_c[0][1]>b_c[0][1]:
        if len(b_c)>1:
            print(n-a_c[0][1]-b_c[1][1])
        else:
            print(n-a_c[0][1])
    else:
        if len(a_c)>1:
            print(n-a_c[1][1]-b_c[0][1])
        else:
            print(n-b_c[0][1])
else:
    print(n-a_c[0][1]-b_c[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_c=collections.Counter(a).most_common()
b_c=collections.Counter(b).most_common()
if a_c[0][0]==b_c[0][0]:
    if a_c[0][1]>=b_c[0][1]:
        if len(b_c)>1:
            print(n-a_c[0][1]-b_c[1][1])
        else:
            print(n-a_c[0][1])
    else:
        if len(a_c)>1:
            print(n-a_c[1][1]-b_c[0][1])
        else:
            print(n-b_c[0][1])
else:
    print(n-a_c[0][1]-b_c[0][1])

Submission status: Wrong Answer

Solution code:
import collections
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_c=collections.Counter(a).most_common()
b_c=collections.Counter(b).most_common()
if a_c[0][0]==b_c[0][0]:
    if a_c[0][1]>=b_c[0][1]:
        if len(b_c)>1:
            print(n-a_c[0][1]-b_c[1][1])
        else:
            print(n-a_c[0][1])
    else:
        if len(b_c)>1:
            print(n-a_c[1][1]-b_c[0][1])
        else:
            print(n-b_c[0][1])
else:
    print(n-a_c[0][1]-b_c[0][1])

Submission status: Wrong Answer

Solution code:
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_set=(list)(set(a))
b_set=(list)(set(b))
mc_a=[]
mc_b=[]
for v in a_set:
    mc_a.append(tuple((v,a.count(v))))
for v in b_set:
    mc_b.append(tuple((v,b.count(v))))

a_l = sorted(mc_a,key=lambda x: x[1])
b_l = sorted(mc_b,key=lambda x:x[1])
if a_l[0][0]==b_l[0][0]:
    if a_l[0][1]>=b_l[0][1]:
        if len(b_l)>1:
            print(n-a_l[0][1]-b_l[1][1])
        else:
            print(n-a_l[0][1])
    else:
        if len(b_l)>1:
            print(n-a_l[1][1]-b_l[0][1])
        else:
            print(n-b_l[0][1])
else:
    print(n-a_l[0][1]-b_l[0][1])

Submission status: Wrong Answer

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

x = []
y = []

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

x.sort()
y.sort()

q = []
r = []
s = []
t = []
countx = 1
county = 1

for j in range(int(n / 2)):
    if x[j - 1] == x[j] and j != 0:
        countx += 1
    if j == n / 2 - 1:
        s.append(countx)
        q.append(x[j])
        countx = 1
    elif x[j - 1] != x[j] and j != 0:
        s.append(countx)
        q.append(x[j - 1])
        countx = 1


for k in range(int(n / 2)):
    if y[k - 1] == y[k] and k != 0:
        county += 1
    if k == n / 2 - 1:
        t.append(county)
        r.append(y[k])
        county = 1
    elif y[k - 1] != y[k] and k != 0:
        t.append(county)
        r.append(y[k - 1])
        county = 1
s2 = s
t2 = t
#a = [int(m) for m in a]
s2.sort(reverse=True)
t2.sort(reverse=True)
sc = -1
tc = -1
sk = 0
tk = 0

for i in s2:
    if sc == -1:
        sk = i
    elif i != sk and sc > -1:
        sk = i
        break
    sc += 1
if sc == 0:
    sk = 0

for i in t2:
    if tc == -1:
        tk = i
    elif i != tk and tc > -1:
        tk = i
        break
    tc += 1
if tc == 0:
    tk = 0

if q[s.index(max(s))] != r[t.index(max(t))]:
    print(n - max(s) - max(t))
else:
    if sk >= tk:
        print(n - sk - max(t))
    else:
        print(n - max(s) - tk)

Submission status: Wrong Answer

Solution code:
n = (int)(input())
l = list(map(int,input().split()))
a = l[::2]
b=l[1::2]

a_set=(list)(set(a))
b_set=(list)(set(b))
mc_a=max(a.count(v) for v in a_set)
mc_b=max(b.count(v) for v in b_set)
print(n-mc_a-mc_b)

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 0
gu = v[::2]
ki = v[1::2]

gudic = collections.Counter(gu)
kidic = collections.Counter(ki)

gumax = gudic.most_common()
kimax = kidic.most_common()



if gumax[0][0] != kimax[0][0]:
    print((n // 2 - gumax[0][1]) + (n // 2 - kimax[0][1]))
else:
    if len(gumax) == 1 and len(kimax) == 1:
        print(n // 2)
    elif len(gumax) == 1 and len(kimax) >= 2:
        print((n // 2 - gumax[0][1]) + (n // 2 - kimax[1][1]))
    
    elif len(gumax) >= 2 and len(kimax) == 1:
        print((n // 2 - gumax[1][1]) + (n // 2 - kimax[0][1]))
    else: 
        one = (n // 2 - gumax[0][1]) + (n // 2 - kimax[1][1])
        ano = (n // 2 - gumax[1][1]) + (n // 2 - kimax[0][1])
        print(max(one, ano))

Submission status: Wrong Answer

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

even = {}
odd = {}

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


et = []
ot = []
for k in even.keys():
    et.append((k, even[k]))

for k in odd.keys():
    ot.append((k, odd[k]))

sorted(et, key=lambda tup: tup[1])
et.reverse()
sorted(ot, key=lambda tup: tup[1])
ot.reverse()

result = -1
hf = int(n / 2)
if len(et) == 1 and len(ot) == 1:
    if et[0][0] == ot[0][0]:
        result = hf

for i in range(len(et)):
    if result != -1:
        break

    for j in range(len(ot)):
        if et[i][0] != ot[j][0]:
            result = hf - et[i][1] + hf - ot[j][1]
            break


print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int, input().split()))
odd = lis[::2]

odd_dic = {'a':(n+1)//2}
for i in odd:
    odd_dic[i] = odd_dic.get(i,(n+1)//2) - 1

even_dic = {'a':n//2}    
even = lis[1::2]
for i in even:
    even_dic[i] = even_dic.get(i,n//2) - 1

odd_count = sorted(list(odd_dic.keys()), key =lambda x: odd_dic[x])
even_count = sorted(list(even_dic.keys()), key =lambda x: even_dic[x])
if odd_count[0] == even_count[0]:
    if odd_dic.get(odd_count[1]) < even_dic.get(even_count[1]):
        ko = odd_count[0]
        ke = even_count[1]
    else:
        ko = odd_count[1]
        ke = even_count[0]
else:
    ko = odd_count[0]
    ke = even_count[0]
print(odd_dic[ko] + even_dic[ke])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [i for i in input().split()]
c = list()
if len(set(v))==2:
  print(0)
elif len(set(v))==1:
  print(int(n/2))
else:
  for i in set(v):
    c.append([v.count(i), i])
  c.sort(reverse=True)
  print(n - c[0][0] - c[1][0])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [i for i in input().split()]
c = list()
for i in set(v):
  c.append([v.count(i), i])
c.sort(reverse=True)
print(n - c[0][0] - c[1][0]) if len(c)>1 else print(int(n/2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
x = list(map(int,input().split()))
even = [j for i,j in enumerate(x) if i%2==0]
odd = [j for i,j in enumerate(x) if i%2==1]
evencnt = Counter(even).most_common()[0][1]
oddcnt = Counter(odd).most_common()[0][1]
if len(set(x)) == 1:
    print(n//2)
else:
    print(n-evencnt-oddcnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
x = list(map(int,input().split()))
even = [j for i,j in enumerate(x) if i%2==0]
odd = [j for i,j in enumerate(x) if i%2==1]
evencnt = Counter(even).most_common()[0][1]
oddcnt = Counter(odd).most_common()[0][1]
if set(x) == 1:
    print(n/2)
else:
    print(n-evencnt-oddcnt)

Submission status: Wrong Answer

Solution code:
import statistics
import sys
n=input()
v=list(map(int,input().split()))
DEBUG=0
cnt=0
v1={}
v2={}
v1n=0
v2n=0
for i in v:
  #(v1 if not cnt%2 else v2).append(i)
  if not cnt%2:
    v1n+=1
    if i in v1:
      v1[i]+=1
    else:
      v1[i]=1
  else:
    v2n+=1
    if i in v2:
      v2[i]+=1
    else:
      v2[i]=1
  cnt+=1

if DEBUG:
  print ("v:   "+str(v))
  print ("v1:  "+str(v1))
  print ("v2:  "+str(v2))
  print("")

v1mk=max(v1, key=v1.get)
v2mk=max(v2, key=v2.get)
v1mn=v1[v1mk]
v2mn=v2[v2mk]

if DEBUG:
  print("v1mk: "+str(v1mk))
  print("v1mn: "+str(v1mn))
  print("")
  print("v2mk: "+str(v2mk))
  print("v2mn: "+str(v2mn))
  print("")
  print("v1ln: "+str(len(v1)))
  print("v2ln: "+str(len(v2)))
  print("")

if len(v1)==1 and len(v2)==1:
  if v1mk==v2mk:
    print(min([v1mn,v2mn]))
    sys.exit()
  print("0")
  sys.exit()

if(not v1mk==v2mk):
  if(v1mn>v2mn):
    print(v2n-v2mn + v1n-v1mn)
  else:
    print(v2n-v2mn + v1n-v1mn)
else:
  if(v1mn>v2mn):
    hoge=v2[v2mk]
    v2[v2mk]=0
    v2mk=max(v2, key=v2.get)
    v2mn=v2[v2mk]
    print(v2n-v2mn +hoge + v1n-v1mn)
  else:
    hoge=v1[v1mk]
    v1[v1mk]=0
    v1mk=max(v1, key=v1.get)
    v1mn=v1[v1mk]
    print(v2n-v2mn +hoge+ v1n-v1mn)

Submission status: Wrong Answer

Solution code:
import statistics
import sys
n=input()
v=list(map(int,input().split()))
DEBUG=0
cnt=0
v1={}
v2={}
v1n=0
v2n=0
for i in v:
  #(v1 if not cnt%2 else v2).append(i)
  if not cnt%2:
    v1n+=1
    if i in v1:
      v1[i]+=1
    else:
      v1[i]=1
  else:
    v2n+=1
    if i in v2:
      v2[i]+=1
    else:
      v2[i]=1
  cnt+=1

if DEBUG:
  print ("v:   "+str(v))
  print ("v1:  "+str(v1))
  print ("v2:  "+str(v2))
  print("")

v1mk=max(v1, key=v1.get)
v2mk=max(v2, key=v2.get)
v1mn=v1[v1mk]
v2mn=v2[v2mk]

if DEBUG:
  print("v1mk: "+str(v1mk))
  print("v1mn: "+str(v1mn))
  print("")
  print("v2mk: "+str(v2mk))
  print("v2mn: "+str(v2mn))
  print("")
  print("v1ln: "+str(len(v1)))
  print("v2ln: "+str(len(v2)))
  print("")

if len(v1)==1 and len(v2)==1:
  if v1mk==v2mk:
    print(min([v1mn,v2mn]))
    sys.exit()
  print("0")
  sys.exit()

if(not v1mk==v2mk):
  if(v1mn>v2mn):
    print(v2n-v2mn + v1n-v1mn)
  else:
    print(v2n-v2mn + v1n-v1mn)
else:
  if(v1mn>v2mn):
    v2[v2mk]=0
    v2mk=max(v2, key=v2.get)
    v2mn=v2[v2mk]
    print(v2n-v2mn + v1n-v1mn)
  else:
    v1[v1mk]=0
    v1mk=max(v1, key=v1.get)
    v1mn=v1[v1mk]
    print(v2n-v2mn + v1n-v1mn)

Submission status: Wrong Answer

Solution code:
import statistics
import sys
n=input()
v=list(map(int,input().split()))
DEBUG=0
cnt=0
v1={}
v2={}
v1n=0
v2n=0
for i in v:
  #(v1 if not cnt%2 else v2).append(i)
  if not cnt%2:
    v1n+=1
    if i in v1:
      v1[i]+=1
    else:
      v1[i]=1
  else:
    v2n+=1
    if i in v2:
      v2[i]+=1
    else:
      v2[i]=1
  cnt+=1

if DEBUG:
  print (v)
  print (v1)
  print (v2)

v1mk=max(v1, key=v1.get)
v2mk=max(v2, key=v2.get)
v1mn=v1[v1mk]
v2mn=v2[v2mk]

if DEBUG:
  print(v1mk)
  print(v2mk)
  print(v1mn)
  print(v2mn)

if len(v1)==1 and len(v2)==1:
  if v1mk==v2mk:
    print(min([v1mn,v2mn]))
    sys.exit()
  print("0")
  sys.exit()

if(not v1mk==v2mk):
  if(v1mn>v2mn):
    print(len(v2)-v2mn)
  else:
    print(len(v1)-v1mn)
else:
  if(v1mn>v2mn):
    v2[v2mk]=0
    v2mk=max(v2, key=v2.get)
    v2mn=v2[v2mk]
    print(len(v2)-v2mn)
  else:
    v1[v1mk]=0
    v1mk=max(v1, key=v1.get)
    v1mn=v1[v1mk]
    print(len(v1)-v1mn)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import combinations
from time import time

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

start_time = time()

a_occ = Counter(a)

if len(a_occ) == 1:
    print(int(n / 2))
    exit()

a_mcommon = a_occ.most_common()

elem = list()
elem.append(a_mcommon[0][0])
elem.append(a_mcommon[1][0])

for i in range(2, len(a_mcommon)):
    if a_mcommon[i][1] >= a_mcommon[1][1]:
        elem.append(a_mcommon[i][0])
    else:
        break


def algo_run(elem_tuple: tuple, list_to_alt: list) -> int:
    item_select = True
    result_true = 0
    result_false = 0
    for i in list_to_alt:
        if item_select:
            if i != elem_tuple[0]:
                result_true += 1
        else:
            if i != elem_tuple[1]:
                result_true += 1

        if not(item_select):
            if i != elem_tuple[0]:
                result_false += 1
        else:
            if i != elem_tuple[1]:
                result_false += 1

        item_select = not (item_select)

    return result_true if result_true < result_false else result_false


minimum = 9999999
for perm in combinations(elem, 2):
    algo_run_cache = algo_run(perm, a)
    if algo_run_cache < minimum:
        minimum = algo_run_cache

    if time() - start_time <= 1.95:
        break


print(minimum)
# print(time()-start_time)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import combinations


n = int(input())
a = list(map(int, input().split()))
a_occ = Counter(a)

if len(a_occ) == 1:
    print(int(n / 2))
    exit()

a_mcommon = a_occ.most_common()

elem = list()
elem.append(a_mcommon[0][0])
elem.append(a_mcommon[1][0])

for i in range(2, len(a_mcommon)):
    if a_mcommon[i][1] >= a_mcommon[1][1]:
        elem.append(a_mcommon[i][0])
    else:
        break


def algo_run(elem_tuple: tuple, list_to_alt: list) -> int:
    item_select = True
    result_true = 0
    result_false = 0
    for i in list_to_alt:
        if item_select:
            if i != elem_tuple[0]:
                result_true += 1
        else:
            if i != elem_tuple[1]:
                result_true += 1

        if not(item_select):
            if i != elem_tuple[1]:
                result_false += 1
        else:
            if i != elem_tuple[0]:
                result_false += 1

        item_select = not (item_select)

    return result_true if result_true < result_false else result_false


minimum = 9999999
for perm in combinations(elem, 2):
    algo_run_cache = algo_run(perm, a)
    if algo_run_cache < minimum:
        minimum = algo_run_cache


print(minimum)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
a_occ = Counter(a)

if len(a_occ) == 1:
    print(int(n / 2))
    exit()

a_mcommon = a_occ.most_common(2)

elem1 = a_mcommon[0][0]
elem2 = a_mcommon[1][0]

first_item = True
first_item_replace = 0
for i, item in enumerate(a):
    if first_item:
        if item != elem1:
            first_item_replace += 1
    else:
        if item != elem2:
            first_item_replace += 1
    first_item = not(first_item)


second_item = True
second_item_replace = 0
for i, item in enumerate(a):
    if second_item:
        if item != elem2:
            second_item_replace += 1
    else:
        if item != elem1:
            second_item_replace += 1
    second_item = not(second_item)

print((first_item_replace if first_item_replace <
       second_item_replace else second_item_replace))

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
l=list(map(int,input().split()))
#print(l)
e=[None]*(n//2)
o=[None]*(n//2)
for i in range(n//2):
    e[i]=l[2*i]
    o[i]=l[2*i+1]
print(e,o)
ce=collections.Counter(e)
co=collections.Counter(o)
ce=ce.most_common()
co=co.most_common()
#print(co)
ce.append((0,0))
co.append((0,0))
if ce[0][0]!=co[0][0]:
    print(n-co[0][1]-ce[0][1])
else:
    print(min(n-ce[1][1]-co[0][1],n-ce[0][1]-co[1][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
d = {(0, 0): 0, (1, 0): 0}
for i in range(n):
  d[i % 2, v[i]] = d.get((i % 2, v[i]), 0) + 1
to_sort = [[], []]
for i in d:
  to_sort[i[0]].append((d[i], i[1]))
to_sort[0].sort()
to_sort[1].sort()
if to_sort[0][-1][1] != to_sort[1][-1][1]:
  ans = n - to_sort[0][-1][0] - to_sort[1][-1][0]
else:
  ans = n - max(to_sort[0][-1][0] - to_sort[1][-2][0], to_sort[0][-2][0] - to_sort[1][-1][0])
print(ans)

Submission status: Wrong Answer

Solution code:

n=int(input())
l=list(map(int,input().split()))
#print(l)
cnt1=0
cnt2=0
cnt3=0
cnt4=0
for i in range(0,n-1,2):
    if l[0]==l[i]:
        cnt1+=1
    else:
        cnt2+=1
a=min(cnt1,cnt2)
for i in range(1,n,2):
    if l[1]==l[i]:
        cnt3+=1
    else:
        cnt4+=1
b=min(cnt3,cnt4)
if a+b==0 and l[0]==l[1]:
    print(n//2)
else:
    print(a+b)

Submission status: Wrong Answer

Solution code:
'''
問題文
	数列 a1,a2,...,an が以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。
	・各 i=1,2,..,n−2 について、ai=ai+2
	・数列に現れる数はちょうど 2 種類
	偶数長の数列 v1,v2,...,vn が与えられます。 
	要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。

制約
2 ≤ n ≤ 10^5
n は偶数
1 ≤ vi ≤ 10^5
vi は整数

入力
入力は以下の形式で標準入力から与えられる。
n
v1 v2 ... vn

出力
書き換える要素数の最小値を出力してください。

入力例 1 
4
3 1 3 2
出力例 1 
1
数列 
3,1,3,2 は /\/\/\/ ではありませんが、
1 要素書き換えることで /\/\/\/ にすることができます。 例えば、4 要素目を書き換えて 3,1,3,1 とすればよいです。

入力例 2 
6
105 119 105 119 105 119
出力例 2 
0
数列 
105,119,105,119,105,119 は /\/\/\/ です。

入力例 3 
4
1 1 1 1
出力例 3 
Copy
2
数列 
1,1,1,1 は 1 種類の数からなる数列であるため、 /\/\/\/ ではありません。
'''

import collections

def calcChange(even_list, odd_list) :
	"""
	/\/\/\/にするために変更する要素数を算出

	Parameters
	----------
	even_list : list
			偶数番目の要素のリスト
	odd_list : list
			奇数番目の要素のリスト
	
	Returns
	-------
	change : int
			/\/\/\/にするために変更する要素数
			
	"""	

	# 変更回数を代入する変数
	change = 0

	# 各リストについて、要素名:要素数 の辞書を、Counterで作成
	even_counter = collections.Counter(even_list)
	odd_counter = collections.Counter(odd_list)
	
	# 最多要素を取得
	most_even = even_counter.most_common()
	most_odd = odd_counter.most_common()

	# 最多要素が被っていない
	if most_even[0][0] != most_odd[0][0] :
		even_change = len(even_list) - most_even[0][1]
		odd_change  = len(odd_list)  - most_odd[0][1]
		change = even_change + odd_change
	# 被ってる
	else :
		if len(most_even)==1 and len(most_odd)==1 :# 全かぶり
			even_change = len(even_list)
			odd_change  = 0
		elif most_even[0][1] < most_odd[0][1] :
			even_change = len(even_list) - most_even[1][1]
			odd_change  = len(odd_list)  - most_odd[0][1]
		else :
			even_change = len(even_list) - most_even[0][1]
			odd_change  = len(odd_list)  - most_odd[1][1]
		change = even_change + odd_change


	return change



def main():
	'''
	メイン関数
	'''
	# 数列の大きさ
	n = int(input())
	# 数列
	v = list(map(int, input().split()))

	# 偶数番目を抽出した配列
	v_e = [ v[i] for i in range(0,n) if i%2==0 ]

	# 奇数番目を抽出した配列
	v_o = [ v[i] for i in range(0,n) if i%2==1 ]

	print(calcChange(v_e, v_o))


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
'''
問題文
	数列 a1,a2,...,an が以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。
	・各 i=1,2,..,n−2 について、ai=ai+2
	・数列に現れる数はちょうど 2 種類
	偶数長の数列 v1,v2,...,vn が与えられます。 
	要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。

制約
2 ≤ n ≤ 10^5
n は偶数
1 ≤ vi ≤ 10^5
vi は整数

入力
入力は以下の形式で標準入力から与えられる。
n
v1 v2 ... vn

出力
書き換える要素数の最小値を出力してください。

入力例 1 
4
3 1 3 2
出力例 1 
1
数列 
3,1,3,2 は /\/\/\/ ではありませんが、
1 要素書き換えることで /\/\/\/ にすることができます。 例えば、4 要素目を書き換えて 3,1,3,1 とすればよいです。

入力例 2 
6
105 119 105 119 105 119
出力例 2 
0
数列 
105,119,105,119,105,119 は /\/\/\/ です。

入力例 3 
4
1 1 1 1
出力例 3 
Copy
2
数列 
1,1,1,1 は 1 種類の数からなる数列であるため、 /\/\/\/ ではありません。
'''

import collections

def calcChange(even_list, odd_list) :
	"""
	/\/\/\/にするために変更する要素数を算出

	Parameters
	----------
	even_list : list
			偶数番目の要素のリスト
	odd_list : list
			奇数番目の要素のリスト
	
	Returns
	-------
	change : int
			/\/\/\/にするために変更する要素数
			
	"""	

	# 変更回数を代入する変数
	change = 0

	# 各リストについて、要素名:要素数 の辞書を、Counterで作成
	even_counter = collections.Counter(even_list)
	odd_counter = collections.Counter(odd_list)
	
	# 最多要素を取得
	most_even = even_counter.most_common()
	most_odd = odd_counter.most_common()

	# 最多要素が被っていない
	if most_even[0][0] != most_odd[0][0] :
		even_change = len(even_list) - most_even[0][1]
		odd_change  = len(odd_list)  - most_odd[0][1]
		change = even_change + odd_change
	# 被ってる
	else :
		if len(most_even)==1 and len(most_odd)==1 :# 全かぶり
			even_change = len(even_list)
			odd_change  = 0
		elif most_even[0][1] < most_odd[0][1] :
			even_change = len(even_list) - most_even[1][1]
			odd_change  = len(odd_list)  - most_odd[0][1]
		else :
			even_change = len(even_list) - most_even[0][1]
			odd_change  = len(odd_list)  - most_odd[1][1]
		change = even_change + odd_change

	print(change)

	return change



def main():
	'''
	メイン関数
	'''
	# 数列の大きさ
	n = int(input())
	# 数列
	v = list(map(int, input().split()))

	# 偶数番目を抽出した配列
	v_e = [ v[i] for i in range(0,n) if i%2==0 ]

	# 奇数番目を抽出した配列
	v_o = [ v[i] for i in range(0,n) if i%2==1 ]

	return calcChange(v_e, v_o)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c1 = Counter(a[::2])
c2 = Counter(a[1::2])
c1f1 = max(c1, key=lambda k: c1[k])
c2f1 = max(c2, key=lambda k: c2[k])

if c1f1 != c2f1:
    print(n - c1[c1f1] - c2[c2f1])
else:
    if c1[c1f1] > c2[c2f1]:
        del c2[c2f1]
        if not c2:
            print(n - c1[c1f1])
            exit(0)
        c2f1 = max(c2, key=lambda k: c2[k])
        print(n - c1[c1f1] - c2[c2f1])
    else:
        del c1[c1f1]
        if not c1:
            print(n - c2[c2f1])
            exit(0)
        c1f1 = max(c1, key=lambda k: c1[k])
        print(n - c1[c1f1] - c2[c2f1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

V1 = [V[i] for i in range(0, len(V), 2)]
V2 = [V[i] for i in range(1, len(V), 2)]

x = Counter(V1).most_common(2)
y = Counter(V2).most_common(2)
for i in range(min(len(x),len(y))):
    if x[i][1] > y[i][1]:
        break
    elif x[i][1] < y[i][1]:
        x, y = (y, x)
        break

l = int(N / 2)
res = l - x[0][1]
if y[0][0] == x[0][0]:
    res += l - (y[1][1] if len(y) > 1 else 0)
else:
    res += l - y[0][1]

print(res)