codeforces-scrape

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

845B.md (1313B)


      1 Source: https://codeforces.com/problemset/problem/845/B
      2 
      3 B. Luba And The Ticket
      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 Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
     22 
     23 The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
     24 
     25 Input
     26 
     27 You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
     28 
     29 Output
     30 
     31 Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 000000
     39 ```
     40 
     41 Output
     42 
     43 ```
     44 0
     45 ```
     46 
     47 Input
     48 
     49 ```
     50 123456
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 2
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 111000
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 1
     69 ```
     70 
     71 Note
     72 
     73 In the first example the ticket is already lucky, so the answer is 0.
     74 
     75 In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
     76 
     77 In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.