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:
n=int(input())
#a,b=map(int,input().split())
vl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

dic1={};dic2={}

for i in range(n):
    v=vl[i]
    if i%2==0:
        dic1[v]=dic1.get(v,0)+1
    else:
        dic2[v]=dic2.get(v,0)+1

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

mx1_val,mx1_count=dic1[0]
mx2_val,mx2_count=dic2[0]

ans=0
total=n//2
if n==2:
    if vl[0]==vl[1]:
        ans=1
    else:
        ans=0
else:
    if mx1_count>=mx2_count:
        ans+=total-mx1_count
        if mx1_val==mx2_val:
            if len(dic2)==1:
                ans+=total
            else:
                mx2_count=dic2[1][1]
                ans+=total-mx2_count
        else:
            ans+=total-mx2_count
    else:
        ans+=total-mx2_count
        if mx1_val==mx2_val:
            if len(dic1)==1:
                ans+=total
            else: 
                mx1_count=dic1[1][1]
                ans+=total-mx1_count
        else:
            ans+=total-mx1_count
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
#a,b=map(int,input().split())
vl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

dic1={};dic2={}

for i in range(n):
    v=vl[i]
    if i%2==0:
        dic1[v]=dic1.get(v,0)+1
    else:
        dic2[v]=dic2.get(v,0)+1

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

mx1_val,mx1_count=dic1[0]
mx2_val,mx2_count=dic2[0]

ans=0
total=n//2
if mx1_count>=mx2_count:
    ans+=total-mx1_count
    if mx1_val==mx2_val:
        if len(dic2)==1:
            ans+=total
        else:
            mx2_count=dic2[1][1]
            ans+=total-mx2_count
    else:
        ans+=total-mx2_count
else:
    ans+=total-mx2_count
    if mx1_val==mx2_val:
        if len(dic1)==1:
            ans+=total
        else: 
            mx1_count=dic1[1][1]
            ans+=total-mx1_count
    else:
        ans+=total-mx1_count
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

n = int(sys.stdin.readline().rstrip())
v = list(map(int, sys.stdin.readline().rstrip().split()))
v1 = v[::2]
v2 = v[1::2]

v1d = {}
v2d = {}
for vi in v1:
    if vi in v1d:
        v1d[vi] += 1
    else:
        v1d[vi] = 1
for vi in v2:
    if vi in v2d:
        v2d[vi] += 1
    else:
        v2d[vi] = 1

if max(v1d, key=v1d.get) != max(v2d, key=v2d.get):
    print(len(v1) - max(v1d.values()) + len(v2) - max(v2d.values()))
else:
    if len(v1) - max(v1d.values()) > len(v2) - max(v2d.values()):
        if len(v1d.values()) == 1:
            tmp = 0
        else:
            tmp = sorted(v1d.values())[-2]
        print(len(v1) - tmp + len(v2) - max(v2d.values()))
    else:
        if len(v2d.values()) == 1:
            tmp = 0
        else:
            tmp = sorted(v2d.values())[-2]
        print(len(v1) - max(v1d.values()) + len(v2) - tmp)
# min(len(v1) - max(v1d.values), len(v2) - max(v2d.values))
# print(len(set(v1)) - 1 + len(set(v2)) - 1)

Submission status: Wrong Answer

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

l_o = l[::2]
o = len(l_o)
l_g = l[1::2]
g = len(l_g)

a,b = Counter(l_o).most_common()[0]
c,d = Counter(l_g).most_common()[0]
if a!=c:
  print((o-b) + (g-d))
else:
  if b>=d:
    if len(Counter(l_g).most_common())==1:
      print((o-b) + g)
    else:
      print((o-b) + (g-Counter(l_g).most_common()[1][1]))
  else:
    if len(Counter(l_o).most_common())==1:
      print(o+g-d)
    else:
      print((o-Counter(l_o).most_common()[1][1]) + (g-d))

Submission status: Wrong Answer

Solution code:
import math
import sys

n = int(sys.stdin.readline().rstrip())
v = list(map(int, sys.stdin.readline().rstrip().split()))
v1 = v[::2]
v2 = v[1::2]

v1d = {}
v2d = {}
for vi in v1:
    if vi in v1d:
        v1d[vi] += 1
    else:
        v1d[vi] = 1
for vi in v2:
    if vi in v2d:
        v2d[vi] += 1
    else:
        v2d[vi] = 1

if max(v1d, key=v1d.get) != max(v2d, key=v2d.get):
    print(len(v1) - max(v1d.values()) + len(v2) - max(v2d.values()))
else:
    if len(v1) - max(v1d.values()) > len(v2) - max(v2d.values()):
        if len(v1d.values()) == 1:
            tmp = 0
        else:
            tmp = sorted(v1d.values())[1]
        print(len(v1) - tmp + len(v2) - max(v2d.values()))
    else:
        if len(v2d.values()) == 1:
            tmp = 0
        else:
            tmp = sorted(v2d.values())[1]
        print(len(v1) - max(v1d.values()) + len(v2) - tmp)
# min(len(v1) - max(v1d.values), len(v2) - max(v2d.values))
# print(len(set(v1)) - 1 + len(set(v2)) - 1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
    exit()
kisu = v[::2]
gusu = v[1::2]
kisu_color = list(Counter(kisu).items())[:2]
gusu_color = list(Counter(gusu).items())[:2]
if kisu_color[0][0] != gusu_color[0][0]:
    ans = n - kisu_color[0][1] - gusu_color[0][1]
else:
    ans = min(n - kisu_color[0][1] - gusu_color[1][1], n - kisu_color[1][1] - gusu_color[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
    exit()
kisu = v[::2]
gusu = v[1::2]
kisu_color = list(Counter(kisu).items())[:2]
gusu_color = list(Counter(gusu).items())[:2]
print(kisu_color)
print(gusu_color)
if kisu_color[0][0] != gusu_color[0][0]:
    ans = n - kisu_color[0][1] - gusu_color[0][1]
else:
    ans = min(n - kisu_color[0][1] - gusu_color[1][1], n - kisu_color[1][1] - gusu_color[0][1])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter, OrderedDict
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
    print(n // 2)
    exit()
kisu = v[::2]
gusu = v[1::2]
kisu_color = list(OrderedDict(Counter(kisu)).items())[:2]
gusu_color = list(OrderedDict(Counter(gusu)).items())[:2]
if kisu_color[0][0] != gusu_color[0][0]:
    ans = n - kisu_color[0][1] - gusu_color[0][1]
else:
    if kisu_color[1][1] >= gusu_color[1][1]:
        ans = n - kisu_color[1][1] - gusu_color[0][1]
    else:
        ans = n - kisu_color[0][1] - gusu_color[1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
color = list(collections.Counter(v).keys())[:2]
if len(set(v)) == 1:
    print(n // 2)
    exit()
kisu = v[::2]
gusu = v[1::2]
kisu_color = list(collections.Counter(kisu).items())[:2]
gusu_color = list(collections.Counter(gusu).items())[:2]
if kisu_color[0][0] != gusu_color[0][0]:
    ans = n - kisu_color[0][1] - gusu_color[0][1]
else:
    if kisu_color[1][1] >= gusu_color[1][1]:
        ans = n - kisu_color[1][1] - gusu_color[0][1]
    else:
        ans = n - kisu_color[0][1] - gusu_color[1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
color = list(collections.Counter(v).keys())[:2]
if len(set(v)) == 1:
    print(2)
    exit()
kisu = v[::2]
gusu = v[1::2]
kisu_color = list(collections.Counter(kisu).items())[:2]
gusu_color = list(collections.Counter(gusu).items())[:2]
if kisu_color[0][0] != gusu_color[0][0]:
    ans = n - kisu_color[0][1] - gusu_color[0][1]
else:
    if kisu_color[1][1] >= gusu_color[1][1]:
        ans = n - kisu_color[1][1] - gusu_color[0][1]
    else:
        ans = n - kisu_color[0][1] - gusu_color[1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = li()

d_o = defaultdict(int)
d_e = defaultdict(int)

for i in range(N):
    if i % 2:
        d_o[A[i]] += 1
    else:
        d_e[A[i]] += 1

l_d = sorted(list(d_o.items()), key=lambda x:x[1], reverse=True)
l_e = sorted(list(d_e.items()), key=lambda x:x[1], reverse=True)

if l_d[0][0] != l_e[0][0]:
    print(N - l_d[0][1] - l_e[0][1])
elif len(l_d) == len(l_e) == 1:
        print(N - max(l_d[0][1], l_e[0][1]))
elif len(l_d) == 1:
        print(N - l_d[0][1] - l_e[1][1])
elif len(l_e) == 1:
        print(N - l_d[1][1] - l_e[0][1])
else:
    ans = max(N-l_d[1][1]-l_e[0][1], N-l_d[0][1]-l_e[1][1])
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int, input().split()))
color = list(collections.Counter(v).keys())[:2]
if len(color) == 1:
    print(2)
    exit()
count = 0
for i in range(n - 2):
    if v[i] not in color:
        count += 1
    if v[i + 2] not in color:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import collections

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

if len(set(v)) == 1:
  print(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cmc1 = collections.Counter(v1).most_common()
  cmc2 = collections.Counter(v2).most_common()
  
  print(cmc1[:5])
  print(cmc2[:5])
  
  if cmc1[0][0] == cmc2[0][0]:    
    ans1 = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[1][1])
    ans2 = (len(v1) - cmc1[1][1]) + (len(v2) - cmc2[0][1])
    print(min(ans1, ans2))
  else:
    ans = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[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(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cmc1 = collections.Counter(v1).most_common()
  cmc2 = collections.Counter(v2).most_common()
  
  if cmc1[0][0] == cmc2[0][0]:    
    ans1 = (len(v1) - cmc2[0][1]) + (len(v2) - cmc1[1][1])
    ans2 = (len(v1) - cmc1[1][1]) + (len(v2) - cmc2[0][1])
    print(min(ans1, ans2))
  else:
    ans = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[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(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cmc1 = collections.Counter(v1).most_common()
  cmc2 = collections.Counter(v2).most_common()
  
  if cmc1[0][0] == cmc2[0][0]:    
    ans1 = (len(v1) - cmc2[1][1]) + (len(v2) - cmc1[1][1])
    ans2 = (len(v1) - cmc1[1][1]) + (len(v2) - cmc2[1][1])
    print(min(ans1, ans2))
  else:
    ans = (len(v1) - cmc1[0][1]) + (len(v2) - cmc2[0][1])
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2])
v2 = Counter(v[1::2])
if len(v1) != 1: 
    e1, e2 = list(v1.keys())[0], list(v1.keys())[1]
else: e1,e2= list((v1.keys()))[0], 0
if len(v2) != 1:
    o1, o2 = list(v2.keys())[0], list(v2.keys())[1]
else: o1, o2 = list(v2.keys())[0], 0

ans = []
cnt = 0
if len(v1) != 1:
    for x,y in v1.items():
        if x == e1: continue
        else: cnt += y
if len(v2) == 1:
    if e1 in v2: cnt += n//2
else:
    for x,y in v2.items():
        if x == o2: continue
        else: cnt += y
ans.append(cnt)

cnt = 0
if len(v1) == 1:
    if o1 in v1: cnt = n//2
else:
    for x, y in v1.items():
        if x == e2: continue
        else: cnt += y
if len(v2) != 1:
    for x, y in v2.items():
        if x == o1: continue
        else: cnt += y

print(min(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2])
v2 = Counter(v[1::2])

ans = []
cnt = 0
if len(v1) != 1:
    b = ""
    for x,y in v1.items():
        if b == "": b = x
        else: cnt += y
else: b = v[0]
if len(v2) == 1 and b not in v2: ans.append(cnt)
else:
    for x,y in v2.items():
        if b != "" and b != x:
            b = ""
        elif b == x: 
            cnt += y
            b = -1
        elif b == -1: 
            b = ""
            continue
        else: cnt += y
    ans.append(cnt)

cnt2 = 0
if len(v2) != 1:
    b = ""
    for x,y in v2.items():
        if b == "": b = x
        else: cnt2 += y
else: b = v[1]
if len(v1) == 1 and b not in v1: ans.append(cnt2)
else:
    for x,y in v1.items():
        if b != "" and b != x:
            b = ""
        elif b == x: 
            cnt2 += y
            b = -1
        elif b == -1: 
            b = ""
            continue
        else: cnt2 += y
    ans.append(cnt2)
print(min(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2])
v2 = Counter(v[1::2])
cnt = 0
if len(v1) != 1:
    b = ""
    for x,y in v1.items():
        if b == "": b = x
        else: cnt += y
else: b = v[0]
if len(v2) == 1 and b not in v2: print(cnt)
else:
    for x,y in v2.items():
        if b != "" and b != x:
            b = ""
        elif b == x: 
            cnt += y
            b = -1
        elif b == -1: 
            b = ""
            continue
        else: cnt += y
    print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
V = list(map(int, input().split()))

V1 = V[::2]
V2 = V[1::2]

if len(set(V1)) == 1 and len(set(V2)) == 1 and V1[0] == V2[0]:
    print(len(V1))
    exit()


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

max1 = 0
max1_2 = 0
index1 = 0
max2 = 0
max2_2 = 0
index2 = 0

for c, i in C1.items():
    if i >= max1:
        max1_2 = max1
        max1 = i
        index1 = c

for c, i in C2.items():
    if i >=max2:
        max2_2 = max2
        max2 = i
        index2 = c

nokori1 = len(V1) - max1
nokori2 = len(V2) - max2

nokori1_2 = len(V1) - max1_2
nokori2_2 = len(V2) - max2_2

ans = 0
if index1 == index2:
    if len(set(V1)) == 1:
        ans = nokori2_2
    elif len(set(V2)) == 1:
        ans = nokori1_2
    else:
        ans = min(nokori1_2 + nokori2, min(nokori1 + nokori2_2, nokori1+nokori2))
else:
    ans = nokori1 + nokori2
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
V = list(map(int, input().split()))

V1 = V[::2]
V2 = V[1::2]

if len(set(V1)) == 1 and len(set(V2)) == 1 and V1[0] == V2[0]:
    print(len(V1))
    exit()


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

max1 = 0
max1_2 = 0
index1 = 0
max2 = 0
max2_2 = 0
index2 = 0

for c, i in C1.items():
    if i >= max1:
        max1_2 = max1
        max1 = i
        index1 = c

for c, i in C2.items():
    if i >=max2:
        max2_2 = max2
        max2 = i
        index2 = c

nokori1 = len(V1) - max1
nokori2 = len(V2) - max2

nokori1_2 = len(V1) - max1_2
nokori2_2 = len(V2) - max2_2

ans = 0

if index1 == index2:
    if len(set(V1)) == 1:
        ans = nokori2_2
    elif len(set(V2)) == 1:
        ans = nokori1_2
    else:
        ans = min(nokori1_2 + nokori2, nokori1 + nokori2_2)
else:
    ans = nokori1 + nokori2
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(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cmc1 = collections.Counter(v1).most_common()
  cmc2 = collections.Counter(v2).most_common()
  
  if cmc1[0][0] == cmc2[0][0]:    
    if cmc1[1][1] > cmc2[1][1]:
      ans = len(v1) - cmc2[1][1]
      ans += len(v2) - cmc1[1][1]
    else:
      ans = len(v1) - cmc1[1][1]
      ans += len(v2) - cmc2[1][1]
  else:
    ans = len(v1) - cmc1[0][1]
    ans += len(v2) - cmc2[0][1]
  
  print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
V = list(map(int, input().split()))

V1 = V[::2]
V2 = V[1::2]

if len(set(V1)) == 1 and len(set(V2)) == 1 and V1[0] == V2[0]:
    print(len(V1))
    exit()


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

max1 = 0
max1_2 = 0
index1 = 0
max2 = 0
max2_2 = 0
index2 = 0

for c, i in C1.items():
    if i > max1:
        max1_2 = max1
        max1 = i
        index1 = c

for c, i in C2.items():
    if i > max2:
        max2_2 = max2
        max2 = i
        index2 = c


nokori1 = len(V1) - max1
nokori1_2 = len(V1) - max1_2
nokori2 = len(V2) - max2
nokori2_2 = len(V2) - max2_2

ans = 0

if index1 == index2:
    ans = min(nokori1_2 + nokori2, nokori1 + nokori2_2)
else:
    ans = nokori1 + nokori2
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
V = list(map(int, input().split()))

V1 = V[::2]
V2 = V[1::2]

if len(set(V1)) == 1 and len(set(V2)) == 1 and V1[0] == V2[0]:
    print(len(V1))
    exit()


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

max1 = 0
max1_2 = 0
index1 = 0
max2 = 0
max2_2 = 0
index2 = 0

for c, i in C1.items():
    if i > max1:
        max1_2 = max1
        max1 = i
        index1 = c

for c, i in C2.items():
    if i > max2:
        max2_2 = max2
        max2 = i
        index2 = c


nokori1 = len(V1) - max1
nokori1_2 = len(V1) - max1_2
nokori2 = len(V2) - max2
nokori2_2 = len(V2) - max2_2

ans = 0

if index1 == index2:
    ans = min(nokori1_2, nokori2_2)
else:
    ans = nokori1 + nokori2
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
V = list(map(int, input().split()))

V1 = V[::2]
V2 = V[1::2]

if len(set(V1)) == 1 and len(set(V2)) == 1 and V1[0] == V2[0]:
    print(len(V1))
    exit()


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

max1 = 0
index1 = 0
max2 = 0
index2 = 0

for c, i in C1.items():
    if i > max1:
        max1 = i
        index1 = c

for c, i in C2.items():
    if i > max2:
        max2 = i
        index2 = c


nokori1 = len(V1) - max1
nokori2 = len(V2) - max2

ans = 0

if index1 == index2:
    ans = nokori1 + max1
else:
    ans = nokori1 + nokori2
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
V = list(map(int, input().split()))

V1 = []
V2 = []

for i in range(N):
    if i%2==0: V1.append(V[i])
    else: V2.append(V[i])

if len(set(V1)) == 1 and len(set(V2)) == 1 and V1[0] == V2[0]:
    print(len(V1))
    exit()


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

max1 = 0
max2 = 0

for c, i in C1.items():
    if i > max1: max1 = i

for c, i in C2.items():
    if i > max2: max2 = i

nokori1 = len(V1) - max1
nokori2 = len(V2) - max2
ans = nokori1 + nokori2
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
N = int(input())
V = list(map(int, input().split()))

V1 = []
V2 = []

for i in range(N):
    if i%2==0: V1.append(V[i])
    else: V2.append(V[i])

if len(set(V1)) == 1 and len(set(V2)) == 1 and V[1] == V[2]:
    print(len(V1))
    exit()


C1 = collections.Counter(V1)
C2 = collections.Counter(V2)

max1 = 0
max2 = 0

for c, i in C1.items():
    if i > max1: max1 = i

for c, i in C2.items():
    if i > max2: max2 = i

nokori1 = len(V1) - max1
nokori2 = len(V2) - max2
ans = nokori1 + nokori2
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(n//2)
else:
  v1 = v[::2]
  v2 = v[1::2]
  
  cl1 = collections.Counter(v1)
  cl2 = collections.Counter(v2)
  
  ans = len(v1) - cl1.most_common()[0][1]
  ans += len(v2) - cl2.most_common()[0][1]
  print(ans)

Submission status: Wrong Answer

Solution code:

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

evn=dict()
odd=dict()

maxevn1=0
maxevnv1=0
maxodd1=0
maxoddv1=0

maxevn2=0
maxevnv2=0
maxodd2=0
maxoddv2=0

for i in range(n):
    if i%2==0:
        if v[i] in evn:
            evn[v[i]]+=1
        else:
            evn[v[i]]=1
        if evn[v[i]]>maxevn1  and v[i]==maxevnv1:
            maxevn1=evn[v[i]]
        elif evn[v[i]]>maxevn1  and v[i]!=maxevnv1:
            maxevn2=maxevn1
            maxevnv2=maxevnv1
            maxevn1=evn[v[i]]
            maxevnv1=v[i]           
    else:
        if v[i] in odd:
            odd[v[i]]+=1
        else:
            odd[v[i]]=1
        if odd[v[i]]>maxodd1 and v[i]==maxoddv1:
            maxodd1=odd[v[i]]
        elif odd[v[i]]>maxodd1 and v[i]!=maxoddv1:
            maxodd2=maxodd1
            maxoddv2=maxoddv1
            maxodd1=odd[v[i]]
            maxoddv1=v[i]           

if maxevnv1!=maxoddv1:
    print(n-maxevn1-maxodd1)
else:
    kk=min(n-maxevn1-maxodd2,n-maxevn2-maxodd1)
    print(kk)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

from collections import Counter

def solve():
    n = II()
    V = LI()
    
    even = V[::2]
    odd = V[1::2]
    harf = n // 2
    
    ec = Counter(even).most_common()
    oc = Counter(odd).most_common()
    print(n)
    print(ec[:3])
    print(oc[:3])

    
    if ec[0][0] == oc[0][0]:
      # 小さい方を変える
      if ec[0][1] < oc[0][1]:
        ans = n - oc[0][1] - (ec[1][1] if len(ec) > 1 else 0)
      elif ec[0][1] == oc[0][1]:
        ans = n - ec[0][1] - max((ec[1][1] if len(ec) > 1 else 0), (oc[1][1] if len(oc) > 1 else 0))
      else:
        ans = n - ec[0][1] - (oc[1][1] if len(oc) > 1 else 0)
    else:
      ans = n - ec[0][1] - oc[0][1]
    
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

from collections import Counter

def solve():
    n = II()
    V = LI()
    
    even = V[::2]
    odd = V[1::2]
    harf = n // 2
    
    ec = Counter(even).most_common()
    oc = Counter(odd).most_common()
    # print(ec)
    # print(oc)

    
    if ec[0][0] == oc[0][0]:
      # 小さい方を変える
      if ec[0][1] < oc[0][1]:
        ans = n - oc[0][1] - (ec[1][1] if len(ec) > 1 else 0)
      else:
        ans = n - ec[0][1] - (oc[1][1] if len(oc) > 1 else 0)
    else:
      ans = n - ec[0][1] - oc[0][1]
    
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
numbers = [int(x) for x in input().split()]

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

c1 = Counter(odds).most_common(2)
c2 = Counter(evens).most_common(2)

if c1[0][0] == c2[0][0]:
  if c1[0][1] > c2[0][1]:
    print(N - c1[0][1] - (c2[1][1] if len(c2) > 1 else 0))
  else:
    print(N - c2[0][1] - (c1[1][1] if len(c1) > 1 else 0))
else:  
  print(N - c1[0][1] - c2[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
numbers = [int(x) for x in input().split()]

odds = [x for i, x in enumerate(numbers, 1) if i % 2 != 0]
evens = [x for i, x in enumerate(numbers, 1) if i % 2 == 0]

c1 = [(k, v) for k, v in Counter(odds).items()]
c2 = [(k, v) for k, v in Counter(evens).items()]

c1.sort(reverse=True)
c2.sort(reverse=True)

if c1[0][0] == c2[0][0]:
  if c1[0][1] > c2[0][1]:
    print(N - c1[0][1] - (c2[1][1] if len(c2) > 1 else 0))
  else:
    print(N - c2[0][1] - (c1[1][1] if len(c1) > 1 else 0))
else:  
  print(N - c1[0][1] - c2[0][1])

Submission status: Wrong Answer

Solution code:
import sys

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

if len(set(V))==1:
    print(len(V)//2)
    sys.exit()
#偶数
d_e = {}
#奇数
d_o = {}

for i in range(N):
    if i%2==0:
        if V[i] in d_e:
            d_e[V[i]] += 1
        else:
            d_e[V[i]] = 1
    if i%2!=0:
        if V[i] in d_o:
            d_o[V[i]] += 1
        else:
            d_o[V[i]] = 1

#最大度数分布を探す
max_e = 0
max_o = 0

for i in range(N):
    if i%2==0:
        max_e = max(max_e, d_e[V[i]])
    else:
        max_o = max(max_o, d_o[V[i]])
t = N//2

print(t-max_e+t-max_o)

Submission status: Wrong Answer

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 奇数番目の最頻値と偶数番目の最頻値が同じ時に注意
N = ir()
V = lr()
odd = V[::2]
even = V[1::2]
cnt_odd = Counter(odd)
cnt_even = Counter(even)
cnt_odd_most = cnt_odd.most_common()
cnt_even_most = cnt_even.most_common()
if cnt_odd_most[0][0] == cnt_even_most[0][0]:
    answer = N // 2
    if len(cnt_odd) > 1:
        temp = N - cnt_odd_most[1][1] - cnt_even_most[0][1]
        answer = min(answer, temp)
    if len(cnt_even) > 1:
        temp = N - cnt_odd_most[0][1] - cnt_even_most[1][1]
        answer = min(answer, temp)
else:
    answer = N - cnt_odd_most[0][1] - cnt_even_most[0][1]

print(answer)

Submission status: Wrong Answer

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

a = v[::2]
b = v[1::2]
ac = collections.Counter(a)
bc = collections.Counter(b)
an = len(a)-ac.most_common()[0][1]
if ac.most_common()[0][0] == bc.most_common()[0][0]:
    bn = len(b)
else:
    bn = len(b)-bc.most_common()[0][1]

print(an+bn)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    n=int(input())
    V=[int(_) for _ in input().split()]
    even=V[0::2]
    odd=V[1::2]
    even_c=Counter(even)
    odd_c=Counter(odd)
    even_ci,odd_ci=list(even_c.items()),list(odd_c.items())
    even_ci.sort(key=itemgetter(1),reverse=True)
    odd_ci.sort(key=itemgetter(1),reverse=True)
    if even_ci[0][0]==odd_ci[0][0]:
        print(n//2)
    else:
        print(sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[0][1])

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
from operator import itemgetter
def main():
    n=int(input())
    V=[int(_) for _ in input().split()]
    even=V[0::2]
    odd=V[1::2]
    even_c=Counter(even)
    odd_c=Counter(odd)
    even_ci,odd_ci=list(even_c.items()),list(odd_c.items())
    even_ci.sort(key=itemgetter(1),reverse=True)
    odd_ci.sort(key=itemgetter(1),reverse=True)
    print(even_ci)
    print(odd_ci)
    if even_ci[0][0]==odd_ci[0][0]:
        print(n//2)
    else:
        print(sum(even_c.values())-even_ci[0][1]+sum(odd_c.values())-odd_ci[0][1])

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ac=Counter(v[::2]).most_common(2)
bc=Counter(v[1::2]).most_common(2)

#print(ac,bc)
if ac[0][0] != bc[0][0]:
    ans = n -(ac[0][1] + bc[0][1])
else:
    if ac[0][1] == bc[0][1]:
        ans = n//2
    else:
        ans = n-max(ac[1][1] + bc[0][1],bc[1][1] + ac[0][1])
    
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ac=Counter(v[::2]).most_common(2)
bc=Counter(v[1::2]).most_common(2)

#print(ac,bc)
if ac[0][0] != bc[0][0]:
    ans = n -(ac[0][1] + bc[0][1])
elif ac[0][1] == bc[0][1]:
    ans = n//2
else:
    ans = n-max(ac[1][1] + bc[0][1],bc[1][1] + ac[0][1])
    
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ac=Counter(v[::2]).most_common(2)
bc=Counter(v[1::2]).most_common(2)

print(ac,bc)
if ac[0][0] != bc[0][0]:
    ans = n -(ac[0][1] + bc[0][1])
elif ac[0][1] == bc[0][1]:
    ans = n//2
else:
    ans = n-max(ac[1][1] + bc[0][1],bc[1][1] + ac[0][1])
    
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import itemgetter

n = int(input())
v = list(map(int, input().split()))
vodd = []
veven = []


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

lstodd = Counter(vodd)
lsteven = Counter(veven)

ans = []
for i, ii in zip(range(2), lstodd.most_common()):
    for j, jj in zip(range(2), lsteven.most_common()):
        if ii[0] == jj[0]:continue
        ans.append(len(vodd) - ii[1] + len(veven) - jj[1])
if ans == []:ans.append(n//2)

print(max(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])
# print(v_odd)
# print(v_even)
# print(Counter(v_odd).most_common())
# print(Counter(v_even).most_common())

if Counter(v_odd).most_common()[0][0] != Counter(v_even).most_common()[0][0]:
    number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
    number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]
else:
    if Counter(v_odd).most_common()[0][1] >= Counter(v_even).most_common()[0][1]:
        number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
        foo = Counter(v_even).most_common()[1][1] if len(Counter(v_even).most_common()) >= 2 else 0
        number_of_rewrites += len(v_even) - foo
    else:
        foo = Counter(v_odd).most_common()[1][1] if len(Counter(v_odd).most_common()) >= 2 else 0
        number_of_rewrites = len(v_odd) - foo
        number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]


print(number_of_rewrites)