codeforces-scrape

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

87A.md (2698B)


      1 Source: https://codeforces.com/problemset/problem/87/A
      2 
      3 A. Trains
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
     22 
     23 When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every *a* minutes, but a train goes to Masha's direction every *b* minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
     24 
     25 We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
     26 
     27 Help Vasya count to which girlfriend he will go more often.
     28 
     29 Input
     30 
     31 The first line contains two integers *a* and *b* (*a* ≠ *b*, 1 ≤ *a*, *b* ≤ 106).
     32 
     33 Output
     34 
     35 Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 3 7
     43 ```
     44 
     45 Output
     46 
     47 ```
     48 Dasha
     49 ```
     50 
     51 Input
     52 
     53 ```
     54 5 3
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 Masha
     61 ```
     62 
     63 Input
     64 
     65 ```
     66 2 3
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 Equal
     73 ```
     74 
     75 Note
     76 
     77 Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
     78 
     79 If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
     80 
     81 If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
     82 
     83 If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
     84 
     85 If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
     86 
     87 In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often.