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

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

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

c = Counter(v_even)
mode1 = c.most_common(1)
cnt1 = mode1[0][1]

cnt2 = 0
d = Counter(v_odd)
mode2 = d.most_common()
for i in range(len(mode2)):
    if  mode1[0][0]!=mode2[i][0]:
        cnt2 = mode2[i][1]
        
print(n-cnt1-cnt2)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []
for i, num in enumerate(v):
    if (i+1) % 2 != 0:
        odd.append(num)
    else:
        even.append(num)

odds = collections.Counter(odd).most_common()
evens = collections.Counter(even).most_common()

cnt_odd = 0
cnt_even = 0

ans = 0
if odds[0][0]  == evens[0][0]:
    if len(evens) == 1 and len(odds) == 1:
        ans = evens[0][1]
        print(ans)
        exit()

    ans1 = 10 ** 5
    ans2 = 10 ** 5
    if len(evens) > 1:
        for i, e in enumerate(evens):
            if i != 1:
                cnt_even += e[1]
        for i, o in enumerate(odds):
            if i > 0:
                cnt_odd += o[1]
        ans1 = cnt_even + cnt_odd
    if len(odds) > 1:
        for i, e in enumerate(evens):
            if i > 0:
                cnt_even += e[1]
        for i, o in enumerate(odds):
            if i != 1:
                cnt_odd += o[1]
        ans2 = cnt_even + cnt_odd
    ans = min(ans1, ans2)
    print(ans)
    exit()

for i, o in enumerate(odds):
    if i > 0:
        cnt_odd += o[1]
for i, e in enumerate(evens):
    if i > 0:
        cnt_even += e[1]
ans = cnt_odd + cnt_even

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

odd = []
even = []
for i, num in enumerate(v):
    if (i+1) % 2 != 0:
        odd.append(num)
    else:
        even.append(num)

odds = collections.Counter(odd).most_common()
evens = collections.Counter(even).most_common()

ans = 0
if odds[0][0]  == evens[0][0]:
    if len(evens) > 1:
        val0 = evens[0][0]
        cnt0 = evens[0][1]
        val1 = evens[1][0]
        cnt1 = evens[1][1]
        evens[0] = (val1, cnt0)
        evens[1] = (val0, cnt1)
    elif len(odds) > 1:
        val0 = odds[0][0]
        cnt0 = odds[0][1]
        val1 = odds[1][0]
        cnt1 = odds[1][1]
        odds[0] = (val1, cnt0)
        odds[1] = (val0, cnt1)
    else:
        ans = evens[0][1]
        print(ans)
        exit()

cnt_odd = 0
cnt_even = 0

for i, o in enumerate(odds):
    if i > 0:
        cnt_odd += o[1]
for i, e in enumerate(evens):
    if i > 0:
        cnt_even += e[1]
ans = cnt_odd + cnt_even

print(ans)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=II()
  l=LI()

  if n==4 and ' '.join(str(x) for x in l)=='3 1 3 2':
    exit()

  l1=[]
  l2=[]

  for i in range(len(l)):
    if i%2==0:
      l1.append(l[i])
    else:
      l2.append(l[i])

  l1.sort()
  l2.sort()

  a1=[l1[0],1]
  a2=[0,0]
  b1=[l2[0],1]
  b2=[0,0]

  _a=l1[0]
  c1=1
  for x in l1[1:]:
    if _a==x:
      c1+=1
    else:
      if c1>a1[1]:
        if a1[0]!=l1[0]:
          a2[0]=a1[0]
          a2[1]=a1[1]
        a1[0]=_a
        a1[1]=c1
      elif c1>a2[1]:
        if a1[0]!=_a:
          a2[0]=_a
          a2[1]=c1
      _a=x
      c1=1
  if c1>a1[1]:
    if a1[0]!=l1[0]:
      a2[0]=a1[0]
      a2[1]=a1[1]
    a1[0]=_a
    a1[1]=c1
  elif c1>a2[1]:
    if a1[0]!=_a:
      a2[0]=_a
      a2[1]=c1

  _b=l2[0]
  c2=1
  for x in l2[1:]:
    if _b==x:
      c2+=1
    else:
      if c2>b1[1]:
        if b1[0]!=l2[0]:
          b2[0]=b1[0]
          b2[1]=b1[1]
        b1[0]=_b
        b1[1]=c2
      elif c2>b2[1]:
        if b1[0]!=_b:
          b2[0]=_b
          b2[1]=c2
      _b=x
      c2=1
  if c2>b1[1]:
    if b1[0]!=l2[0]:
      b2[0]=b1[0]
      b2[1]=b1[1]
    b1[0]=_b
    b1[1]=c2
  elif c2>b2[1]:
    if b1[0]!=_b:
      b2[0]=_b
      b2[1]=c2

  if a1[0]!=b1[0]:
    return len(l1)-a1[1]+len(l2)-b1[1]
  else:
    return min(len(l1)-a1[1]+len(l2)-b2[1],len(l1)-a2[1]+len(l2)-b1[1])

# main()
print(main())

Submission status: Wrong Answer

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1

#ソートして一番目、二番目を見る
odd_sorted  = sorted(odd.items(), key = lambda x : -x[1])
even_sorted  = sorted(even.items(), key = lambda x : -x[1])




#候補が同じ場合
if odd_sorted[0][0] == even_sorted[0][0]:
    #奇数も偶数も2番目が存在する？
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        #数が大きい方を採用
        if odd_sorted[0][1] > even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        elif odd_sorted[0][1] < even_sorted[0][1]:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
        else:
            #両者が一致した場合
            if odd_sorted[1][1] >= even_sorted[1][1]:
                ans_odd = odd_sorted[1][0]
                ans_even = even_sorted[0][0]
            elif odd_sorted[1][1] < even_sorted[1][1]:
                ans_odd = odd_sorted[0][0]
                ans_even = even_sorted[1][0]

    #お互いに二番目が存在しない(ただし数は必ず一致するのでどちらか)
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    #奇数に2番目が存在しない
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    #偶数に2番目が存在しない
    else: #len(even.keys()):
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1


print(odd_sorted)
print(even_sorted)

print(ans_odd, ans_even)
print(ans)

Submission status: Wrong Answer

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1

#ソートして一番目、二番目を見る
odd_sorted  = sorted(odd.items(), key = lambda x : -x[1])
even_sorted  = sorted(even.items(), key = lambda x : -x[1])




#候補が同じ場合
if odd_sorted[0][0] == even_sorted[0][0]:
    #奇数も偶数も2番目が存在する？
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        #数が大きい方を採用
        if odd_sorted[0][1] >= even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        else:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
    #お互いに二番目が存在しない(ただし数は必ず一致するのでどちらか)
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    #奇数に2番目が存在しない
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    #偶数に2番目が存在しない
    else: #len(even.keys()):
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1


print(ans)

Submission status: Wrong Answer

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

odd = {}
even = {}

for i in range(len(v)):
    if i % 2 == 1:
        if v[i] in odd:
            odd[v[i]] += 1
        else:
            odd[v[i]] = 1
    else:
        if v[i] in even:
            even[v[i]] += 1
        else:
            even[v[i]] = 1

#ソートして一番目、二番目を見る
odd_sorted  = sorted(odd.items(), key = lambda x : x[1])
even_sorted  = sorted(even.items(), key = lambda x : x[1])




#候補が同じ場合
if odd_sorted[0][0] == even_sorted[0][0]:
    #奇数も偶数も2番目が存在する？
    if len(odd.keys()) > 1 and len(even.keys()) > 1:
        #数が大きい方を採用
        if odd_sorted[0][1] >= even_sorted[0][1]:
            ans_odd = odd_sorted[0][0]
            ans_even = even_sorted[1][0]
        else:
            ans_odd = odd_sorted[1][0]
            ans_even = even_sorted[0][0]
    #お互いに二番目が存在しない(ただし数は必ず一致するのでどちらか)
    elif len(odd.keys()) == 1 and len(even.keys()) == 1:
        ans_odd = -1
        ans_even = even_sorted[0][0]
    #奇数に2番目が存在しない
    elif len(odd.keys()):
        ans_odd = odd_sorted[0][0]
        ans_even = even_sorted[1][0]
    #偶数に2番目が存在しない
    else: #len(even.keys()):
        ans_odd = odd_sorted[1][0]
        ans_even = even_sorted[0][0]

else:
    ans_odd = odd_sorted[0][0]
    ans_even = even_sorted[0][0]

ans = 0
for i in range(len(v)):
    if i % 2:
        if v[i] != ans_odd:
            ans += 1
    else:
        if v[i] != ans_even:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = map(int, input().split())
from collections import defaultdict
ans = defaultdict(int)
result = int(n / 2)
for i in s:
  ans[i] += 1

ln = len(ans)
if ln == 1:
  print(result)
elif ln == 2:
  ind = 0
  a = 0
  z = sorted(ans.items(), key=lambda x: x[1], reverse=True)
  for _, v in z:
    if ind < 2:
      a += abs(result - v)
    else:
      break
    ind += 1
  print(a)
else:
  z = sorted(ans.items(), key=lambda x: x[1], reverse=True)
  print(n - z[0][1] - z[1][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
s = map(int, input().split())
from collections import defaultdict
ans = defaultdict(int)
result = int(n / 2)
for i in s:
  ans[i] += 1

ln = len(ans)
if ln == 1:
  print(result)
elif ln == 2:
  ind = 0
  a = 0
  z = sorted(ans.items(), key=lambda x: x[1], reverse=True)
  for _, v in z:
    if ind < 2:
      a += abs(result - v)
    else:
      break
    ind += 1
  print(a)
else:
  z = sorted(ans.items(), key=lambda x: x[1], reverse=True)
  print(n - z[0][1])

Submission status: Wrong Answer

Solution code:
n = int(input())
s = map(int, input().split())
from collections import defaultdict
ans = defaultdict(int)
result = int(n / 2)
for i in s:
  ans[i] += 1

ln = len(ans)
if ln == 1:
  print(result)
else:
  ind = 0
  a = 0
  z = sorted(ans.items(), key=lambda x: x[1], reverse=True)
  for _, v in z:
    if ind < 2:
      a += abs(result - v)
    else:
      break
    ind += 1
  print(a)

Submission status: Wrong Answer

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

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

odd_h = {}
even_h = {}

for i in range(n):
    if i % 2:
        if v[i] in odd_h:
            odd_h[v[i]] += 1
        else:
             odd_h[v[i]] = 1
    else:
        if v[i] in even_h:
            even_h[v[i]] += 1
        else:
             even_h[v[i]] = 1


odd_h = sorted(odd_h.items(), key=lambda x: x[1])
even_h = sorted(even_h.items(), key=lambda x: x[1])


if odd_h[0][0] == even_h[0][0] and odd_h[0][1] >= even_h[0][1]:
    #odd と　evenが同じ数だと次に大きいものを使う。
    max_odd = odd_h[0][0]
    if len(even_h) > 1:
        max_even = even_h[1][0]
    else:
        max_even = -99
elif odd_h[0][0] == even_h[0][0]:
    if len(odd_h) > 1:
        max_odd = odd_h[1][0]
    else:
        max_odd = -99
    max_even = even_h[0][0]

else:
    max_odd = odd_h[0][0]
    max_even = even_h[0][0]

ans = 0
for i in range(n):
    if i % 2:
        ans += 1 if v[i] != max_odd else 0
    else:
        ans +=  1 if v[i] != max_even else 0

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a = v[0]
b = v[1]

if a == b:
    print(int(n/2))
    exit()

ans = 0
for i in range(0,n):
    if i % 2:
        if v[i] != b:
            ans += 1
    else:
        if v[i] != a:
            ans += 1

print(ans)

Submission status: Wrong Answer

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

even_map = {}
for i in range(0, n)[::2]:
    if v[i] not in even_map:
        even_map[v[i]] = 1
    else:
        even_map[v[i]] += 1

odd_map = {}
for i in range(1, n)[::2]:
    if v[i] not in odd_map:
        odd_map[v[i]] = 1
    else:
        odd_map[v[i]] += 1


odd_list = list(odd_map.items())
odd_list.sort(key=lambda x: x[1], reverse=True)
even_list = list(even_map.items())
even_list.sort(key=lambda x: x[1], reverse=True)

odd = odd_list[0][0]
even = even_list[0][0]

while odd == even:
    if odd_list[0][1] > even_list[0][1]:
        if len(even_list) > 1:
            even = even_list[1][0]
            even_list.pop(0)
        else:
            even = odd + 1
    else:
        if len(odd_list) > 1:
            odd = odd_list[1][0]
            odd_list.pop(0)
        else:
            odd = even + 1


ans = 0
for k, v in odd_map.items():
    if k != odd:
        ans += v
for k, v in even_map.items():
    if k != even:
        ans += v
print(ans)

Submission status: Wrong Answer

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

even_map = {}
for i in range(0, n)[::2]:
    if v[i] not in even_map:
        even_map[v[i]] = 1
    else:
        even_map[v[i]] += 1

odd_map = {}
for i in range(1, n)[::2]:
    if v[i] not in odd_map:
        odd_map[v[i]] = 1
    else:
        odd_map[v[i]] += 1


odd_list = list(odd_map.items())
odd_list.sort(key=lambda x: x[1], reverse=True)
even_list = list(even_map.items())
even_list.sort(key=lambda x: x[1], reverse=True)

odd = odd_list[0][0]
even = even_list[0][0]

if odd == even:
    if odd_list[0][1] > even_list[0][1]:
        if len(even_list) > 1:
            even = even_list[1][0]
        else:
            even = odd + 1
    else:
        if len(odd_list) > 1:
            odd = odd_list[1][0]
        else:
            odd = even + 1


ans = 0
for k, v in odd_map.items():
    if k != odd:
        ans += v
for k, v in even_map.items():
    if k != even:
        ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - /\/\/\/
https://atcoder.jp/contests/abc111/tasks/arc103_a

"""
import sys


from collections import Counter

def solve(n, nums):
    e_cnt = Counter(nums[::2])
    o_cnt = Counter(nums[1::2])
    e = e_cnt.most_common()
    o = o_cnt.most_common()

    if len(e_cnt) == 1 or len(o_cnt) == 1:
        if len(e_cnt) == 1 and len(o_cnt) == 1:
            if e[0][0] == o[0][0]:
                return len(nums)//2
            else:
                return 0
        else:
            if len(e_cnt) == 1:
                ans, x = len(nums)//2, e[0][0]
                if o[0][0] == x:
                    return ans - o[1][1]
                else:
                    return ans - o[0][1]
            else:
                ans, x = len(nums), o[0][0]
                if e[0][0] == x:
                    return ans - e[1][1]
                else:
                    return ans - e[0][1]

    if e[0][0] == o[0][0]:
        ans1 = len(nums) - (e[0][1] + o[1][1])
        ans2 = len(nums) - (o[0][1] + e[1][1])
        return min(ans1, ans2)
    else:
        return len(nums) - (e[0][1] + o[0][1])



def main(args):
    n = int(input())
    nums = [int(i) for i in input().split()]
    ans = solve(n, nums)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
C - /\/\/\/
https://atcoder.jp/contests/abc111/tasks/arc103_a

"""
import sys


from collections import Counter

def solve(n, nums):
    evens = nums[::2]
    odds = nums[1::2]
    e_cnt = Counter(evens)
    o_cnt = Counter(odds)

    if len(e_cnt) == 1 and len(o_cnt) == 1:
        if evens[0] == odds[0]:
            return len(evens)
        else:
            return 0
    ans = len(nums)
    e = e_cnt.most_common()
    o = o_cnt.most_common()
    if e[0][0] == o[0][0]:
        if e[0][1] >= o[0][1]:
            ans -= (e[0][1] + o[1][1])
        else:
            ans -= (o[0][1] + e[1][1])
    else:
        ans -= (e[0][1] + o[0][1])
    return ans


def main(args):
    n = int(input())
    nums = [int(i) for i in input().split()]
    ans = solve(n, nums)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
n = input()
li = list(map(int,input().split()))
li0 = li[0::2]
li1 = li[1::2]

cnt_li0 = {}
cnt_li1 = {}
for n in li0 :
    if n not in cnt_li0 :
        cnt_li0[n] = 0
    cnt_li0[n] = cnt_li0[n]+1

for n in li1 :
    if n not in cnt_li1 :
        cnt_li1[n] = 0
    cnt_li1[n] = cnt_li1[n]+1

cnt_li0 = sorted(cnt_li0.items(), key=lambda x: -x[1])
cnt_li1 = sorted(cnt_li1.items(), key=lambda x: -x[1])

try :
    if cnt_li0[0][0] == cnt_li1[0][0] :
        if cnt_li0[0][1] < cnt_li1[0][1] :
            n = len(li) - (cnt_li0[1][1] + cnt_li1[0][1])
        else :
            n = len(li) - (cnt_li0[0][1] + cnt_li1[1][1])
    else :
        n = len(li) - (cnt_li0[0][1] + cnt_li1[0][1])
    print(n)
except IndexError :
    print(cnt_li0[0][1])

Submission status: Wrong Answer

Solution code:
import collections
c = collections.Counter

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

v_odd = v[::2]
v_eve = v[1::2]

c1 = c(v_odd).most_common(2)
c2 = c(v_eve).most_common(2)

if len(c1) == 1 and len(c2) == 1:
    ans = int(N/2)
else:
    if c1[0] != c2[0]:
        ans = N - c1[0][1] - c2[0][1]
    else:
        if c1[1][1] >= c2[1][1]:
            ans = N - c1[1][1] - c2[0][1]
        else:
            ans = N - c1[0][1] - c2[1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

def counter(c):
    c = collections.Counter(c)
    a,b = zip(*c.most_common())
    a = list(a)
    b = list(b)
    if b[0] == N/2 :
        b.append(0)
        return a,b
    else:
        a,b =zip(*c.most_common(2))
        a = list(a)
        b = list(b)
        return a,b

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

v_odd = v[::2]
v_eve = v[1::2]

v_o_v,v_o_c = counter(v_odd)
v_e_v,v_e_c = counter(v_eve)

if v_o_v[0] == v_e_v[0]:
    if v_o_c[0] >= v_e_c[0]:
        ans = N - v_e_c[0] - v_o_c[1]
    else:
        ans = N - v_e_c[1] - v_o_c[0]
else:
    ans = N - v_o_c[0] - v_e_c[0]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

def counter(c):
    c = collections.Counter(c)
    a,b = zip(*c.most_common())
    a = list(a)
    b = list(b)
    if b[0] == N/2 :
        a.append(-1)
        b.append(0)
        return a,b
    else:
        a,b =zip(*c.most_common(2))
        a = list(a)
        b = list(b)
        return a,b

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

v_odd = v[::2]
v_eve = v[1::2]

v_o_v,v_o_c = counter(v_odd)
v_e_v,v_e_c = counter(v_eve)

if v_o_v[0] == v_e_v[0]:
    if v_o_c[0] >= v_e_c[0]:
        ans = N - v_e_c[0] - v_o_c[1]
    else:
        ans = N - v_e_c[1] - v_o_c[0]
else:
    ans = N - v_o_c[0] - v_e_c[0]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = []
for i in range(2):
  sort_list = sorted(count_dict[i].items(), key=lambda kv: kv[1])
  cands = []
  value = []
  for item in sort_list:
    value.append(item[1])
    if len(set(value)) > 2:
      break
    cands.append(item)
  candidates.append(cands)

candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)

Submission status: Wrong Answer

Solution code:
import collections

def counter(c):
    c = collections.Counter(c)
    a,b = zip(*c.most_common())
    a = list(a)
    b = list(b)
    if b[0] == N/2 :
        a.append(0)
        b.append(0)
        return a,b
    else:
        a,b =zip(*c.most_common(2))
        a = list(a)
        b = list(b)
        return a,b

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

v_odd = v[::2]
v_eve = v[1::2]

v_o_v,v_o_c = counter(v_odd)
v_e_v,v_e_c = counter(v_eve)

if v_o_v[0] == v_e_v[0]:
    if v_o_c[0] >= v_e_c[0]:
        ans = N - v_e_c[0] - v_o_c[1]
    else:
        ans = N - v_e_c[1] - v_o_c[0]
else:
    ans = N - v_o_c[0] - v_e_c[0]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

def counter(c):
    c = collections.Counter(c)
    a,b = zip(*c.most_common())
    if len(b) == 1 :
        a = list(a)
        b = list(b)
        a.append(0)
        b.append(0)
        return a,b
    else:
        a,b =zip(*c.most_common(2))
        a = list(a)
        b = list(b)
        return a,b

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

v_odd = v[::2]
v_eve = v[1::2]

v_o_v,v_o_c = counter(v_odd)
v_e_v,v_e_c = counter(v_eve)

if v_o_v[0] == v_e_v[0]:
    if v_o_c[0] >= v_e_c[0]:
        ans = N - v_e_c[0] - v_o_c[1]
    else:
        ans = N - v_e_c[1] - v_o_c[0]
else:
    ans = N - v_o_c[0] - v_e_c[0]

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections

if __name__ == '__main__':
    n = int(input())
    v_list = np.array(list(map(int, input().split())))

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

    v_odd_cnt = {}
    v_even_cnt = {}

    for e in set(v_odd):
        v_odd_cnt[str(e)] = np.count_nonzero(v_odd == e)

    for e in set(v_even):
        v_even_cnt[str(e)] = np.count_nonzero(v_even == e)

    answer = -1

    len_v_odd = len(set(v_odd))
    len_v_even = len(set(v_even))
    cnt_v_odd = collections.Counter(v_odd)
    cnt_v_even = collections.Counter(v_even)

    if  len_v_odd == 1 and len_v_even == 1:
        answer = 0
    elif len_v_odd == 1:
        answer = len_v_odd - cnt_v_even.most_common()[0][1]
    elif len_v_even == 1:
        answer = len_v_even - cnt_v_odd.most_common()[0][1]
    else:
        answer = min(len_v_even - cnt_v_even.most_common()[0][1], len_v_odd - cnt_v_odd.most_common()[0][1])

    print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections

if __name__ == '__main__':
    n = int(input())
    v_list = np.array(list(map(int, input().split())))

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

    v_odd_cnt = {}
    v_even_cnt = {}

    for e in set(v_odd):
        v_odd_cnt[str(e)] = np.count_nonzero(v_odd == e)

    for e in set(v_even):
        v_even_cnt[str(e)] = np.count_nonzero(v_even == e)

    answer = -1

    len_v_odd = len(set(v_odd))
    len_v_even = len(set(v_even))
    cnt_v_odd = collections.Counter(v_odd)
    cnt_v_even = collections.Counter(v_even)

    if  len_v_odd == 1 and len_v_even == 1:
        answer = 0
    elif len_v_odd == 1:
        answer = cnt_v_even.most_common()[1][1]
    elif len_v_even == 1:
        answer = cnt_v_odd.most_common()[1][1]
    else:
        answer = min(cnt_v_even.most_common()[1][1], cnt_v_odd.most_common()[1][1])

    print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np


if __name__ == '__main__':
    n = int(input())
    # v_list = np.ndarray(list(map(int, input().split())))
    v_list = np.array(list(map(int, input().split())))

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


    v_odd_cnt = {}
    v_even_cnt = {}

    for e in set(v_odd):
        v_odd_cnt[str(e)] = np.count_nonzero(v_odd == e)

    for e in set(v_even):
        v_even_cnt[str(e)] = np.count_nonzero(v_even == e)

    answer = -1

    if len(set(v_odd)) == 1 and len(set(v_even)) == 1:
        answer = 0
    elif len(set(v_odd)) == 1:
        answer = v_even_cnt[min(v_even_cnt)]
    elif len(set(v_even)) == 1:
        answer = v_odd_cnt[min(v_odd_cnt)]
    else:
        answer = min(v_even_cnt[min(v_even_cnt)], v_odd_cnt[min(v_odd_cnt)])

    print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())

v = list(map(int,input().split()))
v_odd = []
v_eve = []
v_odd_set = []
v_eve_set = []
v_odd_count = []
v_eve_count = []
v_o_max = 0
v_e_max = 0


for i in range(N):
    if i % 2 == 0:
        v_odd.append(v[i])
    else:
        v_eve.append(v[i])

v_odd_set = list(set(v_odd))
v_eve_set = list(set(v_eve))

for c in v_odd_set:
    a = v_odd.count(c)
    v_odd_count.append(a)
    if a == max(v_odd_count):
        v_o_max = c
    else:
        continue

for c in v_eve_set:
    a = v_eve.count(c)
    v_eve_count.append(a)
    if a == max(v_eve_count):
        v_e_max = c
    else:
        continue

v_odd_count.sort()
v_eve_count.sort()


if len(v_odd_count) != 1 and len(v_eve_count) != 1:
    if v_o_max == v_e_max:
        if v_odd_count[-1] >= v_eve_count[-2]:
            print(N - v_eve_count[-1] - v_eve_count[-2])
        else:
            print(N - v_odd_count[-1] - v_eve_count[-2])
    else:
        print(N - v_eve_count[-1] - v_odd_count[-1])
else:
    if v_o_max == v_e_max:
        print(int(N/2))
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 16 16:43:15 2019

@author: avina
"""

n = int(input())
l = list(map(int, input().split()))
d = {}
k = {}
for i in range(n):
    if i%2 != 0:
        if l[i] not in d:
            d[l[i]] = 1
        else:
            d[l[i]]+=1
    else:
        if l[i] not in k:
            k[l[i]] = 1
        else:
            k[l[i]] +=1

a = abs(max(k.values()) -  max(d.values()))
if a ==0 and k == d :
    print(max(k.values()))
else:
    print(a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 16 16:43:15 2019

@author: avina
"""

n = int(input())
l = list(map(int, input().split()))
d = {}
k = {}
for i in range(n):
    if i%2 != 0:
        if l[i] not in d:
            d[l[i]] = 1
        else:
            d[l[i]]+=1
    else:
        if l[i] not in k:
            k[l[i]] = 1
        else:
            k[l[i]] +=1

a = abs(max(k.values()) -  max(d.values()))
if a ==0:
    print(max(k.values()))
else:
    print(a)

Submission status: Wrong Answer

Solution code:

n = int(input())
l = list(map(int, input().split()))
d = {}
for i in l:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
e = max(d)
value = d[e]
if len(d)==1:
    print(value//2)      
else:
    s = list(d.values())
    s.sort()
    
    print(value - s[-2])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 16 16:43:15 2019

@author: avina
"""

n = int(input())
l = list(map(int, input().split()))
v= set(l)
k = []
for i in v:
  k.append(l.count(i))
k.sort(reverse =True)
if len(k) == 1:
  print( k[0]//2)
else:
  print(k[0] - k[1])

Submission status: Wrong Answer

Solution code:
import collections

def main():
    N = int(input())
    V = list(map(int, input().split()))
    ans = 0

    odd_arr = []
    even_arr = []

    for i in range(N):
        if i % 2 == 0:
            odd_arr.append(V[i])
        else:
            even_arr.append(V[i])

    if len(odd_arr) > 1:
        most_num_oddvalue = collections.Counter(odd_arr).most_common()[0][0]
        for j in range(len(odd_arr)):
            if most_num_oddvalue != odd_arr[j]:
                ans += 1

    if len(even_arr) > 1:
        most_num_evenvalue = collections.Counter(even_arr).most_common()[0][0]
        for k in range(len(even_arr)):
            if most_num_evenvalue != even_arr[k]:
                ans += 1

    if most_num_evenvalue == most_num_oddvalue:
        for l in range(len(odd_arr)):
            ans += 1

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = []
for i in range(2):
  candidates.append(sorted(count_dict[i].items(), key=lambda kv: kv[1])[:5])

candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(N-no_move)

Submission status: Wrong Answer

Solution code:
# 2019/05/14
# AtCoder Beginner Contest 111 - C

from operator import itemgetter

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

l_even = list()
l_odd = list()

# Separate Odd or Even
for i in range(n):
    if i % 2 == 0:
        l_even.append(v[i])
    else:
        l_odd.append(v[i])

l_even.sort()
l_odd.sort()
wk_cnt_e = 1
wk_cnt_o = 1

cnt_even = list()
cnt_odd = list()

# Count
for x in range(int(n/2)-1):
    if l_even[x] != l_even[x+1]:
        cnt_even.append([l_even[x], wk_cnt_e])
        wk_cnt_e = 1
    else:
        wk_cnt_e += 1

    if l_odd[x] != l_odd[x+1]:
        cnt_odd.append([l_odd[x], wk_cnt_o])
        wk_cnt_o = 1
    else:
        wk_cnt_o += 1

cnt_even.append([l_even[x+1], wk_cnt_e])
cnt_odd.append([l_odd[x+1], wk_cnt_o])

cnt_even.sort(key=itemgetter(1),reverse=True)
cnt_odd.sort(key=itemgetter(1),reverse=True)

# Max is same
if cnt_even[0][0] == cnt_odd[0][0]:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = n / 2
    elif len(cnt_even) == 1:
        ans = n / 2 - cnt_odd[1][1]
    elif len(cnt_odd) == 1:
        ans = n / 2 - cnt_even[1][1]
    else:
        ans = (n / 2 - cnt_even[1][1]) + (n / 2 - cnt_odd[1][1])
# Max is Not same
else:
    if len(cnt_even) == 1 and len(cnt_odd) == 1:
        ans = 0
    elif len(cnt_even) == 1:
        ans = n / 2 - cnt_odd[0][1]
    elif len(cnt_odd) == 1:
        ans = n / 2 - cnt_even[0][1]
    else:
        ans = (n / 2 - cnt_even[0][1]) + (n / 2 - cnt_odd[0][1])

# Output
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
count_dict = {i:{} for i in range(2)}
#print(count_dict[0])
for i in range(2):
  for j in A[i::2]:
    if j not in count_dict[i]:
      count_dict[i][j] = 1
    else:
      count_dict[i][j] += 1

candidates = []
for i in range(2):
  candidates.append(sorted(count_dict[i].items(), key=lambda kv: kv[1])[:2])

candidates = [i[1]+j[1] for i in candidates[0] for j in candidates[1] if i[0] != j[0]]
no_move = max(candidates) if candidates != [] else len(A) // 2
print(len(A)-no_move)