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:
#encoding utf-8
def main(n,v):
    # n = int(input())
    # v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

    for i in range(n):
        if i%2 == 0:
            odd_v.append(v[i])
        else:
            even_v.append(v[i])

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    for i in range(len(odd_keys)-1):
        if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
            if odd_keys[i] > odd_keys[i+1]:
                tem = odd_keys[i]
                odd_keys[i] = odd_keys[i+1]
                odd_keys[i+1] = tem

    for i in range(len(even_keys)-1):
        if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
            if even_keys[i] > even_keys[i+1]:
                tem = even_keys[i]
                even_keys[i] = even_keys[i+1]
                even_keys[i+1] = tem


  
    # print(even_keys,odd_keys)
    if (len(odd_keys) == 1 and len(even_keys) == 1) and odd_keys[0] == even_keys[0]:
        answer = n/2
    elif odd_keys[0] == even_keys[0]:
        ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        answer = min(ans1, ans2)
    else:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])







    # if odd_keys[0] != even_keys[0]:
    #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
    # else:
    #     if len(odd_keys) == 1 and len(even_keys) == 1:
    #         answer = len(odd_v)
    #     elif len(odd_keys) == 1:
    #         answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #     elif len(even_keys) == 1:
    #         answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #     else:
    #         # if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
    #         #     answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #         # else:
    #         #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #         ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #         ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #         answer = min(ans1, ans2)
    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main(n,v):
    # n = int(input())
    # v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

    for i in range(n):
        if i%2 == 0:
            odd_v.append(v[i])
        else:
            even_v.append(v[i])

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    for i in range(len(odd_keys)-1):
        if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
            if odd_keys[i] > odd_keys[i+1]:
                tem = odd_keys[i]
                odd_keys[i] = odd_keys[i+1]
                odd_keys[i+1] = tem

    for i in range(len(even_keys)-1):
        if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
            if even_keys[i] > even_keys[i+1]:
                tem = even_keys[i]
                even_keys[i] = even_keys[i+1]
                even_keys[i+1] = tem


    print(even_dic,odd_dic)
    # print(even_keys,odd_keys)
    if (len(odd_keys) == 1 and len(even_keys) == 1) and odd_keys[0] == even_keys[0]:
        answer = n/2
    elif odd_keys[0] == even_keys[0]:
        ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        answer = min(ans1, ans2)
    else:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])







    # if odd_keys[0] != even_keys[0]:
    #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
    # else:
    #     if len(odd_keys) == 1 and len(even_keys) == 1:
    #         answer = len(odd_v)
    #     elif len(odd_keys) == 1:
    #         answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #     elif len(even_keys) == 1:
    #         answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #     else:
    #         # if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
    #         #     answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #         # else:
    #         #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #         ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #         ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #         answer = min(ans1, ans2)
    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main(n,v):
    # n = int(input())
    # v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

    for i in range(n):
        if i%2 == 0:
            odd_v.append(v[i])
        else:
            even_v.append(v[i])

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1], reverse=True):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1],reverse=True):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    # for i in range(len(odd_keys)-1):
    #     if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
    #         if odd_keys[i] > odd_keys[i+1]:
    #             tem = odd_keys[i]
    #             odd_keys[i] = odd_keys[i+1]
    #             odd_keys[i+1] = tem
    #
    # for i in range(len(even_keys)-1):
    #     if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
    #         if even_keys[i] > even_keys[i+1]:
    #             tem = even_keys[i]
    #             even_keys[i] = even_keys[i+1]
    #             even_keys[i+1] = tem


    # print(even_dic,odd_dic)
    # print(even_keys,odd_keys)
    if (len(odd_keys) == 1 and len(even_keys) == 1) and odd_keys[0] == even_keys[0]:
        answer = n/2
    elif odd_keys[0] == even_keys[0]:
        ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        answer = min(ans1, ans2)
    else:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])







    # if odd_keys[0] != even_keys[0]:
    #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
    # else:
    #     if len(odd_keys) == 1 and len(even_keys) == 1:
    #         answer = len(odd_v)
    #     elif len(odd_keys) == 1:
    #         answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #     elif len(even_keys) == 1:
    #         answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #     else:
    #         # if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
    #         #     answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #         # else:
    #         #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #         ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #         ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #         answer = min(ans1, ans2)
    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main(n,v):
    # n = int(input())
    # v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

    for i in range(n):
        if i%2 == 0:
            odd_v.append(v[i])
        else:
            even_v.append(v[i])

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    # for i in range(len(odd_keys)-1):
    #     if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
    #         if odd_keys[i] > odd_keys[i+1]:
    #             tem = odd_keys[i]
    #             odd_keys[i] = odd_keys[i+1]
    #             odd_keys[i+1] = tem
    #
    # for i in range(len(even_keys)-1):
    #     if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
    #         if even_keys[i] > even_keys[i+1]:
    #             tem = even_keys[i]
    #             even_keys[i] = even_keys[i+1]
    #             even_keys[i+1] = tem


    # print(even_dic,odd_dic)
    # print(even_keys,odd_keys)
    if (len(odd_keys) == 1 and len(even_keys) == 1) and odd_keys[0] == even_keys[0]:
        answer = n/2
    elif odd_keys[0] == even_keys[0]:
        ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        answer = min(ans1, ans2)
    else:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])







    # if odd_keys[0] != even_keys[0]:
    #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
    # else:
    #     if len(odd_keys) == 1 and len(even_keys) == 1:
    #         answer = len(odd_v)
    #     elif len(odd_keys) == 1:
    #         answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #     elif len(even_keys) == 1:
    #         answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #     else:
    #         # if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
    #         #     answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #         # else:
    #         #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #         ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
    #         ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
    #         answer = min(ans1, ans2)
    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Submission status: Wrong Answer

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

s = [[],[]]
for i in range(n):
    s[i % 2].append(v[i])

t = []
t.append(list(set(s[0])))
t.append(list(set(s[1])))

#print(s, t)

t_dict = [{}, {}]

for j in range(2):
    for i in range(len(t[j])):
        t_dict[j][t[j][i]] = 0

for j in range(2):
    for i in range(len(s[j])):
        t_dict[j][s[j][i]] += 1

for j in range(2):
    t_dict[j] = list(reversed(sorted(t_dict[j].items(), key=lambda x:x[1])))

#print(t_dict)
if t_dict[0][0] != t_dict[1][0]:
    print( len(s[0]) - t_dict[0][0][1] + len(s[1]) - t_dict[1][0][1])
elif len(t[0]) == 1 and len(t[1]) == 1:
    print(n // 2)
elif len(t[0]) == 1:
    print(len(s[0]) - t_dict[0][0][1] + len(s[1]) - t_dict[1][1][1])
else:
    print(len(s[0]) - t_dict[0][1][1] + len(s[1]) - t_dict[1][0][1])

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main(n,v):
    # n = int(input())
    # v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

    for i in range(n):
        if i%2 == 0:
            odd_v.append(v[i])
        else:
            even_v.append(v[i])

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    # for i in range(len(odd_keys)-1):
    #     if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
    #         if odd_keys[i] > odd_keys[i+1]:
    #             tem = odd_keys[i]
    #             odd_keys[i] = odd_keys[i+1]
    #             odd_keys[i+1] = tem
    #
    # for i in range(len(even_keys)-1):
    #     if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
    #         if even_keys[i] > even_keys[i+1]:
    #             tem = even_keys[i]
    #             even_keys[i] = even_keys[i+1]
    #             even_keys[i+1] = tem


    # print(even_dic,odd_dic)
    # print(even_keys,odd_keys)

    if odd_keys[0] != even_keys[0]:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
    else:
        if len(odd_keys) == 1 and len(even_keys) == 1:
            answer = len(odd_v)
        elif len(odd_keys) == 1:
            answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        elif len(even_keys) == 1:
            answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        else:
            # if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
            #     answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            # else:
            #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            answer = min(ans1, ans2)
    print(int(answer))
    

if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main(n,v):
    # n = int(input())
    # v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

    for i in range(n):
        if i%2 == 0:
            odd_v.append(v[i])
        else:
            even_v.append(v[i])

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    # for i in range(len(odd_keys)-1):
    #     if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
    #         if odd_keys[i] > odd_keys[i+1]:
    #             tem = odd_keys[i]
    #             odd_keys[i] = odd_keys[i+1]
    #             odd_keys[i+1] = tem
    #
    # for i in range(len(even_keys)-1):
    #     if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
    #         if even_keys[i] > even_keys[i+1]:
    #             tem = even_keys[i]
    #             even_keys[i] = even_keys[i+1]
    #             even_keys[i+1] = tem


    # print(even_dic,odd_dic)
    # print(even_keys,odd_keys)

    if odd_keys[0] != even_keys[0]:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
    else:
        if len(odd_keys) == 1 and len(even_keys) == 1:
            answer = len(odd_v)
        elif len(odd_keys) == 1:
            answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        elif len(even_keys) == 1:
            answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        else:
            # if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
            #     answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            # else:
            #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            answer = min(ans1, ans2)
    print(int(answer))
    return 0

if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main():
    n = int(input())
    v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

    for i in range(n):
        if i%2 == 0:
            odd_v.append(v[i])
        else:
            even_v.append(v[i])

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    # for i in range(len(odd_keys)-1):
    #     if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
    #         if odd_keys[i] > odd_keys[i+1]:
    #             tem = odd_keys[i]
    #             odd_keys[i] = odd_keys[i+1]
    #             odd_keys[i+1] = tem
    #
    # for i in range(len(even_keys)-1):
    #     if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
    #         if even_keys[i] > even_keys[i+1]:
    #             tem = even_keys[i]
    #             even_keys[i] = even_keys[i+1]
    #             even_keys[i+1] = tem


    # print(even_dic,odd_dic)
    # print(even_keys,odd_keys)

    if odd_keys[0] != even_keys[0]:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
    else:
        if len(odd_keys) == 1 and len(even_keys) == 1:
            answer = len(odd_v)
        elif len(odd_keys) == 1:
            answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        elif len(even_keys) == 1:
            answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        else:
            # if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
            #     answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            # else:
            #     answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            answer = min(ans1, ans2)
    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#encoding utf-8
def main():
    n = int(input())
    v = list(int(i) for i in input().split())
    even_v = []
    odd_v = []

    for i in range(n):
        if i%2 == 0:
            odd_v.append(v[i])
        else:
            even_v.append(v[i])

    odd_dic = {}
    even_dic = {}
    for i in range(len(odd_v)):
        if odd_v[i] in odd_dic.keys():
            odd_dic[odd_v[i]] += 1
        else:
            odd_dic[odd_v[i]] = 1

    for i in range(len(even_v)):
        if even_v[i] in even_dic.keys():
            even_dic[even_v[i]] += 1
        else:
            even_dic[even_v[i]] = 1

    tem_dic = {}
    for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    even_dic = tem_dic
    tem_dic = {}
    for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):
        tem_dic[k] = v
    odd_dic = tem_dic

    # odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
    # even_dic = sorted(even_dic.items(),key=lambda x:x[1])

    odd_keys = list(odd_dic.keys())
    even_keys = list(even_dic.keys())

    # for i in range(len(odd_keys)-1):
    #     if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
    #         if odd_keys[i] > odd_keys[i+1]:
    #             tem = odd_keys[i]
    #             odd_keys[i] = odd_keys[i+1]
    #             odd_keys[i+1] = tem
    #
    # for i in range(len(even_keys)-1):
    #     if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
    #         if even_keys[i] > even_keys[i+1]:
    #             tem = even_keys[i]
    #             even_keys[i] = even_keys[i+1]
    #             even_keys[i+1] = tem


    # print(even_dic,odd_dic)

    if odd_keys[0] != even_keys[0]:
        answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
    else:
        if len(odd_keys) == 1 and len(even_keys) == 1:
            answer = len(odd_v)
        else:
            if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
                answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            else:
                answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            # ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
            # ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
            # answer = min(ans1, ans2)
    print(int(answer))
    # return(int(answer))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#encoding utf-8

n = int(input())
v = list(int(i) for i in input().split())

even_v = []
odd_v = []

for i in range(n):
    if i%2 == 0:
        odd_v.append(v[i])
    else:
        even_v.append(v[i])

odd_dic = {}
even_dic = {}
for i in range(len(odd_v)):
    if odd_v[i] in odd_dic.keys():
        odd_dic[odd_v[i]] += 1
    else:
        odd_dic[odd_v[i]] = 1

for i in range(len(even_v)):
    if even_v[i] in even_dic.keys():
        even_dic[even_v[i]] += 1
    else:
        even_dic[even_v[i]] = 1


for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):pass
for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):pass

# odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
# even_dic = sorted(even_dic.items(),key=lambda x:x[1])

odd_keys = list(odd_dic.keys())
even_keys = list(even_dic.keys())

# for i in range(len(odd_keys)-1):
#     if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
#         if odd_keys[i] > odd_keys[i+1]:
#             tem = odd_keys[i]
#             odd_keys[i] = odd_keys[i+1]
#             odd_keys[i+1] = tem
#
# for i in range(len(even_keys)-1):
#     if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
#         if even_keys[i] > even_keys[i+1]:
#             tem = even_keys[i]
#             even_keys[i] = even_keys[i+1]
#             even_keys[i+1] = tem


# print(even_dic,even_keys)

if odd_keys[0] != even_keys[0]:
    answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
else:
    if len(odd_keys) == 1 and len(even_keys) == 1:
        answer = len(odd_v)
    else:
        if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
            answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        else:
            answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        # ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        # ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        # answer = min(ans1, ans2)
print(int(answer))

Submission status: Wrong Answer

Solution code:
#encoding utf-8

n = int(input())
v = list(int(i) for i in input().split())

even_v = []
odd_v = []

for i in range(n):
    if i%2 == 0:
        odd_v.append(v[i])
    else:
        even_v.append(v[i])

odd_dic = {}
even_dic = {}
for i in range(len(odd_v)):
    if odd_v[i] in odd_dic.keys():
        odd_dic[odd_v[i]] += 1
    else:
        odd_dic[odd_v[i]] = 1

for i in range(len(even_v)):
    if even_v[i] in even_dic.keys():
        even_dic[even_v[i]] += 1
    else:
        even_dic[even_v[i]] = 1


for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):pass
for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):pass

# odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
# even_dic = sorted(even_dic.items(),key=lambda x:x[1])

odd_keys = list(odd_dic.keys())
even_keys = list(even_dic.keys())

# for i in range(len(odd_keys)-1):
#     if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
#         if odd_keys[i] > odd_keys[i+1]:
#             tem = odd_keys[i]
#             odd_keys[i] = odd_keys[i+1]
#             odd_keys[i+1] = tem
#
# for i in range(len(even_keys)-1):
#     if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
#         if even_keys[i] > even_keys[i+1]:
#             tem = even_keys[i]
#             even_keys[i] = even_keys[i+1]
#             even_keys[i+1] = tem


print(even_dic,even_keys)

if odd_keys[0] != even_keys[0]:
    answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
else:
    if len(odd_keys) == 1 and len(even_keys) == 1:
        answer = len(odd_v)
    else:
        if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
            answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        else:
            answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        # ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        # ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        # answer = min(ans1, ans2)
print(int(answer))

Submission status: Wrong Answer

Solution code:
#encoding utf-8

n = int(input())
v = list(int(i) for i in input().split())

even_v = []
odd_v = []

for i in range(n):
    if i%2 == 0:
        odd_v.append(v[i])
    else:
        even_v.append(v[i])

odd_dic = {}
even_dic = {}
for i in range(len(odd_v)):
    if odd_v[i] in odd_dic.keys():
        odd_dic[odd_v[i]] += 1
    else:
        odd_dic[odd_v[i]] = 1

for i in range(len(even_v)):
    if even_v[i] in even_dic.keys():
        even_dic[even_v[i]] += 1
    else:
        even_dic[even_v[i]] = 1


for k, v in sorted(even_dic.items(), key=lambda x: -x[1]):pass
for k, v in sorted(odd_dic.items(), key=lambda x: -x[1]):pass

# odd_dic = sorted(odd_dic.items(),key=lambda x:x[1])
# even_dic = sorted(even_dic.items(),key=lambda x:x[1])

odd_keys = list(odd_dic.keys())
even_keys = list(even_dic.keys())

for i in range(len(odd_keys)-1):
    if odd_dic[odd_keys[i]] == odd_dic[odd_keys[i+1]]:
        if odd_keys[i] > odd_keys[i+1]:
            tem = odd_keys[i]
            odd_keys[i] = odd_keys[i+1]
            odd_keys[i+1] = tem

for i in range(len(even_keys)-1):
    if even_dic[even_keys[i]] == even_dic[even_keys[i+1]]:
        if even_keys[i] > even_keys[i+1]:
            tem = even_keys[i]
            even_keys[i] = even_keys[i+1]
            even_keys[i+1] = tem


if odd_keys[0] != even_keys[0]:
    answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[0]])
else:
    if len(odd_keys) == 1 and len(even_keys) == 1:
        answer = len(odd_v)
    else:
        if odd_dic[odd_keys[1]] > even_dic[even_keys[1]]:
            answer = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        else:
            answer = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        # ans1 = n-int(odd_dic[odd_keys[0]])-int(even_dic[even_keys[1]])
        # ans2 = n-int(odd_dic[odd_keys[1]])-int(even_dic[even_keys[0]])
        # answer = min(ans1, ans2)
print(int(answer))