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 collections import Counter
n = int(input())
V = list(map(int, input().split()))

E = V[0::2]
O = V[1::2]
EC = Counter(E).most_common()
OC = Counter(O).most_common()
#Counterは"出現文字，回数"の順番
if len(EC) ==1 and len(OC) == 1:
  if EC[0][0] == OC[0][0]:
    print(n//2)
    exit()
  else:
    print(0)
    exit()
elif len(EC) == 1 and len(OC) > 1:
  if EC[0][0] == OC[0][0]:
    print(len(OC) - OC[1][1])
    exit()
  else:
    print(len(OC) - OC[0][1])
    exit()
elif len(EC) > 1 and len(OC) == 1:
  if EC[0][0] == OC[0][0]:
    print(len(EC) - EC[1][1])
    exit()
  else:
    print(len(EC) - EC[0][1])
    exit()
else:
  if EC[0][0] != OC[0][0]:
    print(len(EC)-EC[0][1] + len(OC) - OC[0][1])
    exit()
  else:
    if EC[1][1] > OC[1][1]:
      print(len(EC) -EC[1][1] + len(OC)-OC[0][1])
      exit()
    else:
      print(len(EC)-EC[0][1] + len(OC) - OC[1][1])
      exit()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
ls = list(map(int,input().split()))
lso = ls[::2]
lse = ls[1::2]
lso.sort()
lse.sort(reverse=True)
co = Counter(lso)
ce = Counter(lse)
co1,co2 = co.most_common()[0][0],co.most_common()[0][1]
ce1,ce2 = ce.most_common()[0][0],ce.most_common()[0][1]
if co1 == ce1:
    print(len(ls)-max(co2,ce2))
else:
    print(len(ls)-co2-ce2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
ls = list(map(int,input().split()))
lso = ls[::2]
lse = ls[1::2]
co = Counter(lso)
ce = Counter(lse)
co1,co2 = co.most_common()[0][0],co.most_common()[0][1]
ce1,ce2 = ce.most_common()[0][0],ce.most_common()[0][1]
if co1 == ce1:
    print(len(ls)-max(co2,ce2))
else:
    print(len(ls)-co2-ce2)

Submission status: Wrong Answer

Solution code:
n = int(input())
vl = list(map(int,input().split()))
v1 = vl[::2]
v2 = vl[1::2]
v1d = dict()
v2d = dict()
for a1 in v1:
  if a1 in v1d:
    v1d[a1] += 1
  else:
    v1d[a1] = 1
for a2 in v2:
  if a2 in v2d:
    v2d[a2] += 1
  else:
    v2d[a2] = 1
v1s = sorted(v1d.items(), key=lambda x:x[1],reverse=True)
v2s = sorted(v2d.items(), key=lambda x:x[1],reverse=True)
if len(v1s) == len(v2s) == 1:
  if v1s[0][0] == v2s[0][0]:
    print(v1s[0][1])
  else:
    print(0)
elif v1s[0][0] != v2s[0][0]:
  print(n-v1s[0][1]-v2s[0][1])
elif v1s[0][1] > v2s[0][1]:
  print(n-v1s[0][1]-v2s[1][1])
else:
  print(n-v1s[1][1]-v2s[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
vl = list(map(int,input().split()))
v1 = vl[::2]
v2 = vl[1::2]
v1d = dict()
v2d = dict()
for a1 in v1:
  if a1 in v1d:
    v1d[a1] += 1
  else:
    v1d[a1] = 1
for a2 in v2:
  if a2 in v2d:
    v2d[a2] += 1
  else:
    v2d[a2] = 1
v1s = sorted(v1d.items(), key=lambda x:x[1],reverse=True)
v2s = sorted(v2d.items(), key=lambda x:x[1],reverse=True)
if len(v1s) == len(v2s) == 1:
  if v1s[0][0] == v2s[0][0]:
    print(v1s[0][1])
  else:
    print(0)
elif v1s[0][0] != v2s[0][0]:
  print(n-v1s[0][1]-v2s[0][1])

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_list = []
    one_list = []
    for i in range(n):
        if i % 2 == 0:
            zero_list.append(num_list[i])
        else:
            one_list.append(num_list[i])

    zero_c = Counter(zero_list)
    one_c = Counter(one_list)

    zero_saihin_key = zero_c.most_common()[0][0]
    zero_saihin_val = zero_c.most_common()[0][1]
    one_saihin_key = zero_c.most_common()[0][0]
    one_saihin_val = one_c.most_common()[0][1]

    if zero_saihin_key != one_saihin_key:
        print(n - zero_saihin_val - one_saihin_val)
        exit()

    if num_list.count(zero_saihin_key) == n:
        print(n//2)
        exit()

    if len(zero_c) == 1:
        zero_saihin_val2 = 0
    else:
        zero_saihin_val2 = zero_c.most_common()[1][1]

    if len(one_c) == 1:
        one_saihin_val2 = 0
    else:
        one_saihin_val2 = one_c.most_common()[1][1]

    count1 = n - zero_saihin_val - one_saihin_val2
    count2 = n - zero_saihin_val2 - one_saihin_val

    print(min(count1, count2))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_list = []
    one_list = []
    for i in range(n):
        if i % 2 == 0:
            zero_list.append(num_list[i])
        else:
            one_list.append(num_list[i])

    zero_c = Counter(zero_list)
    one_c = Counter(one_list)

    zero_saihin_key = zero_c.most_common()[0][0]
    zero_saihin_val = zero_c.most_common()[0][1]
    one_saihin_key = zero_c.most_common()[0][0]
    one_saihin_val = one_c.most_common()[0][1]

    if zero_saihin_key != one_saihin_key:
        print(n - zero_saihin_val - one_saihin_val)
        exit()

    if num_list.count(zero_saihin_key) == n:
        print(n//2)
        exit()

    zero_f = False
    one_f = False

    if len(zero_c) == 1:
        zero_saihin_val2 = zero_saihin_val
        zero_f = True
    else:
        zero_saihin_val2 = zero_c.most_common()[1][1]

    if len(one_c) == 1:
        one_saihin_val2 = one_saihin_val
        one_f = True
    else:
        one_saihin_val2 = one_c.most_common()[1][1]

    count1 = n - zero_saihin_val - one_saihin_val2
    count2 = n - zero_saihin_val2 - one_saihin_val

    if zero_f:
        print(count2)
    elif one_f:
        print(count1)
    else:
        print(min(count1, count2))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_list = []
    one_list = []
    for i in range(n):
        if i % 2 == 0:
            zero_list.append(num_list[i])
        else:
            one_list.append(num_list[i])

    zero_c = Counter(zero_list)
    one_c = Counter(one_list)

    zero_saihin_key = zero_c.most_common()[0][0]
    zero_saihin_val = zero_c.most_common()[0][1]
    one_saihin_key = zero_c.most_common()[0][0]
    one_saihin_val = one_c.most_common()[0][1]

    if zero_saihin_key != one_saihin_key:
        print(n - zero_saihin_val - one_saihin_val)
        exit()

    if num_list.count(zero_saihin_key) == n:
        print(n//2)
        exit()

    if len(zero_c) == 1:
        zero_saihin_val2 = zero_saihin_val
    else:
        zero_saihin_val2 = zero_c.most_common()[1][1]

    if len(one_c) == 1:
        one_saihin_val2 = one_saihin_val
    else:
        one_saihin_val2 = one_c.most_common()[1][1]

    count1 = n - zero_saihin_val - one_saihin_val2
    count2 = n - zero_saihin_val2 - one_saihin_val

    print(min(count1, count2))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_list = []
    one_list = []
    for i in range(n):
        if i % 2 == 0:
            zero_list.append(num_list[i])
        else:
            one_list.append(num_list[i])

    zero_c = Counter(zero_list)
    one_c = Counter(one_list)

    zero_saihin_key = zero_c.most_common()[0][0]
    zero_saihin_val = zero_c.most_common()[0][1]
    one_saihin_key = zero_c.most_common()[0][0]
    one_saihin_val = one_c.most_common()[0][1]

    if zero_saihin_key != one_saihin_key:
        print(n - zero_saihin_val - one_saihin_val)
        exit()

    if num_list.count(zero_saihin_key) == n:
        print(n//2)
        exit()

    if len(zero_c) != n // 2:
        zero_saihin_val2 = zero_saihin_val
    else:
        zero_saihin_val2 = zero_c.most_common()[1][1]

    if len(one_c) != n // 2:
        one_saihin_val2 = one_saihin_val
    else:
        one_saihin_val2 = one_c.most_common()[1][1]

    count1 = n - zero_saihin_val - one_saihin_val2
    count2 = n - zero_saihin_val2 - one_saihin_val

    print(min(count1, count2))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
vs=list(map(int,input().split()))
xs=vs[0::2]
ys=vs[1::2]
cx=Counter(xs).most_common()
cy=Counter(ys).most_common()
if len(cx)==1:
    cx.append((0,0))
if len(cy)==1:
    cy.append((-1,0))
if not cx[0][0]==cy[0][0]:
    print(len(xs)-cx[0][1]+len(ys)-cy[0][1])
else:
    mx=len(xs)-cx[1][1]
    my=len(ys)-cy[1][1]
    print(min(mx,my))

Submission status: Wrong Answer

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

vx = [[None] * (n // 2), [None] * (n // 2)]
for i in range(n):
    vx[i%2][i//2] = v[i]

a = sorted([(n, vx[0].count(n)) for n in set(vx[0])], key=lambda x: x[1])
b = sorted([(n, vx[1].count(n)) for n in set(vx[1])], key=lambda x: x[1])

if a[0][0] != b[0][0]:
    ans = n - (a[0][1] + b[0][1])
else:
    if len(a) == 1:
        a.append((-1, 0))
    if len(b) == 1:
        b.append((-1, 0))

    ans = min(n - (a[0][1] + b[1][1]), n - (a[1][1] + b[0][1]))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

d1 = defaultdict(int)
d2 = defaultdict(int)
for i, v in enumerate(V):
    if i % 2 == 0:
        d1[v] += 1
    else:
        d2[v] += 1
d1 = sorted(d1.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
d2 = sorted(d2.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

if d1[0][1] < d2[0][1]:
    d1, d2 = d2, d1

ans = N // 2 - d1[0][1]
val = d1[-1][0]
if d2[0][0] != val:
    ans += N // 2 - d2[0][1]
else:
    ans += d2[0][1]
    if 2 < len(d2):
        ans += N // 2 - d2[0][1] - d2[1][1]
print(ans)

Submission status: Wrong Answer

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

x = [vs[0], None]

for i in range(1, n, 2):
    if vs[0] != vs[i]:
        x[1] = vs[i]
        break
else:
    x[1] = -1

cnt = 0
for i in range(2, n):
    if x[i%2] != -1:
        if x[i%2] != vs[i]:
            cnt += 1

if x[1] == -1:
    print(cnt + n // 2)
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
import operator

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

P = set(S)
if len(P) == 1:
    print(int(len(S) / 2))
elif len(P) == 2:
    print(0)
else:
    res = {}
    for p in P:
        res[p] = S.count(p)
    count = 2

    while count > 0:
        m = max(res.items(), key=operator.itemgetter(1))[0]
        n = n - res[m]
        del res[m]
        count -= 1
    
    print(n)

Submission status: Wrong Answer

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

x = [vs[0], None]

for i in range(1, n, 2):
    if vs[0] != vs[i]:
        x[1] = vs[i]
        break
else:
    x[1] = vs[0]


cnt = 0
for i in range(2, n):
    if x[i%2] != vs[i]:
        cnt += 1

if x[0] == x[1]:
    print(cnt + n // 2)
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

d1 = defaultdict(int)
d2 = defaultdict(int)
for i, v in enumerate(V):
    if i % 2 == 0:
        d1[v] += 1
    else:
        d2[v] += 1
d1 = sorted(d1.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
d2 = sorted(d2.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

ans = 0
if d1[0][0] == d2[0][0]:
    if d1[0][1] < d2[0][1]:
        if 2 <= len(d1):
            ans += N // 2 - d1[1][1]
        else:
            ans += d1[0][1]
    else:
        if 2 <= len(d2):
            ans += N // 2 - d2[1][1]
        else:
            ans += d2[0][1]
else:
    ans += N - d1[0][1] - d2[0][1]
print(ans)

Submission status: Wrong Answer

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


a = set()
b = set()

for i in range(n):
    if i % 2 == 0:
        a.add(vs[i])
    else:
        b.add(vs[i])

if len(a & b) == 1:
    print(2)
else:
    print((len(a) - 1) + (len(b) - 1))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = [int(n) for n in input().split()]

c = len(set(V))

if c == 3:
    print(1)
elif c == 4:
    print(2)
elif c == 1:
    print(2)
elif c == 2:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
import collections
c = collections.Counter(v)
c1 = collections.Counter(v1)
c2 = collections.Counter(v2)
z1 = list(set(v1))
z2 = list(set(v2))
x1 = []
x2 = []
for i in range(len(z1)):
    x1.append([z1[i], c1[z1[i]]])
for i in range(len(z2)):
    x2.append([z2[i], c2[z2[i]]])
x1.sort(key= lambda val : val[1],reverse=True)
x2.sort(key= lambda val : val[1],reverse=True)
x1.append([-1,x1[0][1]])
x2.append([-1,x2[0][1]])
ans = 0
if x1[0][0] == x2[0][0]:
    if x1[0][1] > x2[0][1]:
        ans = n - x1[0][1] - x2[1][1]
    elif x1[0][1] > x2[0][1]:
        ans = n - x1[1][1] - x2[0][1]
    else:
        if x1[1][1] >= x2[1][1]:
            ans = n - x1[1][1]
        else:
            ans = n - x2[1][1]
else:
    ans = n - x1[0][1] - x2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

if len(set(V)) == 1:
    print(n // 2)
    exit()

d0, d1 = defaultdict(int), defaultdict(int)

for i, v in enumerate(V):
    if i % 2 == 0:
        d0[v] += 1
    else:
        d1[v] += 1

d0_ = sorted(d0.items(), key=lambda x: -x[1])
d1_ = sorted(d1.items(), key=lambda x: -x[1])

a0, n0 = d0_[0]
a1, n1 = d1_[0]

if a0 != a1:
    ans = n - n0 - n1
else:
    if n0 > n1:
        m1 = d1_[1][1]
        ans = n - n0 - m1
    else:
        m0 = d0_[1][1]
        ans = n - m0 - n1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

if len(set(V)) == 1:
    print(n // 2)
    exit()

d0, d1 = defaultdict(int), defaultdict(int)

for i, v in enumerate(V):
    if i % 2 == 0:
        d0[v] += 1
    else:
        d1[v] += 1

d0_ = sorted(d0.items(), key=lambda x: -x[1])
d1_ = sorted(d1.items(), key=lambda x: -x[1])

a0, n0 = d0_[0]
a1, n1 = d1_[0]

if a0 != a1:
    ans = n - n0 - n1
else:
    if len(d0_) == 1 or len(d1_) == 1:
        ans = n // 2 - min(n0, n1)
    else:
        _, m0 = d0_[1]
        _, m1 = d1_[1]
        if n0 > n1:
            ans = n - n0 - m1
        else:
            ans = n - m0 - n1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

def main():
    n = int(input())
    v = list(map(str, input().split()))

    c1 = collections.Counter(v[0::2])
    c2 = collections.Counter(v[1::2])
    
    def most(c, x, y):
        return c.most_common()[x][y]
    
    if most(c1, 0, 1) == most(c2, 0, 1) == n//2 and most(c1, 0, 0) == most(c2, 0, 0):
        print(n // 2)
    elif most(c1, 0, 0) != most(c2, 0, 0):
        print(n - most(c1, 0, 1)- most(c2, 0, 1))
    else:
            a  = n - most(c1, 1, 1)- most(c2, 0, 1)
            b  = n - most(c1, 0, 1)- most(c2, 1, 1)
            print(max(a, b))
         
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c1 = Counter(v[::2]).most_common() + [(0, 0)]
c2 = Counter(v[1::2]).most_common() + [(0, 0)]

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
else:
    if c1[0][1] > c2[0][1]:
        ans = n - c1[0][1] - c2[1][1]
    else:
        ans = n - c1[1][1] - c2[0][1]

print(ans)

Submission status: Wrong Answer

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

first = {}
second = {}

for x in range(N):
    if x % 2 == 0:
        first.setdefault(v[x], 0)
        first[v[x]] += 1
    else:
        second.setdefault(v[x], 0)
        second[v[x]] += 1

first_sorted = sorted(first.items(), key=lambda x: x[1], reverse=True)
second_sorted = sorted(second.items(), key=lambda x: x[1], reverse=True)
sum_change = 0

first_value = 0
for y in range(len(first_sorted)):
    if y == 0:
        first_value = first_sorted[y][0]
    if y != 0:
        sum_change += first_sorted[y][1]

for z in range(len(second_sorted)):
    if first_value != second_sorted[0][0]:
        if z != 0:
            sum_change += second_sorted[z][1]
    else:
        if z != 1:
            sum_change += second_sorted[z][1]

print(sum_change)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = [int(i) for i in input().split()]
if len(set(v)) == 1:
    print(n//2)
    exit()
even = defaultdict(int)
odd = defaultdict(int)
for i in range(n):
    if i % 2 == 0: even[v[i]] += 1
    else: odd[v[i]] += 1
print(n-max(list(even.values()))-max(list(odd.values())))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
 
n = INT()
v = LIST()

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

ans1 = len(v1) - Counter(v1).most_common()[0][1]

if Counter(v1).most_common()[0][0] != Counter(v2).most_common()[0][0]:
	ans2 = len(v2) - Counter(v2).most_common()[0][1]
else:
	if len(Counter(v2).most_common()) == 1:
		ans2 = Counter(v2).most_common()[0][1]
	else:
		ans2 = len(v1) - Counter(v1).most_common()[1][1]

print(ans1 + ans2)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(input())
V = list(map(int, sys.stdin.readline().rsplit()))

Ceven = Counter(V[::2])
Codd = Counter(V[1::2])

evenM = max(Ceven.items(), key=lambda x: x[1])
oddM = max(Codd.items(), key=lambda x: x[1])

if evenM[0] == oddM[0]:
    res = min(oddM[1], evenM[1])
else:
    res = len(V) - (oddM[1] + evenM[1])
print(res)

Submission status: Wrong Answer

Solution code:
import sys, heapq, bisect, math, fractions
from collections import deque
from collections import Counter
from collections import OrderedDict

N = int(input())
V = list(map(int, sys.stdin.readline().rsplit()))

Ceven = Counter(V[::2])
Codd = Counter(V[1::2])

evenM = max(Ceven.items())
oddM = max(Codd.items())

if evenM[0] == oddM[0]:
    res = min(oddM[1], evenM[1])
else:
    res = len(V) - (oddM[1] + evenM[1])
print(res)

Submission status: Wrong Answer

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

odd = []
even = []
for i, v in enumerate(V):
    if i % 2 == 0:
        odd.append(v)
    else:
        even.append(v)
num_odd = {}
for v in odd:
    if v in num_odd:
        num_odd[v] += 1
    else:
        num_odd[v] = 1
num_even = {}
for v in even:
    if v in num_even:
        num_even[v] += 1
    else:
        num_even[v] = 1
val_odd = sorted(num_odd.items(), key=lambda x:x[1])
val_even = sorted(num_even.items(), key=lambda x:x[1])
if len(val_odd) == 1 and len(val_even) == 1:
    if val_odd[0][0] == val_even[0][0]:
        # 全部同じ値 -> 半分変化させる
        print(n // 2)
    else:
        # すでに整ってる
        print(0)
else:
    # 奇数・偶数ともに必要なだけ変化させる
    if val_odd[-1][0] != val_even[-1][0]:
        # 最も多い値が違う場合はそれぞれその値を増やせばいい
        count_odd = n // 2 - val_even[-1][1]
        count_even = n // 2 - val_odd[-1][1]
        print(count_odd + count_even)
    else:
        # 同じ場合は、少ない方の第二頻出値を増やす
        if val_odd[-1][1] > val_even[-1][1]:
            val_max, val_min = val_odd, val_even
        else:
            val_max, val_min = val_even, val_odd
        count_max = n // 2 - val_max[-1][1]
        count_min = n // 2 - val_min[-2][1]
        print(count_max + count_min)

Submission status: Wrong Answer

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

odd = []
even = []
for i, v in enumerate(V):
    if i % 2 == 0:
        odd.append(v)
    else:
        even.append(v)
num_odd = {}
for v in odd:
    if v in num_odd:
        num_odd[v] += 1
    else:
        num_odd[v] = 1
num_even = {}
for v in even:
    if v in num_even:
        num_even[v] += 1
    else:
        num_even[v] = 1
val_odd = sorted(num_odd.items(), key=lambda x:x[1])
val_even = sorted(num_even.items(), key=lambda x:x[1])
if len(val_odd) == 1 and len(val_even) == 1:
    if val_odd[0][0] == val_even[0][0]:
        # 全部同じ値 -> 半分変化させる
        print(n // 2)
    else:
        # すでに整ってる
        print(0)
else:
    # 奇数・偶数ともに必要なだけ変化させる
    count_odd = n // 2 - val_even[-1][1]
    count_even = n // 2 - val_odd[-1][1]
    print(count_odd + count_even)

Submission status: Wrong Answer

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

numbers = {}
for v in V:
    if v in numbers:
        numbers[v] += 1
    else:
        numbers[v] = 1
values = sorted(numbers.items(), key=lambda x:x[1])
values = [[v[0], v[1]] for v in values]
count = 0
if len(values) == 1:
    # 1種類しか値がないので、半分を書き換える
    print(n // 2)
else:
    # 2種類になるまで出現数の少ない値を書き換える
    for i, n in values[:-2]:
        values[-2][1] += n
        if values[-2][1] > values[-2][1]:
            values[-1], values[-2] = values[-2], values[-1]
        count += n
    n1 = values[-1][1]
    n2 = values[-2][1]
    # 残りの2種類で出現数に差がある場合は一番多いものから変化させる
    count += (n1 - n2) // 2
    print(count)

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
lisA = list(map(int,input().split()))

kv1 = Counter(lisA[0:N:2]).most_common()
kv2 = Counter(lisA[1:N:2]).most_common()

if len(kv1)==len(kv2)==1 and kv1[0]==kv2[0]:
    print(N//2)
    exit()

ans1 = N
ans2 = N
for i in range(0,N//2-1):
    try:
        if kv1[0][0]!=kv2[i][0]:
            ans1 = min(ans1,N-(kv1[0][1]+kv2[i][1]))
        if kv1[i][0]!=kv2[0][0]:
            ans2 = min(ans1,N-(kv1[i][1]+kv2[0][1]))
    except:
        pass

print(min(ans1,ans2))
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
lisA = list(map(int,input().split()))

kv1 = Counter(lisA[0:N:2]).most_common()
kv2 = Counter(lisA[1:N:2]).most_common()

if len(kv1)==len(kv2)==1 and kv1[0]==kv2[0]:
    print(N//2)
    exit()

print(kv1,kv2)
ans1 = N
ans2 = N
for i in range(0,N//2-1):
    try:
        if kv1[0][0]!=kv2[i][0]:
            ans1 = min(ans1,N-(kv1[0][1]+kv2[i][1]))
        if kv1[i][0]!=kv2[0][0]:
            ans2 = min(ans1,N-(kv1[i][1]+kv2[0][1]))
    except:
        pass

print(min(ans1,ans2))
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
a = []
b = []
for i in range(n):
    if i % 2 == 0:
        a.append(v[i])
    else:
        b.append(v[i])
a.sort()
b.sort()
counta = 1
maxam = -1
maxa = 0
max2a = 0
countb = 1
maxbm = -1
maxb = 0
max2b = 0
for i in range(1,n//2):
    if a[i] == a[i-1]:
        counta+=1
    else:
        if maxa != 0 and counta > maxa:
            max2a = maxa
            maxa = counta
            maxam = a[i-1]
        elif maxa != 0 and counta > max2a:
            max2a = counta
        counta = 1
    if b[i] == b[i-1]:
        countb+=1
    else:
        if maxb != 0 and countb > maxb:
            max2b = maxb
            maxb = countb
            maxbm = b[i-1]
        elif maxb != 0 and countb > max2b:
            max2b = countb
        countb = 1
if counta > maxa:
    max2a = maxa
    maxa = counta
    maxam = a[-1]
elif countb > max2a:
    max2a = counta
if countb > maxb:
    max2b = maxb
    maxb = countb
    maxbm = b[-1]
elif countb > max2b:
    max2b = countb
if maxam == maxbm:
    print(min(n-maxa-max2b,n-max2a-maxb))
else:
    print(n-maxa-maxb)