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())
a = [int(aa) for aa in input().split()]

def add_entry(hist, aa):
    if aa in hist:
        hist[aa] += 1
    else:
        hist[aa] = 1


def make_hist(a):
    even_hist = {}
    odd_hist = {}

    for i in range(len(a)//2):
        add_entry(even_hist, a[2*i])
        add_entry(odd_hist, a[2*i+1])

    return even_hist, odd_hist


def get_sorted_hist(hist):
    return sorted(hist.items(), key=lambda x: x[0])

eh, oh = make_hist(a)
seh = get_sorted_hist(eh)
soh = get_sorted_hist(oh)

if seh[0][0] != soh[0][0]:
    print(len(a) - seh[0][1] - soh[0][1])
else:
    if len(seh) == 1 and len(soh) == 1:
        print(len(a)//2)
    elif len(seh) == 1:
        print(len(a) - seh[0][1] - soh[1][1])
    elif len(soh) == 1:
        print(len(a) - soh[0][1] - seh[1][1])
    else:
        print(min(len(a) - seh[0][1] - soh[1][1], len(a) - soh[0][1] - seh[1][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
ma = {}
ma[lst[0]] = 1
mb = {}
mb[lst[1]] = 1
for i in range(2, n, 2):
    lst[i] in ma
    if lst[i] in ma:
        ma[lst[i]] += 1
    else:
        ma[lst[i]] = 1
    lst[i+1] in mb
    if lst[i+1] in mb:
        mb[lst[i+1]] += 1
    else:
        mb[lst[i+1]] = 1
if max(ma, key=ma.get) in mb:
    mb[max(ma, key=ma.get)] = 0
d = n - max(ma.values()) - max(mb.values())
print(d)

Submission status: Wrong Answer

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

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

cv1 = collections.Counter(v[::2])
cv2 = collections.Counter(v[1::2])
num1 = cv1.most_common()[0][0]
num2 = cv2.most_common()[0][0]
cnt1 = cv1.most_common()[0][1]
cnt2 = cv2.most_common()[0][1]

if num1==num2:
  if cnt1>cnt2:
    cnt2 = cv2.most_common()[1][1]
  else:
    cnt1 = cv1.most_common()[1][1]

print(n-(cnt1+cnt2))

Submission status: Wrong Answer

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(a):
    if i % 2 == 0:
        c[b[i]-1] += 1
    else:
        cc[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(d+1):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = [int(i) for i in input().split()]
odd = collections.Counter(v[1::2])
even = collections.Counter(v[0::2])
# print(odd)

max_odd = max(odd, key=odd.get)
# print(max_odd)
max_even = max(even, key=even.get)
# print(max_even)

max_odd_v = odd[max_odd]
max_even_v = even[max_even]
if max_odd == max_even:
    if max_odd_v < max_even_v:
        del(odd[max_odd])
        if len(odd) > 0:
            max_odd = max(odd, key=odd.get)
            max_odd_v = odd[max_odd]
        else:
            max_odd_v = 0
    else:
        del(even[max_even])
        if len(even) > 0:
            max_even = max(even, key=even.get)
            max_even_v = even[max_even]
        else:
            max_even_v = 0

num_change_odd = int(n / 2) - max_odd_v
num_change_even = int(n / 2) - max_even_v
print(num_change_odd + num_change_even)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
n = N // 2

index = 0
g_inputs = []
k_inputs = []

for i in input().split():
    if index % 2 == 0:
        g_inputs.append(int(i))
        index += 1
    else:
        k_inputs.append(int(i))
        index += 1

g = Counter(g_inputs)
k = Counter(k_inputs)

g_max = max([(v,k) for k,v in g.items()])[1] 
k_max = max([(v,k) for k,v in k.items()])[1]

if g_max == k_max:
    if g[g_max] < k[k_max]:
        del g[g_max]
        g_max = max([(v,k) for k,v in g.items()])[1]
        print(N - g[g_max] - k[k_max])
    elif g[g_max] > k[k_max]:
        del k[k_max]
        k_max = max([(v,k) for k,v in k.items()])[1]
        print(N - g[g_max] - k[k_max])
    else:
        del g[g_max]
        del k[k_max]
        if len(g) == 0 and len(k) == 0:
            print(n)
        elif len(g) != 0 and len(k) == 0:
            print(n - g[max([(v,k) for k,v in g.items()])[1]])
        elif len(g) == 0 and len(k) != 0:
            print(n - k[max([(v,k) for k,v in k.items()])[1]])
        elif len(g) != 0 and len(k) != 0:
            g_max = max([(v,k) for k,v in g.items()])[1]
            k_max = max([(v,k) for k,v in k.items()])[1]
            if g[g_max] < k[k_max]:
                print(n - k[k_max])
            elif g[g_max] > k[k_max]:
                print(n - g[g_max])
            else:
                print(n- k[k_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
e = []
o = []
for i, a in enumerate(v):
    if i % 2:
        o.append(a)
    else:
        e.append(a)
oc = Counter(o)
ec = Counter(e)
h = n//2
ans = h

a = []
for i, (k, v) in enumerate(oc.most_common()):
    if not v in a:
        a.append(v)
    if len(a) >= 3:
        break
a = []
for j, (k, v) in enumerate(ec.most_common()):
    if not v in a:
        a.append(v)
    if len(a) >= 3:
        break
for k, v in oc.most_common(i):
    for k2, v2 in ec.most_common(j):
        if k == k2:
            continue
        ans = min(ans, h - v + h - v2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(aa) for aa in input().split()]

def add_entry(hist, aa):
    if aa in hist:
        hist[aa] += 1
    else:
        hist[aa] = 1


def make_hist(a):
    even_hist = {}
    odd_hist = {}

    for i in range(len(a)//2):
        add_entry(even_hist, a[2*i])
        add_entry(odd_hist, a[2*i+1])

    return even_hist, odd_hist


def get_sorted_hist(hist):
    return sorted(hist.items(), key=lambda x: x[0])

eh, oh = make_hist(a)
seh = get_sorted_hist(eh)
soh = get_sorted_hist(oh)

print(soh, seh)


if seh[0][0] != soh[0][0]:
    print(len(a) - seh[0][1] - soh[0][1])
else:
    if len(seh) == 1 and len(soh) == 1:
        print(len(a)//2)
    elif len(seh) == 1:
        print(len(a) - seh[0][1] - soh[1][1])
    elif len(soh) == 1:
        print(len(a) - soh[0][1] - seh[1][1])
    else:
        print(min(len(a) - seh[0][1] - soh[1][1], len(a) - soh[0][1] - seh[1][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

v0 = Counter(v).most_common()
v1 = Counter(v[0::2]).most_common()
v2 = Counter(v[1::2]).most_common()

if len(v0)<=2:
    if len(v1)==1 and len(v2)==1:
        if v1[0][0]==v2[0][0]:
            print(v1[0][1])
        else:
            print(0)
    else:
        print(min(v1,v2)[0][1])
else:
    c = 0
    if v1[0][0]==v2[0][0]:
        for i in v1[1:]:
            c += i[1]
        for i in v2:
            c += i[1]
        print(c-v2[1][1])
    else:
        if len(v1) >= 2:
            for i in v1[1:]:
                c += i[1]
        if len(v2) >= 2:
            for i in v2[1:]:
                c += i[1]
        print(c)

Submission status: Wrong Answer

Solution code:
import collections

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

v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]

count1 = collections.Counter(v1)
count2 = collections.Counter(v2)

if len(count1) == 1 and len(count2) == 1:
    if v1 == v2:
        print(len(v1))
    else:
        print(0)

elif v1 == v2:
    res = len(v1) - max(count1.values())
    count2.pop(max(count2,key=count2.get))
    res = res + len(v2) - max(count2.values())
    print(res)

else:
    res = len(v1) - max(count1.values()) + len(v2) - max(count2.values())
    print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

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

    if len(set(v)) == 1:
        print(half)
        exit()
    else:
        even = Counter(v[::2]).most_common(1)[0][0]
        odd = Counter(v[1::2]).most_common(1)[0][0]
        ans1 = 0
        ans2 = 0
        ans3 = 0

        if even == odd:
            even2 = Counter(v[::2]).most_common(2)[0][0]
            odd2 = Counter(v[1::2]).most_common(2)[0][0]

            for i in range(n):
                if i % 2 == 0:
                    if v[i] != even:
                        ans2 += 1
                else:
                    if v[i] != odd2:
                        ans2 += 1

            for i in range(n):
                if i % 2 == 0:
                    if v[i] != even2:
                        ans3 += 1
                else:
                    if v[i] != odd:
                        ans3 += 1

            print(min(ans2, ans3))
            exit()

        for i in range(n):
            if i % 2 == 0:
                if v[i] != even:
                    ans1 += 1
            else:
                if v[i] != odd:
                    ans1 += 1

        print(ans1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a = [ v[i] for i in range(0,n,2)]
b = [ v[i] for i in range(1,n,2)]
A = [0] * 100010
B = [0] * 100010

for i in range(int(n/2)):
    A[a[i]] += 1
    B[b[i]] += 1

if A.index(max(A)) == B.index(max(B)):
    if max(A) > max(B):
        BB = sorted(B)
        print(len(b) - BB[-2] + len(a) - max(A))
    else:
        AA = sorted(A)
        print(len(a) - AA[-2] + len(b) - max(B))
else:
    print(n - max(A) - max(B))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
v = input().split()
c=Counter(v)
c1=c.most_common()[0][1]

if (c1==n):
    print("0")
else:
    c2=c.most_common()[1][1]
    print(n//2-c2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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


    ans = 0
    vc = Counter(v)
    vc0 = Counter(v[::2])
    vc1 = Counter(v[1::2])

    if len(set(v[::2])) == 1:
        print(len(v)//2 - vc1.most_common(1)[0][1])
        exit()
    elif len(set(v[1::2])) == 1:
        print(len(v)//2 - vc0.most_common(1)[0][1])
        exit()

    if vc.most_common(1)[0][1] >= len(v)//2:
        if vc0.most_common(2)[1][1] > vc1.most_common(2)[1][1]:
            if len(set(v[::2])) !=1:
                ans += len((v[::2])) - vc0.most_common(2)[1][1]
            ans += len((v[1::2])) - vc1.most_common(1)[0][1]
        else:
            ans += len((v[::2])) - vc0.most_common(1)[0][1]
            if len(set(v[1::2])) !=1:
                ans += len((v[1::2])) - vc1.most_common(2)[1][1]

    else:
        ans += len((v[::2])) - vc0.most_common(1)[0][1]
        ans += len((v[1::2])) - vc1.most_common(1)[0][1]

    print(ans)

if __name__ == "__main__":
        main()

Submission status: Wrong Answer

Solution code:
import collections

n = input()
nums = list(map(int, input().split()))
odd = nums[0::2]
even = nums[1::2]
odd_c = collections.Counter(odd)
even_c = collections.Counter(even)


if odd_c.most_common(1)[0][0] == even_c.most_common(1)[0][0]:
    if len(odd_c) >= 3 and len(even_c) >= 3:
        odd_first_count = len(odd) - odd_c.most_common(1)[0][1]
        even_first_count = len(even) - even_c.most_common(1)[0][1]
        odd_second_count = len(odd) - odd_c.most_common(2)[1][1]
        even_second_count = len(even) - even_c.most_common(2)[1][1]
        if odd_first_count + even_second_count > odd_second_count + even_first_count:
            print(odd_first_count + even_second_count)
            exit()
        else:
            print(odd_second_count + even_first_count)
            exit()
    odd_next_most = 0
    even_next_most = 0
    if len(odd_c) >= 2:
        odd_next_most = odd_c.most_common(2)[1][1]
    if len(even_c) >= 2:
        even_next_most = even_c.most_common(2)[1][1]
    if odd_next_most > even_next_most:
        print(len(odd) - odd_next_most + len(even) - even_c.most_common(1)[0][1])
    else:
        print(len(odd) - odd_c.most_common(1)[0][1] + len(even) - even_next_most)
else:
    print("else")
    odd_change = len(odd) - odd_c.most_common(1)[0][1]
    even_change = len(even) - even_c.most_common(1)[0][1]
    print(odd_change + even_change)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
evens = []
odds = []
for i in range(0, n, 2):
    evens.append(v[i])
for i in range(1, n, 2):
    odds.append(v[i])
evens_cnts = Counter(evens)
odds_cnts = Counter(odds)
evens_change = n // 2 - max(evens_cnts.values())
odds_change = n // 2 - max(odds_cnts.values())
if evens_change == 0 and odds_change == 0:
    # 要素が全て同じか判定
    if evens[0] == odds[0]:
        print(n // 2)
    else:
        print(0)
else:
    if evens == odds:
        li = list(odds_cnts.keys())
        odds_cnts.pop(li[0])
        odds_change = n // 2 - max(odds_cnts.values())
        print(evens_change + odds_change)
        exit()
    if evens_change < odds_change:
        li = list(evens_cnts.keys())
        if li[0] in odds:
            odds_cnts.pop(li[0])
        odds_change = n // 2 - max(odds_cnts.values())
    else:
        li = list(odds_cnts.keys())
        if li[0] in evens:
            evens_cnts.pop(li[0])
        evens_change = n // 2 - max(evens_cnts.values())
    print(evens_change + odds_change)

Submission status: Wrong Answer

Solution code:
s = raw_input()
num = int(s)
l = map(int, raw_input().split())


retsulen = len(l)

odd = []
even = []

for i in range(retsulen//2):
    odd.append(l[2*i])
    even.append(l[2*i+1])

oddset = set(odd)
evenset = set(even)

allset = oddset | evenset



oddnum = 0
evennum = 0


oddcount = []
evencount = []

for i in oddset:
    oddcount.append(i)


for i in evenset:
    evencount.append(i)


oddcountnum = []
evencountnum = []

for i in range(len(oddcount)):
    oddcountnum.append(odd.count(oddcount[i]))

oddcountdict = dict(zip(oddcountnum, oddcount))


for i in range(len(evencount)):
    evencountnum.append(even.count(evencount[i]))

evencountdict = dict(zip(evencountnum, evencount))

oddcount.sort()
evencount.sort()


sorted(oddcountdict.items(), key=lambda x: -x[0])
sorted(evencountdict.items(), key=lambda x: -x[0])



oddkey = oddcountdict.keys()
oddvalue = oddcountdict.values()

evenkey = evencountdict.keys()
evenvalue = evencountdict.values()

if len(allset) == 1:
    print(num//2)
elif oddvalue[0] == evenvalue[0] and oddkey[0]>evenkey[0]:

    for i in range(len(oddcount)-1):
        oddnum = oddnum + oddcountnum[i]
    for i in range(len(evencount)-2):
        evennum = evennum + evencountnum[i+2] + evencountnum[0]
    print (oddnum + evennum)


elif oddvalue[0] == evenvalue[0] and evenkey[0]>oddkey[0]:

    for i in range(len(oddcount)-2):
        oddnum = oddnum + oddcountnum[i+2]+oddcountnum[0]
    for i in range(len(evencount)-1):
        evennum = evennum + evencountnum[i]
    print (oddnum + evennum)

elif oddvalue[0] != evenvalue[0]:
    for i in range(len(oddcount)-1):
        oddnum = oddnum + oddcountnum[i]
    for i in range(len(evencount)-1):
        evennum = evennum + evencountnum[i]
    print (oddnum + evennum)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())

al = [int(l) for l in input().split()]

a = []
b = []
for i, x in enumerate(al):
    if i%2 == 0:
        a.append(x)
    else:
        b.append(x)

ac = collections.Counter(a).most_common()
bc = collections.Counter(b).most_common()

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if ac[0][1] >= bc[0][1]:
        if len(bc) <= 1:
            print(n-ac[0][1])
        else:
            print(n-ac[0][1]-bc[1][1])
    else:
        if len(ac) <= 1:
            print(n-bc[0][1])
        else:
            print(n-ac[1][1]-bc[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int,input().split()))
l = list(range(n))
odd = [v[i] for i in l if i%2 == 0]
even = [v[i] for i in l if i%2 == 1]

import collections
oddm = collections.Counter(odd).most_common()
evenm = collections.Counter(odd).most_common()

if oddm[0][0] != evenm[0][0]:
    a = (n/2)-oddm[0][1]+(n/2)-evenm[0][1]
else:
    if len(oddm) == 1 and len(evenm) == 1:
        a = n/2
    elif len(oddm) == 1:
        a = (n/2)-evenm[1][1]
    elif len(evenm) == 1:
        a = (n/2)-oddm[1][1]
    else:
        a = n-max(evenm[1][1]+oddm[0][1],evenm[0][1]+oddm[1][1])

print(int(a))

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import collections

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

c = 0
even, odd = [],[]

even = V[0::2]
odd = V[1::2]

ce = collections.Counter(even)
co = collections.Counter(odd)
cV = collections.Counter(V)


if len(ce.keys()) == 1 and len(co.keys()) == 1:
    c = 0

elif len(ce.keys()) == 1 and len(co.keys()) > 1:
    c = len(co) - co.most_common()[0][1]

elif len(co.keys()) == 1 and len(ce.keys()) > 1:
    c = len(ce) - ce.most_common()[0][1]

else:
    c = len(ce) + len(co) - ce.most_common()[0][1] - co.most_common()[0][1]
    
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
count=0
v=[]
v=[int(i) for i in input().split()]
for i in range(n-2):
    if v[i]==v[i+2]:
        pass
    else:
        count+=1
flag=True
for i in range(n-1):
    if v[i]==v[i+1]:
        continue
    else:
        flag=False
if flag:
    if n%2==0:
        count=int(n/2)
    else:
        count=int((n-1)/2)
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

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

    if len(set(v)) == 1:
        print(half)
        exit()
    else:
        even = Counter(v[::2]).most_common(1)[0][0]
        odd = Counter(v[1::2]).most_common(1)[0][0]
        ans1 = 0
        ans2 = 0
        ans3 = 0

        if even == odd:
            even2 = Counter(v[::2]).most_common(2)[0][0]
            odd2 = Counter(v[1::2]).most_common(2)[0][0]

            for i in range(n):
                if i % 2 == 0:
                    if v[i] != even:
                        ans2 += 1
                else:
                    if v[i] != odd2:
                        ans2 += 1

            for i in range(n):
                if i % 2 == 0:
                    if v[i] != even2:
                        ans3 += 1
                else:
                    if v[i] != odd:
                        ans3 += 1

            print(min(ans2, ans3))

        for i in range(n):
            if i % 2 == 0:
                if v[i] != even:
                    ans1 += 1
            else:
                if v[i] != odd:
                    ans1 += 1

        print(ans1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split(' ')]

v_odd = v[1::2]
v_even = v[0::2]

vo = collections.Counter(v_odd).most_common()
ve = collections.Counter(v_even).most_common()

# 最大の値が同じ場合
if vo[0][0] == ve[0][0]:
    # 奇数のほうが少ない場合
    if vo[0][1] > ve[0][1]:
        result = len(v_odd) - vo[0][1] + len(v_even) - ve[1][1]
    elif vo[0][1] < ve[0][1]:
        result = len(v_odd) - vo[1][1] + len(v_even) - ve[0][1]
    else:
        if len(ve) == 1:
            result = len(v_odd) - vo[0][1] + len(v_even)
        else:
            result = len(v_odd) - vo[0][1] + len(v_even) - ve[1][1]
        
else:
    result = len(v_odd) - vo[0][1] + len(v_even) - ve[0][1]

print(result)

Submission status: Wrong Answer

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

head = vlist[::2]
foll = vlist[1::2]

import collections
ch = collections.Counter(head).most_common()
cf = collections.Counter(foll).most_common()

h_ = ch[0]
f_ = cf[0]

if h_[0] == f_[0]:
    if h_[1] > f_[1]:
        if len(cf) != 1:
            f_ = cf[1]
        else:
            f_ = (-1.1, 0)
    else:
        if len(ch) != 1:
            h_ = ch[1]
        else:
            h_ = (-1.1, 0)
elif h_[1] == f_[1]:
    if h_[0] == vlist[0]:
        f_ = (-1.1, 0)
    else:
        h_ = (-1.1, 0)

count = 0
for i in range(len(vlist)):
    if i % 2 == 0 and vlist[i] != h_[0]:
        count += 1
    if i % 2 == 1 and vlist[i] != f_[0]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
def exchange(v):
    cnt = 0
    pattern2 = 0
    for (i, num) in enumerate(v):
        if i == 0:
            pattern1 = num
        elif i % 2 == 0:
            if pattern1 != num:
                cnt += 1
        elif i % 2 == 1:
            if pattern2 == 0 and num != pattern1:
                pattern2 = num
            elif pattern2 == 0 and num == pattern1:
                cnt += 1
            elif pattern2 != num:
                cnt += 1
    return cnt

        

if __name__ == "__main__":
    n = int(input())
    v = list(map(int,input().split()))
    print(exchange(v))

Submission status: Wrong Answer

Solution code:
#Bad_Beast
n=int(input())
a=list(map(int,input().split()))
if len(set(a))==1:
    print(int(n/2))
    
else:
    cur1=a[0]
    cur2=a[1]
    i=0
    t=True
    while i<n:
        if a[i]!=cur1:
            t=False
            break
        if a[i+1]!=cur2:
            t=False
            break
        i+=2
    if t:
        #print("in")
        print(0)
        
    else:    
        i=0
        oc=[0]*100005
        for i in range(n):
            oc[a[i]]+=1
        m=0    
        cur1=0
        cur2=0
        for i in range(100005):
            if oc[i]>m:
                m=oc[i]
                cur1=i
        oc[cur1]=0
        m=0
        for i in range(100005):
            if oc[i]>m:
                m=oc[i]
                cur2=i
        ind1=100005
        ind2=100005
        for i in range(n):
            if a[i]==cur1:
                if i<ind1:
                    ind1=i
                
            elif a[i]==cur2:
                if i<ind2   : 
                    ind2=i
        #print(ind1,ind2)
        if ind1>ind2:
            total=0
            i=0
            while i<n:
                if a[i]!=cur2:
                    total+=1
                if a[i+1]!=cur1:
                    total+=1
                i+=2    
            print(total)
        elif ind1<ind2:
            total=0
            i=0
            while i<n:
                
                if a[i]!=cur1:
                    total+=1
                if a[i+1]!=cur2:
                    total+=1
                i+=2 
            print(total)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())

array = list(map(int, input().split()))

array_0 = collections.Counter(array[::2]).most_common()
array_1 = collections.Counter(array[1::2]).most_common()

array_0_v = array_0[0][0]
array_1_v = array_1[0][0]

if array_0_v == array_1_v:
    if len(array_0) * len(array_1) == 1:
        print(n // 2)
        exit()
    elif array_0[0][1] > array_1[0][1]:
        array_1_v = array_1[1][0]
    else:
        array_0_v = array_0[1][0]

count = 0
for i in range(n // 2):
    count += array[i * 2] != array_0_v
    count += array[i * 2 + 1] != array_1_v

print(count)

Submission status: Wrong Answer

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

head = vlist[::2]
foll = vlist[1::2]

import collections
ch = collections.Counter(head).most_common()
cf = collections.Counter(foll).most_common()

h_ = ch[0]
f_ = cf[0]

if h_[1] == f_[1]:
    if h_[0] == vlist[0]:
        f_ = (-1.1, 0)
    else:
        h_ = (-1.1, 0)
elif h_[0] == f_[0]:
    if h_[1] > f_[1]:
        if len(cf) != 1:
            f_ = cf[1]
        else:
            f_ = (-1.1, 0)
    else:
        if len(ch) != 1:
            h_ = ch[1]
        else:
            h_ = (-1.1, 0)

count = 0
for i in range(len(vlist)):
    if i % 2 == 0 and vlist[i] != h_[0]:
        count += 1
    if i % 2 == 1 and vlist[i] != f_[0]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
v_ = map(int, input().split())
v = []
for val in v_:
	v.append(val)
v = np.array(v)

v_c = [sum(v==a) for a in range(1, 11, 1) if sum(v==a) != 0]
if len(v_c) < 2:
	print(2)
elif len(v_c) == 2:
	print(0)
else:
	print(sum(sorted(v_c, reverse=True)[2:]))

Submission status: Wrong Answer

Solution code:
n = int(input())
m = input().split(" ")
li = [int(i) for i in m]
li_0 = [k for ix, k in enumerate(li) if ix%2 == 0]
li_1 = [k for ix, k in enumerate(li) if ix%2 == 1]

#li_0
se_0 = set(li_0)
li_02 = list(se_0) 
s0 = []
for i in range(len(li_02)):
    c = li_02.count(li_02[i])
    s0.append(c)
change_0 = sum(s0) - max(s0)

#li_1
se_1 = set(li_1)
li_12 = list(se_1) 
s1 = []
for i in range(len(li_12)):
    c = li_12.count(li_12[i])
    s1.append(c)
change_1 = sum(s1) - max(s1)

print(change_0 + change_1)

Submission status: Wrong Answer

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

def w2(x):
    return x[::2], x[1:][::2]

def isnnn(x):
    return len(set(x))==2 and len(set(x[::2]))==1 and len(set(x[1:][::2]))==1

def sa(v):
    vd = {}
    for i in v:
        if i in vd:
            vd[i] += 1
        else:
            vd[i] = 1
    max_k = max(vd, key=vd.get)
    return max_k, len(v) - vd[max_k], 

if isnnn(vs):
    print(0)
elif len(set(vs))==1:
    print(int(len(vs)/2))
else:
    v1, v2 = w2(vs)
    v1_k, sa1 = sa(v1)
    v2_k, sa2 = sa(v2)
    if v1_k != v2_k:
        print(sa1+sa2)
    elif sa1 < sa2:
        v1_s = list(filter(lambda x: x != v1_k, v1))
        v1_k2, sa12 = sa(v1_s)
        print(sa12+sa2+v1.count(v1_k))
    else:
        v2_s = list(filter(lambda x: x != v2_k, v2))
        v2_k2, sa22 = sa(v2_s)
        print(sa1+sa22+v2.count(v2_k))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
list = input().split(" ")
array = [int(s) for s in list]
even = []
odd = []
for i in range(n):
  num = array[i]
  if i % 2 == 0:
    even.append(num)
  else:
    odd.append(num)
e = collections.Counter(even)
o = collections.Counter(odd)
e_max = e.most_common()[0][0]
o_max = o.most_common()[0][0]
if even == odd:
  count = len(even)
  print(count)
elif e_max == o_max:
  if e.most_common()[1][1] <= o.most_common()[1][1]:
    o_max = o.most_common()[1][1]
  else:
    e_max = e.most_common()[1][1] 
  sol = [] 
  for i in even:
    if i != e_max:
      sol.append(1)
  for i in odd:
    if i != o_max:
      sol.append(1)
  ans = len(sol)
  print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
v_P=list(map(int, input().split()))
P_odd={}
P_even={}
for i in range(N):
	if i%2==0:
		if (v_P[i] in P_even)==0:
			P_even[v_P[i]]=1
		else:
			P_even[v_P[i]] += 1
	else:
		if (v_P[i] in P_odd)==0:
			P_odd[v_P[i]]=1
		else:
			P_odd[v_P[i]] += 1

max_odd, max_even=max(P_odd.values()), max(P_even.values())
print(N-max_odd-max_even)

Submission status: Wrong Answer

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

num_v = {}
for v_ in v:
	if v_ not in num_v:
		num_v[v_]  = 1
	else:
		num_v[v_] += 1
if len(num_v) == 1:
	print n / 2
else:
	sorted_num_v = sorted(num_v.items(), key=lambda x:x[1])
	v_1st = sorted_num_v[-1][0]
	v_2nd = sorted_num_v[-2][0]
	odd = 0
	even = 0
	for i in range(n):
		if v[i] == v_1st and i % 2 == 0:
			odd += 1	
		if v[i] == v_1st and i % 2 != 0:
			even += 1
		if v[i] == v_2nd and i % 2 == 0:
			even += 1
		if v[i] == v_2nd and i % 2 != 0:
			odd += 1
			
	print n - max(even, odd)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
v = [int(i) for i in input().split()]
odd = collections.Counter(v[1::2])
even = collections.Counter(v[0::2])
# print(odd)

max_odd = max(odd, key=odd.get)
# print(max_odd)
max_even = max(even, key=even.get)
# print(max_even)

max_odd_v = odd[max_odd]
max_even_v = even[max_even]
if max_odd == max_even:
    if max_odd_v < max_even_v:
        del(odd[max_odd])
        try:
            max_odd = max(odd, key=odd.get)
            max_odd_v = odd[max_odd]
        except:
            max_odd_v = 0
    else:
        del(even[max_even])
        try:
            max_even = max(even, key=even.get)
            max_even_v = even[max_even]
        except:
            max_even_v = 0

num_change_odd = int(n / 2) - max_odd_v
num_change_even = int(n / 2) - max_even_v
print(num_change_odd + num_change_even)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
num_list = input().split()
m=1
num_list_1 = []
num_list_2 = []
for n in range(0, n, 2):
    num_list_1.append(num_list[n])
    num_list_2.append(num_list[n+1])
c_1 = collections.Counter(num_list_1)
c_2 = collections.Counter(num_list_2)

lib_1 = c_1.most_common()
lib_2 = c_2.most_common()
k = 0
print(lib_1)
print(lib_2)
z = len(lib_1)
for n in range(1,z):
    k += int(lib_1[n][1])

z = len(lib_2)
for n in range(1,z):
    k += int(lib_2[n][1])
    
if lib_1[0][0] != lib_2[0][0]:
    print(k)
else:
    if lib_1[0][1] >= lib_2[0][1]:
        print(k+lib_2[0][1])
    else:
        print(k+lib_1[0][1])