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:
""" AtCoder """

import collections

n = int(input())
v = list(map(int, input().split()))
a = []
b = []
for i in range(0, n, 2):
    a.append(v[i])
    b.append(v[i + 1])

aa = collections.Counter(a)
bb = collections.Counter(b)

ans = aa.most_common()[0][1] + bb.most_common()[0][1]

if aa.most_common()[0][0] == bb.most_common()[0][0]:
    if len(aa.most_common()) == 1:
        ans = aa.most_common()[0][1]
    elif len(bb.most_common()) == 1:
        ans = bb.most_common()[0][1]
    else:
        ans = min(aa.most_common()[1][1] + bb.most_common()[0][1], aa.most_common()[0][1] + bb.most_common()[1][1])

print(len(a) + len(b) - ans)

Submission status: Wrong Answer

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

v_even = defaultdict(int)
v_odd = defaultdict(int)

for k in range(n//2):
  v_even[V[2*k]] += 1
  v_odd[V[2*k + 1]] += 1

even_max = 0
even_max2 = 0
for k, v in v_even.items():
  if v > even_max:
    even_max = v
    even_num = k
  else:
    even_max2 = max(even_max2, v)

odd_max = 0
odd_max2 = 0
for k, v in v_odd.items():
  if v > odd_max:
    odd_max = v
    odd_num = k
  else:
    odd_max2 = max(odd_max2, v)

if  even_num != odd_num:
  print(n - even_max - odd_max)
else:
  print(n - max(even_max + odd_max2, even_max2 + odd_max))

Submission status: Wrong Answer

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

v_even = []
v_odd = []
for k in range(n//2):
  v_even.append(V[2*k])
  v_odd.append(V[2*k + 1])
v_even = np.array(v_even)
v_odd = np.array(v_odd)
cnt_even = 0
cnt_even2= 0
cnt_odd = 0
cnt_odd2 = 0
for num in set(v_even):
  a = (v_even == num).sum()
  if cnt_even < a:
    cnt_even = a
    num_even = num
  elif cnt_even2 < a:
    cnt_even2 = a
    num_even2 = num
for num in set(v_odd):
  a = (v_odd == num).sum()
  if cnt_odd < a:
    cnt_odd = a
    num_odd = num
  elif cnt_odd2 < a:
    cnt_odd2 = a
    num_odd2 = num
if num_even != num_odd:
  print(n - cnt_even - cnt_odd)
else:
  print(n - max(cnt_even + cnt_odd2, cnt_even2 + cnt_odd))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    v = LI()
    d = [defaultdict(int) for i in range(2)]
    for i in range(n):
        d[i%2][v[i]] += 1
    if len(d[0].keys()) == len(d[1].keys()) == 1:
        if d[0].keys() == d[1].keys():
            ans = n//2
        else:
            d = [list(d[i].values()) for i in range(2)]
            ans = sum(d[0])-max(d[0])+sum(d[1])-max(d[1])
    else:
        d = [sorted(list(d[i].items()),key = lambda x:-x[1]) for i in range(2)]
        if d[0][0][0] != d[1][0][0]:
            ans = -d[0][0][1]-d[1][0][0]
            for i in range(len(d[0])):
                ans += d[0][i][1]
            for i in range(len(d[1])):
                ans += d[1][i][1]
        else:
            ans = -d[0][0][1]-d[1][0][1]
            for i in range(len(d[0])):
                ans += d[0][i][1]
            for i in range(len(d[1])):
                ans += d[1][i][1]
            ans2 = -d[0][0][1]-d[1][0][1]
            for i in range(len(d[0])):
                ans2 += d[0][i][1]
            for i in range(len(d[1])):
                ans2 += d[1][i][1]
            ans = min(ans,ans2)
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    v = LI()
    d = [defaultdict(int) for i in range(2)]
    for i in range(n):
        d[i%2][v[i]] += 1
    if len(d[0].keys()) == len(d[1].keys()) == 1:
        if d[0].keys() == d[1].keys():
            ans = n//2
        else:
            d = [list(d[i].values()) for i in range(2)]
            ans = sum(d[0])-max(d[0])+sum(d[1])-max(d[1])
    else:
        d = [list(d[i].values()) for i in range(2)]
        ans = sum(d[0])-max(d[0])+sum(d[1])-max(d[1])
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    v = LI()
    d = [defaultdict(int) for i in range(2)]
    for i in range(n):
        d[i%2][v[i]] += 1
    if d[0] == d[1]:
        ans = n//2
    else:
        d = [list(d[i].values()) for i in range(2)]
        ans = sum(d[0])-max(d[0])+sum(d[1])-max(d[1])
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    v = LI()
    d = [defaultdict(int) for i in range(2)]
    for i in range(n):
        d[i%2][v[i]] += 1
    d = [list(d[i].values()) for i in range(2)]
    if d[0] == d[1]:
        ans = n//2
    else:
        ans = sum(d[0])-max(d[0])+sum(d[1])-max(d[1])
    print(ans)
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    v = LI()
    d1 = defaultdict(int)
    d0 = defaultdict(int)
    for num, a in enumerate(v):
        if num % 2:
            d1[a] += 1
        else:
            d0[a] += 1
    A = list(d0.items())
    A.sort(key = lambda x: x[1], reverse = True)
    A = A[:2]
    A.append((0,0))
    B = list(d1.items())
    B.sort(key = lambda x: x[1], reverse = True)
    B = B[:2]
    B.append((0,0))
    if A[0][0] == B[0][0]:
        if A[0][1] >= B[0][0]:
            A = A[0][1]
            B = B[1][1]
        else:
            A = A[1][1]
            B = B[0][1]
    else:
        #print(A,B)
        A = A[0][1]
        B = B[0][1]
    a = n // 2
    b = (n + 1) // 2
    print(a+b-A-B)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        odd.append(v[i])
    else:
        even.append(v[i])

if len(set(odd)) == len(set(even)) == 1 and set(odd) == set(even):
    print(n//2)
else:
    o = Counter(odd)
    e = Counter(even)
    mode_odd = o.most_common(2)
    mode_even = e.most_common(2)
    if mode_odd[0][0] != mode_even[0][0]:
        cnt = n - mode_odd[0][1] - mode_even[0][1]
    else:
        if mode_odd[0][1] >= mode_even[0][1]:
            cnt = n - mode_odd[0][1] - mode_even[1][1]
        else:
            cnt = n - mode_even[0][1] - mode_odd[1][1]
    print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(n):
    if i % 2 == 0:
        odd.append(v[i])
    else:
        even.append(v[i])

if len(set(odd)) == len(set(even)) == 1 and set(odd) == set(even):
    print(n//2)
else:
    o = Counter(odd)
    e = Counter(even)
    mode_odd = o.most_common(1)
    mode_even = e.most_common(1)
    cnt = n - mode_odd[0][1] - mode_even[0][1]
    print(cnt)

Submission status: Wrong Answer

Solution code:
import collections as cl


def count_most_common(n):
    c = cl.Counter(n)
    return c.most_common()[0][1]


n = int(input())
v = input().split()

answer = 0
if(count_most_common(v) == len(v)):
    answer = len(v) // 2
else:
    answer = len(v) - count_most_common(v[::2]) - count_most_common(v[1::2])
print(answer)

Submission status: Wrong Answer

Solution code:
import collections as cl


def count_most_common(n):
    c = cl.Counter(n)
    return c.most_common()[0][1]


n = int(input())
v = input().split()

answer = len(v) - count_most_common(v[::2]) - count_most_common(v[1::2])
print(answer)

Submission status: Wrong Answer

Solution code:

def solve(v):
    e = v[0::2]
    o = v[1::2]
    e_mode, e_mode2 = mode(e)
    o_mode, o_mode2 = mode(o)
    if e_mode != o_mode:
        return distance(e, o, e_mode, o_mode)
    else:
        if e_mode2 is None and o_mode2 is not None:
            return distance(e, o, e_mode, o_mode2)
        elif e_mode2 is not None and o_mode2 is None:
            return distance(e, o, e_mode2, o_mode)
        elif e_mode2 is None and o_mode is None:
            return len(e)
        else:
            return min(distance(e, o, e_mode, o_mode2), distance(e, o, e_mode2, o_mode))


def mode(arr):
    arr = sorted(arr)

    mode = None
    mode_count = 0
    mode2 = None
    mode2_count = 0

    curr_num = None
    curr_count = 0

    for num in arr:
        if curr_num is None:
            curr_num = num
            curr_count = 1
        elif curr_num == num:
            curr_count += 1
        else:
            if curr_count >= mode_count:
                mode2 = mode
                mode2_count = mode_count
                mode = curr_num
                mode_count = curr_count
            curr_num = num
            curr_count = 1
    if curr_count >= mode_count:
        mode2 = mode
        mode2_count = mode_count
        mode = curr_num
        mode_count = curr_count
    return mode, mode2


def distance(e, o, e_num, o_num):
    distance = 0
    for num in e:
        if num != e_num:
            distance += 1
    for num in o:
        if num != o_num:
            distance += 1
    return distance


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

print(solve(v))

Submission status: Wrong Answer

Solution code:

def solve(v):
    e = v[0::2]
    o = v[1::2]
    e_mode, e_mode2 = mode(e)
    o_mode, o_mode2 = mode(o)
    if e_mode != o_mode:
        return distance(e, o, e_mode, o_mode)
    else:
        if e_mode2 is None and o_mode2 is not None:
            return distance(e, o, e_mode, o_mode2)
        elif e_mode2 is not None and o_mode2 is None:
            return distance(e, o, e_mode2, o_mode)
        elif e_mode2 is None and o_mode is None:
            return len(e)
        else:
            return min(distance(e, o, e_mode, o_mode2), distance(e, o, e_mode2, o_mode))


def mode(arr):
    arr = sorted(arr)

    mode = None
    mode_count = 0
    mode2 = None
    mode2_count = 0

    curr_num = None
    curr_count = 0

    for num in arr:
        if curr_num is None:
            curr_num = num
            curr_count = 1
        elif curr_num == num:
            curr_count += 1
        else:
            if curr_count >= mode_count:
                mode2 = mode
                mode2_count = mode_count
                mode = curr_num
                mode_count = curr_count
            curr_num = num
            curr_count = 1
    if curr_count >= mode_count:
        mode2 = mode
        mode2_count = mode_count
        mode = curr_num
        mode_count = curr_count
    return mode, mode2


def distance(e, o, e_num, o_num):
    distance = 0
    for num in e:
        if num != e_num:
            distance += 1
    for num in o:
        if num != o_num:
            distance += 1
    return distance


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

print(mode(v))

Submission status: Wrong Answer

Solution code:

def solve(v):
    e = v[0::2]
    o = v[1::2]
    e_mode, e_mode2 = mode(e)
    o_mode, o_mode2 = mode(o)
    if e_mode != o_mode:
        return distance(e, o, e_mode, o_mode)
    else:
        if e_mode2 is None and o_mode2 is not None:
            return distance(e, o, e_mode, o_mode2)
        elif e_mode2 is not None and o_mode2 is None:
            return distance(e, o, e_mode2, o_mode)
        elif e_mode2 is None and o_mode is None:
            return len(e)
        else:
            return min(distance(e, o, e_mode, o_mode2), distance(e, o, e_mode2, o_mode))


def mode(arr):
    sorted(arr)

    mode = None
    mode_count = 0
    mode2 = None
    mode2_count = 0

    curr_num = None
    curr_count = 0

    for num in arr:
        if curr_num is None:
            curr_num = num
            curr_count = 1
        elif curr_num == num:
            curr_count += 1
        else:
            if curr_count >= mode_count:
                mode2 = mode
                mode2_count = mode_count
                mode = curr_num
                mode_count = curr_count
            curr_num = num
            curr_count = 1
    if mode is None:
        mode = curr_num
        mode_count = curr_count
    return mode, mode2

def distance(e, o, e_num, o_num):
    distance = 0
    for num in e:
        if num != e_num:
            distance += 1
    for num in o:
        if num != o_num:
            distance += 1
    return distance


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

print(solve(v))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=v[0::2]
b=v[1::2]
c=dict()
d=dict()

for i in a:
  if i in c:
    c[i]+=1
  else:
    c[i]=1
for j in b:
  if j in d:
    d[j]+=1
  else:
    d[j]=1

e=sorted([[c,v] for v,c in c.items()],reverse=True)
f=sorted([[c,v] for v,c in d.items()],reverse=True)

if e[0][1]!=f[0][1]:
  print(n-e[0][0]-f[0][0])
elif e[0][0]>f[0][0]:
  print(n-e[0][0]-f[1][0])
elif e[0][0]<f[0][0]:
  print(n-e[1][0]-f[0][0])
elif e[0][0]==f[0][0] and e[0][1]==f[0][1]:
  print(n-e[0][0]-min(len(a),len(b)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a1 = [a[x*2] for x in range(n//2+n%2)]
a2 = [a[x*2+1] for x in range(n//2)]
sa1 = set(a1)
sa2 = set(a2)
a1set = []
a2set = []

for k in sa1:
    a1set.append([k,a1.count(k)])
for k in sa2:
    a2set.append([k,a2.count(k)])

a1set.sort(key=lambda x:x[1])
a2set.sort(key=lambda x:x[1])

while True:
    if a1set[0][0] != a2set[0][0]:
        print(n-a1set[0][1]-a2set[0][1])
        exit(0)
    elif len(a1set) > 1 and len(a2set) > 1:
        if a1set[0][1] + a2set[1][1] > a2set[0][1] + a1set[1][1]:
            a2set.pop(0)
        else:
            a1set.pop(0)
    elif len(a1set) > 1:
        a1set.pop(0)
    elif len(a2set) > 1:
        a2set.pop(0)
    else:
        print(n - a1set[0][1])
        exit(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
element = [int(i) for i in input().split()]
ele_len = len(set(element))

if ele_len == 2:
    print(0)
elif ele_len < 2:
    print(abs(ele_len - n)-1)
elif ele_len > 2:
    print(abs(ele_len-n))

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=open(0).read().split()
n=int(n)
a=[v[s]for s in range(0,n,2)]
b=[v[s]for s in range(1,n,2)]
c=Counter(a).most_common()
d=Counter(b).most_common()
#print(c,d)
if len(c)==1 and len(d)==1:
  if c==d:
    print(n//2)
  else:
    print(0)
elif c[0][1]!=d[0][1]:
  print(sum([s[1]for s in c[1:]])+sum([s[1]for s in d[1:]]))
else:
  x=sum([s[1]for s in c[1:]])+d[0][1]+sum([s[1]for s in d[2:]])
  y=sum([s[1]for s in d[1:]])+c[0][1]+sum([s[1]for s in c[2:]])
  print(min(x,y))

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=open(0).read().split()
n=int(n)
a=[v[s]for s in range(0,n,2)]
b=[v[s]for s in range(1,n,2)]
c=Counter(a).most_common()
d=Counter(b).most_common()
print(c,d)
if len(c)==1 and len(d)==1:
  if c==d:
    print(n//2)
  else:
    print(0)
elif c[0][1]!=d[0][1]:
  print(sum([s[1]for s in c[1:]])+sum([s[1]for s in d[1:]]))
else:
  x=sum([s[1]for s in c[1:]])+d[0][1]+sum([s[1]for s in d[2:]])
  y=sum([s[1]for s in d[1:]])+c[0][1]+sum([s[1]for s in c[2:]])
  print(min(x,y))

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=open(0).read().split()
n=int(n)
a=[v[s]for s in range(0,n,2)]
b=[v[s]for s in range(1,n,2)]
#print(Counter(a).most_common(),Counter(b).most_common())
c=Counter(a).most_common()
d=Counter(b).most_common()
if c[0][1]!=d[0][1]:
  print(sum([s[1]for s in c[1:]])+sum([s[1]for s in d[1:]]))
else:
  if (len(c)and len(d))==1:
    if c==d:
      print(n//2)
    else:
      print(0)
  else:
    x=sum([s[1]for s in c[1:]])+d[0][1]+sum([s[1]for s in d[2:]])
    y=sum([s[1]for s in d[1:]])+c[0][1]+sum([s[1]for s in c[2:]])
    print(min(x,y))

Submission status: Wrong Answer

Solution code:
#

Submission status: Wrong Answer

Solution code:
n=int(input())
g=[]
k=[]
v=list(map(int,input().split()))
for i in range(n):
    if(i%2==0):
        g.append(v[i])
    else:
        k.append(v[i])

import collections
ans=0
ans+=len(g)-list(collections.Counter(g).items())[-1][1]
ans+=len(k)-list(collections.Counter(k).items())[-1][1]
if(len(v)==list(collections.Counter(v).items())[-1][1]):
    print(len(v)//2)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
V=[int(x) for x in input().split()]
A=[[n,0] for n in range((10**5)+1)]
B=[[n,0] for n in range((10**5)+1)]
for i in range(len(V)):
    if (i % 2 == 0):
        A[V[i]][1]+=1
    else:
        B[V[i]][1]+=1

def sortsecond(i):
    return i[1]

A.sort(key=sortsecond, reverse=True)
B.sort(key=sortsecond, reverse=True)
a=A[0]
b=B[0]
if a[0]==b[0]:
    if A[1][1]+B[1][1]==0:
        b[1]=0
    elif a[1]>B[1][1]:
        b=B[1]
    else:
        a=A[1]

print(len(V)-(a[1]+b[1]))

Submission status: Wrong Answer

Solution code:
N=int(input())
V=[int(x) for x in input().split()]
A=[[n,0] for n in range((10**5)+1)]
B=[[n,0] for n in range((10**5)+1)]
for i in range(len(V)):
    if (i % 2 == 0):
        A[V[i]][1]+=1
    else:
        B[V[i]][1]+=1

def sortsecond(i):
    return i[1]

A.sort(key=sortsecond, reverse=True)
B.sort(key=sortsecond, reverse=True)
a=A[0]
b=B[0]
if a[0]==b[0]:
    if A[1][1]+B[1][1]==0:
        b[1]=0
    elif a[1]>b[1]:
        b=B[1]
    else:
        a=A[1]

print(len(V)-a[1]-b[1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

n = int(input())
a = input().split()
o = a[1::2]
e = a[0::2]

if o == e:
    print(int(n/2))
    sys.exit()

o1= Counter(o).most_common()[0][1]
e1 = Counter(e).most_common()[0][1]

try:
    o2= Counter(o).most_common()[1][1]
except:
    print(int(n/2 - e1))
    sys.exit()

try:
    e2 = Counter(e).most_common()[1][1]
except:
    print(int(n/2 - o1))
    sys.exit()

print(min(n - o1 - e2, n - o2 - e1))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

n = int(input())
a = input().split()
o = a[1::2]
e = a[0::2]

o1= Counter(o).most_common()[0][1]

e1 = Counter(e).most_common()[0][1]
try:
    o2= Counter(o).most_common()[1][1]
except:
    print(int(n/2 - e1))
    sys.exit()

try:
    e2 = Counter(e).most_common()[1][1]
except:
    print(int(n/2 - o1))
    sys.exit()

print(min(n - o1 - e2, n - o2 - e1))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

n = int(input())
a = input().split()
o = a[1::2]
e = a[0::2]

o1= Counter(o).most_common()[0][1]

e1 = Counter(e).most_common()[0][1]
try:
    o2= Counter(o).most_common()[1][1]
except:
    print(int(n/2 - e1))
    sys.exit()

try:
    e2 = Counter(e).most_common()[1][1]
except:
    print(int(n/2 - e1))
    sys.exit()

print(min(n - o1 - e2, n - o2 - e1))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = input().split()
o = a[1::2]
e = a[0::2]

o1= Counter(o).most_common()[0][1]
try:
    o2= Counter(o).most_common()[1][1]
except:
    o2 = o1

e1 = Counter(e).most_common()[0][1]

try:
    e2 = Counter(e).most_common()[1][1]
except:
    e2 = e1

print(min(n - o1 - e2, n - o2 - e1))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(zip(*[iter(input().split())]*2))

c = Counter(a).most_common()[0][1]

if c == n:
    print(0)
else:
    print(n - c*2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a).most_common()[:3]

if len(c) >= 2:
    print(n-c[0][1]-c[1][1])
elif  len(c) == 1:
    print(int(n/2))
else:
    print(int((c[0][1] - c[1][1]) /2))

Submission status: Wrong Answer

Solution code:
n = int(input())
sequence = [int(x) for x in input().split(" ")]
odds = sequence[::2]
evens = sequence[1::2]
odd_counts = {}
even_counts = {}
for i in odds:
    odd_counts[i] = odd_counts.get(i, 0) + 1
for i in evens:
    even_counts[i] = even_counts.get(i, 0) + 1
odd_sorted = sorted(odd_counts.items(), key=lambda x: x[1])
even_sorted = sorted(even_counts.items(), key=lambda x: x[1])
best_even_num, best_even_count = even_sorted[0]
best_odd_num, best_odd_count = odd_sorted[0]
if best_even_num == best_odd_num:
    second_best_even_count = even_sorted[1][1] if len(even_sorted) > 1 else 0
    second_best_odd_count = odd_sorted[1][1] if len(odd_sorted) > 1 else 0
    print(max(n - best_even_count - second_best_odd_count, n - second_best_even_count - best_odd_count))
else:
    print(n - best_even_count - best_odd_count)

Submission status: Wrong Answer

Solution code:
n = int(input())
sequence = [int(x) for x in input().split(" ")]
odds = sequence[::2]
evens = sequence[1::2]
odd_counts = {}
even_counts = {}
for i in odds:
    odd_counts[i] = odd_counts.get(i, 0) + 1
for i in evens:
    even_counts[i] = even_counts.get(i, 0) + 1
odd_sorted = sorted(odd_counts.items(), key=lambda x: x[1])
even_sorted = sorted(even_counts.items(), key=lambda x: x[1])
best_even_num, best_even_count = even_sorted[0]
best_odd_num, best_odd_count = odd_sorted[0]
if best_even_num == best_odd_num:
    if best_odd_count >= best_even_count:
        if len(even_sorted) > 1:
            best_even_num, best_even_count = even_sorted[1]
        else:
            best_even_count = 0
    else:
        if len(odd_sorted) > 1:
            best_odd_count = odd_sorted[1][1]
        else:
            best_odd_count = 0
print(n - best_even_count - best_odd_count)

Submission status: Wrong Answer

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


a = vlist[::2]
b = vlist[1::2]

Ma, Mb = max(a), max(b)


x = len(a) - a.count(Ma)
y = len(b) - b.count(Mb)

if len(set(vlist)) == 1:
    print(min(len(a), len(b)))
else:
    print(x+y)

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=map(int,open(0).read().split())
a=Counter(v[::2]).most_common()+[(0,0)]
b=Counter(v[1::2]).most_common()+[(0,0)]
print(a,b)
if a[0][0]==b[0][0]:
    print(min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1]))
else:
    print(n-a[0][1]-b[0][1])

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=map(int,open(0).read().split())
a=Counter(v[::2]).most_common()+[(0,0)]
b=Counter(v[1::2]).most_common()+[(0,0)]
if a[0][0]==b[0][0]:
    print(min(n-a[0][1]-b[1][1],n-a[1][1],b[0][1]))
else:
    print(n-a[0][1]-b[0][1])

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=open(0).read().split()
n=int(n)
a=[v[s]for s in range(0,n,2)]
b=[v[s]for s in range(1,n,2)]
#print(Counter(a).most_common(),Counter(b).most_common())
c=Counter(a).most_common()
d=Counter(b).most_common()
if c[0][1]!=d[0][1]:
  print(sum([s[1]for s in c[1:]])+sum([s[1]for s in d[1:]]))
else:
  if len(c)and len(d)==1:
    if c==d:
      print(n//2)
    else:
      print(0)
  else:
    x=sum([s[1]for s in c[1:]])+d[0][1]+sum([s[1]for s in d[2:]])
    y=sum([s[1]for s in d[1:]])+c[0][1]+sum([s[1]for s in c[2:]])
    print(min(x,y))

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=open(0).read().split()
n=int(n)
a=[v[s]for s in range(0,n,2)]
b=[v[s]for s in range(1,n,2)]
print(Counter(a).most_common(),Counter(b).most_common())
c=Counter(a).most_common()
d=Counter(b).most_common()
if c[0][1]!=d[0][1]:
  print(sum([s[1]for s in c[1:]])+sum([s[1]for s in d[1:]]))
else:
  if len(c)and len(d)==1:
    if c==d:
      print(n//2)
    else:
      print(0)
  else:
    x=sum([s[1]for s in c[1:]])+d[0][1]+sum([s[1]for s in d[2:]])
    y=sum([s[1]for s in d[1:]])+c[0][1]+sum([s[1]for s in c[2:]])
    print(min(x,y))

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=open(0).read().split()
n=int(n)
w=[(v[s],v[s+1]) for s in range(0,int(n),2)]
a=Counter(w).most_common()
#print(a)
common=a[0][0]
ans=0
if len(a)==1:
  if len(set(common))==1:
    print(n//2)
  else:
    print(0)
else:
  for s in a[1:]:
#    print(s[0][0],common[0],s[0][1],common[1])
#    print((s[0][0]!=common[0]),(s[0][1]!=common[1]))
    ans+=(s[0][0]!=common[0])+(s[0][1]!=common[1])
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=open(0).read().split()
w=[(v[s],v[s+1]) for s in range(0,int(n),2)]
a=Counter(w).most_common()

ans=0
if len(a)==1:
  if a[0][0][0]==a[0][0][1]:
    print(int(n)//2)
    exit()
  else:
    print(0)
    exit()
common=a[0][0]
#print(a)
#print(common)
for s in a[1:]:
  ans+=len(set(s[0])|set(common))-2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=open(0).read().split()
w=[(v[s],v[s+1]) for s in range(0,int(n),2)]
a=Counter(w).most_common()
#print(a)
common=a[0][0]
ans=0
if len(a)==1:
  print(0)
  exit()
for s in a[1:]:
  ans+=len(set(s[0])|set(common))-2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import*
n,*v=map(int,open(0).read().split())
a=Counter(v).most_common(2)
try:print(n-a[0][1]-a[1][1])
except:print(n//2)