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

d = [{}, {}]
for i in range(n):
    if v[i] not in d[i%2].keys():
        d[i%2][v[i]]=1
    else:
        d[i%2][v[i]]+=1

print(n - (max(d[0].values()) + max(d[1].values())))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
v=0
for i in range(n-2):
    if(l[i]!=l[i+2] or (l[i]==l[i+1] and v<2)):
        if(l[i]==l[i+1]):
            v+=1
        l[i+2]=l[i]
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = [int(x) for x in input().split()]

c0 = Counter(v)

if len(c0.values()) == 1:
    ans = n // 2
else:
    c1 = Counter(v[::2])
    c2 = Counter(v[1::2])

    x1 = sorted(c1.values(), reverse=True)
    x2 = sorted(c2.values(), reverse=True)

    ans = 0
    for v in x1[1:] + x2[1:]:
        ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A1 = A[::2]
A2 = A[1::2]

n1 = len(A1)
n2 = len(A2)

c1 = n1
c2 = n2

for s1 in set(A1):
    c1 = min(c1, n1 - A1.count(s1))

for s2 in set(A2):
    c2 = min(c2, n2 - A2.count(s2))

print(c1 + c2)

Submission status: Wrong Answer

Solution code:
import collections

def inputN(typ=str):
    return map(typ, raw_input().split())


N = inputN(int)[0]
v = inputN(int)

col0 = collections.Counter(v[::2])
col1 = collections.Counter(v[1::2])
X0 = col0.most_common(1)[0]
X1 = col1.most_common(1)[0]

if X0[0] == X1[0]:
    print N / 2
else:
    print N - X0[1] - X1[1]

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
for i in range(n-2):
    if(l[i]!=l[i+2] or l[i]==l[i+1]):
        l[i+2]=l[i]
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1m = max(c1.items(), key=lambda x:x[1])
c2m = max(c2.items(), key=lambda x:x[1])
tmp = N - c1m[1] - c2m[1]
if tmp == 0:
    if c1m[0] == c2m[0]:
        print(N // 2)
        exit()
print(tmp)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c1 = Counter(A[::2])
c2 = Counter(A[1::2])
c1m = max(c1.items(), key=lambda x:x[1])
c2m = max(c2.items(), key=lambda x:x[1])
print(N - c1m[1] - c2m[1])

Submission status: Wrong Answer

Solution code:
n = input()
a = map(int, raw_input().strip().split())
eve = {}
odd = {}
for i in xrange(0, n, 2):
    try: eve[a[i]] += 1
    except: eve[a[i]] = 1
for i in xrange(1, n, 2):
    try: odd[a[i]] += 1
    except: odd[a[i]] = 1
eM = oM = 0
for k in eve: eM = max(eM, eve[k])
for k in odd: oM = max(oM, odd[k])

ans = n - oM - eM
print ans

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(map(int , input().split()))
ev=[]
ov=[]
ev=v[0::2]
ov=v[1::2]
ev2=set(ev)
ov2=set(ov)
mins=n
if len(set(v))==1:
    print(int(n/2))
else:
    for i in ev2:
        for j in ov2:
            if n/2-ev.count(i)+n/2-ov.count(j)<mins:
                mins=n/2-ev.count(i)+n/2-ov.count(j)
    print(int(mins))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(map(int , input().split()))
ev=[]
ov=[]
for i in range(n):
    if i%2==0:
        ev.append(v[i])
    else:
        ov.append(v[i])
ev2=set(ev)
ov2=set(ov)
mins=n
if len(set(v))==1:
    print(int(n/2))
else:
    for i in ev2:
        for j in ov2:
            if n/2-ev.count(i)+n/2-ov.count(j)<mins:
                mins=n/2-ev.count(i)+n/2-ov.count(j)
    print(int(mins))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(map(int,input().split()))
a=[0]*(10**5)
b=[0]*(10**5)
s,t=0,0
o,e,oi,ei=0,0,0,0
for i in range(1,n+1):
    if i%2==1:
        a[v[i-1]-1]+=1
        s+=1
    else:
        b[v[i-1]-1]+=1
        t+=1
o=max(a)
oi=[i for i, x in enumerate(a) if x == max(a)]
e=max(b)
ei=[i for i, x in enumerate(b) if x == max(b)]
if len(oi)==1 and s-o==t-e and len(ei)==1:
    a.sort(reverse=True)
    b.sort(reverse=True)
    print(min(t-e+s-a[1],t-a[1]+s-o))
else:
    print(s+t-e-o)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
ODD = defaultdict(int)
EVEN = defaultdict(int)
ALL = set([])
N = int(input())

A = list(map(int,input().split()))
for i in range(N):
  ALL.add(A[i])
  if i%2 == 0:
    EVEN[A[i]] += 1
  else:
    ODD[A[i]] += 1
if len(ALL) == 1:
  ans = N//2
  print(ans)
  exit()
modd = max(ODD.values())
meven = max(EVEN.values())
mlodd = [];mleven = []
dicodd = sorted(ODD.items(), key=lambda x:x[1], reverse = True)
diceven = sorted(EVEN.items(), key=lambda x:x[1], reverse = True)
ans = N
for x, vx in dicodd:
  for y, vy in diceven:
    if x != y:
      temp = N-(vx+vy)
      if ans != temp:
        ans = min(ans,temp)
      else:
        print(ans)
        exit()
print(ans)
exit()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(map(int,input().split()))
odd=[]
even=[]
on=[]
en=[]
for x in range(n//2):
  odd.append(v[2*x])
  even.append(v[2*x-1])
  if v[2*x] not in on:
    on.append(v[2*x])
  if v[2*x-1] not in en:
    en.append(v[2*x-1])
if even!=odd:
  oc=0
  for y in on:
    if oc<odd.count(y):
      oc=odd.count(y)
  ec=0
  for z in en:
    if ec<even.count(z):
      ec=even.count(z)
  print(n-oc-ec)
else:
  print(n//2)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
import collections
N = int(input())
nums = list(map(int, input().split()))
odd_nums = []
even_nums = []
for i, num in enumerate(nums):
    if i % 2 == 1:
        even_nums.append(num)
    else:
        odd_nums.append(num)

useable_nums = set(nums)
even_length = len(even_nums)
odd_length = len(odd_nums)
even_counter = collections.Counter(even_nums)
odd_counter = collections.Counter(odd_nums)
# print(even_counter)  # 偶数
# print(odd_counter)  # 奇数
inf = float('inf')
min_ans = inf
if len(useable_nums) == 1:
    useable_nums.add(0)
useable_permutaions = list(permutations(useable_nums, 2))
# print(useable_permutaions)

for permutation in useable_permutaions:
    ans = 0
    if permutation[0] in odd_counter:
        ans += odd_length - odd_counter[permutation[0]]
    else:
        ans += odd_length
    if permutation[1] in even_counter:
        ans += even_length - even_counter[permutation[1]]
    else:
        ans += even_length
    min_ans = min(min_ans, ans)

print(min_ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
N = int(input())
nums = list(map(int, input().split()))

useable_nums = set(nums)

# print(nums)
# print(useable_nums)

inf = float('inf')
min_ans = inf
if len(useable_nums) == 1:
    useable_nums.add(list(useable_nums)[0] + 1)
useable_permutaions = permutations(useable_nums, 2)
# print(useable_permutaions)
# print(list(useable_permutaions))
# print(list(useable_permutaions))
for permutation in useable_permutaions:
    ans = 0
    for i, num in enumerate(nums):
        if i % 2 == 0:
            if permutation[0] != num:
                # print(num, i, permutation[0])
                ans += 1
        else:
            if permutation[1] != num:
                # print(num, i, permutation[1])
                ans += 1
    # print(permutation, ans)
    min_ans = min(min_ans, ans)

print(min_ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
a = sorted(([i,v[::2].count(i)] for i in set(v[::2])), key=lambda x:x[1])
b = sorted(([j,v[1::2].count(j)] for j in set(v[1::2])),key=lambda x:x[1])
if a[-1]!=b[-1]:
    print(n-a[-1][1]-b[-1][1])
elif len(a) == 1 and len(b) == 1:
    print(min(a[-1][1],b[-1][1]))
elif len(a) ==1:
    print(n-a[-1][1]-b[-2][1])
elif len(b) ==1:
    print(n-a[-2][1]-b[-1][1])
else:
    print(min(n-a[-2][1]-b[-1][1],n-a[-1][1]-b[-2][1]))

Submission status: Time Limit Exceeded

Solution code:
n,*v = map(int,open(0).read().split())
v1 = v[::2]
v2 = v[1::2]
v1 = sorted([(i,v1.count(i)) for i in set(v1)],key =lambda x:x[1],reverse=True)
v2 = sorted([(i,v2.count(i)) for i in set(v2)],key =lambda x:x[1],reverse=True)
if len(v1) == 1:
  if len(v2) == 1:
    if v1[0][0] != v2[0][0]:
      print(0)
    else:
      print(n//2)
  else:
    if v1[0][0] != v2[0][0]:
      print(n//2-v2[0][1])
    else:
      print(n//2-v2[1][1])
else:
  if len(v2) == 1:
    if v1[0][0] != v2[0][0]:
      print(n//2-v1[0][1])
    else:
      print(n//2-v1[1][1])
  else:
    if v1[0][0] != v2[0][0]:
      print(n-v1[0][1]-v2[0][1])
    else:
      print(min(n-v1[0][1]-v2[1][1],n-v1[1][1]-v2[0][1]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1:
  print(n//2)
else:
  x=[]
  y=[]
  cnt=0
  for i in a:
    if cnt%2==0:
      x.append(i)
      cnt+=1
    else:
      y.append(i)
      cnt+=1
  s=list(set(x))
  t=list(set(y))
  o=0
  p=0
  for i in s:
    o=max(o,x.count(i))
  for i in t:
    p=max(p,y.count(i))
  print(n-o-p)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
vs=list(map(int,input().split()))
xs=vs[0::2]
ys=vs[1::2]
xfs=set(xs)
yfs=set(ys)
m=float('inf')
for xf in xfs:
    for yf in yfs:
        if not xf==yf:
            m=min(m,len(xs)-xs.count(xf)+len(ys)-ys.count(yf))
print(n//2 if m==float('inf') else m)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(input().split())
list1=[]
list2=[]
for i in range(n):
    if i%2==0:
        list1.append(v[i])
    else:
        list2.append(v[i])
num1=set()
num2=set()
max1=[]
max2=[]
for i in range(n):
    if i%2==0:
        num1.add(v[i])
    else:
        num2.add(v[i])
for i in range(len(num1)):
    str1=num1.pop()
    max1.append([str1,list1.count(str1)])
for i in range(len(num2)):
    str2=num2.pop()
    max2.append([str2,list2.count(str2)])
stra= lambda val: val[1]
max1.sort(key=stra,reverse=True)
max2.sort(key=stra,reverse=True)
if max1[0][0]==max2[0][0]:
    if len(max1)==1 and len(max2)==1:
        numa=max1[0][1]
        numb=0
    elif len(max1)==1:
        numa=max1[0][1]
        numb=max2[1][1]
    elif len(max2)==1:
        numa=max1[1][1]
        numb=max2[0][1]
    elif max1[1][1]>max2[1][1]:
        numa=max1[1][1]
        numb=max2[0][1]
    else:
        numa=max1[0][1]
        numb=max2[1][1]
else:
    numa=max1[0][1]
    numb=max2[0][1]
print(n-(numa+numb))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)

vodd = V_odd_counter.most_common()
veven = V_even_counter.most_common()
vlen = len(V)
while True:
    if vodd[0][0] != veven[0][0]:
        print(vlen - vodd[0][1] - veven[0][1])
        exit()
    else:
        print(min(vlen - vodd[1][1] - veven[0][1],
                    vlen - vodd[0][1] - veven[1][1]))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)

vodd = V_odd_counter.most_common()
veven = V_even_counter.most_common()

while True:
    if vodd[0][0] != veven[0][0]:
        print(len(V) - vodd[0][1] - veven[0][1])
        exit()
    else:
        print(min(len(V) - vodd[1][1] - veven[0][1],
                    len(V) - vodd[0][1] - veven[1][1]))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)

while True:
    if V_odd_counter.most_common()[0][0] != V_even_counter.most_common()[0][0]:
        print(len(V) - V_odd_counter.most_common()[0][1] - V_even_counter.most_common()[0][1])
        exit()
    else:
        print(min(len(V) - V_odd_counter.most_common()[1][1] - V_even_counter.most_common()[0][1],
                    len(V) - V_odd_counter.most_common()[0][1] - V_even_counter.most_common()[1][1]))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

V_odd = [i for i in V[::2]]
V_even = [i for i in V[1::2]]
V_odd_counter = Counter(V_odd)
V_even_counter = Counter(V_even)
while True:
    if V_odd_counter.most_common()[0][0] != V_even_counter.most_common()[0][0]:
        print(len(V) - V_odd_counter.most_common()[0][1] - V_even_counter.most_common()[0][1])
        exit()
    else:
        if V_odd_counter.most_common()[0][1] >= V_even_counter.most_common()[0][1]:
            V_even = [i for i in V_even if i != V_even_counter.most_common()[0][0] ]
            V_even_counter = Counter(V_even)
        else:
            V_odd = [i for i in V_odd if i != V_odd_counter.most_common()[0][0] ]
            V_odd_counter = Counter(V_odd)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int,input().split()))
odd = v[::2 ]
even = v[1::2]
def count(aaa):
    if len(set(aaa))!=1:
        aaa_min = min(aaa, key=aaa.count)
    else:
        aaa_min = 0
    return int(aaa_min)
if len(set(v))==1:
    print(int(n/2))
else:
    even_min = count(even)
    odd_min = count(odd)
    print(even_min+odd_min)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int,input().split()))
odd = []
even = []
for i in range(n):
    if i%2 == 0:
        even.append(v[i])
    else:
        odd.append(v[i])
def count(aaa):
    if len(set(aaa))!=1:
        aaa_min = min(aaa,key = aaa.count)
    else:
        aaa_min = 0
    return int(aaa_min)
if len(set(v))==1:
    print(int(n/2))
else:
    even_min = count(even)
    odd_min = count(odd)
    print(even_min+odd_min)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

v1 = []

v2 = []

q = 0

for i in v:
    if q == 0:
        v1.append(i)
        q = 1
    else:
        v2.append(i)
        q = 0
        
maxv1 = 0

maxv2 = 0

for i in set(v1):
    a = tuple(v1).count(i)
    if a>maxv1:
        maxv1 = a
        
for i in set(v2):
    b = tuple(v2).count(i)
    if b>maxv2:
        maxv2 = b
        
if v1 == v2:
    print(n//2)
else:
    print(n-maxv1-maxv2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

v1 = []

v2 = []

q = 0

for i in v:
    if q == 0:
        v1.append(i)
        q = 1
    else:
        v2.append(i)
        q = 0
        
maxv1 = 0

maxv2 = 0

for i in set(v1):
    a = v1.count(i)
    if a>maxv1:
        maxv1 = a
        
for i in set(v2):
    b = v2.count(i)
    if b>maxv2:
        maxv2 = b
        
if v1 == v2:
    print(n//2)
else:
    print(n-maxv1-maxv2)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])

c1 = dict(c1)
c2 = dict(c2)
c1[-1] = 0
c2[-2] = 0

MAX = 0
for k,v in c1.items():
    for k2,v2 in c2.items():
        if k != k2:
            MAX = max(v+v2,MAX)

print(N - MAX)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
a = list(map(int,input().split()))
s = list(set(a))
ans = 10**6
if len(s)==1:
    print(n//2)
else:
    for t in combinations(s,2):
        b = 0
        c = 0
        for i in range(n):
            if i%2==0:
                if t[1]!=a[i]:
                    b+=1
                if t[0]!=a[i]:
                    c+=1
            else:
                if t[0]!=a[i]:
                    b+=1
                if t[1]!=a[i]:
                    c+=1
        ans = min(ans,b,c)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import collections

def search_b(a_char, a_count, b_most_common, fixed_count):
  thres = fixed_count - a_count
  for (b_char, b_count) in [b for b in b_most_common if b[1] > thres]:
    if a_char != b_char:
      return a_count + b_count
  
  return fixed_count


def search(a_most_common, b_most_common):
  fixed_count = -1
  for (a_char, a_count) in a_most_common:
    fixed_count = search_b(a_char, a_count, b_most_common, fixed_count)
  
  return fixed_count


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

  a = V[::2]
  b = V[1::2]
  
  a_counter = collections.Counter(a)
  b_counter = collections.Counter(b)

  a_most_common = a_counter.most_common()
  b_most_common = b_counter.most_common()

  if len(a_most_common) == 1 and len(b_most_common) == 1 and a_most_common[0][0] == b_most_common[0][0]:
    print(n // 2)
    return

  print(n - search(a_most_common, b_most_common))


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
ans=[]
if len(Counter(l).values()) == 1:
  ans.append(len(f))
elif len(Counter(f).values()) == len(Counter(s).values()) == 1:
  ans.append(0)
else:
  for fk,fv in Counter(f).items():
    fdk=fk
    a=sum(Counter(f).values())-fv
    for sk,sv in Counter(s).items():
      if fk != sk:
        ans.append(a+sum(Counter(s).values())-sv)
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
l=list(map(int,input().split()))
f=l[0::2]
s=l[1::2]
ans=[]
if len(Counter(l).values()) == 1:
  ans.append(len(f))
elif len(Counter(f).values()) == len(Counter(s).values()) == 1:
  ans.append(0)
else:
  for fk,fv in sorted(Counter(f).items(),key=lambda x:x[0]):
    fdk=fk
    a=sum(Counter(f).values())-fv
    for sk,sv in sorted(Counter(s).items(),key=lambda x:x[0]):
      if fk != sk:
        ans.append(a+sum(Counter(s).values())-sv)
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int,input().split()))
a = {}
b = {}
for i in range(n//2):
  if v[2*i] in a.keys():
    a[v[2*i]] += 1
  else:
    a[v[2*i]] = 1
  if v[2*i+1] in b.keys():
    b[v[2*i+1]] += 1
  else:
    b[v[2*i+1]] = 1
mxa = 0
mxi = -1
smxa = 0
smxi = -1
for k in a.keys():
  if a[k] > mxa:
    smxi = mxi
    smxa = mxa
    mxa = a[k]
    mxi = k
  elif a[k] > smxa:
    smxi = k
    smxa = a[k]
mxb = 0
mxj = -1
smxb = 0
smxj = -1
for k in b.keys():
  if b[k] > mxb:
    smxj = mxj
    smxb = mxb
    mxb = b[k]
    mxj = k
  elif b[k] > smxb:
    smxj = k
    smxb = b[k]
if mxi != mxj:
  print(n-mxa-mxb)
else:
  print(n-max(mxa+smxb,smxa+mxb))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
v1 = v[0::2]
v2 = v[1::2]
count1 = Counter(v1)
count2 = Counter(v2)
count1[0] = 0
MAX = 0
for i in count1.keys():
    for j in count2.keys():
        if i != j and MAX < count1[i] + count2[j]:
            MAX = count1[i] + count2[j]
print(n - MAX)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
vlist = list(map(int,input().split()))
even = vlist[0:n:2]
odd = vlist[1:n:2]
e_counter= collections.Counter(even)
o_counter = collections.Counter(odd)
e_v = list(e_counter.values())
e_k = list(e_counter.keys())
o_v = list(o_counter.values())
o_k = list(o_counter.keys())
ans = 10**9
#ans = len(even)-e + len(odd)-o
#print(e_k,o_k)

for i in range(len(e_v)):
  for j in range(len(o_v)):
    if e_k[i] != o_k[j]:
      ans = min(ans,len(even)-e_v[i]+len(odd)-o_v[j])
    else:
      ans = min(ans,len(even)-e_v[i]+len(odd),len(even)-o_v[i]+len(odd))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
li = list(map(int,input().split()))
a = [l for i,l in enumerate(li) if i % 2 == 0]
b = [l for i,l in enumerate(li) if i % 2 == 1]
se_a = list(set(a))
se_b = list(set(b))
all_lis = []
for aa in se_a:
    tmp_cnt = len(a) - Counter(a)[aa]
    #print(tmp_cnt,len(a),Counter(a)[aa])
    tmp_list = []
    for bb in se_b:
        if aa == bb:
            continue
        tmp_list.append(tmp_cnt+len(b) - Counter(b)[bb])
    #print(tmp_list)
    all_lis += tmp_list
if all_lis:
    print(min(all_lis))
else:
    print(len(a))

Submission status: Time Limit Exceeded

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

v1=v[::2]
V1=list(set(v1))
n1=len(V1)
v2=v[1::2]
V2=list(set(v2))
n2=len(V2)

cnt1={}
cnt2={}

for i in range(n1):
  cnt1[V1[i]]=v1.count(V1[i])
for i in range(n2):
  cnt2[V2[i]]=v2.count(V2[i])

max1_k=max(cnt1,key=cnt1.get)
max2_k=max(cnt2,key=cnt2.get)
if max1_k!=max2_k:
  print(N-cnt1[max1_k]-cnt2[max2_k])
else:
  if cnt1[max1_k]>=cnt2[max2_k]:
    if n2==1:
      print(N-cnt1[max1_k])
    else:
      cnt2.pop(max2_k)
      max2_k=max(cnt2,key=cnt2.get)
      print(N-cnt1[max1_k]-cnt2[max2_k])
  else:
    if n1==1:
      print(N-cnt2[max2_k])
    else:
      cnt1.pop(max1_k)
      max1_k=max(cnt1,key=cnt.get)
      print(N-cnt1[max1_k]-cnt2[max2_k])

Submission status: Time Limit Exceeded

Solution code:
import collections

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

even_num=[v[i] for i in range(0,n,2)]
odd_num=[v[i] for i in range(1,n,2)]
#print(even_num)
#print(odd_num)

count_even=[(el, even_num.count(el)) for el in set(even_num)]
count_odd=[(el, odd_num.count(el)) for el in set(odd_num)]

count_even=collections.Counter(even_num).most_common()
count_odd=collections.Counter(odd_num).most_common()

#count_even=sorted(count_even, key=lambda val:val[1], reverse=True)
#count_odd=sorted(count_odd, key=lambda val:val[1], reverse=True)

#print(count_even)
#print(count_odd)
count_even.append((0,0))
count_odd.append((0,0))

if count_even[0][0]!=count_odd[0][0]:
    print(n-count_even[0][1]-count_odd[0][1])
else:
    odd_even=count_odd[0][1]+count_even[1][1]
    even_odd=count_even[0][1]+count_odd[1][1]
    if odd_even>even_odd:
        print(n-odd_num)
    else:
        print(n-even_odd)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

even_num=[v[i] for i in range(0,n,2)]
odd_num=[v[i] for i in range(1,n,2)]
#print(even_num)
#print(odd_num)

count_even=[(el, even_num.count(el)) for el in set(even_num)]
count_odd=[(el, odd_num.count(el)) for el in set(odd_num)]

count_even=sorted(count_even, key=lambda val:val[1], reverse=True)
count_odd=sorted(count_odd, key=lambda val:val[1], reverse=True)

#print(count_even)
#print(count_odd)
count_even.append((0,0))
count_odd.append((0,0))

if count_even[0][0]!=count_odd[0][0]:
    print(n-count_even[0][1]-count_odd[0][1])
else:
    odd_even=count_odd[0][1]+count_even[1][1]
    even_odd=count_even[0][1]+count_odd[1][1]
    if odd_even>even_odd:
        print(n-odd_num)
    else:
        print(n-even_odd)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

from itertools import permutations
p = list(set(l))
q = list(permutations(p, 2))

if len(p) == 1:
    print(int(len(l)/2))
    exit()

gu, ki = [], []
for i in range(n):
    if i % 2 == 0:
        gu.append(l[i])
    else:
        ki.append(l[i])

y = []
for k in range(len(q)):
    x = 0
    for j in range(int(len(l)/2)):
        if q[k][0] != gu[j]:
            x += 1
        if q[k][1] != ki[j]:
            x += 1
    y.append(x)

print(min(y))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
v=list(map(int,input().split()))
v1 = [v[2*i] for i in range(n//2)]

if len(set(v))==1:
    print(n//2)
    exit()
set_v1 = set(v1)
ma1=0
for x in set_v1:
    if v1.count(x)>=ma1:
        ma1=v1.count(x)

v2 = [v[2*i+1] for i in range(n//2)]
set_v2 = set(v2)
ma2=0
for x in set_v2:
    if v2.count(x)>=ma2:
        ma2=v2.count(x)
print(n-ma1-ma2)

Submission status: Time Limit Exceeded

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

even=[v[i] for i in range(n) if i%2 == 0]
odd=[v[i] for i in range(n) if i%2 == 1]
ans=0

e_n=max(even,key=even.count)
o_n=max(odd,key=odd.count)

if even==odd:
    print(even.count(even[0]))
else:
    ans=len(even)-even.count(e_n)+len(odd)-odd.count(o_n)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(n//2)
  exit()
oddv = v[::2]
evenv = v[1::2]
maxoddcnt = 0
maxevencnt = 0
for vi in set(oddv):
  maxoddcnt = max(oddv.count(vi), maxoddcnt)
for vi in set(evenv):
  maxevencnt = max(evenv.count(vi), maxevencnt)
# print(oddv, evenv, maxoddcnt, maxevencnt)
print(len(oddv) - maxoddcnt + len(evenv) - maxevencnt)

Submission status: Time Limit Exceeded

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



def main():
    N = int(input())
    V = [int(x) for x in input().split()]

    a = []
    b = []
    for i in range(N):
        if i & 1:
            a.append(V[i])
        else:
            b.append(V[i])

    ac = Counter(a)
    bc = Counter(b)

    acm = ac.most_common()
    bcm = bc.most_common()

    if acm[0][0] != bcm[0][0]:
        print(N // 2 - acm[0][1] + N // 2 - bcm[0][1])
    else:
        ans = float("inf")
        for i in acm:
            for j in bcm:
                if i[0] == j[0]:
                    continue
                ans = min(ans, N // 2 - i[1] + N // 2 - j[1])
        if ans == float("inf"):
            print(N // 2)
        else:
            print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Odd, Evn = [], []
for i in range(n):
    Evn.append(V[i]) if i%2 == 0 else Odd.append(V[i])
Evn = sorted( dict(Counter(Evn)).items(), key = lambda x:x[1])
Odd = sorted( dict(Counter(Odd)).items(), key = lambda x:x[1])

cnt = -1
for evn in Evn:
    for odd in Odd:
        if evn[0] != odd[0]:
            cnt = max(cnt, evn[1]+odd[1])
print(n-cnt) if cnt > 0 else print(n//2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = input().split()
k = len(set(a))
ans = 0
if k == 1:
    ans += n//2
else:
    # 偶奇でリストを分割
    # それぞれで最も多い要素を選択
    # 選択した要素が異なるならOK
    # 少ない方を二番目に変更
    od = a[::2]
    ev = a[1::2]
    k_od = list(set(od))
    k_ev = list(set(ev))
    c_od = [(od.count(i),i) for i in k_od]
    c_ev = [(ev.count(i),i) for i in k_ev]
    c_od.sort()
    c_ev.sort()
    if c_od[-1][1] != c_ev[-1][1]:
        ans += n-c_od[-1][0]-c_ev[-1][0]
    else:
        ans += n-max(c_od[-1][0],c_ev[-1][0])
        ans -= c_od[-2][0] if c_od[-1][0]>=c_ev[-1][0] else c_ev[-2][0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
a = []
b = []
ca = []
cb = []
for i in range(n // 2):
    a.append(l[i * 2])
    b.append(l[i * 2 + 1])
while (len(a) > 0):
    ca.append([a[0], a.count(a[0])])
    a = [s for s in a if not(s == a[0])]
while (len(b) > 0):
    cb.append([b[0], b.count(b[0])])
    b = [s for s in b if not (s == b[0])]
ca.sort(key=lambda x: x[1], reverse=True)
cb.sort(key=lambda x: x[1], reverse=True)
ca_max = ca[0]
cb_max = cb[0]
ca_max_num = ca[0][1]
cb_max_num = cb[0][1]
if ca_max[0] == cb_max[0]:
    if ca_max[1] > cb_max[1]:
        if len(cb) > 1:
            cb_max_num = cb[1][1]
        else:
            cb_max_num = 0
    else:
        if len(ca) > 1:
            ca_max_num = ca[1][1]
        else:
            ca_max_num = 0
print((n // 2) * 2 - ca_max_num - cb_max_num)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
F=[]
G=[]
for i in range(N):
  if i%2==0:
    F +=[A[i]]
  else:
    G +=[A[i]]
answer=float('inf')
for i in range(min(F),max(F)+1):
  for j in range(min(G),max(G)+1):
    if i==j:
      break
    diff =0
    for k in range(N//2):
      diff += abs(F[k]-i)+abs(G[k]-j)
    answer=min(answer,diff)
print(answer if answer!=float('inf') else N//2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
V = list(map(int,input().split()))
cnt = 0
cnt1 = 0
for i in range(n-2):
  if len(set(V)) == 1:
    print(n//2)
    exit()
  if V[i] == V[i+2] and i%2==0:
    cnt += 1
  elif V[i] == V[i+2] and i%2==1:
    cnt1 += 1
print(max(cnt,cnt1)-min(cnt,cnt1))