Problem: 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.

Submission attempts (in order):
#################################






#################################
def separate(values,a,b):
    for v in values:
        a.append(v)
        a,b = b,a


##############################





##############################
def getCount(values):
    currentNum=0
    currentCount=0
    ret={'First' :{'Num':[],'Cnt':0},
         'Second':{'Num':[],'Cnt':0}}
    for v in values:
        if v==currentNum:
            currentCount+=1
        else:
            
            if ret['First']['Cnt'] < currentCount:
                
                ret['Second']=ret['First'].copy()
                ret['First']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['First']['Cnt'] == currentCount:
                
                ret['First']['Num'].append(currentNum)
            elif ret['Second']['Cnt'] < currentCount:
                
                ret['Second']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['Second']['Cnt'] == currentCount:
                
                ret['Second']['Num'].append(currentNum)

            currentNum=v
            currentCount=1

    
    if ret['First']['Cnt'] < currentCount:
        ret['Second']=ret['First'].copy()
        ret['First']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['First']['Cnt'] == currentCount:
        ret['First']['Num'].append(currentNum)
    elif ret['Second']['Cnt'] < currentCount:
        ret['Second']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['Second']['Cnt'] == currentCount:
        ret['Second']['Num'].append(currentNum)

    return ret


#############################

#############################
vars = input ()
a=[]
b=[]
varArray=vars.split(" ")
separate(varArray,a,b)
a.sort()
b.sort()
a_result=getCount(a)
b_result=getCount(b)
if (len(a_result['First']['Num'])>1 or
    len(b_result['First']['Num'])>1):
    
    xa=len(a)-a_result['First']['Cnt']
    xb=len(b)-b_result['First']['Cnt']
    x=xa+xb
else:
    
    if a_result['First']['Num'][0]!=b_result['First']['Num'][0]:
        
        xa=len(a)-a_result['First']['Cnt']
        xb=len(b)-b_result['First']['Cnt']
        x=xa+xb
    else:
        
        xaa=len(a)-a_result['First']['Cnt']
        xab=len(b)-b_result['Second']['Cnt']
        xa=xaa+xab
        xba=len(a)-a_result['Second']['Cnt']
        xbb=len(b)-b_result['First']['Cnt']
        xb=xba+xbb
        x=xa if xa<xb else xb

print(x)



#################################






#################################
def separate(values,a,b):
    for v in values:
        a.append(v)
        a,b = b,a


##############################





##############################
def getCount(values):
    currentNum=0
    currentCount=0
    ret={'First' :{'Num':[],'Cnt':0},
         'Second':{'Num':[],'Cnt':0}}
    for v in values:
        if v==currentNum:
            currentCount+=1
        else:
            
            if ret['First']['Cnt'] < currentCount:
                
                ret['Second']=ret['First'].copy()
                ret['First']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['First']['Cnt'] == currentCount:
                
                ret['First']['Num'].append(currentNum)
            elif ret['Second']['Cnt'] < currentCount:
                
                ret['Second']={'Num':[currentNum],'Cnt':currentCount}
            elif ret['Second']['Cnt'] == currentCount:
                
                ret['Second']['Num'].append(currentNum)

            currentNum=v
            currentCount=1

    
    if ret['First']['Cnt'] < currentCount:
        ret['Second']=ret['First'].copy()
        ret['First']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['First']['Cnt'] == currentCount:
        ret['First']['Num'].append(currentNum)
    elif ret['Second']['Cnt'] < currentCount:
        ret['Second']={'Num':[currentNum],'Cnt':currentCount}
    elif ret['Second']['Cnt'] == currentCount:
        ret['Second']['Num'].append(currentNum)

    return ret


#############################

#############################
n = input()
vars = input ()
a=[]
b=[]
varArray=vars.split(" ")
separate(varArray,a,b)
a.sort()
b.sort()
a_result=getCount(a)
b_result=getCount(b)
if (len(a_result['First']['Num'])>1 or
    len(b_result['First']['Num'])>1):
    
    xa=len(a)-a_result['First']['Cnt']
    xb=len(b)-b_result['First']['Cnt']
    x=xa+xb
else:
    
    if a_result['First']['Num'][0]!=b_result['First']['Num'][0]:
        
        xa=len(a)-a_result['First']['Cnt']
        xb=len(b)-b_result['First']['Cnt']
        x=xa+xb
    else:
        
        xaa=len(a)-a_result['First']['Cnt']
        xab=len(b)-b_result['Second']['Cnt']
        xa=xaa+xab
        xba=len(a)-a_result['Second']['Cnt']
        xbb=len(b)-b_result['First']['Cnt']
        xb=xba+xbb
        x=xa if xa<xb else xb

print(x)


n=int(input())
d=1
for i in range(3):
    x=n//d%10
    if x==1:
        n+=8*d
    elif x==9:
        n-=8*d
    d*=10

print(n)

Verdicts: Wrong Answer

Runtime Error

Accepted