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 math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
b = [v[i] for i in range(n) if i%2]
a = [v[i] for i in range(n) if i%2==0]
cnt_a = Counter(a)
cnt_b = Counter(b)
max_a = cnt_a.most_common()[0][1]
max_b = cnt_b.most_common()[0][1]

str_a = cnt_a.most_common()[0][0]
str_b = cnt_b.most_common()[0][0]

max_2a = max_2b = 0

for i in cnt_a:
    if str_a != i  and cnt_a[i] > max_2a:
        max_2a = cnt_a[i]

for i in cnt_b:
    if str_b != i  and cnt_b[i] > max_2b:
        max_2b = cnt_a[i]

if str_a != str_b:
    print(n//2 - max_a + n//2 - max_b)
else:
    tmp_a = n//2 - max_2a + n//2 - max_b
    tmp_b = n//2 - max_a + n//2 - max_2b
    print(min(tmp_a,tmp_b))

Submission status: Wrong Answer

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

a = {}
for i in range(0, len(v), 2):
    a[v[i]] = a.get(v[i], 0) + 1

b = {}
for i in range(1, len(v), 2):
    b[v[i]] = b.get(v[i], 0) + 1

sorted_a = sorted(a.items(), reverse=True, key=lambda x: x[1])
sorted_b = sorted(b.items(), reverse=True, key=lambda x: x[1])

res = 0
if sorted_a[0][0] == sorted_b[0][0]:
    if sorted_a[0][1] >= sorted_b[0][1]:
        res += sorted_b[0][1]
        if len(sorted_b) > 1:
            res -= 1
    else:
        res += sorted_a[0][1]
        if len(sorted_a) > 1:
            res -= 1

for i in range(len(sorted_a)):
    if i == 0:
        continue
    res += sorted_a[i][1]
for i in range(len(sorted_b)):
    if i == 0:
        continue
    res += sorted_b[i][1]

print(res)

Submission status: Wrong Answer

Solution code:
import collections

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

hantei = 0

for i in range(0,n):
    if u[0] != u[i]:
        hantei = 1
        break

if hantei == 0:
    print(n // 2)
else:
   u1 = [] 
   u2 = [] 
   ans = 0
   for j in range(n):
       if j % 2 == 0:
           u2.append(u[j])
       else:
           u1.append(u[j])
   u1_list =collections.Counter(u1)
   u2_list =collections.Counter(u2)
   values1, counts1 = u1_list.most_common()[0]
   values2, counts2 = u2_list.most_common()[0]
   if values1 != values2:
       ans += n // 2 - counts1
       ans += n // 2 - counts2
   else:
       if len(u1_list) > 1 and len(u2_list) > 1:
           values3, counts3 = u1_list.most_common()[0]
           values4, counts4 = u2_list.most_common()[0]
           ans1 = n - counts1 - counts4
           ans2 = n - counts2 - counts3
           ans = min(ans1,ans2)
       elif len(u1_list) > 1 and len(u2_list) < 2:
           values3, counts3 = u1_list.most_common()[0]
           ans = n - counts2 - counts3
       elif len(u1_list) < 2 and len(u2_list) > 1:
           values3, counts3 = u2_list.most_common()[0]
           ans = n - counts1 - counts3

       ans = min(ans1,ans2)
   print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

hantei = 0

for i in range(1,n):
    if u[0] != u[i]:
        hantei = 1
        break

if hantei == 0:
    print(n // 2)
else:
   u1 = [] 
   u2 = [] 
   ans = 0
   for j in range(n):
       if j % 2 == 0:
           u2.append(u[j])
       else:
           u1.append(u[j])
   u1_list =collections.Counter(u1)
   u2_list =collections.Counter(u2)
   values1, counts1 = u1_list.most_common()[0]
   values2, counts2 = u2_list.most_common()[0]
   ans += n // 2 - counts1
   ans += n // 2 - counts2
   print(ans)

Submission status: Wrong Answer

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

hantei = 0

for i in range(1,n):
    if u[0] != u[i]:
        hantei = 1
        break

if hantei == 0:
    print(n // 2)
else:
    count = 0
    count1 = 0
    for i in range(2,n):
        if i % 2 == 0:
            if u[0] != u[i]:
                count += 1
        else :
            if u[1] != u[i]:
                count += 1
    for i in range(0, n-2)[::-1]:
        if i % 2 == 0:
            if u[n-1] != u[i]:
                count1 += 1
        else :
            if u[n-2] != u[i]:
                count1 += 1

    print(min(count,count1))

Submission status: Wrong Answer

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

hantei = 0

for i in range(1,n):
    if u[0] != u[i]:
        hantei = 1
        break

if hantei == 0:
    print(n // 2)
else:
    count = 0
    for i in range(2,n):
        if i % 2 == 0:
            if u[0] != u[i]:
                count += 1
        else :
            if u[1] != u[i]:
                count += 1
    print(count)

Submission status: Wrong Answer

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

a = {}
for i in range(0, len(v), 2):
    a[v[i]] = a.get(v[i], 0) + 1

b = {}
for i in range(1, len(v), 2):
    b[v[i]] = b.get(v[i], 0) + 1

sorted_a = sorted(a.items(), reverse=True, key=lambda x: x[1])
sorted_b = sorted(b.items(), reverse=True, key=lambda x: x[1])

res = 0
if sorted_a[0][0] == sorted_b[0][0]:
    if sorted_a[0][1] >= sorted_b[0][1]:
        res += sorted_b[0][1]
    else:
        res += sorted_a[0][1]

for i in range(len(sorted_a)):
    if i == 0:
        continue
    res += sorted_a[i][1]
for i in range(len(sorted_b)):
    if i == 0:
        continue
    res += sorted_b[i][1]

print(res)

Submission status: Wrong Answer

Solution code:
import math,fractions
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()]
b = [v[i] for i in range(n) if i%2]
a = [v[i] for i in range(n) if i%2==0]
cnt_a = Counter(a)
cnt_b = Counter(b)
max_a = max_b = 0
max_2a = max_2b = 0
str_a = str_b = ''
str_2a = str_2b = ''
for i in cnt_a:
    if cnt_a[i] > max_a:
        max_a = cnt_a[i]
        str_a = i
    elif cnt_a[i] > max_2a:
        max_2a = cnt_a[i]
        str_2a = i
for i in cnt_b:
    if cnt_b[i] > max_b:
        max_b = cnt_b[i]
        str_b = i
    elif cnt_b[i] > max_2b:
        max_2b = cnt_b[i]
        str_2b = i
if str_a != str_b:
    print(n//2-max_a + n//2-max_b)
else:
    tmp_a = n//2-max_2a + n//2-max_b
    tmp_b = n//2-max_a + n//2-max_2b
    print(min(tmp_a,tmp_b))

Submission status: Wrong Answer

Solution code:

    
from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))

a = Counter(v[0::2]).most_common()
b = Counter(v[1::2]).most_common()
print(a)
print(b)
a.append([0,0])
b.append([0,0])
if a[0][0] != b[0][0]:
  print(n-(a[0][1]+b[0][1]))
else:
  print(min(n-(a[0][1]+b[1][1]),n-(a[1][1]+b[0][1])))

Submission status: Wrong Answer

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

vo = [0] * (10**5 + 1)
ve = [0] * (10**5 + 1)

for i in range(n):
    if (i+1) % 2 == 0:
        ve[v[i]] += 1
    else:
        vo[v[i]] += 1
if vo.index(max(vo)) != ve.index(max(ve)):
    print(n - max(vo) - max(ve))
    
elif max(vo) >= max(ve):
    ve1 = sorted(ve, reverse = True)
    print(n - max(vo) - ve1[1])
else:
    vo1 = sorted(vo, reverse = True)
    print(n - max(ve) - vo1[1])

Submission status: Wrong Answer

Solution code:

import math
import sys
import collections
n = int(input())
vvv = list(map(int,input().split()))
odd = [vvv[i] for i in range(1,n,2)]
even = [vvv[i] for i in range(0,n,2)]
c_o = collections.Counter(odd)
_, odd_c = zip(*c_o.most_common())
c_e = collections.Counter(even)
_, even_c = zip(*c_e.most_common())
if c_o.most_common()[0][0] == c_e.most_common()[0][0]:
  print(int(n/2))
  sys.exit()
ans = sum(list(odd_c)[1:]) + sum(list(even_c)[1:])
print(ans)

Submission status: Wrong Answer

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

odd = {}
even = {}
for i in range(N):
    tmp = l[i]
    if i % 2:
        if not odd.get(tmp):
            odd[tmp] = 0
        odd[tmp] += 1
    else:
        if not even.get(tmp):
            even[tmp] = 0
        even[tmp] += 1

odd_1st = sorted(odd.items(), key=lambda x: -x[1])[0][0]
if len(odd.keys()) > 1:
    odd_2nd = sorted(odd.items(), key=lambda x: -x[1])[1][0]
else:
    odd_2nd = odd_1st
even_1st = sorted(even.items(), key=lambda x: -x[1])[0][0]
even_2nd = sorted(even.items(), key=lambda x: -x[1])[0][0]
if len(even.keys()) > 1:
    even_2nd = sorted(even.items(), key=lambda x: -x[1])[1][0]
else:
    even_2nd = even_1st

odd_switch_1st = sum([v for k, v in odd.items() if k != odd_1st])
odd_switch_2nd = sum([v for k, v in odd.items() if k != odd_2nd])
even_switch_1st = sum([v for k, v in even.items() if k != even_1st])
even_switch_2nd = sum([v for k, v in even.items() if k != even_2nd])

if odd_switch_1st + even_switch_1st == 0:
    print(N//2)
    exit()

if odd_switch_1st == even_switch_1st:
    print(min(odd_switch_2nd + even_switch_1st, odd_switch_1st + even_switch_2nd))
else:
    print(odd_switch_1st + even_switch_1st)

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import Counter

N = int(input())
v = list(map(int,input().split()))
e = [ v[i] for i in range(N) if i % 2 == 0 ]
o = [ v[i] for i in range(N) if i % 2 != 0 ]
d = Counter(e).most_common()
cnt = 0
E1 = d[0][0]
try:
    E2 = d[1][0]
except:
    cnt += 1
    E2 = d[0][0]

d = Counter(o).most_common()
ccnt = 0
O1 = d[0][0]
try:
    O2 = d[1][0]
except:
    ccnt += 1
    O2 = d[0][0]
if E1 == O1:
    print(N//2)
    exit()
ans = 0
for i in e:
    if i != E1:
        ans += 1
for i in o:
    if i != O2:
        ans += 1
aans = 0
for i in e:
    if i != E2:
        aans += 1
for i in o:
    if i != O1:
        aans += 1
print(min(aans,ans))

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import Counter

N = int(input())
v = list(map(int,input().split()))
e = [ v[i] for i in range(N) if i % 2 == 0 ]
o = [ v[i] for i in range(N) if i % 2 != 0 ]
d = Counter(e).most_common()
cnt = 0
E1 = d[0][0]
try:
    E2 = d[1][0]
except:
    cnt += 1
    E2 = d[0][0]

d = Counter(o).most_common()
ccnt = 0
O1 = d[0][0]
try:
    O2 = d[1][0]
except:
    ccnt += 1
    O2 = d[0][0]
if ccnt + cnt == 2 and E1 == O1:
    print(N//2)
    exit()
ans = 0
for i in e:
    if i != E1:
        ans += 1
for i in o:
    if i != O2:
        ans += 1
aans = 0
for i in e:
    if i != E2:
        aans += 1
for i in o:
    if i != O1:
        aans += 1
print(min(aans,ans))

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import Counter

N = int(input())
v = list(map(int,input().split()))
e = [ v[i] for i in range(N) if i % 2 == 0 ]
o = [ v[i] for i in range(N) if i % 2 != 0 ]
d = Counter(e).most_common()
cnt = 0
E1 = d[0][0]
try:
    E2 = d[1][0]
except:
    cnt += 1
    E2 = d[0][0]

d = Counter(o).most_common()
ccnt = 0
O1 = d[0][0]
try:
    O2 = d[1][0]
except:
    ccnt += 1
    O2 = d[0][0]
if ccnt + cnt == 2:
    print(N//2)
    exit()
ans = 0
for i in e:
    if i != E1:
        ans += 1
for i in o:
    if i != O2:
        ans += 1
aans = 0
for i in e:
    if i != E2:
        aans += 1
for i in o:
    if i != O1:
        aans += 1
print(min(aans,ans))

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import Counter

N = int(input())
v = list(map(int,input().split()))
e = [ v[i] for i in range(N) if i % 2 == 0 ]
o = [ v[i] for i in range(N) if i % 2 != 0 ]
d = Counter(e).most_common()
E1 = d[0][0]
try:
    E2 = d[1][0]
except:
    E2 = d[0][0] + 1

d = Counter(o).most_common()
O1 = d[0][0]
try:
    O2 = d[1][0]
except:
    O2 = d[0][0] + 1
ans = 0
for i in e:
    if i != E1:
        ans += 1
for i in o:
    if i != O2:
        ans += 1
aans = 0
for i in e:
    if i != E2:
        aans += 1
for i in o:
    if i != O1:
        aans += 1
print(min(aans,ans))

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import Counter

N = int(input())
v = list(map(int,input().split()))
e = [ v[i] for i in range(N) if i % 2 == 0 ]
o = [ v[i] for i in range(N) if i % 2 != 0 ]
d = Counter(e).most_common()
E1 = d[0][0]
try:
    E2 = d[1][0]
except:
    E2 = d[0][0]

d = Counter(o).most_common()
O1 = d[0][0]
try:
    O2 = d[1][0]
except:
    O2 = d[0][0]
ans = 0
for i in e:
    if i != E1:
        ans += 1
for i in o:
    if i != O2:
        ans += 1
aans = 0
for i in e:
    if i != E2:
        aans += 1
for i in o:
    if i != O1:
        aans += 1
print(min(aans,ans))

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import Counter

N = int(input())
v = list(map(int,input().split()))
e = [ v[i] for i in range(N) if i % 2 == 0 ]
o = [ v[i] for i in range(N) if i % 2 != 0 ]
d = Counter(e).most_common()
E1 = d[0][0]
try:
    E2 = d[1][0]
except:
    E2 = d[0][0]

d = Counter(o).most_common()
O1 = d[0][0]
try:
    O2 = d[1][0]
except:
    O2 = d[0][0]
ans = 0
for i in e:
    if i != E1:
        ans += 1
for i in o:
    if i != O2:
        ans += 1
aans = 0
for i in e:
    if i != E2:
        aans += 1
for i in o:
    if o != O1:
        aans += 1
print(min(aans,ans))

Submission status: Wrong Answer

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

odd = {}
even = {}
for i in range(N):
    tmp = l[i]
    if i % 2:
        if not odd.get(tmp):
            odd[tmp] = 0
        odd[tmp] += 1
    else:
        if not even.get(tmp):
            even[tmp] = 0
        even[tmp] += 1

odd_max = sorted(odd.items(), key=lambda x: -x[1])[0][0]
even_max = sorted(even.items(), key=lambda x: -x[1])[0][0]

odd_switch = sum([v for k, v in odd.items() if k != odd_max])
even_switch = sum([v for k, v in even.items() if k != even_max])

if odd_switch + even_switch == 0:
    print(N // 2)
else:
    print(odd_switch + even_switch)

Submission status: Wrong Answer

Solution code:
import collections

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

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

c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

if list(c_even.keys()) == list(c_odd.keys()) and len(c_even) == len(c_odd) and len(c_even)==1:
    print(min(len(even), len(odd)))
else:
    print(len(v) - max(list(c_even.values()))  - max(list(c_odd.values())))

Submission status: Wrong Answer

Solution code:
import collections

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

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

c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

if list(c_even.values())[0] == list(c_odd.values())[0] and len(c_even) == len(c_odd) == 1:
    print(min(len(even), len(odd)))
else:
    print(len(v) - max(list(c_even.values()))  - max(list(c_odd.values())))

Submission status: Wrong Answer

Solution code:
import collections

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

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

c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

if list(c_even.keys())[0] == list(c_odd.keys())[0] and len(c_even) == len(c_odd) == 1:
    print(min(len(even), len(odd)))
else:
    print(len(v) - max(list(c_even.values()))  - max(list(c_odd.values())))

Submission status: Wrong Answer

Solution code:
import collections

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

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

c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

if list(c_even.keys())[0] == list(c_odd.keys())[0] and len(c_even) == len(c_odd) == 1:
    print(min(len(even), len(odd)))
else:
    print(len(v) - list(c_even.values())[0]  - list(c_odd.values())[0])

Submission status: Wrong Answer

Solution code:
import collections

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

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

c_even = collections.Counter(even)
c_odd = collections.Counter(odd)

if list(c_even.keys())[0] == list(c_odd.keys())[0] and len(c_even) == len(c_even) == 1:
    print(len(even))
else:
    print(len(even) - list(c_even.values())[0] + len(odd) - list(c_odd.values())[0])

Submission status: Wrong Answer

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

if len(set(l)) == 1:
    print(2)

elif n == 2:
    print(1)

elif len(set(l[::2])) == 1 and len(set(l[1::2])) == 1:
    print(0)

elif len(set(l[::2])) == 2 and len(set(l[1::2])) == 1:
    print(min(set(l[::2])))

elif len(set(l[::2])) == 1 and len(set(l[1::2])) == 2:
    print(min(set(l[1::2])))
        
else:
    print(2)

Submission status: Wrong Answer

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

vo=[0]*(10**5+1)
ve=[0]*(10**5+1)

for i in range(n):
    if i%2==0:
        vo[v[i]] +=1
    else:
        ve[v[i]] +=1


if vo.index(max(vo))==ve.index(max(ve)):
    ans1 = sum(vo)-max(vo)+sum(ve)-sorted(vo)[-2]
    ans2 = sum(vo)-sorted(vo)[-2]+sum(ve)-max(ve)
    print(min(ans1,ans2))
else:
    print(sum(vo)-max(vo)+sum(ve)-max(ve))

Submission status: Wrong Answer

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

if len(set(l)) == 1:
    print(2)

elif n == 2:
    print(1)

elif len(set(l[::2])) == 1 and len(set(l[1::2])) == 1:
    print(0)

elif len(set(l[::2])) == 2 and len(set(l[1::2])) == 1:
    if n == 4:
        print(0)
    else:
        for i in range(0,n,2):
            if l[::2].count(l[i])==1:
                print(i)

elif len(set(l[::2])) == 1 and len(set(l[1::2])) == 2:
    if n == 4:
        print(1)
    else:
        for i in range(1,n,2):
            if l[1::2].count(l[i])==1:
                print(i)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
import collections


def counter(l):
    c = collections.Counter(l)
    array = list(c.values())
    return array[0]


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

if n == 2:
    print(0)
    exit()

l1 = v[0::2]
l2 = v[1::2]

if l1 == l2 and counter(l1) == len(l1):
    print(int(n/2))
    exit()

print(len(l1) - counter(l1) + len(l2) - counter(l2))

Submission status: Wrong Answer

Solution code:
import collections


def counter(l):
    c = collections.Counter(l)
    array = list(c.values())
    return array[0]


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

if n == 2:
    print(0)
    exit()

l1 = v[0::2]
l2 = v[1::2]

if l1 == l2:
    print(int(n/2))
    exit()

print(len(l1) - counter(l1) + len(l2) - counter(l2))

Submission status: Wrong Answer

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

if n == 2:
    print(0)
    exit()

for i in range(n-1):
    if v[i] == v[i+1]:
        count += 1
    if count == n-1:
        print(int(n/2))
        exit()

for i in range(n-2):
    if v[i] + v[i+1] != v[i+1] + v[i+2]:
        count_2 += 1

print(count_2)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
#偶数
eve = [0 for i in range(100000+1)]
#奇数
odd = [0 for i in range(100000+1)]

for i in range(0,n,2):
    eve[v[i]] += 1
for i in range(1,n,2):
    odd[v[i]] += 1

eve_1st_ind = eve.index(max(eve))
odd_1st_ind = odd.index(max(odd))
eve_1st_cnt = max(eve)
odd_1st_cnt = max(odd)

#2番目
eve[eve_1st_ind] = 0
odd[odd_1st_ind] = 0
eve_2nd_ind = eve.index(max(eve))
odd_2nd_ind = odd.index(max(odd))
eve_2nd_cnt = max(eve)
odd_2nd_cnt = max(odd)

#全部同じ文字
if len(set(v))==1: 
    out = n//2
#最初からできてる
elif len(set(eve))==1 and len(set(odd))==1 and (eve_1st_ind!=odd_1st_ind):
    out = 0
elif len(set(eve)) == 1 and (eve_1st_ind!=odd_1st_ind):
    out = n//2- odd_1st_cnt
elif len(set(odd)) == 1 and (eve_1st_ind!=odd_1st_ind):
    out = n//2- eve_1st_cnt
else:
    out1 = n//2-eve_1st_cnt + n//2-odd_2nd_cnt
    out2 = n//2-odd_1st_cnt + n//2-eve_2nd_cnt 
    out = min(out1,out2)
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
#偶数
eve = [0 for i in range(100000+1)]
#奇数
odd = [0 for i in range(100000+1)]

for i in range(0,n,2):
    eve[v[i]] += 1
for i in range(1,n,2):
    odd[v[i]] += 1

eve_1st_ind = eve.index(max(eve))
odd_1st_ind = odd.index(max(odd))
eve_1st_cnt = max(eve)
odd_1st_cnt = max(odd)

#2番目
eve[eve_1st_ind] = 0
odd[odd_1st_ind] = 0
eve_2nd_ind = eve.index(max(eve))
odd_2nd_ind = odd.index(max(odd))
eve_2nd_cnt = max(eve)
odd_2nd_cnt = max(odd)

#全部同じ文字
if len(set(v))==1: 
    out = n//2
#最初からできてる
elif len(set(eve))==1 and len(set(odd))==1 and (eve_1st_ind!=odd_1st_ind):
    out = 0
elif len(set(eve)) == 1:
    out = n//2- odd_1st_cnt
elif len(set(odd)) == 1:
    out = n//2- eve_1st_cnt
else:
    out1 = n//2-eve_1st_cnt + n//2-odd_2nd_cnt
    out2 = n//2-odd_1st_cnt + n//2-eve_2nd_cnt 
    out = min(out1,out2)
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
#偶数
eve = [0 for i in range(100000+1)]
#奇数
odd = [0 for i in range(100000+1)]

for i in range(0,n,2):
    eve[v[i]] += 1
for i in range(1,n,2):
    odd[v[i]] += 1

eve_1st_ind = eve.index(max(eve))
odd_1st_ind = odd.index(max(odd))
eve_1st_cnt = max(eve)
odd_1st_cnt = max(odd)

#2番目
eve[eve_1st_ind] = 0
odd[odd_1st_ind] = 0
eve_2nd_ind = eve.index(max(eve))
odd_2nd_ind = odd.index(max(odd))
eve_2nd_cnt = max(eve)
odd_2nd_cnt = max(odd)

#全部同じ文字
if len(set(v))==1: 
    out = n//2
#最初からできてる
elif len(set(eve))==1 and len(set(odd))==1 and (eve_1st_ind!=odd_1st_ind):
    out = 0
elif set(eve) == 1:
    out = n//2- odd_1st_cnt
elif set(odd) == 1:
    out = n//2- eve_1st_cnt
else:
    out1 = n//2-eve_1st_cnt + n//2-odd_2nd_cnt
    out2 = n//2-odd_1st_cnt + n//2-eve_2nd_cnt 
    out = min(out1,out2)
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
#偶数
eve = [0 for i in range(100000+1)]
#奇数
odd = [0 for i in range(100000+1)]

for i in range(0,n,2):
    eve[v[i]] += 1
for i in range(1,n,2):
    odd[v[i]] += 1

eve_1st_ind = eve.index(max(eve))
odd_1st_ind = odd.index(max(odd))
eve_1st_cnt = max(eve)
odd_1st_cnt = max(odd)

#2番目
eve[eve_1st_ind] = 0
odd[odd_1st_ind] = 0
eve_2nd_ind = eve.index(max(eve))
odd_2nd_ind = odd.index(max(odd))
eve_2nd_cnt = max(eve)
odd_2nd_cnt = max(odd)

#全部同じ文字
if len(set(v))==1: 
    out = n//2
#最初からできてる
elif len(set(eve))==len(set(odd)) and (eve_1st_ind!=odd_1st_ind):
    out = 0
elif set(eve) == 1:
    out = n//2- odd_1st_cnt
elif set(odd) == 1:
    out = n//2- eve_1st_cnt
else:
    out1 = n//2-eve_1st_cnt + n//2-odd_2nd_cnt
    out2 = n//2-odd_1st_cnt + n//2-eve_2nd_cnt 
    out = min(out1,out2)
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
#偶数
eve = [0 for i in range(100000+1)]
#奇数
odd = [0 for i in range(100000+1)]

for i in range(0,n,2):
    eve[v[i]] += 1
for i in range(1,n,2):
    odd[v[i]] += 1

eve_1st_ind = eve.index(max(eve))
odd_1st_ind = odd.index(max(odd))
eve_1st_cnt = max(eve)
odd_1st_cnt = max(odd)

#2番目
eve[eve_1st_ind] = 0
odd[odd_1st_ind] = 0
eve_2nd_ind = eve.index(max(eve))
odd_2nd_ind = odd.index(max(odd))
eve_2nd_cnt = max(eve)
odd_2nd_cnt = max(odd)

#全部同じ文字
if len(set(v))==1: 
    out = n//2
#最初からできてる
elif len(set(eve))==len(set(odd)) and (eve_1st_ind==odd_1st_ind):
    out = 0
else:
    if eve_1st_ind != odd_1st_ind:
        out = n//2-eve_1st_cnt + n//2-odd_1st_cnt
    else:
        out1 = n//2-eve_1st_cnt + n//2-odd_2nd_cnt
        out2 = n//2-odd_1st_cnt + n//2-eve_2nd_cnt 
        out = min(out1,out2)
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
#偶数
eve = [0 for i in range(100000+1)]
#奇数
odd = [0 for i in range(100000+1)]

for i in range(0,n,2):
    eve[v[i]] += 1
for i in range(1,n,2):
    odd[v[i]] += 1

eve_1st_ind = eve.index(max(eve))
odd_1st_ind = odd.index(max(odd))
eve_1st_cnt = max(eve)
odd_1st_cnt = max(odd)

#2番目
eve[eve_1st_ind] = 0
odd[odd_1st_ind] = 0
eve_2nd_ind = eve.index(max(eve))
odd_2nd_ind = odd.index(max(odd))
eve_2nd_cnt = max(eve)
odd_2nd_cnt = max(odd)

#全部同じ文字
if len(set(v))==1: #残り
    out = n//2
#最初からできてる
elif len(set(eve))==len(set(odd)):
    out = 0
else:
    if eve_1st_ind != odd_1st_ind:
        out = n//2-eve_1st_cnt + n//2-odd_1st_cnt
    else:
        out1 = n//2-eve_1st_cnt + n//2-odd_2nd_cnt
        out2 = n//2-odd_1st_cnt + n//2-eve_2nd_cnt 
        out = min(out1,out2)
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
#偶数
eve = [0 for i in range(100000+1)]
#奇数
odd = [0 for i in range(100000+1)]

for i in range(0,n,2):
    eve[v[i]] += 1
for i in range(1,n,2):
    odd[v[i]] += 1

eve_1st_ind = eve.index(max(eve))
odd_1st_ind = odd.index(max(odd))
eve_1st_cnt = max(eve)
odd_1st_cnt = max(odd)

#2番目
eve[eve_1st_ind] = 0
odd[odd_1st_ind] = 0
eve_2nd_ind = eve.index(max(eve))
odd_2nd_ind = odd.index(max(odd))
eve_2nd_cnt = max(eve)
odd_2nd_cnt = max(odd)

#全部同じ文字
if len(set(v))==1: #残り
    out = n//2
#最初からできてる
elif len(set(eve))==len(set(odd)):
    out = 0
else:
    out1 = n//2-eve_1st_cnt + n//2-odd_2nd_cnt
    out2 = n//2-odd_1st_cnt + n//2-eve_2nd_cnt 
    out = min(out1,out2)
    
print(out)

Submission status: Wrong Answer

Solution code:
n=int(input())
v=list(map(int,input().split()))
#偶数
eve = [0 for i in range(100000+1)]
#奇数
odd = [0 for i in range(100000+1)]

for i in range(0,n,2):
    eve[v[i]] += 1
for i in range(1,n,2):
    odd[v[i]] += 1

eve_1st_ind = eve.index(max(eve))
odd_1st_ind = odd.index(max(odd))
eve_1st_cnt = max(eve)
odd_1st_cnt = max(odd)

#2番目
eve[eve_1st_ind] = 0
odd[odd_1st_ind] = 0
eve_2nd_ind = eve.index(max(eve))
odd_2nd_ind = odd.index(max(odd))
eve_2nd_cnt = max(eve)
odd_2nd_cnt = max(odd)

#同じ場合
if eve_1st_cnt == odd_1st_cnt and eve_1st_ind==odd_1st_ind:
    #残り
    out = (n//2-eve_1st_cnt)+(n//2-min(eve_2nd_cnt,odd_2nd_cnt))
#最初からできてる
elif eve_1st_cnt == odd_1st_cnt and odd_1st_cnt==n//2:
    out = 0
else:
    out1 = n//2-eve_1st_cnt + n//2-odd_2nd_cnt
    out2 = n//2-odd_1st_cnt + n//2-eve_2nd_cnt 
    out = min(out1,out2)
    
print(out)

Submission status: Wrong Answer

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

k = [[0]*2 for i in range(10**5+1)]
g = [[0]*2 for i in range(10**5+1)]
# k = [[0]*2 for i in range(10)]
# g = [[0]*2 for i in range(10)]

_ksum = 0
_gsum = 0

for i in range(N):
    if i % 2 == 0:
        k[A[i]][0] += 1
        k[A[i]][1] = A[i]
        _ksum += 1
    else:
        g[A[i]][0] += 1
        g[A[i]][1] = A[i]
        _gsum += 1

_kmax = 0
_gmax = 0

b_k = k.copy()
b_g = g.copy()

b_k.sort()
b_g.sort()

if b_k[-1][1] != b_g[-1][1]:
    print(_ksum-b_k[-1][0]+_gsum-b_g[-1][0])

else:
    print(max(_ksum-b_k[-1][0]+_gsum-b_g[-2][0], _ksum-b_k[-2][0]+_gsum-b_g[-1][0]))

Submission status: Wrong Answer

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

k = [[0]*2 for i in range(10**5+1)]
g = [[0]*2 for i in range(10**5+1)]
# k = [[0]*2 for i in range(10)]
# g = [[0]*2 for i in range(10)]

_ksum = 0
_gsum = 0

for i in range(N):
    if i % 2 == 0:
        k[A[i]][0] += 1
        k[A[i]][1] = A[i]
        _ksum += 1
    else:
        g[A[i]][0] += 1
        g[A[i]][1] = A[i]
        _gsum += 1

_kmax = 0
_gmax = 0

b_k = k.copy()
b_g = g.copy()

b_k.sort()
b_g.sort()

if b_k[-1][1] != b_g[-1][1]:
    print(_ksum-b_k[-1][0]+_gsum-b_g[-1][0])

elif b_k[-1][0] > b_g[-1][0]:
    print(_ksum-b_k[-1][0]+_gsum-b_g[-2][0])
else:
    print(_ksum-b_k[-2][0]+_gsum-b_g[-1][0])

Submission status: Wrong Answer

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

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	ki = defaultdict(int)
	gu = defaultdict(int)
	for i in range(n):
		if i % 2 == 0:
			gu[v[i]] += 1
		else:
			ki[v[i]] += 1
	km = 0
	kmi = 0
	ksm = 0
	ksmi = 0
	gm = 0
	gsm = 0
	gmi = 0
	gsmi = 0
	for k, v in ki.items():
		if v > km:
			km = v
			kmi = k
	for k, v in ki.items():
		if k == kmi:
			continue
		if v > ksm:
			ksm = v
			ksmi = k

	for k, v in gu.items():
		if v > gm:
			gm = v
			gmi = k
	for k, v in gu.items():
		if k == gmi:
			continue
		if v > gsm:
			gsm = v
			gsmi = k
	ks = sum(ki.values()) - km
	gs = sum(gu.values()) - gm
	if kmi == gmi:
		if km < gm:
			ks = ks - ksm + km
		else:
			gs = gs - gsm + gm
	print(ks + gs)
	return 0

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	ki = defaultdict(int)
	gu = defaultdict(int)
	for i in range(n):
		if i % 2 == 0:
			gu[v[i]] += 1
		else:
			ki[v[i]] += 1
	km = 0
	kmi = 0
	ksm = 0
	ksmi = 0
	gm = 0
	gsm = 0
	gmi = 0
	gsmi = 0
	for k, v in ki.items():
		if v > km:
			km = v
			kmi = k
	for k, v in ki.items():
		if k == kmi:
			continue
		if v > ksm:
			ksm = v
			ksmi = k

	for k, v in gu.items():
		if v > gm:
			gm = v
			gmi = k
	for k, v in gu.items():
		if k == gmi:
			continue
		if v > gsm:
			gsm = v
			gsmi = k
	ks = sum(ki.values()) - km
	gs = sum(gu.values()) - gm
	if kmi == gmi:
		if km < gm:
			ks = ks - ksm + km
		else:
			gs = gs - gsm + gm
	# print(ki)
	# print(gu)
	# print(ks)
	# print(gs)
	print(ks + gs)
	return 0

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

def main():
	n = int(input().strip())
	v = list(map(int, input().strip().split()))
	ki = defaultdict(int)
	gu = defaultdict(int)
	for i in range(n):
		if i % 2 == 0:
			gu[v[i]] += 1
		else:
			ki[v[i]] += 1
	km = 0
	kmi = 0
	ksm = 0
	ksmi = 0
	gm = 0
	gsm = 0
	gmi = 0
	gsmi = 0
	for k, v in ki.items():
		if v > km:
			km = v
			kmi = k
	for k, v in ki.items():
		if k == kmi:
			continue
		if v > ksm:
			ksm = v
			ksmi = k

	for k, v in gu.items():
		if v > gm:
			gm = v
			gmi = k
	for k, v in gu.items():
		if k == gmi:
			continue
		if v > gsm:
			gsm = v
			gsmi = k
	ks = sum(ki.values()) - km
	gs = sum(gu.values()) - gm
	if kmi == gmi:
		if km < gm:
			ks = ks - ksm + km
		else:
			gs = gs - gsm + gm
	# print(ki)
	# print(gu)
	# print(ks)
	# print(gs)
	print(ks + gs)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(V):
    n = len(V)
    ac = Counter(V[::2]).most_common(2)
    bc = Counter(V[1::2]).most_common(2)
    print(ac,bc)
    if ac[0][0] != bc[0][0]:
        return n - ac[0][1] - bc[0][1]
    else:
        if len(bc) == 1 or len(ac) == 1:
            return n // 2
        else:
            return n - max(ac[0][1] + bc[1][1], ac[1][1] + bc[0][1])


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