Problem p03244 (python)

Fixed submission:
import collections

N = int(raw_input().replace("\n", ""))

a_list = map(int, raw_input().replace("\n", "").split(" "))
even_list = a_list[::2]
odd_list = a_list[1::2]

len_vec = N / 2

even_c = collections.Counter(even_list)
odd_c = collections.Counter(odd_list)

even_c_most_common = even_c.most_common()
odd_c_most_common = odd_c.most_common()

even_first_value, even_first_count = even_c_most_common[0]
odd_first_value, odd_first_count  = odd_c_most_common[0]
#(even_first_value, even_first_count), (even_second_value, even_second_count) = even_c.most_common()[:2]
#(odd_first_value, odd_first_count), (odd_second_value, odd_second_count) = odd_c.most_common()[:2]

if even_first_value == odd_first_value and len(even_c) == 1 and len(odd_c) == 1:
    cost = len_vec
elif even_first_value != odd_first_value:
    cost =  (even_first_count + odd_first_count)
elif len(even_c) == 1 and len(odd_c) > 1:
    odd_second_value, odd_second_count = odd_c_most_common[1]
    cost = len_vec + odd_second_count
elif len(odd_c) == 1 and len(even_c) > 1:
    even_second_value, even_second_count = even_c_most_common[1]
    #cost = len_vec + odd_second_count
    cost = len_vec + even_second_count
else: # ryouhou no first ga onaji de hutatuijou arutoki
    odd_second_value, odd_second_count = odd_c_most_common[1]
    even_second_value, even_second_count = even_c_most_common[1]
    cost = max(even_first_count+odd_second_count, even_second_count+odd_first_count)

print(2* len_vec - cost)

Buggy submission (verdict: Runtime Error):
import collections

N = int(raw_input().replace("\n", ""))

a_list = map(int, raw_input().replace("\n", "").split(" "))
even_list = a_list[::2]
odd_list = a_list[1::2]

len_vec = N / 2

even_c = collections.Counter(even_list)
odd_c = collections.Counter(odd_list)



even_first_value, even_first_count = even_c.most_common()[0]
odd_first_value, odd_first_count  = odd_c.most_common()[0]
#(even_first_value, even_first_count), (even_second_value, even_second_count) = even_c.most_common()[:2]
#(odd_first_value, odd_first_count), (odd_second_value, odd_second_count) = odd_c.most_common()[:2]

if even_first_value == odd_first_value and len(even_c) == 1 and len(odd_c) == 1:
    cost = len_vec
elif even_first_value != odd_first_value:
    cost =  (even_first_count + odd_first_count)
elif len(even_c) == 1 and len(odd_c) > 1:
    odd_second_value, odd_second_count = odd_c.most_common(1)
    cost = len_vec + odd_second_count
elif len(odd_c) == 1 and len(even_c) > 1:
    even_second_value, even_second_count = even_c.most_common(1)
    #cost = len_vec + odd_second_count
    cost = len_vec + even_second_count
else: # ryouhou no first ga onaji de hutatuijou arutoki
    odd_second_value, odd_second_count = odd_c.most_common(1)
    even_second_value, even_second_count = even_c.most_common(1)
    cost = max(even_first_count+odd_second_count, even_second_count+odd_first_count)

print 2* len_vec - cost

Buggy submission (verdict: Runtime Error):
import collections

N = int(raw_input().replace("\n", ""))

a_list = map(int, raw_input().replace("\n", "").split(" "))
even_list = a_list[::2]
odd_list = a_list[1::2]

len_vec = N / 2

even_c = collections.Counter(even_list)
odd_c = collections.Counter(odd_list)

even_first_value, even_first_count = even_c.most_common()[0]
odd_first_value, odd_first_count  = odd_c.most_common()[0]
#(even_first_value, even_first_count), (even_second_value, even_second_count) = even_c.most_common()[:2]
#(odd_first_value, odd_first_count), (odd_second_value, odd_second_count) = odd_c.most_common()[:2]

if even_first_value == odd_first_value and len(even_c) == 1 and len(odd_c) == 1:
    cost = len_vec
elif even_first_value != odd_first_value:
    cost =  (even_first_count + odd_first_count)
elif len(even_c) == 1 and len(odd_c) > 1:
    odd_second_value, odd_second_count = odd_c.most_common(1)
    cost = len_vec + odd_second_count
elif len(odd_c) == 1 and len(even_c) > 1:
    even_second_value, even_second_count = even_c.most_common(1)
    cost = len_vec + odd_second_count
else: # ryouhou no first ga onaji de hutatuijou arutoki
    odd_second_value, odd_second_count = odd_c.most_common(1)
    even_second_value, even_second_count = even_c.most_common(1)
    cost = max(even_first_count+odd_second_count, even_second_count+odd_first_count)

print 2* len_vec - cost