JOIN
Get Time

   Problem Statement  

 Problem Statement for LuckyRemainder

Problem Statement

    Little Arthur loves numbers and 9 is his most favorite. When encountering a number, he always calculates its lucky remainder - the remainder after division by 9.



This time Arthur is given a number X of length N which contains no zeros. He is asked to find the supersum of X: super(X).



super(X) is defined as follows. For a given non-full set S of digit positions in X we erase the digits in these positions to obtain a sub-number. For example, if X = 12345 and S = {2, 4} we erase 2nd and 4th digits and obtain a sub-number 135. Supersum of X is simply the sum of sub-numbers for all valid sets S.



For example, if X is 123, then super(X) = 123 + 12 + 13 + 23 + 1 + 2 + 3 = 177.



Calculating super(X) is very difficult for Arthur. However, before getting to work he is wondering if it is possible to quickly tell what the lucky reminder of the supersum of X is. You have to help him.



Given String X, which contains the decimal representation of the number X, return super(X)'s lucky remainder.
 

Definition

    
Class:LuckyRemainder
Method:getLuckyRemainder
Parameters:String
Returns:int
Method signature:int getLuckyRemainder(String X)
(be sure your method is public)
    
 

Constraints

-X will contain between 1 and 50 characters, inclusive.
-Each character of X will be one of the following: '1', '2', '3', '4', '5', '6', '7', '8', '9'.
 

Examples

0)
    
"123"
Returns: 6
Example from the problem statement. super(123) = 177, which gives remainder 6 after division by 9.
1)
    
"24816"
Returns: 3
Supersum of 24816 is 43986.
2)
    
"8"
Returns: 8
3)
    
"11235813213455"
Returns: 7
Supersum is 43950094900477.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

This problem was used for:
       Single Round Match 509 Round 1 - Division I, Level One
       Single Round Match 509 Round 1 - Division II, Level Two