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:
import collections
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])
    
ac = collections.Counter(a)
bc = collections.Counter(b)

atemp = []
for i in ac:
    atemp.append(ac[i])
btemp = []
for i in bc:
    btemp.append(bc[i])

mxma = max(atemp)
mxmb = max(btemp)
for i in ac:
    if ac[i] == mxma:
        mxma = i
        break
for i in bc:
    if bc[i] == mxmb:
        mxmb = i
        break

atemp.sort()
btemp.sort()

if mxma != mxmb:
    print(n-max(atemp)-max(btemp))
else:
    if len(atemp) == 1 and len(btemp) == 1:
        print(n-max(atemp))
    else:
        temp = [a[-2]+b[-1],a[-1],b[-2]]
        print(n-max(temp))

Submission status: Wrong Answer

Solution code:
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
v = il()
a = dict()
b = dict()
for i in range(n):
    if i&1:
        if v[i] in a:
            a[v[i]] += 1
        else:
            a[v[i]] = 1
    else:
        if v[i] in b:
            b[v[i]] += 1
        else:
            b[v[i]] = 1
ans = 0
if len(a) > 1:
    A = sorted(a.values())
    ans += n//2 - A[-1]
if len(b) > 1:
    A = sorted(b.values())
    ans += n//2 - A[-1]
if a == b:
    ans += n //2 
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


C1 = list(dict(Counter(A[::2])).items())
N1 = len(A[::2])
C2 = list(dict(Counter(A[1::2])).items())
N2 = len(A[::2])

C1.append([-1, 0])
C2.append([-1, 0])
C1.sort(key=lambda x: x[1], reverse=True)
C2.sort(key=lambda x: x[1], reverse=True)

if C1[0][0] != C2[0][0]:
    print(N1 - C1[0][1] + N2 - C2[0][1])
else:
    ans1 = N1 - C1[0][1] + N2 - C2[1][1]
    ans2 = N1 - C1[1][0] + N2 - C2[0][1]
    print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    a =list(map(int, input().split()))
    b = a[::2]
    c = a[1::2]

    retB ={}
    for i in b:
        retB[i] = retB.get(i, 0) + 1

    retC ={}
    for i in c:
        retC[i] = retC.get(i, 0) + 1

    retB = sorted(retB.items(), key=lambda x: x[1])
    retC = sorted(retC.items(), key=lambda x: x[1])
    if retB[0][0] != retC[0][0]:
        tmpB = len(b) - retB[0][1]
        tmpC = len(c) - retC[0][1]
        print(tmpC + tmpB)
    else:
        if len(retB) == 1 and len(retC) == 1:
            print(len(c))
            return
        if len(retB) == 1:
            tmpB = len(b) - retB[0][1]
            tmpC = len(c) - retC[1][1]
            print(tmpB+tmpC)
            return
        if len(retC) == 1:
            tmpB = len(b) - retB[1][1]
            tmpC = len(c) - retC[0][1]
            print(tmpB+tmpC)
            return
        tmpB = len(b) - retB[1][1]
        tmpC = len(c) - retC[0][1]
        ret = [tmpB+tmpC]
        tmpB = len(b) - retB[0][1]
        tmpC = len(c) - retC[1][1]
        ret.append(tmpB+tmpC)
        print(min(ret))
main()

Submission status: Wrong Answer

Solution code:
from sys import stdin

input = lambda: stdin.readline()

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

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

    even = {V[i] for i in range(N) if not i % 2}
    odd = {V[i] for i in range(N) if i % 2}
    print(len(even) + len(odd) - 2)

main()

Submission status: Wrong Answer

Solution code:
import sys

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

check=0
for i in range(n):
    if V[i]!=V[i-1]:
        check=1
        break

if check==0:
    print(n//2)
    sys.exit()


G=[]
K=[]
for i in range(n):
    if i%2==0:
        G.append(V[i])
    else:
        K.append(V[i])

G.sort()
K.sort()

count=1
GANS=0
for i in range(1,len(G)):
    if G[i]==G[i-1]:
        count+=1
    else:
        GANS=max(GANS,count)
        count=1

GANS=max(GANS,count)

count=1
KANS=0
for i in range(1,len(K)):
    if K[i]==K[i-1]:
        count+=1
    else:
        KANS=max(KANS,count)
        count=1

KANS=max(KANS,count)

ANS=len(G)-GANS+len(K)-KANS
print(ANS)

Submission status: Wrong Answer

Solution code:
n = int(input())
t = list(map(int,input().split(" ")))
dic1 = {}
dic2 = {}
for i in range(n):
    v = t[i]
    if i % 2 == 1:
        if v in dic1:
            dic1[v] += 1
        else:
            dic1[v] = 1
    else:
        if v in dic2:
            dic2[v] += 1
        else:
            dic2[v] = 1


a = list(dic1.items())
b = list(dic2.items())
a.sort(key=lambda x:x[1])
b.sort(key=lambda x:x[1]) 

if a[-1][0] != b[-1][0]:
    m1 = a[-1][1]
    m2 = b[-1][1]

elif len(a) == 1 and len(b) == 1:
    m1 = a[-1][1]
    m2 = 0

elif  len(a) == 1:
    m1 = a[-1][1]
    m2 = b[-2][1]

elif len(b) == 1:
    m1 = a[-2][1]
    m2 = b[-1][1]

else:
    m = [ a[-1][1],a[-2][1],b[-1][1],b[-2][1]]
    m.sort()
    m1 = m[-1]
    m2 = m[-2]

print(n - m1 - m2)

Submission status: Wrong Answer

Solution code:
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
v = il()
a = dict()
b = dict()
for i in range(n):
    if i&1:
        if v[i] in a:
            a[v[i]] += 1
        else:
            a[v[i]] = 1
    else:
        if v[i] in b:
            b[v[i]] += 1
        else:
            b[v[i]] = 1
ans = 0
if len(a) > 1:
    A = sorted(a.values())
    ans += A[0]
if len(b) > 1:
    A = sorted(b.values())
    ans += A[0]
if a == b:
    ans += n //2 
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

even = Counter(a[::2])
odd = Counter(a[1::2])

emax = [0]
ekey = [0]
for ek,ev in even.items():
    if ev >= emax[-1]:
        emax.append(ev)
        ekey.append(ek)
    
omax = [0]
okey = [0]
for ok,ov in odd.items():
    if ov >= omax[-1]:
        omax.append(ov)
        okey.append(ok)

if ekey[-1] != okey[-1]:
    print((n//2-emax[-1]) + (n//2-omax[-1]))
else:
    print(max((n//2-emax[-1]) + (n//2-omax[-2]),
              (n//2-emax[-2]) + (n//2-omax[-1])))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
a = v[0::2]
b = v[1::2]
a = sorted(a)
b = sorted(b)
a = collections.Counter(a).most_common()
b = collections.Counter(b).most_common()
if a[0][0]!=b[0][0]:
    print(n - a[0][1] - b[0][1])
elif a==b:
    print(n//2)
else:
    print(min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from collections import Counter
n = int(input())
A = inpl()

C1 = Counter(A[::2])
C2 = Counter(A[1::2])

S1 = sorted(C1.items(), key=lambda x: x[1], reverse=True) + [[0, 0]]
S2 = sorted(C2.items(), key=lambda x: x[1], reverse=True) + [[0, 0]]

if S1[0] != S2[0]:
    print(n - S1[0][1] - S2[0][1])
else:
    print(n - max(S1[1][1] - S2[0][1], S1[0][1] - S2[1][1]))

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n = read()
v = reads()

evens = sorted((v, k) for k, v in Counter(v[::2]).items()) + [(0, -1)]
odds = sorted((v, k) for k, v in Counter(v[1::2]).items()) + [(0, -1)]

if evens[0][1] != odds[0][1]:
  ans = n - evens[0][0] - odds[0][0]
else:
  ans = n - max(evens[0][0] + odds[1][0], evens[1][0] + odds[0][0])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

check=0
for i in range(n):
    if V[i]!=V[i-1]:
        check=1
        break

if check==0:
    print(n//2)
    sys.exit()


G=[]
K=[]
for i in range(n):
    if i%2==0:
        G.append(V[i])
    else:
        K.append(V[i])

G.sort()
K.sort()

count=1
GANS=0
for i in range(1,len(G)):
    if G[i]==G[i-1]:
        count+=1
    else:
        GANS=max(GANS,count)
        count=0

GANS=max(GANS,count)

count=1
KANS=0
for i in range(1,len(K)):
    if K[i]==K[i-1]:
        count+=1
    else:
        KANS=max(KANS,count)
        count=0

KANS=max(KANS,count)

ANS=len(G)-GANS+len(K)-KANS
print(ANS)

Submission status: Wrong Answer

Solution code:
import sys
n = int(raw_input())
nums = list(map(int,raw_input().split()))
cnt1 = [0 for x in range(100001)]
cnt2 = [0 for x in range(100001)]
for i in range(n):
    if i%2:
        cnt1[nums[i]] += 1
    else:
        cnt2[nums[i]] += 1
a1 = -1
a2 = -1
n1 = 0
n2 = 0
b1 = -1
b2 = -1
m1 = 0
m2 = 0
for i in range(100001):
    if cnt1[i]>a1:
        a2 = a1
        a1 = cnt1[i]
        n2 = n1
        n1 = i
    elif cnt1[i]>a2:
        a2 = cnt1[i]
        n2 = i
    if cnt2[i]>b1:
        b2 = b1
        b1 = cnt2[i]
        m2 = m1
        m1 = i
    elif cnt2[i]>b2:
        b2 = cnt2[i]
        m2 = i
if m1!=n1:
    print n-a1-b1
else:
    if m1+n2<m2+n1:
        print n-a1-b2
    else:
        print n-a2-b1

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
v = list(map(int, input().split()))
rec = defaultdict(int)
for k in v:
    rec[k] += 1

m = n // 2
INF = float("inf")
ma = INF
se = INF
mai = 0
sei = 0
for i, k in rec.items():
    if abs(k - m) < ma:
        sei = mai
        se = ma
        mai = i
        ma = abs(k - m)
        continue
    if abs(k - m) < se:
        se = abs(k - m)
        sei = i

if se + ma == INF:
    print(m)
else:
    print(se + ma)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
V = [int(_) for _ in input().split()]

res = Counter(V).most_common()

if len(res) == 1:
    print(n // 2)
else:
    print(sum([num for x, num in res[2:]]))

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n = read()
v = reads()

evens = sorted((v, k) for k, v in Counter(v[::2]).items()) + [(0, -1)]
odds = sorted((v, k) for k, v in Counter(v[1::2]).items()) + [(0, -1)]

print(evens, odds)

if evens[0][1] != odds[0][1]:
  ans = n - evens[0][0] - odds[0][0]
else:
  ans = n - max(evens[0][0] + odds[1][0], evens[1][0] + odds[0][0])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

one = sorted(Counter([v[i] for i in range(0, n, 2)]).items(), key=lambda x: x[1], reverse=True)
two = sorted(Counter([v[i] for i in range(1, n, 2)]).items(), key=lambda x: x[1], reverse=True)

if one[0][0] != two[0][0]:
	print(n - one[0][1] - two[0][1])
else:
	if len(one) == 1 and len(two) == 1:
		print(n // 2)
	elif len(one) == 1:
		print(n // 2 - two[1][1])
	elif len(two) == 1:
		print(n // 2 - one[1][1])
	else:
		print(n - one[0][1] - two[1][1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

from collections import Counter

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

c = Counter(v)
if len(c) == 1:
    print(n//2)
    exit()
fc = c.most_common(2)
count1 = fc[0][1]
count2 = fc[1][1]
ok = 0

if count1 <= n//2:
    ok += count1
else:
    ok = n//2
ok += count2


print(n-ok)

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n = read()
v = reads()

evens = sorted((v, k) for k, v in Counter(v[::2]).items()) + [(0, -1)]
odds = sorted((v, k) for k, v in Counter(v[1::2]).items()) + [(0, -1)]

if evens[0][1] != odds[0][1]:
  ans = n - evens[0][0] - odds[0][0]
else:
  ans = n - min(evens[0][0] + odds[1][0], evens[1][0] + odds[0][0])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

ODD = defaultdict(int)
EVEN = defaultdict(int)
NUMBER = set()

for i in range(n):
    if i%2==0:
        EVEN[V[i]] += 1
    else:
        ODD[V[i]] += 1
    NUMBER.add(V[i])
    
if len(NUMBER)==1:
    print(n//2)
else:
    print(n-max(ODD.values())-max(EVEN.values()))

Submission status: Wrong Answer

Solution code:
import collections

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

count_even = collections.Counter(v[0::2])
count_odd =  collections.Counter(v[1::2])
print(n//2 - max(count_even.values()) + n//2 - max(count_odd.values()))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(input().split())
from collections import Counter
x, y = list(Counter(v[::2]).items()), list(Counter(v[1::2]).items())
x.sort(key=lambda i:i[1], reverse=True)
y.sort(key=lambda i:i[1], reverse=True)
r = []
for a, b in x[:max(len(x), 3)]:
    for aa, bb in y[:max(len(y), 3)]:
        if a == aa:
            r.append(n-max(b, bb))
        else:
            r.append(n-b-bb)
print(min(r))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(input().split())
from collections import Counter
x, y = list(Counter(v[::2]).items()), list(Counter(v[1::2]).items())

r = []
for a, b in x:
    for aa, bb in y:
        if a == aa:
            r.append(n-max(b, bb))
        else:
            r.append(n-b-bb)
print(min(r))

Submission status: Time Limit Exceeded

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

if l == 2 and n == 2:
    print(0)

elif l == 1 and n == 2:
    print(1)
    

elif l >= 2:
    v0 = v[0::2]
    v1 = v[1::2]
    print(n-v0.count(max(v0, key=v0.count))-v1.count(max(v1, key=v1.count)))   

else :
    print(n//2)

Submission status: Time Limit Exceeded

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


if len(list(set(v))) == 2 and n == 2:
    print(0)

elif len(list(set(v))) == 1 and n == 2:
    print(1)
    

elif len(list(set(v))) >= 2:
    v0 = v[0::2]
    v1 = v[1::2]
    print(n-v0.count(max(v0, key=v0.count))-v1.count(max(v1, key=v1.count)))   

else :
    print(n//2)

Submission status: Time Limit Exceeded

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

v0 = v[0::2]
v1 = v[1::2]
a = len(v0) - v0.count(max(v0, key=v0.count))
b = len(v1) - v1.count(max(v1, key=v1.count))


if len(list(set(v))) == 2 and n == 2:
    print(0)

elif len(list(set(v))) == 1 and n == 2:
    print(1)
    

elif len(list(set(v))) >= 2:
    print(a+b)   

else :
    print(n//2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
cnt = 0
a = max(v[0::2], key=v[0::2].count)
b = max(v[1::2], key=v[1::2].count)


if len(list(set(v))) == 2 and n == 2:
    print(0)

elif len(list(set(v))) == 1 and n == 2:
    print(1)
    

elif len(list(set(v))) >= 2:
    for i in range(n//2):
        if a != v[2*i]:
            cnt += 1
    for i in range(n//2):
        if b != v[2*i+1]:
            cnt += 1
    print(cnt)   

else :
    print(n//2)

Submission status: Time Limit Exceeded

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

if len(list(set(v))) >= 2:
    for i in range(0, n-2, 2):
        if v[i+2] in v and v[0] != v[i+2]:
            cnt += 1
    for i in range(1, n-2, 2):
        if v[i+2] in v and v[1] != v[i+2]:
            cnt += 1
    print(cnt)   

else :
    print(n//2)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
if len(set(ar)) == 1:
    print(a // 2)
    exit()
br = []
cr = []
for i in range(a):
    if i % 2 == 0:
        br.append(ar[i])
    else:
        cr.append(ar[i])
sb = set(br)
sc = set(cr)
count = 0
b = []
c = []
for s in sb:
    b.append(br.count(s))
for s in sc:
    c.append(cr.count(s))
count += a // 2 - max(b)
count += a // 2 - max(c)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
import collections

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

evli=[]
odli=[]

for i in range(n):
    if i%2==0:
        evli.append(l[i])
        ce=collections.Counter(evli)
    else:
        odli.append(l[i])
        co=collections.Counter(odli)

e=ce.most_common()[0][1]
o=co.most_common()[0][1]

if ce.most_common()[0][0] == co.most_common()[0][0]:
    if e>o and o!=n//2:
        o=co.most_common()[1][1]
    elif e==o and o==n//2:
        o=0
    elif o>e and e!=n//2:
        e=ce.most_common()[1][1]
    else:
        e2=ce.most_common()[1][1]
        o2=co.most_comoon()[1][1]
        if e2>o2:
            e=e2
        else:
            o=o2
            

print(n-e-o)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main():
    N = int(input())
    V = list(map(int, input().split()))
    V1 = []
    V2 = []
    for i in range(0,len(V),2):
        V1.append(V[i])
    for i in range(1,len(V),2):
        V2.append(V[i])  
    VC1 = Counter(V1)
    VC2 = Counter(V2)
    count = 0
    for i in range(1,len(VC1)):
        count += VC1.most_common()[i][1]
    for i in range(1,len(VC2)):
        count += VC2.most_common()[i][1]
    if str(VC1.most_common()[0][0]) == str(VC2.most_common()[0][0]) and len(VC1)==1:
        count += VC1.most_common()[0][1]
    elif  str(VC1.most_common()[0][0]) == str(VC2.most_common()[0][0]):
        vc1sa = VC1.most_common()[0][1] - VC1.most_common()[1][1]
        vc2sa = VC1.most_common()[0][1] - VC1.most_common()[1][1]
        count += min([vc1sa,vc2sa])


    print(count)




if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def str_to_int(lista):
    for num, i in enumerate(lista):
        lista[num]=int(i)
    
    
def main():
    N= int(input())
    lst_v = input().split()
    str_to_int(lst_v)
    lst_sum_o = []
    lst_srt_o = []
    lst_sum_e = []
    lst_srt_e = []
    for num, i in enumerate(lst_v):
        if num%2 == 0:
            if i in lst_srt_e:
                lst_sum_e[lst_srt_e.index(i)] = lst_sum_e[lst_srt_e.index(i)] + 1
            else:
                lst_srt_e.append(i)
                lst_sum_e.append(1)
        elif num%2 == 1:    
            if i in lst_srt_o:
                lst_sum_o[lst_srt_o.index(i)] = lst_sum_o[lst_srt_o.index(i)] + 1
            else:
                lst_srt_o.append(i)
                lst_sum_o.append(1)

    if lst_srt_o[lst_sum_o.index(max(lst_sum_o))] == lst_srt_e[lst_sum_e.index(max(lst_sum_e))]:
        if len(lst_sum_o) == 1 and len(lst_sum_e) == 1 :
            print(max(lst_sum_o))
        
        else:
            if len(lst_sum_o) == 1:
                lst_sum_o.append(max(lst_sum_o))
                
            if len(lst_sum_e) == 1:
                lst_sum_e.append(max(lst_sum_e))
        
            lst_sum_o.sort()
            lst_sum_e.sort()
            if lst_sum_o[-2]>=lst_sum_e[-2]:
                print(int(N/2)- max(lst_sum_o) + int(N/2)- lst_sum_e[-2])
                #print("OK1")
            else:
                print(int(N/2)- max(lst_sum_e) + int(N/2)- lst_sum_o[-2])
                #print("OK2")
        #print(lst_sum_e)
    #print(lst_srt_o, lst_sum_o,lst_srt_e, lst_sum_e)
    else:
        print(N - max(lst_sum_o) + - max(lst_sum_e) )
    
        
    
main()

Submission status: Time Limit Exceeded

Solution code:

def str_to_int(lista):
    for num, i in enumerate(lista):
        lista[num]=int(i)
    
    
def main():
    N= int(input())
    lst_v = input().split()
    str_to_int(lst_v)
    lst_sum_o = []
    lst_srt_o = []
    lst_sum_e = []
    lst_srt_e = []
    for num, i in enumerate(lst_v):
        if num%2 == 0:
            if i in lst_srt_e:
                lst_sum_e[lst_srt_e.index(i)] = lst_sum_e[lst_srt_e.index(i)] + 1
            else:
                lst_srt_e.append(i)
                lst_sum_e.append(1)
        elif num%2 == 1:    
            if i in lst_srt_o:
                lst_sum_o[lst_srt_o.index(i)] = lst_sum_o[lst_srt_o.index(i)] + 1
            else:
                lst_srt_o.append(i)
                lst_sum_o.append(1)

    if lst_srt_o[lst_sum_o.index(max(lst_sum_o))] == lst_srt_e[lst_sum_e.index(max(lst_sum_e))]:
        if len(lst_sum_o) == 1 and len(lst_sum_e) == 1 :
            print(max(lst_sum_o))
        
        else:
            if len(lst_sum_o) == 1:
                lst_sum_o.append(max(lst_sum_o))
                
            if len(lst_sum_e) == 1:
                lst_sum_e.append(max(lst_sum_e))
        
            lst_sum_o.sort()
            lst_sum_e.sort()
            if lst_sum_o[-2]>=lst_sum_e[-2]:
                print(int(N/2)- max(lst_sum_o) + int(N/2)- lst_sum_e[-2])
                print("OK1")
            else:
                print(int(N/2)- max(lst_sum_e) + int(N/2)- lst_sum_o[-2])
                print("OK2")
        #print(lst_sum_e)
    #print(lst_srt_o, lst_sum_o,lst_srt_e, lst_sum_e)
    else:
        print(N - max(lst_sum_o) + - max(lst_sum_e) )
    
        
    
main()

Submission status: Time Limit Exceeded

Solution code:

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

u1 = u[::2]
u2 = u[1::2]

k1 = len(set(u1))
k2 = len(set(u2))

if k1 == k2 == 1:
    if u1[0] == u2[0]:
        print(n//2)
    else:
        print(0)
elif k1 == 1:
    c2 = []
    for i in u2:
        c2.append(u2.count(i))
    m2 = max(c2)
    if m2 != u1[0]:
        f2 = u2.index(m2)
        n2 = len(u2) - u2.count(u2[f2])
        print(n2)
    else:
        for i in c2:
            if i == u1[0]:
                c2.remove(i)
        m2 = max(c2)
        f2 = u2.index(m2)
        n2 = len(u2) - u2.count(u2[f2])
        print(n2)
elif k2 == 1:
    c1 = []
    for i in u1:
        c1.append((u1.count(i)))
    m1 = max(c1)
    if m1 != u2[0]:
        f1 = u1.index(m1)
        n1 = len(u1) - u1.count(u1[f1])
        print(n1)
    else:
        for i in c1:
            if i == u2[0]:
                c1.remove(i)
        m1 = max(c1)
        f1 = u1.index(m1)
        n1 = len(u1) - u1.count(u1[f1])
        print(n1)
else:
    c2 = []
    for i in u2:
        c2.append(u2.count(i))
    m2 = max(c2)
    c1 = []
    for i in u1:
        c1.append((u1.count(i)))
    m1 = max(c1)
    if m1 == m2:
        c1c = c1.copy()
        for i in c1c:
            if m2 == i:
                c1c.remove(i)
        l1 = max(c1c)
        c2c = c2.copy()
        for i in c2c:
            if m1 == i:
                c2c.remove(i)
        l2 = max(c2c)
        if l1 >= l2:
            n2 = len(u2) - u2.count(l2)
            print(n2)
        else:
            n1 = len(n1) - u1.count(l1)
            print(n1)
    else:
        f1 = u1.index(m1)
        n1 = len(u1) - u1.count(u1[f1])
        f2 = u2.index(m2)
        n2 = len(u2) - u2.count(u2[f2])
        print(n1 + n2)

Submission status: Time Limit Exceeded

Solution code:

N = int(raw_input())
A = [int(i) for i in raw_input().split()]

A0 = A[0:N:2]
A1 = A[1:N:2]

S0 = set(A0)
S1 = set(A1)
N0 = []
N1 = []

for s in S0:
    N0.append((s, sum(map(lambda x: x==s, A0))))

for s in S1:
    N1.append((s, sum(map(lambda x: x==s, A1))))

N0.sort(key=lambda x: x[1], reverse=True)
N1.sort(key=lambda x: x[1], reverse=True)

if N0[0][0] == N1[0][0]:
    if N0[0][0] < N1[0][0]:
        if len(N0) == 1:
            print N - N1[0][1]
        else:
            print N - N0[1][1] - N1[0][1]
    else:
        if len(N1) == 1:
            print N - N0[0][1]
        else:
            print N - N0[0][1] - N1[1][1]
else:
    print N - N0[0][1] - N1[0][1]

Submission status: Time Limit Exceeded

Solution code:
N = int(raw_input())
A = [int(i) for i in raw_input().split()]

A0 = [A[i] for i in xrange(0, N, 2)]
A1 = [A[i] for i in xrange(1, N, 2)]

Count = 0
S0 = set(A0)
S1 = set(A1)
N0 = []
N1 = []

for s in S0:
    N0.append((s, sum(map(lambda x: x==s, A0))))

for s in S1:
    N1.append((s, sum(map(lambda x: x==s, A1))))

N0.sort(key=lambda x: x[1], reverse=True)
N1.sort(key=lambda x: x[1], reverse=True)

if N0[0][0] == N1[0][0]:
    if N0[0][0] < N1[0][0]:
        if len(N0) == 1:
            print N - N1[0][1]
        else:
            print N - N0[1][1] - N1[0][1]
    else:
        if len(N1) == 1:
            print N - N0[0][1]
        else:
            print N - N0[0][1] - N1[1][1]
else:
    print N - N0[0][1] - N1[0][1]

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n=int(input())
    v=list(map(int,input().split()))
    if len(set(v))==1:
    	print(n//2)
    else:
	    ki=v[::2]
	    gu=v[1::2]
	    ski=set(ki)
	    sgu=set(gu)
	    cki=max([ki.count(i) for i in ski])
	    cgu=max([gu.count(i) for i in sgu])
	    print(len(ki)-cki + len(gu)-cgu)

resolve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int,input().split()))
vodd = v[0::2]
veven = v[1::2]

set_vodd = list(set(vodd))
set_veven = list(set(veven))
cnt_vodd = [0] * len(set_vodd)
cnt_veven = [0] * len(set_veven)

if len(set_vodd) == 1 and set_vodd == set_veven:
    print(int(n/2))
else:
    for i in range(len(set_vodd)):
        cnt_vodd[i] = vodd.count(set_vodd[i])
    sort_cnt_vodd = sorted(cnt_vodd)
    ans_vodd = (n/2) - (sort_cnt_vodd[-1])

    for i in range(len(set_veven)):
        cnt_veven[i] = veven.count(set_veven[i])
    sort_cnt_veven = sorted(cnt_veven)
    ans_veven = (n/2) - (sort_cnt_veven[-1])
    
    print(int(ans_vodd) + int(ans_veven))

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(l):
  maximam = 0
  for i in set(l):
    count = l.count(i)
    if count > maximam:
      num = [i]
      maximam = count
    elif count == maximam:
      num.append(i)

  return maximam, num

odd_count = count(odd)
even_count = count(even)

if odd_count[1] == even_count[1] and len(odd_count[1]) ==1:
  if odd_count[0] == N//2:
    ans = N // 2
  else:
    even = [i if i != even_count[1][0] else -1 for i in even]
    odd = [i if i != odd_count[1][0] else -1 for i in odd]
    even_count2 = count(odd)
    odd_count2 = count(even)
    ans = N - max(odd_count[0] + even_count2[0], odd_count2[0] + even_count[0])
else:
  ans = N - (odd_count[0] + even_count[0])
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
if len(set(l))==1:
  print(n//2)
else:
  import collections as co
  op=0
  evc=co.Counter(l[::2])
  odc=co.Counter(l[1::2])
  for a in odc:
    for b in evc:
      if a!=b:
        op=max([op,evc[b]+odc[a]])
  print(n-op)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
sl=set(l)
if len(sl)==1:
  print(n//2)
elif len(sl)>2:
  ev=l[::2]
  od=l[1::2]
  op=0
  for a in set(ev):
    for b in set(od):
      if a!=b:
        op=max([op,ev.count(a)+od.count(b)])
  print(n-op)
else:
  a,b=list(sl)[0],list(sl)[1]
  s,d=0,0
  for i in l[::2]:
    if i!=a:
      s+=1
    else:
      d+=1
  for jg in l[1::2]:
    if jg!=a:
      d+=1
    else:
      s+=1
  print(min([s,d]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=list(map(int,input().split()))
sl=set(l)
if len(sl)==1:
  print(n//2)
elif len(sl)>2:
  ans=n
  lsl=list(sl)
  d=len(sl)
  for a in range(d)[1:]:
    for b in range(d)[:a]:
      y,x=lsl[a],lsl[b]
      g,h=0,0
      for rt in l[::2]:
        if rt != y:
          g+=1
        if rt != x:
          h+=1
      for ef in l[1::2]:
        if ef!=x:
          g+=1
        if ef!=y:
          h+=1
      ans=min([g,h,ans])
  print(ans)
else:
  a,b=list(sl)[0],list(sl)[1]
  s,d=0,0
  for i in l[::2]:
    if i!=a:
      s+=1
    else:
      d+=1
  for jg in l[1::2]:
    if jg!=a:
      d+=1
    else:
      s+=1
  print(min([s,d]))

Submission status: Time Limit Exceeded

Solution code:
# 2125
n = int(input())
get_inf = list(map(int, input().split(' ')))
a = get_inf[::2]
b = get_inf[1::2]

def count_unique(lis):
    r = []
    s = []
    i = 0
    while i < len(lis):
        count = 1
        k = i + 1
        if lis[i] > 0:
            while k < len(lis):
                if lis[i] == lis[k] and lis[k] > 0:
                    count += 1
                    lis[k] *= -1
                k += 1
            r.append(count)
            s.append(lis[i])
            lis[i] *= -1
            i += 1
        else:
            i += 1
    return r, s

x = []
x_1 = []
y = []
y_1= []
x, x_1 = count_unique(a)
y, y_1 = count_unique(b)
x.append(0)
y.append(0)

if x_1[x.index(max(x))] != y_1[y.index(max(y))]:
    print(n-max(x)-max(y))
else:
    p = max(x)
    q = max(y)
    x[x.index(max(x))] *= -1
    y[y.index(max(y))] *= -1
    print(min([n-p-max(y), n-q-max(x)]))

Submission status: Time Limit Exceeded

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

count = 0
count1 = 0
for i in range(0,n,2):
    count = max(count, v.count(v[i]))
for j in range(1,n,2):
    count1 = max(count1, v.count(v[j]))
print(n//2 if len(set(v)) == 1 else n-count-count1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = list(map(int, input().split()))
a = v[::2]
b = v[1::2]
count = 0
count1 = 0
for i in a:
    count = max(count, a.count(i))
for j in b:
    count1 = max(count1, b.count(j))
print(n//2 if len(set(v)) == 1 else n-count-count1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
v = input().split()
set_v = set(v)
odd = []
even = []
if len(set_v) == 1:
  print(len(v)//2)
else:
    for i in range(0,n,2):
        odd.append(v[i])
    for i in range(1,n+1,2):
        even.append(v[i])
    max_odd = 0
    max_even = 0
    for i in set(odd):
        max_odd = max(max_odd,odd.count(i))
    for i in set(even):
        max_even = max(max_even,even.count(i))
    print(n-max_odd-max_even)