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

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(){
    int a,b,max_ev=1,max_od=1,sum=0;
    int range_min_odd=1,range_max_odd=1,range_min_even=1,range_max_even=1;
    int even[100000]={};
    int odd[100000]={};
    scanf("%d",&a);
    //////////////////   MAX10^15
    for(int i=1;i<a+1;i++){
        if(i%2==1){
            scanf("%d",&b);
            odd[b]+=1;
            if(range_min_odd>b)
                range_min_odd=b;
            if(range_max_odd<b)
                range_max_odd=b;
        }
        else{
            scanf("%d",&b);
            even[b]+=1;
            if(range_min_even>b)
                range_min_even=b;
            if(range_max_even<b)
                range_max_even=b;
        }
    }
    
    //puts("__________");
    
    
    for(int i=range_min_even;i<range_max_even+1;i++){
        if(max_ev<=even[i])
        max_ev=i;
    }
    
    for(int i=range_min_odd;i<range_max_odd+1;i++){
        if(max_od<=odd[i])
            max_od=i;
    }
   /* printf("max_ev:%d\n",max_ev);
    printf("max_od:%d\n",max_od);
    printf("range_even:%d--%d\n",range_min_even,range_max_even);
    printf("range_odd:%d--%d\n",range_min_odd,range_max_odd);
    */
    for(int i=range_min_odd;i<range_max_odd+1;i++){
            sum+=odd[i];
    }

    for(int i=range_min_even;i<range_max_even+1;i++){
            sum+=even[i];
    }
   // printf("sum::::%d\n",sum);
    
    sum=sum-even[max_ev]-odd[max_od];
    if(max_ev==max_od && sum==0){
        printf("%d\n",a/2);
        return 0;
    }
    printf("%d\n",sum);
    return 0;
    
    
}