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())
vlist=list(map(int,input().split()))

vlist1=[vlist[2*i] for i in range(n//2)]
vlist2=[vlist[2*i+1] for i in range(n//2)]
#print(vlist1)
#print(vlist2)

vc1=collections.Counter(vlist1).most_common()
vc2=collections.Counter(vlist2).most_common()
#print(vc1)
#print(vc2)

if vc1[0][0]!=vc2[0][0]:
  print(n-vc1[0][1]-vc2[0][1])
elif len(vc1)==1 and len(vc2)==1:
  print(n//2)
elif len(vc1)==1:
  print(n//2-vc2[1][1])
elif len(vc2)==1:
  print(n//2-vc1[1][1])
else:
  if vc1[0][1]>vc2[0][1]:
    print(n-vc1[0][1]-vc2[1][1])
  else:
    print(n-vc1[1][1]-vc2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)

max_odd = 0
max_even = 0
f_odd = 0
f_even = 0
s_odd = 0
s_even = 0

for i, v in enumerate(V):
    i += 1
    if i % 2 == 0:
        even[v] += 1
        if even[v] > max_even:
            max_even = even[v]
            if f_even != 0 and v != f_even:
                s_even = f_even
                f_even = v
            elif f_even == 0:
                f_even = v

    elif i % 2 == 1:
        odd[v] += 1
        if odd[v] > max_odd:
            max_odd = odd[v]
            if f_odd != 0 and v != f_odd:
                s_odd = f_odd
                f_odd = v
            elif f_odd == 0:
                f_odd = v

half = n / 2
cnt = 0

if f_odd != f_even:
    c1 = (half - max_odd) + (half - max_even)
    c2 = (half - max_even) + (half - max_odd)
    if c1 > c2:
        cnt = c2
    else:
        cnt = c1
elif f_odd == f_even:
    c1 = (half - max_odd) + (half - even[s_even])
    c2 = (half - max_even) + (half - odd[s_odd])
    if c1 > c2:
        cnt = c2
    else:
        cnt = c1

print(int(cnt))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)

max_odd = 0
max_even = 0
f_odd = 0
f_even = 0
s_odd = 0
s_even = 0

for i, v in enumerate(V):
    i += 1
    if i % 2 == 0:
        even[v] += 1
        if even[v] > max_even:
            max_even = even[v]
            if f_even != 0 and v != f_even:
                s_even = f_even
                f_even = v
            elif f_even == 0:
                f_even = v

    elif i % 2 == 1:
        odd[v] += 1
        if odd[v] > max_odd:
            max_odd = odd[v]
            if f_odd != 0 and v != f_odd:
                s_odd = f_odd
                f_odd = v
            elif f_odd == 0:
                f_odd = v

half = n / 2
cnt = 0

if max_odd > max_even:
    cnt += half - max_odd
    if f_odd != f_even:
        cnt += half - max_even
    else:
        cnt += half - even[s_even]
elif max_odd < max_even:
    cnt += half - max_even
    if f_odd != f_even:
        cnt += half - max_odd
    else:
        cnt += half - odd[s_odd]
else:
    if f_odd != f_even:
        cnt += half - max_even
        cnt += half - max_odd
    else:
        if odd[s_odd] > even[s_even]:
            cnt += half - max_even
            cnt += half - odd[s_odd]
        else:
            cnt += half - max_odd
            cnt += half - even[s_even]

print(int(cnt))
# print(odd, even)
# print(f'{max_odd}, {max_even}, {f_odd}, {s_odd}, {f_even}, {s_even}')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)

max_odd = 0
max_even = 0
f_odd = 0
f_even = 0
s_odd = 0
s_even = 0

for i, v in enumerate(V):
    i += 1
    if i % 2 == 0:
        even[v] += 1
        if even[v] > max_even:
            max_even = even[v]
            if f_even != 0 and v != f_even:
                s_even = f_even
                f_even = v
            elif f_even == 0:
                f_even = v

    elif i % 2 == 1:
        odd[v] += 1
        if odd[v] > max_odd:
            max_odd = odd[v]
            if f_odd != 0 and v != f_odd:
                s_odd = f_odd
                f_odd = v
            elif f_odd == 0:
                f_odd = v

half = n / 2
cnt = 0

if max_odd > max_even:
    cnt += half - max_odd
    if f_odd != f_even:
        cnt += half - max_even
    else:
        cnt += half - even[s_even]
elif max_odd < max_even:
    cnt += half - max_even
    if f_odd != f_even:
        cnt += half - max_odd
    else:
        cnt += half - odd[s_odd]
else:
    if odd[s_odd] > even[s_even]:
        cnt += half - max_even
        cnt += half - odd[s_odd]
    else:
        cnt += half - max_odd
        cnt += half - even[s_even]

print(int(cnt))
# print(odd, even)
# print(f'{max_odd}, {max_even}, {f_odd}, {s_odd}, {f_even}, {s_even}')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)

max_odd = 0
max_even = 0
f_odd = 0
f_even = 0
s_odd = 0
s_even = 0

for i, v in enumerate(V):
    i += 1
    if i % 2 == 0:
        even[v] += 1
        if even[v] > max_even:
            max_even = even[v]
            if f_even != 0 and v != f_even:
                s_even = f_even
                f_even = v
            elif f_even == 0:
                f_even = v

    elif i % 2 == 1:
        odd[v] += 1
        if odd[v] > max_odd:
            max_odd = odd[v]
            if f_odd != 0 and v != f_odd:
                s_odd = f_odd
                f_odd = v
            elif f_odd == 0:
                f_odd = v

half = n / 2
cnt = 0

if max_odd >= max_even:
    cnt += half - max_odd
    if f_odd != f_even:
        cnt += half - max_even
    else:
        cnt += half - even[s_even]
else:
    cnt += half - max_even
    if f_odd != f_even:
        cnt += half - max_odd
    else:
        cnt += half - odd[s_odd]

print(int(cnt))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)

max_odd = 0
max_even = 0
f_odd = 0
f_even = 0
s_odd = 0
s_even = 0

for i, v in enumerate(V):
    i += 1
    if i % 2 == 0:
        even[v] += 1
        if even[v] > max_even:
            max_even = even[v]
            if f_even != 0 and v != f_even:
                s_even = f_even
                f_even = v
            elif f_even == 0:
                f_even = v

    elif i % 2 == 1:
        odd[v] += 1
        if odd[v] > max_odd:
            max_odd = odd[v]
            if f_odd != 0 and v != f_odd:
                s_odd = f_odd
                f_odd = v
            elif f_odd == 0:
                f_odd = v

print('test')
# print(odd, even)
# print(f'{max_odd}, {max_even}, {f_odd}, {s_odd}, {f_even}, {s_even}')

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
VO=[]
VE=[]
for i in range(n):
  if i%2==1:
    VO.append(V[i])
  else:
    VE.append(V[i])
vo=Counter(VO).most_common(2)
ve=Counter(VE).most_common(2)
if ve[0][0]!=vo[0][0]:
  ans=n-ve[0][1]-vo[0][1]
else:
  if len(ve)==1 and len(vo)==1:
    ans=n//2
  elif len(ve)==1:
    ans=n-ve[0][1]-vo[1][1]
  elif len(vo)==1:
    ans=n-vo[0][1]-ve[1][1]
  else:
    ans=min((n-ve[0][1]-vo[1][1]),(n-vo[0][1]-ve[0][1]))    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
V=list(map(int,input().split()))
VO=[]
VE=[]
for i in range(n):
  if i%2==1:
    VO.append(V[i])
  else:
    VE.append(V[i])
vo=collections.Counter(VO).most_common()
ve=collections.Counter(VE).most_common()
if ve[0][0]!=vo[0][0]:
  ans=n-ve[0][1]-vo[0][1]
else:
  if len(ve)==1 and len(vo)==1:
    ans=n//2
  elif len(ve)==1:
    ans=n-ve[0][1]-vo[1][1]
  elif len(ve)!=1:
    ans=n-vo[0][1]-ve[1][1]
  else:
    ans=min((n-ve[0][1]-vo[1][1]),(n-vo[0][1]-ve[0][1]))    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
V=list(map(int,input().split()))
VO=[]
VE=[]
for i in range(n):
  if i%2==1:
    VO.append(V[i])
  else:
    VE.append(V[i])
vo=collections.Counter(VO).most_common()
ve=collections.Counter(VE).most_common()
if ve[0][0]!=vo[0][0]:
  ans=n-ve[0][1]-vo[0][1]
else:
  if len(ve)==1 and len(vo)==1:
    ans=n//2
  elif len(ve)==1 and len(vo)!=1:
    ans=n-ve[0][1]-vo[1][1]
  elif len(ve)!=1 and len(vo)==1:
    ans=n-vo[0][1]-ve[1][1]
  elif len(ve)!=1 and len(vo)!=1:
    ans=min((n-ve[0][1]-vo[1][1]),(n-vo[0][1]-ve[0][1]))    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
V=list(map(int,input().split()))
VO=[]
VE=[]
for i in range(n):
  if i%2==0:
    VO.append(V[i])
  else:
    VE.append(V[i])
vo=collections.Counter(VO).most_common()
ve=collections.Counter(VE).most_common()
if ve[0][0]!=vo[0][0]:
  ans=n-ve[0][1]-vo[0][1]
else:
  if len(ve)==1 and len(vo)==1:
    ans=n//2
  elif len(ve)==1 and len(vo)!=1:
    ans=n-ve[0][1]-vo[1][1]
  elif len(ve)!=1 and len(vo)==1:
    ans=n-vo[0][1]-ve[1][1]
  elif len(ve)!=1 and len(vo)!=1:
    ans=min((n-ve[0][1]-vo[1][1]),(n-vo[0][1]-ve[0][1]))    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
V=list(map(int,input().split()))
VO=[]
VE=[]
for i in range(n):
  if i%2==0:
    VO.append(V[i])
  else:
    VE.append(V[i])
vo=collections.Counter(VO).most_common()
ve=collections.Counter(VE).most_common()
if ve[0][0]!=vo[0][0]:
  ans=n-ve[0][1]-vo[0][1]
else:
  if len(ve)==1 and len(vo)==1:
    ans=min(ve[0][1],vo[0][1])
  elif len(ve)==1 and len(vo)!=1:
    ans=len(VO)-vo[1][1]
  elif len(ve)!=1 and len(vo)==1:
    ans=len(VE)-ve[1][1]
  elif len(ve)!=1 and len(vo)!=1:
    ans=min((n-ve[0][1]-vo[1][1]),(n-vo[0][1]-ve[0][1]))    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = v[::2], v[1::2]
count_even = sorted(Counter(v_even).items(), key=lambda x:x[1], reverse=True)
count_odd = sorted(Counter(v_odd).items(), key=lambda x:x[1], reverse=True)
max_e = max(count_even, key=lambda x:x[1])[0]
max_o = max(count_odd, key=lambda x:x[1])[0]
#print(max_e, max_o)

ans = 0
if max_e != max_o:
    #print('1')
    for i in range(n // 2):
        if v_even[i] != max_e:
            ans += 1
        if v_odd[i] != max_o:
            ans += 1

elif max_e == max_o and len(count_even) == 1 and len(count_odd) == 1:
    #print('2')
    ans = n // 2
    
else:
    #print('3')
    ans1 = 0
    ans2 = 0
    
    if len(count_even) > 1:
        max_e = count_even[1][0]

    for i in range(n // 2):
        if v_even[i] != max_e:
            ans1 += 1
        if v_odd[i] != max_o:
            ans1 += 1
            
    if len(count_odd) > 1:
        max_o = count_odd[1][0]
    max_e = max(count_even, key=lambda x:x[1])

    for i in range(n // 2):
        if v_even[i] != max_e:
            ans2 += 1
        if v_odd[i] != max_o:
            ans2 += 1
        
    ans = min(ans1, ans2)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1])
V2=sorted(V2.items(),key=lambda x:x[1])
cut = max(V1[0][1],V2[0][1])
for i in V1[:3]:
    for j in V2[:3]:
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1])
V2=sorted(V2.items(),key=lambda x:x[1])
cut = max(V1[0][1],V2[0][1])
for i in V1[:2]:
    for j in V2[:2]:
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
V1,V2={},{}
ans = N-1
for n,i in enumerate(list(map(int,input().split(' ')))):
    if n%2==0:
        V1.setdefault(i,0)
        V1[i]+=1
    else:
        V2.setdefault(i,0)
        V2[i]+=1
V1=sorted(V1.items(),key=lambda x:x[1])
V2=sorted(V2.items(),key=lambda x:x[1])
for i in V1[:2]:
    for j in V2[:2]:
        if i[0]!=j[0]:
            ans = min(ans,N-i[1]-j[1])
        else:
            ans = min(ans,N-max(i[1],j[1]))
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2 != 0]
#print(v_even, v_odd)
counter_even = collections.Counter(v_even)
counter_odd = collections.Counter(v_odd)

max_count_even = max(counter_even.items(), key=lambda x:x[1])
#print(max_count_even[0])
max_count_odd = max(counter_odd.items(), key=lambda x:x[1])
#print(max_count_odd[0])

if len(counter_even) == 1 and len(counter_odd) == 1 and max_count_even[0] == max_count_odd[0]:

    ans1 = 0
    for i in range(n // 2):
        if v_even[i] != max_count_even[1]:
            #print(v_even[i], max_count_even[0])
            v_even[i] = max_count_even[1]
            ans1 += 1
        
        if v_odd[i] != max_count_odd[0]:
            #print(v_odd[i], max_count_odd[0])
            v_odd[i] = max_count_odd[0]
            ans1 += 1

    ans2 = 0
    for i in range(n // 2):
        if v_even[i] != max_count_even[0]:
            #print(v_even[i], max_count_even[0])
            v_even[i] = max_count_even[0]
            ans2 += 1
        
        if v_odd[i] != max_count_odd[1]:
            #print(v_odd[i], max_count_odd[0])
            v_odd[i] = max_count_odd[1]
            ans2 += 1

    ans = min(ans1, ans2)

else:
    ans = 0 
    for i in range(n // 2):
        if v_even[i] != max_count_even[0]:
            #print(v_even[i], max_count_even[0])
            v_even[i] = max_count_even[0]
            ans += 1
        
        if v_odd[i] != max_count_odd[0]:
            #print(v_odd[i], max_count_odd[0])
            v_odd[i] = max_count_odd[0]
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2 != 0]
#print(v_even, v_odd)
counter_even = collections.Counter(v_even)
counter_odd = collections.Counter(v_odd)

max_count_even = max(counter_even.items(), key=lambda x:x[1])
#print(max_count_even[0])
max_count_odd = max(counter_odd.items(), key=lambda x:x[1])
#print(max_count_odd[0])
ans = 0
for i in range(n // 2):
    if v_even[i] != max_count_even[0]:
        #print(v_even[i], max_count_even[0])
        v_even[i] = max_count_even[0]
        ans += 1
        
    if v_odd[i] != max_count_odd[0]:
        #print(v_odd[i], max_count_odd[0])
        v_odd[i] = max_count_odd[0]
        ans += 1

if len(counter_even) == 1 and len(counter_odd) == 1 and max_count_even[0] == max_count_odd[0]:
    ans = n // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2 != 0]
#print(v_even, v_odd)
counter_even = collections.Counter(v_even)
counter_odd = collections.Counter(v_odd)

max_count_even = max(counter_even.items(), key=lambda x:x[1])
#print(max_count_even[0])
max_count_odd = max(counter_odd.items(), key=lambda x:x[1])
#print(max_count_odd[0])
ans = 0
for i in range(n // 2):
    if v_even[i] != max_count_even[0]:
        v_even[i] = max_count_even[0]
        ans += 1
        
    if v_odd[i] != max_count_odd[0]:
        v_odd[i] = max_count_odd[0]
        ans += 1

if len(counter_even) == 1 and len(counter_odd) == 1:
    ans = n // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2 != 0]
#print(v_even, v_odd)
counter_even = collections.Counter(v_even)
counter_odd = collections.Counter(v_odd)

max_count_even = max(counter_even.items(), key=lambda x:x[1])
#print(max_count_even[0])
max_count_odd = max(counter_odd.items(), key=lambda x:x[1])
#print(max_count_odd[0])
ans = 0
for i in range(n // 2):
    if v_even[i] != max_count_even[0]:
        v_even[i] = max_count_even[0]
        ans += 1
        
    if v_odd[i] != max_count_odd[0]:
        v_odd[i] = max_count_odd[0]
        ans += 1
        
if len(counter_even) == 1 and len(max_count_odd) == 1:
    ans = n // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
*v, = map(int, input().split())
v_even, v_odd = [v[i] for i in range(n) if i % 2 == 0], [v[i] for i in range(n) if i % 2 != 0]
#print(v_even, v_odd)
counter_even = collections.Counter(v_even)
counter_odd = collections.Counter(v_odd)

max_count_even = max(counter_even.items(), key=lambda x:x[1])
#print(max_count_even[0])
max_count_odd = max(counter_odd.items(), key=lambda x:x[1])
#print(max_count_odd[0])
ans = 0
for i in range(n // 2):
    if v_even[i] != max_count_even[0]:
        v_even[i] = max_count_even[0]
        ans += 1
        
    if v_odd[i] != max_count_odd[0]:
        v_odd[i] = max_count_odd[0]
        ans += 1
        
if len(counter_even) == 1 and len(max_count_odd):
    ans = n // 2

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [int(x) for x in input().split()]
li_odd = v[0:n:2]
li_even = v[1:n:2]

if len(v) == v.count(v[0]):
    print(len(v)//2)
else:
    c_odd = Counter(li_odd).most_common()
    c_even = Counter(li_even).most_common()
    if c_odd[0][0] != c_even[0][0]:
        print(len(li_odd) - c_odd[0][1] + len(li_even) - c_even[0][1])
    else:
        ans1 = len(li_odd) - c_odd[1][1] + len(li_even) - c_even[0][0]
        ans2 = len(li_odd) - c_odd[0][0] + len(li_even) - c_even[1][1]
        print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
n,*v = map(int,open(0).read().split())
v0,v1 = {},{}
flg = True
for i in v:
    if flg:
        v0[i]= v0[i]+1 if i in v0 else 1
    else:    
        v1[i]= v1[i]+1 if i in v1 else 1
    flg = not flg
len0,len1 = len(v0),len(v1)
if len0==1 and len1==1:
    if v0.keys() != v1.keys():
        print(0)
    else:
        sv = sorted(v1.values())[0]
        print(sv)
elif len0==1:
    sort_v1 = sorted(v1.items(),key=lambda x:x[1])
    sum1 = sum(v1.values())
    print(sum1 - max(v1.values()))
else:
    sort_v0 = sorted(v0.items(),key=lambda x:x[1])
    sum0 = sum(v0.values())
    print(sum0 - max(v0.values()))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    
    N = int(input())
    V = list(map(int,input().split()))
    odd = V[1::2]
    even = V[0::2]
    mode_o = Counter(odd).most_common()
    mode_o.append([0,0])
    mode_e = Counter(even).most_common()
    mode_e.append([0,0])
    ans = 0
    if mode_o[0][0] != mode_e[0][0]:
        ans = N-mode_o[0][1]-mode_e[0][1]
    else:
        ans = N - max(mode_e[0][1]-mode_o[1][1],mode_e[1][1]-mode_o[0][1])
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    
    N = int(input())
    V = list(map(int,input().split()))
    odd = V[1::2]
    even = V[0::2]
    mode_o = Counter(odd).most_common()
    mode_o.append([0,0])
    mode_e = Counter(even).most_common()
    mode_e.append([0,0])
    ans = 0
    if mode_o[0][0] != mode_e[0][0]:
        ans = N-mode_o[0][1]-mode_e[0][1]
    else:
        if mode_e[0][1] < mode_o[0][1]:
            ans = N - mode_e[0][1] - mode_o[1][1]
        else:
            ans = N - mode_e[1][1] - mode_o[0][1]
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    
    N = int(input())
    V = list(map(int,input().split()))
    odd = V[1::2]
    even = V[0::2]
    mode_o = Counter(odd).most_common()
    mode_o.append([0,0])
    mode_e = Counter(even).most_common()
    mode_e.append([0,0])
    ans = 0
    if mode_o[0][0] != mode_e[0][0]:
        ans = N-mode_o[0][1]-mode_e[0][1]
    else:
        if mode_e[0][1] < mode_o[0][1]:
            ans = N - mode_e[0][1] - mode_o[1][1]
        else:
            ans = N - mode_e[1][1] - mode_o[0][1]
    
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    
    N = int(input())
    V = list(map(int,input().split()))
    odd = V[1::2]
    even = V[0::2]
    mode_o = list(Counter(odd).most_common())
    mode_o.append([0,0])
    mode_e = list(Counter(even).most_common())
    mode_e.append([0,0])
    ans = 0
    if mode_o[0][0] != mode_e[0][0]:
        ans = N-mode_o[0][1]-mode_e[0][1]
    else:
        if mode_e[0][1] > mode_o[0][1]:
            ans = N - mode_e[0][1] - mode_o[1][1]
        else:
            ans = N - mode_e[1][1] - mode_o[0][1]
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,*v=map(int,open(0).read().split())
w=sorted(Counter(v).items(),key=lambda x:x[1])
if len(w)>1:
  print(w[-1][1]-w[-2][1])
else:
  print(n//2)

Submission status: Wrong Answer

Solution code:
import collections

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

if len(set(A)) == 1:
    print(n//2)
    
else:
    k = []
    g = []
    for i in range(n):
        if i%2 == 0:
            k.append(A[i])
        else:
            g.append(A[i])
    
    ck = collections.Counter(k) 
    ckk, ckv = zip(*ck.most_common())
    cg = collections.Counter(g) 
    cgk, cgv = zip(*cg.most_common())
    if ckk[0] == cgk[0]:
        if ckv[0] >= cgv[0]:
            print(n - ckv[0] - cgv[1])
        else:
            print(n - ckv[1] - cgv[0])
    else:
        print(n - ckv[0] - cgv[0])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int, input().split()))
even=Counter(V[::2])
odd=Counter(V[1::2])
eD=sorted(even.items(), key = lambda x: x[1])
even1 = eD[0][1]
oD=sorted(odd.items(), key = lambda x: x[1])
odd1 = oD[0][1]
if eD[0][0] != oD[0][0]:
    print(n-even1-odd1)
else:
    if len(even) == 1 or len(odd) == 1:
        print(n//2)
    else:
        print(n-max(even1+oD[1][1],odd1+eD[1][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int, input().split()))
even=Counter(V[::2])
odd=Counter(V[1::2])
eD=sorted(even.items(), key = lambda x: x[1])
even1 = eD[0][1]
oD=sorted(odd.items(), key = lambda x: x[1])
odd1 = oD[0][1]
if eD[0][0] != oD[0][0]:
    print(n-even1-odd1)
else:
    if len(even) == 1 or len(odd) == 1:
        print(n//2)
    else:
        even2 = eD[1][1]
        odd2 = oD[1][1]
        cand1 = n-even1-odd2
        cand2 = n-even2-odd1
        print(min(cand1,cand2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int, input().split()))
even=Counter(V[::2])
odd=Counter(V[1::2])
eD=sorted(even.items(), key = lambda x: x[1])
even1 = eD[0][1]
oD=sorted(odd.items(), key = lambda x: x[1])
odd1 = oD[0][1]
if eD[0][0] != oD[0][0]:
    print(n-even1-odd1)
else:
    if len(even) == 1 or len(odd) == 1:
        print(n//2)
    else:
        even2 = eD[1][1]
        odd2 = oD[1][1]
        cand1 = n-even1-odd2
        cand2 = n--even2-odd1
        print(min(cand1,cand2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int, input().split()))
even=Counter(V[::2])
odd=Counter(V[1::2])
eD=sorted(even.items(), key = lambda x: x[1])
even1 = eD[0][1]
oD=sorted(odd.items(), key = lambda x: x[1])
odd1 = oD[0][1]
if eD[0][0] != oD[0][0]:
    print(n-even1-odd1)
else:
    if len(even)>1:
        even2 = eD[1][1]
    else:
        even2 = 0
    if len(odd)>1:
        odd2 = oD[1][1]
    else:
        odd2 = 0
    cand1 = n-even1-odd2
    cand2 = n--even2-odd1
    print(min(cand1,cand2))

Submission status: Wrong Answer

Solution code:

from collections import defaultdict as dic

n = int(input())

v = list(map(int, input().split()))
dict1 = dic(int)
dict2 = dic(int)

for i in range(n):
    if i % 2 == 1:
        dict1[v[i]] += 1
    else:
        dict2[v[i]] += 1
    
def search_second_larger(dict):
    largest = max(dict.values())
    ret = min(dict.values())
    for k, v in dict.items():
        if v >= largest and k != max(dict):
            ret = largest
            largest = i
        elif v > ret:
            ret = v
    return ret


max_1 = max(dict1.values())
second_larger_1 = search_second_larger(dict1)
max_2 = max(dict2.values())
second_larger_2 = search_second_larger(dict2)

if  dict1 == dict2:
    print(n - max_1)
elif max(dict1) == max(dict2):
    print(min(n - max_1 - second_larger_2, n - second_larger_1 - max_2))
else:
    print(n - max_1 - max_2)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict as dic

n = int(input())

v = list(map(int, input().split()))
dict1 = dic(int)
dict2 = dic(int)

for i in range(n):
    if i % 2 == 1:
        dict1[v[i]] += 1
    else:
        dict2[v[i]] += 1
    
max_1 = max(dict1.values())
dict1[max(dict1)] -= 1
max_2 = max(dict2.values())
dict2[max(dict2)] -= 1
if  dict1 == dict2:
    print(n - max_1)
elif max(dict1) == max(dict2):
    print(min(n - max_1 - max(dict2.values()), n - max(dict1.values()) - max_2))
else:
    print(n - max_1 - max_2)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict as dic

n = int(input())

v = list(map(int, input().split()))
dict1 = dic(int)
dict2 = dic(int)

for i in range(n):
    if i % 2 == 1:
        dict1[v[i]] += 1
    else:
        dict2[v[i]] += 1
    
max_1 = max(dict1.values())
dict1[max(dict1)] -= 1
max_2 = max(dict2.values())
dict2[max(dict2)] -= 1

if len(dict1) == len(dict2) == 1:
    print(n - max_1)
elif max(dict1) == max(dict2):
    print(min(n - max_1 - max(dict2.values()), n - max(dict1) - max_2))
else:
    print(n - max_1 - max_2)

"""
if len(dict1) == len(dict2) == 1:
    if len(dict) == 2:
        print(0)
    else:
        print(dict1[v[0]])
else:
    print(n - max(dict1.values()) - max(dict2.values()))
"""

Submission status: Wrong Answer

Solution code:

from collections import defaultdict as dic

n = int(input())

v = list(map(int, input().split()))
dict1 = dic(int)
dict2 = dic(int)
dict = dic(int)

for i in range(n):
    if i % 2 == 1:
        dict1[v[i]] += 1
    else:
        dict2[v[i]] += 1
    
    dict[v[i]] += 1

max_1 = max(dict1.values())
dict1[max(dict1)] -= 1
max_2 = max(dict2.values())
dict2[max(dict2)] -= 1

if dict1 == dict2:
    print(n - max_1)
elif max(dict1) == max(dict2):
    print(min(n - max_1 - max(dict2.values()), n - max(dict1) - max_2))
else:
    print(n - max_1 - max_2)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict as dic

n = int(input())

v = list(map(int, input().split()))
dict1 = dic(int)
dict2 = dic(int)
dict = dic(int)

for i in range(n):
    if i % 2 == 1:
        dict1[v[i]] += 1
    else:
        dict2[v[i]] += 1
    
    dict[v[i]] += 1

if len(dict1) == len(dict2) == 1:
    if len(dict) == 2:
        print(0)
    else:
        print(dict1[v[0]])
else:
    print(n - max(dict1.values()) - max(dict2.values()))

Submission status: Wrong Answer

Solution code:

from collections import defaultdict as dic

n = int(input())

v = list(map(int, input().split()))
dict1 = dic(int)
dict2 = dic(int)
dict = dic(int)

for i in range(n):
    if i % 2 == 1:
        dict1[v[i]] += 1
    else:
        dict2[v[i]] += 1
    
    dict[v[i]] += 1

if len(dict1) == len(dict2):
    if len(dict) == 2:
        print(0)
    else:
        print(dict1[v[0]])
else:
    print(n - max(dict1.values()) - max(dict2.values()))

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(0,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 = 0
valmax2 = 0
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 = 0
valmax2 = 0
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)