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:
import collections

n = int(input())
v = list(map(int, input().split()))
even = []
odd = []
for i in range(0, n, 2):
    odd.append(v[i])
for i in range(1, n, 2):
    even.append(v[i])
odd_counter = collections.Counter(odd)
even_counter = collections.Counter(even)

odd_counter_sorted = sorted(odd_counter.items(),
                            key=lambda x: x[1],
                            reverse=True)
even_counter_sorted = sorted(even_counter.items(),
                             key=lambda x: x[1],
                             reverse=True)
if odd_counter_sorted[0][0] != even_counter_sorted[0][0]:
    print(
        len(odd) - odd_counter_sorted[0][1] + len(even) -
        even_counter_sorted[0][1])
else:
    if len(odd) - odd_counter_sorted[0][1] > len(
            even) - even_counter_sorted[0][1]:
        if len(odd_counter_sorted) > 1:
            print(
                len(odd) - odd_counter_sorted[1][1] + len(even) -
                even_counter_sorted[0][1])
        else:
            print(len(odd) + len(even) - even_counter_sorted[0][1])
    else:
        if len(even_counter_sorted) > 1:
            print(
                len(odd) - odd_counter_sorted[0][1] + len(even) -
                even_counter_sorted[1][1])
        else:
            print(len(odd) - odd_counter_sorted[0][1] + len(even))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = list(map(int, input().split()))
even = []
odd = []
for i in range(0, n, 2):
    odd.append(v[i])
for i in range(1, n, 2):
    even.append(v[i])
odd_counter = collections.Counter(odd)
even_counter = collections.Counter(even)

odd_counter_sorted = sorted(odd_counter.items(),
                            key=lambda x: x[1],
                            reverse=True)
even_counter_sorted = sorted(even_counter.items(),
                             key=lambda x: x[1],
                             reverse=True)
if odd_counter_sorted[0][0] != even_counter_sorted[0][0]:
    print(
        len(odd) - odd_counter_sorted[0][1] + len(even) -
        even_counter_sorted[0][1])
else:
    if odd_counter_sorted[0][1] <= even_counter_sorted[0][1]:
        if len(odd_counter_sorted) > 1:
            print(
                len(odd) - odd_counter_sorted[1][1] + len(even) -
                even_counter_sorted[0][1])
        else:
            print(len(odd) + len(even) - even_counter_sorted[0][1])
    elif odd_counter_sorted[0][1] > even_counter_sorted[0][1]:
        if len(even_counter_sorted) > 1:
            print(
                len(odd) - odd_counter_sorted[0][1] + len(even) -
                even_counter_sorted[1][1])
        else:
            print(len(odd) - odd_counter_sorted[0][1] + len(even))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
e=Counter(v[0::2])
o=Counter(v[1::2])
if max(e)==max(o):
    if max(e.values())>=max(o.values()):
        o[max(o)]=0
    else:
        e[max(e)]=0
print(n-max(e.values())-max(o.values()))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
e=Counter(v[0::2])
o=Counter(v[1::2])
print(n-max(e.values())-max(o.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        odd.append(V[i])
    else:
        even.append(V[i])
import collections
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)
# print(c_even.most_common(1))
# print(c_odd.most_common(1))
cnt = 0
if c_even.most_common(1)[0][0] == c_odd.most_common(1)[0][0]:
    try:
        if c_even.most_common(1)[0][1] > c_odd.most_common(1)[0][1]:
            cnt += n - (c_even.most_common(1)[0][1] + c_odd.most_common(2)[1][1])
        else:
            cnt += n - (c_even.most_common(2)[1][1] + c_odd.most_common(1)[0][1])
    except Exception as e:
        cnt += n - max(c_even.most_common(1)[0][1], c_odd.most_common(1)[0][1])
    print(cnt)
else:
    print(n - (c_even.most_common(1)[0][1] + c_odd.most_common(1)[0][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        odd.append(V[i])
    else:
        even.append(V[i])
import collections
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)
# print(c_even.most_common(1))
# print(c_odd.most_common(1))
cnt = 0
if c_even.most_common(1)[0][0] == c_odd.most_common(1)[0][0]:
    try:
        if c_even.most_common(1)[0][1] > c_odd.most_common(1)[0][1]:
            cnt += n - (c_even.most_common(1)[0][1] + c_odd.most_common(2)[1][1])
        else:
            cnt += n - (c_even.most_common(2)[2][1] + c_odd.most_common(1)[0][1])
    except Exception as e:
        cnt += n - max(c_even.most_common(1)[0][1], c_odd.most_common(1)[0][1])
    print(cnt*(-1))
else:
    print(n - (c_even.most_common(1)[0][1] + c_odd.most_common(1)[0][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
even = []
odd = []
for i in range(n):
    if i % 2 == 0:
        odd.append(V[i])
    else:
        even.append(V[i])
import collections
c_even = collections.Counter(even)
c_odd = collections.Counter(odd)
# print(c_even.most_common(1))
# print(c_odd.most_common(1))
cnt = 0
if c_even.most_common(1)[0][0] == c_odd.most_common(1)[0][0]:
    try:
        if c_even.most_common(1)[0][1] > c_odd.most_common(1)[0][1]:
            cnt += n - (c_even.most_common(1)[0][1] + c_odd.most_common(2)[1][1])
        else:
            cnt += n - (c_even.most_common(2)[2][1] + c_odd.most_common(1)[0][1])
    except Exception as e:
        cnt += n - max(c_even.most_common(1)[0][1], c_odd.most_common(1)[0][1])
    print(cnt)
else:
    print(n - (c_even.most_common(1)[0][1] + c_odd.most_common(1)[0][1]))

Submission status: Wrong Answer

Solution code:
import collections
import sys

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

even = v[0:n-1:2]
odd = v[1:n:2]

c_even = collections.Counter(even).most_common()
c_odd = collections.Counter(odd).most_common()

if len(c_even) == 1 and len(c_odd) == 1:
  print(int(n/2))
  sys.exit()
elif len(c_even) == 1:
  print(int(n/2) - c_odd[1][1])
  sys.exit()

elif len(c_odd) == 1:
  print(int(n/2) - c_even[1][1])
  sys.exit()

    

if c_odd[0][0] == c_even[0][0]:
  if c_even[1][1] > c_odd[1][1]:
     answer = (len(even)-c_even[1][1])+(len(odd)-c_odd[0][1])
  else:
     answer = (len(even)-c_even[0][1])+(len(odd)-c_odd[1][1])
else:
  answer = (len(even)-c_even[0][1])+(len(odd)-c_odd[0][1])
print(answer)

Submission status: Wrong Answer

Solution code:
import collections

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

even = v[0:n-1:2]
odd = v[1:n:2]

c_even = collections.Counter(even).most_common()
c_odd = collections.Counter(odd).most_common()

answer = (len(even)-c_even[0][1])+(len(odd)-c_odd[0][1])
print(answer)

Submission status: Wrong Answer

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

v_a = v[0:len(v)+1:2]
v_b = v[1:len(v):2]

sum_a = 0
sum_b = 0
v_ac = collections.Counter(v_a)
v_bc = collections.Counter(v_b)
v_ac_val = v_ac.values()
v_bc_val = v_bc.values()
v_ac_val = sorted(v_ac_val,reverse=True)
v_bc_val = sorted(v_bc_val,reverse=True)

if len(set(v)) == 1:
  print(int(len(v)/2))
elif len(set(v_a)) == 1 and len(set(v_b)) == 1 and len(set(v)) != 1:
  print(0)
elif v_ac_val[0] == v_bc_val[0]:
  print(sum(v_ac_val[1:]) + sum(v_bc_val[1:]))
else:
  ans1 = sum(v_ac_val[1:]) + int(v_bc_val[0]) + sum(v_bc_val[2:])
  ans2 = int(v_ac_val[0]) + sum(v_ac_val[2:]) + sum(v_bc_val[1:])
  print(min(ans1,ans2))

Submission status: Wrong Answer

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

v_a = v[0:len(v)+1:2]
v_b = v[1:len(v):2]

sum_a = 0
sum_b = 0
v_ac = collections.Counter(v_a)
v_bc = collections.Counter(v_b)
v_ac_val = v_ac.values()
v_bc_val = v_bc.values()
v_ac_val = sorted(v_ac_val,reverse=True)
v_bc_val = sorted(v_bc_val,reverse=True)

if len(set(v)) == 1:
  print(int(len(v)/2))
elif len(set(v_a)) == 1 and len(set(v_b)) == 1 and len(set(v)) != 1:
  print(0)
else:
  ans1 = sum(v_ac_val[1:]) + int(v_bc_val[0]) + sum(v_bc_val[2:])
  ans2 = int(v_ac_val[0]) + sum(v_ac_val[2:]) + sum(v_bc_val[1:])
  ans3 = sum(v_ac_val[1:]) + sum(v_bc_val[1:])
  print(min(ans1,ans2,ans3))

Submission status: Wrong Answer

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

v_a = v[0:len(v)+1:2]
v_b = v[1:len(v):2]

sum_a = 0
sum_b = 0
v_ac = collections.Counter(v_a)
v_bc = collections.Counter(v_b)
v_ac_val = v_ac.values()
v_bc_val = v_bc.values()
v_ac_val = sorted(v_ac_val,reverse=True)
v_bc_val = sorted(v_bc_val,reverse=True)

if len(set(v)) == 1:
  print(int(len(v)/2))
elif len(set(v_a)) == 1 and len(set(v_b)) == 1 and len(set(v)) != 1:
  print(0)
else:
  ans1 = sum(v_ac_val[1:]) + int(v_bc_val[0]) + sum(v_bc_val[2:])
  ans2 = int(v_ac_val[0]) + sum(v_ac_val[2:]) + sum(v_bc_val[1:])
  print(min(ans1,ans2))

Submission status: Wrong Answer

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

v_a = v[0:len(v)+1:2]
v_b = v[1:len(v):2]

sum_a = 0
sum_b = 0
v_ac = collections.Counter(v_a)
v_bc = collections.Counter(v_b)
v_ac_val = v_ac.values()
v_bc_val = v_bc.values()
v_ac_val = sorted(v_ac_val,reverse=True)
v_bc_val = sorted(v_bc_val,reverse=True)

if len(set(v))==1:
  print(int(len(v)/2))
elif len(set(v_a)) == 1 and len(set(v_b)) == 1:
  print(0)
else:
  ans1 = sum(v_ac_val[1:])+v_bc_val[0] + sum(v_bc_val[2:])
  ans2 = v_ac_val[0] + sum(v_ac_val[2:])+sum(v_bc_val[1:])
  if ans1 < ans2:
    print(ans1)
  else:
    print(ans2)

Submission status: Wrong Answer

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

v_a = v[0:len(v)+1:2]
v_b = v[1:len(v):2]

sum_a = 0
sum_b = 0
v_ac = collections.Counter(v_a)
v_bc = collections.Counter(v_b)
v_ac_val = v_ac.values()
v_bc_val = v_bc.values()
v_ac_val = sorted(v_ac_val,reverse=True)
v_bc_val = sorted(v_bc_val,reverse=True)

if len(set(v))==1:
  print(int(len(v)/2))
else:
  ans1 = sum(v_ac_val[1:])+v_bc_val[0] + sum(v_bc_val[2:])
  ans2 = v_ac_val[0] + sum(v_ac_val[2:])+sum(v_bc_val[1:])
  if ans1 < ans2:
    print(ans1)
  else:
    print(ans2)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
o=[]
e=[]
for i in range(n):
  if i%2==0:
    o.append(a[i])
  else:
    e.append(a[i])
from collections import Counter as co
o=co(o)
e=co(e)
o['x']=0
e['x']=0
ov=o.values()
ev=e.values()
mo=max(ov)
me=max(ev)
if n==2:
  if a[0]==a[1]:
    print(1)
  else:
    print(0)
else:
  if max(o,key=o.get)==max(e,key=e.get):
    if mo>me:
      me=sorted(ev)[-2]
    else:
      mo=sorted(ov)[-2]
  print(n-mo-me)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
def doit(vs):
    ret = {}
    for v in vs:
        ret[v] = ret.get(v, 0) + 1
    return sorted((-ret[v], v) for c in ret) + [(0, None)]
odd = doit(v[0::2])
even = doit(v[1::2])
if odd[0][1] != even[0][1]:
    print(n + odd[0][0] + even[0][0])
else:
    print(n + min(odd[1][0] + even[0][0], odd[0][0] + even[1][0]))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

n = int(input())
v = list(map(int, input().split()))
odd = list(sorted((-len(list(g)), k) for k, g in groupby(v[0::2]))) + [(0, None)]
even = list(sorted((-len(list(g)), k) for k, g in groupby(v[1::2]))) + [(0, None)]
if odd[0][1] != even[0][1]:
    print(n + odd[0][0] + even[0][0])
else:
    print(n + min(odd[1][0] + even[0][0], odd[0][0] + even[1][0]))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

n = int(input())
v = list(map(int, input().split()))
odd = sorted((-len(list(g)), k) for k, g in groupby(v[0::2])) + [(0, None)]
even = sorted((-len(list(g)), k) for k, g in groupby(v[1::2])) + [(0, None)]
if odd[0][1] != even[0][1]:
    print(n + odd[0][0] + even[0][0])
else:
    print(n + min(odd[1][0] + even[0][0], odd[0][0] + even[1][0]))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

n = int(input())
v = list(map(int, input().split()))
odd = sorted((-len(list(g)), k) for k, g in groupby(v[0::2])) + [(0, None)]
even = sorted((-len(list(g)), k) for k, g in groupby(v[1::2])) + [(0, None)]
if odd[0][1] != even[0][1]:
    print(n + odd[0][0] + even[0][0])
else:
    print(n + max(odd[1][0] + even[0][0], odd[0][0] + even[1][0]))

Submission status: Wrong Answer

Solution code:
#111c
import collections
import copy

n = int(input()) #2≤n≤10**5 偶数
v_list = [int(e) for e in input().split()]

#数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。

#・各 i=1,2,...,n−2について、ai=ai+2 
#・数列に現れる数はちょうど 2種類

#偶数長の数列 v1,v2,...,vnが与えられます。 
#要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。

#一番多く出てくる文字を求め、書き換えない数字を決める
v_list_odd = [v_list[i] for i in range(n) if i%2==1]
v_list_even = [v_list[i] for i in range(n) if i%2==0]

#print(v_list_odd)
#print(v_list_even)

c = collections.Counter(v_list_odd)
v_list_odd_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
c = collections.Counter(v_list_even)
v_list_even_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
#固定文字の決定
#1文字目が重複していなければ、両方とも出現回数最多を固定する
if fix_picklist_for_v_list_even[0] != fix_picklist_for_v_list_odd[0]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]

#1文字目が重複している場合
#両方1文字しかなければ片方のみ
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = "!"
#片方が1文字ならば、そうでない方は2文字目を使う。
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) != 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif len(fix_picklist_for_v_list_even) != 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
#両方2文字あるなら、固定パターンの合計が多い方を採用
elif fix_picklist_for_v_list_even[0]+fix_picklist_for_v_list_odd[2] > fix_picklist_for_v_list_even[2]+fix_picklist_for_v_list_odd[0]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif  fix_picklist_for_v_list_even[0]+fix_picklist_for_v_list_odd[2] <= fix_picklist_for_v_list_even[2]+fix_picklist_for_v_list_odd[0]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]

#print(fix_char_for_v_list_odd)
#print(fix_char_for_v_list_even)
        
#書き換え要素数をカウント
ans_odd = n/2 - v_list_odd_counter[fix_char_for_v_list_odd]
ans_even = n/2 - v_list_even_counter[fix_char_for_v_list_even]
print(int(ans_odd + ans_even))

Submission status: Wrong Answer

Solution code:
#111c
import collections
import copy

n = int(input()) #2≤n≤10**5 偶数
v_list = [int(e) for e in input().split()]

#数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。

#・各 i=1,2,...,n−2について、ai=ai+2 
#・数列に現れる数はちょうど 2種類

#偶数長の数列 v1,v2,...,vnが与えられます。 
#要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。

#一番多く出てくる文字を求め、書き換えない数字を決める
v_list_odd = [v_list[i] for i in range(n) if i%2==1]
v_list_even = [v_list[i] for i in range(n) if i%2==0]

#print(v_list_odd)
#print(v_list_even)

c = collections.Counter(v_list_odd)
v_list_odd_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
c = collections.Counter(v_list_even)
v_list_even_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
#固定文字の決定
#1文字目が重複していなければ、両方とも出現回数最多を固定する
if fix_picklist_for_v_list_even[0] != fix_picklist_for_v_list_odd[0]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]

#1文字目が重複している場合
#両方1文字しかなければ片方のみ
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = "!"
#片方が1文字ならば、そうでない方は2文字目を使う。
elif len(fix_picklist_for_v_list_even) == 2 and len(fix_picklist_for_v_list_odd) != 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif len(fix_picklist_for_v_list_even) != 2 and len(fix_picklist_for_v_list_odd) == 2:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
#両方2文字あるなら、固定パターンの合計が多い方を採用
elif fix_picklist_for_v_list_even[0]+fix_picklist_for_v_list_odd[2] > fix_picklist_for_v_list_even[2]+fix_picklist_for_v_list_odd[0]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
elif  fix_picklist_for_v_list_even[0]+fix_picklist_for_v_list_odd[2] <= fix_picklist_for_v_list_even[2]+fix_picklist_for_v_list_odd[0]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]

#print(fix_char_for_v_list_odd)
#print(fix_char_for_v_list_even)
        
#書き換え要素数をカウント
ans_odd = n/2 - v_list_odd_counter[fix_char_for_v_list_odd]
ans_even = n/2 - v_list_even_counter[fix_char_for_v_list_even]
print(int(ans_odd + ans_even))

Submission status: Wrong Answer

Solution code:
#111c
import collections
import copy

n = int(input()) #2≤n≤10**5 偶数
v_list = [int(e) for e in input().split()]

#数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。

#・各 i=1,2,...,n−2について、ai=ai+2 
#・数列に現れる数はちょうど 2種類

#偶数長の数列 v1,v2,...,vnが与えられます。 
#要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。 書き換える要素の数は最小でいくつになるか求めてください。

#一番多く出てくる文字を求め、書き換えない数字を決める
v_list_odd = [v_list[i] for i in range(n) if i%2==1]
v_list_even = [v_list[i] for i in range(n) if i%2==0]

#print(v_list_odd)
#print(v_list_even)

c = collections.Counter(v_list_odd)
v_list_odd_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    
c = collections.Counter(v_list_even)
v_list_even_counter = copy.copy(c)
if len(c)>1:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1],((c.most_common(2))[1])[0],((c.most_common(2))[1])[1]]
else:
    fix_picklist_for_v_list_even = [((c.most_common(2))[0])[0],((c.most_common(2))[0])[1]]
    

if fix_picklist_for_v_list_odd[1] >= fix_picklist_for_v_list_even[1]:
    fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
    if fix_picklist_for_v_list_even[0] != fix_picklist_for_v_list_odd[0]:
        fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    elif fix_picklist_for_v_list_even[0] == fix_picklist_for_v_list_odd[0]:
        if len(fix_picklist_for_v_list_even)>2:
            fix_char_for_v_list_even = fix_picklist_for_v_list_even[2]
        else:
            fix_char_for_v_list_even = "!"
elif fix_picklist_for_v_list_odd[1] < fix_picklist_for_v_list_even[1]:
    fix_char_for_v_list_even = fix_picklist_for_v_list_even[0]
    if fix_picklist_for_v_list_odd[0] != fix_picklist_for_v_list_even[0]:
        fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[0]
    elif fix_picklist_for_v_list_odd[0] == fix_picklist_for_v_list_even[0]:
        if len(fix_picklist_for_v_list_odd)>2:
            fix_char_for_v_list_odd = fix_picklist_for_v_list_odd[2]
        else:
            fix_char_for_v_list_odd = "!"

#print(fix_char_for_v_list_odd)
#print(fix_char_for_v_list_even)
        
#書き換え要素数をカウント
ans_odd = n/2 - v_list_odd_counter[fix_char_for_v_list_odd]
ans_even = n/2 - v_list_even_counter[fix_char_for_v_list_even]
print(int(ans_odd + ans_even))

Submission status: Wrong Answer

Solution code:
n = int(input())
os = {}
es = {}
os_max = 1
es_max = 1
os_second = 0
es_second = 0
os_str = ''
es_str = ''
for i, v in enumerate(input().split()):
    if int(i) % 2 == 0:
        if (v in os.keys()):
            os[v] = os[v] + 1
            if (os[v] > os_max):
                os_max = max(os_max, os[v])
                os_str = v
            if (os[v] < os_max):
                os_second = max(os_second, os[v])
        else:
            os[v] = 1
    else:
        if (v in es.keys()):
            es[v] = es[v] + 1
            if (es[v] > es_max):
                es_max = max(es_max, es[v])
                es_str = v
            if (es[v] < es_max):
                es_second = max(es_second, es[v])
        else:
            es[v] = 1
tmpmax = int(n / 2)
for o in os.keys():
    for e in es.keys():
        if (o != e):
            tmpmax = max(tmpmax, os[o] + es[e])
print (n - tmpmax)

Submission status: Wrong Answer

Solution code:
n = int(input())
os = {}
es = {}
os_max = 1
es_max = 1
os_second = 0
es_second = 0
os_str = ''
es_str = ''
for i, v in enumerate(input().split()):
    if int(i) % 2 == 0:
        if (v in os.keys()):
            os[v] = os[v] + 1
            if (os[v] > os_max):
                os_max = max(os_max, os[v])
                os_str = v
            if (os[v] < os_max):
                os_second = max(os_second, os[v])
        else:
            os[v] = 1
    else:
        if (v in es.keys()):
            es[v] = es[v] + 1
            if (es[v] > es_max):
                es_max = max(es_max, es[v])
                es_str = v
            if (es[v] < es_max):
                es_second = max(es_second, es[v])
        else:
            es[v] = 1
if (os_str != es_str):
    print (n - os_max - es_max)
else:
    print (n - max(os_max + es_second, es_max + os_second))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a = sorted(Counter(v[ ::2]).items(), key=lambda x: -x[1])
b = sorted(Counter(v[1::2]).items(), key=lambda x: -x[1])
al = len(a)
bl = len(b)
while a[0][0] == b[0][0] and al > 0 and bl > 0:
  if a[0][1] >= b[0][1] and bl > 0:
    b = b[1:] + [b[0]]
    bl -= 1
  elif a[0][1] <= b[0][1] and al > 0:
    a = a[1:] + [a[0]]
    al -= 1
  
c = sum(c for _, c in a[1:])
d = sum(c for _, c in b[1:])
print(c + d if a[0][0] != b[0][0] else n // 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a = sorted(Counter(v[ ::2]).items(), key=lambda x: -x[1])
b = sorted(Counter(v[1::2]).items(), key=lambda x: -x[1])
al = len(a)
bl = len(b)
while a[0][0] == b[0][0] and al > 0 and bl > 0:
  if a[0][1] >= b[0][1] and bl > 0:
    b = b[1:] + [b[0]]
    bl -= 1
  elif a[0][1] <= b[0][1] and al > 0:
    a = a[1:] + [a[0]]
    al -= 1
  
c = sum(c for _, c in a[1:])
d = sum(c for _, c in b[1:])
print(c + d)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a = sorted(Counter(v[ ::2]).items(), key=lambda x: -x[1])
b = sorted(Counter(v[1::2]).items(), key=lambda x: -x[1])

while a[0][0] == b[0][0]:
  if a[0][1] >= b[0][1]:
    b = b[1:] + [b[0]]
  else:
    a = a[1:] + [a[0]]
  
c = sum(c for _, c in a[1:])
d = sum(c for _, c in b[1:])
print(c + d)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a = sorted(Counter(v[ ::2]).items(), key=lambda x: -x[1])
b = sorted(Counter(v[1::2]).items(), key=lambda x: -x[1])

if a[0][0] == b[0][0]:
  print(n // 2)
else:
  print(sum(c for _, c in a[1:]) + sum(c for _, c in b[1:]))

Submission status: Wrong Answer

Solution code:
n = int(input())
os = []
es = []
os_set = set()
es_set = set()
for i, v in enumerate(input().split()):
    if int(i) % 2 == 0:
        es.append(v)
        es_set.add(v)
    else:
        os.append(v)
        os_set.add(v)
join = int(n / 2)
for o in list(set(os)):
    for e in list(set(es)):
        if (o != e):
            join = max(join, os.count(o) + es.count(e))
print (n - join)

Submission status: Wrong Answer

Solution code:
n = int(input()) // 2
ns = list(map(int, input().split()))

a = [ns[i] for i in range(len(ns)) if i % 2 == 0]
b = [ns[i] for i in range(len(ns)) if i % 2 == 1]
#ca = sorted([(a.count(s), s) for s in sa])[::-1]
#cb = sorted([(b.count(s), s) for s in sb])[::-1]  # [(出た回数, num)]
# countが遅かったので
da = {}
db = {}
for s in a:
    da[s] = da.get(s, 0) + 1
for s in b:
    db[s] = db.get(s, 0) + 1
ca = sorted([(v, k) for k, v in da.items()])[::-1]
cb = sorted([(v, k) for k, v in db.items()])[::-1]

if ca[0][1] != cb[0][1]:
    print(n-ca[0][0] + n-cb[0][0])
else:
    if len(ca) == 1 and len(cb) == 1:
        print(n)
    elif len(ca) == 1 and len(cb) > 1:
        print(n-ca[0][0] + n-cb[1][0])
    elif len(ca) > 1 and len(cb) == 1:
        print(n-ca[1][0] + n-cb[0][0])
    else:
        print(n-ca[1][0] + n-cb[1][0])  # ?

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
vs = [int(s) for s in input().split(' ')]
vs_odd = vs[0::2]
vs_odd.sort()
vs_even = vs[1::2]
vs_even.sort()
odd_group = {0: 0}
even_group = {0: 0}

for k, g in itertools.groupby(vs_odd):
    odd_group[k] = len(list(g))
for k, g in itertools.groupby(vs_even):
    even_group[k] = len(list(g))

ret = len(vs)

odd_max = max(odd_group, key=odd_group.get)
odd_max_v = odd_group[odd_max]
even_max = max(even_group, key=even_group.get)
even_max_v = even_group[even_max]
if odd_max == even_max:
    del odd_group[even_max]
    del even_group[even_max]
    odd_max2 = max(odd_group, key=odd_group.get)
    odd_max2_v = odd_group[odd_max2]
    even_max2 = max(even_group, key=even_group.get)
    even_max2_v = even_group[even_max2]
    ret -= max(odd_max_v + even_max2_v, odd_max2_v + even_max2_v)
else:
    ret -= (odd_max_v + even_max_v )
print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input()) // 2
ns = list(map(int, input().split()))

a = [ns[i] for i in range(len(ns)) if i % 2 == 0]
b = [ns[i] for i in range(len(ns)) if i % 2 == 1]
#ca = sorted([(a.count(s), s) for s in sa])[::-1]
#cb = sorted([(b.count(s), s) for s in sb])[::-1]  # [(出た回数, num)]
# countが遅かったので
da = {}
db = {}
for s in a:
    da[s] = da.get(s, 0) + 1
for s in b:
    db[s] = db.get(s, 0) + 1
ca = sorted([(v, k) for k, v in da.items()])[::-1]
cb = sorted([(v, k) for k, v in db.items()])[::-1]

if ca[0][1] != cb[0][1]:
    print(n-ca[0][0] + n-cb[0][0])
else:
    if len(ca) == 1 and len(cb) == 1:
        print(n)
    elif len(ca) == 1:
        print(n-ca[0][0] + n-cb[1][0])
    else:
        print(n-ca[1][0] + n-cb[0][0])

Submission status: Wrong Answer

Solution code:
n = int(input()) // 2
ns = list(map(int, input().split()))

a = [ns[i] for i in range(len(ns)) if i % 2 == 0]
b = [ns[i] for i in range(len(ns)) if i % 2 == 1]
#ca = sorted([(a.count(s), s) for s in sa])[::-1]
#cb = sorted([(b.count(s), s) for s in sb])[::-1]  # [(出た回数, num)]
# countが遅かったので
da = {}
db = {}
for s in a:
    da[s] = da.get(s, 0) + 1
for s in b:
    db[s] = db.get(s, 0) + 1
ca = sorted([(v, k) for k, v in da.items()])
cb = sorted([(v, k) for k, v in db.items()])[::-1]

if ca[0][1] != cb[0][1]:
    print(n-ca[0][0] + n-cb[0][0])
else:
    if len(ca) == 1 and len(cb) == 1:
        print(n)
    elif len(ca) == 1:
        print(n-ca[0][0] + n-cb[1][0])
    else:
        print(n-ca[1][0] + n-cb[0][0])

Submission status: Wrong Answer

Solution code:
n = int(input()) // 2
ns = list(map(int, input().split()))

a = [ns[i] for i in range(len(ns)) if i % 2 == 0]
b = [ns[i] for i in range(len(ns)) if i % 2 == 1]
sa = set(a)
sb = set(b)
#ca = sorted([(a.count(s), s) for s in sa])[::-1]
#cb = sorted([(b.count(s), s) for s in sb])[::-1]  # [(出た回数, num)]
# countが遅かったので
da = {}
db = {}
for s in sa:
    da[s] = da.get(s, 0) + 1
for s in sb:
    db[s] = db.get(s, 0) + 1
ca = sorted([(v, k) for k, v in da.items()])
cb = sorted([(v, k) for k, v in db.items()])[::-1]

if ca[0][1] != cb[0][1]:
    print(n-ca[0][0] + n-cb[0][0])
else:
    if len(ca) == 1 and len(cb) == 1:
        print(n)
    elif len(ca) == 1:
        print(n-ca[0][0] + n-cb[1][0])
    else:
        print(n-ca[1][0] + n-cb[0][0])

Submission status: Wrong Answer

Solution code:
n = int(input()) // 2
ns = list(map(int, input().split()))

n = 200000
ns = [i for i in range(n)]

a = [ns[i] for i in range(len(ns)) if i % 2 == 0]
b = [ns[i] for i in range(len(ns)) if i % 2 == 1]
sa = set(a)
sb = set(b)
#ca = sorted([(a.count(s), s) for s in sa])[::-1]
#cb = sorted([(b.count(s), s) for s in sb])[::-1]  # [(出た回数, num)]
# countが遅かったので
da = {}
db = {}
for s in sa:
    da[s] = da.get(s, 0) + 1
for s in sb:
    db[s] = db.get(s, 0) + 1
ca = sorted([(v, k) for k, v in da.items()])
cb = sorted([(v, k) for k, v in db.items()])[::-1]

if ca[0][1] != cb[0][1]:
    print(n-ca[0][0] + n-cb[0][0])
else:
    if len(ca) == 1 and len(cb) == 1:
        print(n)
    elif len(ca) == 1:
        print(n-ca[0][0] + n-cb[1][0])
    else:
        print(n-ca[1][0] + n-cb[0][0])