codeforces-scrape

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

740A.md (1812B)


      1 Source: https://codeforces.com/problemset/problem/740/A
      2 
      3 A. Alyona and copybooks
      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 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks.
     22 
     23 What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n* + *k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
     24 
     25 Input
     26 
     27 The only line contains 4 integers *n*, *a*, *b*, *c* (1 ≤ *n*, *a*, *b*, *c* ≤ 109).
     28 
     29 Output
     30 
     31 Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n* + *k* is divisible by 4.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 1 1 3 4
     39 ```
     40 
     41 Output
     42 
     43 ```
     44 3
     45 ```
     46 
     47 Input
     48 
     49 ```
     50 6 2 1 1
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 1
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 4 4 4 4
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 0
     69 ```
     70 
     71 Input
     72 
     73 ```
     74 999999999 1000000000 1000000000 1000000000
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 1000000000
     81 ```
     82 
     83 Note
     84 
     85 In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.
     86 
     87 In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total.
     88 
     89 In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.
     90 
     91 In the fourth example Alyona should buy one pack of one copybook.