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 collections

n = int(input())
vs = [int(i) for i in input().split()]
evens = []
odds = []
for i,num in enumerate(vs):
    if i % 2 == 0:
        evens.append(num)
    elif i % 2 == 1:
        odds.append(num)

def plana():
    if (len(set(vs)) == 2) and (len(set(evens)) == 1) and (len(set(odds)) == 1):
        return 0
    elif (len(set(vs)) == 1):
        return len(evens)
    ec = collections.Counter(evens)
    oc = collections.Counter(odds)

    # check
    if ec.most_common()[0][0] == oc.most_common()[0][0]:
        if ec.most_common()[0][1] >= oc.most_common()[0][1]:
            count = 0
            count += (len(evens) - ec.most_common()[0][1])
            count += (len(odds) - oc.most_common()[1][1])
            return count
        elif ec.most_common()[0][1] < oc.most_common()[0][1]:
            count = 0
            count += (len(evens) - ec.most_common()[1][1])
            count += (len(odds) - oc.most_common()[0][1])
            return count

    count = 0
    count += (len(evens) - ec.most_common()[0][1])
    count += (len(odds) - oc.most_common()[0][1])
    return count

print(int(plana()))

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])
    if 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)
        if len(g) != 0 and len(k) == 0:
            print(g_max)
        if len(g) == 0 and len(k) != 0:
            print(g_max)
        if len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            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 - g[g_max] - 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 = list(map(int,input().split()))
v_o = []
v_e = []
ans = 0

if len(Counter(v)) == 1:
    ans = len(v)//2
else:
    for i in range(len(v)):
        if (i+1)%2==1:
            v_o.append(v[i])
        else:
            v_e.append(v[i])

    o_values = list(Counter(v_o).values())
    o_values = sorted(o_values)
    e_values = list(Counter(v_e).values())
    e_values = sorted(e_values)

    for o in range(len(o_values)):
        ans += o_values[o]
    ans = ans - o_values[0]

    for e in range(len(e_values)):
        ans += e_values[e]
    ans = ans - e_values[0]

print(ans)

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

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 == 1 and pattern1 != num:
            pattern2 = num
        elif i % 2 == 0:
            if pattern1 != num:
                cnt += 1
        elif i % 2 == 1:
            if 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:
import collections
n = int(input())
v = list(map(int,input().split()))

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

v1 = v[::2]
cv1 = collections.Counter(v1)
v2 = v[1::2]
cv2 = collections.Counter(v2)
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:
  temp1 = cv1.most_common()[0][1]
  temp2 = cv2.most_common()[0][1]
  if temp1>temp2:
    cnt2 = cv2.most_common()[0][1]
  else:
    cnt1 = cv1.most_common()[0][1]

print((len(v1)+len(v2))-(cnt1+cnt2))

Submission status: Wrong Answer

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

a = []
b = []

a_dic = {}
b_dic = {}

for i in range(n):
    if i % 2 == 0:
        if v[i] in a_dic.keys():
            a_dic[v[i]] += 1
        else:
            a_dic[v[i]] = 1
    else:
        if v[i] in b_dic.keys():
            b_dic[v[i]] += 1
        else:
            b_dic[v[i]] = 1

max_a = 0
max_b = 0

for val in a_dic.values():
    if val > max_a:
        max_a = val

for val in b_dic.values():
    if val > max_b:
        max_b = val

ans = (int(n / 2) - max_a) + (int(n / 2) - max_b)

if (len(a_dic) == 1 and len(b_dic) == 1) and a_dic.keys() ==  b_dic.keys():
    print(int(n / 2))
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]

o=[]
e=[]


for i in range(n):
    if i%2==1:
        o.append(a[i])
    else:
        e.append(a[i])

oc = Counter(o)
ec = Counter(e)

ok=[]
ek=[]
ol=[]
el=[]
for word, cnt in oc.most_common():
    ok.append(cnt)
    ol.append(word)
for word, cnt in ec.most_common():
    ek.append(cnt)
    el.append(word)

if len(ok)==1:
    ok.append(0)
if len(ek)==1:
    ek.append(0)
if el[0]!=ol[0]:
    print(n-ok[0]-ek[0])
else:
    m=max(ok[0],ek[0])
    if m==ok[0]:
        print(n-m-ek[1])
    else:
        print(n-m-ok[1])

Submission status: Wrong Answer

Solution code:
import collections


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

gusuList=[]
kisuList=[]

for i in range(n):
  if(i % 2==0):
    gusuList.append(vList[i])
  else:
    kisuList.append(vList[i])
#print(gusuList)
#print(kisuList)

g = collections.Counter(gusuList)
gStatus=g.most_common()

k = collections.Counter(kisuList)
kStatus=k.most_common()

ans=-100
if(not gStatus[0][0]==kStatus[0][0]):
    ans=(n/2-gStatus[0][1])+(n/2-kStatus[0][1])
else:
  if(gStatus[0][1]>=kStatus[0][1]):
    if(not len(kStatus)==1):
      ans=(n/2-gStatus[0][1])+(n/2-kStatus[1][1])
    else:
      ans=(n/2-gStatus[0][1])+n/2
  else:
    if(not len(gStatus)==1):
      ans=(n/2-gStatus[1][1])+(n/2-kStatus[0][1])
    else:
      ans=n/2+(n/2-kStatus[0][1])

print(int(ans))

Submission status: Wrong Answer

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

odd = list()
even = list()

for i in range(n):
    if i%2 == 1:
        odd.append(v[i])
    else:
        even.append(v[i])

odd.sort()
even.sort()

o = 0
ob = 0
e = 0
eb = 0

onum = int()
onumb = int()
enum = int()
enumb = int()

for i in range(int(n/2)):
    if odd.count(odd[i]) > o:
        ob = o
        o = odd.count(odd[i])
        onumb = onum
        onum = odd[i]
    if even.count(even[i]) > e:
        eb = e
        e = even.count(even[i])
        enumb = enum
        enum = even[i]
else:
    #print(odd)
    #print(o)
    if o == n/2 and e == n/2:
        print(0)
        exit()
    if onum == enum:
        if ob + e > o + eb:
            print(n-(ob+e))
        else:
            print(n-(o+eb))
    else:
        print(n-(o+e))

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])
    if 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)
        if len(g) != 0 and len(k) == 0:
            print(n - g_max - max([(v,k) for k,v in g.items()])[1])
        if len(g) == 0 and len(k) != 0:
            print(n - k_max - max([(v,k) for k,v in k.items()])[1])
        if len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            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 - g[g_max] - k[k_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
import collections

n = int(raw_input())
v = map(int, raw_input().split())

even = [vi for i,vi in enumerate(v) if i % 2 == 0]
odd  = [vi for i,vi in enumerate(v) if i % 2 == 1]

evenc = collections.Counter(even)
oddc = collections.Counter(odd)

evenc_most_common = evenc.most_common(len(set(even)))
oddc_most_common = oddc.most_common(len(set(odd)))

# print(evenc_most_common)
# print(oddc_most_common)

if evenc_most_common[0][0] != oddc_most_common[0][0]:
    a = len(even) - evenc_most_common[0][1]
    b = len(odd) - oddc_most_common[0][1]
    print(a+b)
else:
    if evenc_most_common[0][1] >= oddc_most_common[0][1]:
        a = len(even) - evenc_most_common[0][1]
        b = len(odd)
        if len(oddc_most_common) > 1:
            b = len(odd) - oddc_most_common[1][1]
        print(a+b)
    elif evenc_most_common[0][1] < oddc_most_common[0][1]:
        a = len(odd) - oddc_most_common[0][1]
        b = len(even)
        if len(evenc_most_common) > 1:
            b = len(even) - evenc_most_common[1][1]
        print(a+b)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
odd_list = v[1::2]  # 偶数番目
even_list = v[::2]  # 奇数番目

odd_list_len = len(odd_list)
even_list_len = len(even_list)

odd_mode = Counter(odd_list).most_common(1)
even_mode = Counter(even_list).most_common(1)

ans = 0

if odd_mode > even_mode:
    ans += odd_list_len - odd_mode[0][1]
    if odd_mode[0] != even_mode[0]:
        ans += even_list_len - even_mode[0][1]
    else:
        if len(Counter(even_list).most_common(2)) == 2:
            ans += even_list_len - Counter(even_list).most_common(2)[1][1]
        else:
            ans += even_list_len
else:
    ans += even_list_len - even_mode[0][1]
    if even_mode[0] != odd_mode[0]:
        ans += odd_list_len - odd_mode[0][1]
    else:
        if len(Counter(odd_list).most_common(2)) == 2:
            ans += odd_list_len - Counter(odd_list).most_common(2)[1][1]
        else:
            ans += odd_list_len
print(ans)

Submission status: Wrong Answer

Solution code:
import operator

n=int(input().strip())
lst=input().split(' ')
map(int, lst)

d1 = {}
d2 = {}

for i in range(len(lst)):
    if i % 2 == 0:
        if lst[i] in d1:
            d1[lst[i]] += 1
        else:
            d1[lst[i]] = 1
    else:
        if lst[i] in d2:
            d2[lst[i]] += 1
        else:
            d2[lst[i]] = 1

key1 = max(d1.items(), key=operator.itemgetter(1))[0]
key2 = max(d2.items(), key=operator.itemgetter(1))[0]

sorted1 = sorted(((v,k) for k,v in d1.items()))

if(key1 == key2):
    #print(n/2-d2[key2]+n/2-max(sorted(d1.values(), reverse=True)[1],sorted(d2.values(), reverse=True)[1]))
    toret = 0
    while(key1 != None and key2 != None and d1[key1]== d2[key2]):
        toret += d1[key1]
        d1.pop(key1)
        d2.pop(key2)

        if(len(d1) == 0 or len(d2) == 0):
            break
        key1 = max(d1.items(), key=operator.itemgetter(1))[0]
        key2 = max(d2.items(), key=operator.itemgetter(1))[0]

    s = 0
    if(len(d1) != 0):
        s = sum(d1.values())

    m = 0
    if key1 in d1 and key2 in d2:
        m = min(d1[key1],d2[key2])
    elif key1 not in d1 and key2 in d2:
        m = d2[key2]
    elif key1 in d1 and key2 not in d2:
        m = d1[key1]


    print(int(toret + m + s))

else:
    print(n-d1[key1]-d2[key2])

Submission status: Wrong Answer

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

dd_even = defaultdict(int)
dd_odd  = defaultdict(int)

# 偶数番目のヒストグラムを作る
for i in range(0, n, 2):
    dd_even[v[i]] += 1

l_even = list(dd_even.items())
l_even.sort(key= lambda x:x[1])
top_even = l_even[-1][0]
#print(l_even)

# 奇数番目のヒストグラムを作る
for i in range(1, n, 2):
    dd_odd[v[i]] += 1

l_odd = list(dd_odd.items())
l_odd.sort(key= lambda x:x[1])
#print(l_odd)
top_odd = l_odd[-1][0]

if top_even == top_odd:
    if len(l_odd) == 1: # つまり全部同じ数字のとき
        res = int(n / 2)
        print(res)
        sys.exit()
    else:
        l_odd = [l for l in l_odd if l[0] != l_odd[-2][0]]
else:
    l_odd = [l for l in l_odd if l[0] != top_odd]

sum_odd = sum(l[1] for l in l_odd)
#print(l_odd, sum_odd)

l_even = [l for l in l_even if l[0] != top_even]
sum_even = sum(l[1] for l in l_even)
#print(l_even, sum_even)

res = sum_odd + sum_even
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
if len(set(a)) == 1:
    print(n//2)
    exit()
if a[0] == a[1]:
    for i in range(2,n,2):
        if a[i] != a[0]:
            cnt += 1
    for i in range(3,n,2):
        if a[i] != a[1]:
            cnt += 1
    print(cnt+1)
    exit()
for i in range(2,n,2):
    if a[i] != a[0]:
        cnt += 1
for i in range(3,n,2):
    if a[i] != a[1]:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def c_zigzag(N, V):
    from collections import defaultdict
    count_seq_even = defaultdict(int)
    count_seq_odd = defaultdict(int)
    for v in V[0:N - 1:2]:
        count_seq_even[v] += 1
    for v in V[1:N:2]:
        count_seq_odd[v] += 1

    count_seq_even_s = sorted(count_seq_even.items(), key=lambda x: x[1], reverse=True)
    count_seq_odd_s = sorted(count_seq_odd.items(), key=lambda x: x[1], reverse=True)

    seq_even_select = []
    max_seq_appear_even = count_seq_even_s[0][1]
    for k, v in count_seq_even_s:
        if v < max_seq_appear_even:
            break
        seq_even_select.append(k)
    seq_odd_select = []
    max_seq_appear_odd = count_seq_odd_s[0][1]
    for k, v in count_seq_odd_s:
        if v < max_seq_appear_odd:
            break
        seq_odd_select.append(k)
    ans = float('inf')
    for e in seq_even_select:
        for o in seq_odd_select:
            if e == o:
                ans = min(ans, N - count_seq_even[e] - count_seq_odd[-1])
                ans = min(ans, N - count_seq_even[-1] - count_seq_odd[o])
                continue
            ans = min(ans, N - count_seq_even[e] - count_seq_odd[o])

    return ans

N = int(input())
V = [int(i) for i in input().split()]
print(c_zigzag(N,V))

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
A = []
B = []
Q = [0,0]
R = [0,0]
S = [0,0]
T = [0,0]
J = 1
K = 1
for i in range(n):
  if (i%2 == 0):
    A.append(L[i])
  else:
    B.append(L[i])
A.sort()
B.sort()
A.append(-1)
B.append(-1)
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J > Q[0]):
      Q[1] = Q[0]
      del Q[0]
      Q.insert(0,J)
      R[1] = R[0]
      del R[0]
      R.insert(0,A[j-1])
      j += J
      J = 1
    elif (Q[0] >= J >= Q[1]):
      del Q[1]
      Q.append(J)
      del R[1]
      R.append(A[j-1])
      j += J
      J = 1
    else:
      j += J
      J = 1
for k in range(1,len(B)):
  if (B[k-1] == B[k]):
    K += 1
  else:
    if (K > S[0]):
      S[1] = S[0]
      del S[0]
      S.insert(0,K)
      T[1] = T[0]
      del T[0]
      T.insert(0,B[k-1])
      k += K
      K = 1
    elif (S[0] >= J >= S[1]):
      del S[1]
      S.append(K)
      del T[1]
      T.append(B[k-1])
      k += K
      K = 1
    else:
      k += K
      K = 1
if (R[0] != T[0]):
  print(n-Q[0]-S[0])
else:
  if (Q[0] >= S[0]):
    print(n-Q[0]-S[1])
  else:
    print(n-S[0]-Q[1])

Submission status: Wrong Answer

Solution code:
n=int(input())
v=input().split()
vodd=[]
veven=[]
for i in range(n):
    if i%2:
        veven.append(int(v[i]))
    else:
        vodd.append(int(v[i]))

changeCnt=0

voddNum=[vodd[0]]
voddCnt=[0]
j=0
for i,odd in enumerate(vodd):
    if voddNum[j]!=odd:
        for k,num in enumerate(voddNum):
            if num==odd:
                j=k
                break
        else:
            j=k+1
            voddNum.append(odd)
            voddCnt.append(0)
            
    voddCnt[j]+=1
'''
print(vodd)
print(voddNum)
print(voddCnt)
'''
oddMax=0
maxIndex=0
if len(voddNum)!=1:
    for i,num in enumerate(voddNum):
        if oddMax<num:
            oddMax=num
            maxIndex=i
            
    changeCnt+=len(voddNum)-voddCnt[maxIndex]


vevenNum=[veven[0]]
vevenCnt=[0]
j=0
for i,even in enumerate(veven):
    if vevenNum[j]!=even:
        for k,num in enumerate(vevenNum):
            if num==even:
                j=k
                break
        else:
            j=k+1
            vevenNum.append(even)
            vevenCnt.append(0)

    vevenCnt[j]+=1
'''
print()
print(veven)
print(vevenNum)
print(vevenCnt)
'''
evenMax=0
maxIndex=0
if len(vevenNum)!=1:
    for i,num in enumerate(vevenNum):
        if evenMax<num:
            evenMax=num
            maxIndex=i
            
    changeCnt+=len(vevenNum)-vevenCnt[maxIndex]

if changeCnt==0:
   if voddNum[0]==vevenNum[0]:
      changeCnt+=voddCnt[0]
    
print(changeCnt)

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]==v2[0]:
            print(v1[0][1])
        else:
            print(0)
    else:
        print(min(v1,v2)[0][1])
else:
    c = 0
    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())

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

b=A[0::2]
c=A[1::2]

d = collections.Counter(b)
values, counts = zip(*d.most_common())
bA = values
bB = counts
bA=list(bA)
bB=list(bB)
bB.append(0)

e = collections.Counter(c)
values, counts = zip(*e.most_common())
cA = values
cB = counts
cA=list(cA)
cB=list(cB)
cB.append(0)

ans =0

if bA[0] == cA[0]:
    if bB[0] >=cB[0]:
        ans += N - bB[0] - cB[1]
    else:
        ans += N - bB[1] - cB[0]
else:
    ans += N - bB[0] - cB[0]

print(ans)

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])
    if 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)
        if len(g) != 0 and len(k) == 0:
            print(n - g_max - max([(v,k) for k,v in g.items()])[1])
        if len(g) == 0 and len(k) != 0:
            print(n - k_max - max([(v,k) for k,v in k.items()])[1])
        if len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            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 - g[g_max] - (n - k[k_max]))
            elif g[g_max] < k[k_max]:
                print(N - (n - g[g_max]) - k[k_max])
            else:
                print(N - g[g_max] - k[k_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
import collections as cole


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

v1 = v[::2]   #odd
v2 = v[1::2]  #even

d1 = cole.Counter(v1)
d2 = cole.Counter(v2)

values1, counts1 = zip(*d1.most_common())
values2, counts2 = zip(*d2.most_common())

max1 = values1[0]
max2 = values2[0]

if max1 == max2:
    if len(counts1) != 1 and counts1[0] == counts1[1]:
        max1 = values1[1]
    elif len(counts2) != 1 and counts2[0] == counts2[1]:
        max2 = values1[1]
    elif len(counts1) != 1 and len(counts2) != 1:
        if counts1[1] > counts2[1]:
            max1 = values1[1]
        else:
            max2 = values2[1]
    elif len(counts1) != 1:
        max1 = values1[1]
    elif len(counts2) != 1:
        max2 = values2[1]


count = 0
if max1 != max2:
    count += len([x for x in v1 if x != max1])
    count += len([y for y in v2 if y != max2])

else:
    count += len(v1)


print(count)

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
    else:
        cc[b[i]] += 1

one = 0
onee = 0
two = 0
twoo = 0
p = 0
pp = 0
for i in range(d+1):
    if one <= c[i]:
        onee = one
        one = c[i]
        p += 1
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        p += 1
    if p == 2:
        pp = 1
    else:
        pp = 0
    p = 0

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

if pp == 0:
    print(a-one-two)
else:
    print(a-t)

Submission status: Wrong Answer

Solution code:
import sys
a=int(input())
b=input()
c=b.split(" ")
map(int,c)
min1=0

for x in range(len(c)-2):
    if c[x] != c[x+2]:
        min1=min1+1
print(min1)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v_o = []
v_e = []
ans = 0

if len(Counter(v)) == 1:
    ans = len(v)//2

for i in range(len(v)):
    if (i+1)%2==1:
        v_o.append(v[i])
    else:
        v_e.append(v[i])

o_values = list(Counter(v_o).values())
e_values = list(Counter(v_e).values())

for o in range(len(o_values)):
    ans += o_values[o]
ans = ans - o_values[0]

for e in range(len(e_values)):
    ans += e_values[e]
ans = ans - e_values[0]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
A = []
B = []
Q = [0,0]
R = [0,0]
S = [0,0]
T = [0,0]
J = 1
K = 1
for i in range(n):
  if (i%2 == 0):
    A.append(L[i])
  else:
    B.append(L[i])
A.sort()
B.sort()
A.append(-1)
B.append(-1)
for j in range(1,len(A)):
  if (A[j-1] == A[j]):
    J += 1
  else:
    if (J > Q[0]):
      Q[1] = Q[0]
      del Q[0]
      Q.insert(0,J)
      del R[0]
      R.insert(0,A[j-1])
      j += J
      J = 1
    elif (Q[0] >= J >= Q[1]):
      del Q[1]
      Q.append(J)
      del R[1]
      R.append(A[j-1])
      j += J
      J = 1
    else:
      j += J
      J = 1
for k in range(1,len(B)):
  if (B[k-1] == B[k]):
    K += 1
  else:
    if (K > S[0]):
      S[1] = S[0]
      del S[0]
      S.insert(0,K)
      del T[0]
      T.insert(0,B[k-1])
      k += K
      K = 1
    elif (S[0] >= J >= S[1]):
      del S[1]
      S.append(K)
      del T[1]
      T.append(B[k-1])
      k += K
      K = 1
    else:
      k += K
      K = 1
if (R[0] != T[0]):
  print(n-Q[0]-S[0])
else:
  if (Q[0] >= S[0]):
    print(n-Q[0]-S[1])
  else:
    print(n-S[0]-Q[1])

Submission status: Wrong Answer

Solution code:
import collections
n=input()
N=list(map(int,input().split(" ")))
list_odd=N[::2]
list_even=N[1::2]
c_odd = collections.Counter(list_odd)
c_even = collections.Counter(list_even)
most_odd=c_odd.most_common()[0][1]
most_even=c_even.most_common()[0][1]
if(len(list_even)==most_even and len(list_odd)==most_odd):
    print("0")
else:
    print(len(list_even)+len(list_odd)-most_even-most_odd)
#c_odd.most_common()[0][0]==c_even.most_common()[0][0]

Submission status: Wrong Answer

Solution code:
n = int(input())
v = [int(i) for i in input().split()] 
lv0 = []
dv0 = {}
lv1 = []
dv1 = {}

for i,x in enumerate(v):
    if i%2 == 0:
        if x not in lv0:
            lv0.append(x)
            dv0[x] = 1
        else:
            #lv0.append(x)
            dv0[x] += 1
    else:
        if x not in lv1:
            lv1.append(x)
            dv1[x] = 1
        else:
            #lv1.append(x)
            dv1[x] += 1

#print("lv0 : {}".format(lv0))
#print("lv1 : {}".format(lv1))
#print("dv0 : {}".format(dv0))
#print("dv1 : {}".format(dv1))

v0_m = [1]
v0_n = [0,0]
v1_m = [1]
v1_n = [0,0]

for x in lv0:
    if dv0[x] > v0_m[0]:
        v0_m = [dv0[x]]
        v0_m.append(x)
    if dv0[x] == v0_m[0]:
        v0_m.append(x)
    if (dv0[x] < v0_m[0]) and (dv0[x] > v0_n[0]):
        v0_n = [dv0[x]]
        v0_n.append(x)
    if dv0[x] == v0_n[0]:
        v0_n.append(x)

for x in lv1: 
    if dv1[x] > v1_m[0]:
        v1_m = [dv1[x]]
        v1_m.append(x)
    if dv1[x] == v1_m[0]:
        v1_m.append(x)
    if (dv1[x] < v1_m[0]) and (dv1[x] > v1_n[0]):
        v1_n = [dv1[x]]
        v1_n.append(x)
    if dv1[x] == v1_n[0]:
        v1_n.append(x)
    
    #print(i)
    #print(" v0_m : {}".format(v0_m))
    #print(" v0_n : {}".format(v0_n))
    #print(" v1_m : {}".format(v1_m))
    #print(" v1_n : {}".format(v1_n))

ans = n-v0_m[0]-v1_m[0]
if v0_m[0] == v1_m[0]:
    #print("Check")
    count = 0
    for i in range(1,len(v0_m)):
        if v0_m[i] in v1_m[1:]:
            count += 1
    #print(count)
    if count == (len(v0_m)-1):
        #print("Check2")
        ans = n-v0_n[0]-v1_m[0]
print(ans)

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])
    if 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)
        if len(g) != 0 and len(k) == 0:
            print(n - g_max - max([(v,k) for k,v in g.items()])[1])
        if len(g) == 0 and len(k) != 0:
            print(n - k_max - max([(v,k) for k,v in k.items()])[1])
        if len(g) != 0 and len(k) != 0:
            g_temp = g_max
            k_temp = k_max
            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 - g[g_max] - (n - k[k_max]))
            elif g[g_max] < k[k_max]:
                print(N - (n - g[g_max]) - k[k_max])
            else:
                print(N - g_temp - k[k_max])
else:
    print(N - g[g_max] - k[k_max])

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(V):
    odd = Counter()
    even = Counter()
    for i, c in enumerate(V):
        if i % 2 == 0:
            even.update([c])
        else:
            odd.update([c])
    even_maxs = even.most_common(2)
    odd_maxs = odd.most_common(2)
    if len(odd_maxs) > 1:
        odd_max, odd_2nd_max = odd_maxs[0], odd_maxs[1]
    else:
        odd_max, odd_2nd_max = odd_maxs[0], None

    if len(even_maxs) > 1:
        even_max, even_2nd_max = even_maxs[0], even_maxs[1]
    else:
        even_max, even_2nd_max = even_maxs[0], None

    ans = 0
    if odd_max[0] != even_max[0]:
        odd_max = odd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max != None and even_2nd_max == None:
        even_max = even_max[0]
        odd_max = odd_2nd_max[0]
    elif odd_2nd_max == None and even_2nd_max != None:
        odd_max = odd_max[0]
        even_max = even_2nd_max[0]
    elif odd_2nd_max == None and even_2nd_max == None:
        odd_max = odd_max[0]
        even_max = even_max[0] + even_max[0]
    else: # odd_2nd_max != None and even_2nd_max != None:
        if odd_max[0] != even_2nd_max[0]:
            odd_max = odd_max[0]
            even_max = even_2nd_max[0]
        elif odd_2nd_max[0] != even_max[0]:
            odd_max = odd_2nd_max[0]
            even_max = even_max[0]
        else:
            if odd_max[1] >= even_max[1]:
                odd_max = odd_max[0]
                even_max = even_2nd_max[0]
            else:
                odd_max = odd_2nd_max[0]
                even_max = even_max[0]

    for key, count in even.items():
        if key != even_max:
            ans += count
    for key, count in odd.items():
        if key != odd_max:
            ans += count
    return ans


if __name__ == "__main__":
    n = int(input())
    l = input()
    print(solve(l.split(" ")))

Submission status: Wrong Answer

Solution code:
import collections

n = input()
line = input().split()
odd = line[::2]
even = line[1::2]
o = collections.Counter(odd)
e = collections.Counter(even)
maxoddcnt = o.most_common()[0][1]
maxevencnt = e.most_common()[0][1]

if o.most_common()[0][0] == e.most_common()[0][0]:
    if o.most_common()[0][1] > e.most_common()[0][1]:
        maxevencnt = e.most_common()[0][1]
    else:
        maxoddcnt = o.most_common()[0][1]

print(len(odd)-maxoddcnt+len(even)-maxevencnt)