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

O = {}
E = {}

for i in v[0::2]:
    if i in O:
        O[i] += 1
    else:
        O[i] = 1

for i in v[1::2]:
    if i in E:
        E[i] += 1
    else:
        E[i] = 1

o_candidate = [[0, 0], [0, 0]]
e_candidate = [[0, 0], [0, 0]]

for i, j in O.items():
    if j >= o_candidate[0][1] or j >= o_candidate[1][1]:
        o_candidate[1] = o_candidate[0]
        o_candidate[0] = [i, j]

for i, j in E.items():
    if j >= e_candidate[0][1] or j >= e_candidate[1][1]:
        e_candidate[1] = e_candidate[0]
        e_candidate[0] = [i, j]
    elif j == e_candidate[0][1]:
        e_candidate[1] = [i, j]

if o_candidate[0][0] != e_candidate[0][0]:
    ans = n - o_candidate[0][1] - e_candidate[0][1]
else:
    ans = min(n - o_candidate[0][1] - e_candidate[1][1],
              n - o_candidate[1][1] - e_candidate[0][1])

print(ans)

Submission status: Wrong Answer

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

O = {}
E = {}

for i in v[0::2]:
    if i in O:
        O[i] += 1
    else:
        O[i] = 1

for i in v[1::2]:
    if i in E:
        E[i] += 1
    else:
        E[i] = 1

o_candidate = [[0, 0], [0, 0]]
e_candidate = [[0, 0], [0, 0]]

for i, j in O.items():
    if j >= o_candidate[0][1]:
        o_candidate[1] = o_candidate[0]
        o_candidate[0] = [i, j]

for i, j in E.items():
    if j >= e_candidate[0][1]:
        e_candidate[1] = e_candidate[0]
        e_candidate[0] = [i, j]

if o_candidate[0][0] != e_candidate[0][0]:
    ans = n - o_candidate[0][1] - e_candidate[0][1]
else:
    ans = min(n - o_candidate[0][1] - e_candidate[1][1],
              n - o_candidate[1][1] - e_candidate[0][1])

print(ans)

Submission status: Wrong Answer

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

O = {}
E = {}

for i in v[0::2]:
    if i in O:
        O[i] += 1
    else:
        O[i] = 1

for i in v[1::2]:
    if i in E:
        E[i] += 1
    else:
        E[i] = 1

o_candidate = [[0, 0], [0, 0]]
e_candidate = [[0, 0], [0, 0]]

for i, j in O.items():
    if j >= o_candidate[0][1]:
        o_candidate[1] = o_candidate[0]
        o_candidate[0] = [i, j]

for i, j in E.items():
    if j >= e_candidate[0][1]:
        e_candidate[1] = e_candidate[0]
        e_candidate[0] = [i, j]

if o_candidate[0][0] != e_candidate[0][0]:
    ans = n - o_candidate[0][1] - e_candidate[0][1]
else:
    if o_candidate[0][1] > e_candidate[0][1]:
        ans = n - o_candidate[0][1] - e_candidate[1][1]
    elif o_candidate[0][1] < e_candidate[0][1]:
        ans = n - o_candidate[1][1] - e_candidate[0][1]
    else:
        if o_candidate[1][1] > e_candidate[1][1]:
            ans = n - o_candidate[1][1] - e_candidate[0][1]
        else:
            ans = n - o_candidate[0][1] - e_candidate[1][1]

print(ans)

Submission status: Wrong Answer

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

O = {}
E = {}

for i in v[0::2]:
    if i in O:
        O[i] += 1
    else:
        O[i] = 1

for i in v[1::2]:
    if i in E:
        E[i] += 1
    else:
        E[i] = 1

o_candidate = [[0, 0], [0, 0]]
e_candidate = [[0, 0], [0, 0]]

for i, j in O.items():
    if j >= o_candidate[0][1]:
        o_candidate[1] = o_candidate[0]
        o_candidate[0] = [i, j]

for i, j in E.items():
    if j >= e_candidate[0][1]:
        e_candidate[1] = e_candidate[0]
        e_candidate[0] = [i, j]

if o_candidate[0][0] != e_candidate[0][0]:
    ans = n - o_candidate[0][1] - e_candidate[0][1]
else:
    if o_candidate[0][1] > e_candidate[0][1]:
        ans = n - o_candidate[0][1] - e_candidate[1][1]
    else:
        ans = n - o_candidate[1][1] - e_candidate[0][1]

print(ans)

Submission status: Wrong Answer

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

O = {}
E = {}

for i in v[0::2]:
    if i in O:
        O[i] += 1
    else:
        O[i] = 1

for i in v[1::2]:
    if i in E:
        E[i] += 1
    else:
        E[i] = 1

o_candidate = [[0, 0], [0, 0]]
e_candidate = [[0, 0], [0, 0]]

for i, j in O.items():
    if j >= o_candidate[0][1]:
        o_candidate[1] = o_candidate[0]
        o_candidate[0] = [i, j]

for i, j in E.items():
    if j >= e_candidate[0][1]:
        e_candidate[1] = e_candidate[0]
        e_candidate[0] = [i, j]

if o_candidate[0][0] != e_candidate[0][0]:
    ans = n - o_candidate[0][1] - e_candidate[0][1]
else:
    if o_candidate[0][1] > o_candidate[1][1]:
        ans = n - o_candidate[0][1] - e_candidate[1][1]
    else:
        ans = n - o_candidate[1][1] - e_candidate[0][1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

even, odd = [sorted(Counter(V[i::2]).items(), key=lambda x: x[1]) + [[None, 0]] for i in range(2)]
if even[0][0] == odd[0][0]:
	print(min(N-even[0][1]-odd[1][1], N-even[1][1]-odd[0][1]))
else:
	print(N-even[0][1]-odd[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
L = list(input().split())
L0 = []
L1 = []
ans = 0

for i in range(0, n, 2):
    L0.append(L[i])
    L1.append(L[i + 1])
    
C0 = Counter(L0).most_common()
C1 = Counter(L1).most_common()

if C0[0][0] != C1[0][0]:
    ans = (n // 2 - C0[0][1]) + (n // 2 - C1[0][1])
else:
    if len(C0) == 1 and len(C1) == 1:
        ans = n // 2
    elif len(C0) == 1 and len(C1) != 1:
        ans = n // 2 - C1[1][1]
    elif len(C0) != 1 and len(C1) == 1:
        ans = n // 2 - C0[1][1]
    else:
        a = n // 2 - C0[0][1] - C1[1][1]
        b = n // 2 - C0[1][1] - C1[0][1]
        ans = min(a, b)

print(ans)

Submission status: Wrong Answer

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

def cnt(v):
    count_map = {}
    for i in v:
        count_map[i] = count_map.get(i, 0) + 1
    if len(count_map) == 1:
        count_map[-1] = 0
    return sorted(count_map.items(), key=lambda x: x[1], reverse=True)

maxv = list(map(cnt, [a[::2], a[1::2]]))

def check(v1, v2):
    return (n + 1) // 2 - v1 + n // 2 - v2

if maxv[0][0][0] == maxv[1][0][0]:
    result = max(
        check(maxv[0][1][1], maxv[1][0][1]),
        check(maxv[0][0][1], maxv[1][1][1]),
    )
else:
    result = check(maxv[0][0][1], maxv[1][0][1])
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
n = int(input())
vs = input().split()
 
xs = [v for v in vs[::2]]
x = Counter(xs).most_common()
 
ys = [v for v in vs[1::2]]
y = Counter(ys).most_common()
 
if x[0][0] != y[0][0]:
    rw1 = n - x[0][1] - y[0][1]
    print(rw1)
else:
    if len(x) == 1 and len(y) != 1:
        rw2 = n//2 - y[1][1]
        print(rw2)
    elif len(x) != 1 and len(y) == 1:
        rw3 = n//2 - x[1][1]
        print(rw3)
    elif len(x) ==1 and len(y) == 1:
        rw4 = n//2
        print(rw4)
    else:
        rw5 = (n//2 - x[0][1]) + (n//2 - y[1][1])
        print(rw5)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=[i for i in input().strip().split()]
a,b=[],[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])
aa=False
bb=False

if a.count(a[0])==len(a):
    aa=True
    saihina=Counter(b).most_common()
else:
    saihina=Counter(a).most_common()
    acn=len(a)-saihina[0][1]

if b.count(b[0])==len(b):
    bb=True
    saihinb=Counter(b).most_common()
else:
    saihinb=Counter(b).most_common()
    bcn=len(b)-saihinb[0][1]

if aa and bb:
    if a[0]==b[0]:
        print(len(b))
        exit()
    else:
        print(0)
        exit()
if aa:
    if not bb:
        if saihina[0][0]==saihinb[0][0]:
            bcn=len(b)-saihinb[1][1]
        print(bcn)
        exit()
if bb:
    if not aa:
        if saihina[0][0]==saihinb[0][0]:
            acn=len(a)-saihina[1][1]
        print(acn)
        exit()

if saihina[0][0]==saihinb[0][0]:
    if saihina[1][1]>saihinb[1][1]:
        bcn=len(b)-saihinb[1][1]
    else:
        acn=len(a)-saihina[1][1]

print(bcn+acn)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=[i for i in input().strip().split()]
a,b=[],[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])
aa=False
bb=False

if a.count(a[0])==len(a):
    aa=True
else:
    saihina=Counter(a).most_common()
    acn=len(a)-saihina[0][1]

if b.count(b[0])==len(b):
    bb=True
else:
    saihinb=Counter(b).most_common()
    bcn=len(b)-saihinb[0][1]

if aa and bb:
    if a[0]==b[0]:
        print(len(a))
        exit()
    else:
        print(0)
        exit()
if aa:
    if not bb:
        if a[0]==saihinb[0][0]:
            bcn=len(b)-saihinb[1][1]
        print(bcn)
        exit()
if bb:
    if not aa:
        if saihina[0][0]==b[0]:
            acn=len(a)-saihina[1][1]
        print(acn)
        exit()

if saihina[0][0]==saihinb[0][0]:
    if saihina[1][1]>saihinb[1][1]:
        bcn=len(b)-saihinb[1][1]
    else:
        acn=len(a)-saihina[1][1]

if not aa:
    if not bb:
        print(bcn+acn)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=[i for i in input().strip().split()]
a,b=[],[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])
aa=False
bb=False

if a.count(a[0])==len(a):
    aa=True
else:
    saihina=Counter(a).most_common()
    acn=len(a)-saihina[0][1]

if b.count(b[0])==len(b):
    bb=True
else:
    saihinb=Counter(b).most_common()
    bcn=len(b)-saihinb[0][1]

if aa and bb:
    if a[0]==b[0]:
        print(len(a))
        exit()
    else:
        print(0)
        exit()
if aa:
    if not bb:
        print(bcn)
        exit()
if bb:
    if not aa:
        print(acn)
        exit()

if saihina[0][0]==saihinb[0][0]:
    if saihina[1][1]>saihinb[1][1]:
        bcn=len(b)-saihinb[1][1]
    else:
        acn=len(a)-saihina[1][1]

if not aa:
    if not bb:
        print(bcn+acn)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
v=[i for i in input().strip().split()]
a,b=[],[]
for i in range(n):
    if i%2==0:
        a.append(v[i])
    else:
        b.append(v[i])
aa=False
bb=False
if a.count(a[0])==len(a):
    aa=True
else:
    saihina=Counter(a).most_common(1)[0][1]
    acn=len(a)-saihina

if b.count(b[0])==len(b):
    bb=True
else:
    saihinb=Counter(b).most_common(1)[0][1]
    bcn=len(b)-saihinb

if aa and bb:
    if a[0]==b[0]:
        print(len(a))
        exit()
    else:
        print(0)
        exit()
if aa:
    if not bb:
        print(bcn)
        exit()
if bb:
    if not aa:
        exit()
if not aa:
    if not bb:
        print(bcn+acn)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []

for i in range(len(v)):
    if i % 2:
        even.append(v[i])
    else:
        odd.append(v[i])

odd = collections.Counter(odd)
even = collections.Counter(even)
max_odd = 0
max_odd2 = 0
max_even = 0
max_even2 = 0
for i in odd:
    if max_odd < odd[i]:
        max_odd2 = max_odd
        max_odd = odd[i]
        x = i
    elif max_odd2 < odd[i]:
        max_odd2 = odd[i]
    

for j in even:
    if max_even < even[j]:
        max_even2 = max_even
        max_even = even[j]
        y = j
    elif max_even2 < even[j]:
        max_even2 = even[j]

if x != y:
    print(n - max_odd - max_even)
else:
    if odd[x] > even[y]:
        print(n - max_odd - max_even2)
    else:
        print(n - max_odd2 - max_even)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []

for i in range(len(v)):
    if i % 2:
        even.append(v[i])
    else:
        odd.append(v[i])

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

max_odd = 0
max_odd2 = 0
max_even = 0
max_even2 = 0
for i, j in zip(odd, even):
    if max_odd < odd[i]:
        max_odd = odd[i]
        x = i
    elif max_odd2 < odd[i]:
        max_odd2 = odd[i]
    if max_even < even[j]:
        max_even = even[j]
        y = j
    elif max_even2 < even[j]:
        max_even2 = even[j]

if x != y:
    print(n - max_odd - max_even)
else:
    if odd[x] > even[y]:
        print(n - max_odd - max_even2)
    else:
        print(n - max_odd2 - max_even)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []

for i in range(len(v)):
    if i % 2:
        even.append(v[i])
    else:
        odd.append(v[i])

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

max_odd = 0
max_odd2 = 0
max_even = 0
max_even2 = 0
for i, j in zip(odd, even):
    if max_odd < odd[i]:
        max_odd = odd[i]
        x = i
    elif max_odd2 < odd[i]:
        max_odd2 = odd[i]
    if max_even < even[j]:
        max_even = even[j]
        y = j
    elif max_even2 < even[j]:
        max_even2 = even[j]

if x != j:
    print(n - max_odd - max_even)
else:
    print(min(n - max_odd2 - max_even, n - max_odd - max_even2))

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []

for i in range(len(v)):
    if i % 2:
        even.append(v[i])
    else:
        odd.append(v[i])

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

max_odd = 0
max_odd2 = 0
max_even = 0
max_even2 = 0
for i, j in zip(odd, even):
    if max_odd < odd[i]:
        max_odd = odd[i]
        x = i
    elif max_odd2 < odd[i]:
        max_odd2 = odd[i]
    if max_even < even[j]:
        max_even = even[j]
        y = j
    elif max_even2 < even[j]:
        max_even2 = even[j]

if x != j:
    print(n - max_odd - max_even)
else:
    if odd[x] > even[y]:
        print(n - max_odd - max_even2)
    else:
        print(n - max_odd2 - max_even)

Submission status: Wrong Answer

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

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

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

if len(ev) == 1 and len(ov) == 1:
    print (n//2)    
    exit(0)

#li = []
#for elm in list(ev.keys()) :
#    li.append([0,[elm,ev[elm]]])
#for elm in list(ov.keys()) :
    #li.append([1,[elm,ov[elm]]])
#li.sort(key=lambda x : x[1][1],reverse=True)
#print(li)

ee  = list(ev.keys())[0]
oo  = list(ov.keys())[0]

es0 = list(ev.values())[0]
os0 = list(ov.values())[0]
ans = n - es0 - os0

if ee == oo:
    es1 = list(ev.values())[1]
    tmp1 = n  - es1  - os0

    os1 = list(ov.values())[1]
    tmp2 = n  - es0  - os1

    if tmp1 > tmp2 :
        ans = tmp2 
    else :
        ans = tmp1

print(ans)

Submission status: Wrong Answer

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

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

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

#li = []
#for elm in list(ev.keys()) :
#    li.append([0,[elm,ev[elm]]])
#for elm in list(ov.keys()) :
    #li.append([1,[elm,ov[elm]]])
#li.sort(key=lambda x : x[1][1],reverse=True)
#print(li)

ee  = list(ev.keys())[0]
oo  = list(ov.keys())[0]

es0 = list(ev.values())[0]
os0 = list(ov.values())[0]
ans = n - es0 - os0

if ee == oo:
    tmp1 = n - es0
    tmp2 = n - os0

    if len(ev) > 1:
        es1 = list(ev.values())[1]
        tmp1 = n  - es1  - os0

    if len(ov) > 1:
        os1 = list(ov.values())[1]
        tmp2 = n  - es0  - os1

    if tmp1 > tmp2 :
        ans = tmp2 
    else :
        ans = tmp1

print(ans)

Submission status: Wrong Answer

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

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

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

#li = []
#for elm in list(ev.keys()) :
#    li.append([0,[elm,ev[elm]]])
#for elm in list(ov.keys()) :
#    li.append([1,[elm,ov[elm]]])
#li.sort(key=lambda x : x[1][1],reverse=True)
#print(li)

ee  = list(ev.keys())[0]
oo  = list(ov.keys())[0]

es0 = list(ev.values())[0]
os0 = list(ov.values())[0]
ans = n - es0 - os0

if ee == oo:
    tmp1 = n - es0
    tmp2 = n - os0

    if len(ev) > 1:
        es1 = list(ev.values())[1]
        tmp1 = n  - es1  - os0

    if len(ov) > 1:
        os1 = list(ov.values())[1]
        tmp2 = n  - es0  - os1
    
    if tmp1 > tmp2 :
        ans = tmp2 
    else :
        ans = tmp1

print(ans)

Submission status: Wrong Answer

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

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

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

#li = []
#for elm in list(ev.keys()) :
#    li.append([0,[elm,ev[elm]]])
#for elm in list(ov.keys()) :
#    li.append([1,[elm,ov[elm]]])
#li.sort(key=lambda x : x[1][1],reverse=True)
#print(li)

es0 = list(ev.values())[0]
os0 = list(ov.values())[0]
ans = n - es0 - os0

if es0 == os0:
    tmp1 = n - es0
    tmp2 = n - os0

    if len(ev) > 1:
        es1 = list(ev.values())[1]
        tmp1 = n  - es1  - os0

    if len(ov) > 1:
        os1 = list(ov.values())[1]
        tmp2 = n  - es0  - os1
    
    if tmp1 > tmp2 :
        ans = tmp2 
    else :
        ans = tmp1

print(ans)

Submission status: Wrong Answer

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

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

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

eidx = 0
oidx = 0
et = list(ev.values())[eidx]
ot = list(ov.values())[oidx]

if et == ot :
    if len(ev) > len(ov) :
        if len(ov) > 1:
            ot = list(ov.values())[oidx+1]
        else:
            ot = 0
    else:
        if len(ev) > 1:
            et = list(ev.values())[eidx+1]
        else:
            et = 0

ans = len(e) - et + len(o) - ot
print(ans)

Submission status: Wrong Answer

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

#数列の添字（1始まり）に対応
v_odd = []
v_even = []


for i in range(n):
    if i % 2:
        v_even.append(v[i])
    else:
        v_odd.append(v[i])

if v_odd == v_even:
    print(n//2)
    exit()

v_odd_counter = collections.Counter(v_odd)
results_odd = (n//2) - max(v_odd_counter.values())
v_even_counter = collections.Counter(v_even)
results_even = (n//2) - max(v_even_counter.values())

print(results_odd + results_even)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


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

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

counter = defaultdict(int)
for i in range(N):
    if i % 2 == 0:
        counter[V[i]] += 1

pairs_1 = sorted([(k, v) for k, v in counter.items()], key=lambda p: p[1], reverse=True)

counter = defaultdict(int)
for i in range(N):
    if i % 2 != 0:
        counter[V[i]] += 1

pairs_2 = sorted([(k, v) for k, v in counter.items()], key=lambda p: p[1], reverse=True)

if pairs_1[0][0] != pairs_2[0][0]:
    ans = (N // 2 - pairs_1[0][1]) + (N // 2 - pairs_2[0][1])
else:
    ans = max((N // 2 - pairs_1[0][1]) + (N // 2 - pairs_2[1][1]), (N // 2 - pairs_1[1][1]) + (N // 2 - pairs_2[0][1]))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


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

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

counter = defaultdict(int)
for i in range(N):
    if i % 2 == 0:
        counter[V[i]] += 1

ans = N // 2 - sorted(counter.values())[-1]

counter = defaultdict(int)
for i in range(N):
    if i % 2 != 0:
        counter[V[i]] += 1

ans += N // 2 - sorted(counter.values())[-1]

print(ans)

Submission status: Wrong Answer

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()

ans = N//2
if m1[0][0] != m2[0][0]:
    ans = N - m1[0][1] - m2[0][1]
if len(m1) > 1 and m1[1][0] != m2[0][0]:
    ans = min(ans, N - m1[1][1] - m2[0][1])
if len(m2) > 1 and m1[0][0] != m2[1][0]:
    ans = min(ans, N - m1[0][1] - m2[1][1])
if len(m1) > 1 and len(m2) > 1 and m1[1][0] != m2[1][0]:
    ans = min(ans, N - m1[1][1] - m2[1][1])
print(ans)

Submission status: Wrong Answer

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

c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()

ans = N//2
if m1[0][0] != m2[0][0]:
    ans = N - m1[0][1] - m2[0][1]
if len(m1) > 1 and m1[1][0] != m2[0][0]:
    ans = min(ans, N - m1[1][1] - m2[0][1])
if len(m2) > 1 and m1[0][0] != m2[1][0]:
    ans = min(ans, N - m1[0][1] - m2[1][1])
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

n = int(raw_input())
vs = [int(x) for x in raw_input().split()]

from collections import defaultdict
v1 = defaultdict(int)
v2 = defaultdict(int)
for i in xrange(0, n, 2):
	v1[vs[i]] += 1
	v2[vs[i+1]] += 1
v1 = [(k, v) for k, v in v1.iteritems()]
v2 = [(k, v) for k, v in v2.iteritems()]
v1 = sorted(v1, key=lambda x: x[1], reverse=True)
v2 = sorted(v2, key=lambda x: x[1], reverse=True)
count = 0
x = v1[0][0]
count += (sum([v for _, v in v1]) - v1[0][1])
if len(v2) == 1 and v2[0][0] == x:
	count += v2[0][1]
else:
	if v2[0][0] == x:
		count += (sum([v for _, v in v2]) - v2[1][1])
	else:
		count += (sum([v for _, v in v2]) - v2[0][1])
print count

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

n = int(raw_input())
vs = [int(x) for x in raw_input().split()]

from collections import defaultdict
v1 = defaultdict(int)
v2 = defaultdict(int)
for i in xrange(0, n, 2):
	v1[vs[i]] += 1
	v2[vs[i+1]] += 1
v1 = [(k, v) for k, v in v1.iteritems()]
v2 = [(k, v) for k, v in v2.iteritems()]
v1 = sorted(v1, reverse=True)
v2 = sorted(v2, reverse=True)
count = 0
x = v1[0][0]
count += (sum([v for _, v in v1]) - v1[0][1])
if len(v2) == 1 and v2[0][0] == x:
	count += v2[0][1]
else:
	if v2[0][0] == x:
		count += (sum([v for _, v in v2]) - v2[1][1])
	else:
		count += (sum([v for _, v in v2]) - v2[0][1])
print count

Submission status: Wrong Answer

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 in sorted(even.values(), reverse=True)[:2]:
        for o in sorted(odd.values(), reverse=True)[:2]:
            m = max(m, e + o)

    print(N - m)

Submission status: Wrong Answer

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

x1 = x[::2]
x2 = x[1::2]


t1 = 0
k1 = x1[1]
for x in set(x1):
   temp  = x1.count(x)
   if temp > t1:
       t1 = temp
       k1 = x

t2 = 0
k2 = x2[1]
for x in set(x2):
   temp  = x2.count(x)
   if temp > t2:
       t2 = temp
       k2 = x


if k1 == k2:
    print(len(x1) - max(t1, t2) + len(x2))
else:
    print(len(x1) - t1 + len(x2)-t2)

Submission status: Wrong Answer

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

x1 = x[::2]
x2 = x[1::2]


t1 = 0
k1 = x1[1]
for x in set(x1):
   temp  = x1.count(x)
   if temp > t1:
       t1 = temp
       k1 = x

t2 = 0
k2 = x2[1]
for x in set(x2):
   temp  = x2.count(x)
   if temp > t2:
       t2 = temp
       k2 = x


if k1 == k2:
    print(len(x1) - max(t1, t2) + len(x2))
else:
    print(len(x1) - t1 + len(x2)-t2)

Submission status: Wrong Answer

Solution code:
str1= int(raw_input())
str2 = map(int , raw_input().split(" "))
from collections import Counter
import operator
def test(str1, str2):
    if len(set(str2)) == 1:
        print str1/2
        return
    res = Counter(str2)
    sorted_x = sorted(res.iteritems(), key=operator.itemgetter(1))
    sum = 0
    for i in str2:
        if i not in [sorted_x[-1][0], sorted_x[-2][0]]:
            sum +=1
    print sum
test(str1, str2)

Submission status: Wrong Answer

Solution code:

n=int(input())
v=map(int,input().split())
vodd={'a':0}
veven={'a':0}
for i,vi in enumerate(v):
    if i%2:
        if(vi in veven):
            veven[vi]+=1
        else:
            veven[vi]=1
    else:
        if(vi in vodd):
            vodd[vi]+=1
        else:
            vodd[vi]=1
veven=list(veven.items())
veven.sort(key=lambda x:x[1])
veven.reverse()
vodd=list(vodd.items())
vodd.sort(key=lambda x:x[1])
vodd.reverse()
if veven[0][0]==vodd[0][0]:
    a=veven[0][1]+vodd[1][1]
    b=veven[1][1]+vodd[0][1]
    changeCnt=a if a<b else b
else:
    changeCnt=veven[1][1]+vodd[1][1]

print(changeCnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=map(int,input().split())
vodd={0:0}
veven={0:0}
for i,vi in enumerate(v):
    if i%2:
        if(vi in veven):
            veven[vi]+=1
        else:
            veven[vi]=1
    else:
        if(vi in vodd):
            vodd[vi]+=1
        else:
            vodd[vi]=1
veven=list(veven.items())
veven.sort(key=lambda x:x[1])
veven.reverse()
vodd=list(vodd.items())
vodd.sort(key=lambda x:x[1])
vodd.reverse()
if veven[0][0]==vodd[0][0]:
    a=veven[0][1]+vodd[1][1]
    b=veven[1][1]+vodd[0][1]
    changeCnt=a if a<b else b
else:
    changeCnt=veven[1][1]+vodd[1][1]

print(changeCnt)

Submission status: Wrong Answer

Solution code:
from collections import *

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]

v1_count_list = Counter(v1_list).most_common()
v2_count_list = Counter(v2_list).most_common()

if v1_count_list[0][0] != v2_count_list[0][0]:
    print(len(v_list) - v1_count_list[0][1] - v2_count_list[0][1])
else:
    countor1 = len(v_list) - v1_count_list[1][1] - v2_count_list[0][1]
    countor2 = len(v_list) - v1_count_list[0][1] - v2_count_list[0][1]
    print(min(countor1, countor2))

Submission status: Wrong Answer

Solution code:
from collections import *

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]

v1_count_list = Counter(v1_list).most_common()
v2_count_list = Counter(v2_list).most_common()

if v1_count_list[0][0] != v2_count_list[0][0]:
    print(len(v_list) - v1_count_list[0][1] - v2_count_list[0][1])
elif v1_count_list[0][1] > v2_count_list[0][1]:
    print(len(v_list) - v1_count_list[1][1] - v2_count_list[0][1])
else:
    print(len(v_list) - v1_count_list[0][1] - v2_count_list[1][1])

Submission status: Wrong Answer

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, 0

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

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

v1_list = []
v2_list = []

for i in range(len(v_list)):
    if i%2 == 0:
        v1_list.append(i)
    else:
        v2_list.append(i)
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: Wrong Answer

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], vi_count_list
    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)]
leave_v1, rewrite_v1, v1_count_list = rewrite_count(v1_list)
leave_v2, rewrite_v2, v2_count_list = rewrite_count(v2_list)

if rewrite_v1 < rewrite_v2:
    print(rewrite_v1 + rewrite_v2 if(v2_count_list[-1][0] != leave_v1) else rewrite_v1 + v2_count_list[-2][1])
else:
    print(rewrite_v2 + rewrite_v1 if(v1_count_list[-1][0] != leave_v2) else rewrite_v2 + v2_count_list[-2][1])

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

nn = n // 2
for i in range(nn):
    a[v[i * 2]] += 1
    b[v[i * 2 + 1]] += 1

ma1 = list(sorted(a, key=a.get, reverse=True))
mb1 = list(sorted(b, key=b.get,reverse=True))

if (ma1[0] == mb1[0]):
    if (len(ma1) == 1):
        mb1.pop(0)
    elif (len(mb1) == 1):
        ma1.pop(0)
    else:
        if (a[ma1[0]] < b[mb1[0]]):
            mb1.pop(1)
        elif (a[ma1[0]] < b[mb1[0]]):
            ma1.pop(1)
        else:
            if (a[ma1[1]] < b[mb1[1]]):
                mb1.pop(1)
            elif (a[ma1[1]] < b[mb1[1]]):
                ma1.pop(1)
            else:
                ma1.pop(1)
else:
    ma1.pop(0)
    mb1.pop(0)

count = 0
while(ma1 or mb1):
    if (ma1):
        count += a[ma1[0]]
        ma1.pop(0)
    if (mb1):
        count += b[mb1[0]]
        mb1.pop(0)
print(count)