#P3409. 值日班长值周班长

值日班长值周班长

Description

In a semester, there are nn daily duty monitors (值日班长), where A is the mm-th daily duty monitor, and there are pp weekly duty monitors (值周班长), where B is the qq-th weekly duty monitor. Assume we ignore holidays and any other schedule changes, and the daily/weekly duty rotations are never rearranged; that is, every week always has 55 school days and 22 rest days, and this semester never ends. On which day of the semester will it first happen that A is the daily duty monitor and B is the weekly duty monitor at the same time? If it never happens, output Orz mgh!!!.

Input Format

Multiple test cases. Each test case consists of one line with four integers n,m,p,qn, m, p, q. It is guaranteed that mnm \le n and qpq \le p.

Output Format

For each test case, output one line with the result.

20 7 3 3
30 7 4 3
27
Orz mgh!!!

Hint

Test point ID Number of test cases nn pp Special property
1 104\le 10^4 100\le 100 Yes
2 100\le 100 1000\le 1000 No
3 1000\le 1000 104\le 10^4
4 105\le 10^5 Yes
5 No
6 106\le 10^6
7 107\le 10^7
8 104\le 10^4 Yes
9 1000\le 1000 109\le 10^9
10 No

Special property: nn is a multiple of 55.

For 100%100\% of the testdata, 1mn1091 \le m \le n \le 10^9, 1qp1091 \le q \le p \le 10^9, and the number of test cases does not exceed 10410^4. Note that the maximum number of test cases and the maximum values of nn and pp will not be reached at the same time.

Translated by ChatGPT 5