Problem:


Score : 100 points

Problem Statement

Cat Snuke is learning to write characters.
Today, he practiced writing digits 1 and 9, but he did it the other way around.

You are given a three-digit integer n written by Snuke.
Print the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.

Constraints

111 \leq n \leq 999

n is an integer consisting of digits 1 and 9.

Input

Input is given from Standard Input in the following format:

n

Output

Print the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.

Sample Input 1

119

Sample Output 1

991

Replace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.

Sample Input 2

999

Sample Output 2

111



Sample input:
119


Sample output:
991

Submission status: Runtime Error

Solution code:
s = input()
cha = list(s)
answer = []
for hoge in int_cha:
  if hoge == '1':
    answer.append('9')
  else:
    answer.append('1')
print(''.join(answer))

Submission status: Runtime Error

Solution code:
s = input()
cha = list()
answer = []
for hoge in int_cha:
  if hoge == '1':
    answer.append('9')
  else:
    answer.append('1')
print(''.join(answer))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

if ki[0][0] == gu[0][0] :
    if len(ki) == 1 and len(gu) == 1 :
        print(n/2)
    else :
        if ki[1][1] > gu[1][1]  :
            print(n-ki[1][1]-gu[0][1])
        else :
            print(n-ki[0][1]- gu[1][1])

else :
    print(n-ki[0][1]-gu[0][1])

Submission status: Runtime Error

Solution code:
L = readline()
m = {"1":"9","9","1"}:
res = [m.get(i,i) for i in L]
print "".join(L)

Submission status: Runtime Error

Solution code:
n = str(input())
for i in n:
    if i == 9:
        n[i] = 1
    else:
        n[i] = 9
print(int(n))

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))
for_set_v = v # set用
set_v = set(v)
even = []
odd = []
count = 0 # 置き換えた回数
count_list = []
for num in range(n):
    if num % 2 == 0:
        even.append(v[num])
    else:
        odd.append(v[num])

even_most = Counter(even).most_common()
odd_most = Counter(odd).most_common()
#print(even_most)
#print(odd_most)
if len(set(v)) >= 2:
    if even_most[0][0] != odd_most[0][0]:
        if len(set(even)) != 1:
            count += (n/2) - int(even_most[0][1])
        if len(set(odd)) != 1:
            count += (n/2) - int(odd_most[0][1])
    else:
        try:
            count_list.append(n-int(even_most[0][1])-int(odd_most[1][1]))
            count_list.append(n-int(even_most[1][1])-int(odd_most[0][1]))
            #print(count_list)
            count += int(min(count_list))
        except:
            if len(even_most) == 1:
                count += (n/2)-int(odd_most[1][1])
            elif len(odd_most) == 1:
                count += (n/2)-int(even_most[1][1])
else:
    count += (n/2)
print(int(count))

Submission status: Runtime Error

Solution code:
n = int(input())
XY = [list(map(int, input().split())) for _ in range(n)]
mod = sum(XY[0])%2
for x, y in XY:
    if mod != (x+y)%2:
        print(-1)
        exit()

m = 33-mod
print(m)
D = [2**i for i in range(31, -1, -1)]
if mod:
    D.append(1)

print(" ".join(map(str, D)))
for x, y in XY:
    w = " "
    for d in D:
        if x-y >= 0 and x+y >= 0:
            w += "R"
            x -= d
        elif x-y < 0 and x+y >= 0:
            w += "U"
            y -= d
        elif x-y >= 0 and x+y < 0:
            w += "D"
            y += d
        else:
            w += "L"
            x += d
    print(w)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
k = n//2
a = list(map(int, input().split()))
p = []
q = []
for i in range(k):
    p.append(a[2*i])
    q.append(a[2*i+1])
s = Counter(p).most_common()
t = Counter(q).most_common()
u, v = len(s), len(t)
ans = 0
if s[0][0] == t[0][0]:
    if u == 1 and v == 1:
        ans = k
    elif u == 1:
        ans = k - t[1][1]
    elif v == 1:
        ans = k - s[1][1]
    else:
        comp = max(s[1][1], t[1][1])
        ans = n - s[0][1] - comp
else:
    ans = n - s[0][1] - t[0][1]
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
	print(1110-N)

Submission status: Runtime Error

Solution code:
a = input()
for i in a:
    print(i == "1" and "9" or "1" end="")

Submission status: Runtime Error

Solution code:
import collections

def answer(list,n):
    Even = collections.Counter(list[::2]).most_common(2)
    Odd = collections.Counter(list[1::2]).most_common(2)

    if Even[0][0] != Odd[0][0]:
        return n - Even[0][1] - Odd[0][1]
    else:
        if len(Even) == 1 or len(Odd) == 1:
            return n // 2
        else:
            return n - max(Even[0][1]+Odd[1][1],Even[1][1]+Odd[0][1])

N = int(input())
list = input().split(" ")
print(answer(list,N))

Submission status: Runtime Error

Solution code:
n = int(input())

m = 1110 - n

print m

Submission status: Runtime Error

Solution code:
print(input().translate("1": "9", "9": "1"))

Submission status: Runtime Error

Solution code:
from collections import Counter

def f(n,v):
	a=Counter(v[0::2]).most_common()
	b=Counter(v[1::2]).most_common()
	
	if a[0][0]!=b[0][0]:
		return n-(a[0][1]+b[0][1])
	elif len(a) == 1 and len(b) == 1:
		return int(n/2)
	else:
		return max(n-(a[1][1]+b[0][1]),n-(a[0][1]+b[1][1]))

if __name__=="__main__":
	x=int(input())
	data=[int(i) for i in input().split()]
	print(f(x,data))

Submission status: Runtime Error

Solution code:
n = int(input())
int a, b, c

a*100 + b*10 + c == n

if a == 9:
  a = 1
if b == 9:
   b = 1
if c == 9:
   c = 1
elif:
  a, b, c = 9
  
n = a*100 + b*10 + c
print(n)

Submission status: Runtime Error

Solution code:
n = int(input())
int a, b, c

n == a*100 + b*10 + c

if a == 9:
  a = 1
if b == 9:
  b = 1
if c == 9:
  c = 1
elif:
  a, b, c = 9
  
n = a*100 + b*10 + c
print(n)

Submission status: Runtime Error

Solution code:
n = int(input())
int a, b, c

n == a*100 + b*10 + c

if a == 9:
  a = 1
elif b == 9:
  b = 1
elif c == 9:
  c = 1
  
elif :
  a, b, c = 9
  
n = a*100 + b*10 + c
print(n)

Submission status: Runtime Error

Solution code:
n = int(input())
int a, b, c

n == a*100 + b*10 + c

if a == 9:
  a = 1
elif b == 9:
  b = 1
elif c == 9:
  c = 1
  
elif a, b, c = 9

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

input = raw_input()

result = ""
for i in range(0, 3):
    if input[i] == "1":
        result += "9"
    else input[i] == "9":
        result += "1"
    else:
        result += input[i]

print int(result)

Submission status: Runtime Error

Solution code:
n = read()

arr = list(n)
output = ""
for e in arr
  if e == '1':
    output += '9'
  else:
    output += '1'

print(output)

Submission status: Runtime Error

Solution code:
N = int(input())
NA = int(input())
NX = NA.split(" ")
NW = []
for i in range (1,N+1):
    Ni = int(NX.count(i))
    NW.append(Ni)
NN = NW.sort()
print(NW)
S = 0
for x in range (0,N-2):
    S = S + NW[x]
print(S)

Submission status: Runtime Error

Solution code:
from collections import Counter
a,b,n = 0,0,int(input())
n1 = n//2 + n%2
n2 = n//2
z = list(map(int,input().split()))
a,b = Counter(z[0::2]).most_common(2),Counter(z[1::2]).most_common(2)

if a[0] == b[0]:
	print(n2)
elif len(a) == 1 and len(b) == 1:
    print(int(n/2))
else:
	print(n1 - a[0][1]+n2 - b[0][1])

Submission status: Runtime Error

Solution code:
num = list(int(input().rstrip()))
res = ''.join([ 1 if a % 9 == 0 else 9 for a in num ])
print(res)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

import collections

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

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

v_l_odd = []
v_l_even = []

for i in range(n):
    if i % 2 == 0:
        v_l_odd.append(v_l[i])
    else:
        v_l_even.append(v_l[i])

max_odd = collections.Counter(v_l_odd)
mon = max_odd.most_common(1)[0][0]
max_even = collections.Counter(v_l_even)
men = max_even.most_common(1)[0][0]

if mon == men:
    if max(max_odd.most_common(2)[1][1], max_even.most_common(2)[1][1]) == max_odd.most_common(2)[1][1]:
        mon = max_odd.most_common(2)[1][1]
    else:
        men = max_even.most_common(2)[1][1]

v_l_odd_l = []
v_l_even_l = []

for i in range(n):
    if i % 2 == 0:
        if v_l[i] != mon:
            v_l_odd_l.append(v_l[i])
    else:
        if v_l[i] != men:
            v_l_even_l.append(v_l[i])

print(len(v_l_odd_l) + len(v_l_even_l))

Submission status: Runtime Error

Solution code:
n = input('')
i == ''

if i == 1:
  i = 9
elsif i == 9:
  i = 1
  
print(n)

Submission status: Runtime Error

Solution code:
n =input()
if 111 =< n <= 999:

Submission status: Runtime Error

Solution code:
n = input()
 
ans = ''
for w in str(s):
    if w == '1':
        ans += '9'
    elif w == '9':
        ans += '1'
    else:
        ans += str(w)
        
print(int(ans))

Submission status: Runtime Error

Solution code:
n = int(input())

ans = ''
for w in str(s):
    if w == '1':
        ans += '9'
    elif w == '9':
        ans += '1'
    else:
        ans += str(w)
        
print(int(ans))

Submission status: Runtime Error

Solution code:
n = input()
n = n.replace("1","a")
n = n.replace("9","1")
n = n.replace("a,"9")
print(n)

Submission status: Runtime Error

Solution code:
s = input()
scopy = list(s)
for i in scopy:
    if i == "1":
        scopy[int(i)-1] = "9"
    if i == "9":
        scopy[int(i)-1] = "1"
        
news = ''.join(scopy)
print(news)

Submission status: Runtime Error

Solution code:

def answer(in0, in1):
    even = {}
    odd = {}

    list = in1.split(" ")

    for i in range(len(list)):
        n = list[i]
        if i % 2 == 0:
            odd[n] = odd.get(n, 0) + 1
        else:
            even[n] = even.get(n, 0) + 1

    odd = sorted(
        [{'key': k, 'value': odd[k]} for k in odd],
        key=lambda x: (-x['value'], int(x['key'])))

    even = sorted(
        [{'key': k, 'value': even[k]} for k in even],
        key=lambda x: (-x['value'], int(x['key'])))

    oddMax = odd[0]
    evenMax = even[0]

    #print(odd)
    #print(even)

    # 奇数偶数ともにトップのキーが一緒
    if oddMax['key'] == evenMax['key']:
        # 文字列が全部同じだからどっちかを書き換えればOK
        if len(even) == 1 and len(odd) == 1:
            return int(int(in0) / 2)

        if oddMax['value'] > evenMax['value']:
            evenMax = even[1]
        else:
            oddMax = odd[1]

    oddCount = 0
    evenCount = 0

    for v in odd:
        if v['key'] != oddMax['key']:
            oddCount += v['value']

    for v in even:
        if v['key'] != evenMax['key']:
            evenCount += v['value']

    return oddCount + evenCount

print(answer(input(), input()))

Submission status: Runtime Error

Solution code:
#encoding utf-8
from collections import Counter
def main(n,v):
    odd = Counter(v[0::2]).most_common(2) + [(0,0)]
    even = Counter(v[1::2]).most_common(2) + [(0,0)]

    if odd[0][0] == even[0][0]:
        ans = min(n-odd[0][1]-even[1][1],
        n-odd[1][1]-even[0][1])
    else:
        ans = n-odd[0][1]-even[0][1]
    print(ans)


if __name__ == "__main__":
    n = int(input())
    v = list(int(i) for i in input().split())
    main(n,v)

Submission status: Runtime Error

Solution code:
n = input()
ans = ''
for x in n:
  if x == '1':
    ans += '9'
   else:
    ans += '1'
print(ans)

Submission status: Runtime Error

Solution code:
print(''.join(map(lambda x:{'1':'9','9':'1'}[x],input().split())))

Submission status: Runtime Error

Solution code:

N = input()

if N = "111":
	print("999")
if N = "119":
	print("991")
if N = "199":
	print("911")
if N = "999":
	print("111")
if N = "191":
	print("919")
if N = "919":
	print("191")
if N = "911":
	print("199")
if N = "991":
	print("119")

Submission status: Runtime Error

Solution code:

N = input()

if N = 111:
	print("999")
elif N = 119:
	print("991")
elif N = 199:
	print("911")
elif N = 999:
	print("111")
elif N = 191:
	print("919")
elif N = 919:
	print("191")
elif N = 911:
	print("199")
elif N = 991:
	print("119")

Submission status: Runtime Error

Solution code:

N = int(input())

if N = 111:
	print("999")
elif N = 119:
	print("991")
elif N = 199:
	print("911")
elif N = 999:
	print("111")
elif N = 191:
	print("919")
elif N = 919:
	print("191")
elif N = 911:
	print("199")
elif N = 991:
	print("119")

Submission status: Runtime Error

Solution code:
import collections

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

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if len(o.most_common()) > 1 and len(e.most_common()) <= 1:
        maxoddcnt = o.most_common()[1][1]
    if len(o.most_common()) <= 1 and len(e.most_common()) > 1:
        maxevencnt = e.most_common()[1][1]
    if o.most_common()[1][1] + e.most_common()[0][1] >= o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]
        input()

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

Submission status: Runtime Error

Solution code:
import collections

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

#すべての値が同じときは半分を置換する
if odd == even:
    print(len(odd))
    exit(0)

#奇数列，偶数列それぞれの最頻の文字が同じ場合は，いずれかを2番目に多い文字に置換しなければならない
if o.most_common()[0][0] == e.most_common()[0][0]:
    if o.most_common()[1][1] + e.most_common()[0][1] > o.most_common()[0][1] + e.most_common()[1][1]:
        maxoddcnt = o.most_common()[1][1]
    else: #if o.most_common()[1][1] + e.most_common()[0][1] <= o.most_common()[0][1] + e.most_common()[1][1] :
        maxevencnt = e.most_common()[1][1]

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[0][1] > gu[0][1]:
            ans = n - ki[0][1]
        else:
            ans = n - gu[0][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0

if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n / 2)
    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter as C;n,v=input(),raw_input().split();a,b=C(v[::2]),C(v[1::2]);a,c=a.most_common()[:2];b,d=b.most_common()[:2];print n-(a[1]-b[1]if a[0]!=b[0]else min(c[1]+b[1],a[1]+d[1]))

Submission status: Runtime Error

Solution code:
n = int(input())
AllList = list(map(int, input().split()))
OddList = [0 for i in range(100001)]
EvenList = [0 for i in range(100001)]
for i in range(n):
    if i % 2 == 0:
        OddList[AllList[i]] += 1
    else:
        EvenList[AllList[i]] += 1

OddMax = max(OddList)
EvenMax = max(EvenList)
OddMaxNum = OddList.index(OddMax)
EvenMaxNum = EvenList.index(EvenMax)

if OddMaxNum == EvenMaxNum:
    if OddMax > EvenMax:
        EvenList[EvenMaxNum] = 0
    else:
        OddList[OddMaxNum] = 0

OddMax = max(OddList)
EvenMax = max(EvenList)

ans = n - OddMax - EvenMax

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter


def solve(V):
    n = len(V)
    odd = Counter()
    even = Counter()
    total = Counter()
    for i, c in enumerate(V):
        total.update([c])
        if i % 2 == 0:
            even.update([c])
        else:
            odd.update([c])

    total_max = total.most_common()[0]
    if total_max[1] == len(V):
        return len(V) / 2

    even_maxs = even.most_common(2)
    odd_maxs = odd.most_common(2)
    if len(odd_maxs) > 1:
        odd_max, odd_2nd_max = odd_maxs[0], odd_maxs[1]
    else:
        odd_max, odd_2nd_max = odd_maxs[0], None

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

    ans = 0
    if odd_max[0] != even_max[0]:
        odd_max = odd_max[0]
        even_max = even_max[0]
    elif odd_2nd_max != None and even_2nd_max == None:
        even_max = even_max[0]
        odd_max = odd_2nd_max[0]
    elif odd_2nd_max == None and even_2nd_max != None:
        odd_max = odd_max[0]
        even_max = even_2nd_max[0]
    else:  # odd_2nd_max != None and even_2nd_max != None:
        return n - max(even_maxs[0][1] + odd_maxs[1][1], 
                       even_maxs[1][1] + odd_maxs[0][1])

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


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

Submission status: Runtime Error

Solution code:
import collections
 
n = int(input())
v = [int(i) for i in input().split()]
 
v1 = [v[i] for i in range(0,n,2)]
v2 = [v[i] for i in range(1,n,2)]
 
count1 = collections.Counter(v1).most_common(2)
count2 = collections.Counter(v2).most_common(2)

if max(count1.values()) != max(count2.values()):
    res = len(v1) - max(count1.values()) + len(v2) - max(count2.values())
    print(res)
else:
    if len(count1) == 1:
        print(len(v1))
    else:
        res1 = len(v1) - count1[0][1] + len(v2) - count2[1][1]
        res2 = len(v1) - count1[1][1] + len(v2) - count2[0][1]
        print(min(res1,res2))

Submission status: Runtime Error

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,6)+1)]
cc = [0 for i in range(pow(10,6)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        cc[b[i]-1] += 1
    else:
        c[b[i]-1] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

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

if k != kk:
    print(a-one-two)
else:
    print(a-t)

Submission status: Runtime Error

Solution code:
print(1110-int(input())

Submission status: Runtime Error

Solution code:
from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))
odd = v[::2]
even = v[1::2]
    
c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)

print(c_even, c_odd)
    
if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
elif(len(c_even) >= 2 and len(c_odd) >= 2):
    second = max[c_even[1][1], c_odd[1][1]]
    print(n - c_even[0][1] - second)
else:
    print(n/2)

Submission status: Runtime Error

Solution code:
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+100)]
cc = [0 for i in range(pow(10,5)+100)]
for i in range(a):
    if i % 2 == 0:
        c[b[i]] += 1
    else:
        cc[b[i]] += 1

one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(len(c)):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i

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

print(a-one-two)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(aa) for aa in input().split()]

def add_entry(hist, aa):
    if aa in hist:
        hist[aa] += 1
    else:
        hist[aa] = 1


def make_hist(a):
    even_hist = {}
    odd_hist = {}

    for i in range(len(a)//2):
        add_entry(even_hist, a[2*i])
        add_entry(odd_hist, a[2*i+1])

    return even_hist, odd_hist


def get_sorted_hist(hist):
    return sorted(hist.items(), key=lambda x: -x[1])

eh, oh = make_hist(a)
seh = get_sorted_hist(eh)
soh = get_sorted_hist(oh)

print(seh, soh)

if seh[0][0] != soh[0][0]:
    print(len(a) - seh[0][1] - soh[0][1])
else:
    if len(seh) == 1 and len(soh) == 1:
        print(len(a)//2)
    elif len(seh) == 1:
        print(len(a) - seh[0][1] - soh[1][1])
    elif len(soh) == 1:
        print(len(a) - soh[0][1] - seh[1][1])
    else:
        print(min(len(a) - seh[0][1] - soh[1][1], len(a) - soh[0][1] - seh[1][1]))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
v = input().split()
v_int = [int(i) for i in v]
v_odd = []
v_even = []
for i in range(int(n/2)):
  v_even.append(v_int[i*2])
  v_odd.append(v_int[i*2+1])
c_odd = collections.Counter(v_odd)
c_even = collections.Counter(v_even)
max_odd = 0
second_odd = 0
max_key_odd = 0
for key in c_odd:
  if max_odd < c_odd[key]:
    second_odd = max_odd
    max_odd = c_odd[key]
    max_key_odd = key
  elif second_odd < c_odd[key]:
    second_odd = c_odd[key]
    
max_even = 0
second_even = 0
max_key_even = 0
for key in c_even:
  if max_even < c_even[key]:
    second_even = max_even
    max_even = c_even[key]
    max_key_even = key
  elif second_even < c_even[key]:
    second_even = c_even[key]
    
if max_key_even != max_key_odd:
  print(int(n)- max_even - max_odd)
else:
  if max_even > max_odd:
    if max_even == second_even:
      print(int(n) - max_even - max_odd)
    else:
      print(int(n) - max_even - second_odd)
  elif max_even < max_odd:
    if max_odd == second_odd:
      print(int(n) - max_odd - max_even)
    else:
      print(int(n) - max_odd - second_even)
  else : 
    if second_odd > second_even:
      print(int(n) - max_even - second_odd)
    else :
      print(int(n) - max_odd - second_even)

Submission status: Runtime Error

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

A=[[0,i] for i in range(10**5+3)]
B=[[0,i] for i in range(10**5+3)]

for i in range(0,n,2):
    A[V[i]][0]+=1
for i in range(1,n,2):
    B[V[i]][0]+=1

A.sort(reverse=1)
B.sort(reverse=1)

#print(A[:10])
#print(B[:10])

Ma=[]
Mb=[]

ma=A[0][0]
mb=B[0][0]
i=0
j=0
while A[i][0]==ma :
    Ma.append(A[i][1])
    i+=1

while B[j][0]==mb :
    Mb.append(B[j][1])
    j+=1

if Ma==Mb :
    print(min(n-ma-B[j][0],n-mb-A[i][0]))
else :
    print(n-ma-mb)

Submission status: Runtime Error

Solution code:
n = int(input())
numberL = list(map(int, input().split()))
 
kisuuSyuL=[]
kisuuKosuL=[]
kisuuKosuL2=[]
gusuSyuL=[]
gusuKosuL=[]
gusuKosuL2=[]
 
index=0
while index<n:
    if index==0:
        gusuSyuL.append(numberL[index])
        gusuKosuL.append(1)
        gusuKosuL2.append(1)
    elif index==1:
        kisuuSyuL.append(numberL[index])
        kisuuKosuL.append(1)
        kisuuKosuL2.append(1)
    else:
        if index%2==0:
            if numberL[index] in gusuSyuL:
                tarI = gusuSyuL.index(numberL[index])
                gusuKosuL[tarI]+=1
                gusuKosuL2[tarI]+=1
            else:
                gusuSyuL.append(numberL[index])
                gusuKosuL.append(1)
                gusuKosuL2.append(1)
        else:
            if numberL[index] in kisuuSyuL:
                tarI = kisuuSyuL.index(numberL[index])
                kisuuKosuL[tarI]+=1
                kisuuKosuL2[tarI]+=1
            else:
                kisuuSyuL.append(numberL[index])
                kisuuKosuL.append(1)
                kisuuKosuL2.append(1)
    index+=1

 
if len(kisuuSyuL)==1 and len(gusuSyuL)==1:
    if kisuuSyuL[0]==gusuSyuL[0]:
        print(int(n/2))
    else:
        print(0)
else:
    kiIndex = kisuuKosuL.index(max(kisuuKosuL))
    guIndex = gusuKosuL.index(max(gusuKosuL))
    if kisuuSyuL[kiIndex]!=gusuSyuL[guIndex]:
        noC=max(kisuuKosuL)+max(gusuKosuL)
        print(n-noC)
    else:
        if max(kisuuKosuL) < max(gusuKosuL):
            kisuuKosuL.sort()
            noC=kisuuKosuL[len(kisuuKosuL)-1]+max(gusuKosuL)
            print(n-noC)
        else:
            gusuKosuL.sort()
            noC=gusuKosuL[len(gusuKosuL)-1]+max(kisuuKosuL)
            print(n-noC)

Submission status: Runtime Error

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

head = vlist[::2]
foll = vlist[1::2]

import collections
ch = collections.Counter(head).most_common()
cf = collections.Counter(foll).most_common()

h_ = ch[0]
f_ = cf[0]

if h_[0] == f_[0]:
    if h_[1] > f_[1]:
        if len(cf) != 1:
            f_ = cf[1]
        else:
            f_ = (-1.1, 0)
    else:
        if len(ch) != 1:
            h_ = ch[1]
        else:
            h_ = (-1.1, 0)
elif h_[1] == f_[1]:
    if h_[0] == vlist[0]:
        f_ = (-1.1, 0)
    else:
        h_ = (-1.1, 0)

count = 0
for i in range(len(vlist)):
    if i % 2 == 0 and vlist[i] != h_[0]:
        count += 1
    if i % 2 == 1 and vlist[i] != f_[0]:
        count += 1

print(count)

Submission status: Runtime Error

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

head = vlist[::2]
foll = vlist[1::2]

import collections
ch = collections.Counter(head).most_common()
cf = collections.Counter(foll).most_common()

h_ = ch[0]
f_ = cf[0]

if h_[0] == f_[0]:
    #if h_[1] == f_[1]:
    #    if h_[0] == vlist[0]:
    #        f_ = (-1.1, 0)
    #    else:
    #        h_ = (-1.1, 0)
    if h_[1] > f_[1]:
        if len(cf) != 1:
            f_ = cf[1]
        else:
            f_ = (-1.1, 0)
    else:
        if len(ch) != 1:
            h_ = ch[1]
        else:
            h_ = (-1.1, 0)

count = 0
for i in range(len(vlist)):
    if i % 2 == 0 and vlist[i] != h_[0]:
        count += 1
    if i % 2 == 1 and vlist[i] != f_[0]:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
v=[int(i) for i in input().split(' ')]

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

vo = collections.Counter(v_odd).most_common()
ve = collections.Counter(v_even).most_common()

# 最大の値が同じ場合
if vo[0][0] == ve[0][0]:
    # 奇数のほうが少ない場合
    if vo[0][1] > ve[0][1]:
        result = len(v_odd) - vo[0][1] + len(v_even) - ve[1][1]
    elif vo[0][1] < ve[0][1]:
        result = len(v_odd) - vo[1][1] + len(v_even) - ve[0][1]
    else:
        result = len(v_odd) - vo[0][1] + len(v_even) 
else:
    result = len(v_odd) - vo[0][1] + len(v_even) - ve[0][1]

print(result)

Submission status: Runtime Error

Solution code:
n=int(input())

l=list(map(int,input().split()))
l1=[]
l2=[]

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

count1=[]
count2=[]

for i in range(100000):
	count1.append(0)
	count2.append(0)

for i in range(n//2):
	count1[l1[i]-1]+=1
	count2[l2[i]-1]+=1

max1=0
max2=0

maxc1=[]
maxc2=[]

for i in range(100000):
	if count1[i]>=max1:
		max1=count1[i]
		maxc1.append(i)

	if count2[i]>=max2:
		max2=count2[i]
		maxc2.append(i)

# print('maxc1',maxc1)
# print('maxc2',maxc2)
# print('max1',max1)
# print('max2',max2)

# if len(maxc2)+len(maxc1)>2 or (len(maxc2)+len(maxc1)==2 and maxc1[0]!=maxc2[0]):
# 	final=max1+max2

# else :
max3=0
max4=0
for i in range(100000):
	if i!=maxc1[0]:
		if count1[i]>=max3:
			max3=count1[i]
			maxc1.append(i)

	if i!=maxc2[0]:
		if count2[i]>=max4:
			max4=count2[i]
			maxc2.append(i)

final=max(max1+max4,max2+max3)

print(n-final)

Submission status: Runtime Error

Solution code:
import collections


n = int(input())
v = list(map(int, input().split()))
odd = []
even = []
for i in range(int(n/2)):
    even.append(v[2*i])
    odd.append(v[2*i + 1])
evencount = collections.Counter(even)
oddcount = collections.Counter(odd)


def hoge(i):
    global ans
    try:
        if evencount.most_common()[i][0] == oddcount.most_common()[i][0]:

            if evencount.most_common()[i][1] > oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
                print(ans)
            elif evencount.most_common()[i][1] < oddcount.most_common()[i][1]:
                ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
                print(ans)
            else:
                if len(evencount) == 1:
                    ans = int(n/2)
                    print(ans)
                else:
                    hoge(i+1)

        else: 
            ans = n - evencount.most_common()[i][1] - oddcount.most_common()[i][1]
            print(ans)
    except IndexError:   
        ans = n - evencount.most_common()[0][1] - oddcount.most_common()[1][1]
        print(ans) 


hoge(0)

Submission status: Runtime Error

Solution code:
def cal(n,v):
    k=n//2
    even=range(0,2*k,2)
    odd=range(1,2*k+1,2)

    el=[]
    for i in even:
        el.append(v[i])
    ol=[]
    for i in odd:
        ol.append(v[i])

    d={}
    for i in el:
        if((i in d) is False):
            d[i]=0
        else:
            d[i]+=1

    f={}
    for i in ol:
        if((i in f) is False):
            f[i]=0
        else:
            f[i]+=1

    while(True):
        e = max(d, key=d.get)
        o = max(f, key=f.get)
        if(e==o):
            if(d[e]>f[e]):
                del f[e]
            elif(d[e]<f[e]):
                del d[e]
            else:
                return print(k)
        else:
            break

    sum=0
    for i in el:
        if(i!=e):
            sum+=1
    for i in ol:
        if(i!=o):
            sum+=1
    return print(sum)

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

Submission status: Runtime Error

Solution code:
n=int(input())
v=list(map(int,input().split()))
 
k=n//2
even=range(0,2*k,2)
odd=range(1,2*k+1,2)
 
el=[]
for i in even:
    el.append(v[i])
ol=[]
for i in odd:
    ol.append(v[i])
 
d={}
for i in el:
    if((i in d)is False ):
        d[i]=0
    else:
        d[i]+=1
e = max(d, key=d.get)
 
d={}
for i in ol:
    if((i in d)is False ):
        d[i]=0
    else:
        d[i]+=1
o = max(d, key=d.get)
 
if(el==ol):
    print(k)
else:
    sum=0
    for i in el:
        if(i!=e):
            sum+=1
    for i in ol:
        if(i!=o):
            sum+=1
    print(sum)

Submission status: Runtime Error

Solution code:
n=int(input())
N=list(map(int,input().split()))
even=[]
odd=[]
for i in range(len(N)):
    if i%2==0:
        even.append(N[i])
    if i%2==1:
        odd.append(N[i])
import collections
c = collections.Counter(even)
x=c.most_common()[0][0]
o=even.count(x)
d= collections.Counter(odd)
y=d.most_common()[0][0]
p=odd.count(y)
s=len(even)-even.count(x)
t=len(odd)-odd.count(y)
if x!=y and o==len(even) and p==len(odd):
    print(0)
elif x!=y:
    print(s+t)
elif x==y and o==len(even) and p==len(odd):
    print(n/2)
else:
    if o>p:
        y=d.most_common()[1][0]
        s=len(even)-even.count(x)
        t=len(odd)-odd.count(y)
        print(s+t)
    else:
        x=c.most_common()[1][0]
        s=len(even)-even.count(x)
        t=len(odd)-odd.count(y)
        print(s+t)