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()))

# 全要素が同じとき
if len(set(v)) == 1:
    print(len(v)//2)
    exit()

v_even = v[::2]
v_odd = v[1::2]

c_even = collections.Counter(v_even)
n_v_even_majority = c_even.most_common()[0][1]
c_odd = collections.Counter(v_odd)
n_v_odd_majority = c_odd.most_common()[0][1]

# 最頻要素が同じとき
if c_even.most_common()[0][0] == c_odd.most_common()[0][0]:
    if len(set(v_even)) > 1:
        print(n - c_even.most_common()[1][1] - n_v_odd_majority)
    elif len(set(v_odd)) > 1:
        print(n - n_v_even_majority - c_odd.most_common()[1][1])
    else:
        print(0)
else:
    print(n - n_v_even_majority - n_v_odd_majority)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

counter = Counter(v)
ans = 0
if len(counter.most_common())!=1:
  max_common = counter.most_common()[0][1]
  second_max_common = counter.most_common()[1][1]
  ans = ((n/2)-max_common)+ ((n/2)-second_max_common)
else:
  ans = n/2
print ans

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):
        if odd.get(V[i],None)==None:
            odd[V[i]]=1
        else:
            odd[V[i]]+=1
    else:
        if even.get(V[i],None)==None:
            even[V[i]]=1
        else:
            even[V[i]]+=1


max_odd_k = max(odd, key=odd.get)
max_even_k = max(even, key=even.get)
max_odd_v = max(odd.values())
max_even_v = max(even.values())
len_odd = len(odd)
len_even = len(even)

if(max_odd_k!=max_even_k):
    print(N-max_odd_v-max_even_v)
    exit()

if((len_odd==1)&(len_even==1)):
    print(N//2)
    exit()


if(len_odd==1):
    del even[max_even_k]
    max_even_k = max(even, key=even.get)
    max_even_v = max(even.values())
    print(N-max_odd_v-max_even_v)
    exit()

if(len_even==1):
    del odd[max_odd_k]
    max_odd_k = max(odd, key=odd.get)
    max_odd_v = max(odd.values())
    print(N-max_odd_v-max_even_v)
    exit()

#print()

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):
        if odd.get(V[i],None)==None:
            odd[V[i]]=1
        else:
            odd[V[i]]+=1
    else:
        if even.get(V[i],None)==None:
            even[V[i]]=1
        else:
            even[V[i]]+=1


max_odd_k = max(odd, key=odd.get)
max_even_k = max(even, key=even.get)
max_odd_v = max(odd.values())
max_even_v = max(even.values())
len_odd = len(odd)
len_even = len(even)

if(max_odd_k!=max_even_k):
    print(N-max_odd_v-max_even_v)
    exit()

if((len_odd==1)&(len_even==1)):
    print(N//2)
    exit()


if(len_odd==1):
    del even[max_even_k]
    max_even_k = max(even, key=even.get)
    max_even_v = max(even.values())
    print(N-max_odd_v-max_even_v)
    exit()

if(len_even==1):
    del odd[max_odd_k]
    max_odd_k = max(odd, key=even.get)
    max_odd_v = max(odd.values())
    print(N-max_odd_v-max_even_v)
    exit()

#print()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
odd = collections.Counter(v[0::2]).most_common()
even = collections.Counter(v[1::2]).most_common()
if odd[0][0] != even[0][0]:
    print(n - odd[0][1] - even[0][1])
else:
    if len(odd) == 1 and len(even) == 1:
        print(n / 2)
    elif len(odd) == 1 and len(even) != 1:
        print(n - even[1][1])
    elif len(even) == 1 and len(odd) != 1:
        print(n - odd[1][1])
    else:
        print(n - max(odd[0][1] + even[1][1], odd[1][1] + even[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import heapq

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

if len(set(Vs)) == 1:
  print(N//2)
  exit()

Veve, Vodd = [],[]
idx = 0
for v in Vs:
  if idx%2 == 0: Veve.append(v)
  else: Vodd.append(v)
  idx += 1

Veve_cnt, Vodd_cnt = [], []
[heapq.heappush(Veve_cnt, [-num,val]) for val, num in Counter(Veve).items()]
[heapq.heappush(Vodd_cnt, [-num,val]) for val, num in Counter(Vodd).items()]

neg_num, val = heapq.heappop(Veve_cnt)
eve_val = val
eve_num = -neg_num

neg_num, val = heapq.heappop(Vodd_cnt)
odd_val = val
odd_num = -neg_num

if eve_val != odd_val:
  print(N-eve_num-odd_num)
else:
  if len(Vodd_cnt) != 0:odd_num2 = -heapq.heappop(Vodd_cnt)[0]
  else:odd_num2 = float('inf')

  if len(Veve_cnt) != 0:eve_num2 = -heapq.heappop(Veve_cnt)[0]
  else:eve_num2 = float('inf')

  print(max(N-eve_num2-odd_num,N-eve_num-odd_num2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import heapq

N = int(input())
Vs = list(map(int,input().split()))
if len(set(Vs)) == 1:
  print(N//2)
  exit()

Veve, Vodd = [],[]
idx = 0
for v in Vs:
  if idx%2 == 0: Veve.append(v)
  else: Vodd.append(v)
  idx += 1

Veve_cnt, Vodd_cnt = [], []
[heapq.heappush(Veve_cnt, [-num,val]) for val, num in Counter(Veve).items()]
[heapq.heappush(Vodd_cnt, [-num,val]) for val, num in Counter(Vodd).items()]

neg_num, val = heapq.heappop(Veve_cnt)
eve_val = val
eve_num = -neg_num

neg_num, val = heapq.heappop(Vodd_cnt)
odd_val = val
odd_num = -neg_num

while eve_val == odd_val:
  if eve_num > odd_num:
    neg_num, val = heapq.heappop(Vodd_cnt)
    odd_val = val
    odd_num = -neg_num
  else:
    neg_num, val = heapq.heappop(Veve_cnt)
    eve_val = val
    eve_num = -neg_num
  #print(eve_val, odd_val, Veve_cnt)
print(N-eve_num-odd_num)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import heapq

N = int(input())

if str(N)[0]*len(str(N)) == str(N):
  print(N//2)
  exit()

Veve, Vodd = [],[]
idx = 0
for v in map(int,input().split()):
  if idx%2 == 0: Veve.append(v)
  else: Vodd.append(v)
  idx += 1

Veve_cnt, Vodd_cnt = [], []
[heapq.heappush(Veve_cnt, [-num,val]) for val, num in Counter(Veve).items()]
[heapq.heappush(Vodd_cnt, [-num,val]) for val, num in Counter(Vodd).items()]

eve_val, odd_val = None, None
while eve_val == odd_val:
  if eve_val is None:
    neg_num, val = heapq.heappop(Veve_cnt)
    eve_val = val
    eve_num = -neg_num
  if odd_val is None:
    neg_num, val = heapq.heappop(Vodd_cnt)
    odd_val = val
    odd_num = -neg_num
print(N-eve_num-odd_num)

Submission status: Wrong Answer

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

Vo=V[::2]
Ve=V[1::2]

oddmost = collections.Counter(Vo).most_common()[0][1]
evenmost = collections.Counter(Ve).most_common()[0][1]

print(len(Vo)-oddmost+len(Ve)-evenmost)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import operator
N = int(input())
V = list(map(int,input().split()))
D1 = defaultdict(int)
D2 = defaultdict(int)
for i in range(N//2):
    D1[V[2*i]] += 1
    D2[V[2*i+1]] += 1
D1 = sorted(D1.items(), key=operator.itemgetter(1))
D2 = sorted(D2.items(), key=operator.itemgetter(1))
D1.append((0,0))
D2.append((0,0))
if D1[0][0] != D2[0][0]:
    ans = N - (D1[0][1] + D2[0][1])
    print(ans)
else:
    a = N - (D1[0][1] + D2[1][1])
    b = N - (D1[1][1] + D2[0][1])
    ans = min(a,b)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import operator
N = int(input())
V = list(map(int,input().split()))
D1 = defaultdict(int)
D2 = defaultdict(int)
for i in range(N//2):
    D1[V[2*i]] += 1
    D2[V[2*i+1]] += 1
D1 = sorted(D1.items(), key=operator.itemgetter(1))
D2 = sorted(D2.items(), key=operator.itemgetter(1))
D1.append((-1,0))
D2.append((-1,0))
if D1[0][0] != D2[0][0]:
    ans = N - (D1[0][1] + D2[0][1])
else:
    a = N - (D1[0][1] + D2[1][1])
    b = N - (D1[1][1] + D2[0][1])
    ans = min(a,b)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import operator

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

for i in range(N//2):
    D1[V[2*i]] += 1
    D2[V[2*i+1]] += 1
D1 = sorted(D1.items(), key=operator.itemgetter(1))
D2 = sorted(D2.items(), key=operator.itemgetter(1))
D1.append((-1,0))
D2.append((-1,0))


if D1[0][0] != D2[0][0]:
    ans = N - (D1[0][1] + D2[0][1])
else:
    a = D1[0][1] + D2[1][1]
    b = D1[1][1] + D2[0][1]
    if a > b:
        ans = N-a
    else:
        ans = N-b
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import operator

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

for i in range(N//2):
    D1[V[2*i]] += 1
    D2[V[2*i+1]] += 1
D1 = sorted(D1.items(), key=operator.itemgetter(1))
D2 = sorted(D2.items(), key=operator.itemgetter(1))
D1.append((-1,0))
D2.append((-1,0))


if D1[0][0] != D2[0][0]:
    ans = N - (D1[0][1] + D2[0][1])
else:
    if D1[0][1] >= D2[0][1]:
        ans = N-(D1[0][1] + D2[1][1])
    else:
        ans = N-(D1[1][1] + D2[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(0)
  exit()
cov = collections.Counter(v[1::2])
cev = collections.Counter(v[::2])
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
ans = len(v) - cov[mov] - cev[mev]

if mov == mev:
  ans1 = len(v) - cov.most_common()[1][1] - cev.most_common()[0][1]
  ans2 = len(v) - cov.most_common()[0][1] - cev.most_common()[1][1]
  ans = min(ans1, ans2)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(0)
  exit()
ov = [v[i] for i in range(1,len(v),2)]
ev = [v[i] for i in range(0, len(v), 2)]

cov = collections.Counter(ov)
cev = collections.Counter(ev)
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
ans = len(v) - cov[mov] - cev[mev]

if mov == mev:
  ans1 = len(v) - cov.most_common()[1][1] - cev.most_common()[0][1]
  ans2 = len(v) - cov.most_common()[0][1] - cev.most_common()[1][1]
  ans = min(ans1, ans2)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  exit()
ov = [v[i] for i in range(1,len(v),2)]
ev = [v[i] for i in range(0, len(v), 2)]

cov = collections.Counter(ov)
cev = collections.Counter(ev)
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
ans = len(v) - cov[mov] - cev[mev]

if mov == mev:
  ans1 = len(v) - cov.most_common()[1][1] - cev.most_common()[0][1]
  ans2 = len(v) - cov.most_common()[0][1] - cev.most_common()[1][1]
  ans = min(ans1, ans2)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  exit()
ov = [v[i] for i in range(1,len(v),2)]
ev = [v[i] for i in range(0, len(v), 2)]

cov = collections.Counter(ov)
cev = collections.Counter(ev)
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
if mov == mev:
  if cov[mov] == cev[mev]:
    if cev.most_common()[1][1] > cov.most_common()[1][1]:
      mev = cev.most_common()[1][0]
    else:
      mov = cov.most_common()[1][0]
  elif cov[mov] > cev[mev]:
    mev = cev.most_common()[1][0]
  else:
    mov = cov.most_common()[1][0]
ans = len(v) - cov[mov] - cev[mev]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  exit()
ov = [v[i] for i in range(1,len(v),2)]
ev = [v[i] for i in range(0, len(v), 2)]

cov = collections.Counter(ov)
cev = collections.Counter(ev)
mov = cov.most_common()[0][0]
mev = cev.most_common()[0][0]
if mov == mev:
  if cov[mov] > cev[mev]:
    mev = cev.most_common()[1][0]
  else:
    mov = cov.most_common()[1][0]
ans = len(v) - cov[mov] - cev[mev]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  exit()
ov = [v[i] for i in range(1,len(v),2)]
ev = [v[i] for i in range(0, len(v), 2)]

cov = collections.Counter(ov)
cev = collections.Counter(ev)
mov = max(cov)
mev = max(cev)
if mov == mev:
  if cov[mov] > cev[mev]:
    mev = cev.most_common()[1]
  else:
    mov = cov.most_common()[1]
ans = len(v) - cov[mov] - cev[mev]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v1 = sorted(Counter(v[::2]).items(), key=lambda x: x[1])
v2 = sorted(Counter(v[1::2]).items(), key=lambda x: x[1])
v1.append((0, 0))
v2.append((0, 0))
if v1[0][0] != v2[0][0]:
    print(n - v1[0][1] - v2[0][1])
else:
    print(min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
v1 = sorted(Counter(v[::2]).items(), key=lambda x: x[1])
v2 = sorted(Counter(v[1::2]).items(), key=lambda x: x[1])

if v1[0][0] != v2[0][0]:
    print(n - v1[0][1] - v2[0][1])
else:
    if len(v1) == 1 and len(v2) == 1:
        print(n // 2)
    elif len(v1) == 1:
        print(n - v1[0][1] - v2[1][1])
    elif len(v2) == 1:
        print(n - v1[1][1] - v2[0][1])
    else:
        print(min(n - v1[0][1] - v2[1][1], n - v1[1][1] - v2[0][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
v_list = list(map(int, input().split()))
count1 = [[0, i] for i in range(10**5)]
count2 = [[0, i] for i in range(10**5)]  # [v-1][数, 数値]

for i in range(0, n, 2):
    count1[v_list[i]-1][0] += 1
    count2[v_list[i+1]-1][0] += 1

count1 = sorted(count1)[::-1]
count2 = sorted(count2)[::-1]
if count1[0][1] == count2[0][1]:
    if count1[0][0] > count2[0][0]:
        ans = n - count1[0][0] - count2[1][0]
    elif count1[0][0] < count2[0][0]:
        ans = n - count2[0][0] - count1[1][0]
    else:
        ans = max(n - count2[0][0] - count1[1][0], n - count1[0][0] - count2[1][0])
else:
    ans = n - count1[0][0] - count2[0][0]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v_list = list(map(int, input().split()))
count1 = [[0, i] for i in range(10**5)]
count2 = [[0, i] for i in range(10**5)]  # [v-1][数, 数値]

for i in range(0, n, 2):
    count1[v_list[i]-1][0] += 1
    count2[v_list[i+1]-1][0] += 1

count1 = sorted(count1)[::-1]
count2 = sorted(count2)[::-1]
if count1[0][1] == count2[0][1]:
    if count1[0][0] >= count2[0][0]:
        ans = n - count1[0][0] - count2[1][0]
    else:
        ans = n - count2[0][0] - count1[1][0]
else:
    ans = n - count1[0][0] - count2[0][0]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v_list = list(map(int, input().split()))
v1 = [0]*(n//2)
v2 = [0]*(n//2)

for i in range(0, n, 2):
    v1[i//2] = v_list[i]
    v2[i//2] = v_list[i+1]

for w in Counter(v2).most_common(1):
    a = n//2-w[1]
    
for x in Counter(v1).most_common(1):
    b = n//2-x[1]
if  w[0]== x[0]:
    print(n//2)
else:
    print(a+b)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v_list = list(map(int, input().split()))
v1 = [0]*(n//2)
v2 = [0]*(n//2)

for i in range(0, n, 2):
    v1[i//2] = v_list[i]
    v2[i//2] = v_list[i+1]

for w in Counter(v2).most_common(1):
    a = n//2-w[1]
    
for w in Counter(v1).most_common(1):
    b = n//2-w[1]
if a == b:
    print(n//2)
else:
    print(a+b)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int, input().split()))
from collections import Counter
dic_odd = Counter(V[::2])
dic_even = Counter(V[1::2])
max_odd = max(dic_odd.values())
sum_odd = sum(dic_odd.values())
ch_max_odd = [key for key, val in dic_odd.items() if val == max_odd]
max_even = max(dic_even.values())
sum_even = sum(dic_even.values())
ch_max_even = [key for key, val in dic_even.items() if val == max_even]


if len(ch_max_odd) == 1  and  ch_max_odd == ch_max_even:
  num_odd_val = list(dic_odd.values())
  num_odd_val = num_odd_val.remove(max_odd)
  if num_odd_val == None:
    max_odd_2nd = 0
  else:
    max_odd_2nd = max(num_odd_val)
  num_even_val = list(dic_even.values()).remove(max_even)
  if num_even_val == None:
    max_even_2nd = 0
  else:
    max_even_2nd = max(num_even_val)  
  print(min(sum_odd - max_odd_2nd + sum_even - max_even,
        sum_odd - max_odd_2nd + sum_even - max_even_2nd))
else:
  print(sum_odd - max_odd + sum_even - max_even)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
cnt = 0
for i in range(2,len(v)):
    if v[i-2] != v[i]:
        v[i] = v[i-2]
        cnt+=1
d = list(set(v))
if len(d) == 1:
    cnt  =len(v)//2
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
cnt = 0
for i in range(2,len(v)):
    if v[i-2] != v[i]:
        v[i] = v[i-2]
        cnt+=1
d =list(set(v))
if len(d) == 1:
    cnt = 2
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
cnt = 0
for i in range(2,len(v)):
    if v[i-2] != v[i]:
        cnt+=1
d =list(set(v))
if len(d) == 1:
    cnt = 2
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int,input().split()))
V1 = V[::2]
V2 = V[1::2]
V1_s = list(set(V1))
V2_s = list(set(V2))
S1 = len(V1_s)
S2 = len(V2_s)
if S1 == 1 and S2 == 1:
  if V1[0] != V2[0]:
    print(0)
  else:
    print(len(V) // 2)
else:
  V1_l = [0] * ((10 ** 5) + 1)
  V2_l = [0] * ((10 ** 5) + 1)
  for i in range(N // 2):
    V1_l[V1[i]] += 1
  for i in range(N // 2):
    V2_l[V2[i]] += 1
  S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
  S2_MAX = [V2_l.index(max(V2_l)),max(V2_l)]
  if S1_MAX[0] != S2_MAX[0]:
    print(N - S1_MAX[1] - S2_MAX[1])
  else:
    if S1_MAX[1] > S2_MAX[1]:
      V2_l.pop(S2_MAX[0])
      S2_MAX = [V2_l.index(max(V2_l)),max(V2_l)]
      print(N - S1_MAX[1] - S2_MAX[1])
    else:
      V1_l.pop(S1_MAX[0])
      S1_MAX = [V1_l.index(max(V1_l)),max(V1_l)]
      print(N - S1_MAX[1] - S2_MAX[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int,input().split()))
V1 = V[::2]
V2 = V[1::2]
V1_s = list(set(V1))
V2_s = list(set(V2))
S1 = len(V1_s)
S2 = len(V2_s)
if S1 == 1 and S2 == 1:
  if V1[0] != V2[0]:
    print(0)
  else:
    print(len(V) // 2)
else:
  V1_l = [0] * ((10 ** 5) + 1)
  V2_l = [0] * ((10 ** 5) + 1)
  for i in range(N // 2):
    V1_l[V1[i]] += 1
  for i in range(N // 2):
    V2_l[V2[i]] += 1
  tmp = 0
  ans = 0
  for i in range(S1):
    tmp = max(tmp,V1_l[V1_s[i]])
  ans += len(V1) - tmp
  tmp = 0
  for i in range(S2):
    tmp = max(tmp,V2_l[V2_s[i]])
  ans += len(V2) - tmp
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
even_dic = {}
odd_dic = {}
for i in range(0, n, 2):
    if v[i] in even_dic:
        even_dic[v[i]] += 1
    else:
        even_dic[v[i]] = 1
    if v[i + 1] in odd_dic:
        odd_dic[v[i + 1]] += 1
    else:
        odd_dic[v[i + 1]] = 1
even_list = []
for k, v in even_dic.items():
    tmp = [k, v]
    even_list.append(tmp)
odd_list = []
for k, v in odd_dic.items():
    tmp = [k, v]
    odd_list.append(tmp)
even_list.sort(key=lambda x: x[1], reverse=True)
odd_list.sort(key=lambda x: x[1], reverse=True)
if even_list[0][0] == odd_list[0][0]:
    if len(even_list) == 1 and len(odd_list) == 1:
        print(n // 2)
    elif len(even_list) == 1 and len(odd_list) != 1:
        print(n // 2 - odd_list[1][1])
    elif len(even_list) != 1 and len(odd_list) == 1:
        print(n // 2 - even_list[1][1])
    else:
        min(n - even_list[0][1] - odd_list[1][1], n - even_list[1][1] - odd_list[0][1])
else:
    print(n - even_list[0][1] - odd_list[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()]
even_dic = {}
odd_dic = {}
for i in range(0, n, 2):
    if v[i] in even_dic:
        even_dic[v[i]] += 1
    else:
        even_dic[v[i]] = 1
    if v[i + 1] in odd_dic:
        odd_dic[v[i + 1]] += 1
    else:
        odd_dic[v[i + 1]] = 1
even_list = []
for k, v in even_dic.items():
    tmp = [k, v]
    even_list.append(tmp)
odd_list = []
for k, v in odd_dic.items():
    tmp = [k, v]
    odd_list.append(tmp)
even_list.sort(key=lambda x: x[1], reverse=True)
odd_list.sort(key=lambda x: x[1], reverse=True)
if even_list[0][0] == odd_list[0][0]:
    if len(even_list) == 1 and len(odd_list) == 1:
        print(n // 2)
    elif len(even_list) == 1 and len(odd_list) != 1:
        print(n - even_list[0][1] - odd_list[1][1])
    elif len(even_list) != 1 and len(odd_list) == 1:
        print(n - even_list[1][1] - odd_list[0][1])
    else:
        min(n - even_list[0][1] - odd_list[1][1], n - even_list[1][1] - odd_list[0][1])
else:
    print(n - even_list[0][1] - odd_list[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

evn = Counter(V[0::2])
odd = Counter(V[1::2])

em = evn.most_common(1)[0]
om = odd.most_common(1)[0]


def f(d, val):
    res = 0
    for elem, amount in d.items():
        if elem == val:
            continue
        res += amount
    return res


ans = 0
if em[0] != om[0]:
    ans += f(evn, em[0])
    ans += f(odd, om[0])
else:
    if em[1] > om[1]:
        if len(odd) < 2:
            ans += om[1]
        else:
            ans += f(odd, odd.most_common()[1][0])
        ans += f(evn, em[0])
    else:
        if len(evn) < 2:
            ans += em[1]
        else:
            ans += f(evn, evn.most_common()[1][0])
        ans += f(odd, om[0])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline


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

    if len(set(A))==1:
        print(n//2)
        return
    
    ans = n
    d_1 = defaultdict(int)
    for i in range(0, n, 2):
        d_1[A[i]] += 1
    d_2 = defaultdict(int)
    for i in range(1, n, 2):
        d_2[A[i]] += 1

    print(ans - max(d_1.values()) - max(d_2.values()))
    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
V = list(map(int, input().split()))
S1 = Counter([V[i] for i in range(0, N, 2)])
S2 = Counter([V[i] for i in range(1, N, 2)])

S1 = sorted(S1.items(), key=lambda x: x[1], reverse=True)
S2 = sorted(S2.items(), key=lambda x: x[1], reverse=True)

if S1[0][0] == S2[0][0]:
    if S1[0][1] > S2[0][1]:
        ans = sum([i[1] for i in S1[1:]])
        ans += S2[0][1] + sum([i[1] for i in S2[2:]])
    else:
        ans = sum([i[1] for i in S2[1:]])
        ans += S1[0][1] + sum([i[1] for i in S1[2:]])
else:
    ans = sum([i[1] for i in S1[1:]])
    ans += sum([i[1] for i in S2[1:]])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
a_tmp = set(a)
if len(a_tmp) == 1:
    print(N//2)
    exit()
kisu = []
guu = []
for i in range(N):
    if i %2 ==0:
        guu.append(a[i])
    else:
        kisu.append(a[i])
kisu_c = collections.Counter(kisu)
guu_c = collections.Counter(guu)

kisu_max = kisu_c.most_common()[0][0]
guu_max = guu_c.most_common()[0][0]

if kisu_max == guu_max:
    tmp = len(a)-kisu.count(kisu_c.most_common()[0][0])-guu.count(guu_c.most_common()[1][0])
    tmp2 = len(a)-kisu.count(kisu_c.most_common()[0][0])-guu.count(guu_c.most_common()[1][0])
    if tmp < tmp2:
        print(tmp)
    else:
        print(tmp2)
    exit()

print(len(a)-kisu.count(kisu_max)-guu.count(guu_max))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
a_tmp = set(a)
if len(a_tmp) == 1:
    print(N//2)
    exit()
kisu = []
guu = []
for i in range(N):
    if i %2 ==0:
        guu.append(a[i])
    else:
        kisu.append(a[i])
kisu_c = collections.Counter(kisu)
guu_c = collections.Counter(guu)

kisu_max = kisu_c.most_common()[0][0]
guu_max = guu_c.most_common()[0][0]

# if kisu_max == guu_max:
#     if kisu_c.most_common()[0][1] <= guu_c.most_common()[0][1]:
#         kisu_max = kisu_c.most_common()[1][0]
#     else:
#         guu_max = guu_c.most_common()[1][0]
print(len(a)-kisu.count(kisu_max)-guu.count(guu_max))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
a_tmp = set(a)
if len(a_tmp) == 1:
    print(N//2)
    exit()
kisu = []
guu = []
for i in range(N):
    if i %2 ==0:
        guu.append(a[i])
    else:
        kisu.append(a[i])
kisu_c = collections.Counter(kisu)
guu_c = collections.Counter(guu)

kisu_max = kisu_c.most_common()[0][0]
guu_max = guu_c.most_common()[0][0]

if kisu_max == guu_max:
    if kisu_c.most_common()[0][1] <= guu_c.most_common()[0][1]:
        kisu_max = kisu_c.most_common()[1][0]
    else:
        guu_max = guu_c.most_common()[1][0]
print(len(a)-kisu.count(kisu_max)-guu.count(guu_max))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
a_tmp = set(a)
if len(a_tmp) == 1:
    print(N//2)
    exit()
kisu = []
guu = []
for i in range(N):
    if i %2 ==0:
        guu.append(a[i])
    else:
        kisu.append(a[i])
kisu_c = collections.Counter(kisu)
guu_c = collections.Counter(guu)
kisu_tmp = set(kisu)
guu_tmp = set(guu)
print(len(kisu)-kisu.count(kisu_c.most_common()[0][0])+len(guu)-guu.count(guu_c.most_common()[0][0]))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

ki=[0]*100001
gu=[0]*100001

for i in range(n):
    if i%2==0:
        ki[l[i]]+=1
    else:
        gu[l[i]]+=1
km1=[max(ki),ki.index(max(ki))]
km2=[sorted(ki)[-2],ki.index(sorted(ki)[-2])]
gm1=[max(gu),gu.index(max(gu))]
gm2=[sorted(gu)[-2],gu.index(sorted(gu)[-2])]

if km1[1]!=gm1[1]:
    print(n-km1[0]-gm1[0])
else:
    if km1[1]-km2[1]>=gm1[1]-gm2[1]:
        print(n-km1[0]-gm2[0])
    else:
        print(n-gm1[0]-km2[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
count1 = 0
count2 = 0
count = 0
dict_1 = dict()
dict_2 = dict()
max1 = 0
max2 = 0
check = True
ans = 0
for i in range(n):
    if i != (n-1):
        if v[i] != v[i+1]:
            check = False
    if i % 2 == 0:
        if v[i] in dict_1:
            dict_1[v[i]] += 1
        else:
            dict_1[v[i]] = 1
            count1 += 1
        if dict_1[v[i]] > max1:
            max1 = dict_1[v[i]]
    else:
        if v[i] in dict_2:
            dict_2[v[i]] += 1
        else:
            dict_2[v[i]] = 1
            count2 += 1
        if dict_2[v[i]] > max2:
            max2 = dict_2[v[i]]

if count1 > 1:
    ans += (n/2) - max1
if count2 > 1:
    ans += (n/2) - max2
if check:
    print(int(n/2))
else:
    print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections  import Counter
n = int(input())
l = [int(i) for i in input().split()]

l1 = [l[i] for i in range(n) if i%2 ==0]
l2 = [l[i] for i in range(n) if i%2 ==1]

c1 = Counter(l1)
c2 = Counter(l2)
ans = 0
ans += (n//2 - c1.most_common()[0][1]) + (n//2 - c2.most_common()[0][1])

if c1.most_common()[0][0] == c2.most_common()[0][0]:
    print(ans + len(l2))
else:
    print(ans)

Submission status: Wrong Answer

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

if l[0] != l[1]:
    ct = 0 
else:
    ct = 1
    l[1] = -1
for i in range(len(l)-2):
    if l[i] == l[i+2]:
        pass
    else:
        ct += 1

print(ct)

Submission status: Wrong Answer

Solution code:
import sys

def mode(list1):
    dic = {}
    for n in list1:
        if n in dic:
            dic[n] += 1
        else:
            dic[n] = 1
    max1 = 0
    num1  = -1
    for key in dic:
        if max1 < dic[key]:
            max1 = dic[key] 
            num1 = key

    max2 = 0
    num2 = -1
    for key in dic:
        if key == num1:
            continue
        if max2 < dic[key]:
            max2 = dic[key] 
            num2 = key
    return max1,num1,max2,num2

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

if min(vlist) == max(vlist):
    print(n//2)
    sys.exit()

alist=[]
blist=[]
for i in range(n//2):
    alist.append(vlist[2*i])
    blist.append(vlist[2*i+1])

amax,ka,amax2,ka2 = mode(alist)
bmax,kb,bmax2,kb2 = mode(blist)

if ka != kb:
    ans = n - amax - bmax
else:
    if amax2 >= bmax2:
        ans =n - amax -bmax2
    else:
        ans =n - bmax -amax2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys

N = int(input())
li = list(map(int,input().split()))
even = [li[i] for i in range(N) if i%2==0]
odd =[ li[i] for i in range(N) if i%2!=0]

e = collections.Counter(even).most_common()
o = collections.Counter(odd).most_common()

if e==o:
  print(len(even))
  sys.exit()
ec=e[0][1]
oc=o[0][1]

if e[0][0]==o[0][0]:
  if e[0][1] > o[0][1]:
    oc=o[1][1]
  else:
    ec=e[1][1]
    
ans = N-(ec+oc)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

if evens_c[0][0] != odds_c[0][0]:
    print(n - evens_c[0][1] - odds_c[0][1])
    exit()

cands = []

if len(evens_c) > 1 and evens_c[1][0] != odds_c[0][0]:
    cands.append(n - evens_c[1][1] - odds_c[0][1])
if len(odds_c) > 1 and evens_c[0][0] != odds_c[1][0]:
    cands.append(n - evens_c[0][1] - odds_c[1][1])

cands.append(n // 2)

print(min(cands))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

odds = []
evens = []

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

evens_c = Counter(evens).most_common()
odds_c = Counter(odds).most_common()

if evens_c[0][0] != odds_c[0][0]:
    print(n - evens_c[0][1] - odds_c[0][1])
    exit()

cands = []

if len(evens_c) > 1 and evens_c[1][0] != odds_c[0][0]:
    cands.append(n - evens_c[1][1] - odds_c[0][1])
if len(odds_c) > 1 and evens_c[0][0] != odds_c[1][0]:
    cands.append(n - evens_c[0][1] - odds_c[1][1])

cands.append(n // 2)

print(max(cands))