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:
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    n=int(input())
    v=list(map(int,input().split()))
    do=defaultdict(int)
    de=defaultdict(int)
    for i,x in enumerate(v):
        if i%2:
            do[x]+=1
        else:
            de[x]+=1
    o1,e1,o2,e2=0,0,0,0
    for x in do.keys():
        if do[x]>o1:
            o1=do[x]
            o1n=x
        else:
            o2=max(o2,do[x])
    for x in de.keys():
        if de[x]>e1:
            e1=de[x]
            e1n=x
        else:
            e2=max(e2,de[x])
    if o1n!=e1n:
        print(n-(o1+e1))
    else:
        print(n-max(o1+e2,o2+e1))
            
            

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#python3
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

odd = [a[i] for i in range(n) if i%2==0]
even = [a[i] for i in range(n) if i%2!=0]

cntOdd = Counter(odd).most_common(2)
cntEven = Counter(even).most_common(2)

 

if cntOdd[0][0] != cntEven[0][0]:
    print(n - cntOdd[0][1] - cntEven[0][1])
else:
    if len(cntEven) == 1 and len(cntEven):
        print(n//2)
    else:
        ans1 = n - cntOdd[1][1] - cntEven[0][1]
        ans2 = n - cntOdd[0][1] - cntEven[1][0]
        print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
#python3
import collections as clct
import operator as op 

n=int(input())
a=[int(i) for i in input().split()]
odd = [a[i] for i in range(n) if i%2 == 0] 
even = [a[i] for i in range(n) if i%2 != 0]

if len(set(a)) == 1:
    print(n//2)
else:
    def mostFreq(array):
        dic = clct.Counter(array)
        mostFreqnum = -1
        maxFreq = -1
        for number, count in dic.items():
            if count > mostFreqnum:
                maxFreq = count
                mostFreqnum = number
        return mostFreqnum

    def secondFreq(array):
        dic = clct.Counter(array)
        tmp = [(0, 0)]*(n//2)
        for i, j in dic.items():
            tmp.append((i, j))
        tmp.sort(key=op.itemgetter(1), reverse=True)

        return tmp[1][0]

    

    def s(array):
        mFreqNum = mostFreq(array)
        cnt = 0
        for num in array:
            if num != mFreqNum:
                cnt += 1
        return cnt


    def t(array):
        sFreqNum = secondFreq(array)
        cnt = 0
        for num in array:
            if num != sFreqNum:
                cnt +=1
        return cnt

    mostFreqOdd = s(odd)
    mostFreqEven = s(even)
    secondFreqOdd = t(odd)
    secondFreqEven = t(even)

    sum1 = mostFreqOdd + mostFreqEven
    sum2 = mostFreqOdd + secondFreqEven
    sum3 = mostFreqEven + secondFreqOdd

    ans = min(sum1, min(sum2, sum3))
    print(ans)

Submission status: Wrong Answer

Solution code:
#python3
import collections as clct
n=int(input())
a=[int(i) for i in input().split()]
odd = [a[i] for i in range(n) if i%2 == 0] 
even = [a[i] for i in range(n) if i%2 != 0]

if len(set(a)) == 1:
    print(n//2)
else:
    def mostFreq(array):
        dic = clct.Counter(array)
        mostFreqnum = -1
        maxFreq = -1
        for number, count in dic.items():
            if count > mostFreqnum:
                maxFreq = count
                mostFreqnum = number
        return mostFreqnum

    def s(array):
        mFrepNum = mostFreq(array)
        cnt = 0
        for num in array:
            if num != mFrepNum:
                cnt += 1
        return cnt

    print(s(odd)+s(even))

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(n//2)
  exit()
oddv = v[::2]
oddvcnts = {}
evenv = v[1::2]
evenvcnts = {}
for vi in oddv:
  oddvcnts[vi] = oddvcnts.get(vi, 0) + 1
for vi in evenv:
  evenvcnts[vi] = evenvcnts.get(vi, 0) + 1
maxoddvcnt = max(list(oddvcnts.values()))
maxevenvcnt = max(list(evenvcnts.values()))
maxoddv = list(filter(lambda x:x[1] == maxoddvcnt, oddvcnts.items()))[0][0]
maxevenv = list(filter(lambda x:x[1] == maxevenvcnt, evenvcnts.items()))[0][0]
# print(maxoddv, maxevenv)
if maxoddv == maxevenv:
  maxevenvcnt = sorted(list(evenvcnts.values()), reverse=True)[1]
# print(oddv, evenv, maxoddvcnt, maxevenvcnt)
print(len(oddv) - maxoddvcnt + len(evenv) - maxevenvcnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
if len(set(v)) == 1:
  print(n//2)
  exit()
oddv = v[::2]
oddvcnts = {}
evenv = v[1::2]
evenvcnts = {}
for vi in oddv:
  oddvcnts[vi] = oddvcnts.get(vi, 0) + 1
for vi in evenv:
  evenvcnts[vi] = evenvcnts.get(vi, 0) + 1
maxoddcnt = max(list(oddvcnts.values()))
maxevencnt = max(list(evenvcnts.values()))
# print(oddv, evenv, maxoddcnt, maxevencnt)
print(len(oddv) - maxoddcnt + len(evenv) - maxevencnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()
    if a[0][0] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] < b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        elif a[0][1] > b[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
        elif a[0][1] == b[0][1]:
            if len(a) != 1 and len(b) != 1:
                if a[1][1] > b[1][1]:
                    print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
                elif a[1][1] < b[1][1]:
                    print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
            elif len(a) != 1:
                print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
            elif len(b) != 1:
                print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()
    if a[0][0] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] < b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        elif a[0][1] > b[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
        elif a[0][1] == b[0][1]:
            if len(a) != 1:
                print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
            elif len(b) != 1:
                print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()
    print(a)
    print(b)
    if a[0][0] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] < b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        elif a[0][1] > b[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
        elif a[0][1] == b[0][1]:
            if len(a) != 1:
                print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
            elif len(b) != 1:
                print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0][0] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] < b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        if b[0][1] < a[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0][0] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] > b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        if b[0][1] > a[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0][1] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] > b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        if b[0][1] > a[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0][1] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] < b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        if b[0][1] < a[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0] != b[0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[1] < b[1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        if b[1] < a[1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0] != b[0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[1] < b[1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        if b[1] > a[1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()

    if a[0] != b[0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[1] > b[1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        if b[1] > a[1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()[0][1]
    b = Counter(v[1::2]).most_common()[0][1]

    print((len(v[0::2]) - a) + (len(v[1::2]) - b))
else:
    print(len(v[1::2]))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda  x:x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda  x:x[1], reverse=True)

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
elif len(even_idx_cnt) == 1:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
elif len(odd_idx_cnt) == 1:
    print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
else:
    if even_idx_cnt[1][0] > odd_idx_cnt[1][0]:
        print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
    else:
        print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda  x:x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda  x:x[1], reverse=True)

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
elif len(even_idx_cnt) == 1:
    print(min(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1], N - odd_idx_cnt[0][1]))
elif len(odd_idx_cnt) == 1:
    print(min(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1], N - even_idx_cnt[0][1]))
else:
    if even_idx_cnt[1][0] > odd_idx_cnt[1][0]:
        print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
    else:
        print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda  x:x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda  x:x[1], reverse=True)

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
elif len(even_idx_cnt) == 1:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
elif len(odd_idx_cnt) == 1:
    print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
else:
    if even_idx_cnt[1][0] > odd_idx_cnt[1][0]:
        print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
    else:
        print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda x: x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda x: x[1], reverse=True)

ans = [N - even_idx_cnt[0][1] - odd_idx_cnt[0][1]]
if len(odd_idx_cnt) >= 2:
    ans.append(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
if len(even_idx_cnt) >= 2:
    ans.append(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])
if len(odd_idx_cnt) >= 2 and len(even_idx_cnt) >= 2:
    ans.append(N - even_idx_cnt[1][1] - odd_idx_cnt[1][1])
print(min(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))

even_idx_cnt = {}
odd_idx_cnt = {}
for idx, v in enumerate(V):
    if idx % 2 == 0:
        if v not in even_idx_cnt:
            even_idx_cnt[v] = 0
        even_idx_cnt[v] += 1
    else:
        if v not in odd_idx_cnt:
            odd_idx_cnt[v] = 0
        odd_idx_cnt[v] += 1

if len(even_idx_cnt) == 1 and len(odd_idx_cnt) == 1:
    if even_idx_cnt.keys() == odd_idx_cnt.keys():
        print(N - even_idx_cnt[V[0]])
    else:
        print(0)
    exit()

even_idx_cnt = sorted(even_idx_cnt.items(), key=lambda  x:x[1], reverse=True)
odd_idx_cnt = sorted(odd_idx_cnt.items(), key=lambda  x:x[1], reverse=True)

if even_idx_cnt[0][0] != odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[0][1])
elif even_idx_cnt[0][0] > odd_idx_cnt[0][0]:
    print(N - even_idx_cnt[0][1] - odd_idx_cnt[1][1])
else:
    print(N - even_idx_cnt[1][1] - odd_idx_cnt[0][1])

Submission status: Wrong Answer

Solution code:
from collections  import Counter
n = int(input())
l = [int(i) for i in input().split()]
 
l1 = [l[i] for i in range(n) if i%2 ==0]
l2 = [l[i] for i in range(n) if i%2 ==1]
 
c1 = Counter(l1)
c2 = Counter(l2)

change1 = n//2 - c1.most_common()[0][1]
change2 = n//2 - c2.most_common()[0][1]

if c1.most_common()[0][0] == c2.most_common()[0][0] and change1 == change2:
    print(change1 + n//2)
else:
    print(change1 + change2)

Submission status: Wrong Answer

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

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []


for i in range(10**5+1):
    if dic0[i] == MX0_1:
        li0.append(i)
        dic0[i] = 0
    if dic1[i] == MX1_1:
        li1.append(i)
        dic1[i] = 0

if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0[0] == li1[0]:
    if MX0_1+max(dic1) >= MX1_1+max(dic0):
        print(n-MX0_1-max(dic1))
    else:
        print(MX1_1+max(dic0))

elif li0[0] != li1[0]:
    print(n-MX0_1-MX1_1)

Submission status: Wrong Answer

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

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []


for i in range(10**5+1):
    if dic0[i] == MX0_1:
        li0.append(i)
        dic0[i] = 0
    if dic1[i] == MX1_1:
        li1.append(i)
        dic1[i] = 0

print(li0,li1)
print(MX0_1,MX1_1)


if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0[0] == li1[0]:
    if MX0_1+max(dic1) >= MX1_1+max(dic0):
        print(n-MX0_1-max(dic1))
    else:
        print(MX1_1+max(dic0))

elif li0[0] != li1[0]:
    print(n-MX0_1-MX1_1)

Submission status: Wrong Answer

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

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []

for i in range(10**5+1):
    if dic0[i] == MX0_1:
        li0.append(i)
        dic0[i] = 0
    if dic1[i] == MX1_1:
        li1.append(i)
        dic1[i] = 0

if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0[0] == li1[0]:
    if MX0_1 >= MX1_1:
        MX1_1 = max(dic1)
        print(n-MX0_1-MX1_1)
    else:
        MX0_1 = max(dic0)
        print(n-MX0_1-MX1_1)

elif li0[0] != li1[0]:
    print(n-MX0_1-MX1_1)

Submission status: Wrong Answer

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

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []

for i in range(len(dic0)):
    if dic0[i] == MX0_1:
        li0.append(i)
        dic0[i] = 0
    if dic1[i] == MX1_1:
        li1.append(i)
        dic1[i] = 0

if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0 == li1:
    if MX0_1 >= MX1_1:
        MX1_1 = max(dic1)
        print(n-MX0_1-MX1_1)
    else:
        MX0_1 = max(dic0)
        print(n-MX0_1-MX1_1)

elif li0 != li1:
    print(n-MX0_1-MX1_1)

Submission status: Wrong Answer

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

dic0 = [0 for i in range(10**5+1)]
dic1 = [0 for i in range(10**5+1)]
for i in range(n):
    if i%2==0:    
        dic0[v[i]] += 1
    if i%2==1:
        dic1[v[i]] += 1

MX0_1 = max(dic0)
MX1_1 = max(dic1)

li0 = []
li1 = []

for i in range(len(dic0)):
    if dic0[i] == MX0_1:
        li0.append(i)
    if dic1[i] == MX1_1:
        li1.append(i)

if len(li0)>=2 or len(li1)>=2:
    print(n-MX0_1-MX1_1)
elif li0 != li1:
    if MX0_1 >= MX1_1:
        pass

    else:
        pass

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
ans = 0
f,s = [],[]
count = 0
for i in map(int,input().split()):
    if count%2 == 0:
        f.append(i)
    else:
        s.append(i)
    count += 1
c1,c2 = Counter(f),Counter(s)
a,b = [],[]
for i in c1.keys():
    a.append([i,c1[i]])
for j in c2.keys():
    b.append([j,c2[j]])
a = sorted(a,key=lambda x: x[1],reverse = True)
b = sorted(b,key=lambda x: x[1],reverse = True)
"""
if a[0][0] == b[0][0]:
    if a[0][1] >= b[0][1]:
        if len(b) == 1:
            print(n-a[0][1])
        else:
            print(n-a[0][1]-b[1][1])
    else:
        if len(a) == 1:
            print(n-b[0][1])
        else:
            print(n-a[1][1]-b[0][1])
else:
"""
print(n-a[0][1]-b[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
ans = 0
f,s = [],[]
count = 0
for i in map(int,input().split()):
    if count%2 == 0:
        f.append(i)
    else:
        s.append(i)
    count += 1
c1,c2 = Counter(f),Counter(s)
a,b = [],[]
for i in c1.keys():
    a.append([i,c1[i]])
for j in c2.keys():
    b.append([j,c2[j]])
a = sorted(a,key=lambda x: x[1],reverse = True)
b = sorted(b,key=lambda x: x[1],reverse = True)
if a[0][0] == b[0][0]:
    if a[0][1] >= b[0][1]:
        if len(b) == 1:
            print(n-a[0][1])
        else:
            print(n-a[0][1]-b[1][1])
    else:
        if len(a) == 1:
            print(n-b[0][1])
        else:
            print(n-a[1][1]-b[0][1])
else:
    print(n-a[0][1]-b[0][1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter



def main():
    N = int(input())
    V = [int(x) for x in input().split()]

    a = []
    b = []
    for i in range(N):
        if i & 1:
            a.append(V[i])
        else:
            b.append(V[i])

    ac = Counter(a)
    bc = Counter(b)

    acm = ac.most_common()
    bcm = bc.most_common()

    if acm[0][0] != bcm[0][0]:
        print(N // 2 - acm[0][1] + N // 2 - bcm[0][1])
    else:
        ans = N // 2
        for i in acm:
            if i[0] == bcm[0][0]:
                continue
            ans = min(ans, N // 2 - i[1] + N // 2 - bcm[0][1])

        for j in bcm:
            if acm[0][0] == j[0]:
                continue
            ans = min(ans, N // 2 - j[1] + N // 2 - acm[0][1])
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter



def main():
    N = int(input())
    V = [int(x) for x in input().split()]

    a = []
    b = []
    for i in range(N):
        if i & 1:
            a.append(V[i])
        else:
            b.append(V[i])

    ac = Counter(a)
    bc = Counter(b)

    acm = ac.most_common()
    bcm = bc.most_common()

    ans = N // 2
    for i in acm:
        for j in bcm:
            if i[0] == j[0]:
                continue
            ans = min(ans, N // 2 - i[1] + N // 2 - j[1])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter



def main():
    N = int(input())
    V = [int(x) for x in input().split()]

    a = []
    b = []
    for i in range(N):
        if i & 1:
            a.append(V[i])
        else:
            b.append(V[i])

    ac = Counter(a)
    bc = Counter(b)

    ans = N // 2
    for i in ac.keys():
        for j in bc.keys():
            if i == j:
                continue
            ans = min(ans, N // 2 - ac[i] + N // 2 - bc[j])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
C=Counter(V).most_common()
y=len(set(C))
if y==1:
    print(n//2)
elif y==2: 
    print((C[0][1]-C[1][1])//2)
else:
    if C[0][1]<=n//2:
        print(n-C[0][1]-C[1][1])
    else:
        print(n//2-C[1][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
C=Counter(V).most_common()
y=len(set(C))
if y==1:
    print(n//2)
else:
    print(n-C[0][1]-C[1][1])

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [i for i in map(int,input().split())]
v_odd = v[::2]
v_even = v[1::2]
odd_nums = (collections.Counter(v_odd)).most_common()
even_nums = (collections.Counter(v_even)).most_common()
ans = 0
if odd_nums[0][0] != even_nums[0][0]: # 最頻出数値が等しくない場合
  for i in range(1,len(odd_nums)):
    ans += odd_nums[i][1]
  for i in range(1,len(even_nums)):
    ans += even_nums[i][1]
else: # 最頻出数値が等しい場合
  ans += min(even_nums[0][1], odd_nums[0][1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [i for i in map(int,input().split())]
v_odd = v[::2]
v_even = v[1::2]
odd_nums = (collections.Counter(v_odd)).most_common()
even_nums = (collections.Counter(v_even)).most_common()
print(odd_nums)
print(even_nums)
ans = 0
if odd_nums[0][0] != even_nums[0][0]: # 最頻出数値が等しくない場合
  for i in range(1,len(odd_nums)):
    ans += odd_nums[i][1]
  for i in range(1,len(even_nums)):
    ans += even_nums[i][1]
else: # 最頻出数値が等しい場合
  ans += min(even_nums[0][1], odd_nums[0][1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = [i for i in map(int,input().split())]
v_odd = v[::2]
v_even = v[1::2]
odd_nums = (collections.Counter(v_odd)).most_common()
even_nums = (collections.Counter(v_even)).most_common()
ans = 0
if odd_nums[0][0] != even_nums[0][0]: # 最頻出数値が等しくない場合
  for i in range(1,len(odd_nums)):
    ans += odd_nums[i][1]
  for i in range(1,len(even_nums)):
    ans += even_nums[i][1]
else: # 最頻出数値が等しい場合
  if len(odd_nums) == 1 and len(even_nums) == 1: # どちらも1種類のみ
    ans += odd_nums[0][1]
  elif len(odd_nums) == 1:
    ans += even_nums[0][1]
  elif len(even_nums) == 1:
    ans += odd_nums[0][1]
  else:
    ans += min(even_nums[0][1], odd_nums[0][1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))

V1 = V[0::2]
V2 = V[1::2]

import collections

def count_change(V):
    res = collections.Counter(V)
    if len(res) == 1:
        return(0)
    else:
        return len(V) - max(res.values())

if len(set(V)) == 1:
    print(int(len(V)/2))
else:
    print(count_change(V1) + count_change(V2))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))

V1 = V[0::2]
V2 = V[1::2]

import collections

def count_change(V):
    res = collections.Counter(V)
    if len(res) == 1:
        return(0)
    else:
        return min(res.values())

if len(set(V)) == 1:
    print(int(len(V)/2))
else:
    print(count_change(V1) + count_change(V2))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = list(map(int, input().split()))

print(V)

V1 = V[0::2]
V2 = V[1::2]

import collections

def count_change(V):
    res = collections.Counter(V)
    if len(res) == 1:
        return(0)
    else:
        return min(res.values())

if len(set(V)) == 1:
    print(len(set(V)))
    print("all element is equal")
    print(int(len(V)/2))
else:
    print(count_change(V1) + count_change(V2))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a1=a[::2]
a2=a[1::2]
import collections
c1=collections.Counter(a1)
c2=collections.Counter(a2)
c1=c1.most_common(2)
c2=c2.most_common(2)
if a1==a2 and len(c1)==1 and len(c2)==1:
  print(len(a1))
  exit()
if len(c1)==1 and len(c2)==1:
  print(0)
  exit()
ans=0
if c1[0][0]!=c2[0][0]:
  ans+=n-c1[0][1]-c2[0][1]
else:
  if len(c1)==1:
    ans+=len(a2)-c2[1][1]
  elif len(c2)==1:
    ans+=len(a1)-c1[1][1]
  elif c1[1][1]>=c2[1][1]:
    ans+=len(a1)-c1[0][1]+len(a2)-c2[1][1]
  else:
    ans+=len(a1)-c1[1][1]+len(a2)-c2[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a1=a[::2]
a2=a[1::2]
import collections
c1=collections.Counter(a1)
c2=collections.Counter(a2)
c1=c1.most_common(2)
c2=c2.most_common(2)
if a1==a2:
  print(len(a1))
  exit()
if len(c1)==1 and len(c2)==1:
  print(0)
  exit()
ans=0
if c1[0][0]!=c2[0][0]:
  ans+=n-c1[0][1]-c2[0][1]
else:
  if len(c1)==1:
    ans+=len(a2)-c2[1][1]
  elif len(c2)==1:
    ans+=len(a1)-c1[1][1]
  elif c1[1][1]>=c2[1][1]:
    ans+=len(a1)-c1[0][1]+len(a2)-c2[1][1]
  else:
    ans+=len(a1)-c1[1][1]+len(a2)-c2[0][1]
print(ans)