This page is still under construction.

Parts of this page are still being built. What you see may change.

Neatness

Time limit1sMemory limit512 MB

Summary
Choose a first cleaning day among 1..k and a starting boy so that, after swap rules during non-overlapping absences, both boys clean equally often in an n-day month.
Level

Medium7 of 10

Topics
Math, Number theory, Implementation, Brute force
Solved
No attempts yet

Problem

Boys Dima and Mitya share a room in a dormitory and take turns cleaning it every kk days. A new month, consisting of nn days, has just begun, so the boys have to come up with a new cleaning schedule. To do it, the boys simply choose who is going to clean first, and which of the first kk days of the month it will happen. The next cleaning will happen exactly kk days after the previous one, and the other boy will have to do it. For example, if Dima cleans the room on day ii, then on day i+ki + k Mitya will have to do the cleaning, on day i+2ki + 2k it will be Dima's turn again, and so on.

The schedule should be fair: both boys should clean the room an equal number of times. The situation is complicated by the fact that both Dima and Mitya are planning to go to an olympiad once during this month. If one of the boys is absent during his cleaning day, the other boy cleans in his place. The schedule does not shift in this case. It is known that Dima will be absent from the aa-th day to the bb-th day inclusive, and Mitya from the cc-th day until the dd-th day. Days in the month are numbered from 1 to nn. The boys' trips to olympiads do not intersect, so every day at least one of the boys is at home.

Help the boys decide who should clean the room first, and which day among the first kk days of the month it should happen, or determine that it is impossible.

Input

The first line contains two integers nn and kk: the number of days in this month and the number of days between two consecutive cleanings (2≤n≤10182 \le n \le 10^{18}, 1≤k≤n1 \le k \le n).

The second line contains integers aa, bb, cc and dd, describing the boys' trips to olympiads (1≤a≤b≤n1 \le a \le b \le n; 1≤c≤d≤n1 \le c \le d \le n; b<cb < c or d<ad < a).

Output

If it is impossible to create a fair schedule, print −1-1.

Otherwise, print one integer in the first line: the day of the first cleaning. On the second line print <<Dima>> if Dima should clean first, and <<Mitya>> otherwise.

If there are multiple possible solutions, print any of them.

Notes

Let us represent the samples as tables using the following notation:

  • <<d>> --- day when Dima is away,
  • <<m>> --- day when Mitya is away,
  • <<D>> --- day when Dima cleans the room,
  • <<M>> --- day when Mitya cleans the room,
  • <<*>> --- possible starting day.

Then for the first sample we get the following table:

Days123456789101112
Departures*****dddddmm
Schedule..D....M....
Actual..D....M....

This way both boys will clean the room an equal number of times, and the boys' trips do not affect the schedule.

Table for the second sample:

Days123456789101112131415161718
Departuresm*m*m*m*mm........dddd
Schedule..M...D...M...D...
Actual..D...D...M...M...

Because Mitya is absent on the third day, Dima will clean instead. Mitya will clean the room on the 15th day because of Dima's trip. This way each boy cleans the room twice, even if it was not scheduled.

Examples3

  1. Example 1

    Input
    12 5
    6 10 11 12
    
    Expected output
    3
    Dima
    
  2. Example 2

    Input
    18 4
    15 18 1 6
    
    Expected output
    3
    Mitya
    
  3. Example 3

    Input
    10 3
    1 4 5 6
    
    Expected output
    -1