Control C301B P19564


Statement
 

pdf   zip

html

We define the valencia of a natural number n as the absolute value of the substraction between the sum of the digits that are in odd positions and the sum of the digits that are in even positions (the positions are counted starting in one and from the right to the left). n is balanced if its valencia is 0.

For instance 15741 is a balanced number, because the sum of the digits that are in odd positions and the sum of the digits that are in even positions is 9, therefore it has valencia 0. However, 31 is not a balanced number, because its valencia is 2.

Your task is to write a program that, given a non empty sequence of natural numbers, prints the first balanced number of the sequence. If there is not any balanced number, print the greatest valencia of the numbers in the sequence.

Input

The input is a non empty sequence of natural numbers.

Output

Your program must print a line with the first balanced number of the sequence. If there is not any, print the greatest valencia of the sequence. Follow the format of the instances.

Observation

Your program must implement and use the function

int valencia(int n);

that, given a natural number |n|, returns its valencia.

Public test cases
  • Input

    20394 15741 42 111 25
    

    Output

    The first balanced number is 20394.
    
  • Input

    1 2 98 89
    

    Output

    The greatest valencia is 2.
    
  • Input

    11
    

    Output

    The first balanced number is 11.
    
  • Input

    777 123456789 31 0
    

    Output

    The first balanced number is 0.
    
  • Information
    Author
    Professorat de P1
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++