codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

550C.md (1363B)


      1 Source: https://codeforces.com/problemset/problem/550/C
      2 
      3 C. Divisibility by Eight
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
     22 
     23 Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.
     24 
     25 If a solution exists, you should print it.
     26 
     27 Input
     28 
     29 The single line of the input contains a non-negative integer *n*. The representation of number *n* doesn't contain any leading zeroes and its length doesn't exceed 100 digits.
     30 
     31 Output
     32 
     33 Print "NO" (without quotes), if there is no such way to remove some digits from number *n*.
     34 
     35 Otherwise, print "YES" in the first line and the resulting number after removing digits from number *n* in the second line. The printed number must be divisible by 8.
     36 
     37 If there are multiple possible answers, you may print any of them.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 3454
     45 ```
     46 
     47 Output
     48 
     49 ```
     50 YES  
     51 344
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 10
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 YES  
     64 0
     65 ```
     66 
     67 Input
     68 
     69 ```
     70 111111
     71 ```
     72 
     73 Output
     74 
     75 ```
     76 NO
     77 ```