codeforces-scrape

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

375A.md (1141B)


      1 Source: https://codeforces.com/problemset/problem/375/A
      2 
      3 A. Divisible by Seven
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
     22 
     23 Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.
     24 
     25 Input
     26 
     27 The first line contains positive integer *a* in the decimal record. It is guaranteed that the record of number *a* contains digits: 1, 6, 8, 9. Number *a* doesn't contain any leading zeroes. The decimal representation of number *a* contains at least 4 and at most 106 characters.
     28 
     29 Output
     30 
     31 Print a number in the decimal notation without leading zeroes — the result of the permutation.
     32 
     33 If it is impossible to rearrange the digits of the number *a* in the required manner, print 0.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 1689
     41 ```
     42 
     43 Output
     44 
     45 ```
     46 1869
     47 ```
     48 
     49 Input
     50 
     51 ```
     52 18906
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 18690
     59 ```