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: Time Limit Exceeded

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

v_odd = v[1::2]
v_even = v[::2]

v_odd_unique = list(set(v_odd))
v_even_unique = list(set(v_even))

v_odd_max = 0
v_even_max = 0
v_odd_max_num = 0
v_even_max_num = 0
v_odd_semi = 0
v_even_semi = 0
v_odd_semi_num = 0
v_even_semi_num = 0

for v_odd_num in v_odd_unique:
    v_odd_tmp = v_odd.count(v_odd_num)
    if v_odd_max <= v_odd_tmp:
        v_odd_semi = v_odd_max
        v_odd_max = v_odd_tmp
        v_odd_semi_num = v_odd_max_num
        v_odd_max_num = v_odd_num

for v_even_num in v_even_unique:
    v_even_tmp = v_even.count(v_even_num)
    if v_even_max <= v_even_tmp:
        v_even_semi = v_even_max
        v_even_max = v_even_tmp
        v_eve_semi_num = v_even_max_num
        v_even_max_num = v_even_num

if v_odd_max_num == v_even_max_num:
    print(min(len(v_odd)-v_odd_max+len(v_even)-v_even_semi,len(v_odd)-v_odd_semi+len(v_even)-v_even_max))
else:
    print(len(v_odd)-v_odd_max+len(v_even)-v_even_max)

Submission status: Time Limit Exceeded

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

e = [a[2*i] for i in range(n//2)]
o = [a[2*i+1] for i in range(n//2)]
ne = [e.count(x) for x in e]
no = [o.count(x) for x in o]

ie1 = 0
ie2 = 0
for i in range(n//2):
    if ne[ie1] < ne[i]:
        ie2 = ie1
        ie1 = i
    elif ne[ie2] < ne[i]:
        ie2 = i

io1 = 0
io2 = 0
for i in range(n//2):
    if no[io1] < no[i]:
        io2 = io1
        io1 = i
    elif no[io2] < no[i]:
        io2 = i   

if o[io1] != e[ie1]:
    ans = n - no[io1] - ne[ie1]
elif no[io1] > ne[ie1]:
    if ne[ie1]==len(e):
        ans = n - no[io1]
    else:
        ans = n - no[io1] - ne[ie2]
else:
    if no[io2] == len(o):
        ans = n - ne[ie1]
    else:
        ans = n - ne[ie1] - no[io2]

print(ans)

Submission status: Time Limit Exceeded

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

o = [a[2*i] for i in range(n//2)]
e = [a[2*i+1] for i in range(n//2)]

o = sorted(o,key=lambda x: o.count(x), reverse = True)
e = sorted(e,key=lambda x: e.count(x), reverse = True)

if o[0] != e[0]:
    ans = n - o.count(o[0]) - e.count(e[0])
elif o.count(o[0]) > e.count(e[0]):
    if e.count(e[0]) == len(e):
        ans = n - o.count(o[0])
    else:
        ans = n - o.count(o[0]) - e.count(e[e.count(e[0])])
else:
    if o.count(o[0]) == len(o):
        ans = n - e.count(e[0])
    else:
        ans = n - e.count(e[0]) - o.count(o[o.count(o[0])])

print(ans)

Submission status: Time Limit Exceeded

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

o = [a[2*i] for i in range(n//2)]
e = [a[2*i+1] for i in range(n//2)]

omax = max(o,key=lambda x:o.count(x))
emax = max(e,key=lambda x:e.count(x))

if omax == emax:
    if o.count(omax) < e.count(emax):
        c = set(o)
        c.remove(omax)
        if len(c) == 0:
            omax = n//2
        else:
            omax = max(c,key=lambda x:o.count(x))
    else:
        c = set(e)
        c.remove(emax)
        if len(c) == 0:
            emax = n//2
        else:
            emax = max(c,key=lambda x:e.count(x))

ans = n - o.count(omax) - e.count(emax)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
V = list(map(int,input().split()))
Vodd = list()
Veven = list()
nodd = 0
neven = 0
for x in range(0,n//2):
    Vodd.append(V[2*x])
    Veven.append(V[2*x+1]) 

for x in set(Vodd):
    k = Vodd.count(x)
    if k > nodd:
        nodd = k
        odd_number = x
for x in set(Veven):
    k = Veven.count(x)
    if k > neven:
        neven = k
        even_number = x

answer = n - nodd - neven

if odd_number == even_number:
    Vodd = [i for i in Vodd if not i == odd_number]
    Veven = [i for i in Veven if not i == even_number]
    a = 0
    b = 0
    if not Vodd is []:
        for x in set(Vodd):
            k = Vodd.count(x)
            if k > a:
                a = k
    if not Veven is []:
        for x in set(Veven):
            k = Veven.count(x)
            if k > a:
                a = k
    answer = min(n - a - neven,n - nodd - b)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
V = list(map(int,input().split()))
Vodd = list()
Veven = list()
for x in range(0,n//2):
    Vodd.append(V[2*x])
    Veven.append(V[2*x+1]) 
oddcounts = {x:Vodd.count(x) for x in set(Vodd)}
evencounts = {x:Veven.count(x) for x in set(Veven)}

max_odd = max(oddcounts.items(),key=lambda x:x[1])
max_even = max(evencounts.items(),key=lambda x:x[1])

number = n - max_odd[1] - max_even[1]

if max_odd[0] == max_even[0]:
    if len(oddcounts) == 1:
        a = 0
    else:
        del oddcounts[max_odd[0]]
        max_odd1 = max(oddcounts.items(),key=lambda x:x[1])
        a = max_odd1[1]
    if len(evencounts) == 1:
        b = 0
    else:
        del evencounts[max_even[0]]
        max_even1 = max(oddcounts.items(),key=lambda x:x[1])
        b = max_even1[1]
    number = min(n - a - max_even[1],n - max_odd[1] - b)

print(number)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
V = list(map(int,input().split()))
nums = [v for v in V if V.count(v) != int(N/2)]
print(int(len(nums)/2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
V = list(map(int,input().split()))
Vodd = list()
Veven = list()
nodd = 0
neven = 0
for x in range(0,n,2):
    Vodd.append(V[x])
    Veven.append(V[x+1]) 
oddcounts = {x:Vodd.count(x) for x in Vodd}
evencounts = {x:Veven.count(x) for x in Veven}

max_odd = max(oddcounts.items(),key=lambda x:x[1])
max_even = max(evencounts.items(),key=lambda x:x[1])

number = n - max_odd[1] - max_even[1]

if max_odd[0] == max_even[0]:
    if len(oddcounts) == 1:
        a = 0
    else:
        del oddcounts[max_odd[0]]
        max_odd1 = max(oddcounts.items(),key=lambda x:x[1])
        a = max_odd1[1]
    if len(evencounts) == 1:
        b = 0
    else:
        del evencounts[max_even[0]]
        max_even1 = max(oddcounts.items(),key=lambda x:x[1])
        b = max_even1[1]
    number = min(n - a - max_even[1],n - max_odd[1] - b)

print(number)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
V = list(map(int,input().split()))
Vodd = list()
Veven = list()
nodd = 0
neven = 0
for x in range(0,n,2):
    Vodd.append(V[x])
    Veven.append(V[x+1]) 
oddcounts = {x:Vodd.count(x) for x in Vodd}
evencounts = {x:Veven.count(x) for x in Veven}

y = sorted(oddcounts.items(),key=lambda x:x[1],reverse=True)
z = sorted(evencounts.items(),key=lambda x:x[1],reverse=True)

number = len(Vodd) - y[0][1] + len(Veven) - z[0][1]

if y[0][0] == z[0][0]:
    if len(y) == 1:
        y.append((0,0))
    if len(z) == 1:
        z.append((0,0))
    number = min(len(Vodd)-y[1][1]+len(Veven)-z[0][1],len(Vodd)-y[0][1]+len(Veven)-z[1][1])

print(number)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
V = list(map(int,input().split()))
Vodd = list()
Veven = list()
nodd = 0
neven = 0
for x in range(0,n,2):
    Vodd.append(V[x])
    Veven.append(V[x+1]) 
oddcounts = {x:Vodd.count(x) for x in set(Vodd)}
evencounts = {x:Veven.count(x) for x in set(Veven)}

y = sorted(oddcounts.items(),key=lambda x:x[1],reverse=True)
z = sorted(evencounts.items(),key=lambda x:x[1],reverse=True)

number = len(Vodd) - y[0][1] + len(Veven) - z[0][1]

if y[0][0] == z[0][0]:
    if len(y) == 1:
        y.append((0,0))
    if len(z) == 1:
        z.append((0,0))
    number = min(len(Vodd)-y[1][1]+len(Veven)-z[0][1],len(Vodd)-y[0][1]+len(Veven)-z[1][1])

print(number)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

d0={}
d1={}

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

for i in range(n//2):
    v_even = v[2*i]
    v_odd  = v[2*i+1]
    if v_even in d0.keys():
        d0[v_even]+=1
    else:
        d0[v_even]=1

    if v_odd in d1.keys():
        d1[v_odd]+=1
    else:
        d1[v_odd]=1

v11,v12,v21,v22 = [0]*4
k1,k2 = [0]*2

for k in d0.keys():
    v = d0[k]
    if v11<v:
        v11=v
        k1=k
for k in d1.keys():
    v = d1[k]
    if v12<v and k!=k1:
        v12=v
    if v22<v:
        v22=v
        k2=k

for k in d0.keys():
    v = d0[k]
    if v21<v and k!=k2:
        v21=v

print(min(n-v11-v12,n-v21-v22))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
V = list(map(int, input().split()))
A = set(V)

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

ans = 0
for i in range(len(V)-2):
	if V[i] != V[i+2]:
		for d in A:
			if V[i] == d:
				V[i+2] = d
				ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = []
cr = []
count = 0
ma = 0
if len(set(ar)) == 1:
    print(a // 2)
else:
    for i,r in enumerate(ar):
        if i % 2 == 0:
            br.append(r)
        else:
            cr.append(r)
    for r in set(br):
        if ma < br.count(r):
            ma = br.count(r)
    count += a // 2 - ma
    ma = 0
    for r in set(cr):
        if ma < cr.count(r):
            ma = cr.count(r)
    count += a // 2 - ma
    print(count)

Submission status: Time Limit Exceeded

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

a=[]
b=[]
for i in range(n):
  if i%2==0:
    a+=[x[i]]
  else:
    b+=[x[i]]
#a=x[::2]
#b=x[1::2]
#print(a)
#print(b)

seta=list(set(a))
setb=list(set(b))

if len(seta) == 1 and len(setb) == 1 and a[0]==b[0]:
  ans=min(len(a),len(b))

else:
  dicta={}
  dictb={}

  for i in range(len(seta)):
    dicta[seta[i]]=a.count(seta[i])

  for i in range(len(setb)):
    dictb[setb[i]]=b.count(setb[i])
  
#  print(dicta)
#  print(dictb)
  ansa=len(a)-max(dicta.values())
  ansb=len(b)-max(dictb.values())
  ans=ansa+ansb
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

x=[i for i in input().split()]
#print(x)

a=x[::2]
b=x[1::2]
#print(a)
#print(b)

seta=list(set(a))
setb=list(set(b))

if len(list(set(x))) ==1 :
  ans=min(len(a),len(b))

else:
  dicta={}
  dictb={}

  for i in range(len(seta)):
    dicta[seta[i]]=a.count(seta[i])

  for i in range(len(setb)):
    dictb[setb[i]]=b.count(setb[i])
  
#  print(dicta)
#  print(dictb)
  ansa=len(a)-max(dicta.values())
  ansb=len(b)-max(dictb.values())
  ans=ansa+ansb
  
print(ans)

Submission status: Time Limit Exceeded

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

ki = []
gu = []

ki = x[0::2]
gu = x[1::2]

a = set(ki)
a = list(a)

dd = 0
z = ki.count(a[0])
b = [0,z]
for i in range(1,len(a)):
    c = ki.count(a[i])
    b.append(c)
    if z < c:
        dd = i

a2 = set(gu)
a2 = list(a2)

bb = 0
y = gu.count(gu[0])
d = [0,y]
for i in range(1,len(a2)):
    c = gu.count(a2[i])
    d.append(c)
    if y < c:
        bb = i

if a[dd] != a2[bb]:
    print(len(ki)-max(b)+len(gu)-max(d))
else:
    if max(a) > max(a2):
        d = sorted(d, reverse=True)
        print(len(ki)-max(b)+len(gu)-d[1])
    else:
        b = sorted(b, reverse=True)
        print(len(ki)-b[1]+len(gu)-max(d))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = input()
x = list(map(int,input().split(' ')))

ki = []
gu = []

ki = x[0::2]
gu = x[1::2]

a = [ki[0]]

for i in range(1,len(ki)):
    if ki[0] != ki[i]:
        a.append(ki[i])

dd = 0
z = ki.count(a[0])
b = [0,z]
for i in range(1,len(a)):
    c = ki.count(a[i])
    b.append(c)
    if z < c:
        dd = i

a2 = [gu[0]]

for p in range(1,len(gu)):
    if gu[0] != gu[i]:
        a2.append(gu[i])

bb = 0
y = gu.count(gu[0])
d = [0,y]
for i in range(1,len(a2)):
    c = gu.count(a2[i])
    d.append(c)
    if y < c:
        bb = i

if a[dd] != a2[bb]:
    print(len(ki)-max(b)+len(gu)-max(d))
else:
    if max(a) > max(a2):
        d = sorted(d, reverse=True)
        print(len(ki)-max(b)+len(gu)-d[1])
    else:
        b = sorted(b, reverse=True)
        print(len(ki)-b[1]+len(gu)-max(d))

Submission status: Time Limit Exceeded

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

ki = []
gu = []

ki = x[0::2]
gu = x[1::2]

a = [ki[0]]

for i in range(1,len(ki)):
    if ki[0] != ki[i]:
        a.append(ki[i])

dd = 0
z = ki.count(a[0])
b = [0,z]
for i in range(1,len(a)):
    c = ki.count(a[i])
    b.append(c)
    if z < c:
        dd = i

a2 = [gu[0]]

for p in range(1,len(gu)):
    if gu[0] != gu[i]:
        a2.append(gu[i])

bb = 0
y = gu.count(gu[0])
d = [0,y]
for i in range(1,len(a2)):
    c = gu.count(a2[i])
    d.append(c)
    if y < c:
        bb = i

if a[dd] != a2[bb]:
    print(len(ki)-max(b)+len(gu)-max(d))
else:
    if max(a) > max(a2):
        d = sorted(d, reverse=True)
        print(len(ki)-max(b)+len(gu)-d[1])
    else:
        b = sorted(b, reverse=True)
        print(len(ki)-b[1]+len(gu)-max(d))

Submission status: Time Limit Exceeded

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

ki = []
gu = []

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

a = [ki[0]]

for i in range(1,len(ki)):
    if ki[0] != ki[i]:
        a.append(ki[i])

dd = 0
z = ki.count(a[0])
b = [0,z]
for i in range(1,len(a)):
    c = ki.count(a[i])
    b.append(c)
    if z < c:
        dd = i

a2 = [gu[0]]

for p in range(1,len(gu)):
    if gu[0] != gu[i]:
        a2.append(gu[i])

bb = 0
y = gu.count(gu[0])
d = [0,y]
for i in range(1,len(a2)):
    c = gu.count(a2[i])
    d.append(c)
    if y < c:
        bb = i

if a[dd] != a2[bb]:
    print(len(ki)-max(b)+len(gu)-max(d))
else:
    if max(a) > max(a2):
        d = sorted(d, reverse=True)
        print(len(ki)-max(b)+len(gu)-d[1])
    else:
        b = sorted(b, reverse=True)
        print(len(ki)-b[1]+len(gu)-max(d))

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())

even = collections.defaultdict(lambda: 0)
odd = collections.defaultdict(lambda: 0)

for i, a in enumerate(map(int, input().split())):
    if i % 2 == 0:
        even[a] += 1
    else:
        odd[a] += 1

if len(even.keys()) == 1 and len(odd.keys()) == 1 and list(even.keys())[0] == list(odd.keys())[0]:
    print(N // 2)
else:
    m = 0
    for e_k, e_v in even.items():
        for o_k, o_v in odd.items():
            if e_k == o_k:
                continue
            m = max(m, e_v + o_v)

    print(N - m)

Submission status: Time Limit Exceeded

Solution code:
'''
問題文
数列 a1,a2,...,anが以下の条件を満たすとき、 /\/\/\/ と呼ぶことにします。

・各 i=1,2,...,n−2について、ai=ai+2
・数列に現れる数はちょうど 2種類

偶数長の数列 v1,v2,...,vnが与えられます。 要素をいくつか書き換えることでこの数列を /\/\/\/ にしたいです。
書き換える要素の数は最小でいくつになるか求めてください。

制約
2≤n≤105
nは偶数
1≤vi≤105
viは整数
'''

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

voddNum=[vodd[0]]
voddCnt=[0]
j=0
for i,odd in enumerate(vodd):
    if voddNum[j]!=odd:
        for k,num in enumerate(voddNum):
            if num==odd:
                j=k
                break
        else:
            j=k+1
            voddNum.append(odd)
            voddCnt.append(0)
    voddCnt[j]+=1
voddSet=list(zip(voddCnt, voddNum))
#voddSet=list(reversed(sorted(voddSet,key=lambda x:x[0])))
voddSet.sort(key=lambda x:x[0])
voddSet.reverse()
# print(vodd)
# print(voddNum)
# print(voddCnt)
# print(voddSet)


vevenNum=[veven[0]]
vevenCnt=[0]
j=0
for i,even in enumerate(veven):
    if vevenNum[j]!=even:
        for k,num in enumerate(vevenNum):
            if num==even:
                j=k
                break
        else:
            j=k+1
            vevenNum.append(even)
            vevenCnt.append(0)
    vevenCnt[j]+=1
vevenSet=list(zip(vevenCnt, vevenNum))
#vevenSet=list(reversed(sorted(vevenSet,key=lambda x:x[0])))
vevenSet.sort(key=lambda x:x[0])
vevenSet.reverse()
# print()
# print(veven)
# print(vevenNum)
# print(vevenCnt)
# print(vevenSet)


changeCnt=len(vodd)+len(veven)
if voddSet[0][1]==vevenSet[0][1]:
    if len(voddSet)==1 & len(vevenSet)==1:
        changeCnt-=len(vodd)
    elif len(voddSet)==1:
        changeCnt-=vevenSet[0][0]
    elif len(vevenSet)==1:
        changeCnt-=voddSet[0][0]
    else:
        if voddSet[1][0]>vevenSet[1][0]:
            changeCnt=changeCnt-voddSet[1][0]-vevenSet[0][0]
        else:
            changeCnt+=-voddSet[0][0]-vevenSet[1][0]
else:
    changeCnt+=-voddSet[0][0]-vevenSet[0][0]

print(changeCnt)
#'''

Submission status: Time Limit Exceeded

Solution code:
def leave_rewrite(vi_list):
    if len(set(vi_list)) > 1:
        sort_vi_list = sorted([(i, vi_list.count(i)) for i in set(vi_list)], key=lambda x: -x[1])
        return sort_vi_list[0][0], len(vi_list) - sort_vi_list[0][1], len(vi_list) - sort_vi_list[1][1]
    else:
        return vi_list[0], 0, 0

N = int(input())
v_list = input().split()

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

v1_list = v_list[::2]
v2_list = v_list[1::2]

l1_leave, rewrite_v1, second_v1 = leave_rewrite(v1_list)
l2_leave, rewrite_v2, second_v2 = leave_rewrite(v2_list)

if l1_leave != l2_leave:
    print(rewrite_v1 + rewrite_v2)
elif rewrite_v1 > rewrite_v2:
    print(rewrite_v2 + second_v1)
else:
    print(rewrite_v1 + second_v2)

Submission status: Time Limit Exceeded

Solution code:
def rewrite_count(vi_list):
    if len(set(vi_list)) != 1:
        vi_count_list = [(i, vi_list.count(i)) for i in set(vi_list)]
        vi_count_list = sorted(vi_count_list, key=lambda x: x[1])
        return vi_count_list[-1][0], len(vi_list) - vi_count_list[-1][1], len(vi_list) - vi_count_list[-2][1]
    else:
        return vi_list, 0, 0

N = int(input())
v_list = input().split()

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

v1_list = [v_list[i] for i in range(0, len(v_list), 2)]
v2_list = [v_list[i] for i in range(1, len(v_list), 2)]
max_v1, max_value_v1, second_value_v1 = rewrite_count(v1_list)
max_v2, max_value_v2, second_value_v2 = rewrite_count(v2_list)

if max_v1 != max_v2:
    ans = max_value_v1 + max_value_v2
elif max_value_v1 > max_value_v2:
    ans = max_value_v2 + second_value_v1
else:
    ans = max_value_v1 + second_value_v2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def rewrite_count(vi_list):
    if len(set(vi_list)) != 1:
        vi_count_list = sorted([(i, vi_list.count(i)) for i in set(vi_list)], key=lambda x: x[1])
        return vi_count_list[-1][0], len(vi_list) - vi_count_list[-1][1], len(vi_list) - vi_count_list[-2][1]
    else:
        return vi_list, 0, "null"

N = int(input())
v_list = input().split()

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

v1_list = [v_list[i] for i in range(0, len(v_list), 2)]
v2_list = [v_list[i] for i in range(1, len(v_list), 2)]
max_v1, max_value_v1, second_value_v1 = rewrite_count(v1_list)
max_v2, max_value_v2, second_value_v2 = rewrite_count(v2_list)

if max_v1 != max_v2:
    ans = max_value_v1 + max_value_v2
elif max_value_v1 > max_value_v2:
    ans = max_value_v2 + second_value_v1
else:
    ans = max_value_v1 + second_value_v2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
odd,even = [a[i] for i in range(0,n,2)],[a[i] for i in range(1,n,2)]
if len(set(odd)) == 1 and len(set(even)) == 1:
    if odd[0] == even[0]:
        print(n//2)
    else:
        print(0)
else:
    odds,evens = [],[]
    for i in set(odd):
        odds.append((i,odd.count(i)))
    for i in set(even):
        evens.append((i,even.count(i)))
    odds.sort(key = lambda x: x[1],reverse = True)
    evens.sort(key = lambda x: x[1], reverse = True)
    if len(odds) == 1:
        if odds[0][0] != evens[0][0]:
            print(n//2 - evens[0][1])
        else:
            print(n//2 - evens[1][1])
    elif len(evens) == 1:
        if odds[0][0] != evens[0][0]:
            print(n//2 - odds[0][1])
        else:
            print(n//2 - odds[1][1])
    else:
        if odds[0][0] == evens[0][0]:
            print(min(n - odds[1][1] - evens[0][1], n - odds[0][1] - evens[1][1]))
        else:
            print(n - odds[0][1] - evens[0][1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
vs = input().split()

vs1 = [vs[i] for i in range(0, len(vs), 2)]
vs2 = [vs[i] for i in range(1, len(vs), 2)]

m1 = 0
i1 = -1
m2 = 0
i2 = -1
ccc = 0
for value in vs1:
    ccc += 1
    count = vs1.count(value)
    if count > m1:
        i2 = i1
        m2 = m1
        i1 = value
        m1 = count

m3 = 0
i3 = -1
m4 = 0
i4 = -1
ccc2 = 0
for value in vs2:
    ccc2 += 1
    count = vs2.count(value)
    if count > m3:
        i4 = i3
        m4 = m3
        i3 = value
        m3 = count

if i1 != i3:
    print((ccc - m1) + (ccc2 - m3))
else:
    if m2 > m4:
        print((ccc - m2) + (ccc2 - m3))
    else:
        print((ccc - m1) + (ccc2 - m4))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations


n = int(input())
a = list(map(int, input().split()))
a_occ = Counter(a)

if len(a_occ) == 1:
    print(int(n / 2))
    exit()

a_mcommon = a_occ.most_common()

elem = list()
elem.append(a_mcommon[0][0])
elem.append(a_mcommon[1][0])

for i in range(2, len(a_mcommon)):
    if a_mcommon[i][1] >= a_mcommon[1][1]:
        elem.append(a_mcommon[i][0])
    else:
        break


def algo_run(elem_tuple: tuple, list_to_alt: list) -> int:
    item_select = True
    result_true = 0
    result_false = 0
    for i in list_to_alt:
        if item_select:
            if i != elem_tuple[0]:
                result_true += 1
        else:
            if i != elem_tuple[1]:
                result_true += 1

        if not(item_select):
            if i != elem_tuple[0]:
                result_false += 1
        else:
            if i != elem_tuple[1]:
                result_false += 1

        item_select = not (item_select)

    return result_true if result_true < result_false else result_false


minimum = 9999999
for perm in combinations(elem, 2):
    algo_run_cache = algo_run(perm, a)
    if algo_run_cache < minimum:
        minimum = algo_run_cache


print(minimum)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import permutations


n = int(input())
a = list(map(int, input().split()))
a_occ = Counter(a)

if len(a_occ) == 1:
    print(int(n / 2))
    exit()

a_mcommon = a_occ.most_common()

elem = list()
elem.append(a_mcommon[0][0])
elem.append(a_mcommon[1][0])

for i in range(2, len(a_mcommon)):
    if a_mcommon[i][1] >= a_mcommon[1][1]:
        elem.append(a_mcommon[i][0])
    else:
        break


def algo_run(elem_tuple: tuple, list_to_alt: list) -> int:
    item_select = True
    result = 0
    for i in list_to_alt:
        if item_select:
            if i != elem_tuple[0]:
                result += 1
        else:
            if i != elem_tuple[1]:
                result += 1
        item_select = not (item_select)
    return result


minimum = 9999999
for perm in permutations(elem, 2):
    algo_run_cache = algo_run(perm, a)
    if algo_run_cache < minimum:
        minimum = algo_run_cache


print(minimum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
v_list = [int(x) for x in input().split()]
s = list(set(v_list))
s.sort()
n = 0
count = []
for i in s:
        count.append(v_list.count(i))
if len(s) > 1:

        ind = v_list.index(s[-1])


        for i in range(ind - len(v_list) + 1, ind):
                if i % 2 == ind % 2:
                        if v_list[i] != s[-1]:
                                n += 1
                else:
                        if v_list[i] != s[-2]:
                                n += 1 

else:
        n = int(N / 2)



print(n)

Submission status: Time Limit Exceeded

Solution code:
n = input()
array = map(int, raw_input().split())
e_list = [array[i] for i in range(0, n, 2)]
o_list = [array[i] for i in range(1, n+1, 2)]
if e_list == o_list and len(e_list) == e_list.count(e_list[0]):
    print len(array) / 2
else:
    e_set = [n for n in set(e_list)]
    o_set = [n for n in set(o_list)]
    if len(o_set) == 1 and len(e_set) == 1:
        print 0
    else:
        e_number = []
        o_number = []
        sum = 0
        max = 0
        for number in e_set:
            sum += e_list.count(number)
            if e_list.count(number) > max:
                max = e_list.count(number)
        e_result = sum - max
        sum = 0
        max = 0
        for number in o_set:
            sum += o_list.count(number)
            if o_list.count(number) > max:
                max = o_list.count(number)
        o_result = sum - max
        print e_result + o_result

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
suretu=list(map(int,input().split()))
m=0
M=0
for k in range(int(n/2)):
    h=int(suretu[::2].count(suretu[2*k]))
    if h>m:
        m=h
    s=int(suretu[1::2].count(suretu[2*k+1]))
    if suretu[2*k]==suretu[2*k+1]:
        s=0 
    if s>M:
        M=s
print(n-M-m)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
suretu=list(map(int,input().split()))
m=0
M=0
for k in range(int(n/2)):
    h=int(suretu[::2].count(suretu[2*k]))
    if h>m:
        m=h
    for l in range(int(n/2)):
        s=int(suretu[1::2].count(suretu[2*l+1]))
        if suretu[2*k]==suretu[2*l+1]:
            s=0 
        
        if s>M:
            M=s
print(n-M-m)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
suretu=list(map(int,input().split()))
m=0
M=0
for k in range(int(n/2)):
    h=int(suretu[0::2].count(suretu[2*k]))
    if h>m:
        m=h
    for l in range(int(n/2)):
        s=int(suretu[1::2].count(suretu[2*l+1]))
        if suretu[2*k]==suretu[2*l+1]:
            s=0 
        
        if s>M:
            M=s
print(n-M-m)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
n=list(map(int,input().split()))
#Divide it into even and odd
n1=[]
n2=[]
for i in range(N//2):
    n1.append(n[i*2])
    n2.append(n[i*2-1])
#end

#make lile {key,value}             tabunn kokoga ikenai
cn1=[]
s=0

while n1!=[]:
    j=1
    count=1
    while j < len(n1):
        if n1[j]==n1[0]:
            n1.pop(j)
            count+=1
        else:
            j+=1
    else:
        cn1.append([count,n1[0]])
        n1.pop(0)
        s+=1

cn2=[]
s=0
while n2!=[]:
    j=1
    count=1
    while j < len(n2):
        if n2[j]==n2[0]:
            n2.pop(j)
            count+=1
        else:
            j+=1
    else:
        cn2.append([count,n2[0]])
        n2.pop(0)
        s+=1

#end

#for example(4,1 1 1 1)
cn1.append([0,0])
cn2.append([0,0])
#end

#sort
    #first input
sum1=0
sum2=0
if cn1[0][0]>=cn1[1][0]:
    max11=cn1[0][0]
    num11=cn1[0][1]

    max12=cn1[1][0]
    num12=cn1[1][1]
else:
    max11=cn1[1][0]
    num11=cn1[1][1]

    max12=cn1[0][0]
    num12=cn1[0][1]


if cn2[0][0]>=cn2[1][0]:
    max21=cn2[0][0]
    num21=cn2[0][1]

    max22=cn2[1][0]
    num22=cn2[1][1]
else:
    max21=cn2[1][0]
    num21=cn2[1][1]

    max22=cn2[0][0]
    num22=cn2[0][1]
    #end

for i in range(2,len(cn1)):
    if max12<cn1[i][0]:
        if max11<cn1[i][0]: #if new one is max
            sum1+=max12

            max12=max11
            num12=num11

            max11=cn1[i][0]
            num11=cn1[i][1]
        else:                #if new one is second max
            sum1+=max12

            max12=cn1[i][0]
            num12=cn1[i][1]
    else:
        sum1+=cn1[i][0]


for i in range(2,len(cn2)):
    if max22<cn2[i][0]:
        if max21<cn2[i][0]: #if new one is max
            sum2+=max22

            max22=max21
            num22=num21

            max21=cn2[i][0]
            num21=cn2[i][1]
        else:               #if new one is second max
            sum2+=max22

            max22=cn2[i][0]
            num22=cn2[i][1]
    else:
        sum2+=cn2[i][0]
#end

#print(cn1,max11,num11,max12,num12,"\n")
#print(cn2,max21,num21,max22,num22,"\n")

#answer
if num11 != num21:
    ans=sum1+sum2+max12+max22
elif max11-max12 > max21-max22:#prefer large disadvantage  
    ans=sum1+sum2+max12+max21
else:
    ans=sum1+sum2+max11+max22
print(ans)
#end

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
n=list(map(int,input().split()))
#Divide it into even and odd
n1=[]
n2=[]
for i in range(N//2):
    n1.append(n[i*2])
    n2.append(n[i*2-1])
#end
#make lile {key,value}
cn1=[]
s=0
while n1!=[]:
    cn1.append([n1.count(n1[0]),n1[0]])
    for j in range(cn1[s][0]):
            n1.remove(cn1[s][1])
    s+=1

cn2=[]
s=0
while n2!=[]:
    cn2.append([n2.count(n2[0]),n2[0]])
    for j in range(cn2[s][0]):
            n2.remove(cn2[s][1])
    s+=1
#end

#for example(4,1 1 1 1)
cn1.append([0,0])
cn2.append([0,0])
#end

#sort
    #first input
sum1=0
sum2=0
if cn1[0][0]>=cn1[1][0]:
    max11=cn1[0][0]
    num11=cn1[0][1]

    max12=cn1[1][0]
    num12=cn1[1][1]
else:
    max11=cn1[1][0]
    num11=cn1[1][1]

    max12=cn1[0][0]
    num12=cn1[0][1]


if cn2[0][0]>=cn2[1][0]:
    max21=cn2[0][0]
    num21=cn2[0][1]

    max22=cn2[1][0]
    num22=cn2[1][1]
else:
    max21=cn2[1][0]
    num21=cn2[1][1]

    max22=cn2[0][0]
    num22=cn2[0][1]
    #end

for i in range(2,len(cn1)):
    if max12<cn1[i][0]:
        if max11<cn1[i][0]: #if new one is max
            sum1+=max12

            max12=max11
            num12=num11

            max11=cn1[i][0]
            num11=cn1[i][1]
        else:                #if new one is second max
            sum1+=max12

            max12=cn1[i][0]
            num12=cn1[i][1]
    else:
        sum1+=cn1[i][0]


for i in range(2,len(cn2)):
    if max22<cn2[i][0]:
        if max21<cn2[i][0]: #if new one is max
            sum2+=max22

            max22=max21
            num22=num21

            max21=cn2[i][0]
            num21=cn2[i][1]
        else:               #if new one is second max
            sum2+=max22

            max22=cn2[i][0]
            num22=cn2[i][1]
    else:
        sum2+=cn2[i][0]
#end

#print(cn1,max11,num11,max12,num12,"\n")
#print(cn2,max21,num21,max22,num22,"\n")

#answer
if num11 != num21:
    ans=sum1+sum2+max12+max22
elif max11-max12 > max21-max22:#prefer large disadvantage  
    ans=sum1+sum2+max12+max21
else:
    ans=sum1+sum2+max11+max22
print(ans)
#end