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

odd = dict()
even = dict()

for i in range(n):
    if i % 2 == 0:
        if even.get(v[i]) == None:
            even[v[i]] = 1
        else:
            even[v[i]] += 1
    else:
        if odd.get(v[i]) == None:
            odd[v[i]] = 1
        else:
            odd[v[i]] += 1


odd_max_v = max(odd.values())
odd_max_key = max(odd, key = odd.get)
even_max_v = max(even.values())
even_max_key = max(even, key = even.get)

ans = n
if odd_max_key != even_max_key:
    ans = n - odd_max_v - even_max_v
else:
    odd[odd_max_key] = 0
    even[even_max_key] = 0

    odd_max_v2 = max(odd.values())
    even_max_v2 = max(even.values())

    ans = min(n - odd_max_v - even_max_v2, n - odd_max_v2 - even_max_v2)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

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

    A = []
    B = []
    for i in range(n // 2):
        A.append(v[2 * i])
        B.append(v[2 * i + 1])

    a = {}
    for i in A:
        a[i] = 0
    for i in A:
        a[i] += 1
    b = {}
    for i in B:
        b[i] = 0
    for i in B:
        b[i] += 1

    for i in a.keys():
        if a[i] == max(a.values()):
            ka = i
            break
    for i in b.keys():
        if b[i] == max(b.values()):
            kb = i
            break

    ans = 0
    for i in a.keys():
        if i != ka:
            ans += a[i]
    for i in b.keys():
        if i != kb:
            ans += b[i]

    if len(set(v)) == 1:
        ans += n // 2

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(raw_input())
ais = map(int,raw_input().split()) 
cc = collections.Counter(ais)
m = 0
s = sorted([(cc[k],k) for k in cc])
s = s[::-1][:2]

def f(u,v,ais):
	vs = [u,v]
	e = 0
	c = 0
	
	ais = [ai for ai in ais if ai == u or ai == v]
	for ai in ais:
		if vs[e] == ai:
			c += 1
			e = 1 - e
	return c


def g(u,ais):
	c = 0
	for a in ais:
		if a == u:
			c += 1

	return c/2
if len(cc) >= 2:
	m = max(m, f(s[0][1], s[1][1], ais))
	m = max(m, f(s[1][1], s[0][1], ais))
if len(cc) >= 1:
	m = max(m, g(s[0][1], ais))

print m

Submission status: Wrong Answer

Solution code:

n = int(raw_input())
h = {}
un = set()
for i,b in enumerate(map(int,raw_input().split())):

	for a in un:
		if a != b:
			h[(a,b)] = (h[(b,a)] if (b,a) in h else 1) + 1
	un.add(b)

print n - max(h.values() if h else [0])

Submission status: Wrong Answer

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

odd_dict = {0: 0}
for i in v_list[0::2]:
    odd_dict[i] = 0

for i in v_list[0::2]:
    odd_dict[i] += 1

even_dict = {0: 0}
for i in v_list[1::2]:
    even_dict[i] = 0

for i in v_list[1::2]:
    even_dict[i] += 1

odd_k, odd_v = 0, 0
for k, v in odd_dict.items():
    if v > odd_v:
        odd_k = k
        odd_v = v

even_k, even_v = 0, 0
for k, v in even_dict.items():
    if v > even_v:
        even_k = k
        even_v = v

ans_odd = n // 2 - odd_v
ans_even = n // 2 - even_v

if ans_odd == ans_even:
    del odd_dict[odd_k]
    del even_dict[even_k]

    odd_v = max(odd_dict.values())
    even_v = max(even_dict.values())

    if even_v > odd_v:
        ans_odd = n // 2 - odd_v
    elif even_v < odd_v:
        ans_even = n // 2 - even_v
    else:
        ans_odd = n // 2

ans = ans_odd + ans_even
print(ans)

Submission status: Wrong Answer

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

odd_dict = {0: 0}
for i in v_list[0::2]:
    odd_dict[i] = 0

for i in v_list[0::2]:
    odd_dict[i] += 1

even_dict = {0: 0}
for i in v_list[1::2]:
    even_dict[i] = 0

for i in v_list[1::2]:
    even_dict[i] += 1

print(odd_dict)
print(even_dict)

odd_k, odd_v = 0, 0
for k, v in odd_dict.items():
    if v > odd_v:
        odd_k = k
        odd_v = v

even_k, even_v = 0, 0
for k, v in even_dict.items():
    if v > even_v:
        even_k = k
        even_v = v

ans_odd = n // 2 - odd_v
ans_even = n // 2 - even_v

if ans_odd == ans_even:
    del odd_dict[odd_k]
    del even_dict[even_k]

    odd_v = max(odd_dict.values())
    even_v = max(even_dict.values())

    if even_v > odd_v:
        ans_odd = n // 2 - odd_v
    elif even_v < odd_v:
        ans_even = n // 2 - even_v
    else:
        pass

ans = n - ans_odd - ans_even
print(ans)

Submission status: Wrong Answer

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

odd_dict = {}
for i in v_list[0::2]:
    odd_dict[i] = 0

for i in v_list[0::2]:
    odd_dict[i] += 1

even_dict = {}
for i in v_list[1::2]:
    even_dict[i] = 0

for i in v_list[1::2]:
    even_dict[i] += 1

odd_k, odd_v = 0, 0
for k, v in odd_dict.items():
    if v > odd_v:
        odd_k = k
        odd_v = v

even_k, even_v = 0, 0
for k, v in even_dict.items():
    if v > even_v:
        even_k = k
        even_v = v

if odd_k == even_k:
    if len(odd_dict) == len(even_dict) == 1:
        odd_v = 0
    elif len(odd_dict) == 1:
        del even_dict[even_k]
        even_v = max(even_dict.values())
    elif len(even_dict) == 1:
        del odd_dict[odd_k]
        odd_v = max(odd_dict.values())
    elif even_v > odd_v:
        del odd_dict[odd_k]
        odd_v = max(odd_dict.values())
    elif even_v < odd_v:
        del even_dict[even_k]
        even_v = max(even_dict.values())
    else:
        pass

ans = n - odd_v - even_v
print(ans)

Submission status: Wrong Answer

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

odd_dict = {}
for i in v_list[0::2]:
    odd_dict[i] = 0

for i in v_list[0::2]:
    odd_dict[i] += 1

even_dict = {}
for i in v_list[1::2]:
    even_dict[i] = 0

for i in v_list[1::2]:
    even_dict[i] += 1

odd_k, odd_v = 0, 0
even_k, even_v = 0, 0

for k, v in odd_dict.items():
    if v > odd_v:
        odd_k = k
        odd_v = v

for k, v in even_dict.items():
    if v > even_v:
        even_k = k
        even_v = v

if odd_k == even_k:
    if even_v > odd_v:
        del odd_dict[odd_k]
        if len(odd_dict) == 0:
            odd_v = int(n / 2)
        else:
            odd_v = max(odd_dict.values())
    else:
        del even_dict[even_k]
        if len(even_dict) == 0:
            even_v = int(n / 2)
        else:
            even_v = max(even_dict.values())

ans = n - odd_v - even_v
print(ans)

Submission status: Wrong Answer

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

if len(set(v)) == 1:
    print(int(n / 2))
else:
    ans = n
    d_odd = {}
    for i in v[0::2]:
        if i in d_odd:
            d_odd[i] += 1
        else:
            d_odd[i] = 1

    max_odd = max({v for k, v in d_odd.items()})
    ans -= max_odd

    d_even = {}
    for i in v[1::2]:
        if i in d_even:
            d_even[i] += 1
        else:
            d_even[i] = 1

    max_even = max({v for k, v in d_even.items()})
    ans -= max_even

    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v))==1:
  print(n//2)
  exit()
  
mc1 = Counter([v[i] for i in range(0,n,2)]).most_common()
mc2 = Counter([v[i] for i in range(1,n,2)]).most_common()

ans = 0
if mc1[0][0] != mc2[0][0]:
  for i in range(1,len(mc1)):
    ans += mc1[i][1]

  for i in range(1,len(mc2)):
    ans += mc2[i][1]
    
else:
  if mc1[0][1] < mc2[0][1]:
    mc1,mc2 = mc2,mc1
  for i in range(1,len(mc1)):
    ans += mc1[i][1]
  for i in range(len(mc2)):
    if i == 1:continue
    ans += mc2[i][1]
  
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v))==1:
  print(n//2)
  exit()
  
mc1 = Counter([v[i] for i in range(0,n,2)]).most_common()
mc2 = Counter([v[i] for i in range(1,n,2)]).most_common()

ans = 0
for i in range(1,len(mc1)):
  ans += mc1[i][1]
  
for i in range(1,len(mc2)):
  ans += mc2[i][1]
  
print(ans)

Submission status: Wrong Answer

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


C_even = collections.Counter(v0)
VC_list_even = C_even.most_common(2)
C_add = collections.Counter(v1)
VC_list_add = C_add.most_common(2)


if len(VC_list_even) >= 2 and len(VC_list_add) >= 2:
    v_even_1, c_even_1 = VC_list_even[0]
    v_even_2, c_even_2 = VC_list_even[1]
    v_add_1, c_add_1 = VC_list_add[0]
    v_add_2, c_add_2 = VC_list_add[1]

    if v_even_1 == v_add_1:
        if c_even_1 > c_add_1:
            deduct_num = c_even_1 + c_add_2
        else:
            deduct_num = c_even_2 + c_add_1
    else:
        deduct_num = c_even_1 + c_add_1
elif len(VC_list_even) >= 2 and len(VC_list_add) < 2:
    v_even_1, c_even_1 = VC_list_even[0]
    v_even_2, c_even_2 = VC_list_even[1]
    v_add_1, c_add_1 = VC_list_add[0]

    if v_even_1 == v_add_1:
        deduct_num = c_even_2 + c_add_1
    else:
        deduct_num = c_even_1 + c_add_1
elif len(VC_list_even) < 2 and len(VC_list_add) >= 2:
    v_even_1, c_even_1 = VC_list_even[0]
    v_add_1, c_add_1 = VC_list_add[0]
    v_add_2, c_add_2 = VC_list_add[1]

    if v_even_1 == v_add_1:
        deduct_num = c_even_1 + c_add_2
    else:
        deduct_num = c_even_1 + c_add_1
else:
    v_even_1, c_even_1 = VC_list_even[0]
    v_add_1, c_add_1 = VC_list_add[0]

    if v_even_1 == v_add_1:
        deduct_num = c_even_1
    else:
        deduct_num = c_even_1 + c_add_1

ans = n - deduct_num
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
# 奇数列、偶数列でそれぞれ最大と2番目を調べる
a_odd = dict()
a_even = dict()
for i,x in enumerate(a):
  if i%2:
    a_odd[x] = 1 + (a_odd[x] if x in a_odd else 0)
  else:
    a_even[x] = 1 + (a_even[x] if x in a_even else 0)
# リストをソート
odd_l = sorted(a_odd.items(), reverse=True, key=lambda x:x[1])
even_l = sorted(a_even.items(), reverse=True, key=lambda x:x[1])
odd_l.append((0,0))
even_l.append((0,0))

if odd_l[0][0] != even_l[0][0]:
  print(n - odd_l[0][1] - even_l[0][1])
elif odd_l[0][1] > even_l[0][1]:
  print(n - odd_l[0][1] - even_l[1][1])
else:
  print(n - odd_l[1][1] - even_l[0][1])
#print(*odd_l)
#print(*even_l)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
# 奇数列、偶数列でそれぞれ最大と2番目を調べる
a_odd = dict()
a_even = dict()
for i,x in enumerate(a):
  if i%2:
    a_odd[x] = 1 + (a_odd[x] if x in a_odd else 0)
  else:
    a_even[x] = 1 + (a_even[x] if x in a_even else 0)
# リストをソート
odd_l = sorted(a_odd.items(), key=lambda x:x[1])
even_l = sorted(a_even.items(), key=lambda x:x[1])
odd_l.append((0,0))
even_l.append((0,0))

if odd_l[0][0] != even_l[0][0]:
  print(n - odd_l[0][1] - even_l[0][1])
elif odd_l[0][1] > even_l[0][1]:
  print(n - odd_l[0][1] - even_l[1][1])
else:
  print(n - odd_l[1][1] - even_l[0][1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

n = ini()
a = inl()
if len(set(a)) == n:
    print(n - 2)
elif len(set(a)) == 1:
    print(n//2)
else:
    f = {}
    s = {}
    for i in range(n):
        if i % 2 == 0:
            if a[i] not in f:
                f[a[i]] = 0
            f[a[i]] += 1
        else:
            if a[i] not in s:
                s[a[i]] = 0
            s[a[i]] += 1
    ans = sum(f.values()) - max(f.values()) + sum(s.values()) - max(s.values())
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
v=[int(x) for x in input().rstrip().split()]
  
done=[1]*n

if v.count(v[0])==n:
  print(n//2)
else:
  mi_1=float('inf')
  mi_2=float('inf')
  for i in range(2,n):
    if v[i]==v[i-2]:
      done[i]=done[i-2]+1

  for i in range(n):
    done[i]=abs(n//2-done[i])
  
  for i in range(n):
    if i%2==0:
      mi_2=min(mi_2,done[i])
    else:
      mi_1=min(mi_1,done[i])
    
  print(mi_1+mi_2)

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
v=[int(x) for x in input().rstrip().split()]
dic={}
for i in v:
  if i not in dic:
    dic[i]=1
  else:
    dic[i]+=1
l=[]


for i in dic: 
  l.append(abs(n//2-dic[i]))

l.sort()
ans=0
# print(l)
if len(l)==1:
  print(n//2)
else:
  for i in range(2):
    ans+=l[i]
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
v=[int(x) for x in input().rstrip().split()]
dic={}
for i in v:
  if i not in dic:
    dic[i]=1
  else:
    dic[i]+=1

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

now=0

for i in range(2):
  if dic[i][1]==n:
    print(n//2)
    sys.exit()
  now+=dic[i][1]
ans=n-now

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
u = list(map(int,input().split()))
ans = 0
for i in range(0,N-2,2):
    if(u[i]==u[i+2]):
        if(u[i]==u[i+1]):
            ans+=1
    else:
        ans +=1
for i in range(1,N-1,2):
    if(u[i]==u[i+2]):
        if(u[i]==u[i+1]):
            ans+=1
    else:
        ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
x = input().split()

w = len(x)

y = []

while True:
    
    a = x[0]
    y.append(x.count(a))
    x.remove(a)
    if len(set(x)) == 1:
        x = [4]
        break
    if len(x) == 0:
        break



y = sorted(y, reverse=True)

if len(y) ==1:
    print(2)
else:
    a = w -  (y[0] + y[1])
    print(a)

Submission status: Wrong Answer

Solution code:
x = input().split()

w = len(x)

y = []

while True:
    
    a = x[0]
    y.append(x.count(a))
    x.remove(a)
    if len(set(x)) == 1:
        x = [4]
        break
    if len(x) == 0:
        break



y = sorted(y, reverse=True)

if len(y) ==1:
    print(2)
else:
    a = w -  (y[0] + y[1])
    print(a)

Submission status: Wrong Answer

Solution code:

x = input().split()
x = set(x)

if len(x) == 2:
    print(0)
elif len(x) >2:
    x -= 2
    print(x)
elif len(x) == 1:
    print(2)

Submission status: Wrong Answer

Solution code:
X = input().split().pop(0)

X = set(X)


   
Y = len(X) - 2

if Y==1:
    print(1)
elif Y==0:
    print(0)
elif Y <0:
    Y =2
    print(Y)
else:
    print(Y)

Submission status: Wrong Answer

Solution code:
X = input().split()

X = set(X)


   
Y = len(X) - 2

if Y==1:
    print(1)
elif Y==0:
    print(0)
elif Y <0:
    Y =2
    print(Y)
else:
    print(Y)

Submission status: Wrong Answer

Solution code:
X = input().split()

X = set(X)


   
Y = len(X) - 2

if Y==1:
    print(1)
elif Y==0:
    print(0)
elif Y <0:
    Y =2
    print(Y)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
INF =  float("inf")
import bisect

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

e = defaultdict(int)
o = defaultdict(int)

e[INF] = 0
o[INF] = 0

ae = (N+1) // 2
ao = N - ae

for i in range(N):
    if i % 2 == 0:
        e[v[i]] += 1
    else:
        o[v[i]] += 1

e_list = sorted(list(e.values()), reverse=True)
o_list = sorted(list(o.values()), reverse=True)

if e_list[0] != o_list[0]:
    print(N-e_list[0]-o_list[0])
else:
    print(min(N-e_list[0]-o_list[1], N-e_list[1]-o_list[0]))

Submission status: Wrong Answer

Solution code:

X = input().split().pop(0)

X = set(X)

Y = len(X) - 2
print(Y)

Submission status: Wrong Answer

Solution code:

X = input().split()

X = set(X)

Y = len(X) - 2
print(Y)

Submission status: Wrong Answer

Solution code:

X = input().split()

X = set(X)
print(X)
Y = len(X) - 2
print(Y)

Submission status: Wrong Answer

Solution code:
X = input()

X = set(X)

Y = len(X) - 2
print(Y)

Submission status: Wrong Answer

Solution code:
num = int(input())
vals = list(map(int, input().split()))
ans = 0

for i in range(num - 2):
    if i % 2 == 0:
       temp = vals[i : i + 4]
       if temp.count(vals[i]) == 4:
           ans += 2
           
    if not vals[i] == vals[i + 2]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#input template
from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda: list(map(int, cin().split()))

def chars(): #function for taking string input as character array since string in python is immutable
    s = cin()
    return(list(s[:len(s) - 1]))

#print list	
def pl(a):	
	for val in a:
		cout(str(val) + ' ')
	cout('\n')
		
#main

def get_key(d, val): 
    for key, value in d.items(): 
         if val == value: 
             return key



n, = mp()
v = mp()

d1 = {}
d2 = {}

for i in range(n):
	if i%2:
		if v[i] in d1:
			d1[v[i]] += 1
		else:
			d1[v[i]] = 1
	else:
		if v[i] in d2:
			d2[v[i]] += 1
		else:
			d2[v[i]] = 1
l1 = sorted(d1.values())
l2 = sorted(d2.values())

if get_key(d1, l1[-1]) == get_key(d2, l2[-1]):
	if l1[-1] + l2[-1] == n:
		cout(str(n//2))
	else:
		if l1[-1] > l2[-1]:
			x = n//2 - l1[-1]
			y = n//2 - l2[-2] 
			cout(str(x+y))
		else:
			x = n//2 - l2[-1]
			y = n//2 - l1[-2]
			cout(str(x+y))
else:
	x = n//2 - l1[-1]
	y = n//2 - l2[-1]
	cout(str(x+y))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
odd = []
even  = []
for i in range(len(a)):
  if i%2==0:
    even.append(a[i])
  else:
    odd.append(a[i])
   
c = collections.Counter(odd)
d = collections.Counter(even)
keep = 0
for i,j in c.most_common():
  for k,l in d.most_common():
    if i==k: continue
    keep = max(keep,j+l)
print(n-keep)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
odd = []
even  = []
for i in range(len(a)):
  if i%2==0:
    even.append(a[i])
  else:
    odd.append(a[i])
   

c = collections.Counter(odd)
d = collections.Counter(even)


for i in range(n//2):
  if odd[i]==even[i]:
    print((len(odd)-c.most_common()[0][1])-(len(even)-d.most_common()[0][1])+odd.count(odd[i]))
    exit()
    
print(len(odd)-c.most_common()[0][1]+len(even)-d.most_common()[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
odd = []
even  = []
for i in range(len(a)):
  if i%2==0:
    even.append(a[i])
  else:
    odd.append(a[i])
    
for i in range(n//2):
  if odd[i]==even[i]:
    print(n-odd.count(max(odd))-even.count(max(even))+odd.count(odd[i]))
    exit()
  else:
    print(n-odd.count(max(odd))-even.count(max(even)))
    exit()

Submission status: Wrong Answer

Solution code:
import collections
n = int(raw_input())
ais = map(int, raw_input().split(' '))
cco = collections.Counter([ais[i] for i in range(len(ais)) if i % 2])
cce = collections.Counter([ais[i] for i in range(len(ais)) if i % 2 == 0])
cce = [(cce[k],k) for k in cce]
cce.sort(key = lambda x:-x[0])

t = n/2
if cce:
	m = t + cce[0][0]
else:
	m = 2*t
for colori in cco:
	for v,colorj in cce:
		if colorj != colori:
			m = min(m,t - cco[colori] + t - v)
			break

print m

Submission status: Wrong Answer

Solution code:
import collections
n = int(raw_input())
ais = map(int, raw_input().split(' '))
cco = collections.Counter([ais[i] for i in range(len(ais)) if i % 2])
cce = collections.Counter([ais[i] for i in range(len(ais)) if i % 2 == 0])
cce = [(cce[k],k) for k in cce]
cce.sort(key = lambda x:-x[0])

m = +float('inf')
t = n/2
for colori in cco:
	for v,colorj in cce:
		if colorj != colori:
			m = min(m,t - cco[colori] + t - v)
print m

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
from collections import Counter
cnt = Counter(v)
odd = v[::2]
even = v[1::2]
ocnt = sorted(Counter(odd).items(), key=lambda x: x[1])
ecnt = sorted(Counter(even).items(), key=lambda x: x[1])
if len(cnt) == 1:
    print(n//2)
elif len(ocnt) == 1 and len(ecnt) == 1:
    print(0)
else:
    ret = 0
    for i in range(len(ocnt) - 1):
        key, val = ocnt[i]
        ret += val
    for i in range(len(ecnt) - 1):
        key, val = ecnt[i]
        ret += val
    print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
from collections import Counter
cnt = Counter(v)
cnt = sorted(cnt.items(), key=lambda x: x[1])
if len(cnt) == 2:
    print(0)
elif len(cnt) == 1:
    print(n // 2)
else:
    ret = 0
    for i in range(len(cnt) - 2):
        key, val = cnt[i]
        ret += val
    print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split())) 
a = 0
ab = 0
ac = 0
b = [0]*(10**5+10)
c = [0]*(10**5+10)
d = [0]*(10**5+10)
e = [0]*(10**5+10)
for i in range(n-1):
  if v[i]==v[i+1]:
    a +=1
if(a == n-1):
  print(int(n/2))
else:
  for i in range(0,n,2):
    b[v[i]] = b[v[i]] + 1
  for j in range(1,n+1,2):
    c[v[j]] =c[v[j]] + 1
  d = sorted(b,reverse=True)
  e = sorted(c,reverse=True)
for s in range(10**5+1):
  if(d[0]==b[s]):
    ab = s
    break
for t in range(10**5+1):
  if(e[0]==c[t]):
    ac = t
    break
if(s==t):
  print(min(2*int(n/2)-d[0]-e[1],2*int(n/2)-d[1]-e[0]))
else: 
  f = int(n/2)-d[0]
  g = int(n/2)-e[0]
  print(f+g)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split())) 
a = 0
b = [0]*(10**5+10)
c = [0]*(10**5+10)
d = [0]*(10**5+10)
e = [0]*(10**5+10)
for i in range(n-1):
  if v[i]==v[i+1]:
    a +=1
if(a == n-1):
  print(int(n/2))
else:
  for i in range(0,n,2):
    b[v[i]] = b[v[i]] + 1
  for j in range(1,n+1,2):
    c[v[j]] =c[v[j]] + 1
  d = sorted(b,reverse=True)
  e = sorted(c,reverse=True)
  f = int(n/2)-d[0]
  g = int(n/2)-e[0]
  print(f+g)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
odd=[]
even=[]
for i in range(n):
  if (i+1)%2==1:
    odd.append(v[i])
  else:
    even.append(v[i])
    
if set(odd)==set(even):
  print(min(len(odd),len(even)))
else:
  #odd evenのそれぞれで最大回数出てくる要素を抜いて、残った要素の個数が答えになる
  #でも最大回数でてくる要素の抽出方法がわからない。ギブ
  pass

Submission status: Wrong Answer

Solution code:
#C
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
e = []
o = []
for i in range(len(v)):
    if i%2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
    
c_e = Counter(e)
c_o = Counter(o)

e_m = c_e.most_common()
o_m = c_o.most_common()

result1 = 10**5+1
result2 = 10**5+1
result3 = 10**5+1
r1 = len(e) - e_m[0][1]
r2 = len(o) - o_m[0][1]
result1 = r1 + r2
if o_m[0][0] == e_m[0][0]:
    if len(o_m) > 1:
        result2 = r1 + len(o) - o_m[1][1]
    if len(e_m) > 1:
        result3 = len(e)-e_m[1][1] + r2
    print(min(result2,result3))
else:
    print(result1)

Submission status: Wrong Answer

Solution code:
#C
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
e = []
o = []
for i in range(len(v)):
    if i%2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
    
c_e = Counter(e)
c_o = Counter(o)

e_m = c_e.most_common()
o_m = c_o.most_common()

result1 = 10**5+1
result2 = 10**5+1
result3 = 10**5+1
r1 = len(e) - e_m[0][1]
r2 = len(o) - o_m[0][1]
result1 = r1 + r2
if o_m[0][0] == e_m[0][0] and len(o_m) > 1:
    result2 = r1 + len(o) - o_m[1][1]
if o_m[0][0] == e_m[0][0] and len(e_m) > 1:
    result3 = len(e)-e_m[1][1] + r2

print(min(result1,result2,result3))

Submission status: Wrong Answer

Solution code:
#C
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
e = []
o = []
for i in range(len(v)):
    if i%2 == 0:
        e.append(v[i])
    else:
        o.append(v[i])
    
c_e = Counter(e)
c_o = Counter(o)

e_m = c_e.most_common()
o_m = c_o.most_common()

result1 = 10**5+1
result2 = 10**5+1
result3 = 10**5+1
r1 = len(e) - e_m[0][1]
r2 = len(o) - o_m[0][1]
result1 = r1 + r2
if len(o_m) > 1:
    result2 = r1 + len(o) - o_m[1][1]
if len(e_m) > 1:
    result3 = len(e)-e_m[1][1] + r2

print(min(result1,result2,result3))

Submission status: Wrong Answer

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

odd=[[0,0] for _ in range(10**5+1)]
even=[[0,0] for _ in range(10**5+1)]
ev=0
od=0


for i,v in enumerate(vv):
    if i%2==0:
        ev+=1
        even[v-1][0]=v-1
        even[v-1][1]+=1
    else:
        od+=1
        odd[v-1][0]=v-1
        odd[v-1][1]+=1

#print(odd)
#print(even)

even.sort()
odd.sort()

if even[-1][0]!=odd[-1][0]:
    print(ev-even[-1][1]+od-odd[-1][1])
else:
    print(min(ev-even[-2][1]+od-odd[-1][1],ev-even[-1][1]+od-odd[-2][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def f(x, y):
  return n - ( x + y )

v0 = Counter(v[::2])
v1 = Counter(v[1::2])
L = v0.most_common(2)
R = v1.most_common(2)

print(L, R)

if L[0][0] != R[0][0]:
  print(f(L[0][1], R[0][1]))
elif len(L) > len(R):
  print(f(L[1][1], R[0][1]))
elif len(L) < len(R):
  print(f(L[0][1], R[1][1]))
elif len(L) == 2:
  print(min(f(L[1][1], R[0][1]), f(L[0][1], R[1][1])))
else:
  print(n//2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def f(x, y):
  return n - ( x + y )

v0 = Counter(v[::2])
v1 = Counter(v[1::2])
L = v0.most_common(2)
R = v1.most_common(2)

if L[0][0] != R[0][0]:
  print(f(L[0][1], R[0][1]))
elif len(L) > len(R):
  print(f(L[1][1], R[0][1]))
elif len(L) < len(R):
  print(f(L[0][1], R[1][1]))
elif len(L) == 2:
  print(max(f(L[1][1], R[0][1]), f(L[0][1], R[1][1])))
else:
  print(n//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)
#print(dictV1, dictV2)

sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
a = 0
if sortdictV1[0][0] != sortdictV2[0][0]:
    a = N - sortdictV1[0][1] - sortdictV2[0][1]
else:
  if len(dictV1) == len(dictV2) == 1:
    a = N // 2
  else:
    if len(dictV1) == 1:
      a = N - sortdictV1[0][1] - sortdictV2[1][1]
    elif len(dictV2) == 1:
      a = N - sortdictV1[1][1] - sortdictV2[0][1]
    else:
      a = min(N - sortdictV1[0][1] - sortdictV2[1][1], N - sortdictV1[1][1] - sortdictV2[0][1])
  print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
V =  [int(i) for i in input().split()]
V1 = [V[2*j-2] for j in range(1, N//2+1)]
V2 = [V[2*j-1] for j in range(1, N//2+1)]
#print(V1, V2)

def dict(x):
  D = {}
  for i in x:
    if i in D:
      D[i] += 1
    else:
      D.setdefault(i, 1)
  return D

dictV1 = dict(V1)
dictV2 = dict(V2)
#print(dictV1, dictV2)

sortdictV1 = sorted(dictV1.items(), key=lambda x:x[1], reverse=True)
sortdictV2 = sorted(dictV2.items(), key=lambda x:x[1], reverse=True)
if len(dictV1) == len(dictV2) == 1:
  if sortdictV1[0][0] == sortdictV2[0][0]:
    a = N // 2
  else:
    a = 0
else:
  a = 0
  if len(sortdictV1) == 1:
    a = a + 0
  else:
    for i in range(1, len(sortdictV1)):
      a = a + sortdictV1[i][1]
  if len(sortdictV2) == 1:
    a = a + 0
  else:
    for i in range(1, len(sortdictV2)):
      a = a + sortdictV2[i][1]
print(a)

Submission status: Wrong Answer

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

D = {}
def dict(x):
  for v in V:
    if v in D:
      D[v] += 1
    else:
      D.setdefault(v, 1)
  return D

dictN = dict(N)
#print(dict(N))

dictN = sorted(dictN.items(), key=lambda x:x[1], reverse=True)
#print(dictN)
if len(dictN) == 1:
  a = N // 2
elif len(dictN) == 2:
  a = 0
else:
  a = 0
  for i in range(2, len(dictN)):
    a = a + dictN[i][1]
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
series = [int(x) for x in input().split()]

odd_dict = {}
even_dict = {}

for i in range(n):
    k = series[i]
    if i % 2 == 0:
        try:
            even_dict[k] += 1
        except KeyError:
            even_dict[k] = 1 
    else:
        try:
            odd_dict[k] += 1
        except KeyError:
            odd_dict[k] = 1

odd_vals = []
even_vals = []

for key in odd_dict.keys():
    odd_vals.append([odd_dict[key], key])
for key in even_dict.keys():
    even_vals.append([even_dict[key], key])

odd_vals.sort(reverse=True)
even_vals.sort(reverse=True)

# print(odd_vals)
# print(even_vals)

if len(odd_vals) == 1 and len(even_vals) == 1:
    a = odd_vals[0][0]
    b = even_vals[0][0]

    if odd_vals[0][1] != even_vals[0][1]:
        print(n - a - b)
    else:
        print(n // 2)
elif len(odd_vals) > 1 and len(even_vals) > 1:
    if odd_vals[0][1] != even_vals[0][1]:
        print(n - odd_vals[0][0] - even_vals[0][0])
    else:
        a = odd_vals[0][0]
        b = odd_vals[1][0]
        c = even_vals[0][0]
        d = even_vals[1][0]
        print(max(n - a - d, n - b - c))
else:
    a = odd_vals[0][0]
    b = even_vals[0][0]
    c = 0
    if len(odd_vals) == 1:
        c = even_vals[1][0]
    else:
        c = odd_vals[1][0]
    
    if odd_vals[0][1] != even_vals[0][1]:
        print(n - a - b)
    else:
        print(n - a - c)

# print(even_dict)
# print(odd_dict)

Submission status: Wrong Answer

Solution code:
n = int(input())
V = list(map(int,input().split()))
A = []
B = []
for i in range(n):
    if i%2==0:
        A.append(V[i])
    else:
        B.append(V[i])
from collections import Counter
NA = len(A)
NB = len(B)
Ac = dict(Counter(A))
Bc = dict(Counter(B))
Am = max(Ac.values())
Bm = max(Bc.values())
if len(Ac.keys())==1 and len(Bc.keys())==1 and A[0]==B[0]:
    print(NB)
else:
    print(NA-Am+NB-Bm)