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:
from collections import Counter
import sys
n = int(input())
v = [int(x) for x in input().split()]
test = [x == v[0] for x in v]
if all(test):
    print(int(n/2))
    sys.exit()
odd = [int(x) for x in v[0::2]]
even = [int(x) for x in v[1::2]]
odd_count = Counter(odd)
key1 = list(reversed(list(odd_count)))
even_count = Counter(even)
key2 = list(reversed(list(even_count)))
num = 0
if key1[0] == key2[0]:
    if  len(key1) > 1 and len(key2) > 1:
        num = max(odd_count[key1[0]]+even_count[key2[1]],odd_count[key1[1]]+even_count[key2[0]])
        print(n-num)
    elif len(key1) == 1:
        print(n-odd_count[key1[0]]-even_count[key2[1]])
    elif len(key2) == 1:
        print(n-odd_count[key1[1]]-even_count[key2[0]])
elif key1[0] != key2[0]:
    print(n-odd_count[key1[0]]-even_count[key2[0]])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = [int(x) for x in input().split()]
test = [x == v[0] for x in v]
if all(test):
    print(int(n/2))
    sys.exit()
odd = [int(x) for x in v[0::2]]
even = [int(x) for x in v[1::2]]
odd_count = Counter(odd)
key1 = list(odd_count)
even_count = Counter(even)
key2 = list(even_count)
num = 0
if key1[0] == key2[0]:
    num = max(odd_count[key1[0]]+even_count[key2[1]],odd_count[key1[1]]+even_count[key2[0]])
    print(n-num)
elif key1[0] != key2[0]:
    print(n-odd_count[key1[0]]-even_count[key2[0]])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = [int(x) for x in input().split()]
test = [x == v[0] for x in v]
if all(test):
    print(int(n/2))
    sys.exit()
odd = [int(x) for x in v[0::2]]
even = [int(x) for x in v[1::2]]
odd_count = Counter(odd)
key1 = list(odd_count)
even_count = Counter(even)
key2 = list(even_count)
num = 0
if key1[0] == key2[0]:
    num = min(odd_count[key1[0]]-odd_count[key1[1]],even_count[key2[0]]-even_count[key2[1]])
    print(n-odd_count[key1[0]]-even_count[key2[0]]+num)
elif key1[0] != key2[0]:
    print(n-odd_count[key1[0]]-even_count[key2[0]])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = [int(x) for x in input().split()]
test = [x == v[0] for x in v]
if all(test):
    print(int(n/2))
    sys.exit()
odd = [int(x) for x in v[0::2]]
even = [int(x) for x in v[1::2]]
odd_count = Counter(odd)
key1 = list(odd_count)
even_count = Counter(even)
key2 = list(even_count)
num = 0
if key1[0] == key2[0]:
    num = min(odd_count[key1[0]]-odd_count[key1[1]],even_count[key2[0]]-even_count[key2[1]])
    print(n-odd_count[key1[0]]-even_count[key2[0]]+num)
else:
    print(n-odd_count[key1[0]]-even_count[key2[0]])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = [int(x) for x in input().split()]
test = [x == v[0] for x in v]
if all(test):
    print(int(n/2))
    sys.exit()
odd = [int(x) for x in v[0::2]]
even = [int(x) for x in v[1::2]]
odd_count = Counter(odd)
key1 = list(odd_count)
even_count = Counter(even)
key2 = list(even_count)
num = 0
if key1[0] == key2[0]:
    num = min(odd_count[key1[0]]-odd_count[key1[1]],even_count[key2[0]]-even_count[key2[1]])
    print(n-odd_count[key1[0]]-even_count[key2[0]]+num)
else:
    print(odd_count[key1[0]],even_count[key2[0]])
    print(n-odd_count[key1[0]]-even_count[key2[0]])

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
v = [int(x) for x in input().split()]
test = [x == v[0] for x in v]
if all(test):
    print(0)
    sys.exit()
odd = [int(x) for x in v[0::2]]
even = [int(x) for x in v[1::2]]
odd_count = Counter(odd)
key1 = list(odd_count)
even_count = Counter(even)
key2 = list(even_count)
num = 0
if key1[0] == key2[0]:
    num = min(odd_count[key1[0]]-odd_count[key1[1]],even_count[key2[0]]-even_count[key2[1]])
    print(n-odd_count[key1[0]]-even_count[key2[0]]+num)
else:
    print(odd_count[key1[0]],even_count[key2[0]])
    print(n-odd_count[key1[0]]-even_count[key2[0]])

Submission status: Wrong Answer

Solution code:
from collections import Counter

l1 = []
l2 = []
n = int(input())
l = list(map(int, input().split()))
for i in range(n):
    if i % 2:
        l1.append(l[i])
    else:
        l2.append(l[i])

d1 = list(Counter(l1).items())
d2 = list(Counter(l2).items())
d1.append((4545454532, 0))
d2.append((4545454532, 0))
if d1[0][0] != d2[0][0]:
    print(n//2-d1[0][1] + n//2-d2[0][1])
else:
    ans1 = n//2 - d1[0][1] + n//2 - d2[1][1]
    ans2 = n//2 - d1[1][1] + n//2 - d2[0][1]
    print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])

if a[-1]!=b[-1]:
    print(n-a[0][1]-b[0][1])
else:
    print(min(n-a[1][1]-b[0][1],n-a[0][1]-b[1][1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2])
b = Counter(v[1::2])
a = sorted(a.items())
b = sorted(b.items())

if a[-1]!=b[-1]:
    print(n-a[-1][1]-b[-1][1])
elif len(a) == 1 and len(b) == 1:
    print(min(a[-1][1],b[-1][1]))
elif len(a) ==1:
    print(n-a[-1][1]-b[-2][1])
elif len(b) ==1:
    print(n-a[-2][1]-b[-1][1])
else:
    print(min(n-a[-2][1]-b[-1][1],n-a[-1][1]-b[-2][1]))

Submission status: Wrong Answer

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

A= [[0 for j in range(2)] for i in range(10**5)]
B= [[0 for j in range(2)] for i in range(10**5)]

for i in range(N):
    if i%2==0:
        A[S[i]-1][1]+=1
    else:
        B[S[i]-1][1]+=1

for i in range(10**5):    
    A[i][0]=i
    B[i][0]=i



TA=sorted(A,key=lambda x:x[1],reverse=True)
TB=sorted(B,key=lambda x:x[1],reverse=True)

if TA[0][0]!=TB[0][0]:
    print(N-TA[0][1]-TB[0][1])
elif TA[1][1]==0 and TB[1][1]==0:
    print(N-min(TA[0][1],TB[0][1]))
else:
    print(N//2-max(TA[1][1],TB[1][1]))

Submission status: Wrong Answer

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

A= [[0 for j in range(2)] for i in range(10**5)]
B= [[0 for j in range(2)] for i in range(10**5)]

for i in range(N):
    if i%2==0:
        A[S[i]-1][1]+=1
    else:
        B[S[i]-1][1]+=1

for i in range(10**5):    
    A[i][0]=i
    B[i][0]=i



TA=sorted(A,key=lambda x:x[1],reverse=True)
TB=sorted(B,key=lambda x:x[1],reverse=True)

if TA[0][0]!=TB[0][0]:
    print(N-TA[0][1]-TB[0][1])
elif TA[1][1]==0 and TB[1][1]==0:
    print(N-min(TA[0][1],TB[0][1]))
else:
    print(N-max(max(TA[0][1],TA[1][1]),max(TB[0][1],TB[1][1])))

Submission status: Wrong Answer

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

A= [[0 for j in range(2)] for i in range(10**5)]
B= [[0 for j in range(2)] for i in range(10**5)]

for i in range(N):
    if i%2==0:
        A[S[i]-1][1]+=1
    else:
        B[S[i]-1][1]+=1

for i in range(10**5):    
    A[i][0]=i
    B[i][0]=i



TA=sorted(A,key=lambda x:x[1],reverse=True)
TB=sorted(B,key=lambda x:x[1],reverse=True)

if TA[0][0]!=TB[0][0]:
    print(N-TA[0][1]-TB[0][1])
elif TA[1][1]==0 and TB[1][1]==0:
    print(N-min(TA[0][1],TB[0][1]))
elif TA[1][1]!=0:
    print(N-min(TA[0][1],TA[1][1]))
elif TB[1][1]!=0:
    print(N-min(TB[0][1],TB[1][1]))

Submission status: Wrong Answer

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

A= [[0 for j in range(2)] for i in range(10**5)]
B= [[0 for j in range(2)] for i in range(10**5)]

for i in range(N):
    if i%2==0:
        A[S[i]-1][1]+=1
    else:
        B[S[i]-1][1]+=1

for i in range(10**5):    
    A[i][0]=i
    B[i][0]=i



TA=sorted(A,key=lambda x:x[1],reverse=True)
TB=sorted(B,key=lambda x:x[1],reverse=True)

if TA[0][0]!=TB[0][0]:
    print(N-TA[0][1]-TB[0][1])
elif TA[1][1]==0 and TB[1][1]==0:
    print(N-min(TA[0][1],TB[0][1]))
else:
    pass

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

e = v[::2]
o = v[1::2]

e1 = Counter(e)
o1 = Counter(o)

e2 = sorted([(0, 0)] + [(x, y) for x, y in e1.items()])
o2 = sorted([(0, 0)] + [(x, y) for x, y in o1.items()])

xe, ye = e2[-1]
xo, yo = o2[-1]
xe1, ye1 = e2[-2]
xo1, yo1 = o2[-2]

if xe != xo:
    print(n - ye - yo)
else:
    print(min(n - ye - yo1, n - yo - ye1))

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    N = int(input())
    V = list(map(int, input().split()))
    c0 = Counter(V[::2])
    c1 = Counter(V[1::2])
    cc0 = sorted([(0, 0)] + [(v, k) for k, v in c0.items()], reverse=True)
    cc1 = sorted([(0, 0)] + [(v, k) for k, v in c1.items()], reverse=True)
    m0, v0 = cc0[0]
    m1, v1 = cc1[0]
    if v0 != v1:
        return N - m0 - m1
    if m0 > m1:
        return N - m0 - cc1[1][0]
    return N - m1 - cc0[1][0]
print(main())

Submission status: Wrong Answer

Solution code:
from collections import Counter
def main():
    N = int(input())
    V = list(map(int, input().split()))
    c0 = Counter(V[::2])
    c1 = Counter(V[1::2])
    cc0 = sorted([(0, 0)] + [(v, k) for k, v in c0.items()], reverse=True)
    cc1 = sorted([(0, 0)] + [(v, k) for k, v in c1.items()], reverse=True)
    m0, v0 = cc0[0]
    m1, v1 = cc0[1]
    if v0 != v1:
        return N - m0 - m1
    if m0 > m1:
        return N - m0 - cc1[1][0]
    return N - m1 - cc0[1][0]
print(main())

Submission status: Wrong Answer

Solution code:
import collections

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

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

even_c = collections.Counter(even)
odd_c = collections.Counter(odd)

even_max1_num = 0
even_max1_cnt = 0
even_max2_num = 0
even_max2_cnt = 0
for k, v in even_c.items():
    if v > even_max1_cnt:
        even_max2_cnt = even_max1_cnt
        even_max2_num = even_max1_num
        even_max1_cnt = v
        even_max1_num = k
    elif v > even_max2_cnt:
        even_max2_cnt = v
        even_max2_num = k

odd_max1_num = 0
odd_max1_cnt = 0
odd_max2_num = 0
odd_max2_cnt = 0
for k, v in odd_c.items():
    if v > odd_max1_cnt:
        odd_max2_cnt = odd_max1_cnt
        odd_max2_num = odd_max1_num
        odd_max1_cnt = v
        odd_max1_num = k
    elif v > odd_max2_cnt:
        odd_max2_cnt = v
        odd_max2_num = k

ans = 0
if even_max1_num == odd_max1_num:
    if even_max1_cnt > odd_max1_cnt:
        ans = N-(even_max1_cnt+odd_max2_cnt)
    else:
        ans = N-(even_max2_cnt+odd_max1_cnt)
else:
    ans = N-(even_max1_cnt+odd_max1_cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

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

even_c = collections.Counter(even)
odd_c = collections.Counter(odd)

even_max1_num = 0
even_max1_cnt = 0
even_max2_num = 0
even_max2_cnt = 0
for k, v in even_c.items():
    if k > even_max1_cnt:
        even_max2_cnt = even_max1_cnt
        even_max2_num = even_max1_num
        even_max1_cnt = v
        even_max1_num = k
    elif k > even_max2_cnt:
        even_max2_cnt = v
        even_max2_num = k

odd_max1_num = 0
odd_max1_cnt = 0
odd_max2_num = 0
odd_max2_cnt = 0
for k, v in odd_c.items():
    if k > odd_max1_cnt:
        odd_max2_cnt = odd_max1_cnt
        odd_max2_num = odd_max1_num
        odd_max1_cnt = v
        odd_max1_num = k
    elif k > odd_max2_cnt:
        odd_max2_cnt = v
        odd_max2_num = k

ans = 0
if even_max1_num == odd_max1_num:
    if even_max1_cnt > odd_max1_cnt:
        ans = N-(even_max1_cnt+odd_max2_cnt)
    else:
        ans = N-(even_max2_cnt+odd_max1_cnt)
else:
    ans = N-(even_max1_cnt+odd_max1_cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

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

even_c = collections.Counter(even)
odd_c = collections.Counter(odd)

even_max1_num = 0
even_max1_cnt = 0
even_max2_num = 0
even_max2_cnt = 0
for k, v in even_c.items():
    if k > even_max1_cnt:
        even_max2_cnt = even_max1_cnt
        even_max2_num = even_max1_num
        even_max1_cnt = v
        even_max1_num = k
    elif k > even_max2_cnt:
        even_max2_cnt = v
        even_max2_num = k

odd_max1_num = 0
odd_max1_cnt = 0
odd_max2_num = 0
odd_max2_cnt = 0
for k, v in odd_c.items():
    if k > odd_max1_cnt:
        odd_max2_cnt = odd_max1_cnt
        odd_max2_num = odd_max1_num
        odd_max1_cnt = v
        odd_max1_num = k
    elif k > odd_max2_cnt:
        odd_max2_cnt = v
        odd_max2_num = k

if even_max1_num == odd_max1_num:
    if even_max1_cnt > odd_max1_cnt:
        print(N-(even_max1_cnt+odd_max2_cnt))
    else:
        print(N-(even_max2_cnt+odd_max1_cnt))
else:
    print(N-(even_max1_cnt+odd_max1_cnt))

Submission status: Wrong Answer

Solution code:
import collections

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

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

even_c = collections.Counter(even)
odd_c = collections.Counter(odd)

even_max1_num = 0
even_max1_cnt = 0
even_max2_num = 0
even_max2_cnt = 0
for k, v in even_c.items():
    if k > even_max1_cnt:
        even_max2_cnt = even_max1_cnt
        even_max2_num = even_max1_num
        even_max1_cnt = v
        even_max1_num = k
    elif k > even_max2_cnt:
        even_max2_cnt = v
        even_max2_num = k

odd_max1_num = 0
odd_max1_cnt = 0
odd_max2_num = 0
odd_max2_cnt = 0
for k, v in odd_c.items():
    if k > odd_max1_cnt:
        odd_max2_cnt = odd_max1_cnt
        odd_max2_num = odd_max1_num
        odd_max1_cnt = v
        odd_max1_num = k
    elif k > odd_max2_cnt:
        odd_max2_cnt = v
        odd_max2_num = k

if even_max1_num == odd_max1_num:
    if even_max1_cnt > odd_max2_cnt:
        print(N-(even_max1_cnt+odd_max2_cnt))
    else:
        print(N-(even_max2_cnt+odd_max1_cnt))
else:
    print(N-(even_max1_cnt+odd_max1_cnt))

Submission status: Wrong Answer

Solution code:
import collections

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

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

even_c = collections.Counter(even)
odd_c = collections.Counter(odd)

even_max1_num = 0
even_max1_cnt = 0
even_max2_num = 0
even_max2_cnt = 0
for k, v in even_c.items():
    if k > even_max1_cnt:
        even_max2_cnt = even_max1_cnt
        even_max2_num = even_max1_num
        even_max1_cnt = v
        even_max1_num = k
    elif k > even_max2_cnt:
        even_max2_cnt = v
        even_max2_num = k

odd_max1_num = 0
odd_max1_cnt = 0
odd_max2_num = 0
odd_max2_cnt = 0
for k, v in odd_c.items():
    if k > odd_max1_cnt:
        odd_max2_cnt = odd_max1_cnt
        odd_max2_num = odd_max1_num
        odd_max1_cnt = v
        odd_max1_num = k
    elif k > odd_max2_cnt:
        odd_max2_cnt = v
        odd_max2_num = k

if even_max1_num == odd_max1_num:
    if even_max1_num > odd_max1_num:
        print(N-(even_max1_cnt+odd_max2_cnt))
    else:
        print(N-(even_max2_cnt+odd_max1_cnt))
else:
    print(N-(even_max1_cnt+odd_max1_cnt))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
E = []
O = []
for i,v in enumerate(V):
    if i%2==0:
        O.append(v)
    else:
        E.append(v)

cO = Counter(O).most_common(); cO.append((-1,0))
cE = Counter(E).most_common(); cE.append((-1,0))
if cO[0][0]==cE[0][0] and not (cO[0][0]==cO[1][0] or cE[0][0]==cE[1][0]): 
    if cO[0][1] >= cE[0][1]:
        ans = n-cO[0][1]-cE[1][1]
    else:
        ans = n-cO[1][1]-cE[0][1]
else:
    ans = n-cO[0][1]-cE[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
V = list(map(int,input().split()))
E = []
O = []
for i,v in enumerate(V):
    if i%2==0:
        O.append(v)
    else:
        E.append(v)

cO = Counter(O).most_common(); cO.append((-1,0))
cE = Counter(E).most_common(); cE.append((-1,0))
if cO[0][0]==cE[0][0]:
    if cO[0][1] >= cE[0][1]:
        ans = n-cO[0][1]-cE[1][1]
    else:
        ans = n-cO[1][1]-cE[0][1]
else:
    ans = n-cO[0][1]-cE[0][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
a1 = []
a2 = []
for i in range(0,n,1):#スライスで絶対もっときれいにかけるなりねー
    if i%2==0:
        a1.append(v[i])
    if i%2==1:
        a2.append(v[i])

c1 = collections.Counter(a1)#配列を渡す
c2 = collections.Counter(a2)#配列を渡す
print(len(a1) - c1.most_common()[0][1] + len(a2) - c2.most_common()[0][1])#最も出現回数が多いものの出現回数

Submission status: Wrong Answer

Solution code:
N = int(input())
V = [int(x) for x in input().split()]
ans = 0

counterA = {}
for i in range(0, N, 2):
    if not V[i] in counterA:
        counterA[V[i]] = 1
    else:
        counterA[V[i]] += 1

counterB = {}
for i in range(1, N, 2):
    if not V[i] in counterB:
        counterB[V[i]] = 1
    else:
        counterB[V[i]] += 1

if not max(counterA) == max(counterB):
    print((N//2 - counterA[max(counterA)]) + (N//2 - counterB[max(counterB)]))
else:
    k = max(counterA)
    v = counterA[max(counterA)]
    counterA[max(counterA)] = 0
    counterB[max(counterB)] = 0
    if max(counterA) > max(counterB):
        print((N//2 - v) + (N//2 - counterA[max(counterA)]))
    else:
        print((N//2 - v) + (N//2 - counterB[max(counterB)]))

Submission status: Wrong Answer

Solution code:
N = int(input())
V = [int(x) for x in input().split()]
ans = 0

counterA = {}
for i in range(0, N, 2):
    if not V[i] in counterA:
        counterA[V[i]] = 1
    else:
        counterA[V[i]] += 1

counterB = {}
for i in range(1, N, 2):
    if not V[i] in counterB:
        counterB[V[i]] = 1
    else:
        counterB[V[i]] += 1

if not max(counterA) == max(counterB):
    print((N//2 - counterA[max(counterA)]) + (N//2 - counterB[max(counterB)]))
else:
    v = max(counterA)
    counterA[max(counterA)] = 0
    counterB[max(counterB)] = 0
    if max(counterA) > max(counterB):
        print((N//2 - v) + (N//2 - max(counterA)))
    else:
        print((N//2 - v) + (N//2 - max(counterB)))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,*v = map(int,open(0).read().split())
v1 = Counter(v[::2])
v2 = Counter(v[1::2])
v1 = sorted([(i,v1[i]) for i in v1.keys()],key =lambda x:x[1],reverse=True)
v2 = sorted([(i,v2[i]) for i in v2.keys()],key =lambda x:x[1],reverse=True)
print(v1,v2)
if len(v1) == 1:
  if len(v2) == 1:
    if v1[0][0] != v2[0][0]:
      print(0)
    else:
      print(n//2)
  else:
    if v1[0][0] != v2[0][0]:
      print(n//2-v2[0][1])
    else:
      print(n//2-v2[1][1])
else:
  if len(v2) == 1:
    if v1[0][0] != v2[0][0]:
      print(n//2-v1[0][1])
    else:
      print(n//2-v1[1][1])
  else:
    if v1[0][0] != v2[0][0]:
      print(n-v1[0][1]-v2[0][1])
    else:
      print(min(n-v1[0][1]-v2[1][1],n-v1[1][1]-v2[0][1]))

Submission status: Wrong Answer

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

from collections import Counter
V_1=V[::2]
V_2=V[1::2]

V_1_counter=Counter(V_1).most_common()
V_2_counter=Counter(V_2).most_common()

V_1_max_1 = V_1_counter[0]
V_1_max_2=(0,0)
if len(V_1_counter)>1:
    V_1_max_2 = V_1_counter[1]
    
V_2_max_1=V_2_counter[0]
V_2_max_2=(0,0)
if len(V_2_counter)>1:
    V_2_max_2 = V_2_counter[1]
    
if V_1_max_1[0] != V_2_max_1[0]:
    ans = len(V_1)-V_1_max_1[1]+len(V_2)-V_2_max_1[1]
    
else:
    if V_1_max_1[1] >= V_2_max_1[1]:
        ans = N-V_1_max_1[1]-V_2_max_2[1]
    else:
        ans = N-V_1_max_2[1]-V_2_max_1[1]
    
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
V_1=V[::2]
V_2=V[1::2]

V_1_counter=Counter(V_1).most_common()
V_2_counter=Counter(V_2).most_common()

V_1_max_1 = V_1_counter[0]
V_1_max_2=(0,0)
if len(V_1_counter)>1:
    V_1_max_2 = V_1_counter[1]
    
V_2_max_1=V_2_counter[0]
V_2_max_2=(0,0)
if len(V_2_counter)>1:
    V_2_max_2 = V_2_counter[1]
    
if V_1_max_1[0] != V_2_max_1[0]:
    ans = len(V_1)-V_1_max_1[1]+len(V_2)-V_2_max_1[1]
    
else:
    if V_1_max_1[0] >= V_2_max_1[0]:
        ans = len(V_1)-V_1_max_1[1]+len(V_2)-V_2_max_2[1]
    else:
        ans = len(V_1)-V_1_max_2[1]+len(V_2)-V_2_max_2[1]
    
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
d1=[0]*(10**5+1)
d2=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        d1[v[i]]+=1
    else:
        d2[v[i]]+=1
assert n-max(d1)-max(d2)>=0
print(n-max(d1)-max(d2))

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
d1=[0]*(10**5+1)
d2=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        d1[v[i]]+=1
    else:
        d2[v[i]]+=1
print(n-max(d1)-max(d2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from collections import Counter

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


c = Counter(v)

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

sorted_values = sorted(list(c.values()))
max1 = sorted_values[-1]
max2 = sorted_values[-2]

ans1 = abs((n+1)//2 - max1)
ans2 = abs(n//2 - max2)

print(ans1+ans2)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
if len(set(v)) == 1:
    print(n // 2)
else:
    print(n - c1.most_common(1)[0][1] - c2.most_common(1)[0][1])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
v = tuple(map(int, input().split()))
c1 = Counter(v[::2])
c2 = Counter(v[1::2])
if c1 == c2:
    print(n // 2)
else:
    print(n - c1.most_common(1)[0][1] - c2.most_common(1)[0][1])

Submission status: Wrong Answer

Solution code:

def solve():
    ans = 0
    for i in range(0,n-2):
        if v[i] != v[i+2]:
            ans += 1
    if ans == 0:
        is_same = all([c == v[0] for c in v[1:]]) if v else False
        if is_same:
            print(n//2)
        elif not is_same:
            print(0)
    
    else:
        print(ans)
            

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

Submission status: Wrong Answer

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

dic_odd = {}
dic_even = {}

for i, v in enumerate(V):
    if i % 2 == 0:
        if v in dic_even:
            dic_even[v] += 1
        else:
            dic_even[v] = 1
    else:
        if v in dic_odd:
            dic_odd[v] += 1
        else:
            dic_odd[v] = 1


odd_lst = [(k, v) for k, v in dic_odd.items()]
even_lst = [(k, v) for k, v in dic_even.items()]
odd_lst.sort(reverse=True)
even_lst.sort(reverse=True)

max_ = 0
for a, b in odd_lst:
    for x, y in even_lst:
        if a == x:
            continue
        else:
            max_ = max(b + y, max_)
            break


print(N - max_)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
v = list(map(int,input().split()))
v_odd = []
v_even = []
for i,v in enumerate(v):
    if i % 2:
        v_even.append(v)
    else:
        v_odd.append(v)
odd_n = len(v_odd)
even_n = len(v_even)
v_odd = collections.Counter(v_odd)
v_odd = sorted(v_odd.items(), key=lambda x:x[1],reverse=True)
v_even = collections.Counter(v_even)
v_even = sorted(v_even.items(), key=lambda x:x[1],reverse=True)

num = v_odd[0][0]

ans = odd_n-v_odd[0][1]
st = 0
for i,v in v_even:
    if num == i:
        continue
    else:
        st = v
        break
print(ans+(even_n-st))

Submission status: Wrong Answer

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

def main(n,v):

    hist=[0]*(10**5+1)
    maxhist=0
    maxvalue=0
    for i in range(n):
        hist[v[i]]+=1
        if (maxhist<hist[v[i]]):
            maxhist=hist[v[i]]
            maxvalue=v[i]
    print('maxvalue: {}, maxhist: {}'.format(maxvalue, maxhist))

    secondhist=0
    for i in range(1,10**5+1):
        if i == maxvalue:
            continue
        secondhist=max(secondhist,hist[i])
    print('secondhist: {}'.format(secondhist))

    nsame=n//2
    nchange=0
    if maxhist>nsame:
        nchange+=maxhist-nsame
    elif maxhist<nsame:
        nchange+=nsame-maxhist
    nchange+=nsame-secondhist
    return nchange

def main2(n,v):
    eList=[]
    oList=[]
    for i in range(n):
        if i%2==0:
            eList.append(v[i])
        else:
            oList.append(v[i])

    #print(eList)
    #print(oList)

    hist=[0]*(10**5+1)
    for i in eList:
        hist[i]+=1
    emaxh=0
    emaxv=0
    for i in range(1,10**5+1):
        if emaxh<hist[i]:
            emaxh=hist[i]
            emaxv=i
    
    hist=[0]*(10**5+1)
    for i in oList:
        hist[i]+=1
    omaxh=0
    omaxv=0
    for i in range(1,10**5+1):
        if omaxh<=hist[i]:
            omaxh=hist[i]
            omaxv=i
    if omaxv==emaxv:
        emaxv=(emaxv+1)%10**5
    
    #print('emaxv: {}, omaxv: {}'.format(emaxv,omaxv))

    nchange=0
    for i in range(n//2):
        if eList[i]!=emaxv:
            nchange+=1
        if oList[i]!=omaxv:
            nchange+=1
    return nchange


if __name__=='__main__':
    n,v=readinput()
    ans=main2(n,v)
    print(ans)

Submission status: Wrong Answer

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

def main(n,v):

    hist=[0]*(10**5+1)
    maxhist=0
    maxvalue=0
    for i in range(n):
        hist[v[i]]+=1
        if (maxhist<hist[v[i]]):
            maxhist=hist[v[i]]
            maxvalue=v[i]
    print('maxvalue: {}, maxhist: {}'.format(maxvalue, maxhist))

    secondhist=0
    for i in range(1,10**5+1):
        if i == maxvalue:
            continue
        secondhist=max(secondhist,hist[i])
    print('secondhist: {}'.format(secondhist))

    nsame=n//2
    nchange=0
    if maxhist>nsame:
        nchange+=maxhist-nsame
    elif maxhist<nsame:
        nchange+=nsame-maxhist
    nchange+=nsame-secondhist
    return nchange

def main2(n,v):
    eList=[]
    oList=[]
    for i in range(n):
        if i%2==0:
            eList.append(v[i])
        else:
            oList.append(v[i])
    hist=[0]*(10**5+1)
    for i in eList:
        hist[i]+=1
    emaxh=0
    emaxv=0
    for i in range(1,10**5+1):
        if emaxh<hist[i]:
            emaxh=hist[i]
            emaxv=i
    
    hist=[0]*(10**5+1)
    for i in oList:
        hist[i]+=1
    omaxh=0
    omaxv=0
    for i in range(1,10**5+1):
        if omaxh<hist[i]:
            omaxh=hist[i]
            omaxv=i
    if omaxv==emaxv:
        emaxv=(emaxv+1)%10**5
    
    nchange=0
    for i in range(n//2):
        if eList[i]!=emaxv:
            nchange+=1
        if oList[i]!=omaxv:
            nchange+=1
    return nchange


if __name__=='__main__':
    n,v=readinput()
    ans=main2(n,v)
    print(ans)

Submission status: Wrong Answer

Solution code:
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''
import collections
def myAnswer(N:int,V:list) -> int:
   odd = []
   even = []
   if len(set(V)) == 1:
      return N//2

   for n,v in enumerate(V):
      even.append(v) if n % 2 == 0 else odd.append(v)
   
   oddCounter = collections.Counter(odd)
   evenCounter = collections.Counter(even)
   oddCounter = sorted(oddCounter.items(),key=lambda x:x[1])
   evenCounter = sorted(evenCounter.items(),key=lambda x:x[1])
   oddMAX = oddCounter[-1][0]
   evenMAX = evenCounter[-1][0]
   if oddMAX == evenMAX:
      evenLen = len(evenCounter)
      oddLen = len(oddCounter)
      if evenLen >= 2 and oddLen >= 2:
         if evenCounter[-2][1] > oddCounter[-2][1]:
            evenMAX = evenCounter[-2][0]
         else:
            oddMAX = oddCounter[-2][0]
      elif evenLen >= 2:
         evenMAX = evenCounter[-2][0]
      else:
         oddMAX = oddCounter[-2][0]

   print(oddCounter,evenCounter,oddMAX,evenMAX)
   total = 0
   for n,v in enumerate(V):
      if n % 2 == 1:
         if oddMAX != v:
            total += 1
      else:
         if evenMAX != v:
            total += 1
   return total
def modelAnswer():
   return
def main():
   N = int(input())
   V = list(map(int,input().split()))
   print(myAnswer(N,V))


if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''
import collections
import itertools
def myAnswer(N:int,V:list) -> int:
   counter = collections.Counter(V)
   if len(counter) == 1:
      return N//2

   counter = sorted(counter.items(), key=lambda x:x[1])
   MAX = counter[-1][0]
   tmp = counter[-2][1]
   MAX2 = {counter[-2][0]}
   for key,value in counter:
      if tmp == value:
         MAX2.add(key)
   if MAX in MAX2:
      return modelAnswer(MAX2,V)

   index = V.index(MAX)
   ans = 10**10
   for m2 in MAX2:
      total = 0
      m = [MAX,m2]
      target = m2
      for i in range(index + 1,N):
         if V[i] != target:
            total += 1
         target = m[0] if target == m[1] else m[1]
      target = m2
      for i in range(index - 1,-1,-1):
         if V[i] != target:
            total += 1
         target = m[0] if target == m[1] else m[1]
      ans = min(ans,total)

   return ans

def modelAnswer(lis,V):
   ans = 10**9
   for m1,m2 in itertools.combinations(lis,2):
      index = V.index(m1)
      total = 0
      target = m2
      for i in range(index + 1,len(V)):
         if V[i] != target:
            total += 1
         target = m1 if target == m2 else m2
      target = m2
      for i in range(index - 1, -1,-1):
         if V[i] != target:
            total += 1
         target = m1 if target == m2 else m2
      ans = min(ans,total)
   return ans
def main():
   N = int(input())
   V = list(map(int,input().split()))
   print(myAnswer(N,V))


if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''
import collections
def myAnswer(N:int,V:list) -> int:
   counter = collections.Counter(V)
   if len(counter) == 1:
      return N//2
   counter = sorted(counter.items(), key=lambda x:x[1])
   m = [counter[-1][0],counter[-2][0]]
   index = V.index(m[0])
   total = 0
   target = m[1]
   for i in range(index + 1,N):
      if V[i] != target:
         total += 1
      target = m[0] if target == m[1] else m[1]
      
   target = m[1]
   for i in range(index - 1,-1,-1):
      if V[i] != target:
         total += 1
      target = m[0] if target == m[1] else m[1]

   return total

def modelAnswer():
   return
def main():
   N = int(input())
   V = list(map(int,input().split()))
   print(myAnswer(N,V))


if __name__ == '__main__':
   main()