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
import sys
import numpy as np
sys.setrecursionlimit(1000000000)

#入力
n = int(input())
v = list(map(int,input().split()))
#解答
p = []
q = []
for i in range(2,n,2):
    p.append(v[i])
for i in range(1,n,2):
    q.append(v[i])
cnt1 = collections.Counter(p)
cnt2 = collections.Counter(q)
pli = []
qli = []
valmax1,valmax2 = -11,-11
for key,value in cnt1.items():
    pli.append([key,value])
    valmax1 = max(valmax1,value)
for key,value in cnt2.items():
    qli.append([key,value])
    valmax2 = max(valmax2,value)
for i in range(len(pli)):
    if valmax1 == pli[i][1]:
        check1 = pli[i][0]
koho = []
for i in range(len(qli)):
    if valmax2 == qli[i][1]:
        koho.append(qli[i][0])
check2 = -1
for i in range(len(koho)):
    if koho[i] != check1:
        check2 = koho[i]
        break
if check2 == -1:
    print(n//2)
    sys.exit()
ans = 0
for i in range(len(p)):
    if check1 != p[i]:
        ans += 1
for i in range(len(q)):
    if check2 != q[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)

#入力
n = int(input())
v = list(map(int,input().split()))
#解答
p = []
q = []
for i in range(2,n,2):
    p.append(v[i])
for i in range(1,n,2):
    q.append(v[i])
cnt1 = collections.Counter(p)
cnt2 = collections.Counter(q)
pli = []
qli = []
valmax1,valmax2 = -11,-11
for key,value in cnt1.items():
    pli.append([key,value])
    valmax1 = max(valmax1,value)
for key,value in cnt2.items():
    qli.append([key,value])
    valmax2 = max(valmax2,value)

for i in range(len(pli)):
    if valmax1 == pli[i][1]:
        check1 = pli[i][0]
koho = []
for i in range(len(qli)):
    if valmax2 == qli[i][1]:
        koho.append(qli[i][0])

check2 = -1
for i in range(len(koho)):
    if koho[i] == check1:
        continue
    else:
        check2 = koho[i]
if check2 == -1:
    print(n//2)
    sys.exit()
ans = 0
for i in range(len(p)):
    if check1 != p[i]:
        ans += 1

for i in range(len(q)):
    if check2 != q[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
v = list(map(int,input().split()))
p = []
q = []
ans = 0
for i in range(0,n,2):
    p.append(v[i])
for i in range(1,n,2):
    q.append(v[i])
ans = collections.Counter(p)
ans2 = collections.Counter(q)
ansl = []
ans2l = []
maxv = 0
for key,value in ans.items():
    ansl.append([key,value])
    maxv = max(maxv,value)
maxv2 = 0
for key,value in ans2.items():
    ans2l.append([key,value])
    maxv2 = max(maxv2,value)
for i in range(len(ansl)):
    if ansl[i][1] == maxv:
        check1 = ansl[i][0]
check2 = -1
koho = []
for i in range(len(ans2l)):
    if ans2l[i][1] == maxv2:
        koho.append(ans2l[i][0])
check2 = -1
for i in range(len(koho)):
    if check1 != koho[i]:
        check2 = koho[i]
        break
if check2 == -1:
    print(n//2)
    sys.exit()
#答え
cnt = 0
for i in range(len(p)):
    if p[i] != check1:
        cnt+=1
for i in range(len(q)):
    if q[i] != check2:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
v = list(map(int,input().split()))
p = []
q = []
ans = 0
for i in range(0,n,2):
    p.append(v[i])
for i in range(1,n,2):
    q.append(v[i])
ans = collections.Counter(p)
ans2 = collections.Counter(q)
ansl = []
ans2l = []
maxv = 0
for key,value in ans.items():
    ansl.append([key,value])
    maxv = max(maxv,value)
maxv2 = 0
for key,value in ans2.items():
    ans2l.append([key,value])
    maxv2 = max(maxv2,value)
for i in range(len(ansl)):
    if ansl[i][1] == maxv:
        check1 = ansl[i][0]
check2 = -1
koho = []
for i in range(len(ans2l)):
    if ans2l[i][1] == maxv2:
        koho.append(ans2l[i][0])
for i in range(len(koho)):
    if check1 != koho[i]:
        check2 = koho[i]
    else:
        check2 = -1
if check2 == -1:
    print(n//2)
    sys.exit()
#答え
cnt = 0
for i in range(len(p)):
    if p[i] != check1:
        cnt+=1
for i in range(len(q)):
    if q[i] != check2:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

if len(set(lst)) == 1:
    print(n//2)
else:
    a = lst[0:n:2]
    b = lst[1:n:2]

    acnt = Counter(a)
    bcnt = Counter(b)

    amax = acnt.most_common()[0]
    bmax = bcnt.most_common()[0]
    if amax[0] != bmax[0]:
        print((n//2 - amax[1]) + (n// - bmax[1]))
    else:
        try:
            asecond = acnt.most_common()[1]
        except:
            asecond = (-1, 0)
        try:
            bsecond = bcnt.most_common()[1]
        except:
            bsecond = (-1, 0)
        res1 = (n//2 - amax[1]) + (n//2 - bsecond[1])
        res2 = (n//2 - asecond[1]) + (n//2 - bmax[1])
        print(min([res1, res2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [i for i in map(int, input().split())]
v_e, v_o = v[0::2], v[1::2]
cnt_e, cnt_o = Counter(v_e), Counter(v_o)
val_e, val_o = list(cnt_e.values()), list(cnt_o.values())
val_e.sort()
val_o.sort()
val_e, val_o = val_e[::-1], val_o[::-1]
cnt_e = sorted(cnt_e.items(), key=lambda x:x[1])[::-1]
cnt_o = sorted(cnt_o.items(), key=lambda x:x[1])[::-1]
key_e, key_o = cnt_e[0][0], cnt_o[0][0]
if key_e == key_o:
    if len(val_e) == len(val_o) == 1:
        print(n // 2)
    elif len(val_e) == 1:
        print(n // 2 - val_o[1])
    elif len(val_o) == 1:
        print(n // 2 - val_e[1])
    else:
        if val_e[0] > val_o[0]:
            print(n - val_e[0] - val_o[1])
        else:
            print(n - val_e[1] - val_o[0])
else:
    if len(val_e) == len(val_o) == 1:
        print(0)
    elif len(val_e) == 1:
        print(n // 2 - val_o[0])
    elif len(val_o) == 1:
        print(n // 2 - val_e[0])
    else:
        print(n - val_o[0] - val_e[0])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [i for i in map(int, input().split())]
v_e, v_o = v[0::2], v[1::2]
cnt_e, cnt_o = Counter(v_e), Counter(v_o)
val_e, val_o = list(cnt_e.values()), list(cnt_o.values())
val_e.sort()
val_o.sort()
val_e, val_o = val_e[::-1], val_o[::-1]
cnt_e = sorted(cnt_e.items(), key=lambda x:x[1])[::-1]
cnt_o = sorted(cnt_o.items(), key=lambda x:x[1])[::-1]
key_e, key_o = cnt_e[0][0], cnt_o[0][0]
if key_e == key_o:
    if len(val_e) == len(val_o) == 1:
        print(n // 2)
    elif len(val_e) == 1:
        print(n // 2 - val_o[1])
    elif len(val_o) == 1:
        print(n // 2 - val_e[1])
    else:
        if val_e[0] > val_o[0]:
            print(n - val_e[0] - val_o[1])
        else:
            print(n - val_e[1] - val_e[0])
else:
    if len(val_e) == len(val_o) == 1:
        print(0)
    elif len(val_e) == 1:
        print(n // 2 - val_o[0])
    elif len(val_o) == 1:
        print(n // 2 - val_e[0])
    else:
        print(n - val_o[0] - val_e[0])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

V_even = Counter(V[::2])
V_odd = Counter(V[1::2])

ans = 0

if len(set(V)) == 1:
  ans = n//2
else:
  ans += (n//2)-V_odd.most_common()[0][1]
  ans += (n//2)-V_even.most_common()[0][1]

print(ans)

Submission status: Wrong Answer

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

first=Counter(v[::2])
next=Counter(v[1::2])

ans  =0
#f != n
if first.most_common()[0][0] != next.most_common()[0][1]:
  for i,j in first.items():
    if i == first.most_common()[0][0]:
      continue
    
    ans += j
  for k,l in next.items():
    if k == next.most_common()[0][0]:
      continue
    
    ans += l
  print(ans)
  exit()
  
  
ans1=0
ans2=0
#f ==n
if first.most_common()[0][0] != next.most_common()[0][1]:
#f(1) and n(2)
  for i,j in first.items():
    if i == first.most_common()[0][0]:
      continue
    
    ans1 += j
  for k,l in next.items():
    if k == next.most_common()[1][0]:
      continue
    
    ans1 += l
  
  
  for i,j in first.items():
    if i == first.most_common()[1][0]:
      continue
    
    ans2 += j
  for k,l in next.items():
    if k == next.most_common()[1][0]:
      continue
    
    ans2 += l
 
print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [i for i in map(int, input().split())]
cnt = Counter(v)
if len(cnt) == 1:
    print(n//2)
    exit()
val = list(cnt.values())
val.sort()
val = val[::-1]
if len(val) == 2:
    print(abs(n//2 - val[0]))
    exit()
else:
    print(max(val[0] - n//2, 0) + sum(val[2:]))
    exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [i for i in map(int, input().split())]
cnt = Counter(v)
if len(cnt) == 1:
    print(n//2)
    exit()
val = list(cnt.values())
val.sort()
val = val[::-1]
if len(val) == 2:
    print(abs(n//2 - val[0]))
    exit()
else:
    print(val)
    print(max(val[0] - n//2, 0) + sum(val[2:]))
    exit()

Submission status: Wrong Answer

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

e = Counter(v[::2])
o = Counter(v[1::2])

ev = sorted([(k,i) for k, i in e.items()],key = lambda z:z[1],reverse = True) + [(0,0)]
od = sorted([(k,i) for k, i in o.items()],key = lambda z:z[1],reverse = True) + [(0,0)]

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

Submission status: Wrong Answer

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

o = Counter([v[i] for i in range(0,n,2)])
e = Counter([v[i] for i in range(1,n,2)])

if o == e:
    print(n//2)
    sys.exit()
elif len(o) == 1 and len(e) == 1:
    print(0)
    sys.exit()
    
odd = sorted([(i,v) for i, v in o.items()],key = lambda z:z[1],reverse = True)
even = sorted([(i,v) for i, v in e.items()],key = lambda z:z[1],reverse = True)

if odd[0][0] != even[0][0]:
    print((n//2 - odd[0][1]) + (n//2 - even[0][1]))

elif len(odd) == 1:
    print((n//2 - odd[0][1]) + (n//2 - even[1][1]))
elif len(even) == 1:
    print((n//2 - odd[1][1]) + (n//2 - even[0][1]))
else:
    print(min((n//2 - odd[1][1]) + (n//2 - even[0][1]), (n//2 - odd[0][1]) + (n//2 - even[1][1])))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v_1 = v[::2]
v_2 = v[1::2]

most_common1 = max(Counter(v_1))
most_common2 = max(Counter(v_2))

ans = 0
for i1, i2 in zip(v_1, v_2):
    if most_common1 != i1:
        ans += 1
    if most_common2 != i2:
        ans += 1

if most_common1 == most_common2:
    print(ans + 1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v_1 = v[::2]
v_2 = v[1::2]

most_common1 = max(Counter(v_1))
most_common2 = max(Counter(v_2))

ans = 0
for i1, i2 in zip(v_1, v_2):
    if most_common1 != i1:
        ans += 1
    if most_common2 != i2:
        ans += 1

if ans == 0 and most_common1 == most_common2:
    print(1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

n = int(input().strip())
v_list = list(map(int, input().rstrip().split()))
#-----

v_odd = [ v_list[i] for i in range(0,len(v_list),2) ]
v_even  = [ v_list[i] for i in range(1,len(v_list),2) ]

sort_cnt_v_odd  = sorted( Counter(v_odd).items(), key=lambda x:x[1], reverse=True)
sort_cnt_v_even = sorted(Counter(v_even).items(), key=lambda x:x[1], reverse=True)


ans=0
# カウント数最大の数値が、v_oddとv_evenで異なるとき
# v_oddとv_evenそれぞれを、1種類の数値に書き換え
if sort_cnt_v_odd[0][0] != sort_cnt_v_even[0][0]:
    ans +=  len(v_odd) -  sort_cnt_v_odd[0][1]
    ans += len(v_even) - sort_cnt_v_even[0][1]
else:
    # v_oddとv_evenそれぞれで、数値が1種類のとき
    # v_oddを全書き換え
    if len(sort_cnt_v_odd)==len(sort_cnt_v_even)==1:
        ans = len(v_odd) -  sort_cnt_v_odd[0][1]
        
    # v_oddの、数値が1種類のとき、v_evenは2番目に多いカウント数の数値に書き換え
    elif len(sort_cnt_v_odd)==1 and len(sort_cnt_v_even)!=1:
        ans =   len(v_odd) -  sort_cnt_v_odd[0][1] \
              + len(v_even) - sort_cnt_v_even[1][1]
        
    # v_evenの、数値が1種類のとき
    elif len(sort_cnt_v_odd)!=1 and len(sort_cnt_v_even)==1:
        ans =    len(v_odd) -  sort_cnt_v_odd[1][1] \
              + len(v_even) - sort_cnt_v_even[0][1]
        
    # 以下2パターンの少ない方を採用
    #   v_odd　 最大カウント数、v_even　2番目のカウント数
    #   v_even　最大カウント数、v_odd　 2番目のカウント数
    elif len(sort_cnt_v_odd)!=1 and len(sort_cnt_v_even)!=1:
        tmp1 =    len(v_odd) -   sort_cnt_v_odd[0][1] \
               + len(v_even) -  sort_cnt_v_even[1][1]
        
        tmp2 =    len(v_odd) -  sort_cnt_v_odd[1][1] \
               + len(v_even) - sort_cnt_v_even[0][1]
              
        ans = min(tmp1,tmp2)
        

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter

n = int(input().strip())
v_list = list(map(int, input().rstrip().split()))
#-----

v_odd = [ v_list[i] for i in range(0,len(v_list),2) ]
v_even  = [ v_list[i] for i in range(1,len(v_list),2) ]

sort_cnt_v_odd  = sorted( Counter(v_odd).items(), key=lambda x:x[1], reverse=True)
sort_cnt_v_even = sorted(Counter(v_even).items(), key=lambda x:x[1], reverse=True)


ans=0
# カウント数最大の数値が、v_oddとv_evenで異なるとき
# v_oddとv_evenそれぞれを、1種類の数値に書き換え
if sort_cnt_v_odd[0][0] != sort_cnt_v_even[0][0]:
    ans +=  len(v_odd) -  sort_cnt_v_odd[0][1]
    ans += len(v_even) - sort_cnt_v_even[0][1]
else:
    # v_oddとv_evenそれぞれで、数値が1種類のとき
    # v_oddを全書き換え
    if len(sort_cnt_v_odd)==len(sort_cnt_v_even)==1:
        ans = sort_cnt_v_odd[0][1]
        
    # v_oddの、数値が1種類のとき、v_evenは2番目に多いカウント数の数値に書き換え
    elif len(sort_cnt_v_odd)==1 and len(sort_cnt_v_even)!=1:
        ans = sort_cnt_v_odd[0][1] + sort_cnt_v_even[1][1]
        
    # v_evenの、数値が1種類のとき
    elif len(sort_cnt_v_odd)!=1 and len(sort_cnt_v_even)==1:
        ans = sort_cnt_v_odd[1][1] + sort_cnt_v_even[0][1]
        
    # 以下2パターンの少ない方を採用
    #   v_odd　 最大カウント数、v_even　2番目のカウント数
    #   v_even　最大カウント数、v_odd　 2番目のカウント数
    elif len(sort_cnt_v_odd)!=1 and len(sort_cnt_v_even)!=1:
        tmp1 = sort_cnt_v_odd[0][1] + sort_cnt_v_even[1][1]
        tmp2 = sort_cnt_v_odd[1][1] + sort_cnt_v_even[0][1]
        ans = min(tmp1,tmp2)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def solve(n, v):
    # すべて同じ値
    if len(set(v)) == 1:
        return len(v) / 2

    odd = []
    even = []

    for i, k in enumerate(v):
        if i % 2 == 0:
            even.append(k)
        else:
            odd.append(k)

    odd_dic = Counter(odd).most_common()
    even_dic = Counter(even).most_common()

    ans = 0

    if odd_dic[0][0] == even_dic[0][0]:
        if odd_dic[0][1] > even_dic[0][1]:
            odd_v = odd_dic[0][0]
            even_v = even_dic[1][0]
        elif odd_dic[0][1] < even_dic[0][1]:
            odd_v = odd_dic[1][0]
            even_v = even_dic[0][0]
        else:
            if odd_dic[1][1] >= even_dic[1][1]:
                odd_v = odd_dic[1][0]
                even_v = even_dic[0][0]
            else:
                odd_v = odd_dic[0][0]
                even_v = even_dic[1][0]
    else:
        odd_v = odd_dic[0][0]
        even_v = even_dic[0][0]

    for i in range(len(even)):
        if even_v != even[i]:
           ans += 1

        if odd_v != odd[i]:
            ans += 1

    return ans

def test():
    assert solve(4, [3, 1, 3, 2]) == 1
    assert solve(6, [105, 119, 105, 119, 105, 119]) == 0
    assert solve(4, [1, 1, 1, 1]) == 2

def main():
    n = int(input())
    v = list(map(int, input().split()))
    ans = solve(n, v)
    print(ans)

if __name__ == '__main__':
    # test()
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def solve(n, v):
    # すべて同じ値
    if len(set(v)) == 1:
        return len(v) / 2

    odd = []
    even = []

    for i, k in enumerate(v):
        if i % 2 == 0:
            even.append(k)
        else:
            odd.append(k)

    odd_dic = Counter(odd).most_common()
    even_dic = Counter(even).most_common()

    ans = 0

    if odd_dic[0][0] == even_dic[0][0]:
        if odd_dic[0][1] >= even_dic[0][1]:
            odd_v = odd_dic[0][0]
            even_v = even_dic[1][0]
        elif odd_dic[0][1] < even_dic[0][1]:
            odd_v = odd_dic[1][0]
            even_v = even_dic[0][0]
    else:
        odd_v = odd_dic[0][0]
        even_v = even_dic[0][0]

    for i in range(len(even)):
        if even_v != even[i]:
           ans += 1

        if odd_v != odd[i]:
            ans += 1

    return ans

def test():
    assert solve(4, [3, 1, 3, 2]) == 1
    assert solve(6, [105, 119, 105, 119, 105, 119]) == 0
    assert solve(4, [1, 1, 1, 1]) == 2

def main():
    n = int(input())
    v = list(map(int, input().split()))
    ans = solve(n, v)
    print(ans)

if __name__ == '__main__':
    # test()
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def solve(n, v):
    # すべて同じ値
    if len(set(v)) == 1:
        return len(v) / 2

    odd = []
    even = []

    for i, k in enumerate(v):
        if i % 2 == 0:
            even.append(k)
        else:
            odd.append(k)

    odd_dic = Counter(odd).most_common()
    even_dic = Counter(even).most_common()

    ans = 0

    if odd_dic[0][0] == even_dic[0][0]:
        if len(odd_dic) > 1:
            odd_v = odd_dic[1][0]
            even_v = even_dic[0][0]
        else:
            odd_v = odd_dic[0][0]
            even_v = even_dic[1][0]
    else:
        odd_v = odd_dic[0][0]
        even_v = even_dic[0][0]

    for i in range(len(even)):
        if even_v != even[i]:
           ans += 1

        if odd_v != odd[i]:
            ans += 1

    return ans

def test():
    assert solve(4, [3, 1, 3, 2]) == 1
    assert solve(6, [105, 119, 105, 119, 105, 119]) == 0
    assert solve(4, [1, 1, 1, 1]) == 2

def main():
    n = int(input())
    v = list(map(int, input().split()))
    ans = solve(n, v)
    print(ans)

if __name__ == '__main__':
    # test()
    main()

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  v = input_list()
  evens = []
  odds = []
  vs = v[:]
  kind = len(set(vs))
  if kind == 1:
    print(n//2)
    exit(0)
  
  for i, vv in enumerate(v):
    if i % 2 == 0:
      evens.append(vv)
    else:
      odds.append(vv)
  ec = collections.Counter(evens)
  oc = collections.Counter(odds)
  
  ans = 0
  em = ec.most_common()
  om = oc.most_common()
  if em[0][0] == om[0][0]:
    if em[0][1] > om[0][1]:
      om.pop(1)
      em.pop(0)
    else:
      om.pop(0)
      em.pop(1)
    for ek, ev in em:
      ans += ev
    for ok, ov in om:
      ans += ov
    print(ans)
  else:
    om.pop(0)
    em.pop(0)
    for ek, ev in em:
      ans += ev
    for ok, ov in om:
      ans += ov
    print(ans)
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
L = [i for i in map(int,input().split())]
U = L[0::2]
V = L[1::2]
L = len(U) + len(V)
from collections import Counter
oc_E2 = 0
oc_F2 = 0
A = Counter(U)
E1 = A.most_common(1)[0][0]
oc_E1 = A.most_common(1)[0][1]
C = Counter(V)
F1 = C.most_common(1)[0][0]
oc_F1 = C.most_common(1)[0][1]
if E1 != F1:
  print(L - oc_E1 - oc_F1)
  sys.exit(0)
else:
  L2 = [el for el in U if el != E1]
  oc_E2 = 0
  if L2 != []: 
    B = Counter(L2)
    E2 = B.most_common(1)[0][0]
    oc_E2 = B.most_common(1)[0][1]
  L3 = [el for el in V if el != F1]
  oc_F2 = 0
  if L3 != []:
    D = Counter(L3)
    F2 = D.most_common(1)[0][0]
    oc_F2 = D.most_common(1)[0][1]
if oc_E1 >= oc_F1:
  print(L-oc_E1-oc_F2)
else:
  print(L-oc_F1-oc_E2)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
L = [i for i in input().split()]
changed = 0
if len(set(L)) == 1:
  print(len(L) // 2)
  sys.exit(0)
for i in range(len(L)-2):
  if L[i] != L[i+2]:
    changed += 1
print(changed)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
L = [i for i in input().split()]
changed = 0
if len(set(L)) == 1:
  print(len(L) // 2)
  sys.exit(0)
for i in range(len(L)-2):
  if L[i] != L[i+2]:
    L[i+2] = L[i]
    changed += 1
print(changed)

Submission status: Wrong Answer

Solution code:
def main():
  n = int(input())
  v = input_list()
  evens = []
  odds = []
  vs = v[:]
  kind = len(set(vs))
  if kind == 1:
    print(n//2)
    exit(0)
  
  for i, vv in enumerate(v):
    if i % 2 == 0:
      evens.append(vv)
    else:
      odds.append(vv)
  ec = collections.Counter(evens)
  oc = collections.Counter(odds)
  
  ans = 0
  em = ec.most_common()
  em.pop(0)
  for ek, ev in em:
    ans += ev
  
  om = oc.most_common()
  om.pop(0)
  for ok, ov in om:
    ans += ov
  print(ans)
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

Submission status: Wrong Answer

Solution code:
import collections 

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

A=sorted(collections.Counter(L[0::2]))
B=sorted(collections.Counter(L[1::2]))
if len(A)==1 and len(B)==1:
	if A==B:
		print(len(L[1::2]))
	else:
		print(0)
elif len(A)==1 and len(B)>=2:
	if A==B[0]:
		print(L[1::2].count(B[0]))
	else:
		print(len(L[1::2])-(L[1::2].count(B[0])))
elif len(A)>=2 and len(B)==1:
	if A[0]==B:
		print(L[0::2].count(A[0]))
	else:
		print(len(L[0::2])-(L[0::2].count(A[0])))
elif len(A)>=2 and len(B)>=2:
	x=len(L[0::2])-L[0::2].count(A[0])
	y=len(L[1::2])-L[1::2].count(B[0])
	print(min(x,y))

Submission status: Wrong Answer

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

dl = {}
du = {}

for i in range(n):
  v = l[i]
  if i%2 == 0:
    if v in dl:
      dl[v] += 1
    else:
      dl[v] = 1
  else:
    if v in du:
      du[v] += 1
    else:
      du[v] = 1

if max(dl, key=dl.get) != max(du, key=du.get):
  ans = n - max(dl.values()) - max(du.values())
else:
  vsl = list(dl.values())
  vsl.sort(reverse=True)
  vsu = list(du.values())
  vsu.sort(reverse=True)
  if len(vsl) == 1 or len(vsu) == 1:
    ans = 10000
  else:
    ans = min(n-vsu[0]-vsl[1], n-vsl[0]-vsu[1])

print(ans)

Submission status: Wrong Answer

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

du = {}
dl = {}
for i in range(n):
    if i%2 == 0:
        if V[i] not in du:
            du[V[i]] = 1
        else:
            du[V[i]] += 1
    else:
        if V[i] not in dl:
            dl[V[i]] = 1
        else:
            dl[V[i]] += 1

l = list(dl.values())
u = list(du.values())
if len(u) == 1 and len(l) == 1 and len(set(V)) != 1:
    print(0)
    exit()
elif len(u) == 1 and len(l) == 1 and len(set(V)) == 1:
    print(n//2)
    exit()
else:
    pass

if max(du, key=du.get) != max(dl, key=dl.get):
    ans = n//2-max(u)+n//2-max(l)
else:
    if len(u) == 1:
        ans = n//2-max(u)+n//2-l[1]
    elif len(l) == 1:
        ans = n//2-max(l)+n//2-u[1]
    else:
        ans = min(n//2-max(l)+n//2-u[1], n//2-max(u)+n//2-l[1])
print(ans)

Submission status: Wrong Answer

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

du = {}
dl = {}
for i in range(n):
    if i%2 == 0:
        if V[i] not in du:
            du[V[i]] = 1
        else:
            du[V[i]] += 1
    else:
        if V[i] not in dl:
            dl[V[i]] = 1
        else:
            dl[V[i]] += 1

l = list(dl.values())
u = list(du.values())
if len(u) == 1 and len(l) == 1 and len(set(V)) != 1:
    print(0)
    exit()
elif len(u) == 1 and len(l) == 1 and len(set(V)) == 1:
    print(n//2)
    exit()
else:
    pass

if max(du, key=du.get) != max(dl, key=dl.get):
    ans = n//2-max(u)+n//2-max(l)
else:
    if len(u) == 1:
        ans = n//2-max(u)+n//2-l[1]
    elif len(l) == 1:
        ans - n//2-max(l)+n//2-u[1]
    else:
        ans = min(n//2-max(l)+n//2-u[1], n//2-max(u)+n//2-l[1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
evens, odds = {}, {}
for i, v in enumerate(list(map(int, input().split()))):
    if i % 2 == 0:
        if v in evens:
            evens[v] += 1
        else:
            evens[v] = 1
    else:
        if v in odds:
            odds[v] += 1
        else:
            odds[v] = 1
evens = sorted(evens.items(), key=lambda x: x[1], reverse=True)
odds = sorted(odds.items(), key=lambda x: x[1], reverse=True)
if len(evens) == 1 and len(odds) == 1:
    if evens[0][0] == odds[0][0]:
        print(n // 2)
    else:
        print(0)
else:
    if evens[0][0] == odds[0][0]:
        if len(evens) == 1:
            print(n // 2 - odds[1][0])
        elif len(odds) == 1:
            print(n // 2 - evens[1][0])
        else:
            print(n // 2 - evens[0][1] + n // 2 - odds[1][1])
    else:
        print(n // 2 - evens[0][1] + n // 2 - odds[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
evens, odds = {}, {}
for i, v in enumerate(list(map(int, input().split()))):
    if i % 2 == 0:
        if v in evens:
            evens[v] += 1
        else:
            evens[v] = 1
    else:
        if v in odds:
            odds[v] += 1
        else:
            odds[v] = 1
evens = sorted(evens.items(), key=lambda x: x[1], reverse=True)
odds = sorted(odds.items(), key=lambda x: x[1], reverse=True)
if len(evens) == 1 and len(odds) == 1:
    if evens[0][0] == odds[0][0]:
        print(n // 2)
    else:
        print(0)
else:
    if evens[0][0] == odds[0][0]:
        if len(evens) == 1:
            print(n / 2 - odds[1][0])
        elif len(odds) == 1:
            print(n / 2 - evens[1][0])
        else:
            print(n // 2 - evens[0][1] + n // 2 - odds[1][1])
    else:
        print(n // 2 - evens[0][1] + n // 2 - odds[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
evens, odds = {}, {}
for i, v in enumerate(list(map(int, input().split()))):
    if i % 2 == 0:
        if v in evens:
            evens[v] += 1
        else:
            evens[v] = 1
    else:
        if v in odds:
            odds[v] += 1
        else:
            odds[v] = 1
evens = sorted(evens.items(), key=lambda x: x[1], reverse=True)
odds = sorted(odds.items(), key=lambda x: x[1], reverse=True)
if len(evens) == 1 and len(odds) == 1:
    if evens[0][0] == odds[0][0]:
        print(n // 2)
    else:
        print(0)
else:
    if evens[0][0] == odds[0][0]:
        print(n // 2 - evens[0][1] + n // 2 - odds[1][1])
    else:
        print(n // 2 - evens[0][1] + n // 2 - odds[0][1])

Submission status: Wrong Answer

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

odds = v[1::2]
evens = v[::2]

o = Counter(odds)
e = Counter(evens)

omx, *ol = sorted(o.items(), reverse=True, key=lambda x: x[1])
emx, *el = sorted(e.items(), reverse=True, key=lambda x: x[1])

ans = 0
if omx[0] != emx[0]:
    ans += n - omx[1] - emx[1]
else:
    if omx[1] == n//2 or emx[1] == n//2:
        r = [ol, el][omx[1] > emx[1]]
        if r:
            ans += n//2 - r[0][1]
        else:
            ans += n//2
    else:
        if omx[1] > emx[1]:
            ans += n - omx[1] - el[0][1]
        else:
            ans += n - emx[1] - ol[0][1]


print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()] 

a1 = [0 for _ in range(n // 2)]
a2 = [0 for _ in range(n // 2)]
for i in range(n):
    if i % 2 == 0:
        a1[i // 2] = v[i]
    elif i % 2 == 1:
        a2[i // 2] = v[i]
#print(a1)
#print(a2)
tmp_a1 = Counter(a1)
tmp_a2 = Counter(a2)
#print(tmp_a1.most_common()[0][1] , tmp_a2.most_common()[0][1])
if tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0] and len(tmp_a1.most_common()) > 1 and len(tmp_a2.most_common()) > 1:
    ans = min(n - tmp_a1.most_common()[0][1] - tmp_a2.most_common()[1][1], n - tmp_a2.most_common()[0][1] - tmp_a1.most_common()[1][1])
if tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0] and (len(tmp_a1.most_common()) == 1 or len(tmp_a2.most_common()) == 1):
    ans = n // 2
else:
    ans = n - (tmp_a1.most_common()[0][1] + tmp_a2.most_common()[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()] 

a1 = [0 for _ in range(n // 2)]
a2 = [0 for _ in range(n // 2)]
for i in range(n):
    if i % 2 == 0:
        a1[i // 2] = v[i]
    elif i % 2 == 1:
        a2[i // 2] = v[i]
#print(a1)
#print(a2)
tmp_a1 = Counter(a1)
tmp_a2 = Counter(a2)
#print(tmp_a1.most_common()[0][1] , tmp_a2.most_common()[0][1])
#if a1 == a2:
#    ans = n // 2
if tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0] and len(tmp_a1.most_common()) > 1 and len(tmp_a2.most_common()) > 1:
    ans = min(tmp_a1.most_common()[0][1] + n // 2 - tmp_a2.most_common()[1][1], tmp_a2.most_common()[0][1] + n // 2 - tmp_a1.most_common()[1][1])
if tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0] and len(tmp_a1.most_common()) == 1 or len(tmp_a2.most_common()) == 1:
    ans = n // 2
else:
    ans = n - (tmp_a1.most_common()[0][1] + tmp_a2.most_common()[0][1])
print(ans)