Problem: 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.

Submission attempts (in order):
#encoding utf-8
def main(n,v):
    # n = int(input())
    
    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

    
    # 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]:
        if odd_dic[odd_keys[0]] == even_dic[even_keys[0]]:
            if len(odd_keys) == 1:
                answer = n-even_dic[even_keys[1]]
            elif len(even_keys) == 1:
                answer = n-odd_dic[odd_keys[1]]
            else:
                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)
        elif len(odd_keys) == 1:
            print("a")
            answer = n-odd_dic[odd_keys[0]]-even_dic[even_keys[1]]
        elif len(even_keys) == 1:
            answer = n-odd_dic[odd_keys[1]]-even_dic[even_keys[0]]
        else:
            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]])

    print(int(answer))
    # return(int(answer))

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


#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


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

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







#

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





#encoding utf-8
def main(n,v):
    # n = int(input())
    
    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

    
    # 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]:
        if odd_dic[odd_keys[0]] == even_dic[even_keys[0]]:
            if len(odd_keys) == 1:
                answer = n-even_dic[even_keys[1]]
            elif len(even_keys) == 1:
                answer = n-odd_dic[odd_keys[1]]
            else:
                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)
        elif len(odd_keys) == 1:
            answer = n-odd_dic[odd_keys[0]]-even_dic[even_keys[1]]
        elif len(even_keys) == 1:
            answer = n-odd_dic[odd_keys[1]]-even_dic[even_keys[0]]
        else:
            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]])

    print(int(answer))
    # return(int(answer))

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

#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

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

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

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

#encoding utf-8
def main(n,v):
    # n = int(input())
    
    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

    
    # 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]])







    
    #     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:
    
    #         #     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)

#encoding utf-8

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


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

#odd part
count={}
for i in range(len(v_odd)):
    if v_odd[i] in count.keys():
        count[v_odd[i]] += 1
    else:
        count[v_odd[i]] = 1

if len(count) == 1:
    pass
    # num_odd = 0
else:
    for k, v in sorted(count.items(), key=lambda x: -x[1]):
        pass
    keys = list(count.keys())
    # num_odd = len(v_odd)-int(count[keys[0]])
# print(num)

#even part
even_count={}

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

if len(even_count) == 1:
    pass
    
else:
    for k, v in sorted(even_count.items(), key=lambda x: -x[1]):
        pass
    even_keys = list(even_count.keys())
    

if even_keys[0] == keys[0]:
    if len(keys) == 1 and len(even_keys) == 1:
        answer = int(len(keys))
    elif len(keys) == 1:
        answer = len(v_even)-int(v_even[even_keys[1]])
    elif len(even_keys) == 1:
        answer = len(v_odd)-int(v_odd[keys[1]])
    else:
        if int(v_even[even_keys[0]]) >= int(v_odd[keys[0]]):
            answer = len(v_odd)-int(count[keys[1]])
            answer += len(v_even)-int(even_count[even_keys[0]])
        else:
            answer = len(v_odd)-int(count[keys[0]])
            answer += len(v_even)-int(even_count[even_keys[1]])
print(int(answer))



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

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)


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

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print("答え",ans)

#encoding utf-8
from collections import Counter
def main(n,v):
    odd = Counter(v[0::2]).most_common(2) + [(0,0)]
    even = Counter(v[1::2]).most_common(2) + [(0,0)]

    if odd[0][0] == even[0][0]:
        ans = min(n-odd[0][1]-even[1][1],
        n-odd[1][1]-even[0][1])
    else:
        ans = n-odd[0][1]-even[0][1]
    print(ans)


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

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted