Buggy python submission (verdict: Time Limit Exceeded):

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]


Fixed submission:

from collections import Counter

n    = int(raw_input())
nums = list(map(int, raw_input().split()))

nums_odd  =   nums[0:n:2]
nums_even =   nums[1:n:2]

N_odd     =   sorted(Counter(nums_odd ).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]
N_even    =   sorted(Counter(nums_even).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]

if N_odd[0][0] == N_even[0][0]:
    if N_odd[0][1] + N_even[1][1] > N_odd[1][1] + N_even[0][1]:
        print n - N_odd[0][1] - N_even[1][1]
    else:
        print n - N_odd[1][1] - N_even[0][1]
else:
    print n - N_odd[0][1] - N_even[0][1]

Buggy python submission (verdict: Time Limit Exceeded):
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]


Fixed submission:

from collections import Counter

n    = int(raw_input())
nums = list(map(int, raw_input().split()))

nums_odd  =   nums[0:n:2]
nums_even =   nums[1:n:2]

N_odd     =   sorted(Counter(nums_odd ).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]
N_even    =   sorted(Counter(nums_even).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]

if N_odd[0][0] == N_even[0][0]:
    if N_odd[0][1] + N_even[1][1] > N_odd[1][1] + N_even[0][1]:
        print n - N_odd[0][1] - N_even[1][1]
    else:
        print n - N_odd[1][1] - N_even[0][1]
else:
    print n - N_odd[0][1] - N_even[0][1]

Buggy python submission (verdict: Runtime Error):

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[

Fixed submission:

from collections import Counter

n    = int(raw_input())
nums = list(map(int, raw_input().split()))

nums_odd  =   nums[0:n:2]
nums_even =   nums[1:n:2]

N_odd     =   sorted(Counter(nums_odd ).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]
N_even    =   sorted(Counter(nums_even).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]

if N_odd[0][0] == N_even[0][0]:
    if N_odd[0][1] + N_even[1][1] > N_odd[1][1] + N_even[0][1]:
        print n - N_odd[0][1] - N_even[1][1]
    else:
        print n - N_odd[1][1] - N_even[0][1]
else:
    print n - N_odd[0][1] - N_even[0][1]

Buggy python submission (verdict: Runtime Error):

A = [int(i) for i in raw_input().split()]
N = len(A)
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]


Fixed submission:

from collections import Counter

n    = int(raw_input())
nums = list(map(int, raw_input().split()))

nums_odd  =   nums[0:n:2]
nums_even =   nums[1:n:2]

N_odd     =   sorted(Counter(nums_odd ).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]
N_even    =   sorted(Counter(nums_even).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]

if N_odd[0][0] == N_even[0][0]:
    if N_odd[0][1] + N_even[1][1] > N_odd[1][1] + N_even[0][1]:
        print n - N_odd[0][1] - N_even[1][1]
    else:
        print n - N_odd[1][1] - N_even[0][1]
else:
    print n - N_odd[0][1] - N_even[0][1]

Buggy python submission (verdict: Runtime Error):

A = [int(i) for i in raw_input().split()]
N = len(A)
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]


Fixed submission:

from collections import Counter

n    = int(raw_input())
nums = list(map(int, raw_input().split()))

nums_odd  =   nums[0:n:2]
nums_even =   nums[1:n:2]

N_odd     =   sorted(Counter(nums_odd ).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]
N_even    =   sorted(Counter(nums_even).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]

if N_odd[0][0] == N_even[0][0]:
    if N_odd[0][1] + N_even[1][1] > N_odd[1][1] + N_even[0][1]:
        print n - N_odd[0][1] - N_even[1][1]
    else:
        print n - N_odd[1][1] - N_even[0][1]
else:
    print n - N_odd[0][1] - N_even[0][1]

Buggy python submission (verdict: Runtime Error):
A = [int(i) for i in raw_input().split()]
N = len(A)
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 = []

if len(S0) == 1:
    N0[0] = append((S0[0], len(A0)))
else:
    for s in S0:
        N0.append((s, sum(map(lambda x: x==s, A0))))


if len(S1) == 1:
    N1.append = (S1[0], len(A1))
else:
    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(N1) == 1:
            print N - N0[0][1]
        else:
            print N - N0[0][1] - N1[1][1]
    else:
        if len(N0) == 0:
            print N - N1[0][1]
        else:
            print N - N0[1][1] - N1[0][1]
else:
    print N - N0[0][1] - N1[0][1]


Fixed submission:

from collections import Counter

n    = int(raw_input())
nums = list(map(int, raw_input().split()))

nums_odd  =   nums[0:n:2]
nums_even =   nums[1:n:2]

N_odd     =   sorted(Counter(nums_odd ).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]
N_even    =   sorted(Counter(nums_even).items(), key=lambda x: x[1], reverse=True) + [(-1,0)]

if N_odd[0][0] == N_even[0][0]:
    if N_odd[0][1] + N_even[1][1] > N_odd[1][1] + N_even[0][1]:
        print n - N_odd[0][1] - N_even[1][1]
    else:
        print n - N_odd[1][1] - N_even[0][1]
else:
    print n - N_odd[0][1] - N_even[0][1]